Browse Source

Invite label popup

tags/0.6.3m1rc1
Chris Smith 15 years ago
parent
commit
c08e5065fb

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

@@ -38,7 +38,6 @@ import com.dmdirc.util.MapList;
38 38
 
39 39
 import java.awt.event.ActionEvent;
40 40
 import java.awt.event.MouseEvent;
41
-import java.awt.event.MouseListener;
42 41
 
43 42
 import java.util.ArrayList;
44 43
 import java.util.Arrays;
@@ -50,11 +49,12 @@ import javax.swing.JMenuItem;
50 49
 import javax.swing.JPopupMenu;
51 50
 import javax.swing.JSeparator;
52 51
 
52
+
53 53
 /**
54 54
  * Invite label.
55 55
  */
56
-public class InviteLabel extends JLabel implements StatusBarComponent, 
57
-        InviteListener, ActionListener, MouseListener {
56
+public class InviteLabel extends StatusbarPopupPanel implements StatusBarComponent,
57
+        InviteListener, ActionListener {
58 58
 
59 59
     /**
60 60
      * A version number for this class. It should be changed whenever the class
@@ -77,10 +77,10 @@ public class InviteLabel extends JLabel implements StatusBarComponent,
77 77
      * Instantiates a new invite label.
78 78
      */
79 79
     public InviteLabel() {
80
-        super();
80
+        super(new JLabel());
81 81
 
82 82
         setBorder(BorderFactory.createEtchedBorder());
83
-        setIcon(IconManager.getIconManager().getIcon("invite"));
83
+        label.setIcon(IconManager.getIconManager().getIcon("invite"));
84 84
 
85 85
         inviteList = new MapList<Server, Invite>();
86 86
         menu = new JPopupMenu();
@@ -120,11 +120,16 @@ public class InviteLabel extends JLabel implements StatusBarComponent,
120 120
         }
121 121
 
122 122
         ActionManager.addListener(this, CoreActionType.CLIENT_FRAME_CHANGED);
123
-        addMouseListener(this);
124 123
 
125 124
         update();
126 125
     }
127 126
 
127
+    /** {@inheritDoc} */
128
+    @Override
129
+    protected StatusbarPopupWindow getWindow() {
130
+        return new InvitePopup(this, activeServer);
131
+    }
132
+
128 133
     /**
129 134
      * Popuplates the menu.
130 135
      */
@@ -161,7 +166,9 @@ public class InviteLabel extends JLabel implements StatusBarComponent,
161 166
 
162 167
         if (activeServer == null || inviteList.get(activeServer).isEmpty()) {
163 168
             setVisible(false);
169
+            closeDialog();
164 170
         } else {
171
+            refreshDialog();
165 172
             setVisible(true);
166 173
             setToolTipText(inviteList.get(activeServer).size() +
167 174
                     " pending invites.");
@@ -206,53 +213,14 @@ public class InviteLabel extends JLabel implements StatusBarComponent,
206 213
      */
207 214
     @Override
208 215
     public void mouseClicked(final MouseEvent e) {
216
+        super.mouseClicked(e);
209 217
         popuplateMenu();
210 218
         if (menu.getComponentCount() > 0) {
211 219
             menu.show(this, e.getX(), e.getY());
212 220
         }
213 221
     }
214 222
 
215
-    /**
216
-     * {@inheritDoc}
217
-     *
218
-     * @param e Mouse event
219
-     */
220
-    @Override
221
-    public void mousePressed(final MouseEvent e) {
222
-        //Ignore
223
-    }
224
-
225
-    /**
226
-     * {@inheritDoc}
227
-     *
228
-     * @param e Mouse event
229
-     */
230
-    @Override
231
-    public void mouseReleased(final MouseEvent e) {
232
-        //Ignore
233
-    }
234
-
235
-    /**
236
-     * {@inheritDoc}
237
-     *
238
-     * @param e Mouse event
239
-     */
240
-    @Override
241
-    public void mouseEntered(final MouseEvent e) {
242
-        //Ignore
243
-    }
244
-
245
-    /**
246
-     * {@inheritDoc}
247
-     *
248
-     * @param e Mouse event
249
-     */
250
-    @Override
251
-    public void mouseExited(final MouseEvent e) {
252
-        //Ignore
253
-    }
254 223
 }
255
-
256 224
 /**
257 225
  * Invite action.
258 226
  */

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

@@ -0,0 +1,72 @@
1
+/*
2
+ * Copyright (c) 2006-2008 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.components.statusbar;
24
+
25
+import com.dmdirc.Invite;
26
+import com.dmdirc.Server;
27
+import com.dmdirc.ui.messages.Formatter;
28
+import javax.swing.JLabel;
29
+import javax.swing.JPanel;
30
+
31
+/**
32
+ * Shows information about received invites.
33
+ *
34
+ * @since 0.6.3
35
+ * @author chris
36
+ */
37
+public class InvitePopup extends StatusbarPopupWindow {
38
+
39
+    /**
40
+     * A version number for this class. It should be changed whenever the class
41
+     * structure is changed (or anything else that would prevent serialized
42
+     * objects being unserialized with the new class).
43
+     */
44
+    private static final long serialVersionUID = 1;
45
+
46
+    /** The server to show invites for. */
47
+    private final Server server;
48
+
49
+    /**
50
+     * Creates a new InvitePopup for the specified panel and server.
51
+     * 
52
+     * @param parent The parent of this popup
53
+     * @param server The server to show invites for
54
+     */
55
+    public InvitePopup(final JPanel parent, final Server server) {
56
+        super(parent);
57
+        this.server = server;
58
+    }
59
+
60
+    /** {@inheritDoc} */
61
+    @Override
62
+    protected void initContent(final JPanel panel) {
63
+        for (Invite invite : server.getInvites()) {
64
+            panel.add(new JLabel(invite.getChannel()), "growx");
65
+            panel.add(new JLabel(invite.getSource()[0], JLabel.CENTER), "growx, al center");
66
+            panel.add(new JLabel(Formatter.formatDuration((int)
67
+                    (System.currentTimeMillis() - invite.getTimestamp()) / 1000) + " ago",
68
+                    JLabel.RIGHT), "growx, al right, wrap");
69
+        }
70
+    }
71
+
72
+}

Loading…
Cancel
Save