Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements to the “Show parent folder name in tab title” option #7930

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platform/core.multitabs/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
javac.source=1.8
javac.release=11
javac.compilerargs=-Xlint -Xlint:-serial
javadoc.arch=${basedir}/arch.xml
nbm.needs.restart=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public boolean isTabRowPerProject() {
return impl.isTabRowPerProject();
}

public boolean isShowFolderName() {
return impl.isShowFolderName();
}

/**
* @return Maximum tab row count.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,26 @@ class DocumentSwitcherTable extends SwitcherTable {

private final JButton btnClose;
private final Controller controller;
private final ProjectColorTabDecorator decorator;
private final ProjectColorTabDecorator projectColorTabDecorator;
private final FolderNameTabDecorator folderNameDecorator;
private final ItemBorder ITEM_BORDER = new ItemBorder();
private final Border SEPARATOR_BORDER = BorderFactory.createEmptyBorder( 2, 2, 0, 5 );

private String itemText;

public DocumentSwitcherTable( Controller controller, SwitcherTableItem[] items, int y ) {
super( items, y );
this.controller = controller;
btnClose = createCloseButton();
if( Settings.getDefault().isSameProjectSameColor() ) {
decorator = new ProjectColorTabDecorator();
projectColorTabDecorator = new ProjectColorTabDecorator();
} else {
projectColorTabDecorator = null;
}
if( Settings.getDefault().isShowFolderName() ) {
folderNameDecorator = new FolderNameTabDecorator(this);
} else {
decorator = null;
folderNameDecorator = null;
}
ToolTipManager.sharedInstance().registerComponent( this );
}
Expand Down Expand Up @@ -103,6 +111,13 @@ public Component prepareRenderer( TableCellRenderer renderer, int row, int colum
lbl.setIcon( null );
lbl.setText( item.getHtmlName() );
} else {
if(null != folderNameDecorator && null != item) {
TabData tab = item.getTabData();
if(null != tab) {
itemText = folderNameDecorator.getText(tab) + (item.isActive() ? " ←" : ""); //NOI18N
lbl.setText(itemText);
}
}
lbl.setBorder( ITEM_BORDER );
}
}
Expand All @@ -115,10 +130,10 @@ public Component prepareRenderer( TableCellRenderer renderer, int row, int colum
res.setBackground( renComponent.getBackground() );
return res;
}
if( null != decorator && null != item && !selected ) {
if( null != projectColorTabDecorator && null != item && !selected ) {
TabData tab = item.getTabData();
if( null != tab ) {
ITEM_BORDER.color = decorator.getBackground( tab, selected);
ITEM_BORDER.color = projectColorTabDecorator.getBackground( tab, selected);
}
}
return renComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.io.File;
import javax.swing.Icon;
import javax.swing.UIManager;
import org.netbeans.core.multitabs.TabDecorator;
import org.netbeans.core.multitabs.prefs.SettingsImpl;
import org.netbeans.swing.popupswitcher.SwitcherTable;
import org.netbeans.swing.tabcontrol.TabData;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.util.lookup.ServiceProvider;
import org.openide.windows.TopComponent;

import static java.util.Objects.requireNonNullElse;

/**
* Show the name of parent folder in tab's title.
* http://netbeans.org/bugzilla/show_bug.cgi?id=222696
Expand All @@ -40,7 +45,24 @@
public class FolderNameTabDecorator extends TabDecorator {

private final SettingsImpl settings = new SettingsImpl();
private static final String pathSeparator = System.getProperty( "file.separator", "/" ); //NOI18N
private final String fadeColor;

/**
* Decorator used for tabs
*/
public FolderNameTabDecorator() {
fadeColor = fadeColor(
requireNonNullElse(UIManager.getColor("nb.multitabs.foreground"), UIManager.getColor("TabbedPane.foreground")), //NOI18N
requireNonNullElse(UIManager.getColor("nb.multitabs.background"), UIManager.getColor("TabbedPane.background")) //NOI18N
);
}

/**
* Decorator used for switcher
*/
FolderNameTabDecorator(SwitcherTable switcher) {
fadeColor = fadeColor(switcher.getForeground(), switcher.getBackground());
}

@Override
public String getText( TabData tab ) {
Expand All @@ -54,7 +76,7 @@ public String getText( TabData tab ) {
if( fo.isData() ) {
FileObject folder = fo.getParent();
if( null != folder ) {
String folderName = folder.getNameExt() + pathSeparator;
String folderName = "<font color=\"" + fadeColor + "\">" + folder.getNameExt() + File.separator + "</font>"; //NOI18N
String defaultText = tab.getText();

return merge( folderName, defaultText );
Expand Down Expand Up @@ -100,4 +122,12 @@ private static String merge( String prefix, String baseText ) {

return res.toString();
}

private String fadeColor(Color f, Color b) {
float a = 0.7f;
return String.format("#%02x%02x%02x", //NOI18N
(int)(b.getRed() + a * (f.getRed() - b.getRed())),
(int)(b.getGreen() + a * (f.getGreen() - b.getGreen())),
(int)(b.getBlue() + a * (f.getBlue() - b.getBlue())));
}
}
Loading