Browse Source

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 years ago
parent
commit
f13dbdb988

+ 19
- 17
src/com/dmdirc/addons/ui_swing/MainFrame.java View File

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

+ 2
- 2
src/com/dmdirc/addons/ui_swing/SwingController.java View File

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

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

173
             @Override
173
             @Override
174
             public void run() {
174
             public void run() {
175
                 ButtonBar.this.parent = parent;
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
                 parent.addComponentListener(ButtonBar.this);
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 View File

27
 import com.dmdirc.config.IdentityManager;
27
 import com.dmdirc.config.IdentityManager;
28
 import com.dmdirc.interfaces.ConfigChangeListener;
28
 import com.dmdirc.interfaces.ConfigChangeListener;
29
 import com.dmdirc.addons.ui_swing.actions.CloseFrameContainerAction;
29
 import com.dmdirc.addons.ui_swing.actions.CloseFrameContainerAction;
30
-import com.dmdirc.addons.ui_swing.components.TreeScroller;
31
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
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
 import java.awt.Rectangle;
32
 import java.awt.Rectangle;
36
 import java.awt.event.ActionEvent;
33
 import java.awt.event.ActionEvent;
101
                 (int) PlatformDefaults.getUnitValueX("related").getValue(),
98
                 (int) PlatformDefaults.getUnitValueX("related").getValue(),
102
                 (int) PlatformDefaults.getUnitValueX("related").getValue(),
99
                 (int) PlatformDefaults.getUnitValueX("related").getValue(),
103
                 (int) PlatformDefaults.getUnitValueX("related").getValue()));
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
         setFocusable(false);
101
         setFocusable(false);
130
 
102
 
131
         dragSelect = IdentityManager.getGlobalConfig().getOptionBool("treeview",
103
         dragSelect = IdentityManager.getGlobalConfig().getOptionBool("treeview",
237
             dragButton = true;
209
             dragButton = true;
238
             final TreePath selectedPath = getPathForLocation(e.getX(), e.getY());
210
             final TreePath selectedPath = getPathForLocation(e.getX(), e.getY());
239
             if (selectedPath != null) {
211
             if (selectedPath != null) {
240
-                ((TreeViewNode) selectedPath.getLastPathComponent()).
241
-                        getWindow().activateFrame();
212
+                ((TreeViewNode) selectedPath.getLastPathComponent()).getWindow().
213
+                        activateFrame();
242
             }
214
             }
243
         }
215
         }
244
         processMouseEvents(e);
216
         processMouseEvents(e);
285
             if (e.isPopupTrigger()) {
257
             if (e.isPopupTrigger()) {
286
                 TextFrame frame = null;
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
                 if (frame == null) {
263
                 if (frame == null) {
292
                     return;
264
                     return;
347
         ((TreeViewModel) getModel()).insertNodeInto(node, parentNode, index);
319
         ((TreeViewModel) getModel()).insertNodeInto(node, parentNode, index);
348
         setExpandedState(nodePath, isExpanded);
320
         setExpandedState(nodePath, isExpanded);
349
     }
321
     }
350
-}
322
+}

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

33
 import com.dmdirc.logger.Logger;
33
 import com.dmdirc.logger.Logger;
34
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
34
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
35
 import com.dmdirc.addons.ui_swing.UIUtilities;
35
 import com.dmdirc.addons.ui_swing.UIUtilities;
36
+import com.dmdirc.addons.ui_swing.components.TreeScroller;
36
 import com.dmdirc.ui.WindowManager;
37
 import com.dmdirc.ui.WindowManager;
37
 import com.dmdirc.ui.interfaces.UIController;
38
 import com.dmdirc.ui.interfaces.UIController;
38
 import com.dmdirc.ui.interfaces.Window;
39
 import com.dmdirc.ui.interfaces.Window;
109
                 scrollPane.setHorizontalScrollBarPolicy(
110
                 scrollPane.setHorizontalScrollBarPolicy(
110
                         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
111
                         JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
111
 
112
 
113
+
114
+                parent.setVisible(false);
112
                 parent.setLayout(new MigLayout("ins 0, fill"));
115
                 parent.setLayout(new MigLayout("ins 0, fill"));
113
                 parent.add(scrollPane, "grow");
116
                 parent.add(scrollPane, "grow");
114
                 parent.setFocusable(false);
117
                 parent.setFocusable(false);
118
+                parent.setVisible(true);
115
 
119
 
116
                 setColours();
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
             @Override
142
             @Override
133
             public void run() {
143
             public void run() {
134
                 model = new TreeViewModel(new TreeViewNode(null, null));
144
                 model = new TreeViewModel(new TreeViewNode(null, null));
135
-                tree = new Tree(TreeFrameManager.this, model, 
145
+                tree = new Tree(TreeFrameManager.this, model,
136
                         TreeFrameManager.this.controller.getWindowFactory());
146
                         TreeFrameManager.this.controller.getWindowFactory());
137
 
147
 
138
                 tree.setCellRenderer(new TreeViewTreeCellRenderer(
148
                 tree.setCellRenderer(new TreeViewTreeCellRenderer(
178
                         nodes.get(window.getContainer());
188
                         nodes.get(window.getContainer());
179
                 if (node.getLevel() == 0) {
189
                 if (node.getLevel() == 0) {
180
                     Logger.appError(ErrorLevel.MEDIUM,
190
                     Logger.appError(ErrorLevel.MEDIUM,
181
-                            "delServer triggered for root node" +
182
-                            node.toString(),
191
+                            "delServer triggered for root node"
192
+                            + node.toString(),
183
                             new IllegalArgumentException());
193
                             new IllegalArgumentException());
184
                 } else {
194
                 } else {
185
                     model.removeNodeFromParent(nodes.get(window.getContainer()));
195
                     model.removeNodeFromParent(nodes.get(window.getContainer()));
187
                 synchronized (nodes) {
197
                 synchronized (nodes) {
188
                     nodes.remove(window.getContainer());
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
 
265
 
253
         if (event == null) {
266
         if (event == null) {
254
             node = null;
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
             node =
270
             node =
258
                     tree.getNodeForLocation(event.getX(), event.getY()).getLabel();
271
                     tree.getNodeForLocation(event.getX(), event.getY()).getLabel();
259
         }
272
         }
301
                 ((DefaultTreeModel) tree.getModel()).setRoot(null);
314
                 ((DefaultTreeModel) tree.getModel()).setRoot(null);
302
                 ((DefaultTreeModel) tree.getModel()).setRoot(new TreeViewNode(
315
                 ((DefaultTreeModel) tree.getModel()).setRoot(new TreeViewNode(
303
                         null, null));
316
                         null, null));
317
+                new TreeTreeScroller(tree);
304
 
318
 
305
                 for (FrameContainer<?> window : WindowManager.getRootWindows()) {
319
                 for (FrameContainer<?> window : WindowManager.getRootWindows()) {
306
                     addWindow(null, window);
320
                     addWindow(null, window);
307
-                    final Collection<FrameContainer<?>> childWindows = window.getChildren();
321
+                    final Collection<FrameContainer<?>> childWindows = window.
322
+                            getChildren();
308
                     for (FrameContainer childWindow : childWindows) {
323
                     for (FrameContainer childWindow : childWindows) {
309
                         addWindow(nodes.get(window), childWindow);
324
                         addWindow(nodes.get(window), childWindow);
310
                     }
325
                     }

+ 71
- 0
src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeTreeScroller.java View File

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
+}

Loading…
Cancel
Save