javax.swing.text.html

Class HTMLEditorKit

public class HTMLEditorKit extends StyledEditorKit implements Serializable, Cloneable, Accessible

Nested Class Summary
static classHTMLEditorKit.HTMLFactory
A {@link ViewFactory} that is able to create {@link View}s for the Elements that are supported.
abstract static classHTMLEditorKit.HTMLTextAction
Abstract Action class that helps inserting HTML into an existing document.
static classHTMLEditorKit.InsertHTMLTextAction
This class is used to insert a string of HTML into an existing document.
static classHTMLEditorKit.LinkController
Fires the hyperlink events on the associated component when needed.
abstract static classHTMLEditorKit.Parser
The abstract HTML parser declaration.
static classHTMLEditorKit.ParserCallback
The "hook" that receives all information about the HTML document structure while parsing it.
Field Summary
static StringBOLD_ACTION
The bold action identifier.
static StringCOLOR_ACTION
The color action indentifier (passing the color as an argument).
static StringDEFAULT_CSS
Default cascading stylesheed file ("default.css").
static StringFONT_CHANGE_BIGGER
The increase font action identifier.
static StringFONT_CHANGE_SMALLER
The decrease font action identifier.
static StringIMG_ALIGN_BOTTOM
Align images at the bottom.
static StringIMG_ALIGN_MIDDLE
Align images at the middle.
static StringIMG_ALIGN_TOP
Align images at the top.
static StringIMG_BORDER
Align images at the border.
static StringITALIC_ACTION
The italic action identifier.
static StringLOGICAL_STYLE_ACTION
The "logical style" action identifier, passing that style as parameter.
static StringPARA_INDENT_LEFT
The "ident paragraph left" action.
static StringPARA_INDENT_RIGHT
The "ident paragraph right" action.
Constructor Summary
HTMLEditorKit()
Constructs an HTMLEditorKit, creates a StyleContext, and loads the style sheet.
Method Summary
Objectclone()
Creates a copy of the editor kit.
DocumentcreateDefaultDocument()
Create a text storage model for this type of editor.
protected voidcreateInputAttributes(Element element, MutableAttributeSet set)
Copies the key/values in elements AttributeSet into set.
voiddeinstall(JEditorPane c)
Called when the this is removed from the JEditorPane.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this.
Action[]getActions()
Gets the action list.
StringgetContentType()
Gets the content type that the kit supports.
CursorgetDefaultCursor()
Returns the default cursor.
MutableAttributeSetgetInputAttributes()
Gets the input attributes used for the styled editing actions.
CursorgetLinkCursor()
Returns the cursor for links.
protected HTMLEditorKit.ParsergetParser()
Get the parser that this editor kit uses for reading HTML streams.
StyleSheetgetStyleSheet()
Get the set of styles currently being used to render the HTML elements.
ViewFactorygetViewFactory()
Gets a factory suitable for producing views of any models that are produced by this kit.
voidinsertHTML(HTMLDocument doc, int offset, String html, int popDepth, int pushDepth, HTML.Tag insertTag)
Inserts HTML into an existing document.
voidinstall(JEditorPane c)
Called when this is installed into the JEditorPane.
booleanisAutoFormSubmission()
Returns true when forms should be automatically submitted by the editor kit.
voidread(Reader in, Document doc, int pos)
Inserts content from the given stream.
voidsetAutoFormSubmission(boolean auto)
Sets whether or not the editor kit should automatically submit forms.
voidsetDefaultCursor(Cursor cursor)
Sets the default cursor.
voidsetLinkCursor(Cursor cursor)
Sets the Cursor for links.
voidsetStyleSheet(StyleSheet s)
Set the set of styles to be used to render the various HTML elements.
voidwrite(Writer out, Document doc, int pos, int len)
Writes content from a document to the given stream in an appropriate format.

Field Detail

BOLD_ACTION

public static final String BOLD_ACTION
The bold action identifier.

COLOR_ACTION

public static final String COLOR_ACTION
The color action indentifier (passing the color as an argument).

DEFAULT_CSS

public static final String DEFAULT_CSS
Default cascading stylesheed file ("default.css").

FONT_CHANGE_BIGGER

public static final String FONT_CHANGE_BIGGER
The increase font action identifier.

FONT_CHANGE_SMALLER

public static final String FONT_CHANGE_SMALLER
The decrease font action identifier.

IMG_ALIGN_BOTTOM

public static final String IMG_ALIGN_BOTTOM
Align images at the bottom.

IMG_ALIGN_MIDDLE

public static final String IMG_ALIGN_MIDDLE
Align images at the middle.

IMG_ALIGN_TOP

public static final String IMG_ALIGN_TOP
Align images at the top.

IMG_BORDER

public static final String IMG_BORDER
Align images at the border.

ITALIC_ACTION

public static final String ITALIC_ACTION
The italic action identifier.

LOGICAL_STYLE_ACTION

public static final String LOGICAL_STYLE_ACTION
The "logical style" action identifier, passing that style as parameter.

PARA_INDENT_LEFT

public static final String PARA_INDENT_LEFT
The "ident paragraph left" action.

PARA_INDENT_RIGHT

public static final String PARA_INDENT_RIGHT
The "ident paragraph right" action.

Constructor Detail

HTMLEditorKit

public HTMLEditorKit()
Constructs an HTMLEditorKit, creates a StyleContext, and loads the style sheet.

Method Detail

clone

public Object clone()
Creates a copy of the editor kit.

Returns: a copy of this.

createDefaultDocument

public Document createDefaultDocument()
Create a text storage model for this type of editor.

Returns: the model

createInputAttributes

protected void createInputAttributes(Element element, MutableAttributeSet set)
Copies the key/values in elements AttributeSet into set. This does not copy component, icon, or element names attributes. This is called anytime the caret moves over a different location.

Parameters: element - the element to create the input attributes for. set - the set to copy the values into.

deinstall

public void deinstall(JEditorPane c)
Called when the this is removed from the JEditorPane. It unregisters any listeners.

Parameters: c - the JEditorPane being removed from.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this.

Returns: the AccessibleContext for this.

getActions

public Action[] getActions()
Gets the action list. This list is supported by the superclass augmented by the collection of actions defined locally for style operations.

Returns: an array of all the actions

getContentType

public String getContentType()
Gets the content type that the kit supports. This kit supports the type text/html.

UNKNOWN: the content type supported.

getDefaultCursor

public Cursor getDefaultCursor()
Returns the default cursor.

Returns: the default cursor

getInputAttributes

public MutableAttributeSet getInputAttributes()
Gets the input attributes used for the styled editing actions.

Returns: the attribute set

getLinkCursor

public Cursor getLinkCursor()
Returns the cursor for links.

Returns: the cursor for links.

getParser

protected HTMLEditorKit.Parser getParser()
Get the parser that this editor kit uses for reading HTML streams. This method can be overridden to use the alternative parser.

Returns: the HTML parser (by default, {@link ParserDelegator}).

getStyleSheet

public StyleSheet getStyleSheet()
Get the set of styles currently being used to render the HTML elements. By default the resource specified by DEFAULT_CSS gets loaded, and is shared by all HTMLEditorKit instances.

Returns: the style sheet.

getViewFactory

public ViewFactory getViewFactory()
Gets a factory suitable for producing views of any models that are produced by this kit.

Returns: the view factory suitable for producing views.

insertHTML

public void insertHTML(HTMLDocument doc, int offset, String html, int popDepth, int pushDepth, HTML.Tag insertTag)
Inserts HTML into an existing document.

Parameters: doc - the Document to insert the HTML into. offset - where to begin inserting the HTML. html - the String to insert popDepth - the number of ElementSpec.EndTagTypes to generate before inserting pushDepth - the number of ElementSpec.StartTagTypes with a direction of ElementSpec.JoinNextDirection that should be generated before insertTag - the first tag to start inserting into document

Throws: IOException - on any I/O error BadLocationException - if pos represents an invalid location within the document

install

public void install(JEditorPane c)
Called when this is installed into the JEditorPane.

Parameters: c - the JEditorPane installed into.

isAutoFormSubmission

public boolean isAutoFormSubmission()
Returns true when forms should be automatically submitted by the editor kit. Set this to false when you want to intercept form submission. In this case you'd want to listen for hyperlink events on the document and handle FormSubmitEvents specially. The default is true.

Returns: true when forms should be automatically submitted by the editor kit, false otherwise

Since: 1.5

See Also: HTMLEditorKit FormSubmitEvent

read

public void read(Reader in, Document doc, int pos)
Inserts content from the given stream. Inserting HTML into a non-empty document must be inside the body Element, if you do not insert into the body an exception will be thrown. When inserting into a non-empty document all tags outside of the body (head, title) will be dropped.

Parameters: in - the stream to read from doc - the destination for the insertion pos - the location in the document to place the content

Throws: IOException - on any I/O error BadLocationException - if pos represents an invalid location within the document

setAutoFormSubmission

public void setAutoFormSubmission(boolean auto)
Sets whether or not the editor kit should automatically submit forms.

Parameters: auto true when the editor kit should handle form submission, false otherwise

Since: 1.5

See Also: isAutoFormSubmission

setDefaultCursor

public void setDefaultCursor(Cursor cursor)
Sets the default cursor.

Parameters: cursor - the new default cursor.

setLinkCursor

public void setLinkCursor(Cursor cursor)
Sets the Cursor for links.

Parameters: cursor - the new cursor for links.

setStyleSheet

public void setStyleSheet(StyleSheet s)
Set the set of styles to be used to render the various HTML elements. These styles are specified in terms of CSS specifications. Each document produced by the kit will have a copy of the sheet which it can add the document specific styles to. By default, the StyleSheet specified is shared by all HTMLEditorKit instances.

Parameters: s - the new style sheet

write

public void write(Writer out, Document doc, int pos, int len)
Writes content from a document to the given stream in an appropriate format.

Parameters: out - the stream to write to doc - the source for the write pos - the location in the document to get the content. len - the amount to write out

Throws: IOException - on any I/O error BadLocationException - if pos represents an invalid location within the document