瀏覽代碼

Make status bar message history popup the same size as the message label.

Fixes CLIENT-211

Change-Id: I4e0165c74b8f7c3c84a23b659aea341e122e849d
Reviewed-on: http://gerrit.dmdirc.com/1902
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.7rc1
Greg Holmes 13 年之前
父節點
當前提交
157f8e18f5

+ 0
- 1
src/com/dmdirc/addons/ui_swing/components/statusbar/ErrorPanel.java 查看文件

@@ -56,7 +56,6 @@ public class ErrorPanel extends StatusbarPopupPanel<JLabel> implements
56 56
      * objects being unserialized with the new class).
57 57
      */
58 58
     private static final long serialVersionUID = 2;
59
-
60 59
     /** non error state image icon. */
61 60
     private static final Icon DEFAULT_ICON = IconManager.getIconManager().
62 61
             getIcon("normal");

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/statusbar/MessageLabel.java 查看文件

@@ -79,7 +79,7 @@ public class MessageLabel extends JPanel implements StatusBarComponent,
79 79
                 IdentityManager.getGlobalConfig());
80 80
         currentMessage = defaultMessage;
81 81
         label = new JLabel();
82
-        historyLabel = new MessagePopup(parentWindow);
82
+        historyLabel = new MessagePopup(this, parentWindow);
83 83
         label.setText("Ready.");
84 84
         label.setBorder(new SidelessEtchedBorder(
85 85
                 SidelessEtchedBorder.Side.RIGHT));

+ 36
- 4
src/com/dmdirc/addons/ui_swing/components/statusbar/MessagePopup.java 查看文件

@@ -25,6 +25,8 @@ package com.dmdirc.addons.ui_swing.components.statusbar;
25 25
 import com.dmdirc.ui.IconManager;
26 26
 import com.dmdirc.ui.StatusMessage;
27 27
 
28
+import java.awt.Dimension;
29
+import java.awt.Point;
28 30
 import java.awt.Window;
29 31
 import java.awt.event.MouseEvent;
30 32
 import java.util.ArrayList;
@@ -40,23 +42,31 @@ import javax.swing.UIManager;
40 42
  */
41 43
 class MessagePopup extends StatusbarTogglePanel<JLabel> {
42 44
 
45
+    /**
46
+     * A version number for this class. It should be changed whenever the class
47
+     * structure is changed (or anything else that would prevent serialized
48
+     * objects being unserialized with the new class).
49
+     */
50
+    private static final long serialVersionUID = 2;
43 51
     /** Parent window. */
44 52
     private final Window parentWindow;
45 53
     /** List of historical messages. */
46 54
     private final List<StatusMessage> messages;
55
+    /** Parent panel. */
56
+    private final JPanel parent;
47 57
 
48 58
     /**
49 59
      * Creates a new message history popup.
50 60
      *
51
-     * @param nonSelectedBorder Border when unselected
52
-     * @param selectedBorder Border when selected
53
-     * @param mainFrame Mainframe
61
+     * @param parent Parent to size against
62
+     * @param parentWindow Parent window
54 63
      */
55
-    public MessagePopup(final Window parentWindow) {
64
+    public MessagePopup(final JPanel parent, final Window parentWindow) {
56 65
         super(new JLabel("^"),
57 66
                 new SidelessEtchedBorder(SidelessEtchedBorder.Side.LEFT),
58 67
                 new SidelessEtchedBorder(SidelessEtchedBorder.Side.TOP));
59 68
         this.parentWindow = parentWindow;
69
+        this.parent = parent;
60 70
         messages = new ArrayList<StatusMessage>();
61 71
     }
62 72
 
@@ -102,6 +112,13 @@ class MessagePopup extends StatusbarTogglePanel<JLabel> {
102 112
     /** Message history status bar popup window. */
103 113
     private class MessageHistoryPanel extends StatusbarPopupWindow {
104 114
 
115
+        /**
116
+         * A version number for this class. It should be changed whenever the
117
+         * class structure is changed (or anything else that would prevent
118
+         * serialized objects being unserialized with the new class).
119
+         */
120
+        private static final long serialVersionUID = 2;
121
+
105 122
         /**
106 123
          * Creates a new message history window.
107 124
          *
@@ -115,6 +132,7 @@ class MessagePopup extends StatusbarTogglePanel<JLabel> {
115 132
         @Override
116 133
         protected void initContent(final JPanel panel) {
117 134
             panel.removeAll();
135
+            panel.setPreferredSize(new Dimension(parent.getSize()));
118 136
             if (messages.isEmpty()) {
119 137
                 panel.add(new JLabel("No previous messages."), "grow, push");
120 138
                 return;
@@ -127,5 +145,19 @@ class MessagePopup extends StatusbarTogglePanel<JLabel> {
127 145
                         "grow, push, wrap");
128 146
             }
129 147
         }
148
+
149
+        /* {@inheritDoc} */
150
+        @Override
151
+        protected Point getPopupLocation() {
152
+            final Point point = parent.getLocationOnScreen();
153
+            point.translate(parent.getWidth() / 2 - this.getWidth() / 2 - 2,
154
+                    - this.getHeight() + 1);
155
+            final int maxX = Math.max(parentWindow.getLocationOnScreen().x
156
+                    + parentWindow.getWidth() - 10 - getWidth(),
157
+                    parent.getLocationOnScreen().x + parent.getWidth() - 1
158
+                    - getWidth());
159
+            point.x = Math.min(maxX, point.x + 1);
160
+            return point;
161
+        }
130 162
     }
131 163
 }

+ 18
- 11
src/com/dmdirc/addons/ui_swing/components/statusbar/StatusbarPopupWindow.java 查看文件

@@ -36,7 +36,6 @@ import javax.swing.border.EtchedBorder;
36 36
 
37 37
 import net.miginfocom.swing.MigLayout;
38 38
 
39
-
40 39
  /**
41 40
  * A popup window which is shown above a status bar component to provide more
42 41
  * detailed information.
@@ -92,16 +91,7 @@ public abstract class StatusbarPopupWindow extends StandardDialog {
92 91
             setResizable(false);
93 92
 
94 93
             pack();
95
-
96
-            final Point point = parent.getLocationOnScreen();
97
-            point.translate(parent.getWidth() / 2 - this.getWidth() / 2,
98
-                    - this.getHeight());
99
-            final int maxX = Math.max(parentWindow.getLocationOnScreen().x
100
-                    + parentWindow.getWidth() - 10 - getWidth(),
101
-                    parent.getLocationOnScreen().x + parent.getWidth() - 1
102
-                    - getWidth());
103
-            point.x = Math.min(maxX, point.x);
104
-            setLocation(point);
94
+            setLocation(getPopupLocation());
105 95
 
106 96
             panel.setBorder(new GappedEtchedBorder());
107 97
         }
@@ -109,6 +99,23 @@ public abstract class StatusbarPopupWindow extends StandardDialog {
109 99
         super.setVisible(b);
110 100
     }
111 101
 
102
+    /**
103
+     * Returns the location the popup window should appear at.
104
+     *
105
+     * @return Point for popup to appear
106
+     */
107
+    protected Point getPopupLocation() {
108
+        final Point point = parent.getLocationOnScreen();
109
+        point.translate(parent.getWidth() / 2 - this.getWidth() / 2,
110
+                - this.getHeight());
111
+        final int maxX = Math.max(parentWindow.getLocationOnScreen().x
112
+                + parentWindow.getWidth() - 10 - getWidth(),
113
+                parent.getLocationOnScreen().x + parent.getWidth() - 1
114
+                - getWidth());
115
+        point.x = Math.min(maxX, point.x);
116
+        return point;
117
+    }
118
+
112 119
     /**
113 120
      * Initialises the content of the popup window.
114 121
      *

Loading…
取消
儲存