|
@@ -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
|
}
|