瀏覽代碼

Use the right default FG colour in the treeview.

If there's no notification, we have to fallback to the treeview's
foreground colour instead of hardcoding black...

Closes #503
pull/504/head
Chris Smith 7 年之前
父節點
當前提交
db2d999190

+ 17
- 11
ui_swing/src/main/java/com/dmdirc/addons/ui_swing/framemanager/tree/NodeLabel.java 查看文件

23
 package com.dmdirc.addons.ui_swing.framemanager.tree;
23
 package com.dmdirc.addons.ui_swing.framemanager.tree;
24
 
24
 
25
 import com.dmdirc.addons.ui_swing.UIUtilities;
25
 import com.dmdirc.addons.ui_swing.UIUtilities;
26
+import com.dmdirc.addons.ui_swing.components.IconManager;
26
 import com.dmdirc.addons.ui_swing.components.ImageButton;
27
 import com.dmdirc.addons.ui_swing.components.ImageButton;
27
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28
 import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
29
 import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
30
 import com.dmdirc.events.FrameIconChangedEvent;
31
 import com.dmdirc.events.FrameIconChangedEvent;
31
 import com.dmdirc.events.FrameNameChangedEvent;
32
 import com.dmdirc.events.FrameNameChangedEvent;
32
 import com.dmdirc.events.UnreadStatusChangedEvent;
33
 import com.dmdirc.events.UnreadStatusChangedEvent;
33
-import com.dmdirc.addons.ui_swing.components.IconManager;
34
 import com.dmdirc.ui.messages.Styliser;
34
 import com.dmdirc.ui.messages.Styliser;
35
-import com.dmdirc.util.colours.Colour;
36
-
37
 import java.awt.Color;
35
 import java.awt.Color;
38
 import java.awt.Font;
36
 import java.awt.Font;
39
-
40
 import javax.swing.JPanel;
37
 import javax.swing.JPanel;
41
 import javax.swing.JTextPane;
38
 import javax.swing.JTextPane;
42
 import javax.swing.UIManager;
39
 import javax.swing.UIManager;
43
 import javax.swing.text.DefaultStyledDocument;
40
 import javax.swing.text.DefaultStyledDocument;
44
 import javax.swing.text.StyledDocument;
41
 import javax.swing.text.StyledDocument;
45
-
46
-import net.miginfocom.swing.MigLayout;
47
-
48
 import net.engio.mbassy.listener.Handler;
42
 import net.engio.mbassy.listener.Handler;
43
+import net.miginfocom.swing.MigLayout;
49
 
44
 
50
 /**
45
 /**
51
  * Node label.
46
  * Node label.
68
     private final JTextPane text = new JTextPane(new DefaultStyledDocument());
63
     private final JTextPane text = new JTextPane(new DefaultStyledDocument());
69
     /** Icon manager. */
64
     /** Icon manager. */
70
     private final IconManager iconManager;
65
     private final IconManager iconManager;
66
+    /** Default foreground colour when there are no notifications. */
67
+    private Color defaultForegroundColour;
71
     /** Current styled text. */
68
     /** Current styled text. */
72
     private String currentText = "";
69
     private String currentText = "";
73
 
70
 
76
      *
73
      *
77
      * @param window Window for this node
74
      * @param window Window for this node
78
      */
75
      */
79
-    public NodeLabel(final TextFrame window, final IconManager iconManager) {
76
+    public NodeLabel(final TextFrame window, final IconManager iconManager, final Color defaultForegroundColour) {
80
         this.window = window;
77
         this.window = window;
81
         this.iconManager = iconManager;
78
         this.iconManager = iconManager;
79
+        this.defaultForegroundColour = defaultForegroundColour;
82
 
80
 
83
         init();
81
         init();
84
     }
82
     }
112
     }
110
     }
113
 
111
 
114
     public void unreadStatusChanged(final UnreadStatusChangedEvent event) {
112
     public void unreadStatusChanged(final UnreadStatusChangedEvent event) {
115
-        // TODO: Should this colour be configurable?
116
-        notificationColour = UIUtilities.convertColour(
117
-                event.getNotificationColour().orElse(Colour.BLACK));
113
+        notificationColour = event.getNotificationColour().map(UIUtilities::convertColour)
114
+                .orElse(defaultForegroundColour);
118
     }
115
     }
119
 
116
 
120
     @Handler
117
     @Handler
167
         return notificationColour;
164
         return notificationColour;
168
     }
165
     }
169
 
166
 
167
+    /**
168
+     * Sets the default foreground colour to use when no notification is present.
169
+     *
170
+     * @param defaultForegroundColour The default colour to use.
171
+     */
172
+    public void setDefaultForegroundColour(Color defaultForegroundColour) {
173
+        this.defaultForegroundColour = defaultForegroundColour;
174
+    }
175
+
170
     @Override
176
     @Override
171
     public Font getFont() {
177
     public Font getFont() {
172
         return UIManager.getFont("TextPane.font");
178
         return UIManager.getFont("TextPane.font");

+ 24
- 10
ui_swing/src/main/java/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java 查看文件

46
 import com.dmdirc.ui.WindowManager;
46
 import com.dmdirc.ui.WindowManager;
47
 import com.dmdirc.ui.messages.ColourManager;
47
 import com.dmdirc.ui.messages.ColourManager;
48
 import com.dmdirc.util.LogUtils;
48
 import com.dmdirc.util.LogUtils;
49
+import java.awt.Color;
49
 import java.awt.Rectangle;
50
 import java.awt.Rectangle;
50
 import java.awt.event.MouseEvent;
51
 import java.awt.event.MouseEvent;
51
 import java.io.Serializable;
52
 import java.io.Serializable;
212
      */
213
      */
213
     public void addWindow(final MutableTreeNode parent, final TextFrame window) {
214
     public void addWindow(final MutableTreeNode parent, final TextFrame window) {
214
         UIUtilities.invokeAndWait(() -> {
215
         UIUtilities.invokeAndWait(() -> {
215
-            final NodeLabel label = new NodeLabel(window, iconManager);
216
+            final NodeLabel label = new NodeLabel(window, iconManager, getForegroundColour());
216
             eventBus.subscribe(label);
217
             eventBus.subscribe(label);
217
             swingEventBus.subscribe(label);
218
             swingEventBus.subscribe(label);
218
             final TreeViewNode node = new TreeViewNode(label, window);
219
             final TreeViewNode node = new TreeViewNode(label, window);
231
                 tree.scrollRectToVisible(new Rectangle(0, (int) view.getY(), 0, 0));
232
                 tree.scrollRectToVisible(new Rectangle(0, (int) view.getY(), 0, 0));
232
             }
233
             }
233
 
234
 
234
-            node.getLabel().unreadStatusChanged(new UnreadStatusChangedEvent(
235
-                    window.getContainer(),
236
-                    window.getContainer().getUnreadStatusManager(),
237
-                    window.getContainer().getUnreadStatusManager().getNotificationColour(),
238
-                    window.getContainer().getUnreadStatusManager().getUnreadLines()));
235
+            refreshNodeLabel(window, node);
239
             node.getLabel().iconChanged(new FrameIconChangedEvent(window.getContainer(),
236
             node.getLabel().iconChanged(new FrameIconChangedEvent(window.getContainer(),
240
                     window.getContainer().getIcon()));
237
                     window.getContainer().getIcon()));
241
         });
238
         });
273
 
270
 
274
     /** Sets treeview colours. */
271
     /** Sets treeview colours. */
275
     private void setColours() {
272
     private void setColours() {
273
+        final Color foregroundColour = getForegroundColour();
274
+        tree.setForeground(foregroundColour);
276
         tree.setBackground(UIUtilities.convertColour(colourManager.getColourFromString(
275
         tree.setBackground(UIUtilities.convertColour(colourManager.getColourFromString(
277
                         config.getOptionString("treeview", "backgroundcolour", "ui",
276
                         config.getOptionString("treeview", "backgroundcolour", "ui",
278
                                 "backgroundcolour"), null)));
277
                                 "backgroundcolour"), null)));
279
-        tree.setForeground(UIUtilities.convertColour(colourManager.getColourFromString(
280
-                        config.getOptionString("treeview", "foregroundcolour", "ui",
281
-                                "foregroundcolour"), null)));
282
-
283
         tree.repaint();
278
         tree.repaint();
279
+
280
+        nodes.entrySet().forEach(pair -> {
281
+            pair.getValue().getLabel().setDefaultForegroundColour(foregroundColour);
282
+            refreshNodeLabel(pair.getKey(), pair.getValue());
283
+        });
284
+    }
285
+
286
+    private Color getForegroundColour() {
287
+        return UIUtilities.convertColour(colourManager.getColourFromString(
288
+                config.getOptionString("treeview", "foregroundcolour", "ui",
289
+                        "foregroundcolour"), null));
290
+    }
291
+
292
+    private void refreshNodeLabel(TextFrame window, TreeViewNode node) {
293
+        node.getLabel().unreadStatusChanged(new UnreadStatusChangedEvent(
294
+                window.getContainer(),
295
+                window.getContainer().getUnreadStatusManager(),
296
+                window.getContainer().getUnreadStatusManager().getNotificationColour(),
297
+                window.getContainer().getUnreadStatusManager().getUnreadLines()));
284
     }
298
     }
285
 
299
 
286
     @Override
300
     @Override

Loading…
取消
儲存