Browse Source

Adds some window arrangement options for MDI mode.

Fixes issue CLIENT-20

Change-Id: Ib36a2434ccee62e44894e7f6c6e49917247fcdb8
Reviewed-on: http://gerrit.dmdirc.com/1536
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: Greg Holmes <greg@dmdirc.com>
tags/0.6.5
Greg Holmes 13 years ago
parent
commit
338ab10219

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

@@ -259,7 +259,7 @@ public final class MainFrame extends JFrame implements WindowListener,
259 259
      *
260 260
      * @return JDesktopPane for the frame
261 261
      */
262
-    public JDesktopPane getDesktopPane() {
262
+    public DMDircDesktopPane getDesktopPane() {
263 263
         return desktopPane;
264 264
     }
265 265
 

+ 70
- 0
src/com/dmdirc/addons/ui_swing/components/desktopPane/DMDircDesktopPane.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.components.desktopPane;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
+import com.dmdirc.FrameContainerComparator;
26 27
 import com.dmdirc.addons.ui_swing.BackgroundOption;
27 28
 import com.dmdirc.addons.ui_swing.MainFrame;
28 29
 import com.dmdirc.addons.ui_swing.SwingController;
@@ -33,6 +34,7 @@ import com.dmdirc.addons.ui_swing.components.frames.InputTextFrame;
33 34
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
34 35
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewModel;
35 36
 import com.dmdirc.addons.ui_swing.framemanager.tree.TreeViewNode;
37
+import com.dmdirc.addons.ui_swing.framemanager.windowmenu.JInternalFrameComparator;
36 38
 import com.dmdirc.config.IdentityManager;
37 39
 import com.dmdirc.interfaces.ConfigChangeListener;
38 40
 import com.dmdirc.interfaces.SelectionListener;
@@ -200,6 +202,74 @@ public class DMDircDesktopPane extends JDesktopPane implements
200 202
         yOffset += FRAME_OPENING_OFFSET;
201 203
     }
202 204
 
205
+    /**
206
+     * Arranges the windows in the specified number of rows and columns.
207
+     *
208
+     * @param windows Windows to arranges
209
+     * @param columns Number of columns to use
210
+     * @param rows Number of rows to use
211
+     */
212
+    private void tileWindows(final JInternalFrame[] windows, final int columns,
213
+            final int rows) {
214
+        ((TextFrame) windows[0]).restore();
215
+        final int total = windows.length;
216
+        final int windowWidth = getWidth() / columns;
217
+        final int windowHeight = getHeight() / rows;
218
+
219
+        int column = 0;
220
+        int x = 0;
221
+        int y = 0;
222
+        for (int i = 0; i < total; i++) {
223
+            windows[i].setBounds(x, y, windowWidth, windowHeight);
224
+            column++;
225
+            x += windowWidth;
226
+            if (column >= columns) {
227
+                column = 0;
228
+                x = 0;
229
+                y += windowHeight;
230
+            }
231
+        }
232
+    }
233
+
234
+    /**
235
+     * Arranges the windows to be equal size in a grid.
236
+     */
237
+    public void tileWindows() {
238
+        if (getAllFrames().length == 0) {
239
+            return;
240
+        }
241
+        final JInternalFrame[] windows = getAllFrames();
242
+        Arrays.sort(windows, new JInternalFrameComparator());
243
+        final int total = windows.length;
244
+        final int columns = (int) Math.floor(Math.sqrt(total));
245
+        final int rows = (int) (Math.ceil(((double) total) / columns));
246
+        tileWindows(windows, columns, rows);
247
+    }
248
+
249
+    /**
250
+     * Arranges the windows to be equal size in a horizontal row.
251
+     */
252
+    public void tileHorizontally() {
253
+        if (getAllFrames().length == 0) {
254
+            return;
255
+        }
256
+        final JInternalFrame[] windows = getAllFrames();
257
+        Arrays.sort(windows, new JInternalFrameComparator());
258
+        tileWindows(windows, 1, windows.length);
259
+    }
260
+
261
+    /**
262
+     * Arranges the windows to be equal size in a vertical row.
263
+     */
264
+    public void tileVertically() {
265
+        if (getAllFrames().length == 0) {
266
+            return;
267
+        }
268
+        final JInternalFrame[] windows = getAllFrames();
269
+        Arrays.sort(windows, new JInternalFrameComparator());
270
+        tileWindows(windows, windows.length, 1);
271
+    }
272
+
203 273
     /**
204 274
      * Returns the select window.
205 275
      *

+ 99
- 0
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/ArrangeWindows.java View File

@@ -0,0 +1,99 @@
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.windowmenu;
24
+
25
+import com.dmdirc.addons.ui_swing.SwingController;
26
+import com.dmdirc.ui.IconManager;
27
+
28
+import java.awt.event.ActionEvent;
29
+import java.awt.event.ActionListener;
30
+
31
+import javax.swing.JMenu;
32
+import javax.swing.JMenuItem;
33
+
34
+/**
35
+ * Menu to add window arrangement options.
36
+ */
37
+public class ArrangeWindows extends JMenu implements ActionListener {
38
+    /**
39
+     * A version number for this class. It should be changed whenever the class
40
+     * structure is changed (or anything else that would prevent serialized
41
+     * objects being unserialized with the new class).
42
+     */
43
+    private static final long serialVersionUID = 1;
44
+    /** Menu items for tiling grid, vertical, horizontal. */
45
+    private final JMenuItem grid, vertical, horizontal;
46
+    /** Desktop pane. */
47
+    private SwingController controller;
48
+
49
+    /**
50
+     * Creates a new arrange windows menu.  Provides options to arrange windows
51
+     * in a grid, tile vertically and tile horizontally.
52
+     *
53
+     * @param controller Swing controller to request mainframe/desktop pane.
54
+     */
55
+    public ArrangeWindows(final SwingController controller) {
56
+        super();
57
+
58
+        this.controller = controller;
59
+
60
+        setIcon(IconManager.getIconManager().getIcon("dmdirc"));
61
+        setMnemonic('a');
62
+        setText("Arrange Windows");
63
+
64
+        grid = new JMenuItem(IconManager.getIconManager().getIcon("dmdirc"));
65
+        grid.setMnemonic('g');
66
+        grid.setText("Arrange in grid");
67
+        grid.setActionCommand("grid");
68
+        grid.addActionListener(this);
69
+        add(grid);
70
+
71
+        horizontal = new JMenuItem(IconManager.getIconManager().getIcon(
72
+                "dmdirc"));
73
+        horizontal.setMnemonic('h');
74
+        horizontal.setText("Arrange horizontally");
75
+        horizontal.setActionCommand("horizontal");
76
+        horizontal.addActionListener(this);
77
+        add(horizontal);
78
+
79
+        vertical = new JMenuItem(IconManager.getIconManager().getIcon(
80
+                "dmdirc"));
81
+        vertical.setMnemonic('v');
82
+        vertical.setText("Arrange vertically");
83
+        vertical.setActionCommand("vertical");
84
+        vertical.addActionListener(this);
85
+        add(vertical);
86
+    }
87
+
88
+    /** {@inheritDoc} */
89
+    @Override
90
+    public void actionPerformed(final ActionEvent e) {
91
+        if (e.getActionCommand().equals("grid")) {
92
+            controller.getMainFrame().getDesktopPane().tileWindows();
93
+        } else if (e.getActionCommand().equals("horizontally")) {
94
+            controller.getMainFrame().getDesktopPane().tileHorizontally();
95
+        } else if (e.getActionCommand().equals("verticallt")) {
96
+            controller.getMainFrame().getDesktopPane().tileVertically();
97
+        }
98
+    }
99
+}

+ 66
- 0
src/com/dmdirc/addons/ui_swing/framemanager/windowmenu/JInternalFrameComparator.java View File

@@ -0,0 +1,66 @@
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.windowmenu;
24
+
25
+import com.dmdirc.FrameContainerComparator;
26
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27
+
28
+import java.io.Serializable;
29
+import java.util.Comparator;
30
+
31
+import javax.swing.JInternalFrame;
32
+
33
+/**
34
+ * A comparator that proxies JInternalFrame arrays to a Frame container
35
+ * comparator if appropriate.
36
+ */
37
+public class JInternalFrameComparator implements Comparator<JInternalFrame>,
38
+        Serializable {
39
+
40
+    /**
41
+     * A version number for this class. It should be changed whenever the class
42
+     * structure is changed (or anything else that would prevent serialized
43
+     * objects being unserialized with the new class).
44
+     */
45
+    private static final long serialVersionUID = 1;
46
+    /** Comparator to proxy compares to. */
47
+    private final FrameContainerComparator comparator =
48
+            new FrameContainerComparator();
49
+
50
+    /**
51
+     * Compares two frame containers names.
52
+     *
53
+     * @param item1 The first container to compare
54
+     * @param item2 The second container to compare
55
+     * @return -1 if item1 is before item2, 0 if they're equal,
56
+     * +1 if item1 is after item2.
57
+     */
58
+    @Override
59
+    public int compare(final JInternalFrame item1, final JInternalFrame item2) {
60
+        if (!(item1 instanceof TextFrame) || (!(item2 instanceof TextFrame))) {
61
+            return 0;
62
+        }
63
+        return comparator.compare(((TextFrame) item1).getContainer(),
64
+                ((TextFrame) item2).getContainer());
65
+    }
66
+}

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

@@ -69,7 +69,8 @@ public final class WindowMenuFrameManager extends JMenu implements
69 69
     /** Non frame container menu count. */
70 70
     private final int itemCount;
71 71
     /** Menu items for toggling, closing and minimising. */
72
-    private final JMenuItem toggleStateMenuItem, closeMenuItem, minimiseMenuItem;
72
+    private final JMenuItem toggleStateMenuItem, closeMenuItem,
73
+            minimiseMenuItem;
73 74
     /** Seperator. */
74 75
     private final JSeparator separator;
75 76
     /** Active window. */
@@ -83,7 +84,7 @@ public final class WindowMenuFrameManager extends JMenu implements
83 84
     private final Map<FrameContainer, FrameContainerMenuItem> items;
84 85
     private final Map<FrameContainer, FrameContainerMenuItem> menuItems;
85 86
 
86
-    /** 
87
+    /**
87 88
      * Creates a new instance of WindowMenuFrameManager.
88 89
      *
89 90
      * @param controller Swing controller
@@ -128,17 +129,19 @@ public final class WindowMenuFrameManager extends JMenu implements
128 129
         closeMenuItem.addActionListener(this);
129 130
         add(closeMenuItem);
130 131
 
132
+        add(new ArrangeWindows(controller));
133
+
131 134
         separator = new JPopupMenu.Separator();
132 135
         add(separator);
133 136
 
134 137
         itemCount = getMenuComponentCount();
135 138
         checkToggleState();
136 139
 
137
-        new WindowMenuScroller(this, controller.getDomain(), 4);
140
+        new WindowMenuScroller(this, controller.getDomain(), itemCount);
138 141
     }
139 142
 
140 143
     /**
141
-     * Checks the number of components in the menu and enables menus items 
144
+     * Checks the number of components in the menu and enables menus items
142 145
      * appropriately.
143 146
      */
144 147
     private void checkMenuItems() {
@@ -306,9 +309,9 @@ public final class WindowMenuFrameManager extends JMenu implements
306 309
         items.put(item.getFrame(), item);
307 310
     }
308 311
 
309
-    /** 
312
+    /**
310 313
      * {@inheritDoc}
311
-     * 
314
+     *
312 315
      * @param e Action event
313 316
      */
314 317
     @Override

Loading…
Cancel
Save