|
@@ -22,7 +22,7 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.messages;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.FrameContainer;
|
|
25
|
+import com.dmdirc.config.ConfigManager;
|
26
|
26
|
import com.dmdirc.interfaces.ConfigChangeListener;
|
27
|
27
|
import com.dmdirc.util.ListenerList;
|
28
|
28
|
import com.dmdirc.util.RollingList;
|
|
@@ -52,11 +52,13 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
52
|
52
|
/** Listener list. */
|
53
|
53
|
private final ListenerList listeners;
|
54
|
54
|
/** Cached lines. */
|
55
|
|
- private transient RollingList<Line> cachedLines;
|
|
55
|
+ private final RollingList<Line> cachedLines;
|
56
|
56
|
/** Cached attributed strings. */
|
57
|
|
- private transient RollingList<AttributedString> cachedStrings;
|
58
|
|
- /** Container that owns this document. */
|
59
|
|
- private final FrameContainer<?> container;
|
|
57
|
+ private final RollingList<AttributedString> cachedStrings;
|
|
58
|
+ /** Config Manager for getting settings. */
|
|
59
|
+ private final ConfigManager configManager;
|
|
60
|
+ /** This document's styliser. */
|
|
61
|
+ private final Styliser styliser;
|
60
|
62
|
/** Font size. */
|
61
|
63
|
private int fontSize;
|
62
|
64
|
/** Font name. */
|
|
@@ -67,26 +69,25 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
67
|
69
|
/**
|
68
|
70
|
* Creates a new instance of IRCDocument.
|
69
|
71
|
*
|
70
|
|
- * @param container The container that owns this document
|
|
72
|
+ * @param configManager Config Manager for required settings.
|
|
73
|
+ * @param styliser Styliser to style text
|
71
|
74
|
* @since 0.6.3
|
72
|
75
|
*/
|
73
|
|
- public IRCDocument(final FrameContainer<?> container) {
|
74
|
|
- this.container = container;
|
|
76
|
+ public IRCDocument(final ConfigManager configManager,
|
|
77
|
+ final Styliser styliser) {
|
|
78
|
+ this.configManager = configManager;
|
|
79
|
+ this.styliser = styliser;
|
75
|
80
|
|
76
|
81
|
lines = new ArrayList<Line>();
|
77
|
82
|
listeners = new ListenerList();
|
78
|
83
|
|
79
|
84
|
cachedLines = new RollingList<Line>(50);
|
80
|
85
|
cachedStrings = new RollingList<AttributedString>(50);
|
81
|
|
- frameBufferSize = container.getConfigManager().getOptionInt("ui",
|
82
|
|
- "frameBufferSize");
|
|
86
|
+ frameBufferSize = configManager.getOptionInt("ui", "frameBufferSize");
|
83
|
87
|
|
84
|
|
- container.getConfigManager().addChangeListener("ui", "textPaneFontSize",
|
85
|
|
- this);
|
86
|
|
- container.getConfigManager().addChangeListener("ui", "textPaneFontName",
|
87
|
|
- this);
|
88
|
|
- container.getConfigManager().addChangeListener("ui", "frameBufferSize",
|
89
|
|
- this);
|
|
88
|
+ configManager.addChangeListener("ui", "textPaneFontSize", this);
|
|
89
|
+ configManager.addChangeListener("ui", "textPaneFontName", this);
|
|
90
|
+ configManager.addChangeListener("ui", "frameBufferSize", this);
|
90
|
91
|
|
91
|
92
|
setCachedSettings();
|
92
|
93
|
}
|
|
@@ -123,7 +124,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
123
|
124
|
public void addText(final String[] text) {
|
124
|
125
|
final int index;
|
125
|
126
|
synchronized (lines) {
|
126
|
|
- final Line line = new Line(container.getStyliser(), text, fontSize, fontName);
|
|
127
|
+ final Line line = new Line(styliser, text, fontSize, fontName);
|
127
|
128
|
lines.add(line);
|
128
|
129
|
index = lines.indexOf(line);
|
129
|
130
|
}
|
|
@@ -139,7 +140,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
139
|
140
|
public void addText(final String[] text, final int lineHeight) {
|
140
|
141
|
final int index;
|
141
|
142
|
synchronized (lines) {
|
142
|
|
- final Line line = new Line(container.getStyliser(), text, lineHeight, fontName);
|
|
143
|
+ final Line line = new Line(styliser, text, lineHeight, fontName);
|
143
|
144
|
lines.add(line);
|
144
|
145
|
index = lines.indexOf(line);
|
145
|
146
|
}
|
|
@@ -156,7 +157,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
156
|
157
|
synchronized (lines) {
|
157
|
158
|
start = lines.size();
|
158
|
159
|
for (String[] string : text) {
|
159
|
|
- lines.add(new Line(container.getStyliser(), string, fontSize, fontName));
|
|
160
|
+ lines.add(new Line(styliser, string, fontSize, fontName));
|
160
|
161
|
}
|
161
|
162
|
}
|
162
|
163
|
fireLinesAdded(start, text.size());
|
|
@@ -176,7 +177,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
176
|
177
|
for (int i = 0; i < text.size(); i++) {
|
177
|
178
|
final String[] string = text.get(i);
|
178
|
179
|
final int lineHeight = lineHeights.get(i);
|
179
|
|
- lines.add(new Line(container.getStyliser(), string, lineHeight, fontName));
|
|
180
|
+ lines.add(new Line(styliser, string, lineHeight, fontName));
|
180
|
181
|
}
|
181
|
182
|
}
|
182
|
183
|
fireLinesAdded(start, text.size());
|
|
@@ -238,7 +239,8 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
238
|
239
|
* @param index Index of the added line
|
239
|
240
|
*/
|
240
|
241
|
protected void fireLineAdded(final int index) {
|
241
|
|
- for (IRCDocumentListener listener : listeners.get(IRCDocumentListener.class)) {
|
|
242
|
+ for (IRCDocumentListener listener
|
|
243
|
+ : listeners.get(IRCDocumentListener.class)) {
|
242
|
244
|
listener.lineAdded(index, lines.size());
|
243
|
245
|
}
|
244
|
246
|
trim(frameBufferSize);
|
|
@@ -251,7 +253,8 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
251
|
253
|
* @param size Number of lines added
|
252
|
254
|
*/
|
253
|
255
|
protected void fireLinesAdded(final int index, final int size) {
|
254
|
|
- for (IRCDocumentListener listener : listeners.get(IRCDocumentListener.class)) {
|
|
256
|
+ for (IRCDocumentListener listener
|
|
257
|
+ : listeners.get(IRCDocumentListener.class)) {
|
255
|
258
|
listener.linesAdded(index, size, lines.size());
|
256
|
259
|
}
|
257
|
260
|
trim(frameBufferSize);
|
|
@@ -264,7 +267,8 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
264
|
267
|
* @param trimedLines Number of trimmed lines
|
265
|
268
|
*/
|
266
|
269
|
protected void fireTrimmed(final int newSize, final int trimedLines) {
|
267
|
|
- for (IRCDocumentListener listener : listeners.get(IRCDocumentListener.class)) {
|
|
270
|
+ for (IRCDocumentListener listener
|
|
271
|
+ : listeners.get(IRCDocumentListener.class)) {
|
268
|
272
|
listener.trimmed(newSize, trimedLines);
|
269
|
273
|
}
|
270
|
274
|
}
|
|
@@ -273,7 +277,8 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
273
|
277
|
* fires the cleared method on all listeners.
|
274
|
278
|
*/
|
275
|
279
|
protected void fireCleared() {
|
276
|
|
- for (IRCDocumentListener listener : listeners.get(IRCDocumentListener.class)) {
|
|
280
|
+ for (IRCDocumentListener listener
|
|
281
|
+ : listeners.get(IRCDocumentListener.class)) {
|
277
|
282
|
listener.cleared();
|
278
|
283
|
}
|
279
|
284
|
}
|
|
@@ -282,7 +287,8 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
282
|
287
|
* fires the need repaint method on all listeners.
|
283
|
288
|
*/
|
284
|
289
|
protected void fireRepaintNeeded() {
|
285
|
|
- for (IRCDocumentListener listener : listeners.get(IRCDocumentListener.class)) {
|
|
290
|
+ for (IRCDocumentListener listener
|
|
291
|
+ : listeners.get(IRCDocumentListener.class)) {
|
286
|
292
|
listener.repaintNeeded();
|
287
|
293
|
}
|
288
|
294
|
}
|
|
@@ -326,7 +332,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
326
|
332
|
}
|
327
|
333
|
|
328
|
334
|
/**
|
329
|
|
- * Returns the line height of the specified line
|
|
335
|
+ * Returns the line height of the specified line.
|
330
|
336
|
*
|
331
|
337
|
* @param line Line
|
332
|
338
|
*
|
|
@@ -337,7 +343,7 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
337
|
343
|
}
|
338
|
344
|
|
339
|
345
|
/**
|
340
|
|
- * Returns the line height of the specified line
|
|
346
|
+ * Returns the line height of the specified.
|
341
|
347
|
*
|
342
|
348
|
* @param line Line
|
343
|
349
|
*
|
|
@@ -347,20 +353,22 @@ public class IRCDocument implements Serializable, ConfigChangeListener {
|
347
|
353
|
return getLineHeight(getLine(line));
|
348
|
354
|
}
|
349
|
355
|
|
|
356
|
+ /**
|
|
357
|
+ * Sets all the cached settings in this document.
|
|
358
|
+ */
|
350
|
359
|
private void setCachedSettings() {
|
351
|
360
|
final Font defaultFont = UIManager.getFont("TextPane.font");
|
352
|
|
- if (container.getConfigManager().hasOptionString("ui", "textPaneFontName")) {
|
353
|
|
- fontName = container.getConfigManager().getOption("ui", "textPaneFontName");
|
|
361
|
+ if (configManager.hasOptionString("ui", "textPaneFontName")) {
|
|
362
|
+ fontName = configManager.getOption("ui", "textPaneFontName");
|
354
|
363
|
} else {
|
355
|
364
|
fontName = defaultFont.getName();
|
356
|
365
|
}
|
357
|
|
- if (container.getConfigManager().hasOptionString("ui", "textPaneFontSize")) {
|
358
|
|
- fontSize = container.getConfigManager().getOptionInt("ui", "textPaneFontSize");
|
|
366
|
+ if (configManager.hasOptionString("ui", "textPaneFontSize")) {
|
|
367
|
+ fontSize = configManager.getOptionInt("ui", "textPaneFontSize");
|
359
|
368
|
} else {
|
360
|
369
|
fontSize = defaultFont.getSize();
|
361
|
370
|
}
|
362
|
|
- frameBufferSize = container.getConfigManager().getOptionInt("ui",
|
363
|
|
- "frameBufferSize");
|
|
371
|
+ frameBufferSize = configManager.getOptionInt("ui", "frameBufferSize");
|
364
|
372
|
trim(frameBufferSize);
|
365
|
373
|
}
|
366
|
374
|
|