瀏覽代碼

General tidying of the frame managers.

pull/63/head
Greg Holmes 9 年之前
父節點
當前提交
9e7c559395

+ 4
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java 查看文件

@@ -398,13 +398,13 @@ public final class ButtonBar implements FrameManager, ActionListener, ComponentL
398 398
             @Override
399 399
             public void run() {
400 400
                 activeWindow = window;
401
-                FrameToggleButton button = getButton(selected);
402
-                if (selected != null && button != null) {
403
-                    button.setSelected(false);
401
+                final FrameToggleButton selectedButton = getButton(selected);
402
+                if (selected != null && selectedButton != null) {
403
+                    selectedButton.setSelected(false);
404 404
                 }
405 405
 
406 406
                 selected = window.getContainer();
407
-                button = getButton(window.getContainer());
407
+                final FrameToggleButton button = getButton(window.getContainer());
408 408
                 if (button != null) {
409 409
                     scrollPane.getViewport().scrollRectToVisible(
410 410
                             button.getBounds());

+ 3
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/Tree.java 查看文件

@@ -44,6 +44,7 @@ import javax.swing.JPopupMenu;
44 44
 import javax.swing.JTree;
45 45
 import javax.swing.UIManager;
46 46
 import javax.swing.tree.DefaultTreeModel;
47
+import javax.swing.tree.MutableTreeNode;
47 48
 import javax.swing.tree.TreeModel;
48 49
 import javax.swing.tree.TreePath;
49 50
 import javax.swing.tree.TreeSelectionModel;
@@ -307,11 +308,11 @@ public class Tree extends JTree implements MouseMotionListener,
307 308
                 windowFactory.getSwingWindow(node.getWindow()).setPopout(false);
308 309
                 break;
309 310
         }
310
-        final TreeViewNode parentNode = (TreeViewNode) node.getParent();
311
+        final MutableTreeNode parentNode = (MutableTreeNode) node.getParent();
311 312
         final TreePath nodePath = new TreePath(node.getPath());
312 313
         final boolean isExpanded = isExpanded(nodePath);
313 314
         ((DefaultTreeModel) getModel()).removeNodeFromParent(node);
314
-        ((TreeViewModel) getModel()).insertNodeInto(node, parentNode, index);
315
+        ((DefaultTreeModel) getModel()).insertNodeInto(node, parentNode, index);
315 316
         setExpandedState(nodePath, isExpanded);
316 317
     }
317 318
 

+ 7
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java 查看文件

@@ -60,9 +60,11 @@ import javax.inject.Inject;
60 60
 import javax.swing.JComponent;
61 61
 import javax.swing.JScrollPane;
62 62
 import javax.swing.JTree;
63
+import javax.swing.ScrollPaneConstants;
63 64
 import javax.swing.SwingUtilities;
64 65
 import javax.swing.tree.DefaultMutableTreeNode;
65 66
 import javax.swing.tree.DefaultTreeModel;
67
+import javax.swing.tree.MutableTreeNode;
66 68
 import javax.swing.tree.TreeNode;
67 69
 import javax.swing.tree.TreePath;
68 70
 
@@ -167,7 +169,8 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
167 169
             public void run() {
168 170
                 final JScrollPane scrollPane = new JScrollPane(tree);
169 171
                 scrollPane.setAutoscrolls(true);
170
-                scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
172
+                scrollPane.setHorizontalScrollBarPolicy(
173
+                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
171 174
 
172 175
                 parent.setVisible(false);
173 176
                 parent.setLayout(new MigLayout("ins 0, fill"));
@@ -212,7 +215,7 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
212 215
                 if (node.getLevel() == 0) {
213 216
                     eventBus.publishAsync(
214 217
                             new UserErrorEvent(ErrorLevel.MEDIUM, new IllegalArgumentException(),
215
-                                    "delServer triggered for root node" + node.toString(), ""));
218
+                                    "delServer triggered for root node" + node, ""));
216 219
                 } else {
217 220
                     model.removeNodeFromParent(nodes.get(window.getContainer()));
218 221
                 }
@@ -230,7 +233,7 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
230 233
      * @param parent Parent node
231 234
      * @param window Window to add
232 235
      */
233
-    public void addWindow(final TreeViewNode parent, final FrameContainer window) {
236
+    public void addWindow(final MutableTreeNode parent, final FrameContainer window) {
234 237
         UIUtilities.invokeAndWait(new Runnable() {
235 238
 
236 239
             @Override
@@ -345,7 +348,7 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
345 348
     @Override
346 349
     public void selectionChanged(final TextFrame window) {
347 350
         synchronized (nodes) {
348
-            final Collection<TreeViewNode> collection = new ArrayList<>(nodes.values());
351
+            final Iterable<TreeViewNode> collection = new ArrayList<>(nodes.values());
349 352
             for (TreeViewNode treeNode : collection) {
350 353
                 final NodeLabel label = treeNode.getLabel();
351 354
                 label.selectionChanged(window);

+ 14
- 25
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/FrameContainerMenu.java 查看文件

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
26 27
 import com.dmdirc.addons.ui_swing.SelectionListener;
27 28
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28 29
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
@@ -35,7 +36,7 @@ import java.awt.event.ActionEvent;
35 36
 import java.awt.event.ActionListener;
36 37
 
37 38
 import javax.swing.JMenu;
38
-import javax.swing.SwingUtilities;
39
+import javax.swing.UIManager;
39 40
 
40 41
 import net.engio.mbassy.listener.Handler;
41 42
 
@@ -76,35 +77,23 @@ public class FrameContainerMenu extends JMenu implements ActionListener, Selecti
76 77
         this.frame = frame;
77 78
 
78 79
         setIcon(frame.getIconManager().getIcon(frame.getIcon()));
79
-        new WindowMenuScroller(this, globalConfig, domain, 0);
80
+        WindowMenuScroller.createScroller(this, globalConfig, domain, 0);
80 81
 
81 82
         addActionListener(this);
82 83
     }
83 84
 
84
-    @Handler
85
+    @Handler(invocation = EdtHandlerInvocation.class)
85 86
     public void iconChanged(final FrameIconChangedEvent event) {
86
-        SwingUtilities.invokeLater(new Runnable() {
87
-
88
-            @Override
89
-            public void run() {
90
-                if (frame != null && window != null && frame.equals(window.getContainer())) {
91
-                    setIcon(window.getIconManager().getIcon(event.getIcon()));
92
-                }
93
-            }
94
-        });
87
+        if (frame != null && window != null && frame.equals(window.getContainer())) {
88
+            setIcon(window.getIconManager().getIcon(event.getIcon()));
89
+        }
95 90
     }
96 91
 
97
-    @Handler
92
+    @Handler(invocation = EdtHandlerInvocation.class)
98 93
     public void nameChanged(final FrameNameChangedEvent event) {
99
-        SwingUtilities.invokeLater(new Runnable() {
100
-
101
-            @Override
102
-            public void run() {
103
-                if (frame != null && window != null && frame.equals(window.getContainer())) {
104
-                    setText(event.getName());
105
-                }
106
-            }
107
-        });
94
+        if (frame != null && window != null && frame.equals(window.getContainer())) {
95
+            setText(event.getName());
96
+        }
108 97
     }
109 98
 
110 99
     @Override
@@ -115,9 +104,9 @@ public class FrameContainerMenu extends JMenu implements ActionListener, Selecti
115 104
     @Override
116 105
     public void selectionChanged(final TextFrame window) {
117 106
         if (frame.equals(window.getContainer())) {
118
-            setFont(getFont().deriveFont(Font.BOLD));
107
+            setFont(UIManager.getFont("Menu.font").deriveFont(Font.BOLD));
119 108
         } else {
120
-            setFont(getFont().deriveFont(Font.PLAIN));
109
+            setFont(UIManager.getFont("Menu.font").deriveFont(Font.PLAIN));
121 110
         }
122 111
     }
123 112
 
@@ -125,7 +114,7 @@ public class FrameContainerMenu extends JMenu implements ActionListener, Selecti
125 114
      * Informs this menu one of its children is selected.
126 115
      */
127 116
     protected void childSelected() {
128
-        setFont(getFont().deriveFont(Font.ITALIC));
117
+        setFont(UIManager.getFont("Menu.font").deriveFont(Font.ITALIC));
129 118
     }
130 119
 
131 120
     @Override

+ 12
- 23
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/FrameContainerMenuItem.java 查看文件

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
26 27
 import com.dmdirc.addons.ui_swing.SelectionListener;
27 28
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28 29
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
@@ -37,7 +38,7 @@ import java.awt.event.ActionEvent;
37 38
 import java.awt.event.ActionListener;
38 39
 
39 40
 import javax.swing.JMenuItem;
40
-import javax.swing.SwingUtilities;
41
+import javax.swing.UIManager;
41 42
 
42 43
 import net.engio.mbassy.listener.Handler;
43 44
 
@@ -81,30 +82,18 @@ public class FrameContainerMenuItem extends JMenuItem implements ActionListener,
81 82
         addActionListener(this);
82 83
     }
83 84
 
84
-    @Handler
85
+    @Handler(invocation = EdtHandlerInvocation.class)
85 86
     public void iconChanged(final FrameIconChangedEvent event) {
86
-        SwingUtilities.invokeLater(new Runnable() {
87
-
88
-            @Override
89
-            public void run() {
90
-                if (frame != null && window != null && frame.equals(window.getContainer())) {
91
-                    setIcon(window.getIconManager().getIcon(event.getIcon()));
92
-                }
93
-            }
94
-        });
87
+        if (frame != null && window != null && frame.equals(window.getContainer())) {
88
+            setIcon(window.getIconManager().getIcon(event.getIcon()));
89
+        }
95 90
     }
96 91
 
97
-    @Handler
92
+    @Handler(invocation = EdtHandlerInvocation.class)
98 93
     public void nameChanged(final FrameNameChangedEvent event) {
99
-        SwingUtilities.invokeLater(new Runnable() {
100
-
101
-            @Override
102
-            public void run() {
103
-                if (frame != null && window != null && frame.equals(window.getContainer())) {
104
-                    setText(Styliser.stipControlCodes(event.getName()));
105
-                }
106
-            }
107
-        });
94
+        if (frame != null && window != null && frame.equals(window.getContainer())) {
95
+            setText(Styliser.stipControlCodes(event.getName()));
96
+        }
108 97
     }
109 98
 
110 99
     @Override
@@ -115,13 +104,13 @@ public class FrameContainerMenuItem extends JMenuItem implements ActionListener,
115 104
     @Override
116 105
     public void selectionChanged(final TextFrame window) {
117 106
         if (frame.equals(window.getContainer())) {
118
-            setFont(getFont().deriveFont(Font.BOLD));
107
+            setFont(UIManager.getFont("MenuItem.font").deriveFont(Font.BOLD));
119 108
             final Optional<FrameContainer> parentWindow = window.getContainer().getParent();
120 109
             if (parentWindow.isPresent()) {
121 110
                 manager.parentSelection(parentWindow.get());
122 111
             }
123 112
         } else {
124
-            setFont(getFont().deriveFont(Font.PLAIN));
113
+            setFont(UIManager.getFont("MenuItem.font").deriveFont(Font.PLAIN));
125 114
         }
126 115
     }
127 116
 

+ 1
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuFrameManager.java 查看文件

@@ -139,7 +139,7 @@ public class WindowMenuFrameManager extends JMenu implements ActionListener, Sel
139 139
 
140 140
         activeFrameManager.addSelectionListener(this);
141 141
 
142
-        new WindowMenuScroller(this, globalConfig, domain, itemCount);
142
+        WindowMenuScroller.createScroller(this, globalConfig, domain, itemCount);
143 143
         checkMenuItems();
144 144
     }
145 145
 

+ 16
- 9
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuScroller.java 查看文件

@@ -54,23 +54,30 @@ public class WindowMenuScroller implements ConfigChangeListener {
54 54
      * @param configDomain Domain to check config settings in
55 55
      * @param fixedCount   Number of fixed items in the menu
56 56
      */
57
-    public WindowMenuScroller(final JMenu menu, final AggregateConfigProvider config,
57
+    private WindowMenuScroller(final JMenu menu, final AggregateConfigProvider config,
58 58
             final String configDomain, final int fixedCount) {
59 59
         this.menu = menu;
60 60
         this.config = config;
61 61
         this.configDomain = configDomain;
62 62
         this.fixedCount = fixedCount;
63
+    }
64
+
65
+    private void init() {
63 66
         this.scroller = new MenuScroller(menu,
64
-                config.getOptionInt(configDomain,
65
-                        "windowMenuItems"),
66
-                config.getOptionInt(configDomain,
67
-                        "windowMenuScrollInterval"), fixedCount, 0);
67
+                config.getOptionInt(configDomain,"windowMenuItems"),
68
+                config.getOptionInt(configDomain, "windowMenuScrollInterval"), fixedCount, 0);
68 69
         scroller.setShowSeperators(false);
69 70
 
70
-        config.addChangeListener(configDomain,
71
-                "windowMenuItems", this);
72
-        config.addChangeListener(configDomain,
73
-                "windowMenuScrollInterval", this);
71
+        config.addChangeListener(configDomain, "windowMenuItems", this);
72
+        config.addChangeListener(configDomain, "windowMenuScrollInterval", this);
73
+    }
74
+
75
+    /**
76
+     * Creates a menu scroller and attaches it to the menu.
77
+     */
78
+    public static void createScroller(final JMenu menu, final AggregateConfigProvider config,
79
+            final String configDomain, final int fixedCount) {
80
+        new WindowMenuScroller(menu, config, configDomain, fixedCount).init();
74 81
     }
75 82
 
76 83
     @Override

Loading…
取消
儲存