Browse Source

Fixes issue 3436: CSD topic history needs to handle (ie strip) formatting

Change-Id: Id7fd280249c3cd5d72e5ba5020fb75f11c170169
Reviewed-on: http://gerrit.dmdirc.com/345
Reviewed-by: Chris Smith <chris@dmdirc.com>
Tested-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 years ago
parent
commit
e121d92128

+ 0
- 1
src/com/dmdirc/addons/ui_swing/components/renderers/TopicCellRenderer.java View File

68
         } else {
68
         } else {
69
             panel = new JPanel(new MigLayout());
69
             panel = new JPanel(new MigLayout());
70
             panel.add(new JLabel(value.toString()));
70
             panel.add(new JLabel(value.toString()));
71
-            
72
         }
71
         }
73
         table.setRowHeight(row, panel.getPreferredSize().height);
72
         table.setRowHeight(row, panel.getPreferredSize().height);
74
         return panel;
73
         return panel;

+ 70
- 4
src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/TopicLabel.java View File

25
 
25
 
26
 import com.dmdirc.Topic;
26
 import com.dmdirc.Topic;
27
 import com.dmdirc.addons.ui_swing.components.text.OldTextLabel;
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
 import java.util.Date;
31
 import java.util.Date;
32
+import javax.swing.JEditorPane;
30
 
33
 
31
 import javax.swing.JPanel;
34
 import javax.swing.JPanel;
32
 import javax.swing.JSeparator;
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
 import net.miginfocom.swing.MigLayout;
42
 import net.miginfocom.swing.MigLayout;
35
 
43
 
46
     private static final long serialVersionUID = 1;
54
     private static final long serialVersionUID = 1;
47
     /** Topic this label represents. */
55
     /** Topic this label represents. */
48
     private final Topic topic;
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
      * Instantiates a new topic label based on the specified topic.
63
      * Instantiates a new topic label based on the specified topic.
53
      * @param topic Specified topic
65
      * @param topic Specified topic
54
      */
66
      */
55
     public TopicLabel(final Topic topic) {
67
     public TopicLabel(final Topic topic) {
68
+        if (topic == null) {
69
+            throw new IllegalArgumentException();
70
+        }
56
         this.topic = topic;
71
         this.topic = topic;
72
+        super.setBackground(UIManager.getColor("Table.background"));
73
+        super.setForeground(UIManager.getColor("Table.foreground"));
57
 
74
 
58
         init();
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
     private void init() {
104
     private void init() {
105
+        initTopicField();
106
+        removeAll();
62
         setLayout(new MigLayout("fillx, ins 0, debug", "[]0[]", "[]0[]"));
107
         setLayout(new MigLayout("fillx, ins 0, debug", "[]0[]", "[]0[]"));
63
 
108
 
64
-        OldTextLabel label;
65
         if (!topic.getTopic().isEmpty()) {
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
         if (topic.getTopic().isEmpty()) {
117
         if (topic.getTopic().isEmpty()) {
71
             label = new OldTextLabel("Topic unset by " + topic.getClient());
118
             label = new OldTextLabel("Topic unset by " + topic.getClient());
72
         } else {
119
         } else {
74
         }
121
         }
75
         add(label, "wmax 450, growy, pushy, wrap, gapleft 5, pad 0");
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
         add(label, "wmax 450, growy, pushy, wrap, gapleft 5, pad 0");
126
         add(label, "wmax 450, growy, pushy, wrap, gapleft 5, pad 0");
79
 
127
 
80
         add(new JSeparator(), "newline, span, growx, pushx");
128
         add(new JSeparator(), "newline, span, growx, pushx");
88
     public Topic getTopic() {
136
     public Topic getTopic() {
89
         return topic;
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
 }

Loading…
Cancel
Save