Browse Source

Show and hide topic bar appropriately.

Change-Id: Icafe5d6cc14f9afc25c5ee9cb27cc160addc12ba
Fixes-Issue: CLIENT-401
Reviewed-on: http://gerrit.dmdirc.com/2637
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.8
Greg Holmes 10 years ago
parent
commit
b982c81d66

+ 39
- 28
src/com/dmdirc/addons/ui_swing/components/TopicBar.java View File

@@ -90,6 +90,12 @@ public class TopicBar extends JComponent implements ActionListener,
90 90
     private Color backgroundColour;
91 91
     /** Error icon. */
92 92
     private final JLabel errorIcon;
93
+    /** Show the topic bar? */
94
+    private boolean showBar;
95
+    /** Show the full topic, or truncate? */
96
+    private boolean showFull;
97
+    /** Hide topic bar when topic is empty? */
98
+    private boolean hideEmpty;
93 99
 
94 100
     /**
95 101
      * Instantiates a new topic bar.
@@ -106,10 +112,10 @@ public class TopicBar extends JComponent implements ActionListener,
106 112
         topicText = new TextPaneInputField(channelFrame.getController(),
107 113
                 parentWindow);
108 114
         topicLengthMax = channel.getMaxTopicLength();
115
+        updateOptions();
109 116
         errorIcon = new JLabel(channelFrame.getIconManager()
110 117
                 .getIcon("input-error"));
111
-        topicText.setEditorKit(new WrapEditorKit(channel.getConfigManager()
112
-                .getOptionBool(controller.getDomain(), "showfulltopic")));
118
+        topicText.setEditorKit(new WrapEditorKit(showFull));
113 119
         ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
114 120
                 new NewlinesDocumentFilter());
115 121
 
@@ -150,7 +156,6 @@ public class TopicBar extends JComponent implements ActionListener,
150 156
                 "enterButton");
151 157
         topicText.getActionMap().put("enterButton", new AbstractAction(
152 158
                 "enterButton") {
153
-
154 159
             /**
155 160
              * A version number for this class. It should be changed whenever the class
156 161
              * structure is changed (or anything else that would prevent serialized
@@ -168,7 +173,6 @@ public class TopicBar extends JComponent implements ActionListener,
168 173
                 "escapeButton");
169 174
         topicText.getActionMap().put("escapeButton", new AbstractAction(
170 175
                 "escapeButton") {
171
-
172 176
             private static final long serialVersionUID = 1;
173 177
 
174 178
             /** {@inheritDoc} */
@@ -192,7 +196,10 @@ public class TopicBar extends JComponent implements ActionListener,
192 196
                 controller.getDomain(), "showfulltopic", this);
193 197
         controller.getGlobalConfig().addChangeListener(
194 198
                 controller.getDomain(), "hideEmptyTopicBar", this);
199
+        controller.getGlobalConfig().addChangeListener(
200
+                controller.getDomain(), "showtopicbar", this);
195 201
 
202
+        setVisible(true);
196 203
         topicText.setFocusable(false);
197 204
         topicText.setEditable(false);
198 205
         topicCancel.setVisible(false);
@@ -204,7 +211,6 @@ public class TopicBar extends JComponent implements ActionListener,
204 211
     @Override
205 212
     public final void topicChanged(final Channel channel, final Topic topic) {
206 213
         UIUtilities.invokeLater(new Runnable() {
207
-
208 214
             /** {@inheritDoc} */
209 215
             @Override
210 216
             public void run() {
@@ -216,15 +222,10 @@ public class TopicBar extends JComponent implements ActionListener,
216 222
                     channel.getStyliser().addStyledString(
217 223
                             (StyledDocument) topicText.getDocument(),
218 224
                             new String[]{Styliser.CODE_HEXCOLOUR
219
-                                    + UIUtilities.getHex(foregroundColour)
220
-                                    + channel.getCurrentTopic().getTopic(), },
225
+                        + UIUtilities.getHex(foregroundColour)
226
+                        + channel.getCurrentTopic().getTopic(),},
221 227
                             as);
222 228
                 }
223
-                if (channel.getConfigManager().getOptionBool(controller.
224
-                        getDomain(),
225
-                        "hideEmptyTopicBar")) {
226
-                    setVisible(topicText.getDocument().getLength() != 0);
227
-                }
228 229
                 topicText.setCaretPosition(0);
229 230
                 validateTopic();
230 231
                 setVisible(false);
@@ -233,6 +234,20 @@ public class TopicBar extends JComponent implements ActionListener,
233 234
         });
234 235
     }
235 236
 
237
+    /** {@inheritDoc} */
238
+    @Override
239
+    public void setVisible(final boolean visibility) {
240
+        if (!showBar || !visibility) {
241
+            super.setVisible(false);
242
+            return;
243
+        }
244
+        if (hideEmpty) {
245
+            super.setVisible(topicText.getDocument().getLength() != 0);
246
+            return;
247
+        }
248
+        super.setVisible(true);
249
+    }
250
+
236 251
     /**
237 252
      * {@inheritDoc}
238 253
      *
@@ -373,7 +388,6 @@ public class TopicBar extends JComponent implements ActionListener,
373 388
      */
374 389
     public void setCaretPosition(final int position) {
375 390
         UIUtilities.invokeLater(new Runnable() {
376
-
377 391
             /** {@inheritDoc} */
378 392
             @Override
379 393
             public void run() {
@@ -389,7 +403,6 @@ public class TopicBar extends JComponent implements ActionListener,
389 403
      */
390 404
     public void setCaretColor(final Color optionColour) {
391 405
         UIUtilities.invokeLater(new Runnable() {
392
-
393 406
             /** {@inheritDoc} */
394 407
             @Override
395 408
             public void run() {
@@ -406,7 +419,6 @@ public class TopicBar extends JComponent implements ActionListener,
406 419
     @Override
407 420
     public void setForeground(final Color optionColour) {
408 421
         UIUtilities.invokeLater(new Runnable() {
409
-
410 422
             /** {@inheritDoc} */
411 423
             @Override
412 424
             public void run() {
@@ -422,7 +434,6 @@ public class TopicBar extends JComponent implements ActionListener,
422 434
      */
423 435
     public void setDisabledTextColour(final Color optionColour) {
424 436
         UIUtilities.invokeLater(new Runnable() {
425
-
426 437
             /** {@inheritDoc} */
427 438
             @Override
428 439
             public void run() {
@@ -439,7 +450,6 @@ public class TopicBar extends JComponent implements ActionListener,
439 450
     @Override
440 451
     public void setBackground(final Color optionColour) {
441 452
         UIUtilities.invokeLater(new Runnable() {
442
-
443 453
             /** {@inheritDoc} */
444 454
             @Override
445 455
             public void run() {
@@ -451,21 +461,24 @@ public class TopicBar extends JComponent implements ActionListener,
451 461
     /** {@inheritDoc} */
452 462
     @Override
453 463
     public void configChanged(final String domain, final String key) {
464
+        updateOptions();
465
+        setVisible(showBar);
454 466
         if ("showfulltopic".equals(key)) {
455
-            topicText.setEditorKit(new WrapEditorKit(channel.getConfigManager()
456
-                .getOptionBool(controller.getDomain(), "showfulltopic")));
467
+            topicText.setEditorKit(new WrapEditorKit(showFull));
457 468
             ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
458 469
                     new NewlinesDocumentFilter());
459 470
             topicChanged(channel, null);
460 471
         }
461 472
         setColours();
462
-        if ("hideEmptyTopicBar".equals(key)) {
463
-            setVisible(true);
464
-            if (channel.getConfigManager().getOptionBool(controller.getDomain(),
465
-                    "hideEmptyTopicBar")) {
466
-                setVisible(topicText.getDocument().getLength() != 0);
467
-            }
468
-        }
473
+    }
474
+
475
+    private void updateOptions() {
476
+        showFull = channel.getConfigManager()
477
+                .getOptionBool(controller.getDomain(), "showfulltopic");
478
+        hideEmpty = channel.getConfigManager()
479
+                .getOptionBool(controller.getDomain(), "hideEmptyTopicBar");
480
+        showBar = channel.getConfigManager()
481
+                .getOptionBool(controller.getDomain(), "showtopicbar");
469 482
     }
470 483
 
471 484
     /**
@@ -480,7 +493,6 @@ public class TopicBar extends JComponent implements ActionListener,
480 493
      */
481 494
     public void validateTopic() {
482 495
         UIUtilities.invokeLater(new Runnable() {
483
-
484 496
             /** {@inheritDoc} */
485 497
             @Override
486 498
             public void run() {
@@ -560,7 +572,6 @@ public class TopicBar extends JComponent implements ActionListener,
560 572
         validateTopic();
561 573
         if (topicText.isEditable()) {
562 574
             SwingUtilities.invokeLater(new Runnable() {
563
-
564 575
                 @Override
565 576
                 public void run() {
566 577
                     applyAttributes();

+ 1
- 11
src/com/dmdirc/addons/ui_swing/components/frames/ChannelFrame.java View File

@@ -27,7 +27,6 @@ import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.ServerState;
28 28
 import com.dmdirc.actions.ActionManager;
29 29
 import com.dmdirc.actions.CoreActionType;
30
-import com.dmdirc.interfaces.actions.ActionType;
31 30
 import com.dmdirc.addons.ui_swing.SwingController;
32 31
 import com.dmdirc.addons.ui_swing.UIUtilities;
33 32
 import com.dmdirc.addons.ui_swing.components.NickList;
@@ -35,6 +34,7 @@ import com.dmdirc.addons.ui_swing.components.SplitPane;
35 34
 import com.dmdirc.addons.ui_swing.components.TopicBar;
36 35
 import com.dmdirc.commandparser.PopupType;
37 36
 import com.dmdirc.config.Identity;
37
+import com.dmdirc.interfaces.actions.ActionType;
38 38
 
39 39
 import java.awt.Dimension;
40 40
 import java.awt.event.ActionEvent;
@@ -86,8 +86,6 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
86 86
 
87 87
         controller.getGlobalConfig().addChangeListener("ui",
88 88
                 "channelSplitPanePosition", this);
89
-        controller.getGlobalConfig().addChangeListener(
90
-                controller.getDomain(), "showtopicbar", this);
91 89
         controller.getGlobalConfig().addChangeListener(
92 90
                 controller.getDomain(), "shownicklist", this);
93 91
         ActionManager.getActionManager().registerListener(this,
@@ -124,8 +122,6 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
124 122
         nicklist = new NickList(this, getContainer().getConfigManager());
125 123
         settingsMI = new JMenuItem("Settings");
126 124
         settingsMI.addActionListener(this);
127
-        topicBar.setVisible(getContainer().getConfigManager().getOptionBool(
128
-                getController().getDomain(), "showtopicbar"));
129 125
 
130 126
         splitPane = new SplitPane(controller.getGlobalConfig(),
131 127
                 SplitPane.Orientation.HORIZONTAL);
@@ -177,7 +173,6 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
177 173
             final int splitPanePosition = getContainer().getConfigManager()
178 174
                     .getOptionInt("ui", "channelSplitPanePosition");
179 175
             UIUtilities.invokeLater(new Runnable() {
180
-
181 176
                 /** {@inheritDoc} */
182 177
                 @Override
183 178
                 public void run() {
@@ -188,10 +183,6 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
188 183
                 }
189 184
             });
190 185
         }
191
-        if ("showtopicbar".equals(key)) {
192
-            topicBar.setVisible(getContainer().getConfigManager().getOptionBool(
193
-                    getController().getDomain(), "showtopicbar"));
194
-        }
195 186
         if ("shownicklist".equals(key)) {
196 187
             if (getContainer().getConfigManager().getOptionBool(getController()
197 188
                     .getDomain(), "shownicklist")) {
@@ -211,7 +202,6 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
211 202
 
212 203
     private void saveSplitPanePosition() {
213 204
         UIUtilities.invokeAndWait(new Runnable() {
214
-
215 205
             /** {@inheritDoc} */
216 206
             @Override
217 207
             public void run() {

Loading…
Cancel
Save