2121import java .awt .Color ;
2222import java .awt .Graphics ;
2323import java .awt .Rectangle ;
24+ import java .io .File ;
2425import javax .swing .Icon ;
2526import javax .swing .UIManager ;
2627import org .netbeans .core .multitabs .TabDecorator ;
2728import org .netbeans .core .multitabs .prefs .SettingsImpl ;
29+ import org .netbeans .swing .popupswitcher .SwitcherTable ;
2830import org .netbeans .swing .tabcontrol .TabData ;
2931import org .openide .filesystems .FileObject ;
3032import org .openide .loaders .DataObject ;
3133import org .openide .util .lookup .ServiceProvider ;
3234import org .openide .windows .TopComponent ;
3335
36+ import static java .util .Objects .requireNonNullElse ;
37+
3438/**
3539 * Show the name of parent folder in tab's title.
3640 * http://netbeans.org/bugzilla/show_bug.cgi?id=222696
4145public class FolderNameTabDecorator extends TabDecorator {
4246
4347 private final SettingsImpl settings = new SettingsImpl ();
44- private static final String pathSeparator = System .getProperty ( "file.separator" , "/" ); //NOI18N
45- private static final String FONT_COLOR = "<font color=\" " + hiddenColor () + "\" >" ; //NOI18N
46- private static final String FONT_COLOR_END = "</font>" ; //NOI18N
48+ private final String fadeColor ;
49+
50+ /**
51+ * Decorator used for tabs
52+ */
53+ public FolderNameTabDecorator () {
54+ fadeColor = fadeColor (
55+ requireNonNullElse (UIManager .getColor ("nb.multitabs.foreground" ), UIManager .getColor ("TabbedPane.foreground" )), //NOI18N
56+ requireNonNullElse (UIManager .getColor ("nb.multitabs.background" ), UIManager .getColor ("TabbedPane.background" )) //NOI18N
57+ );
58+ }
59+
60+ /**
61+ * Decorator used for switcher
62+ */
63+ FolderNameTabDecorator (SwitcherTable switcher ) {
64+ fadeColor = fadeColor (switcher .getForeground (), switcher .getBackground ());
65+ }
4766
4867 @ Override
4968 public String getText ( TabData tab ) {
@@ -57,7 +76,7 @@ public String getText( TabData tab ) {
5776 if ( fo .isData () ) {
5877 FileObject folder = fo .getParent ();
5978 if ( null != folder ) {
60- String folderName = FONT_COLOR + folder .getNameExt () + pathSeparator + FONT_COLOR_END ;
79+ String folderName = "<font color= \" " + fadeColor + " \" >" + folder .getNameExt () + File . separator + "</font>" ; //NOI18N
6180 String defaultText = tab .getText ();
6281
6382 return merge ( folderName , defaultText );
@@ -104,17 +123,8 @@ private static String merge( String prefix, String baseText ) {
104123 return res .toString ();
105124 }
106125
107- private static String hiddenColor () {
108- float a = 0.6f ;
109-
110- Color b = UIManager .getColor ("nb.multitabs.background" ); //NOI18N
111- Color f = UIManager .getColor ("nb.multitabs.foreground" ); //NOI18N
112-
113- if (b == null || f == null ) {
114- f = UIManager .getColor ("TabbedPane.foreground" ); //NOI18N
115- b = UIManager .getColor ("TabbedPane.background" ); //NOI18N
116- }
117-
126+ private String fadeColor (Color f , Color b ) {
127+ float a = 0.7f ;
118128 return String .format ("#%02x%02x%02x" , //NOI18N
119129 (int )(b .getRed () + a * (f .getRed () - b .getRed ())),
120130 (int )(b .getGreen () + a * (f .getGreen () - b .getGreen ())),
0 commit comments