Kaynağa Gözat

Fixes issue 3327: TopicBar uses the wrong font-colour the first time it is edited if no topic is set

Change-Id: I6f54b9516d7a69940dda946a3b1cc4c3403af8d2
Reviewed-on: http://gerrit.dmdirc.com/290
Reviewed-by: Chris Smith <chris@dmdirc.com>
Tested-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 yıl önce
ebeveyn
işleme
59cf76e87b

+ 19
- 17
src/com/dmdirc/addons/ui_swing/components/TopicBar.java Dosyayı Görüntüle

@@ -50,6 +50,7 @@ import javax.swing.JComponent;
50 50
 import javax.swing.JLabel;
51 51
 import javax.swing.JScrollPane;
52 52
 import javax.swing.KeyStroke;
53
+import javax.swing.SwingUtilities;
53 54
 import javax.swing.event.DocumentEvent;
54 55
 import javax.swing.event.DocumentListener;
55 56
 import javax.swing.event.HyperlinkEvent;
@@ -139,16 +140,11 @@ public class TopicBar extends JComponent implements ActionListener,
139 140
                 getIcon("close-active"));
140 141
 
141 142
         new SwingInputHandler(topicText, channelFrame.getCommandParser(),
142
-                channelFrame).setTypes(false,
143
-                false, true, false);
144
-
145
-        topicText.setFocusable(false);
146
-        topicText.setEditable(false);
147
-        topicCancel.setVisible(false);
143
+                channelFrame).setTypes(false, false, true, false);
148 144
 
149 145
         final JScrollPane sp = new JScrollPane(topicText);
150 146
         sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
151
-        sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
147
+        sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
152 148
 
153 149
         setLayout(new MigLayout("fillx, ins 0, hidemode 3"));
154 150
         add(sp, "growx, pushx");
@@ -156,7 +152,6 @@ public class TopicBar extends JComponent implements ActionListener,
156 152
         add(topicCancel, "");
157 153
         add(topicEdit, "");
158 154
 
159
-
160 155
         channel.getChannelInfo().getParser().getCallbackManager().addCallback(
161 156
                 ChannelTopicListener.class, this, channel.getChannelInfo().
162 157
                 getName());
@@ -205,9 +200,11 @@ public class TopicBar extends JComponent implements ActionListener,
205 200
                 controller.getDomain(), "showfulltopic", this);
206 201
         IdentityManager.getGlobalConfig().addChangeListener(
207 202
                 controller.getDomain(), "hideEmptyTopicBar", this);
203
+        
204
+        topicText.setFocusable(false);
205
+        topicText.setEditable(false);
206
+        topicCancel.setVisible(false);
208 207
         setColours();
209
-        ((DefaultStyledDocument) topicText.getDocument()).setCharacterAttributes(
210
-                0, Integer.MAX_VALUE, as, true);
211 208
     }
212 209
 
213 210
     /** {@inheritDoc} */
@@ -225,9 +222,6 @@ public class TopicBar extends JComponent implements ActionListener,
225 222
             return;
226 223
         }
227 224
         topicText.setText("");
228
-        setAttributes();
229
-        ((DefaultStyledDocument) topicText.getDocument()).setCharacterAttributes(
230
-                0, Integer.MAX_VALUE, as, true);
231 225
         if (channel.getCurrentTopic() != null) {
232 226
             Styliser.addStyledString((StyledDocument) topicText.getDocument(),
233 227
                     new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.getHex(
@@ -261,10 +255,6 @@ public class TopicBar extends JComponent implements ActionListener,
261 255
             } else {
262 256
                 topicText.setVisible(false);
263 257
                 topicText.setText("");
264
-                setAttributes();
265
-                ((DefaultStyledDocument) topicText.getDocument()).
266
-                        setCharacterAttributes(
267
-                        0, Integer.MAX_VALUE, as, true);
268 258
                 if (channel.getCurrentTopic() != null) {
269 259
                     topicText.setText(channel.getCurrentTopic().getTopic());
270 260
                 }
@@ -513,6 +503,18 @@ public class TopicBar extends JComponent implements ActionListener,
513 503
     @Override
514 504
     public void insertUpdate(final DocumentEvent e) {
515 505
         validateTopic();
506
+        if (topicText.isEditable()) {
507
+            SwingUtilities.invokeLater(new Runnable() {
508
+
509
+                @Override
510
+                public void run() {
511
+                    setAttributes();
512
+                    ((DefaultStyledDocument) topicText.getDocument()).
513
+                            setCharacterAttributes(0, Integer.MAX_VALUE, as,
514
+                            true);
515
+                }
516
+            });
517
+        }
516 518
     }
517 519
 
518 520
     /** {@inheritDoc} */

Loading…
İptal
Kaydet