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