51 |
import javax.swing.event.CaretListener; |
import javax.swing.event.CaretListener; |
52 |
|
|
53 |
/** |
/** |
54 |
* StyledEditorKit |
* An {@link EditorKit} that supports editing styled text. |
55 |
* |
* |
56 |
* @author Andrew Selkirk |
* @author Andrew Selkirk |
57 |
|
* @author Roman Kennke (roman@kennke.org) |
58 |
*/ |
*/ |
59 |
public class StyledEditorKit extends DefaultEditorKit |
public class StyledEditorKit extends DefaultEditorKit |
60 |
{ |
{ |
61 |
|
/** The serialVersionUID. */ |
62 |
private static final long serialVersionUID = 7002391892985555948L; |
private static final long serialVersionUID = 7002391892985555948L; |
63 |
|
|
64 |
/** |
/** |
65 |
* UnderlineAction |
* Toggles the underline attribute for the selected text. |
66 |
*/ |
*/ |
67 |
public static class UnderlineAction extends StyledEditorKit.StyledTextAction |
public static class UnderlineAction extends StyledEditorKit.StyledTextAction |
68 |
{ |
{ |
69 |
/** |
/** |
70 |
* Constructor UnderlineAction |
* Creates an instance of <code>UnderlineAction</code>. |
71 |
*/ |
*/ |
72 |
public UnderlineAction() |
public UnderlineAction() |
73 |
{ |
{ |
75 |
} |
} |
76 |
|
|
77 |
/** |
/** |
78 |
* actionPerformed |
* Performs the action. |
79 |
* @param event TODO |
* |
80 |
|
* @param event the <code>ActionEvent</code> that describes the action |
81 |
*/ |
*/ |
82 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
83 |
{ |
{ |
92 |
} |
} |
93 |
|
|
94 |
/** |
/** |
95 |
* ItalicAction |
* Toggles the italic attribute for the selected text. |
96 |
*/ |
*/ |
97 |
public static class ItalicAction extends StyledEditorKit.StyledTextAction |
public static class ItalicAction extends StyledEditorKit.StyledTextAction |
98 |
{ |
{ |
99 |
/** |
/** |
100 |
* Constructor ItalicAction |
* Creates an instance of <code>ItalicAction</code>. |
101 |
*/ |
*/ |
102 |
public ItalicAction() |
public ItalicAction() |
103 |
{ |
{ |
105 |
} |
} |
106 |
|
|
107 |
/** |
/** |
108 |
* actionPerformed |
* Performs the action. |
109 |
* @param event TODO |
* |
110 |
|
* @param event the <code>ActionEvent</code> that describes the action |
111 |
*/ |
*/ |
112 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
113 |
{ |
{ |
122 |
} |
} |
123 |
|
|
124 |
/** |
/** |
125 |
* BoldAction |
* Toggles the bold attribute for the selected text. |
126 |
*/ |
*/ |
127 |
public static class BoldAction extends StyledEditorKit.StyledTextAction |
public static class BoldAction extends StyledEditorKit.StyledTextAction |
128 |
{ |
{ |
129 |
/** |
/** |
130 |
* Constructor BoldAction |
* Creates an instance of <code>BoldAction</code>. |
131 |
*/ |
*/ |
132 |
public BoldAction() |
public BoldAction() |
133 |
{ |
{ |
135 |
} |
} |
136 |
|
|
137 |
/** |
/** |
138 |
* actionPerformed |
* Performs the action. |
139 |
* @param event TODO |
* |
140 |
|
* @param event the <code>ActionEvent</code> that describes the action |
141 |
*/ |
*/ |
142 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
143 |
{ |
{ |
152 |
} |
} |
153 |
|
|
154 |
/** |
/** |
155 |
* AlignmentAction |
* Sets the alignment attribute on the selected text. |
156 |
*/ |
*/ |
157 |
public static class AlignmentAction extends StyledEditorKit.StyledTextAction |
public static class AlignmentAction extends StyledEditorKit.StyledTextAction |
158 |
{ |
{ |
159 |
/** |
/** |
160 |
* a |
* The aligment to set. |
161 |
*/ |
*/ |
162 |
private int a; |
private int a; |
163 |
|
|
164 |
/** |
/** |
165 |
* Constructor AlignmentAction |
* Creates a new instance of <code>AlignmentAction</code> to set the |
166 |
* @param nm TODO |
* alignment to <code>a</code>. |
167 |
* @param a TODO |
* |
168 |
|
* @param nm the name of the Action |
169 |
|
* @param a the alignment to set |
170 |
*/ |
*/ |
171 |
public AlignmentAction(String nm, int a) |
public AlignmentAction(String nm, int a) |
172 |
{ |
{ |
175 |
} |
} |
176 |
|
|
177 |
/** |
/** |
178 |
* actionPerformed |
* Performs the action. |
179 |
* @param event TODO |
* |
180 |
|
* @param event the <code>ActionEvent</code> that describes the action |
181 |
*/ |
*/ |
182 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
183 |
{ |
{ |
188 |
} |
} |
189 |
|
|
190 |
/** |
/** |
191 |
* ForegroundAction |
* Sets the foreground color attribute on the selected text. |
192 |
*/ |
*/ |
193 |
public static class ForegroundAction extends StyledEditorKit.StyledTextAction |
public static class ForegroundAction extends StyledEditorKit.StyledTextAction |
194 |
{ |
{ |
195 |
/** |
/** |
196 |
* fg |
* The foreground color to set. |
197 |
*/ |
*/ |
198 |
private Color fg; |
private Color fg; |
199 |
|
|
200 |
/** |
/** |
201 |
* Constructor ForegroundAction |
* Creates a new instance of <code>ForegroundAction</code> to set the |
202 |
* @param nm TODO |
* foreground color to <code>fg</code>. |
203 |
* @param fg TODO |
* |
204 |
|
* @param nm the name of the Action |
205 |
|
* @param fg the foreground color to set |
206 |
*/ |
*/ |
207 |
public ForegroundAction(String nm, Color fg) |
public ForegroundAction(String nm, Color fg) |
208 |
{ |
{ |
211 |
} |
} |
212 |
|
|
213 |
/** |
/** |
214 |
* actionPerformed |
* Performs the action. |
215 |
* @param event TODO |
* |
216 |
|
* @param event the <code>ActionEvent</code> that describes the action |
217 |
*/ |
*/ |
218 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
219 |
{ |
{ |
224 |
} |
} |
225 |
|
|
226 |
/** |
/** |
227 |
* FontSizeAction |
* Sets the font size attribute on the selected text. |
228 |
*/ |
*/ |
229 |
public static class FontSizeAction extends StyledEditorKit.StyledTextAction |
public static class FontSizeAction extends StyledEditorKit.StyledTextAction |
230 |
{ |
{ |
231 |
/** |
/** |
232 |
* size |
* The font size to set. |
233 |
*/ |
*/ |
234 |
private int size; |
private int size; |
235 |
|
|
236 |
/** |
/** |
237 |
* Constructor FontSizeAction |
* Creates a new instance of <code>FontSizeAction</code> to set the |
238 |
* @param nm TODO |
* font size to <code>size</code>. |
239 |
* @param size TODO |
* |
240 |
|
* @param nm the name of the Action |
241 |
|
* @param size the font size to set |
242 |
*/ |
*/ |
243 |
public FontSizeAction(String nm, int size) |
public FontSizeAction(String nm, int size) |
244 |
{ |
{ |
247 |
} |
} |
248 |
|
|
249 |
/** |
/** |
250 |
* actionPerformed |
* Performs the action. |
251 |
* @param event TODO |
* |
252 |
|
* @param event the <code>ActionEvent</code> that describes the action |
253 |
*/ |
*/ |
254 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
255 |
{ |
{ |
260 |
} |
} |
261 |
|
|
262 |
/** |
/** |
263 |
* FontFamilyAction |
* Sets the font family attribute on the selected text. |
264 |
*/ |
*/ |
265 |
public static class FontFamilyAction extends StyledEditorKit.StyledTextAction |
public static class FontFamilyAction extends StyledEditorKit.StyledTextAction |
266 |
{ |
{ |
267 |
/** |
/** |
268 |
* family |
* The font family to set. |
269 |
*/ |
*/ |
270 |
private String family; |
private String family; |
271 |
|
|
272 |
/** |
/** |
273 |
* Constructor FontFamilyAction |
* Creates a new instance of <code>FontFamilyAction</code> to set the |
274 |
* @param nm TODO |
* font family to <code>family</code>. |
275 |
* @param family TODO |
* |
276 |
|
* @param nm the name of the Action |
277 |
|
* @param family the font family to set |
278 |
*/ |
*/ |
279 |
public FontFamilyAction(String nm, String family) |
public FontFamilyAction(String nm, String family) |
280 |
{ |
{ |
283 |
} |
} |
284 |
|
|
285 |
/** |
/** |
286 |
* actionPerformed |
* Performs the action. |
287 |
* @param event TODO |
* |
288 |
|
* @param event the <code>ActionEvent</code> that describes the action |
289 |
*/ |
*/ |
290 |
public void actionPerformed(ActionEvent event) |
public void actionPerformed(ActionEvent event) |
291 |
{ |
{ |
296 |
} |
} |
297 |
|
|
298 |
/** |
/** |
299 |
* StyledTextAction |
* The abstract superclass of all styled TextActions. This class |
300 |
|
* provides some useful methods to manipulate the text attributes. |
301 |
*/ |
*/ |
302 |
public abstract static class StyledTextAction extends TextAction |
public abstract static class StyledTextAction extends TextAction |
303 |
{ |
{ |
304 |
/** |
/** |
305 |
* Constructor StyledTextAction |
* Creates a new instance of <code>StyledTextAction</code>. |
306 |
* @param nm TODO |
* |
307 |
|
* @param nm the name of the <code>StyledTextAction</code> |
308 |
*/ |
*/ |
309 |
public StyledTextAction(String nm) |
public StyledTextAction(String nm) |
310 |
{ |
{ |
312 |
} |
} |
313 |
|
|
314 |
/** |
/** |
315 |
* getEditor |
* Returns the <code>JEditorPane</code> component from which the |
316 |
* @param event TODO |
* <code>ActionEvent</code> originated. |
317 |
* @returns JEditorPane |
* |
318 |
|
* @param event the <code>ActionEvent</code> |
319 |
|
* @return the <code>JEditorPane</code> component from which the |
320 |
|
* <code>ActionEvent</code> originated |
321 |
*/ |
*/ |
322 |
protected final JEditorPane getEditor(ActionEvent event) |
protected final JEditorPane getEditor(ActionEvent event) |
323 |
{ |
{ |
325 |
} |
} |
326 |
|
|
327 |
/** |
/** |
328 |
* setCharacterAttributes |
* Sets the specified character attributes on the currently selected |
329 |
* @param value0 TODO |
* text of <code>editor</code>. If <code>editor</code> does not have |
330 |
* @param value1 TODO |
* a selection, then the attributes are used as input attributes |
331 |
* @param value2 TODO |
* for newly inserted content. |
332 |
|
* |
333 |
|
* @param editor the <code>JEditorPane</code> component |
334 |
|
* @param atts the text attributes to set |
335 |
|
* @param replace if <code>true</code> the current attributes of the |
336 |
|
* selection are replaces, otherwise they are merged |
337 |
*/ |
*/ |
338 |
protected final void setCharacterAttributes(JEditorPane editor, |
protected final void setCharacterAttributes(JEditorPane editor, |
339 |
AttributeSet atts, |
AttributeSet atts, |
371 |
} |
} |
372 |
|
|
373 |
/** |
/** |
374 |
* getStyledDocument |
* Returns the {@link StyledDocument} that is used by <code>editor</code>. |
375 |
* @param value0 TODO |
* |
376 |
* @returns StyledDocument |
* @param editor the <code>JEditorPane</code> from which to get the |
377 |
|
* <code>StyledDocument</code> |
378 |
|
* |
379 |
|
* @return the {@link StyledDocument} that is used by <code>editor</code> |
380 |
*/ |
*/ |
381 |
protected final StyledDocument getStyledDocument(JEditorPane editor) |
protected final StyledDocument getStyledDocument(JEditorPane editor) |
382 |
{ |
{ |
389 |
} |
} |
390 |
|
|
391 |
/** |
/** |
392 |
* getStyledEditorKit |
* Returns the {@link StyledEditorKit} that is used by <code>editor</code>. |
393 |
* @param value0 TODO |
* |
394 |
* @returns StyledEditorKit |
* @param editor the <code>JEditorPane</code> from which to get the |
395 |
|
* <code>StyledEditorKit</code> |
396 |
|
* |
397 |
|
* @return the {@link StyledEditorKit} that is used by <code>editor</code> |
398 |
*/ |
*/ |
399 |
protected final StyledEditorKit getStyledEditorKit(JEditorPane editor) |
protected final StyledEditorKit getStyledEditorKit(JEditorPane editor) |
400 |
{ |
{ |
407 |
} |
} |
408 |
|
|
409 |
/** |
/** |
410 |
* setParagraphAttributes |
* Sets the specified character attributes on the paragraph that |
411 |
* @param value0 TODO |
* contains the currently selected |
412 |
* @param value1 TODO |
* text of <code>editor</code>. If <code>editor</code> does not have |
413 |
* @param value2 TODO |
* a selection, then the attributes are set on the paragraph that |
414 |
|
* contains the current caret position. |
415 |
|
* |
416 |
|
* @param editor the <code>JEditorPane</code> component |
417 |
|
* @param atts the text attributes to set |
418 |
|
* @param replace if <code>true</code> the current attributes of the |
419 |
|
* selection are replaces, otherwise they are merged |
420 |
*/ |
*/ |
421 |
protected final void setParagraphAttributes(JEditorPane editor, |
protected final void setParagraphAttributes(JEditorPane editor, |
422 |
AttributeSet atts, |
AttributeSet atts, |