Переглянути джерело

On the fly frame manager switching.

TreeView supports this, buttonbar has issues.

Fixes issue 4061

Change-Id: If1f254caac4455a0c0f730ea4885f73de62bebec
Reviewed-on: http://gerrit.dmdirc.com/1188
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.4
Greboid 14 роки тому
джерело
коміт
f13dbdb988

+ 19
- 17
src/com/dmdirc/addons/ui_swing/MainFrame.java Переглянути файл

@@ -100,6 +100,8 @@ public final class MainFrame extends JFrame implements WindowListener,
100 100
     private SwingStatusBar statusBar;
101 101
     /** Client Version. */
102 102
     private String version;
103
+    /** Main split pane. */
104
+    private SplitPane mainSplitPane;
103 105
 
104 106
     /**
105 107
      * Creates new form MainFrame.
@@ -113,8 +115,7 @@ public final class MainFrame extends JFrame implements WindowListener,
113 115
 
114 116
         initComponents();
115 117
 
116
-        imageIcon =
117
-                new ImageIcon(IconManager.getIconManager().getImage("icon"));
118
+        imageIcon = new ImageIcon(IconManager.getIconManager().getImage("icon"));
118 119
         setIconImage(imageIcon.getImage());
119 120
 
120 121
         CoreUIUtils.centreWindow(this);
@@ -129,6 +130,8 @@ public final class MainFrame extends JFrame implements WindowListener,
129 130
                 this);
130 131
         IdentityManager.getGlobalConfig().addChangeListener("ui", "showversion",
131 132
                 this);
133
+        IdentityManager.getGlobalConfig().addChangeListener("ui", "framemanager",
134
+                this);
132 135
         IdentityManager.getGlobalConfig().addChangeListener("icon", "icon", this);
133 136
 
134 137
 
@@ -351,6 +354,7 @@ public final class MainFrame extends JFrame implements WindowListener,
351 354
             /** {@inheritDoc} */
352 355
             @Override
353 356
             public void run() {
357
+                frameManagerPanel.removeAll();
354 358
                 final String manager = IdentityManager.getGlobalConfig().
355 359
                         getOption("ui", "framemanager");
356 360
                 try {
@@ -399,8 +403,8 @@ public final class MainFrame extends JFrame implements WindowListener,
399 403
     private void initComponents() {
400 404
         statusBar = new SwingStatusBar(controller, this);
401 405
         frameManagerPanel = new JPanel();
402
-        desktopPane = new DMDircDesktopPane(controller, this, controller.
403
-                getDomain());
406
+        desktopPane = new DMDircDesktopPane(controller, this, controller.getDomain());
407
+        mainSplitPane = new SplitPane(SplitPane.Orientation.HORIZONTAL);
404 408
 
405 409
         initFrameManagers();
406 410
 
@@ -412,7 +416,7 @@ public final class MainFrame extends JFrame implements WindowListener,
412 416
 
413 417
         getContentPane().setLayout(new MigLayout(
414 418
                 "fill, ins rel, wrap 1, hidemode 2"));
415
-        getContentPane().add(initSplitPane(), "grow, push");
419
+        getContentPane().add(initSplitPane(mainSplitPane), "grow, push");
416 420
         getContentPane().add(statusBar,
417 421
                 "hmax 20, wmax 100%-2*rel, wmin 100%-2*rel");
418 422
 
@@ -426,12 +430,9 @@ public final class MainFrame extends JFrame implements WindowListener,
426 430
      *
427 431
      * @return Returns the initialised split pane
428 432
      */
429
-    private JSplitPane initSplitPane() {
430
-        final JSplitPane mainSplitPane =
431
-                new SplitPane(SplitPane.Orientation.HORIZONTAL);
432
-        position =
433
-                FramemanagerPosition.getPosition(IdentityManager.getGlobalConfig().
434
-                getOption("ui", "framemanagerPosition"));
433
+    private JSplitPane initSplitPane(final SplitPane mainSplitPane) {
434
+        position = FramemanagerPosition.getPosition(IdentityManager
435
+                .getGlobalConfig().getOption("ui", "framemanagerPosition"));
435 436
 
436 437
         if (position == FramemanagerPosition.UNKNOWN) {
437 438
             position = FramemanagerPosition.LEFT;
@@ -455,8 +456,7 @@ public final class MainFrame extends JFrame implements WindowListener,
455 456
                 mainSplitPane.setResizeWeight(0.0);
456 457
                 mainSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
457 458
                 frameManagerPanel.setPreferredSize(new Dimension(
458
-                        Integer.MAX_VALUE,
459
-                        IdentityManager.getGlobalConfig().
459
+                        Integer.MAX_VALUE, IdentityManager.getGlobalConfig().
460 460
                         getOptionInt("ui", "frameManagerSize")));
461 461
                 break;
462 462
             case LEFT:
@@ -474,8 +474,7 @@ public final class MainFrame extends JFrame implements WindowListener,
474 474
                 mainSplitPane.setResizeWeight(1.0);
475 475
                 mainSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
476 476
                 frameManagerPanel.setPreferredSize(new Dimension(
477
-                        Integer.MAX_VALUE,
478
-                        IdentityManager.getGlobalConfig().
477
+                        Integer.MAX_VALUE, IdentityManager.getGlobalConfig().
479 478
                         getOptionInt("ui", "frameManagerSize")));
480 479
                 break;
481 480
             case RIGHT:
@@ -574,10 +573,13 @@ public final class MainFrame extends JFrame implements WindowListener,
574 573
         if ("ui".equals(domain)) {
575 574
             if ("lookandfeel".equals(key)) {
576 575
                 controller.updateLookAndFeel();
576
+            } else if ("framemanager".equals(key)) {
577
+                initFrameManagers();
578
+                initSplitPane(mainSplitPane);
579
+                frameManagerPanel.repaint();
577 580
             } else {
578 581
                 showVersion = IdentityManager.getGlobalConfig().getOptionBool(
579
-                        "ui",
580
-                        "showversion");
582
+                        "ui", "showversion");
581 583
             }
582 584
         } else {
583 585
             imageIcon = new ImageIcon(IconManager.getIconManager().getImage(

+ 2
- 2
src/com/dmdirc/addons/ui_swing/SwingController.java Переглянути файл

@@ -780,10 +780,10 @@ public class SwingController extends Plugin implements Serializable,
780 780
                 "Look and feel", "The Java look and feel to use", lafs));
781 781
         general.addSetting(new PreferencesSetting("ui", "framemanager",
782 782
                 "Window manager", "Which window manager should be used?",
783
-                framemanagers).setRestartNeeded());
783
+                framemanagers));
784 784
         general.addSetting(new PreferencesSetting("ui", "framemanagerPosition",
785 785
                 "Window manager position", "Where should the window "
786
-                + "manager be positioned?", fmpositions).setRestartNeeded());
786
+                + "manager be positioned?", fmpositions));
787 787
         general.addSetting(new PreferencesSetting(PreferencesType.FONT,
788 788
                 "ui", "textPaneFontName", "Textpane font",
789 789
                 "Font for the textpane"));

+ 7
- 2
src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java Переглянути файл

@@ -173,9 +173,14 @@ public final class ButtonBar implements FrameManager, ActionListener,
173 173
             @Override
174 174
             public void run() {
175 175
                 ButtonBar.this.parent = parent;
176
-                parent.setLayout(new MigLayout("ins 0, fill"));
177
-                parent.add(scrollPane, "top, left");
176
+                scrollPane.setSize(parent.getWidth(), parent.getHeight());
177
+
178
+                parent.setVisible(false);
179
+                parent.setLayout(new MigLayout("ins 0"));
180
+                parent.add(scrollPane);
178 181
                 parent.addComponentListener(ButtonBar.this);
182
+                parent.setVisible(true);
183
+                relayout();
179 184
             }
180 185
         });
181 186
     }

+ 5
- 33
src/com/dmdirc/addons/ui_swing/framemanager/tree/Tree.java Переглянути файл

@@ -27,10 +27,7 @@ import com.dmdirc.addons.ui_swing.UIUtilities;
27 27
 import com.dmdirc.config.IdentityManager;
28 28
 import com.dmdirc.interfaces.ConfigChangeListener;
29 29
 import com.dmdirc.addons.ui_swing.actions.CloseFrameContainerAction;
30
-import com.dmdirc.addons.ui_swing.components.TreeScroller;
31 30
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
32
-import com.dmdirc.logger.ErrorLevel;
33
-import com.dmdirc.logger.Logger;
34 31
 
35 32
 import java.awt.Rectangle;
36 33
 import java.awt.event.ActionEvent;
@@ -101,31 +98,6 @@ public class Tree extends JTree implements MouseMotionListener,
101 98
                 (int) PlatformDefaults.getUnitValueX("related").getValue(),
102 99
                 (int) PlatformDefaults.getUnitValueX("related").getValue(),
103 100
                 (int) PlatformDefaults.getUnitValueX("related").getValue()));
104
-        new TreeScroller(this) {
105
-
106
-            /** {@inheritDoc} */
107
-            @Override
108
-            protected void setPath(final TreePath path) {
109
-                if (path == null) {
110
-                    Logger.appError(ErrorLevel.HIGH, "Unable to change focus",
111
-                            new IllegalArgumentException("path == null"));
112
-                    return;
113
-                }
114
-                if (path.getLastPathComponent() == null) {
115
-                    Logger.appError(ErrorLevel.HIGH, "Unable to change focus",
116
-                            new IllegalArgumentException("Last component == null"));
117
-                    return;
118
-                }
119
-                if (((TreeViewNode) path.getLastPathComponent()).getWindow() == null) {
120
-                    Logger.appError(ErrorLevel.HIGH, "Unable to change focus",
121
-                            new IllegalArgumentException("Frame is null"));
122
-                    return;
123
-                }
124
-                super.setPath(path);
125
-                ((TreeViewNode) path.getLastPathComponent()).getWindow().
126
-                        activateFrame();
127
-            }
128
-        };
129 101
         setFocusable(false);
130 102
 
131 103
         dragSelect = IdentityManager.getGlobalConfig().getOptionBool("treeview",
@@ -237,8 +209,8 @@ public class Tree extends JTree implements MouseMotionListener,
237 209
             dragButton = true;
238 210
             final TreePath selectedPath = getPathForLocation(e.getX(), e.getY());
239 211
             if (selectedPath != null) {
240
-                ((TreeViewNode) selectedPath.getLastPathComponent()).
241
-                        getWindow().activateFrame();
212
+                ((TreeViewNode) selectedPath.getLastPathComponent()).getWindow().
213
+                        activateFrame();
242 214
             }
243 215
         }
244 216
         processMouseEvents(e);
@@ -285,8 +257,8 @@ public class Tree extends JTree implements MouseMotionListener,
285 257
             if (e.isPopupTrigger()) {
286 258
                 TextFrame frame = null;
287 259
 
288
-                frame = (TextFrame) controller.getSwingWindow(((TreeViewNode)
289
-                        localPath.getLastPathComponent()).getWindow());
260
+                frame = (TextFrame) controller.getSwingWindow(((TreeViewNode) localPath.
261
+                        getLastPathComponent()).getWindow());
290 262
 
291 263
                 if (frame == null) {
292 264
                     return;
@@ -347,4 +319,4 @@ public class Tree extends JTree implements MouseMotionListener,
347 319
         ((TreeViewModel) getModel()).insertNodeInto(node, parentNode, index);
348 320
         setExpandedState(nodePath, isExpanded);
349 321
     }
350
-}
322
+}

+ 24
- 9
src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java Переглянути файл

@@ -33,6 +33,7 @@ import com.dmdirc.logger.ErrorLevel;
33 33
 import com.dmdirc.logger.Logger;
34 34
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
35 35
 import com.dmdirc.addons.ui_swing.UIUtilities;
36
+import com.dmdirc.addons.ui_swing.components.TreeScroller;
36 37
 import com.dmdirc.ui.WindowManager;
37 38
 import com.dmdirc.ui.interfaces.UIController;
38 39
 import com.dmdirc.ui.interfaces.Window;
@@ -109,11 +110,20 @@ public final class TreeFrameManager implements FrameManager,
109 110
                 scrollPane.setHorizontalScrollBarPolicy(
110 111
                         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
111 112
 
113
+
114
+                parent.setVisible(false);
112 115
                 parent.setLayout(new MigLayout("ins 0, fill"));
113 116
                 parent.add(scrollPane, "grow");
114 117
                 parent.setFocusable(false);
118
+                parent.setVisible(true);
115 119
 
116 120
                 setColours();
121
+
122
+                redoTreeView();
123
+                if (controller.getMainFrame().getActiveFrame() != null) {
124
+                    selectionChanged(controller.getMainFrame().getActiveFrame().
125
+                            getContainer());
126
+                }
117 127
             }
118 128
         });
119 129
     }
@@ -132,7 +142,7 @@ public final class TreeFrameManager implements FrameManager,
132 142
             @Override
133 143
             public void run() {
134 144
                 model = new TreeViewModel(new TreeViewNode(null, null));
135
-                tree = new Tree(TreeFrameManager.this, model, 
145
+                tree = new Tree(TreeFrameManager.this, model,
136 146
                         TreeFrameManager.this.controller.getWindowFactory());
137 147
 
138 148
                 tree.setCellRenderer(new TreeViewTreeCellRenderer(
@@ -178,8 +188,8 @@ public final class TreeFrameManager implements FrameManager,
178 188
                         nodes.get(window.getContainer());
179 189
                 if (node.getLevel() == 0) {
180 190
                     Logger.appError(ErrorLevel.MEDIUM,
181
-                            "delServer triggered for root node" +
182
-                            node.toString(),
191
+                            "delServer triggered for root node"
192
+                            + node.toString(),
183 193
                             new IllegalArgumentException());
184 194
                 } else {
185 195
                     model.removeNodeFromParent(nodes.get(window.getContainer()));
@@ -187,9 +197,12 @@ public final class TreeFrameManager implements FrameManager,
187 197
                 synchronized (nodes) {
188 198
                     nodes.remove(window.getContainer());
189 199
                 }
190
-                window.getContainer().removeSelectionListener(TreeFrameManager.this);
191
-                window.getContainer().removeFrameInfoListener(TreeFrameManager.this);
192
-                window.getContainer().removeNotificationListener(TreeFrameManager.this);
200
+                window.getContainer().removeSelectionListener(
201
+                        TreeFrameManager.this);
202
+                window.getContainer().removeFrameInfoListener(
203
+                        TreeFrameManager.this);
204
+                window.getContainer().removeNotificationListener(
205
+                        TreeFrameManager.this);
193 206
             }
194 207
         });
195 208
     }
@@ -252,8 +265,8 @@ public final class TreeFrameManager implements FrameManager,
252 265
 
253 266
         if (event == null) {
254 267
             node = null;
255
-        } else if (tree.getNodeForLocation(event.getX(), event.getY()) !=
256
-                null) {
268
+        } else if (tree.getNodeForLocation(event.getX(), event.getY())
269
+                != null) {
257 270
             node =
258 271
                     tree.getNodeForLocation(event.getX(), event.getY()).getLabel();
259 272
         }
@@ -301,10 +314,12 @@ public final class TreeFrameManager implements FrameManager,
301 314
                 ((DefaultTreeModel) tree.getModel()).setRoot(null);
302 315
                 ((DefaultTreeModel) tree.getModel()).setRoot(new TreeViewNode(
303 316
                         null, null));
317
+                new TreeTreeScroller(tree);
304 318
 
305 319
                 for (FrameContainer<?> window : WindowManager.getRootWindows()) {
306 320
                     addWindow(null, window);
307
-                    final Collection<FrameContainer<?>> childWindows = window.getChildren();
321
+                    final Collection<FrameContainer<?>> childWindows = window.
322
+                            getChildren();
308 323
                     for (FrameContainer childWindow : childWindows) {
309 324
                         addWindow(nodes.get(window), childWindow);
310 325
                     }

+ 71
- 0
src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeTreeScroller.java Переглянути файл

@@ -0,0 +1,71 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ * 
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ * 
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.framemanager.tree;
24
+
25
+import com.dmdirc.addons.ui_swing.components.TreeScroller;
26
+import com.dmdirc.logger.ErrorLevel;
27
+import com.dmdirc.logger.Logger;
28
+import javax.swing.tree.TreePath;
29
+
30
+/**
31
+ * Extention of TreeScroller to scroll the tree view.
32
+ */
33
+public class TreeTreeScroller extends TreeScroller {
34
+
35
+    /**
36
+     * Creates a new Tree scroller for the tree view.
37
+     *
38
+     * @param tree Tree view tree
39
+     */
40
+    public TreeTreeScroller(final Tree tree) {
41
+        super(tree);
42
+    }
43
+
44
+    /** {@inheritDoc} */
45
+    @Override
46
+    protected void setPath(final TreePath path) {
47
+        if (path == null) {
48
+            Logger.appError(ErrorLevel.HIGH,
49
+                    "Unable to change focus",
50
+                    new IllegalArgumentException("path == null"));
51
+            return;
52
+        }
53
+        if (path.getLastPathComponent() == null) {
54
+            Logger.appError(ErrorLevel.HIGH,
55
+                    "Unable to change focus",
56
+                    new IllegalArgumentException(
57
+                    "Last component == null"));
58
+            return;
59
+        }
60
+        if (((TreeViewNode) path.getLastPathComponent()).getWindow()
61
+                == null) {
62
+            Logger.appError(ErrorLevel.HIGH,
63
+                    "Unable to change focus",
64
+                    new IllegalArgumentException("Frame is null"));
65
+            return;
66
+        }
67
+        super.setPath(path);
68
+        ((TreeViewNode) path.getLastPathComponent()).getWindow().
69
+                activateFrame();
70
+    }
71
+}

Завантаження…
Відмінити
Зберегти