Get Bounce at SourceForge.net. Fast secure and Free Open Source software downloads

org.bounce.text.xml
Class XMLEditorKit

java.lang.Object
  extended by javax.swing.text.EditorKit
      extended by javax.swing.text.DefaultEditorKit
          extended by org.bounce.text.xml.XMLEditorKit
All Implemented Interfaces:
java.awt.event.KeyListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, XMLStyleConstants

public class XMLEditorKit
extends javax.swing.text.DefaultEditorKit
implements XMLStyleConstants, java.awt.event.KeyListener

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);
 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();
 
 ...
 

Version:
$Revision: 1.5 $, $Date: 2008/01/28 21:02:14 $
Author:
Edwin Dankert
See Also:
Serialized Form

Nested Class Summary
(package private)  class XMLEditorKit.XMLViewFactory
          A simple view factory implementation.
 
Nested classes/interfaces inherited from class javax.swing.text.DefaultEditorKit
javax.swing.text.DefaultEditorKit.BeepAction, javax.swing.text.DefaultEditorKit.CopyAction, javax.swing.text.DefaultEditorKit.CutAction, javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction, javax.swing.text.DefaultEditorKit.InsertBreakAction, javax.swing.text.DefaultEditorKit.InsertContentAction, javax.swing.text.DefaultEditorKit.InsertTabAction, javax.swing.text.DefaultEditorKit.PasteAction
 
Field Summary
static java.lang.String ERROR_HIGHLIGHTING_ATTRIBUTE
           
 
Fields inherited from class javax.swing.text.DefaultEditorKit
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, writableAction
 
Fields inherited from interface org.bounce.text.xml.XMLStyleConstants
ATTRIBUTE_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 Summary
XMLEditorKit()
          Constructs an XMLEditorKit with view factory and Context, but with line wrapping turned off.
 
Method Summary
 void deinstall(javax.swing.JEditorPane editor)
           
 java.lang.String getContentType()
          Get the MIME type of the data that this kit represents support for.
 javax.swing.text.ViewFactory getViewFactory()
          Fetches the XML factory that can produce views for XML Documents.
 void install(javax.swing.JEditorPane editor)
           
 void keyPressed(java.awt.event.KeyEvent event)
           
 void keyReleased(java.awt.event.KeyEvent keyevent)
           
 void keyTyped(java.awt.event.KeyEvent keyevent)
           
 void setAutoIndentation(boolean enabled)
           
 void setStyle(java.lang.String token, java.awt.Color foreground, int fontStyle)
          Set the style identified by the name.
 void setTagCompletion(boolean enabled)
           
 
Methods inherited from class javax.swing.text.DefaultEditorKit
createCaret, createDefaultDocument, getActions, read, read, write, write
 
Methods inherited from class javax.swing.text.EditorKit
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_HIGHLIGHTING_ATTRIBUTE

public static final java.lang.String ERROR_HIGHLIGHTING_ATTRIBUTE
See Also:
Constant Field Values
Constructor Detail

XMLEditorKit

public XMLEditorKit()
Constructs an XMLEditorKit with view factory and Context, but with line wrapping turned off.

Method Detail

getContentType

public java.lang.String getContentType()
Get the MIME type of the data that this kit represents support for. This kit supports the type text/xml.

Overrides:
getContentType in class javax.swing.text.DefaultEditorKit
Returns:
the type.

getViewFactory

public javax.swing.text.ViewFactory getViewFactory()
Fetches the XML factory that can produce views for XML Documents.

Overrides:
getViewFactory in class javax.swing.text.DefaultEditorKit
Returns:
the XML factory

setTagCompletion

public final void setTagCompletion(boolean enabled)
Parameters:
enabled - true enables the tag completion

setAutoIndentation

public final void setAutoIndentation(boolean enabled)
Parameters:
enabled - true enables the auto indentation

setStyle

public void setStyle(java.lang.String token,
                     java.awt.Color foreground,
                     int fontStyle)
Set the style identified by the name.

Parameters:
token - the style token
foreground - the foreground color
fontStyle - the font style Plain, Italic or Bold

install

public void install(javax.swing.JEditorPane editor)
Overrides:
install in class javax.swing.text.EditorKit

deinstall

public void deinstall(javax.swing.JEditorPane editor)
Overrides:
deinstall in class javax.swing.text.EditorKit

keyPressed

public void keyPressed(java.awt.event.KeyEvent event)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent keyevent)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent keyevent)
Specified by:
keyTyped in interface java.awt.event.KeyListener

Get Bounce at SourceForge.net. Fast secure and Free Open Source software downloads

Copyright 2002-2002-2009 Edwin Dankert. All Rights Reserved.