Sfoglia il codice sorgente

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 anni fa
parent
commit
db2d999190

+ 17
- 11
ui_swing/src/main/java/com/dmdirc/addons/ui_swing/framemanager/tree/NodeLabel.java Vedi File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.framemanager.tree;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.UIUtilities;
26
+import com.dmdirc.addons.ui_swing.components.IconManager;
26 27
 import com.dmdirc.addons.ui_swing.components.ImageButton;
27 28
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28 29
 import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
@@ -30,22 +31,16 @@ import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker;
30 31
 import com.dmdirc.events.FrameIconChangedEvent;
31 32
 import com.dmdirc.events.FrameNameChangedEvent;
32 33
 import com.dmdirc.events.UnreadStatusChangedEvent;
33
-import com.dmdirc.addons.ui_swing.components.IconManager;
34 34
 import com.dmdirc.ui.messages.Styliser;
35
-import com.dmdirc.util.colours.Colour;
36
-
37 35
 import java.awt.Color;
38 36
 import java.awt.Font;
39
-
40 37
 import javax.swing.JPanel;
41 38
 import javax.swing.JTextPane;
42 39
 import javax.swing.UIManager;
43 40
 import javax.swing.text.DefaultStyledDocument;
44 41
 import javax.swing.text.StyledDocument;
45
-
46
-import net.miginfocom.swing.MigLayout;
47
-
48 42
 import net.engio.mbassy.listener.Handler;
43
+import net.miginfocom.swing.MigLayout;
49 44
 
50 45
 /**
51 46
  * Node label.
@@ -68,6 +63,8 @@ public class NodeLabel extends JPanel {
68 63
     private final JTextPane text = new JTextPane(new DefaultStyledDocument());
69 64
     /** Icon manager. */
70 65
     private final IconManager iconManager;
66
+    /** Default foreground colour when there are no notifications. */
67
+    private Color defaultForegroundColour;
71 68
     /** Current styled text. */
72 69
     private String currentText = "";
73 70
 
@@ -76,9 +73,10 @@ public class NodeLabel extends JPanel {
76 73
      *
77 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 77
         this.window = window;
81 78
         this.iconManager = iconManager;
79
+        this.defaultForegroundColour = defaultForegroundColour;
82 80
 
83 81
         init();
84 82
     }
@@ -112,9 +110,8 @@ public class NodeLabel extends JPanel {
112 110
     }
113 111
 
114 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 117
     @Handler
@@ -167,6 +164,15 @@ public class NodeLabel extends JPanel {
167 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 176
     @Override
171 177
     public Font getFont() {
172 178
         return UIManager.getFont("TextPane.font");

+ 24
- 10
ui_swing/src/main/java/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java Vedi File

@@ -46,6 +46,7 @@ import com.dmdirc.plugins.PluginDomain;
46 46
 import com.dmdirc.ui.WindowManager;
47 47
 import com.dmdirc.ui.messages.ColourManager;
48 48
 import com.dmdirc.util.LogUtils;
49
+import java.awt.Color;
49 50
 import java.awt.Rectangle;
50 51
 import java.awt.event.MouseEvent;
51 52
 import java.io.Serializable;
@@ -212,7 +213,7 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
212 213
      */
213 214
     public void addWindow(final MutableTreeNode parent, final TextFrame window) {
214 215
         UIUtilities.invokeAndWait(() -> {
215
-            final NodeLabel label = new NodeLabel(window, iconManager);
216
+            final NodeLabel label = new NodeLabel(window, iconManager, getForegroundColour());
216 217
             eventBus.subscribe(label);
217 218
             swingEventBus.subscribe(label);
218 219
             final TreeViewNode node = new TreeViewNode(label, window);
@@ -231,11 +232,7 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
231 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 236
             node.getLabel().iconChanged(new FrameIconChangedEvent(window.getContainer(),
240 237
                     window.getContainer().getIcon()));
241 238
         });
@@ -273,14 +270,31 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
273 270
 
274 271
     /** Sets treeview colours. */
275 272
     private void setColours() {
273
+        final Color foregroundColour = getForegroundColour();
274
+        tree.setForeground(foregroundColour);
276 275
         tree.setBackground(UIUtilities.convertColour(colourManager.getColourFromString(
277 276
                         config.getOptionString("treeview", "backgroundcolour", "ui",
278 277
                                 "backgroundcolour"), null)));
279
-        tree.setForeground(UIUtilities.convertColour(colourManager.getColourFromString(
280
-                        config.getOptionString("treeview", "foregroundcolour", "ui",
281
-                                "foregroundcolour"), null)));
282
-
283 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 300
     @Override

Loading…
Annulla
Salva