|
Bounce | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.text.EditorKit
javax.swing.text.DefaultEditorKit
org.bounce.text.xml.XMLEditorKit
public class XMLEditorKit
The XML editor kit supports handling of editing XML content. It supports syntax highlighting, line wrapping, automatic indentation and tag completion.
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);
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));
// Enable auto indentation.
editor.getDocument().putProperty( XMLDocument.AUTO_INDENTATION_ATTRIBUTE, new Boolean( true));
// Enable tag completion.
editor.getDocument().putProperty( XMLDocument.TAG_COMPLETION_ATTRIBUTE, new Boolean( true));
// 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();
...
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.text.DefaultEditorKit |
|---|
DefaultEditorKit.BeepAction, DefaultEditorKit.CopyAction, DefaultEditorKit.CutAction, DefaultEditorKit.DefaultKeyTypedAction, DefaultEditorKit.InsertBreakAction, DefaultEditorKit.InsertContentAction, DefaultEditorKit.InsertTabAction, DefaultEditorKit.PasteAction |
| Field Summary |
|---|
| Fields inherited from interface org.bounce.text.xml.XMLStyleConstants |
|---|
ATTRIBUTE_NAME, ATTRIBUTE_PREFIX, ATTRIBUTE_VALUE, COMMENT, DECLARATION, ELEMENT_NAME, ELEMENT_PREFIX, ELEMENT_VALUE, ENTITY, NAMESPACE_NAME, NAMESPACE_PREFIX, NAMESPACE_VALUE, SPECIAL, STRING |
| Constructor Summary | |
|---|---|
XMLEditorKit()
Constructs an XMLEditorKit with view factory and Context, but with line wrapping turned off. |
|
XMLEditorKit(boolean lineWrapping)
Constructs the view factory and the Context. |
|
| Method Summary | |
|---|---|
Document |
createDefaultDocument()
|
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 c)
Called when the kit is being installed into the a JEditorPane. |
boolean |
isFolding()
Returns true when the folding is enables |
boolean |
isLineWrapping()
Returns true when line-wrapping has been turned on. |
boolean |
isWrapStyleWord()
Returns true when the wrapping style is 'word wrapping'. |
void |
read(InputStream in,
Document doc,
int pos)
|
void |
read(Reader in,
Document doc,
int pos)
|
void |
setFolding(boolean folding)
Enables/disables folding for xml |
void |
setLineWrappingEnabled(boolean enabled)
Eanbles/disables the line-wrapping feature. |
void |
setStyle(String name,
Color foreground,
int fontStyle)
Set the style identified by the name. |
void |
setWrapStyleWord(boolean enabled)
Enables/disables the word-wrapping style. |
| Methods inherited from class javax.swing.text.DefaultEditorKit |
|---|
createCaret, getActions, write, write |
| Methods inherited from class javax.swing.text.EditorKit |
|---|
clone, deinstall |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XMLEditorKit()
public XMLEditorKit(boolean lineWrapping)
lineWrapping - enables line wrapping feature if true.| Method Detail |
|---|
public void install(JEditorPane c)
install in class EditorKitc - the JEditorPanepublic boolean isLineWrapping()
public void setLineWrappingEnabled(boolean enabled)
enabled - true when line-wrapping enabled.public boolean isWrapStyleWord()
public void setWrapStyleWord(boolean enabled)
enabled - true when word-wrapping style enabled.public boolean isFolding()
public void setFolding(boolean folding)
folding - true when folding enabledpublic String getContentType()
text/xml.
getContentType in class DefaultEditorKitpublic final ViewFactory getViewFactory()
getViewFactory in class DefaultEditorKit
public void setStyle(String name,
Color foreground,
int fontStyle)
name - the style nameforeground - the foreground colorfontStyle - the font style Plain, Italic or Boldpublic Document createDefaultDocument()
createDefaultDocument in class DefaultEditorKitDefaultEditorKit.createDefaultDocument()
public void read(Reader in,
Document doc,
int pos)
throws IOException,
BadLocationException
read in class DefaultEditorKitIOException
BadLocationExceptionDefaultEditorKit.read( java.io.Reader, javax.swing.text.Document, int)
public void read(InputStream in,
Document doc,
int pos)
throws IOException,
BadLocationException
read in class DefaultEditorKitIOException
BadLocationExceptionDefaultEditorKit.read( java.io.InputStream, javax.swing.text.Document, int)
|
Bounce | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||