Quellcode durchsuchen

Enable link clicking when wrapping topic. Style fixes.

Fixes issue 4318

Change-Id: I74e2dd9b10f59906165561563d3f383b682ad303
Reviewed-on: http://gerrit.dmdirc.com/1431
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4
Greg Holmes vor 14 Jahren
Ursprung
Commit
eb1379ea25

+ 52
- 42
src/com/dmdirc/addons/ui_swing/components/TopicBar.java Datei anzeigen

1
 /*
1
 /*
2
- * 
3
  * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
2
  * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
4
- * 
3
+ *
5
  * Permission is hereby granted, free of charge, to any person obtaining a copy
4
  * Permission is hereby granted, free of charge, to any person obtaining a copy
6
  * of this software and associated documentation files (the "Software"), to deal
5
  * of this software and associated documentation files (the "Software"), to deal
7
  * in the Software without restriction, including without limitation the rights
6
  * in the Software without restriction, including without limitation the rights
8
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
  * copies of the Software, and to permit persons to whom the Software is
8
  * copies of the Software, and to permit persons to whom the Software is
10
  * furnished to do so, subject to the following conditions:
9
  * furnished to do so, subject to the following conditions:
11
- * 
10
+ *
12
  * The above copyright notice and this permission notice shall be included in
11
  * The above copyright notice and this permission notice shall be included in
13
  * all copies or substantial portions of the Software.
12
  * all copies or substantial portions of the Software.
14
- * 
13
+ *
15
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
 import javax.swing.text.SimpleAttributeSet;
59
 import javax.swing.text.SimpleAttributeSet;
61
 import javax.swing.text.StyleConstants;
60
 import javax.swing.text.StyleConstants;
62
 import javax.swing.text.StyledDocument;
61
 import javax.swing.text.StyledDocument;
63
-import javax.swing.text.StyledEditorKit;
64
 
62
 
65
 import net.miginfocom.swing.MigLayout;
63
 import net.miginfocom.swing.MigLayout;
66
 
64
 
84
     /** Cancel button. */
82
     /** Cancel button. */
85
     private final JButton topicCancel;
83
     private final JButton topicCancel;
86
     /** Associated channel. */
84
     /** Associated channel. */
87
-    private Channel channel;
85
+    private final Channel channel;
88
     /** Controller. */
86
     /** Controller. */
89
-    private SwingController controller;
90
-    /** Empty Attrib set. */
87
+    private final SwingController controller;
88
+    /** the maximum length allowed for a topic. */
89
+    private final int topicLengthMax;
90
+    /** Empty Attribute set. */
91
     private SimpleAttributeSet as;
91
     private SimpleAttributeSet as;
92
     /** Foreground Colour. */
92
     /** Foreground Colour. */
93
     private Color foregroundColour;
93
     private Color foregroundColour;
94
     /** Background Colour. */
94
     /** Background Colour. */
95
     private Color backgroundColour;
95
     private Color backgroundColour;
96
-    /** the maximum length allowed for a topic. */
97
-    private int topicLengthMax;
98
     /** Error icon. */
96
     /** Error icon. */
99
     private final JLabel errorIcon;
97
     private final JLabel errorIcon;
100
 
98
 
104
      * @param channelFrame Parent channel frame
102
      * @param channelFrame Parent channel frame
105
      */
103
      */
106
     public TopicBar(final ChannelFrame channelFrame) {
104
     public TopicBar(final ChannelFrame channelFrame) {
105
+        super();
106
+
107
         this.channel = (Channel) channelFrame.getContainer();
107
         this.channel = (Channel) channelFrame.getContainer();
108
         controller = channelFrame.getController();
108
         controller = channelFrame.getController();
109
         topicText = new TextPaneInputField();
109
         topicText = new TextPaneInputField();
110
         topicLengthMax = channel.getMaxTopicLength();
110
         topicLengthMax = channel.getMaxTopicLength();
111
         errorIcon =
111
         errorIcon =
112
                 new JLabel(IconManager.getIconManager().getIcon("input-error"));
112
                 new JLabel(IconManager.getIconManager().getIcon("input-error"));
113
-        if (channelFrame.getContainer().getConfigManager().getOptionBool(
114
-                controller.getDomain(), "showfulltopic")) {
115
-            topicText.setEditorKit(new StyledEditorKit());
116
-        } else {
117
-            topicText.setEditorKit(new WrapEditorKit());
118
-        }
113
+        topicText.setEditorKit(new WrapEditorKit(channel.getConfigManager()
114
+                .getOptionBool(controller.getDomain(), "showfulltopic")));
119
         ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
115
         ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
120
                 new NewlinesDocumentFilter());
116
                 new NewlinesDocumentFilter());
121
 
117
 
137
         sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
133
         sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
138
         sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
134
         sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
139
 
135
 
140
-        setLayout(new MigLayout("fillx, ins 0, hidemode 3"));
136
+        setLayout(new MigLayout("fillx, ins 0, hidemode 3, pack"));
141
         add(sp, "growx, pushx");
137
         add(sp, "growx, pushx");
142
         add(errorIcon, "");
138
         add(errorIcon, "");
143
         add(topicCancel, "");
139
         add(topicCancel, "");
144
         add(topicEdit, "");
140
         add(topicEdit, "");
141
+        //Fix broken layout manager
142
+        invalidate();
143
+        validate();
144
+        invalidate();
145
 
145
 
146
         channel.addTopicChangeListener(this);
146
         channel.addTopicChangeListener(this);
147
         topicText.addActionListener(this);
147
         topicText.addActionListener(this);
156
 
156
 
157
             /** {@inheritDoc} */
157
             /** {@inheritDoc} */
158
             @Override
158
             @Override
159
-            public void actionPerformed(ActionEvent e) {
159
+            public void actionPerformed(final ActionEvent e) {
160
                 commitTopicEdit();
160
                 commitTopicEdit();
161
             }
161
             }
162
         });
162
         });
169
 
169
 
170
             /** {@inheritDoc} */
170
             /** {@inheritDoc} */
171
             @Override
171
             @Override
172
-            public void actionPerformed(ActionEvent e) {
172
+            public void actionPerformed(final ActionEvent e) {
173
                 cancelTopicEdit();
173
                 cancelTopicEdit();
174
             }
174
             }
175
         });
175
         });
198
 
198
 
199
     /** {@inheritDoc} */
199
     /** {@inheritDoc} */
200
     @Override
200
     @Override
201
-    public void topicChanged(final Channel channel, final Topic topic) {
201
+    public final void topicChanged(final Channel channel, final Topic topic) {
202
         UIUtilities.invokeLater(new Runnable() {
202
         UIUtilities.invokeLater(new Runnable() {
203
 
203
 
204
             /** {@inheritDoc} */
204
             /** {@inheritDoc} */
209
                 }
209
                 }
210
                 topicText.setText("");
210
                 topicText.setText("");
211
                 if (channel.getCurrentTopic() != null) {
211
                 if (channel.getCurrentTopic() != null) {
212
-                    channel.getStyliser().addStyledString((StyledDocument) topicText.
213
-                            getDocument(),
214
-                            new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.
215
-                                getHex(
216
-                                foregroundColour) + channel.getCurrentTopic().
217
-                                getTopic(), },
212
+                    channel.getStyliser().addStyledString(
213
+                            (StyledDocument) topicText.getDocument(),
214
+                            new String[]{Styliser.CODE_HEXCOLOUR
215
+                                    + ColourManager.getHex(foregroundColour)
216
+                                    + channel.getCurrentTopic().getTopic(), },
218
                             as);
217
                             as);
219
                 }
218
                 }
220
                 if (channel.getConfigManager().getOptionBool(controller.
219
                 if (channel.getConfigManager().getOptionBool(controller.
251
         }
250
         }
252
     }
251
     }
253
 
252
 
253
+    /**
254
+     * Commits a topic edit to the parent channel.
255
+     */
254
     private void commitTopicEdit() {
256
     private void commitTopicEdit() {
255
         if ((channel.getCurrentTopic() == null && !topicText.getText().isEmpty())
257
         if ((channel.getCurrentTopic() == null && !topicText.getText().isEmpty())
256
                 || (channel.getCurrentTopic() != null
258
                 || (channel.getCurrentTopic() != null
265
         topicCancel.setVisible(false);
267
         topicCancel.setVisible(false);
266
     }
268
     }
267
 
269
 
270
+    /**
271
+     * Sets the topic ready to be edited, changing attributes and focus.
272
+     */
268
     private void setupTopicEdit() {
273
     private void setupTopicEdit() {
269
         topicText.setVisible(false);
274
         topicText.setVisible(false);
270
         topicText.setText("");
275
         topicText.setText("");
280
         topicCancel.setVisible(true);
285
         topicCancel.setVisible(true);
281
     }
286
     }
282
 
287
 
288
+    /**
289
+     * Cancels a topic edit, resetting focus and button states.
290
+     */
283
     private void cancelTopicEdit() {
291
     private void cancelTopicEdit() {
284
         topicText.setFocusable(false);
292
         topicText.setFocusable(false);
285
         topicText.setEditable(false);
293
         topicText.setEditable(false);
297
             if (url == null) {
305
             if (url == null) {
298
                 return;
306
                 return;
299
             }
307
             }
300
-            if (url.startsWith("#")) {
308
+            if (url.charAt(0) == '#') {
301
                 channel.getServer().join(new ChannelJoinRequest(url));
309
                 channel.getServer().join(new ChannelJoinRequest(url));
302
             } else if (url.contains("://")) {
310
             } else if (url.contains("://")) {
303
                 URLHandler.getURLHander().launchApp(e.getDescription());
311
                 URLHandler.getURLHander().launchApp(e.getDescription());
307
         }
315
         }
308
     }
316
     }
309
 
317
 
318
+    /**
319
+     * Load and set colours.
320
+     */
310
     private void setColours() {
321
     private void setColours() {
311
         backgroundColour = channel.getConfigManager().getOptionColour(
322
         backgroundColour = channel.getConfigManager().getOptionColour(
312
                 "ui", "inputbackgroundcolour", "ui", "backgroundcolour");
323
                 "ui", "inputbackgroundcolour", "ui", "backgroundcolour");
319
         setAttributes();
330
         setAttributes();
320
     }
331
     }
321
 
332
 
333
+    /**
334
+     * Sets sensible attributes.
335
+     */
322
     private void setAttributes() {
336
     private void setAttributes() {
323
         as = new SimpleAttributeSet();
337
         as = new SimpleAttributeSet();
324
         StyleConstants.setFontFamily(as, topicText.getFont().getFamily());
338
         StyleConstants.setFontFamily(as, topicText.getFont().getFamily());
330
         StyleConstants.setItalic(as, false);
344
         StyleConstants.setItalic(as, false);
331
     }
345
     }
332
 
346
 
347
+    /**
348
+     * Applies predefined attributes to the topic bar.
349
+     */
333
     private void applyAttributes() {
350
     private void applyAttributes() {
334
         setAttributes();
351
         setAttributes();
335
-        ((DefaultStyledDocument) topicText.getDocument()).setCharacterAttributes(
336
-                0, Integer.MAX_VALUE, as, true);
352
+        ((DefaultStyledDocument) topicText.getDocument())
353
+                .setCharacterAttributes(0, Integer.MAX_VALUE, as, true);
337
     }
354
     }
338
 
355
 
339
     /**
356
     /**
420
 
437
 
421
     /** {@inheritDoc} */
438
     /** {@inheritDoc} */
422
     @Override
439
     @Override
423
-    public void configChanged(String domain, String key) {
440
+    public void configChanged(final String domain, final String key) {
424
         if ("showfulltopic".equals(key)) {
441
         if ("showfulltopic".equals(key)) {
425
-            if (channel.getConfigManager().getOptionBool(controller.getDomain(),
426
-                    "showfulltopic")) {
427
-                topicText.setEditorKit(new StyledEditorKit());
428
-            } else {
429
-                topicText.setEditorKit(new WrapEditorKit());
430
-            }
442
+            topicText.setEditorKit(new WrapEditorKit(channel.getConfigManager()
443
+                .getOptionBool(controller.getDomain(), "showfulltopic")));
431
             ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
444
             ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
432
                     new NewlinesDocumentFilter());
445
                     new NewlinesDocumentFilter());
433
             topicChanged(channel, null);
446
             topicChanged(channel, null);
482
      * @param e Mouse event
495
      * @param e Mouse event
483
      */
496
      */
484
     @Override
497
     @Override
485
-    public void mouseClicked(MouseEvent e) {
486
-        if (e.getClickCount() == 2) {
487
-            if (!topicText.isEditable()) {
488
-                topicEdit.doClick();
489
-            }
498
+    public void mouseClicked(final MouseEvent e) {
499
+        if (e.getClickCount() == 2 && !topicText.isEditable()) {
500
+            topicEdit.doClick();
490
         }
501
         }
491
     }
502
     }
492
 
503
 
557
         validateTopic();
568
         validateTopic();
558
     }
569
     }
559
 }
570
 }
560
-       

+ 33
- 13
src/com/dmdirc/addons/ui_swing/components/text/WrapEditorKit.java Datei anzeigen

31
 public class WrapEditorKit extends StyledEditorKit implements MouseListener,
31
 public class WrapEditorKit extends StyledEditorKit implements MouseListener,
32
         MouseMotionListener {
32
         MouseMotionListener {
33
 
33
 
34
+    /**
35
+     * A version number for this class. It should be changed whenever the class
36
+     * structure is changed (or anything else that would prevent serialized
37
+     * objects being unserialized with the new class).
38
+     */
34
     private static final long serialVersionUID = 1;
39
     private static final long serialVersionUID = 1;
35
     /** Wrap column factory. */
40
     /** Wrap column factory. */
36
-    private ViewFactory defaultFactory = new WrapColumnFactory();
41
+    private final ViewFactory defaultFactory = new WrapColumnFactory();
37
     /** Hand cursor. */
42
     /** Hand cursor. */
38
     private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR);
43
     private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR);
44
+    /** Are we wrapping text? */
45
+    private final boolean wrap;
39
     /** Associated Component. */
46
     /** Associated Component. */
40
     private JEditorPane editorPane;
47
     private JEditorPane editorPane;
41
 
48
 
49
+    /**
50
+     * Initialises a new wrapping editor kit.
51
+     *
52
+     * @param wrapping true iif the text needs to wrap
53
+     */
54
+    public WrapEditorKit(final boolean wrapping) {
55
+        super();
56
+
57
+        wrap = wrapping;
58
+    }
59
+
42
     /** {@inheritDoc} */
60
     /** {@inheritDoc} */
43
     @Override
61
     @Override
44
     public void install(final JEditorPane c) {
62
     public void install(final JEditorPane c) {
60
     /** {@inheritDoc} */
78
     /** {@inheritDoc} */
61
     @Override
79
     @Override
62
     public ViewFactory getViewFactory() {
80
     public ViewFactory getViewFactory() {
63
-        return defaultFactory;
81
+        if (wrap) {
82
+            return super.getViewFactory();
83
+        } else {
84
+            return defaultFactory;
85
+        }
64
     }
86
     }
65
 
87
 
66
     /**
88
     /**
73
         if (editorPane == null) {
95
         if (editorPane == null) {
74
             return;
96
             return;
75
         }
97
         }
76
-        if (!editorPane.isEditable()) {
77
-            if (characterElementAt(e).getAttributes().getAttribute(
78
-                    IRCTextAttribute.HYPERLINK) != null
79
-                    || characterElementAt(e).getAttributes().getAttribute(
80
-                    IRCTextAttribute.CHANNEL) != null
81
-                    || characterElementAt(e).getAttributes().getAttribute(
82
-                    IRCTextAttribute.NICKNAME) != null) {
83
-                editorPane.setCursor(HAND_CURSOR);
84
-                return;
85
-            }
98
+        if (!editorPane.isEditable() && (characterElementAt(e).getAttributes()
99
+                .getAttribute(IRCTextAttribute.HYPERLINK) != null
100
+                || characterElementAt(e).getAttributes().getAttribute(
101
+                IRCTextAttribute.CHANNEL) != null
102
+                || characterElementAt(e).getAttributes().getAttribute(
103
+                IRCTextAttribute.NICKNAME) != null)) {
104
+            editorPane.setCursor(HAND_CURSOR);
105
+            return;
86
         }
106
         }
87
         editorPane.setCursor(Cursor.getDefaultCursor());
107
         editorPane.setCursor(Cursor.getDefaultCursor());
88
     }
108
     }
173
     }
193
     }
174
 
194
 
175
     /**
195
     /**
176
-     * Returns the character element for the positition of the mouse event.
196
+     * Returns the character element for the position of the mouse event.
177
      *
197
      *
178
      * @param e Mouse event to get position from
198
      * @param e Mouse event to get position from
179
      *
199
      *

Laden…
Abbrechen
Speichern