Browse Source

Add generics to the statusbar popup panels.

Tidy up up status bar components.

Change-Id: I52ed05574ab06b819ddb33f8abc3d0048b20eba2
Reviewed-on: http://gerrit.dmdirc.com/1888
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.7rc1
Greg Holmes 13 years ago
parent
commit
af50cf856b

+ 4
- 2
src/com/dmdirc/addons/lagdisplay/LagDisplayPanel.java View File

@@ -24,11 +24,13 @@ package com.dmdirc.addons.lagdisplay;
24 24
 import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupPanel;
25 25
 import com.dmdirc.addons.ui_swing.components.statusbar.StatusbarPopupWindow;
26 26
 
27
+import javax.swing.JLabel;
28
+
27 29
 /**
28 30
  * Shows the user's lag in the status bar, and reveals details of all servers
29 31
  * when the user hovers over it.
30 32
  */
31
-public class LagDisplayPanel extends StatusbarPopupPanel {
33
+public class LagDisplayPanel extends StatusbarPopupPanel<JLabel> {
32 34
 
33 35
     /**
34 36
      * A version number for this class. It should be changed whenever the class
@@ -45,7 +47,7 @@ public class LagDisplayPanel extends StatusbarPopupPanel {
45 47
      * @param plugin The plugin that owns this panel
46 48
      */
47 49
     public LagDisplayPanel(final LagDisplayPlugin plugin) {
48
-        super();
50
+        super(new JLabel());
49 51
         
50 52
         this.plugin = plugin;
51 53
     }

+ 7
- 7
src/com/dmdirc/addons/lagdisplay/LagDisplayPlugin.java View File

@@ -174,7 +174,7 @@ public final class LagDisplayPlugin extends Plugin implements ActionListener, Co
174 174
             pings.put(((Server) arguments[0]), value);
175 175
 
176 176
             if (((Server) arguments[0]).isChild(active) || arguments[0] == active) {
177
-                panel.setText(value);
177
+                panel.getComponent().setText(value);
178 178
             }
179 179
 
180 180
             panel.refreshDialog();
@@ -185,7 +185,7 @@ public final class LagDisplayPlugin extends Plugin implements ActionListener, Co
185 185
             pings.put(((Server) arguments[0]), value);
186 186
 
187 187
             if (((Server) arguments[0]).isChild(active) || arguments[0] == active) {
188
-                panel.setText(value);
188
+                panel.getComponent().setText(value);
189 189
             }
190 190
 
191 191
             panel.refreshDialog();
@@ -193,7 +193,7 @@ public final class LagDisplayPlugin extends Plugin implements ActionListener, Co
193 193
             final FrameContainer active = WindowManager.getActiveWindow();
194 194
 
195 195
             if (((Server) arguments[0]).isChild(active) || arguments[0] == active) {
196
-                panel.setText("Not connected");
196
+                panel.getComponent().setText("Not connected");
197 197
                 pings.remove((Server) arguments[0]);
198 198
             }
199 199
 
@@ -201,11 +201,11 @@ public final class LagDisplayPlugin extends Plugin implements ActionListener, Co
201 201
         } else if (type.equals(CoreActionType.CLIENT_FRAME_CHANGED)) {
202 202
             final FrameContainer source = (FrameContainer) arguments[0];
203 203
             if (source == null || source.getServer() == null) {
204
-                panel.setText("Unknown");
204
+                panel.getComponent().setText("Unknown");
205 205
             } else if (source.getServer().getState() != ServerState.CONNECTED) {
206
-                panel.setText("Not connected");
206
+                panel.getComponent().setText("Not connected");
207 207
             } else {
208
-                panel.setText(getTime(source.getServer()));
208
+                panel.getComponent().setText(getTime(source.getServer()));
209 209
             }
210 210
 
211 211
             panel.refreshDialog();
@@ -224,7 +224,7 @@ public final class LagDisplayPlugin extends Plugin implements ActionListener, Co
224 224
                 getHistory(((Server) arguments[0])).add(duration);
225 225
 
226 226
                 if (((Server) arguments[0]).isChild(active) || arguments[0] == active) {
227
-                    panel.setText(value);
227
+                    panel.getComponent().setText(value);
228 228
                 }
229 229
             } catch (NumberFormatException ex) {
230 230
                 pings.remove((Server) arguments[0]);

+ 10
- 9
src/com/dmdirc/addons/ui_swing/components/statusbar/ErrorPanel.java View File

@@ -46,9 +46,9 @@ import javax.swing.SwingUtilities;
46 46
  * Shows error status in the status bar.
47 47
  *
48 48
  * @since 0.6.3m1
49
- * @author chris
50 49
  */
51
-public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, ActionListener {
50
+public class ErrorPanel extends StatusbarPopupPanel<JLabel> implements
51
+        ErrorListener, ActionListener {
52 52
 
53 53
     /**
54 54
      * A version number for this class. It should be changed whenever the class
@@ -60,12 +60,10 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
60 60
     /** non error state image icon. */
61 61
     private static final Icon DEFAULT_ICON = IconManager.getIconManager().
62 62
             getIcon("normal");
63
-    /** Currently showing error level. */
64
-    private ErrorLevel errorLevel;
65 63
     /** Status controller. */
66 64
     private final MainFrame mainFrame;
67 65
     /** Swing status bar. */
68
-    private SwingStatusBar statusBar;
66
+    private final SwingStatusBar statusBar;
69 67
     /** Error manager. */
70 68
     private final transient ErrorManager errorManager = ErrorManager.getErrorManager();
71 69
     /** Dismiss menu. */
@@ -75,14 +73,16 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
75 73
     /** Show menu item. */
76 74
     private final JMenuItem show;
77 75
     /** Swing controller. */
78
-    private SwingController controller;
76
+    private final SwingController controller;
77
+    /** Currently showing error level. */
78
+    private ErrorLevel errorLevel;
79 79
 
80 80
     /**
81 81
      * Creates a new ErrorPanel for the speicified status bar.
82 82
      *
83 83
      * @param controller Swing controller
84 84
      * @param mainFrame Main frame
85
-     * @param statusBar Status bar  
85
+     * @param statusBar Status bar
86 86
      */
87 87
     public ErrorPanel(final SwingController controller,
88 88
             final MainFrame mainFrame, final SwingStatusBar statusBar) {
@@ -91,7 +91,7 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
91 91
         this.controller = controller;
92 92
         this.mainFrame = mainFrame;
93 93
         this.statusBar = statusBar;
94
-        
94
+
95 95
         menu = new JPopupMenu();
96 96
         dismiss = new JMenuItem("Clear All");
97 97
         show = new JMenuItem("Open");
@@ -152,7 +152,8 @@ public class ErrorPanel extends StatusbarPopupPanel implements ErrorListener, Ac
152 152
                         if (errorLevel == null ||
153 153
                                 !error.getLevel().moreImportant(errorLevel)) {
154 154
                             errorLevel = error.getLevel();
155
-                            label.setIcon(IconManager.getIconManager().getIcon(errorLevel.getIcon()));
155
+                            label.setIcon(IconManager.getIconManager()
156
+                                    .getIcon(errorLevel.getIcon()));
156 157
                         }
157 158
                     }
158 159
                     setVisible(true);

+ 10
- 7
src/com/dmdirc/addons/ui_swing/components/statusbar/ErrorPopup.java View File

@@ -41,7 +41,6 @@ import javax.swing.JSeparator;
41 41
  * Shows a breakdown of errors that have occured.
42 42
  *
43 43
  * @since 0.6.3m1
44
- * @author chris
45 44
  */
46 45
 public class ErrorPopup extends StatusbarPopupWindow {
47 46
 
@@ -65,8 +64,10 @@ public class ErrorPopup extends StatusbarPopupWindow {
65 64
     /** {@inheritDoc} */
66 65
     @Override
67 66
     protected void initContent(final JPanel panel) {
68
-        final List<ProgramError> errors = ErrorManager.getErrorManager().getErrors();
69
-        final MapList<ErrorLevel, ProgramError> buckets = new MapList<ErrorLevel, ProgramError>();
67
+        final List<ProgramError> errors = ErrorManager.getErrorManager()
68
+                .getErrors();
69
+        final MapList<ErrorLevel, ProgramError> buckets
70
+                = new MapList<ErrorLevel, ProgramError>();
70 71
         final MapList<ErrorReportStatus, ProgramError> statuses
71 72
                 = new MapList<ErrorReportStatus, ProgramError>();
72 73
 
@@ -88,8 +89,10 @@ public class ErrorPopup extends StatusbarPopupWindow {
88 89
                 final int count = buckets.values(level).size();
89 90
 
90 91
                 panel.add(new JLabel(level.toString(),
91
-                        IconManager.getIconManager().getIcon(level.getIcon()), JLabel.LEFT));
92
-                panel.add(new JLabel(String.valueOf(count), JLabel.RIGHT), "growx, pushx, wrap");
92
+                        IconManager.getIconManager().getIcon(level.getIcon()),
93
+                        JLabel.LEFT));
94
+                panel.add(new JLabel(String.valueOf(count), JLabel.RIGHT),
95
+                        "growx, pushx, wrap");
93 96
             }
94 97
         }
95 98
 
@@ -108,9 +111,9 @@ public class ErrorPopup extends StatusbarPopupWindow {
108 111
                 final int count = statuses.values(status).size();
109 112
 
110 113
                 panel.add(new JLabel(status.toString(), JLabel.LEFT));
111
-                panel.add(new JLabel(String.valueOf(count), JLabel.RIGHT), "growx, pushx, wrap");
114
+                panel.add(new JLabel(String.valueOf(count), JLabel.RIGHT),
115
+                        "growx, pushx, wrap");
112 116
             }
113 117
         }
114 118
     }
115
-
116 119
 }

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/statusbar/InviteLabel.java View File

@@ -49,7 +49,7 @@ import javax.swing.JSeparator;
49 49
 /**
50 50
  * Invite label.
51 51
  */
52
-public class InviteLabel extends StatusbarPopupPanel implements 
52
+public class InviteLabel extends StatusbarPopupPanel<JLabel> implements
53 53
         StatusBarComponent, InviteListener, ActionListener,
54 54
         java.awt.event.ActionListener {
55 55
 

+ 7
- 7
src/com/dmdirc/addons/ui_swing/components/statusbar/InvitePopup.java View File

@@ -33,7 +33,6 @@ import javax.swing.JPanel;
33 33
  * Shows information about received invites.
34 34
  *
35 35
  * @since 0.6.3m1
36
- * @author chris
37 36
  */
38 37
 public class InvitePopup extends StatusbarPopupWindow {
39 38
 
@@ -43,7 +42,6 @@ public class InvitePopup extends StatusbarPopupWindow {
43 42
      * objects being unserialized with the new class).
44 43
      */
45 44
     private static final long serialVersionUID = 1;
46
-
47 45
     /** The server to show invites for. */
48 46
     private final Server server;
49 47
 
@@ -54,7 +52,8 @@ public class InvitePopup extends StatusbarPopupWindow {
54 52
      * @param server The server to show invites for
55 53
      * @param parentWindow Parent window
56 54
      */
57
-    public InvitePopup(final JPanel parent, final Server server, final Window parentWindow) {
55
+    public InvitePopup(final JPanel parent, final Server server,
56
+            final Window parentWindow) {
58 57
         super(parent, parentWindow);
59 58
         this.server = server;
60 59
     }
@@ -64,11 +63,12 @@ public class InvitePopup extends StatusbarPopupWindow {
64 63
     protected void initContent(final JPanel panel) {
65 64
         for (Invite invite : server.getInvites()) {
66 65
             panel.add(new JLabel(invite.getChannel()), "growx, pushx");
67
-            panel.add(new JLabel(invite.getSource()[0], JLabel.CENTER), "growx, pushx, al center");
66
+            panel.add(new JLabel(invite.getSource()[0], JLabel.CENTER),
67
+                    "growx, pushx, al center");
68 68
             panel.add(new JLabel(Formatter.formatDuration((int)
69
-                    (System.currentTimeMillis() - invite.getTimestamp()) / 1000) + " ago",
70
-                    JLabel.RIGHT), "growx, pushx, al right, wrap");
69
+                    (System.currentTimeMillis() - invite.getTimestamp())
70
+                    / 1000) + " ago", JLabel.RIGHT),
71
+                    "growx, pushx, al right, wrap");
71 72
         }
72 73
     }
73
-
74 74
 }

+ 2
- 2
src/com/dmdirc/addons/ui_swing/components/statusbar/MessageLabel.java View File

@@ -32,10 +32,10 @@ import com.dmdirc.ui.interfaces.StatusMessageNotifier;
32 32
 import java.awt.event.MouseEvent;
33 33
 import java.awt.event.MouseListener;
34 34
 import java.util.Date;
35
+import java.util.LinkedList;
35 36
 import java.util.Queue;
36 37
 import java.util.Timer;
37 38
 import java.util.TimerTask;
38
-import java.util.concurrent.ConcurrentLinkedQueue;
39 39
 
40 40
 import javax.swing.BorderFactory;
41 41
 import javax.swing.JLabel;
@@ -67,7 +67,7 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
67 67
      */
68 68
     public MessageLabel() {
69 69
         super();
70
-        queue = new ConcurrentLinkedQueue<StatusMessage>();
70
+        queue = new LinkedList<StatusMessage>();
71 71
         defaultMessage = new StatusMessage(null, "Ready.", null, -1,
72 72
                 IdentityManager.getGlobalConfig());
73 73
         currentMessage = defaultMessage;

+ 13
- 27
src/com/dmdirc/addons/ui_swing/components/statusbar/StatusbarPanel.java View File

@@ -28,7 +28,7 @@ import com.dmdirc.ui.interfaces.StatusBarComponent;
28 28
 import java.awt.event.MouseListener;
29 29
 
30 30
 import javax.swing.BorderFactory;
31
-import javax.swing.JLabel;
31
+import javax.swing.JComponent;
32 32
 import javax.swing.JPanel;
33 33
 
34 34
 import net.miginfocom.swing.MigLayout;
@@ -39,11 +39,11 @@ import net.miginfocom.swing.MigLayout;
39 39
  *
40 40
  * @since 0.6.3m1
41 41
  */
42
-public abstract class StatusbarPanel extends JPanel
42
+public abstract class StatusbarPanel<T extends JComponent> extends JPanel
43 43
         implements StatusBarComponent, MouseListener {
44 44
 
45 45
     /** The label we use to show information. */
46
-    protected final JLabel label;
46
+    protected final T label;
47 47
     /**
48 48
      * A version number for this class. It should be changed whenever the class
49 49
      * structure is changed (or anything else that would prevent serialized
@@ -53,19 +53,12 @@ public abstract class StatusbarPanel extends JPanel
53 53
     /** The popup window we're using to show extra info. */
54 54
     private StatusbarPopupWindow dialog;
55 55
 
56
-    /**
57
-     * Creates a new {@link StatusbarPanel}, using a default text label.
58
-     */
59
-    public StatusbarPanel() {
60
-        this(new JLabel("Unknown"));
61
-    }
62
-
63 56
     /**
64 57
      * Creates a new {@link StatusbarPanel}, using the specified label.
65 58
      *
66 59
      * @param label The label to be displayed in the status bar
67 60
      */
68
-    public StatusbarPanel(final JLabel label) {
61
+    public StatusbarPanel(final T label) {
69 62
         super();
70 63
 
71 64
         this.label = label;
@@ -77,6 +70,15 @@ public abstract class StatusbarPanel extends JPanel
77 70
         addMouseListener(this);
78 71
     }
79 72
 
73
+    /**
74
+     * Returns the component associated with this panel.
75
+     *
76
+     * @return Assocaited component
77
+     */
78
+    public T getComponent() {
79
+        return label;
80
+    }
81
+
80 82
     /**
81 83
      * Closes and reopens the dialog to update information and border positions.
82 84
      */
@@ -131,22 +133,6 @@ public abstract class StatusbarPanel extends JPanel
131 133
         }
132 134
     }
133 135
 
134
-    /**
135
-     * Sets the text for this label.
136
-     *
137
-     * @param text New text
138
-     */
139
-    public void setText(final String text) {
140
-        UIUtilities.invokeLater(new Runnable() {
141
-
142
-            /** {@inheritDoc} */
143
-            @Override
144
-            public void run() {
145
-                label.setText(text);
146
-            }
147
-        });
148
-    }
149
-
150 136
     /**
151 137
      * Retrieves the implementation of {@link StatusbarPopupWindow} that should
152 138
      * be shown by this panel when the user mouses over it.

+ 4
- 10
src/com/dmdirc/addons/ui_swing/components/statusbar/StatusbarPopupPanel.java View File

@@ -24,7 +24,7 @@ package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25 25
 import java.awt.event.MouseEvent;
26 26
 
27
-import javax.swing.JLabel;
27
+import javax.swing.JComponent;
28 28
 import javax.swing.UIManager;
29 29
 import javax.swing.border.EtchedBorder;
30 30
 
@@ -34,7 +34,8 @@ import javax.swing.border.EtchedBorder;
34 34
  *
35 35
  * @since 0.6.3m1
36 36
  */
37
-public abstract class StatusbarPopupPanel extends StatusbarPanel {
37
+public abstract class StatusbarPopupPanel<T extends JComponent> extends
38
+        StatusbarPanel<T> {
38 39
 
39 40
     /**
40 41
      * A version number for this class. It should be changed whenever the class
@@ -43,19 +44,12 @@ public abstract class StatusbarPopupPanel extends StatusbarPanel {
43 44
      */
44 45
     private static final long serialVersionUID = 2;
45 46
 
46
-    /**
47
-     * Creates a new {@link StatusbarPopupPanel}, using a default text label.
48
-     */
49
-    public StatusbarPopupPanel() {
50
-        this(new JLabel("Unknown"));
51
-    }
52
-
53 47
     /**
54 48
      * Creates a new {@link StatusbarPopupPanel}, using the specified label.
55 49
      *
56 50
      * @param label The label to be displayed in the status bar
57 51
      */
58
-    public StatusbarPopupPanel(final JLabel label) {
52
+    public StatusbarPopupPanel(final T label) {
59 53
         super(label);
60 54
     }
61 55
 

+ 8
- 12
src/com/dmdirc/addons/ui_swing/components/statusbar/StatusbarPopupWindow.java View File

@@ -133,20 +133,16 @@ public abstract class StatusbarPopupWindow extends StandardDialog {
133 133
         @Override
134 134
         public void paintBorder(final Component c, final Graphics g,
135 135
                 final int x, final int y, final int width, final int height) {
136
-            int w = width;
137
-            int h = height;
138
-
139 136
             g.translate(x, y);
140
-
141
-            g.setColor(etchType == LOWERED? getShadowColor(c) : getHighlightColor(c));
142
-            g.drawLine(0, 0, w-1, 0);
143
-            g.drawLine(0, h-1, parent.getLocationOnScreen().x
144
-                    - getLocationOnScreen().x, h-1);
137
+            g.setColor(etchType == LOWERED? getShadowColor(c)
138
+                    : getHighlightColor(c));
139
+            g.drawLine(0, 0, width-1, 0);
140
+            g.drawLine(0, height-1, parent.getLocationOnScreen().x
141
+                    - getLocationOnScreen().x, height-1);
145 142
             g.drawLine(parent.getWidth() + parent.getLocationOnScreen().x
146
-                    - getLocationOnScreen().x - 2, h-1, w-1, h-1);
147
-            g.drawLine(0, 0, 0, h-1);
148
-            g.drawLine(w-1, 0, w-1, h-1);
149
-
143
+                    - getLocationOnScreen().x - 2, height-1, width-1, height-1);
144
+            g.drawLine(0, 0, 0, height-1);
145
+            g.drawLine(width-1, 0, width-1, height-1);
150 146
             g.translate(-x, -y);
151 147
         }
152 148
 

+ 8
- 7
src/com/dmdirc/addons/ui_swing/components/statusbar/UpdaterLabel.java View File

@@ -35,13 +35,14 @@ import java.awt.Dialog.ModalityType;
35 35
 import java.awt.event.MouseEvent;
36 36
 
37 37
 import javax.swing.BorderFactory;
38
+import javax.swing.JLabel;
38 39
 
39 40
 /**
40 41
  * Updater label is responsible for handling the display of updates in the
41 42
  * status bar.
42 43
  */
43
-public class UpdaterLabel extends StatusbarPopupPanel implements StatusBarComponent,
44
-        UpdateCheckerListener {
44
+public class UpdaterLabel extends StatusbarPopupPanel<JLabel> implements
45
+        StatusBarComponent, UpdateCheckerListener {
45 46
 
46 47
     /**
47 48
      * A version number for this class. It should be changed whenever the class
@@ -50,16 +51,16 @@ public class UpdaterLabel extends StatusbarPopupPanel implements StatusBarCompon
50 51
      */
51 52
     private static final long serialVersionUID = 1;
52 53
     /** Swing controller. */
53
-    private MainFrame mainFrame;
54
+    private final MainFrame mainFrame;
54 55
 
55 56
     /**
56 57
      * Instantiates a new updater label, handles showing updates on the status bar.
57
-     * 
58
+     *
58 59
      * @param mainFrame Main frame
59 60
      */
60 61
     public UpdaterLabel(final MainFrame mainFrame) {
61
-        super();
62
-        
62
+        super(new JLabel());
63
+
63 64
         this.mainFrame = mainFrame;
64 65
         setBorder(BorderFactory.createEtchedBorder());
65 66
         UpdateChecker.addListener(this);
@@ -75,7 +76,7 @@ public class UpdaterLabel extends StatusbarPopupPanel implements StatusBarCompon
75 76
     @Override
76 77
     public void mouseReleased(final MouseEvent mouseEvent) {
77 78
         super.mouseClicked(mouseEvent);
78
-        
79
+
79 80
         if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
80 81
             if (UpdateChecker.getStatus().equals(UpdateChecker.STATE.RESTART_REQUIRED)) {
81 82
                 SwingRestartDialog.showSwingRestartDialog(mainFrame, ModalityType.MODELESS);

+ 7
- 4
src/com/dmdirc/addons/ui_swing/components/statusbar/UpdaterPopup.java View File

@@ -24,8 +24,10 @@ package com.dmdirc.addons.ui_swing.components.statusbar;
24 24
 
25 25
 import com.dmdirc.updater.Update;
26 26
 import com.dmdirc.updater.UpdateChecker;
27
+
27 28
 import java.awt.Window;
28 29
 import java.util.List;
30
+
29 31
 import javax.swing.JLabel;
30 32
 import javax.swing.JPanel;
31 33
 import javax.swing.JSeparator;
@@ -34,7 +36,6 @@ import javax.swing.JSeparator;
34 36
  * Information popup for the updater label.
35 37
  *
36 38
  * @since 0.6.3
37
- * @author chris
38 39
  */
39 40
 public class UpdaterPopup extends StatusbarPopupWindow {
40 41
 
@@ -66,12 +67,14 @@ public class UpdaterPopup extends StatusbarPopupWindow {
66 67
             final List<Update> updates = UpdateChecker.getAvailableUpdates();
67 68
 
68 69
             if (state.equals(UpdateChecker.STATE.RESTART_REQUIRED)) {
69
-                panel.add(new JLabel("A restart is required to install updates."), "span,wrap");
70
+                panel.add(new JLabel("A restart is required to install updates."),
71
+                        "span,wrap");
70 72
             } else if (state.equals(UpdateChecker.STATE.UPDATING)) {
71 73
                 panel.add(new JLabel("Update in progress..."), "span,wrap");
72 74
             } else {
73
-                panel.add(new JLabel(updates.size() == 1 ? "There is one update available"
74
-                        : "There are " + updates.size() + " updates available"), "span,wrap");
75
+                panel.add(new JLabel(updates.size() == 1
76
+                        ? "There is one update available" : "There are "
77
+                        + updates.size() + " updates available"), "span,wrap");
75 78
             }
76 79
 
77 80
             panel.add(new JSeparator(), "span, growx, pushx, wrap");

Loading…
Cancel
Save