Browse Source

General tidying of the frame managers.

pull/63/head
Greg Holmes 9 years ago
parent
commit
0ec9c71d1e

+ 1
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java View File

@@ -307,7 +307,7 @@ public final class ButtonBar implements FrameManager, ActionListener, ComponentL
307 307
         final FrameToggleButton button = new FrameToggleButton(
308 308
                 source.getContainer().getName(),
309 309
                 source.getContainer().getIconManager().getIcon(source.getContainer().getIcon()),
310
-                (TextFrame) source, source.getContainer());
310
+                (TextFrame) source);
311 311
         button.addActionListener(this);
312 312
         button.addMouseListener(this);
313 313
         button.setHorizontalAlignment(SwingConstants.LEFT);

+ 5
- 8
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonPanel.java View File

@@ -26,6 +26,7 @@ import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
26 26
 
27 27
 import java.awt.Component;
28 28
 import java.awt.Dimension;
29
+import java.awt.LayoutManager;
29 30
 import java.awt.Rectangle;
30 31
 import java.awt.event.MouseWheelEvent;
31 32
 import java.awt.event.MouseWheelListener;
@@ -33,13 +34,10 @@ import java.awt.event.MouseWheelListener;
33 34
 import javax.swing.JPanel;
34 35
 import javax.swing.Scrollable;
35 36
 
36
-import net.miginfocom.swing.MigLayout;
37
-
38 37
 /**
39 38
  * Implements scrollable onto a JPanel so we have more control over scrolling.
40 39
  */
41
-public class ButtonPanel extends JPanel implements Scrollable,
42
-        MouseWheelListener {
40
+public class ButtonPanel extends JPanel implements Scrollable, MouseWheelListener {
43 41
 
44 42
     /** A version number for this class. */
45 43
     private static final long serialVersionUID = 1;
@@ -55,7 +53,7 @@ public class ButtonPanel extends JPanel implements Scrollable,
55 53
      * @param layout             Layout settings for this ButtonPanel
56 54
      * @param buttonBar          the buttonBar that created this Panel
57 55
      */
58
-    public ButtonPanel(final ActiveFrameManager activeFrameManager, final MigLayout layout,
56
+    public ButtonPanel(final ActiveFrameManager activeFrameManager, final LayoutManager layout,
59 57
             final ButtonBar buttonBar) {
60 58
         super(layout);
61 59
 
@@ -65,7 +63,7 @@ public class ButtonPanel extends JPanel implements Scrollable,
65 63
 
66 64
     @Override
67 65
     public Dimension getPreferredScrollableViewportSize() {
68
-        return super.getPreferredSize();
66
+        return getPreferredSize();
69 67
     }
70 68
 
71 69
     @Override
@@ -97,8 +95,7 @@ public class ButtonPanel extends JPanel implements Scrollable,
97 95
         int newIndex = 0;
98 96
         if (e.getWheelRotation() < 0) {
99 97
             //Up
100
-            newIndex = selectedIndex > 0 ? selectedIndex - 1
101
-                    : getComponentCount() - 1;
98
+            newIndex = selectedIndex > 0 ? selectedIndex - 1 : getComponentCount() - 1;
102 99
         } else if (e.getWheelRotation() > 0) {
103 100
             //Down
104 101
             newIndex = (selectedIndex + 1) % getComponentCount();

+ 1
- 16
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/FrameToggleButton.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.framemanager.buttonbar;
24 24
 
25
-import com.dmdirc.FrameContainer;
26 25
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27 26
 
28 27
 import javax.swing.Icon;
@@ -38,8 +37,6 @@ public class FrameToggleButton extends JToggleButton {
38 37
     private static final long serialVersionUID = 1;
39 38
     /** Contains the window associated with this button. */
40 39
     private final TextFrame textFrame;
41
-    /** The frame container associated with this button. */
42
-    private final FrameContainer frameContainer;
43 40
 
44 41
     /**
45 42
      * Create a new instance of FrameToggleButton.
@@ -47,13 +44,10 @@ public class FrameToggleButton extends JToggleButton {
47 44
      * @param text           Text to show
48 45
      * @param icon           Icon to show
49 46
      * @param textFrame      Text frame
50
-     * @param frameContainer Associated frame container
51 47
      */
52
-    public FrameToggleButton(final String text, final Icon icon, final TextFrame textFrame,
53
-            final FrameContainer frameContainer) {
48
+    public FrameToggleButton(final String text, final Icon icon, final TextFrame textFrame) {
54 49
         super(text, icon);
55 50
         this.textFrame = textFrame;
56
-        this.frameContainer = frameContainer;
57 51
     }
58 52
 
59 53
     /**
@@ -65,13 +59,4 @@ public class FrameToggleButton extends JToggleButton {
65 59
         return textFrame;
66 60
     }
67 61
 
68
-    /**
69
-     * Returns the FrameContainer associated with this button.
70
-     *
71
-     * @return FrameContainer associated with this button
72
-     */
73
-    public FrameContainer getFrameContainer() {
74
-        return frameContainer;
75
-    }
76
-
77 62
 }

+ 18
- 13
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/ctrltab/CtrlTabWindowManager.java View File

@@ -42,12 +42,14 @@ import com.dmdirc.interfaces.config.AggregateConfigProvider;
42 42
 import com.dmdirc.interfaces.ui.Window;
43 43
 import com.dmdirc.logger.ErrorLevel;
44 44
 
45
+import java.awt.event.InputEvent;
45 46
 import java.awt.event.KeyEvent;
46 47
 import java.util.HashMap;
47 48
 import java.util.Map;
48 49
 
49 50
 import javax.inject.Inject;
50 51
 import javax.inject.Singleton;
52
+import javax.swing.InputMap;
51 53
 import javax.swing.JComponent;
52 54
 import javax.swing.KeyStroke;
53 55
 import javax.swing.tree.DefaultTreeSelectionModel;
@@ -106,17 +108,21 @@ public class CtrlTabWindowManager implements SelectionListener {
106 108
 
107 109
         activeFrameManager.addSelectionListener(this);
108 110
 
109
-        mainFrame.getRootPane().getActionMap().put("prevFrameAction",
110
-                new PreviousFrameAction(treeScroller));
111
-        mainFrame.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
112
-                .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
113
-                                KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK),
114
-                        "prevFrameAction");
115
-        mainFrame.getRootPane().getActionMap().put(
116
-                "nextFrameAction", new NextFrameAction(treeScroller));
117
-        mainFrame.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
118
-                .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
119
-                                KeyEvent.CTRL_DOWN_MASK), "nextFrameAction");
111
+        if (mainFrame.getRootPane().getActionMap() != null) {
112
+            mainFrame.getRootPane().getActionMap()
113
+                    .put("prevFrameAction", new PreviousFrameAction(treeScroller));
114
+            mainFrame.getRootPane().getActionMap()
115
+                    .put("nextFrameAction", new NextFrameAction(treeScroller));
116
+        }
117
+        final InputMap ancestorFocusedMap = mainFrame.getRootPane().getInputMap(
118
+                JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
119
+        if (ancestorFocusedMap != null) {
120
+            ancestorFocusedMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
121
+                    InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK), "prevFrameAction");
122
+            ancestorFocusedMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
123
+                    InputEvent.CTRL_DOWN_MASK),
124
+                    "nextFrameAction");
125
+        }
120 126
     }
121 127
 
122 128
     @Handler
@@ -158,7 +164,7 @@ public class CtrlTabWindowManager implements SelectionListener {
158 164
                 if (node.getLevel() == 0) {
159 165
                     eventBus.publishAsync(new UserErrorEvent(ErrorLevel.MEDIUM,
160 166
                             new IllegalArgumentException(),
161
-                            "delServer triggered for root node" + node.toString(), ""));
167
+                            "delServer triggered for root node" + node, ""));
162 168
                 } else {
163 169
                     model.removeNodeFromParent(nodes.get(window));
164 170
                 }
@@ -177,7 +183,6 @@ public class CtrlTabWindowManager implements SelectionListener {
177 183
         treeScroller.changeFocus(false);
178 184
     }
179 185
 
180
-    /* {@inheritDoc} */
181 186
     @Override
182 187
     public void selectionChanged(final TextFrame window) {
183 188
         UIUtilities.invokeLater(new Runnable() {

+ 4
- 51
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/NodeLabel.java View File

@@ -29,7 +29,6 @@ import com.dmdirc.addons.ui_swing.components.ImageButton;
29 29
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
30 30
 import com.dmdirc.events.FrameIconChangedEvent;
31 31
 import com.dmdirc.events.FrameNameChangedEvent;
32
-import com.dmdirc.events.NotificationClearedEvent;
33 32
 import com.dmdirc.events.NotificationSetEvent;
34 33
 import com.dmdirc.ui.messages.Styliser;
35 34
 
@@ -103,27 +102,27 @@ public class NodeLabel extends JPanel implements SelectionListener {
103 102
 
104 103
     @Override
105 104
     public void selectionChanged(final TextFrame window) {
106
-        selected = equals(window.getContainer());
105
+        selected = this.window.equals(window.getContainer());
107 106
     }
108 107
 
109 108
     public void notificationSet(final NotificationSetEvent event) {
110 109
             notificationColour = UIUtilities.convertColour(event.getColour());
111 110
     }
112 111
 
113
-    public void notificationCleared(final NotificationClearedEvent event) {
112
+    public void notificationCleared() {
114 113
             notificationColour = null;
115 114
     }
116 115
 
117 116
     @Handler
118 117
     public void iconChanged(final FrameIconChangedEvent event) {
119
-        if (equals(event.getContainer())) {
118
+        if (window.equals(event.getContainer())) {
120 119
             icon.setIcon(window.getIconManager().getIcon(event.getIcon()));
121 120
         }
122 121
     }
123 122
 
124 123
     @Handler
125 124
     public void nameChanged(final FrameNameChangedEvent event) {
126
-        if (equals(event.getContainer())) {
125
+        if (window.equals(event.getContainer())) {
127 126
             text.setText(event.getName());
128 127
         }
129 128
     }
@@ -164,15 +163,6 @@ public class NodeLabel extends JPanel implements SelectionListener {
164 163
         return notificationColour;
165 164
     }
166 165
 
167
-    @Override
168
-    public boolean equals(final Object obj) {
169
-        if (window == null) {
170
-            return false;
171
-        }
172
-
173
-        return window.equals(obj);
174
-    }
175
-
176 166
     @Override
177 167
     public int hashCode() {
178 168
         if (window == null) {
@@ -187,11 +177,6 @@ public class NodeLabel extends JPanel implements SelectionListener {
187 177
         return UIManager.getFont("TextPane.font");
188 178
     }
189 179
 
190
-    /**
191
-     * Sets the foreground colour for this label.
192
-     *
193
-     * @param colour New foreground colour
194
-     */
195 180
     @Override
196 181
     public void setForeground(final Color colour) {
197 182
         if (text != null) {
@@ -199,11 +184,6 @@ public class NodeLabel extends JPanel implements SelectionListener {
199 184
         }
200 185
     }
201 186
 
202
-    /**
203
-     * Sets the background colour for this label.
204
-     *
205
-     * @param colour New background colour
206
-     */
207 187
     @Override
208 188
     public void setBackground(final Color colour) {
209 189
         if (text != null) {
@@ -211,11 +191,6 @@ public class NodeLabel extends JPanel implements SelectionListener {
211 191
         }
212 192
     }
213 193
 
214
-    /**
215
-     * Sets the font for this label.
216
-     *
217
-     * @param font New font
218
-     */
219 194
     @Override
220 195
     public void setFont(final Font font) {
221 196
         if (text != null) {
@@ -223,11 +198,6 @@ public class NodeLabel extends JPanel implements SelectionListener {
223 198
         }
224 199
     }
225 200
 
226
-    /**
227
-     * Sets the opacity of this label.
228
-     *
229
-     * @param opacity Desired opacity
230
-     */
231 201
     @Override
232 202
     public void setOpaque(final boolean opacity) {
233 203
         if (text != null) {
@@ -235,23 +205,6 @@ public class NodeLabel extends JPanel implements SelectionListener {
235 205
         }
236 206
     }
237 207
 
238
-    /**
239
-     * Sets the text and style in this label.
240
-     *
241
-     * @param styliser   Styliser to use to style text
242
-     * @param styledText Styled text string to use
243
-     */
244
-    public void setStyledText(final Styliser styliser,
245
-            final String styledText) {
246
-        if (currentText.equals(styledText)) {
247
-            return;
248
-        }
249
-        text.setText("");
250
-        currentText = styledText;
251
-        styliser.addStyledString((StyledDocument) text.getDocument(),
252
-                new String[]{styledText,});
253
-    }
254
-
255 208
     /**
256 209
      * Sets the styles for the text in this label.
257 210
      *

+ 4
- 3
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/Tree.java View File

@@ -43,6 +43,7 @@ import javax.swing.JMenuItem;
43 43
 import javax.swing.JPopupMenu;
44 44
 import javax.swing.JTree;
45 45
 import javax.swing.UIManager;
46
+import javax.swing.tree.DefaultTreeModel;
46 47
 import javax.swing.tree.TreeModel;
47 48
 import javax.swing.tree.TreePath;
48 49
 import javax.swing.tree.TreeSelectionModel;
@@ -235,7 +236,7 @@ public class Tree extends JTree implements MouseMotionListener,
235 236
      *
236 237
      * @param e mouse event
237 238
      */
238
-    public void processMouseEvents(final MouseEvent e) {
239
+    void processMouseEvents(final MouseEvent e) {
239 240
         final TreePath localPath = getPathForLocation(e.getX(), e.getY());
240 241
         if (localPath != null && e.isPopupTrigger()) {
241 242
             final TextFrame frame = windowFactory.getSwingWindow(
@@ -293,7 +294,7 @@ public class Tree extends JTree implements MouseMotionListener,
293 294
                 }
294 295
                 break;
295 296
             case "Down":
296
-                if (index == (node.getSiblingCount() - 1)) {
297
+                if (index == node.getSiblingCount() - 1) {
297 298
                     index = 0;
298 299
                 } else {
299 300
                     index++;
@@ -309,7 +310,7 @@ public class Tree extends JTree implements MouseMotionListener,
309 310
         final TreeViewNode parentNode = (TreeViewNode) node.getParent();
310 311
         final TreePath nodePath = new TreePath(node.getPath());
311 312
         final boolean isExpanded = isExpanded(nodePath);
312
-        ((TreeViewModel) getModel()).removeNodeFromParent(node);
313
+        ((DefaultTreeModel) getModel()).removeNodeFromParent(node);
313 314
         ((TreeViewModel) getModel()).insertNodeInto(node, parentNode, index);
314 315
         setExpandedState(nodePath, isExpanded);
315 316
     }

+ 1
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java View File

@@ -390,7 +390,7 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
390 390
             if (event.getWindow() != null && node != null) {
391 391
                 final NodeLabel label = node.getLabel();
392 392
                 if (label != null) {
393
-                    label.notificationCleared(event);
393
+                    label.notificationCleared();
394 394
                     tree.repaint();
395 395
                 }
396 396
             }

+ 10
- 27
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeViewModel.java View File

@@ -27,6 +27,8 @@ import com.dmdirc.GlobalWindow;
27 27
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
28 28
 
29 29
 import javax.swing.tree.DefaultTreeModel;
30
+import javax.swing.tree.MutableTreeNode;
31
+import javax.swing.tree.TreeNode;
30 32
 
31 33
 /**
32 34
  * A simple sorted tree data model based on DefaultTreeModel.
@@ -46,9 +48,7 @@ public class TreeViewModel extends DefaultTreeModel {
46 48
      * @param globalConfig The configuration provider to read settings from.
47 49
      * @param root         a TreeNode object that is the root of the tree.
48 50
      */
49
-    public TreeViewModel(
50
-            final AggregateConfigProvider globalConfig,
51
-            final TreeViewNode root) {
51
+    public TreeViewModel(final AggregateConfigProvider globalConfig, final TreeNode root) {
52 52
         super(root, false);
53 53
 
54 54
         this.globalConfig = globalConfig;
@@ -61,23 +61,8 @@ public class TreeViewModel extends DefaultTreeModel {
61 61
      * @param newChild child to be added.
62 62
      * @param parent   parent child is to be added too.
63 63
      */
64
-    public final void insertNodeInto(final TreeViewNode newChild,
65
-            final TreeViewNode parent) {
66
-        final int index;
67
-        index = getIndex(newChild, parent);
68
-        insertNodeInto(newChild, parent, index);
69
-    }
70
-
71
-    /**
72
-     * Inserts a new node into the tree and fires the appropriate events.
73
-     *
74
-     * @param newChild child to be added.
75
-     * @param parent   parent child is to be added too.
76
-     * @param index    Index of item to add
77
-     */
78
-    public final void insertNodeInto(final TreeViewNode newChild,
79
-            final TreeViewNode parent, final int index) {
80
-        super.insertNodeInto(newChild, parent, index);
64
+    public final void insertNodeInto(final TreeViewNode newChild, final MutableTreeNode parent) {
65
+        insertNodeInto(newChild, parent, getIndex(newChild, parent));
81 66
     }
82 67
 
83 68
     /**
@@ -89,7 +74,7 @@ public class TreeViewModel extends DefaultTreeModel {
89 74
      *
90 75
      * @return index where new node is to be inserted.
91 76
      */
92
-    private int getIndex(final TreeViewNode newChild, final TreeViewNode parent) {
77
+    private int getIndex(final TreeViewNode newChild, final TreeNode parent) {
93 78
         if (newChild.getWindow() instanceof GlobalWindow) {
94 79
             return 0;
95 80
         }
@@ -101,12 +86,10 @@ public class TreeViewModel extends DefaultTreeModel {
101 86
         if (globalConfig.getOptionBool("ui", "sortchildwindows")) {
102 87
             for (int i = 0; i < parent.getChildCount(); i++) {
103 88
                 final TreeViewNode child = (TreeViewNode) parent.getChildAt(i);
104
-                if (sortBefore(newChild, child)) {
105
-                    return i;
106
-                } else if (!sortAfter(newChild, child) && newChild.
107
-                        getUserObject().
108
-                        toString().compareToIgnoreCase(child.getUserObject().
109
-                                toString()) < 0) {
89
+                if (sortBefore(newChild, child)
90
+                        || !sortAfter(newChild, child)
91
+                        && newChild.getUserObject().toString().compareToIgnoreCase(
92
+                        child.getUserObject().toString()) < 0) {
110 93
                     return i;
111 94
                 }
112 95
             }

+ 1
- 10
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeViewNodeMenuItem.java View File

@@ -32,7 +32,7 @@ public class TreeViewNodeMenuItem extends JMenuItem {
32 32
     /** A version number for this class. */
33 33
     private static final long serialVersionUID = 1;
34 34
     /** Tree view node. */
35
-    private TreeViewNode treeNode;
35
+    private final TreeViewNode treeNode;
36 36
 
37 37
     /**
38 38
      * Creates a new treeviewnodemenuitem.
@@ -58,13 +58,4 @@ public class TreeViewNodeMenuItem extends JMenuItem {
58 58
         return treeNode;
59 59
     }
60 60
 
61
-    /**
62
-     * Set the value of treeNode.
63
-     *
64
-     * @param treeNode new value of treeNode
65
-     */
66
-    public void setTreeNode(final TreeViewNode treeNode) {
67
-        this.treeNode = treeNode;
68
-    }
69
-
70 61
 }

+ 1
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeViewTreeCellRenderer.java View File

@@ -110,7 +110,6 @@ public class TreeViewTreeCellRenderer implements TreeCellRenderer,
110 110
         if (label == null) {
111 111
             return new JLabel("Label == null");
112 112
         }
113
-        final boolean bold;
114 113
         Color background = tree.getBackground();
115 114
         Color foreground = tree.getForeground();
116 115
 
@@ -123,6 +122,7 @@ public class TreeViewTreeCellRenderer implements TreeCellRenderer,
123 122
             foreground = colour;
124 123
         }
125 124
 
125
+        final boolean bold;
126 126
         if (label.isSelected()) {
127 127
             bold = activeBold;
128 128
             if (!tree.getBackground().equals(activeBackground)) {

+ 4
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/WindowMenuFrameManager.java View File

@@ -46,6 +46,7 @@ import java.awt.event.ActionListener;
46 46
 import java.util.ArrayList;
47 47
 import java.util.Collection;
48 48
 import java.util.Collections;
49
+import java.util.Comparator;
49 50
 import java.util.HashMap;
50 51
 import java.util.Map;
51 52
 import java.util.concurrent.Callable;
@@ -70,7 +71,7 @@ public class WindowMenuFrameManager extends JMenu implements ActionListener, Sel
70 71
     /** A version number for this class. */
71 72
     private static final long serialVersionUID = 1;
72 73
     /** Comparator. */
73
-    private final FrameContainerComparator comparator = new FrameContainerComparator();
74
+    private final Comparator<FrameContainer> comparator = new FrameContainerComparator();
74 75
     /** Non frame container menu count. */
75 76
     private final int itemCount;
76 77
     /** Menu items closing the active window. */
@@ -388,9 +389,8 @@ public class WindowMenuFrameManager extends JMenu implements ActionListener, Sel
388 389
                 continue;
389 390
             }
390 391
             final FrameContainer child = ((FrameContainerMenuInterface) component).getFrame();
391
-            if (sortBefore(newChild, child)) {
392
-                return i;
393
-            } else if (!sortAfter(newChild, child)
392
+            if (sortBefore(newChild, child)
393
+                    || !sortAfter(newChild, child)
394 394
                     && globalConfig.getOptionBool("treeview", "sortwindows")
395 395
                     && newChild.getName().compareToIgnoreCase(child.getName()) < 0) {
396 396
                 return i;

Loading…
Cancel
Save