Przeglądaj źródła

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 lat temu
rodzic
commit
59cf76e87b

+ 19
- 17
src/com/dmdirc/addons/ui_swing/components/TopicBar.java Wyświetl plik

50
 import javax.swing.JLabel;
50
 import javax.swing.JLabel;
51
 import javax.swing.JScrollPane;
51
 import javax.swing.JScrollPane;
52
 import javax.swing.KeyStroke;
52
 import javax.swing.KeyStroke;
53
+import javax.swing.SwingUtilities;
53
 import javax.swing.event.DocumentEvent;
54
 import javax.swing.event.DocumentEvent;
54
 import javax.swing.event.DocumentListener;
55
 import javax.swing.event.DocumentListener;
55
 import javax.swing.event.HyperlinkEvent;
56
 import javax.swing.event.HyperlinkEvent;
139
                 getIcon("close-active"));
140
                 getIcon("close-active"));
140
 
141
 
141
         new SwingInputHandler(topicText, channelFrame.getCommandParser(),
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
         final JScrollPane sp = new JScrollPane(topicText);
145
         final JScrollPane sp = new JScrollPane(topicText);
150
         sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
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
         setLayout(new MigLayout("fillx, ins 0, hidemode 3"));
149
         setLayout(new MigLayout("fillx, ins 0, hidemode 3"));
154
         add(sp, "growx, pushx");
150
         add(sp, "growx, pushx");
156
         add(topicCancel, "");
152
         add(topicCancel, "");
157
         add(topicEdit, "");
153
         add(topicEdit, "");
158
 
154
 
159
-
160
         channel.getChannelInfo().getParser().getCallbackManager().addCallback(
155
         channel.getChannelInfo().getParser().getCallbackManager().addCallback(
161
                 ChannelTopicListener.class, this, channel.getChannelInfo().
156
                 ChannelTopicListener.class, this, channel.getChannelInfo().
162
                 getName());
157
                 getName());
205
                 controller.getDomain(), "showfulltopic", this);
200
                 controller.getDomain(), "showfulltopic", this);
206
         IdentityManager.getGlobalConfig().addChangeListener(
201
         IdentityManager.getGlobalConfig().addChangeListener(
207
                 controller.getDomain(), "hideEmptyTopicBar", this);
202
                 controller.getDomain(), "hideEmptyTopicBar", this);
203
+        
204
+        topicText.setFocusable(false);
205
+        topicText.setEditable(false);
206
+        topicCancel.setVisible(false);
208
         setColours();
207
         setColours();
209
-        ((DefaultStyledDocument) topicText.getDocument()).setCharacterAttributes(
210
-                0, Integer.MAX_VALUE, as, true);
211
     }
208
     }
212
 
209
 
213
     /** {@inheritDoc} */
210
     /** {@inheritDoc} */
225
             return;
222
             return;
226
         }
223
         }
227
         topicText.setText("");
224
         topicText.setText("");
228
-        setAttributes();
229
-        ((DefaultStyledDocument) topicText.getDocument()).setCharacterAttributes(
230
-                0, Integer.MAX_VALUE, as, true);
231
         if (channel.getCurrentTopic() != null) {
225
         if (channel.getCurrentTopic() != null) {
232
             Styliser.addStyledString((StyledDocument) topicText.getDocument(),
226
             Styliser.addStyledString((StyledDocument) topicText.getDocument(),
233
                     new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.getHex(
227
                     new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.getHex(
261
             } else {
255
             } else {
262
                 topicText.setVisible(false);
256
                 topicText.setVisible(false);
263
                 topicText.setText("");
257
                 topicText.setText("");
264
-                setAttributes();
265
-                ((DefaultStyledDocument) topicText.getDocument()).
266
-                        setCharacterAttributes(
267
-                        0, Integer.MAX_VALUE, as, true);
268
                 if (channel.getCurrentTopic() != null) {
258
                 if (channel.getCurrentTopic() != null) {
269
                     topicText.setText(channel.getCurrentTopic().getTopic());
259
                     topicText.setText(channel.getCurrentTopic().getTopic());
270
                 }
260
                 }
513
     @Override
503
     @Override
514
     public void insertUpdate(final DocumentEvent e) {
504
     public void insertUpdate(final DocumentEvent e) {
515
         validateTopic();
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
     /** {@inheritDoc} */
520
     /** {@inheritDoc} */

Ładowanie…
Anuluj
Zapisz