Browse Source

Add support for a basic history popup

Issue CLIENT-211

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

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

@@ -29,6 +29,7 @@ import com.dmdirc.ui.StatusMessage;
29 29
 import com.dmdirc.ui.interfaces.StatusBarComponent;
30 30
 import com.dmdirc.ui.interfaces.StatusMessageNotifier;
31 31
 
32
+import java.awt.Window;
32 33
 import java.awt.event.MouseEvent;
33 34
 import java.awt.event.MouseListener;
34 35
 import java.util.Date;
@@ -37,14 +38,16 @@ import java.util.Queue;
37 38
 import java.util.Timer;
38 39
 import java.util.TimerTask;
39 40
 
40
-import javax.swing.BorderFactory;
41 41
 import javax.swing.JLabel;
42
+import javax.swing.JPanel;
42 43
 import javax.swing.SwingUtilities;
43 44
 
45
+import net.miginfocom.swing.MigLayout;
46
+
44 47
 /**
45 48
  * Message label handles showing messages in the status bar.
46 49
  */
47
-public class MessageLabel extends JLabel implements StatusBarComponent,
50
+public class MessageLabel extends JPanel implements StatusBarComponent,
48 51
         MouseListener {
49 52
 
50 53
     /**
@@ -57,6 +60,10 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
57 60
     private final StatusMessage defaultMessage;
58 61
     /** Message queue. */
59 62
     private final Queue<StatusMessage> queue;
63
+    /** Messsage label. */
64
+    private final JLabel label;
65
+    /** History label. */
66
+    private final MessagePopup historyLabel;
60 67
     /** Current status messsage. */
61 68
     private StatusMessage currentMessage;
62 69
     /** Timer to clear the message. */
@@ -65,15 +72,20 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
65 72
     /**
66 73
      * Instantiates a new message label.
67 74
      */
68
-    public MessageLabel() {
69
-        super();
75
+    public MessageLabel(final Window parentWindow) {
76
+        super(new MigLayout("fill, ins 0, gap 0  0"));
70 77
         queue = new LinkedList<StatusMessage>();
71 78
         defaultMessage = new StatusMessage(null, "Ready.", null, -1,
72 79
                 IdentityManager.getGlobalConfig());
73 80
         currentMessage = defaultMessage;
74
-        setText("Ready.");
75
-        setBorder(BorderFactory.createEtchedBorder());
76
-        addMouseListener(this);
81
+        label = new JLabel();
82
+        historyLabel = new MessagePopup(parentWindow);
83
+        label.setText("Ready.");
84
+        label.setBorder(new SidelessEtchedBorder(
85
+                SidelessEtchedBorder.Side.RIGHT));
86
+        label.addMouseListener(this);
87
+        add(label, "growx, pushx");
88
+        add(historyLabel, "gapleft 0");
77 89
     }
78 90
 
79 91
     /**
@@ -192,12 +204,12 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
192 204
             @Override
193 205
             public void run() {
194 206
                 if (currentMessage.getIconType() == null) {
195
-                    setIcon(null);
207
+                    label.setIcon(null);
196 208
                 } else {
197
-                    setIcon(IconManager.getIconManager().getIcon(
209
+                    label.setIcon(IconManager.getIconManager().getIcon(
198 210
                             currentMessage.getIconType()));
199 211
                 }
200
-                setText(UIUtilities.clipStringifNeeded(MessageLabel.this,
212
+                label.setText(UIUtilities.clipStringifNeeded(MessageLabel.this,
201 213
                         currentMessage.getMessage(), getWidth()));
202 214
                 if (messageTimer != null && (System.currentTimeMillis()
203 215
                         - messageTimer.scheduledExecutionTime()) <= 0) {
@@ -218,6 +230,7 @@ public class MessageLabel extends JLabel implements StatusBarComponent,
218 230
      */
219 231
     public void clearMessage() {
220 232
         synchronized(queue) {
233
+            historyLabel.addMessage(currentMessage);
221 234
             if (queue.peek() == null) {
222 235
                 currentMessage = defaultMessage;
223 236
             } else {

+ 131
- 0
src/com/dmdirc/addons/ui_swing/components/statusbar/MessagePopup.java View File

@@ -0,0 +1,131 @@
1
+/*
2
+ * Copyright (c) 2006-2011 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.ui.IconManager;
26
+import com.dmdirc.ui.StatusMessage;
27
+
28
+import java.awt.Window;
29
+import java.awt.event.MouseEvent;
30
+import java.util.ArrayList;
31
+import java.util.List;
32
+
33
+import javax.swing.JLabel;
34
+import javax.swing.JPanel;
35
+import javax.swing.SwingConstants;
36
+import javax.swing.UIManager;
37
+
38
+/**
39
+ * Previous status bar messages popup.
40
+ */
41
+class MessagePopup extends StatusbarTogglePanel<JLabel> {
42
+
43
+    /** Parent window. */
44
+    private final Window parentWindow;
45
+    /** List of historical messages. */
46
+    private final List<StatusMessage> messages;
47
+
48
+    /**
49
+     * Creates a new message history popup.
50
+     *
51
+     * @param nonSelectedBorder Border when unselected
52
+     * @param selectedBorder Border when selected
53
+     * @param mainFrame Mainframe
54
+     */
55
+    public MessagePopup(final Window parentWindow) {
56
+        super(new JLabel("^"),
57
+                new SidelessEtchedBorder(SidelessEtchedBorder.Side.LEFT),
58
+                new SidelessEtchedBorder(SidelessEtchedBorder.Side.TOP));
59
+        this.parentWindow = parentWindow;
60
+        messages = new ArrayList<StatusMessage>();
61
+    }
62
+
63
+    /* {@inheritDoc} */
64
+    @Override
65
+    protected StatusbarPopupWindow getWindow() {
66
+        return new MessageHistoryPanel(this);
67
+    }
68
+
69
+    /* {@inheritDoc} */
70
+    @Override
71
+    public void mouseEntered(final MouseEvent e) {
72
+        super.mouseEntered(e);
73
+        if (!isDialogOpen()) {
74
+            setBorder(nonSelectedBorder);
75
+            setBackground(UIManager.getColor("ToolTip.background"));
76
+            setForeground(UIManager.getColor("ToolTip.foreground"));
77
+        }
78
+    }
79
+
80
+    /* {@inheritDoc} */
81
+    @Override
82
+    public void mouseExited(final MouseEvent e) {
83
+        super.mouseExited(e);
84
+        if (!isDialogOpen()) {
85
+            setBorder(new SidelessEtchedBorder(SidelessEtchedBorder.Side.LEFT));
86
+            setBackground(null);
87
+            setForeground(null);
88
+        }
89
+    }
90
+
91
+    /**
92
+     * Adds a message to this history window.
93
+     *
94
+     * @param message to add
95
+     */
96
+    public void addMessage(final StatusMessage message) {
97
+        synchronized(message) {
98
+            messages.add(message);
99
+        }
100
+    }
101
+
102
+    /** Message history status bar popup window. */
103
+    private class MessageHistoryPanel extends StatusbarPopupWindow {
104
+
105
+        /**
106
+         * Creates a new message history window.
107
+         *
108
+         * @param window Parent window
109
+         */
110
+        public MessageHistoryPanel(final JPanel parent) {
111
+            super(parent, parentWindow);
112
+        }
113
+
114
+        /* {@inheritDoc} */
115
+        @Override
116
+        protected void initContent(final JPanel panel) {
117
+            panel.removeAll();
118
+            if (messages.isEmpty()) {
119
+                panel.add(new JLabel("No previous messages."), "grow, push");
120
+                return;
121
+            }
122
+
123
+            for (StatusMessage message : messages) {
124
+                panel.add(new JLabel(message.getMessage(), message.getIconType()
125
+                        == null ? null : IconManager.getIconManager().getIcon(
126
+                        message.getIconType()), SwingConstants.LEFT),
127
+                        "grow, push, wrap");
128
+            }
129
+        }
130
+    }
131
+}

+ 30
- 3
src/com/dmdirc/addons/ui_swing/components/statusbar/StatusbarPanel.java View File

@@ -27,9 +27,11 @@ import com.dmdirc.ui.interfaces.StatusBarComponent;
27 27
 
28 28
 import java.awt.event.MouseListener;
29 29
 
30
-import javax.swing.BorderFactory;
31 30
 import javax.swing.JComponent;
32 31
 import javax.swing.JPanel;
32
+import javax.swing.UIManager;
33
+import javax.swing.border.Border;
34
+import javax.swing.border.EtchedBorder;
33 35
 
34 36
 import net.miginfocom.swing.MigLayout;
35 37
 
@@ -52,18 +54,37 @@ public abstract class StatusbarPanel<T extends JComponent> extends JPanel
52 54
     private static final long serialVersionUID = 2;
53 55
     /** The popup window we're using to show extra info. */
54 56
     private StatusbarPopupWindow dialog;
57
+    /** Non selected border. */
58
+    protected final Border nonSelectedBorder;
59
+    /** Selected border. */
60
+    protected final Border selectedBorder;
55 61
 
56 62
     /**
57 63
      * Creates a new {@link StatusbarPanel}, using the specified label.
58 64
      *
59
-     * @param label The label to be displayed in the status bar
65
+     * @param label The component to be displayed in the status bar
60 66
      */
61 67
     public StatusbarPanel(final T label) {
68
+        this(label, new EtchedBorder(), new SidelessEtchedBorder(
69
+                SidelessEtchedBorder.Side.TOP));
70
+    }
71
+
72
+    /**
73
+     * Creates a new {@link StatusbarPanel}.
74
+     *
75
+     * @param label The component to be displayed in the status bar
76
+     * @param nonSelectedBorder The border for when the panel is unselected
77
+     * @param selectedBorder The border for when for the panel is selected
78
+     */
79
+    public StatusbarPanel(final T label, final Border nonSelectedBorder,
80
+            final Border selectedBorder) {
62 81
         super();
63 82
 
64 83
         this.label = label;
84
+        this.nonSelectedBorder = nonSelectedBorder;
85
+        this.selectedBorder = selectedBorder;
65 86
 
66
-        setBorder(BorderFactory.createEtchedBorder());
87
+        setBorder(nonSelectedBorder);
67 88
         setLayout(new MigLayout("ins 0 rel 0 rel, aligny center"));
68 89
         add(label);
69 90
 
@@ -101,6 +122,9 @@ public abstract class StatusbarPanel<T extends JComponent> extends JPanel
101 122
      */
102 123
     protected final void openDialog() {
103 124
         synchronized (StatusbarPanel.this) {
125
+            setBackground(UIManager.getColor("ToolTip.background"));
126
+            setForeground(UIManager.getColor("ToolTip.foreground"));
127
+            setBorder(selectedBorder);
104 128
             dialog = getWindow();
105 129
             dialog.setVisible(true);
106 130
         }
@@ -111,6 +135,9 @@ public abstract class StatusbarPanel<T extends JComponent> extends JPanel
111 135
      */
112 136
     protected final void closeDialog() {
113 137
         synchronized (StatusbarPanel.this) {
138
+            setBackground(null);
139
+            setForeground(null);
140
+            setBorder(nonSelectedBorder);
114 141
             if (dialog != null) {
115 142
                 dialog.setVisible(false);
116 143
                 dialog.dispose();

+ 0
- 8
src/com/dmdirc/addons/ui_swing/components/statusbar/StatusbarPopupPanel.java View File

@@ -25,8 +25,6 @@ package com.dmdirc.addons.ui_swing.components.statusbar;
25 25
 import java.awt.event.MouseEvent;
26 26
 
27 27
 import javax.swing.JComponent;
28
-import javax.swing.UIManager;
29
-import javax.swing.border.EtchedBorder;
30 28
 
31 29
 /**
32 30
  * A panel shown in the status bar which displays a {@link StatusbarPopupWindow}
@@ -90,9 +88,6 @@ public abstract class StatusbarPopupPanel<T extends JComponent> extends
90 88
      */
91 89
     @Override
92 90
     public void mouseEntered(final MouseEvent e) {
93
-        setBackground(UIManager.getColor("ToolTip.background"));
94
-        setForeground(UIManager.getColor("ToolTip.foreground"));
95
-        setBorder(new SidelessEtchedBorder(SidelessEtchedBorder.Side.TOP));
96 91
         openDialog();
97 92
     }
98 93
 
@@ -103,9 +98,6 @@ public abstract class StatusbarPopupPanel<T extends JComponent> extends
103 98
      */
104 99
     @Override
105 100
     public void mouseExited(final MouseEvent e) {
106
-        setBackground(null);
107
-        setForeground(null);
108
-        setBorder(new EtchedBorder());
109 101
         closeDialog();
110 102
     }
111 103
 }

+ 19
- 18
src/com/dmdirc/addons/ui_swing/components/statusbar/StatusbarTogglePanel.java View File

@@ -26,9 +26,8 @@ import java.awt.event.ComponentEvent;
26 26
 import java.awt.event.ComponentListener;
27 27
 import java.awt.event.MouseEvent;
28 28
 
29
-import javax.swing.JLabel;
30
-import javax.swing.UIManager;
31
-import javax.swing.border.EtchedBorder;
29
+import javax.swing.JComponent;
30
+import javax.swing.border.Border;
32 31
 
33 32
 /**
34 33
  * A panel shown in the status bar which displays a {@link StatusbarPopupWindow}
@@ -36,8 +35,8 @@ import javax.swing.border.EtchedBorder;
36 35
  *
37 36
  * @since 0.6.6
38 37
  */
39
-public abstract class StatusbarTogglePanel extends StatusbarPanel
40
-        implements ComponentListener {
38
+public abstract class StatusbarTogglePanel<T extends JComponent> extends
39
+        StatusbarPanel<T> implements ComponentListener {
41 40
 
42 41
     /**
43 42
      * A version number for this class. It should be changed whenever the class
@@ -47,21 +46,29 @@ public abstract class StatusbarTogglePanel extends StatusbarPanel
47 46
     private static final long serialVersionUID = 2;
48 47
 
49 48
     /**
50
-     * Creates a new {@link StatusbarTogglePanel}, using a default text label.
49
+     * Creates a new {@link StatusbarTogglePanel}, using the specified label.
50
+     *
51
+     * @param label The component to be displayed in the status bar
51 52
      */
52
-    public StatusbarTogglePanel() {
53
-        this(new JLabel("Unknown"));
53
+    public StatusbarTogglePanel(final T label) {
54
+        super(label);
55
+
56
+        addComponentListener(this);
54 57
     }
55 58
 
56 59
     /**
57
-     * Creates a new {@link StatusbarTogglePanel}, using the specified label.
60
+     * Creates a new {@link StatusbarPanel}.
58 61
      *
59
-     * @param label The label to be displayed in the status bar
62
+     * @param label The component to be displayed in the status bar
63
+     * @param nonSelectedBorder The border for when the panel is unselected
64
+     * @param selectedBorder The border for when for the panel is selected
60 65
      */
61
-    public StatusbarTogglePanel(final JLabel label) {
62
-        super(label);
66
+    public StatusbarTogglePanel(final T label, final Border nonSelectedBorder,
67
+            final Border selectedBorder) {
68
+        super(label, nonSelectedBorder, selectedBorder);
63 69
 
64 70
         addComponentListener(this);
71
+
65 72
     }
66 73
 
67 74
     /**
@@ -72,14 +79,8 @@ public abstract class StatusbarTogglePanel extends StatusbarPanel
72 79
     @Override
73 80
     public void mouseClicked(final MouseEvent e) {
74 81
         if (isDialogOpen()) {
75
-            setBackground(null);
76
-            setForeground(null);
77
-            setBorder(new EtchedBorder());
78 82
             closeDialog();
79 83
         } else {
80
-            setBackground(UIManager.getColor("ToolTip.background"));
81
-            setForeground(UIManager.getColor("ToolTip.foreground"));
82
-            setBorder(new SidelessEtchedBorder(SidelessEtchedBorder.Side.TOP));
83 84
             openDialog();
84 85
         }
85 86
     }

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

@@ -70,7 +70,7 @@ public final class SwingStatusBar extends JPanel implements StatusBar {
70 70
             final MainFrame mainFrame) {
71 71
         super();
72 72
 
73
-        messageLabel = new MessageLabel();
73
+        messageLabel = new MessageLabel(mainFrame);
74 74
         errorPanel = new ErrorPanel(controller, mainFrame, this);
75 75
         updateLabel = new UpdaterLabel(mainFrame);
76 76
         inviteLabel = new InviteLabel(mainFrame);

Loading…
Cancel
Save