|
@@ -22,6 +22,7 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.ui.swing.textpane;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.FrameContainer;
|
25
|
26
|
import com.dmdirc.logger.ErrorLevel;
|
26
|
27
|
import com.dmdirc.logger.Logger;
|
27
|
28
|
import com.dmdirc.ui.messages.IRCTextAttribute;
|
|
@@ -66,7 +67,7 @@ public final class TextPane extends JComponent implements AdjustmentListener,
|
66
|
67
|
* structure is changed (or anything else that would prevent serialized
|
67
|
68
|
* objects being unserialized with the new class).
|
68
|
69
|
*/
|
69
|
|
- private static final long serialVersionUID = 4;
|
|
70
|
+ private static final long serialVersionUID = 5;
|
70
|
71
|
|
71
|
72
|
/** Scrollbar for the component. */
|
72
|
73
|
private final JScrollBar scrollBar;
|
|
@@ -74,14 +75,21 @@ public final class TextPane extends JComponent implements AdjustmentListener,
|
74
|
75
|
private final TextPaneCanvas canvas;
|
75
|
76
|
/** IRCDocument. */
|
76
|
77
|
private final IRCDocument document;
|
77
|
|
-
|
|
78
|
+ /** Parent Frame. */
|
|
79
|
+ private final FrameContainer frame;
|
78
|
80
|
/** Listener list. */
|
79
|
81
|
private final EventListenerList textPaneListeners;
|
80
|
82
|
|
81
|
|
- /** Creates a new instance of TextPane. */
|
82
|
|
- public TextPane() {
|
|
83
|
+ /**
|
|
84
|
+ * Creates a new instance of TextPane.
|
|
85
|
+ *
|
|
86
|
+ * @param frame Parent Frame
|
|
87
|
+ */
|
|
88
|
+ public TextPane(final FrameContainer frame) {
|
83
|
89
|
super();
|
84
|
90
|
|
|
91
|
+ this.frame = frame;
|
|
92
|
+
|
85
|
93
|
textPaneListeners = new EventListenerList();
|
86
|
94
|
|
87
|
95
|
document = new IRCDocument();
|
|
@@ -135,7 +143,7 @@ public final class TextPane extends JComponent implements AdjustmentListener,
|
135
|
143
|
*/
|
136
|
144
|
public void addStyledString(final String[] strings) {
|
137
|
145
|
final AttributedString text = styledDocumentToAttributedString(
|
138
|
|
- Styliser.getStyledString(strings, null));
|
|
146
|
+ Styliser.getStyledString(strings, frame));
|
139
|
147
|
|
140
|
148
|
if (text.getIterator().getEndIndex() == 0) {
|
141
|
149
|
addText(new AttributedString("\n"));
|
|
@@ -151,12 +159,15 @@ public final class TextPane extends JComponent implements AdjustmentListener,
|
151
|
159
|
*
|
152
|
160
|
* @return AttributedString representing the specified StyledDocument
|
153
|
161
|
*/
|
154
|
|
- public static AttributedString styledDocumentToAttributedString(final StyledDocument doc) {
|
155
|
|
- //Now lets get hacky, loop through the styled document and add all styles to an attributedString
|
|
162
|
+ public static AttributedString styledDocumentToAttributedString(
|
|
163
|
+ final StyledDocument doc) {
|
|
164
|
+ //Now lets get hacky, loop through the styled document and add all
|
|
165
|
+ //styles to an attributedString
|
156
|
166
|
AttributedString attString = null;
|
157
|
167
|
final Element line = doc.getParagraphElement(0);
|
158
|
168
|
try {
|
159
|
|
- attString = new AttributedString(line.getDocument().getText(0, line.getDocument().getLength()));
|
|
169
|
+ attString = new AttributedString(line.getDocument().getText(0,
|
|
170
|
+ line.getDocument().getLength()));
|
160
|
171
|
} catch (BadLocationException ex) {
|
161
|
172
|
Logger.userError(ErrorLevel.MEDIUM,
|
162
|
173
|
"Unable to insert styled string: " + ex.getMessage());
|
|
@@ -173,39 +184,48 @@ public final class TextPane extends JComponent implements AdjustmentListener,
|
173
|
184
|
if (attrib == IRCTextAttribute.HYPERLINK) {
|
174
|
185
|
//Hyperlink
|
175
|
186
|
attString.addAttribute(IRCTextAttribute.HYPERLINK,
|
176
|
|
- as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
|
|
187
|
+ as.getAttribute(attrib), element.getStartOffset(),
|
|
188
|
+ element.getEndOffset());
|
177
|
189
|
} else if (attrib == IRCTextAttribute.NICKNAME) {
|
178
|
190
|
//Nicknames
|
179
|
191
|
attString.addAttribute(IRCTextAttribute.NICKNAME,
|
180
|
|
- as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
|
|
192
|
+ as.getAttribute(attrib), element.getStartOffset(),
|
|
193
|
+ element.getEndOffset());
|
181
|
194
|
} else if (attrib == IRCTextAttribute.CHANNEL) {
|
182
|
195
|
//Channels
|
183
|
196
|
attString.addAttribute(IRCTextAttribute.CHANNEL,
|
184
|
|
- as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
|
|
197
|
+ as.getAttribute(attrib), element.getStartOffset(),
|
|
198
|
+ element.getEndOffset());
|
185
|
199
|
} else if (attrib == ColorConstants.Foreground) {
|
186
|
200
|
//Foreground
|
187
|
201
|
attString.addAttribute(TextAttribute.FOREGROUND,
|
188
|
|
- as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
|
|
202
|
+ as.getAttribute(attrib), element.getStartOffset(),
|
|
203
|
+ element.getEndOffset());
|
189
|
204
|
} else if (attrib == ColorConstants.Background) {
|
190
|
205
|
//Background
|
191
|
206
|
attString.addAttribute(TextAttribute.BACKGROUND,
|
192
|
|
- as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
|
|
207
|
+ as.getAttribute(attrib), element.getStartOffset(),
|
|
208
|
+ element.getEndOffset());
|
193
|
209
|
} else if (attrib == FontConstants.Bold) {
|
194
|
210
|
//Bold
|
195
|
211
|
attString.addAttribute(TextAttribute.WEIGHT,
|
196
|
|
- TextAttribute.WEIGHT_BOLD, element.getStartOffset(), element.getEndOffset());
|
|
212
|
+ TextAttribute.WEIGHT_BOLD, element.getStartOffset(),
|
|
213
|
+ element.getEndOffset());
|
197
|
214
|
} else if (attrib == FontConstants.Family) {
|
198
|
215
|
//Family
|
199
|
216
|
attString.addAttribute(TextAttribute.FAMILY,
|
200
|
|
- as.getAttribute(attrib), element.getStartOffset(), element.getEndOffset());
|
|
217
|
+ as.getAttribute(attrib), element.getStartOffset(),
|
|
218
|
+ element.getEndOffset());
|
201
|
219
|
} else if (attrib == FontConstants.Italic) {
|
202
|
220
|
//italics
|
203
|
221
|
attString.addAttribute(TextAttribute.POSTURE,
|
204
|
|
- TextAttribute.POSTURE_OBLIQUE, element.getStartOffset(), element.getEndOffset());
|
|
222
|
+ TextAttribute.POSTURE_OBLIQUE, element.getStartOffset(),
|
|
223
|
+ element.getEndOffset());
|
205
|
224
|
} else if (attrib == CharacterConstants.Underline) {
|
206
|
225
|
//Underline
|
207
|
226
|
attString.addAttribute(TextAttribute.UNDERLINE,
|
208
|
|
- TextAttribute.UNDERLINE_ON, element.getStartOffset(), element.getEndOffset());
|
|
227
|
+ TextAttribute.UNDERLINE_ON, element.getStartOffset(),
|
|
228
|
+ element.getEndOffset());
|
209
|
229
|
}
|
210
|
230
|
}
|
211
|
231
|
}
|