From 913d29c6d381709ddea68bf642bfb823ae88d0af Mon Sep 17 00:00:00 2001 From: Alexey Borokhvostov Date: Thu, 31 Oct 2024 22:43:21 +0700 Subject: [PATCH] Small improvements to the "Show parent folder name in tab title" option: - parent folder name is displayed in opened documents list; - parent folder name is displayed in a different color from the file name. Co-authored-by: Michael Bien --- .../nbproject/project.properties | 2 +- .../org/netbeans/core/multitabs/Settings.java | 4 +++ .../multitabs/impl/DocumentSwitcherTable.java | 25 +++++++++++--- .../impl/FolderNameTabDecorator.java | 34 +++++++++++++++++-- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/platform/core.multitabs/nbproject/project.properties b/platform/core.multitabs/nbproject/project.properties index ddd2868cb8ae..564739228fab 100644 --- a/platform/core.multitabs/nbproject/project.properties +++ b/platform/core.multitabs/nbproject/project.properties @@ -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 diff --git a/platform/core.multitabs/src/org/netbeans/core/multitabs/Settings.java b/platform/core.multitabs/src/org/netbeans/core/multitabs/Settings.java index c41aa91512aa..2982808c7b73 100644 --- a/platform/core.multitabs/src/org/netbeans/core/multitabs/Settings.java +++ b/platform/core.multitabs/src/org/netbeans/core/multitabs/Settings.java @@ -88,6 +88,10 @@ public boolean isTabRowPerProject() { return impl.isTabRowPerProject(); } + public boolean isShowFolderName() { + return impl.isShowFolderName(); + } + /** * @return Maximum tab row count. */ diff --git a/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/DocumentSwitcherTable.java b/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/DocumentSwitcherTable.java index 4ff3786b3ac2..54fef8067ee8 100644 --- a/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/DocumentSwitcherTable.java +++ b/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/DocumentSwitcherTable.java @@ -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 ); } @@ -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 ); } } @@ -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; diff --git a/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/FolderNameTabDecorator.java b/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/FolderNameTabDecorator.java index c9fab2d77250..421cdc9573ea 100644 --- a/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/FolderNameTabDecorator.java +++ b/platform/core.multitabs/src/org/netbeans/core/multitabs/impl/FolderNameTabDecorator.java @@ -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 @@ -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 ) { @@ -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 = "" + folder.getNameExt() + File.separator + ""; //NOI18N String defaultText = tab.getText(); return merge( folderName, defaultText ); @@ -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()))); + } }