|
@@ -25,11 +25,19 @@ package com.dmdirc.addons.ui_swing.dialogs.channelsetting;
|
25
|
25
|
|
26
|
26
|
import com.dmdirc.Topic;
|
27
|
27
|
import com.dmdirc.addons.ui_swing.components.text.OldTextLabel;
|
|
28
|
+import com.dmdirc.ui.messages.Styliser;
|
|
29
|
+import java.awt.Color;
|
28
|
30
|
|
29
|
31
|
import java.util.Date;
|
|
32
|
+import javax.swing.JEditorPane;
|
30
|
33
|
|
31
|
34
|
import javax.swing.JPanel;
|
32
|
35
|
import javax.swing.JSeparator;
|
|
36
|
+import javax.swing.UIManager;
|
|
37
|
+import javax.swing.text.SimpleAttributeSet;
|
|
38
|
+import javax.swing.text.StyleConstants;
|
|
39
|
+import javax.swing.text.StyledDocument;
|
|
40
|
+import javax.swing.text.StyledEditorKit;
|
33
|
41
|
|
34
|
42
|
import net.miginfocom.swing.MigLayout;
|
35
|
43
|
|
|
@@ -46,6 +54,10 @@ public class TopicLabel extends JPanel {
|
46
|
54
|
private static final long serialVersionUID = 1;
|
47
|
55
|
/** Topic this label represents. */
|
48
|
56
|
private final Topic topic;
|
|
57
|
+ /** Topic field. */
|
|
58
|
+ private JEditorPane pane;
|
|
59
|
+ /** Empty Attrib set. */
|
|
60
|
+ private SimpleAttributeSet as;
|
49
|
61
|
|
50
|
62
|
/**
|
51
|
63
|
* Instantiates a new topic label based on the specified topic.
|
|
@@ -53,20 +65,55 @@ public class TopicLabel extends JPanel {
|
53
|
65
|
* @param topic Specified topic
|
54
|
66
|
*/
|
55
|
67
|
public TopicLabel(final Topic topic) {
|
|
68
|
+ if (topic == null) {
|
|
69
|
+ throw new IllegalArgumentException();
|
|
70
|
+ }
|
56
|
71
|
this.topic = topic;
|
|
72
|
+ super.setBackground(UIManager.getColor("Table.background"));
|
|
73
|
+ super.setForeground(UIManager.getColor("Table.foreground"));
|
57
|
74
|
|
58
|
75
|
init();
|
59
|
76
|
}
|
60
|
77
|
|
|
78
|
+ private void initTopicField() {
|
|
79
|
+ pane = new JEditorPane();
|
|
80
|
+ pane.setEditorKit(new StyledEditorKit());
|
|
81
|
+
|
|
82
|
+ pane.setFocusable(false);
|
|
83
|
+ pane.setEditable(false);
|
|
84
|
+ pane.setOpaque(false);
|
|
85
|
+
|
|
86
|
+ as = new SimpleAttributeSet();
|
|
87
|
+ StyleConstants.setFontFamily(as, pane.getFont().getFamily());
|
|
88
|
+ StyleConstants.setFontSize(as, pane.getFont().getSize());
|
|
89
|
+ if (getBackground() == null) {
|
|
90
|
+ StyleConstants.setBackground(as, UIManager.getColor("Table.background"));
|
|
91
|
+ } else {
|
|
92
|
+ StyleConstants.setBackground(as, getBackground());
|
|
93
|
+ }
|
|
94
|
+ if (getForeground() == null) {
|
|
95
|
+ StyleConstants.setForeground(as, UIManager.getColor("Table.foreground"));
|
|
96
|
+ } else {
|
|
97
|
+ StyleConstants.setForeground(as, getForeground());
|
|
98
|
+ }
|
|
99
|
+ StyleConstants.setUnderline(as, false);
|
|
100
|
+ StyleConstants.setBold(as, false);
|
|
101
|
+ StyleConstants.setItalic(as, false);
|
|
102
|
+ }
|
|
103
|
+
|
61
|
104
|
private void init() {
|
|
105
|
+ initTopicField();
|
|
106
|
+ removeAll();
|
62
|
107
|
setLayout(new MigLayout("fillx, ins 0, debug", "[]0[]", "[]0[]"));
|
63
|
108
|
|
64
|
|
- OldTextLabel label;
|
65
|
109
|
if (!topic.getTopic().isEmpty()) {
|
66
|
|
- label = new OldTextLabel(topic.getTopic());
|
67
|
|
- add(label, "wmax 450, growy, pushy, wrap, gapleft 5, gapleft 5");
|
|
110
|
+ Styliser.addStyledString((StyledDocument) pane.getDocument(),
|
|
111
|
+ new String[]{topic.getTopic(),},
|
|
112
|
+ as);
|
|
113
|
+ add(pane, "wmax 450, grow, push, wrap, gapleft 5, gapleft 5");
|
68
|
114
|
}
|
69
|
115
|
|
|
116
|
+ OldTextLabel label;
|
70
|
117
|
if (topic.getTopic().isEmpty()) {
|
71
|
118
|
label = new OldTextLabel("Topic unset by " + topic.getClient());
|
72
|
119
|
} else {
|
|
@@ -74,7 +121,8 @@ public class TopicLabel extends JPanel {
|
74
|
121
|
}
|
75
|
122
|
add(label, "wmax 450, growy, pushy, wrap, gapleft 5, pad 0");
|
76
|
123
|
|
77
|
|
- label = new OldTextLabel("on " + new Date(topic.getTime() * 1000).toString());
|
|
124
|
+ label = new OldTextLabel("on " + new Date(topic.getTime() * 1000).
|
|
125
|
+ toString());
|
78
|
126
|
add(label, "wmax 450, growy, pushy, wrap, gapleft 5, pad 0");
|
79
|
127
|
|
80
|
128
|
add(new JSeparator(), "newline, span, growx, pushx");
|
|
@@ -88,4 +136,22 @@ public class TopicLabel extends JPanel {
|
88
|
136
|
public Topic getTopic() {
|
89
|
137
|
return topic;
|
90
|
138
|
}
|
|
139
|
+
|
|
140
|
+ /** {@inheritDoc} */
|
|
141
|
+ @Override
|
|
142
|
+ public void setBackground(final Color bg) {
|
|
143
|
+ super.setBackground(bg);
|
|
144
|
+ if (topic != null) {
|
|
145
|
+ init();
|
|
146
|
+ }
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ /** {@inheritDoc} */
|
|
150
|
+ @Override
|
|
151
|
+ public void setForeground(final Color fg) {
|
|
152
|
+ super.setForeground(fg);
|
|
153
|
+ if (topic != null) {
|
|
154
|
+ init();
|
|
155
|
+ }
|
|
156
|
+ }
|
91
|
157
|
}
|