|
@@ -23,22 +23,32 @@
|
23
|
23
|
package com.dmdirc.addons.ui_swing.framemanager.tree;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.FrameContainer;
|
|
26
|
+import com.dmdirc.addons.ui_swing.components.ImageButton;
|
26
|
27
|
import com.dmdirc.interfaces.FrameInfoListener;
|
27
|
28
|
import com.dmdirc.interfaces.NotificationListener;
|
28
|
29
|
import com.dmdirc.interfaces.SelectionListener;
|
29
|
30
|
import com.dmdirc.ui.IconManager;
|
|
31
|
+import com.dmdirc.ui.messages.Styliser;
|
30
|
32
|
|
31
|
33
|
import java.awt.Color;
|
32
|
34
|
import java.awt.Dimension;
|
|
35
|
+import java.awt.Font;
|
|
36
|
+
|
33
|
37
|
import javax.swing.BorderFactory;
|
34
|
|
-import javax.swing.JLabel;
|
|
38
|
+import javax.swing.JPanel;
|
|
39
|
+import javax.swing.JTextPane;
|
|
40
|
+import javax.swing.SwingUtilities;
|
|
41
|
+import javax.swing.UIManager;
|
|
42
|
+import javax.swing.text.DefaultStyledDocument;
|
|
43
|
+import javax.swing.text.StyledDocument;
|
35
|
44
|
|
36
|
45
|
import net.miginfocom.layout.PlatformDefaults;
|
|
46
|
+import net.miginfocom.swing.MigLayout;
|
37
|
47
|
|
38
|
48
|
/**
|
39
|
49
|
* Node label.
|
40
|
50
|
*/
|
41
|
|
-public class NodeLabel extends JLabel implements SelectionListener,
|
|
51
|
+public class NodeLabel extends JPanel implements SelectionListener,
|
42
|
52
|
NotificationListener, FrameInfoListener {
|
43
|
53
|
|
44
|
54
|
/**
|
|
@@ -55,6 +65,13 @@ public class NodeLabel extends JLabel implements SelectionListener,
|
55
|
65
|
private Color notificationColour;
|
56
|
66
|
/** Are we the selected window? */
|
57
|
67
|
private boolean selected;
|
|
68
|
+ /** Node icon. */
|
|
69
|
+ private final ImageButton icon = new ImageButton("", IconManager
|
|
70
|
+ .getIconManager().getIcon("icon"));
|
|
71
|
+ /** Text label. */
|
|
72
|
+ private final JTextPane text = new JTextPane(new DefaultStyledDocument());
|
|
73
|
+ /** Current styled text. */
|
|
74
|
+ private String currentText = "";
|
58
|
75
|
|
59
|
76
|
/**
|
60
|
77
|
* Instantiates a new node label.
|
|
@@ -77,11 +94,17 @@ public class NodeLabel extends JLabel implements SelectionListener,
|
77
|
94
|
return;
|
78
|
95
|
}
|
79
|
96
|
|
80
|
|
- setText(window.toString());
|
|
97
|
+ icon.setIcon(IconManager.getIconManager().getIcon(window.getIcon()));
|
|
98
|
+ text.setText(window.toString());
|
|
99
|
+ text.setBorder(null);
|
|
100
|
+
|
|
101
|
+ setLayout(new MigLayout("ins 0"));
|
|
102
|
+ add(icon, "left");
|
|
103
|
+ add(text, "left, grow, pushx");
|
81
|
104
|
|
82
|
105
|
|
83
|
|
- setToolTipText(null);
|
84
|
|
- setIcon(IconManager.getIconManager().getIcon(window.getIcon()));
|
|
106
|
+ icon.setToolTipText(null);
|
|
107
|
+ text.setToolTipText(null);
|
85
|
108
|
setBorder(BorderFactory.createEmptyBorder(1, 0, 2, 0));
|
86
|
109
|
|
87
|
110
|
setPreferredSize(new Dimension(100000, getFont().getSize()
|
|
@@ -122,7 +145,7 @@ public class NodeLabel extends JLabel implements SelectionListener,
|
122
|
145
|
@Override
|
123
|
146
|
public void iconChanged(final FrameContainer<?> window, final String icon) {
|
124
|
147
|
if (equals(window)) {
|
125
|
|
- setIcon(IconManager.getIconManager().getIcon(icon));
|
|
148
|
+ this.icon.setIcon(IconManager.getIconManager().getIcon(icon));
|
126
|
149
|
}
|
127
|
150
|
}
|
128
|
151
|
|
|
@@ -130,7 +153,7 @@ public class NodeLabel extends JLabel implements SelectionListener,
|
130
|
153
|
@Override
|
131
|
154
|
public void nameChanged(final FrameContainer<?> window, final String name) {
|
132
|
155
|
if (equals(window)) {
|
133
|
|
- setText(name);
|
|
156
|
+ text.setText(name);
|
134
|
157
|
}
|
135
|
158
|
}
|
136
|
159
|
|
|
@@ -197,4 +220,91 @@ public class NodeLabel extends JLabel implements SelectionListener,
|
197
|
220
|
return window.hashCode();
|
198
|
221
|
}
|
199
|
222
|
|
|
223
|
+ /** {@inheritDoc} */
|
|
224
|
+ @Override
|
|
225
|
+ public Font getFont() {
|
|
226
|
+ return UIManager.getFont("TextPane.font");
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ /**
|
|
230
|
+ * Sets the foreground colour for this label.
|
|
231
|
+ *
|
|
232
|
+ * @param colour New foreground colour
|
|
233
|
+ */
|
|
234
|
+ @Override
|
|
235
|
+ public void setForeground(final Color colour) {
|
|
236
|
+ if (text != null) {
|
|
237
|
+ text.setForeground(colour);
|
|
238
|
+ }
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ /**
|
|
242
|
+ * Sets the background colour for this label.
|
|
243
|
+ *
|
|
244
|
+ * @param colour New background colour
|
|
245
|
+ */
|
|
246
|
+ @Override
|
|
247
|
+ public void setBackground(final Color colour) {
|
|
248
|
+ if (text != null) {
|
|
249
|
+ text.setBackground(colour);
|
|
250
|
+ }
|
|
251
|
+ }
|
|
252
|
+
|
|
253
|
+ /**
|
|
254
|
+ * Sets the font for this label.
|
|
255
|
+ *
|
|
256
|
+ * @param font New font
|
|
257
|
+ */
|
|
258
|
+ @Override
|
|
259
|
+ public void setFont(final Font font) {
|
|
260
|
+ if (text != null) {
|
|
261
|
+ text.setFont(font);
|
|
262
|
+ }
|
|
263
|
+ }
|
|
264
|
+
|
|
265
|
+ /**
|
|
266
|
+ * Sets the opacity of this label.
|
|
267
|
+ *
|
|
268
|
+ * @param opacity Desired opacity
|
|
269
|
+ */
|
|
270
|
+ @Override
|
|
271
|
+ public void setOpaque(final boolean opacity) {
|
|
272
|
+ if (text != null) {
|
|
273
|
+ text.setOpaque(opacity);
|
|
274
|
+ }
|
|
275
|
+ }
|
|
276
|
+
|
|
277
|
+ /**
|
|
278
|
+ * Sets the text and style in this label.
|
|
279
|
+ *
|
|
280
|
+ * @param styliser Styliser to use to style text
|
|
281
|
+ * @param styledText Styled text string to use
|
|
282
|
+ */
|
|
283
|
+ public void setStyledText(final Styliser styliser,
|
|
284
|
+ final String styledText) {
|
|
285
|
+ if (currentText.equals(styledText)) {
|
|
286
|
+ return;
|
|
287
|
+ }
|
|
288
|
+ text.setText("");
|
|
289
|
+ currentText = styledText;
|
|
290
|
+ styliser.addStyledString((StyledDocument) text.getDocument(),
|
|
291
|
+ new String[] {styledText, });
|
|
292
|
+ }
|
|
293
|
+
|
|
294
|
+ /**
|
|
295
|
+ * Sets the styles for the text in this label.
|
|
296
|
+ *
|
|
297
|
+ * @param styliser Styliser to use
|
|
298
|
+ * @param newText Style to set
|
|
299
|
+ */
|
|
300
|
+ public void setTextStyle(final Styliser styliser, final String newText) {
|
|
301
|
+ if (currentText.equals(newText + window.toString())) {
|
|
302
|
+ return;
|
|
303
|
+ }
|
|
304
|
+ text.setText("");
|
|
305
|
+ currentText = newText + window.toString();
|
|
306
|
+ styliser.addStyledString((StyledDocument) text.getDocument(),
|
|
307
|
+ new String[] {newText, window.toString(), });
|
|
308
|
+ }
|
|
309
|
+
|
200
|
310
|
}
|