Sfoglia il codice sorgente

Mouse scrolling of buttonbar works the same as the treeview.

issue 4062

Change-Id: I70082e47c387462e656a566e72ee390cba331770
Reviewed-on: http://gerrit.dmdirc.com/1199
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Simon Mott 14 anni fa
parent
commit
e969295b10

+ 18
- 8
src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java Vedi File

@@ -140,6 +140,7 @@ public final class ButtonBar implements FrameManager, ActionListener,
140 140
             buttonPanel = new ButtonPanel(new MigLayout("ins rel, fill, flowy"),
141 141
                     this);
142 142
         }
143
+        scrollPane.getViewport().addMouseWheelListener(buttonPanel);
143 144
         scrollPane.getViewport().add(buttonPanel);
144 145
     }
145 146
 
@@ -154,6 +155,15 @@ public final class ButtonBar implements FrameManager, ActionListener,
154 155
         return buttonHeight;
155 156
     }
156 157
 
158
+    /**
159
+     * Returns the button object of the current selected window
160
+     *
161
+     * @return Button object for the current selected window
162
+     */
163
+    public FrameToggleButton getSelectedButton() {
164
+        return getButton(selected);
165
+    }
166
+
157 167
     /** {@inheritDoc} */
158 168
     @Override
159 169
     public void setParent(final JComponent parent) {
@@ -163,10 +173,8 @@ public final class ButtonBar implements FrameManager, ActionListener,
163 173
             @Override
164 174
             public void run() {
165 175
                 ButtonBar.this.parent = parent;
166
-                scrollPane.setSize(parent.getWidth(), parent.getHeight());
167
-
168
-                parent.setLayout(new MigLayout("ins 0"));
169
-                parent.add(scrollPane);
176
+                parent.setLayout(new MigLayout("ins 0, fill"));
177
+                parent.add(scrollPane, "top, left");
170 178
                 parent.addComponentListener(ButtonBar.this);
171 179
             }
172 180
         });
@@ -219,8 +227,8 @@ public final class ButtonBar implements FrameManager, ActionListener,
219 227
                             buttonWidth, buttonHeight));
220 228
                 buttonPanel.add(button);
221 229
                 if (!window.getChildren().isEmpty()) {
222
-                    final ArrayList childList = new ArrayList<FrameContainer<?>>(
223
-                            window.getChildren());
230
+                    final ArrayList<FrameContainer<?>> childList = new ArrayList
231
+                            <FrameContainer<?>>(window.getChildren());
224 232
                     if (sortChildWindows) {
225 233
                          Collections.sort(childList, new FrameContainerComparator());
226 234
                     }
@@ -237,8 +245,8 @@ public final class ButtonBar implements FrameManager, ActionListener,
237 245
         buttonPanel.setVisible(false);
238 246
         buttonPanel.removeAll();
239 247
 
240
-        final ArrayList windowList = new ArrayList<FrameContainer<?>>(
241
-                WindowManager.getRootWindows());
248
+        final ArrayList<FrameContainer<?>> windowList = new
249
+                ArrayList<FrameContainer<?>>(WindowManager.getRootWindows());
242 250
         if (sortRootWindows) {
243 251
             Collections.sort(windowList, new FrameContainerComparator());
244 252
         }
@@ -419,6 +427,7 @@ public final class ButtonBar implements FrameManager, ActionListener,
419 427
                 selected = window;
420 428
                 button = getButton(window);
421 429
                 if (button != null) {
430
+                    scrollPane.getViewport().scrollRectToVisible(button.getBounds());
422 431
                     button.setSelected(true);
423 432
                 }
424 433
             }
@@ -534,6 +543,7 @@ public final class ButtonBar implements FrameManager, ActionListener,
534 543
         //Do nothing
535 544
     }
536 545
 
546
+    /** {@inheritDoc} */
537 547
     @Override
538 548
     public void configChanged(String domain, String key) {
539 549
         if ("sortrootwindows".equals(key)) {

+ 42
- 1
src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonPanel.java Vedi File

@@ -22,9 +22,13 @@
22 22
  */
23 23
 package com.dmdirc.addons.ui_swing.framemanager.buttonbar;
24 24
 
25
+import java.awt.Component;
25 26
 import java.awt.Dimension;
26 27
 import java.awt.Rectangle;
27 28
 
29
+import java.awt.event.MouseWheelEvent;
30
+import java.awt.event.MouseWheelListener;
31
+
28 32
 import javax.swing.JPanel;
29 33
 import javax.swing.Scrollable;
30 34
 
@@ -36,7 +40,7 @@ import net.miginfocom.swing.MigLayout;
36 40
  * @author Simon Mott
37 41
  * @since 0.6.4
38 42
  */
39
-public class ButtonPanel extends JPanel implements Scrollable {
43
+public class ButtonPanel extends JPanel implements Scrollable, MouseWheelListener {
40 44
 
41 45
     /**
42 46
      * A version number for this class. It should be changed whenever the class
@@ -88,4 +92,41 @@ public class ButtonPanel extends JPanel implements Scrollable {
88 92
         return false;
89 93
     }
90 94
 
95
+    /** {@inheritDoc} */
96
+    @Override
97
+    public void mouseWheelMoved(MouseWheelEvent e) {
98
+        e.consume();
99
+        final int selectedIndex = getSelectedIndex();
100
+        int newIndex = 0;
101
+        if (e.getWheelRotation() < 0) {
102
+            //Up
103
+            newIndex = selectedIndex > 0 ? selectedIndex - 1 :
104
+                getComponentCount() - 1;
105
+        } else if (e.getWheelRotation() > 0) {
106
+            //Down
107
+            newIndex = (selectedIndex + 1) % getComponentCount();
108
+        }
109
+        ((FrameToggleButton) getComponent(newIndex)).getWindow().activateFrame();
110
+    }
111
+
112
+    /**
113
+     * Gets the component index of the button associated with the current
114
+     * selected window.
115
+     *
116
+     * @return Integer Index for the button of the selected window
117
+     *
118
+     * @since 0.6.4
119
+     */
120
+    private int getSelectedIndex() {
121
+        int selectedIndex = 0;
122
+        final FrameToggleButton selectedButton = buttonBar.getSelectedButton();
123
+        for (Component c : getComponents()) {
124
+            if (c == selectedButton) {
125
+                break;
126
+            }
127
+            selectedIndex++;
128
+        }
129
+        return selectedIndex;
130
+    }
131
+
91 132
 }

Loading…
Annulla
Salva