public class XMLEditorKit extends DefaultEditorKit implements XMLStyleConstants, KeyListener
Note: The XML Editor package is based on the JavaEditorKit example as described in the article 'Customizing a Text Editor' by Timothy Prinzing . See: http://java.sun.com/products/jfc/tsc/articles/text/editor_kit/
JEditorPane editor = new JEditorPane();
// Instantiate a XMLEditorKit with wrapping enabled.
XMLEditorKit kit = new XMLEditorKit( true);
// Set the wrapping style.
kit.setWrapStyleWord(true);
kit.setAutoIndentation(true);
kit.setTagCompletion(true);
editor.setEditorKit( kit);
// Set the font style.
editor.setFont( new Font( "Courier", Font.PLAIN, 12));
// Set the tab size
editor.getDocument().putProperty( PlainDocument.tabSizeAttribute, new Integer(4));
// Set a style
kit.setStyle( XMLStyleConstants.ATTRIBUTE_NAME, new Color( 255, 0, 0), Font.BOLD);
// Put the editor in a panel that will force it to resize, when a different view is choosen.
ScrollableEditorPanel editorPanel = new ScrollableEditorPanel( editor);
JScrollPane scroller = new JScrollPane( editorPanel);
...
To switch between line wrapped and non wrapped views use:
...
XMLEditorKit kit = (XMLEditorKit)editor.getEditorKit();
kit.setLineWrappingEnabled( false);
// Update the UI and create a new view...
editor.updateUI();
...
DefaultEditorKit.BeepAction, DefaultEditorKit.CopyAction, DefaultEditorKit.CutAction, DefaultEditorKit.DefaultKeyTypedAction, DefaultEditorKit.InsertBreakAction, DefaultEditorKit.InsertContentAction, DefaultEditorKit.InsertTabAction, DefaultEditorKit.PasteAction| Modifier and Type | Field and Description |
|---|---|
static String |
ERROR_HIGHLIGHTING_ATTRIBUTE |
backwardAction, beepAction, beginAction, beginLineAction, beginParagraphAction, beginWordAction, copyAction, cutAction, defaultKeyTypedAction, deleteNextCharAction, deleteNextWordAction, deletePrevCharAction, deletePrevWordAction, downAction, endAction, endLineAction, EndOfLineStringProperty, endParagraphAction, endWordAction, forwardAction, insertBreakAction, insertContentAction, insertTabAction, nextWordAction, pageDownAction, pageUpAction, pasteAction, previousWordAction, readOnlyAction, selectAllAction, selectionBackwardAction, selectionBeginAction, selectionBeginLineAction, selectionBeginParagraphAction, selectionBeginWordAction, selectionDownAction, selectionEndAction, selectionEndLineAction, selectionEndParagraphAction, selectionEndWordAction, selectionForwardAction, selectionNextWordAction, selectionPreviousWordAction, selectionUpAction, selectLineAction, selectParagraphAction, selectWordAction, upAction, writableActionATTRIBUTE_NAME, ATTRIBUTE_PREFIX, ATTRIBUTE_VALUE, CDATA, COMMENT, DECLARATION, ELEMENT_NAME, ELEMENT_PREFIX, ELEMENT_VALUE, ENTITY, ENTITY_REFERENCE, NAMESPACE_NAME, NAMESPACE_PREFIX, NAMESPACE_VALUE, SPECIAL, STRING, WHITESPACE| Constructor and Description |
|---|
XMLEditorKit()
Constructs an XMLEditorKit with view factory and Context, but with line
wrapping turned off.
|
| Modifier and Type | Method and Description |
|---|---|
void |
deinstall(JEditorPane editor) |
String |
getContentType()
Get the MIME type of the data that this kit represents support for.
|
ViewFactory |
getViewFactory()
Fetches the XML factory that can produce views for XML Documents.
|
void |
install(JEditorPane editor) |
void |
keyPressed(KeyEvent event) |
void |
keyReleased(KeyEvent keyevent) |
void |
keyTyped(KeyEvent keyevent) |
void |
setAutoIndentation(boolean enabled) |
void |
setStyle(String token,
Color foreground,
int fontStyle)
Set the style identified by the name.
|
void |
setTagCompletion(boolean enabled) |
createCaret, createDefaultDocument, getActions, read, read, write, writepublic static final String ERROR_HIGHLIGHTING_ATTRIBUTE
public XMLEditorKit()
public String getContentType()
text/xml.getContentType in class DefaultEditorKitpublic ViewFactory getViewFactory()
getViewFactory in class DefaultEditorKitpublic final void setTagCompletion(boolean enabled)
enabled - true enables the tag completionpublic final void setAutoIndentation(boolean enabled)
enabled - true enables the auto indentationpublic void setStyle(String token, Color foreground, int fontStyle)
token - the style tokenforeground - the foreground colorfontStyle - the font style Plain, Italic or Boldpublic void install(JEditorPane editor)
public void deinstall(JEditorPane editor)
public void keyPressed(KeyEvent event)
keyPressed in interface KeyListenerpublic void keyReleased(KeyEvent keyevent)
keyReleased in interface KeyListenerpublic void keyTyped(KeyEvent keyevent)
keyTyped in interface KeyListenerCopyright © 2002-2013 Edwin Dankert. All Rights Reserved.