Class XMLEditorKit
java.lang.Object
javax.swing.text.EditorKit
javax.swing.text.DefaultEditorKit
javax.swing.text.StyledEditorKit
net.simplace.ui.xmleditorkit.XMLEditorKit
- All Implemented Interfaces:
Serializable, Cloneable
Editor kit showing XML with syntax highlighting and collapsible tags (click on the box left of a tag). Copying
extends the selection to whole tags.
- Author:
- Stanislav Lapitsky
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassCopy action that extends the selection to whole tags before copying.Nested classes/interfaces inherited from class StyledEditorKit
StyledEditorKit.AlignmentAction, StyledEditorKit.BoldAction, StyledEditorKit.FontFamilyAction, StyledEditorKit.FontSizeAction, StyledEditorKit.ForegroundAction, StyledEditorKit.ItalicAction, StyledEditorKit.StyledTextAction, StyledEditorKit.UnderlineActionNested classes/interfaces inherited from class DefaultEditorKit
DefaultEditorKit.BeepAction, DefaultEditorKit.CopyAction, DefaultEditorKit.CutAction, DefaultEditorKit.DefaultKeyTypedAction, DefaultEditorKit.InsertBreakAction, DefaultEditorKit.InsertContentAction, DefaultEditorKit.InsertTabAction, DefaultEditorKit.PasteAction -
Field Summary
Fields inherited from class DefaultEditorKit
backwardAction, beepAction, beginAction, beginLineAction, beginLineUpAction, beginParagraphAction, beginWordAction, copyAction, cutAction, defaultKeyTypedAction, deleteNextCharAction, deleteNextWordAction, deletePrevCharAction, deletePrevWordAction, downAction, endAction, endLineAction, endLineDownAction, 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcorrectSelectionBounds(int[] selection, Document d) Extends a selection in anXMLDocumentto the smallest tag containing it.voidRemoves the mouse listeners and deinstalls the kit.Action[]protected static ShapegetAllocation(View v, JEditorPane edit) protected intgetInsertPosition(int pos, Document d) voidInstalls the kit and the mouse listeners for collapsing tags.voidread(InputStream in, Document doc, int pos) Reads XML from a stream into the document.voidReads XML from a reader into the document (line breaks are removed before parsing).voidwrite(OutputStream out, Document doc, int pos, int len) Writes a part of the document, extended to whole tags (seecorrectSelectionBounds(int[], Document)).voidWrites a part of the document, extended to whole tags (seecorrectSelectionBounds(int[], Document)).Methods inherited from class StyledEditorKit
clone, createInputAttributes, getCharacterAttributeRun, getInputAttributesMethods inherited from class DefaultEditorKit
createCaret
-
Constructor Details
-
XMLEditorKit
public XMLEditorKit()
-
-
Method Details
-
getViewFactory
- Overrides:
getViewFactoryin classStyledEditorKit- Returns:
- the
XMLViewFactory
-
createDefaultDocument
- Overrides:
createDefaultDocumentin classStyledEditorKit- Returns:
- a new empty
XMLDocument
-
getContentType
- Overrides:
getContentTypein classDefaultEditorKit- Returns:
text/xml
-
read
Reads XML from a reader into the document (line breaks are removed before parsing).- Overrides:
readin classDefaultEditorKit- Parameters:
in- the readerdoc- the document, only anXMLDocumentis filledpos- the position; in a non-empty document the XML is inserted after the start row of the enclosing tag- Throws:
IOException- if the XML cannot be read or parsedBadLocationException- if the position is invalid
-
read
Reads XML from a stream into the document.- Overrides:
readin classDefaultEditorKit- Parameters:
in- the streamdoc- the document, only anXMLDocumentis filledpos- the position; in a non-empty document the XML is inserted after the start row of the enclosing tag- Throws:
IOException- if the XML cannot be read or parsedBadLocationException- if the position is invalid
-
write
public void write(OutputStream out, Document doc, int pos, int len) throws IOException, BadLocationException Writes a part of the document, extended to whole tags (seecorrectSelectionBounds(int[], Document)).- Overrides:
writein classDefaultEditorKit- Parameters:
out- the streamdoc- the documentpos- start of the partlen- length of the part- Throws:
IOException- if writing failsBadLocationException- if the part is invalid
-
write
public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException Writes a part of the document, extended to whole tags (seecorrectSelectionBounds(int[], Document)).- Overrides:
writein classDefaultEditorKit- Parameters:
out- the writerdoc- the documentpos- start of the partlen- length of the part- Throws:
IOException- if writing failsBadLocationException- if the part is invalid
-
correctSelectionBounds
Extends a selection in anXMLDocumentto the smallest tag containing it.- Parameters:
selection- start and end of the selection, changed in placed- the document; other documents are left unchanged
-
getInsertPosition
- Parameters:
pos- the requested positiond- the document- Returns:
- for a non-empty
XMLDocumentthe end of the start row of the innermost tag with children at the position, otherwisepos
-
install
Installs the kit and the mouse listeners for collapsing tags.- Overrides:
installin classStyledEditorKit- Parameters:
c- the editor pane
-
deinstall
Removes the mouse listeners and deinstalls the kit.- Overrides:
deinstallin classStyledEditorKit- Parameters:
c- the editor pane
-
getAllocation
- Parameters:
v- the viewedit- the editor pane- Returns:
- the area of the view in editor coordinates
-
getActions
- Overrides:
getActionsin classStyledEditorKit- Returns:
- the actions of the kit, with the copy action replaced by
XMLEditorKit.XMLCopyAction
-