|
@@ -19,17 +19,20 @@
|
19
|
19
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
20
|
* SOFTWARE.
|
21
|
21
|
*/
|
|
22
|
+
|
22
|
23
|
package com.dmdirc.addons.ui_swing.textpane;
|
23
|
24
|
|
24
|
25
|
import com.dmdirc.config.ConfigManager;
|
25
|
26
|
import com.dmdirc.interfaces.ConfigChangeListener;
|
26
|
27
|
import com.dmdirc.util.RollingList;
|
|
28
|
+import java.awt.Font;
|
27
|
29
|
|
28
|
30
|
import java.io.Serializable;
|
29
|
31
|
import java.text.AttributedCharacterIterator;
|
30
|
32
|
import java.text.AttributedString;
|
31
|
33
|
import java.util.ArrayList;
|
32
|
34
|
import java.util.List;
|
|
35
|
+import javax.swing.UIManager;
|
33
|
36
|
|
34
|
37
|
import javax.swing.event.EventListenerList;
|
35
|
38
|
|
|
@@ -54,6 +57,10 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
54
|
57
|
private RollingList<AttributedString> cachedStrings;
|
55
|
58
|
/** Configuration manager. */
|
56
|
59
|
private ConfigManager config;
|
|
60
|
+ /** Font size. */
|
|
61
|
+ private int fontSize;
|
|
62
|
+ /** Font name. */
|
|
63
|
+ private String fontName;
|
57
|
64
|
|
58
|
65
|
/**
|
59
|
66
|
* Creates a new instance of IRCDocument.
|
|
@@ -67,6 +74,11 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
67
|
74
|
|
68
|
75
|
cachedLines = new RollingList<Line>(50);
|
69
|
76
|
cachedStrings = new RollingList<AttributedString>(50);
|
|
77
|
+
|
|
78
|
+ setCachedSettings();
|
|
79
|
+
|
|
80
|
+ config.addChangeListener("ui", "textPaneFontSize", this);
|
|
81
|
+ config.addChangeListener("ui", "textPaneFontName", this);
|
70
|
82
|
}
|
71
|
83
|
|
72
|
84
|
/**
|
|
@@ -75,7 +87,9 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
75
|
87
|
* @return Number of lines
|
76
|
88
|
*/
|
77
|
89
|
public int getNumLines() {
|
78
|
|
- return lines.size();
|
|
90
|
+ synchronized (lines) {
|
|
91
|
+ return lines.size();
|
|
92
|
+ }
|
79
|
93
|
}
|
80
|
94
|
|
81
|
95
|
/**
|
|
@@ -86,7 +100,9 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
86
|
100
|
* @return Line at the specified number or null
|
87
|
101
|
*/
|
88
|
102
|
Line getLine(final int lineNumber) {
|
89
|
|
- return lines.get(lineNumber);
|
|
103
|
+ synchronized (lines) {
|
|
104
|
+ return lines.get(lineNumber);
|
|
105
|
+ }
|
90
|
106
|
}
|
91
|
107
|
|
92
|
108
|
/**
|
|
@@ -96,7 +112,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
96
|
112
|
*/
|
97
|
113
|
public void addText(final String[] text) {
|
98
|
114
|
synchronized (lines) {
|
99
|
|
- lines.add(new Line(text, config));
|
|
115
|
+ lines.add(new Line(text, fontSize, fontName));
|
100
|
116
|
fireLineAdded(lines.indexOf(text));
|
101
|
117
|
}
|
102
|
118
|
}
|
|
@@ -109,7 +125,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
109
|
125
|
*/
|
110
|
126
|
public void addText(final String[] text, final int lineHeight) {
|
111
|
127
|
synchronized (lines) {
|
112
|
|
- lines.add(new Line(text, config, lineHeight));
|
|
128
|
+ lines.add(new Line(text, lineHeight, fontName));
|
113
|
129
|
fireLineAdded(lines.indexOf(text));
|
114
|
130
|
}
|
115
|
131
|
}
|
|
@@ -123,7 +139,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
123
|
139
|
synchronized (lines) {
|
124
|
140
|
final int start = lines.size();
|
125
|
141
|
for (String[] string : text) {
|
126
|
|
- lines.add(new Line(string, config));
|
|
142
|
+ lines.add(new Line(string, fontSize, fontName));
|
127
|
143
|
}
|
128
|
144
|
fireLinesAdded(start, text.size());
|
129
|
145
|
}
|
|
@@ -135,13 +151,14 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
135
|
151
|
* @param text stylised string to add to the text
|
136
|
152
|
* @param lineHeights line heights for the new lines
|
137
|
153
|
*/
|
138
|
|
- public void addText(final List<String[]> text, final List<Integer> lineHeights) {
|
|
154
|
+ public void addText(final List<String[]> text,
|
|
155
|
+ final List<Integer> lineHeights) {
|
139
|
156
|
synchronized (lines) {
|
140
|
157
|
final int start = lines.size();
|
141
|
|
- for (int i = 0; i < text.size() ; i++) {
|
|
158
|
+ for (int i = 0; i < text.size(); i++) {
|
142
|
159
|
final String[] string = text.get(i);
|
143
|
160
|
final int lineHeight = lineHeights.get(i);
|
144
|
|
- lines.add(new Line(string, config, lineHeight));
|
|
161
|
+ lines.add(new Line(string, lineHeight, fontName));
|
145
|
162
|
}
|
146
|
163
|
fireLinesAdded(start, text.size());
|
147
|
164
|
}
|
|
@@ -247,7 +264,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
247
|
264
|
}
|
248
|
265
|
}
|
249
|
266
|
}
|
250
|
|
-
|
|
267
|
+
|
251
|
268
|
/**
|
252
|
269
|
* fires the need repaint method on all listeners.
|
253
|
270
|
*/
|
|
@@ -269,19 +286,21 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
269
|
286
|
* @return Styled line
|
270
|
287
|
*/
|
271
|
288
|
AttributedCharacterIterator getStyledLine(final Line line) {
|
272
|
|
- AttributedString styledLine = null;
|
273
|
|
- if (cachedLines.contains(line)) {
|
274
|
|
- final int index = cachedLines.getList().indexOf(line);
|
275
|
|
- styledLine = cachedStrings.get(index);
|
276
|
|
- }
|
|
289
|
+ synchronized (lines) {
|
|
290
|
+ AttributedString styledLine = null;
|
|
291
|
+ if (cachedLines.contains(line)) {
|
|
292
|
+ final int index = cachedLines.getList().indexOf(line);
|
|
293
|
+ styledLine = cachedStrings.get(index);
|
|
294
|
+ }
|
277
|
295
|
|
278
|
|
- if (styledLine == null) {
|
279
|
|
- styledLine = line.getStyled();
|
280
|
|
- cachedLines.add(line);
|
281
|
|
- cachedStrings.add(styledLine);
|
282
|
|
- }
|
|
296
|
+ if (styledLine == null) {
|
|
297
|
+ styledLine = line.getStyled();
|
|
298
|
+ cachedLines.add(line);
|
|
299
|
+ cachedStrings.add(styledLine);
|
|
300
|
+ }
|
283
|
301
|
|
284
|
|
- return styledLine.getIterator();
|
|
302
|
+ return styledLine.getIterator();
|
|
303
|
+ }
|
285
|
304
|
}
|
286
|
305
|
|
287
|
306
|
/**
|
|
@@ -295,7 +314,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
295
|
314
|
public AttributedCharacterIterator getStyledLine(final int line) {
|
296
|
315
|
return getStyledLine(getLine(line));
|
297
|
316
|
}
|
298
|
|
-
|
|
317
|
+
|
299
|
318
|
/**
|
300
|
319
|
* Returns the line height of the specified line
|
301
|
320
|
*
|
|
@@ -304,9 +323,9 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
304
|
323
|
* @return Line height
|
305
|
324
|
*/
|
306
|
325
|
int getLineHeight(final Line line) {
|
307
|
|
- return line.getHeight();
|
|
326
|
+ return line.getFontSize();
|
308
|
327
|
}
|
309
|
|
-
|
|
328
|
+
|
310
|
329
|
/**
|
311
|
330
|
* Returns the line height of the specified line
|
312
|
331
|
*
|
|
@@ -315,14 +334,35 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
315
|
334
|
* @return Line height
|
316
|
335
|
*/
|
317
|
336
|
public int getLineHeight(final int line) {
|
318
|
|
- return getLineHeight(getLine(line));
|
|
337
|
+ return getLineHeight(getLine(line));
|
|
338
|
+ }
|
|
339
|
+
|
|
340
|
+ private void setCachedSettings() {
|
|
341
|
+ final Font defaultFont = UIManager.getFont("TextPane.font");
|
|
342
|
+ if (config.hasOptionString("ui", "textPaneFontName")) {
|
|
343
|
+ fontName = config.getOption("ui", "textPaneFontName");
|
|
344
|
+ } else {
|
|
345
|
+ fontName = defaultFont.getName();
|
|
346
|
+ }
|
|
347
|
+ if (config.hasOptionString("ui", "textPaneFontSize")) {
|
|
348
|
+ fontSize = config.getOptionInt("ui", "textPaneFontSize");
|
|
349
|
+ } else {
|
|
350
|
+ fontSize = defaultFont.getSize();
|
|
351
|
+ }
|
319
|
352
|
}
|
320
|
353
|
|
321
|
354
|
/** {@inheritDoc} */
|
322
|
355
|
@Override
|
323
|
356
|
public void configChanged(final String domain, final String key) {
|
|
357
|
+ setCachedSettings();
|
324
|
358
|
cachedLines.clear();
|
325
|
359
|
cachedStrings.clear();
|
|
360
|
+ synchronized (lines) {
|
|
361
|
+ for (Line line : lines) {
|
|
362
|
+ line.setFontName(fontName);
|
|
363
|
+ line.setFontSize(fontSize);
|
|
364
|
+ }
|
|
365
|
+ }
|
326
|
366
|
fireRepaintNeeded();
|
327
|
367
|
}
|
328
|
368
|
}
|