|
@@ -22,18 +22,18 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.ui_swing.textpane;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.config.ConfigManager;
|
|
25
|
+import com.dmdirc.FrameContainer;
|
26
|
26
|
import com.dmdirc.interfaces.ConfigChangeListener;
|
27
|
27
|
import com.dmdirc.util.RollingList;
|
28
|
|
-import java.awt.Font;
|
29
|
28
|
|
|
29
|
+import java.awt.Font;
|
30
|
30
|
import java.io.Serializable;
|
31
|
31
|
import java.text.AttributedCharacterIterator;
|
32
|
32
|
import java.text.AttributedString;
|
33
|
33
|
import java.util.ArrayList;
|
34
|
34
|
import java.util.List;
|
35
|
|
-import javax.swing.UIManager;
|
36
|
35
|
|
|
36
|
+import javax.swing.UIManager;
|
37
|
37
|
import javax.swing.event.EventListenerList;
|
38
|
38
|
|
39
|
39
|
/**
|
|
@@ -55,8 +55,8 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
55
|
55
|
private RollingList<Line> cachedLines;
|
56
|
56
|
/** Cached attributed strings. */
|
57
|
57
|
private RollingList<AttributedString> cachedStrings;
|
58
|
|
- /** Configuration manager. */
|
59
|
|
- private ConfigManager config;
|
|
58
|
+ /** Container that owns this document. */
|
|
59
|
+ private final FrameContainer container;
|
60
|
60
|
/** Font size. */
|
61
|
61
|
private int fontSize;
|
62
|
62
|
/** Font name. */
|
|
@@ -65,20 +65,22 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
65
|
65
|
/**
|
66
|
66
|
* Creates a new instance of IRCDocument.
|
67
|
67
|
*
|
68
|
|
- * @param config Document's config manager
|
|
68
|
+ * @param container The container that owns this document
|
|
69
|
+ * @since 0.6.3
|
69
|
70
|
*/
|
70
|
|
- public IRCDocument(final ConfigManager config) {
|
71
|
|
- this.config = config;
|
|
71
|
+ public IRCDocument(final FrameContainer container) {
|
|
72
|
+ this.container = container;
|
|
73
|
+
|
72
|
74
|
lines = new ArrayList<Line>();
|
73
|
75
|
listeners = new EventListenerList();
|
74
|
76
|
|
75
|
77
|
cachedLines = new RollingList<Line>(50);
|
76
|
78
|
cachedStrings = new RollingList<AttributedString>(50);
|
77
|
79
|
|
78
|
|
- setCachedSettings();
|
|
80
|
+ container.getConfigManager().addChangeListener("ui", "textPaneFontSize", this);
|
|
81
|
+ container.getConfigManager().addChangeListener("ui", "textPaneFontName", this);
|
79
|
82
|
|
80
|
|
- config.addChangeListener("ui", "textPaneFontSize", this);
|
81
|
|
- config.addChangeListener("ui", "textPaneFontName", this);
|
|
83
|
+ setCachedSettings();
|
82
|
84
|
}
|
83
|
85
|
|
84
|
86
|
/**
|
|
@@ -112,7 +114,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
112
|
114
|
*/
|
113
|
115
|
public void addText(final String[] text) {
|
114
|
116
|
synchronized (lines) {
|
115
|
|
- lines.add(new Line(text, fontSize, fontName));
|
|
117
|
+ lines.add(new Line(container.getStyliser(), text, fontSize, fontName));
|
116
|
118
|
fireLineAdded(lines.indexOf(text));
|
117
|
119
|
}
|
118
|
120
|
}
|
|
@@ -125,7 +127,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
125
|
127
|
*/
|
126
|
128
|
public void addText(final String[] text, final int lineHeight) {
|
127
|
129
|
synchronized (lines) {
|
128
|
|
- lines.add(new Line(text, lineHeight, fontName));
|
|
130
|
+ lines.add(new Line(container.getStyliser(), text, lineHeight, fontName));
|
129
|
131
|
fireLineAdded(lines.indexOf(text));
|
130
|
132
|
}
|
131
|
133
|
}
|
|
@@ -139,7 +141,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
139
|
141
|
synchronized (lines) {
|
140
|
142
|
final int start = lines.size();
|
141
|
143
|
for (String[] string : text) {
|
142
|
|
- lines.add(new Line(string, fontSize, fontName));
|
|
144
|
+ lines.add(new Line(container.getStyliser(), string, fontSize, fontName));
|
143
|
145
|
}
|
144
|
146
|
fireLinesAdded(start, text.size());
|
145
|
147
|
}
|
|
@@ -158,7 +160,7 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
158
|
160
|
for (int i = 0; i < text.size(); i++) {
|
159
|
161
|
final String[] string = text.get(i);
|
160
|
162
|
final int lineHeight = lineHeights.get(i);
|
161
|
|
- lines.add(new Line(string, lineHeight, fontName));
|
|
163
|
+ lines.add(new Line(container.getStyliser(), string, lineHeight, fontName));
|
162
|
164
|
}
|
163
|
165
|
fireLinesAdded(start, text.size());
|
164
|
166
|
}
|
|
@@ -339,13 +341,13 @@ public final class IRCDocument implements Serializable, ConfigChangeListener {
|
339
|
341
|
|
340
|
342
|
private void setCachedSettings() {
|
341
|
343
|
final Font defaultFont = UIManager.getFont("TextPane.font");
|
342
|
|
- if (config.hasOptionString("ui", "textPaneFontName")) {
|
343
|
|
- fontName = config.getOption("ui", "textPaneFontName");
|
|
344
|
+ if (container.getConfigManager().hasOptionString("ui", "textPaneFontName")) {
|
|
345
|
+ fontName = container.getConfigManager().getOption("ui", "textPaneFontName");
|
344
|
346
|
} else {
|
345
|
347
|
fontName = defaultFont.getName();
|
346
|
348
|
}
|
347
|
|
- if (config.hasOptionString("ui", "textPaneFontSize")) {
|
348
|
|
- fontSize = config.getOptionInt("ui", "textPaneFontSize");
|
|
349
|
+ if (container.getConfigManager().hasOptionString("ui", "textPaneFontSize")) {
|
|
350
|
+ fontSize = container.getConfigManager().getOptionInt("ui", "textPaneFontSize");
|
349
|
351
|
} else {
|
350
|
352
|
fontSize = defaultFont.getSize();
|
351
|
353
|
}
|