Fields Summary |
---|
private JEditorPane | theEditor |
public static final String | DEFAULT_CSSDefault Cascading Style Sheet file that sets
up the tag views. |
private AccessibleContext | accessibleContext |
private static final Cursor | MoveCursor |
private static final Cursor | DefaultCursor |
private static final ViewFactory | defaultFactoryShared factory for creating HTML Views. |
MutableAttributeSet | input |
private static StyleSheet | defaultStyles |
private LinkController | linkHandler |
private static Parser | defaultParser |
private Cursor | defaultCursor |
private Cursor | linkCursor |
private boolean | isAutoFormSubmission |
public static final String | BOLD_ACTIONThe bold action identifier |
public static final String | ITALIC_ACTIONThe italic action identifier |
public static final String | PARA_INDENT_LEFTThe paragraph left indent action identifier |
public static final String | PARA_INDENT_RIGHTThe paragraph right indent action identifier |
public static final String | FONT_CHANGE_BIGGERThe font size increase to next value action identifier |
public static final String | FONT_CHANGE_SMALLERThe font size decrease to next value action identifier |
public static final String | COLOR_ACTIONThe Color choice action identifier
The color is passed as an argument |
public static final String | LOGICAL_STYLE_ACTIONThe logical style choice action identifier
The logical style is passed in as an argument |
public static final String | IMG_ALIGN_TOPAlign images at the top. |
public static final String | IMG_ALIGN_MIDDLEAlign images in the middle. |
public static final String | IMG_ALIGN_BOTTOMAlign images at the bottom. |
public static final String | IMG_BORDERAlign images at the border. |
private static final String | INSERT_TABLE_HTMLHTML used when inserting tables. |
private static final String | INSERT_UL_HTMLHTML used when inserting unordered lists. |
private static final String | INSERT_OL_HTMLHTML used when inserting ordered lists. |
private static final String | INSERT_HR_HTMLHTML used when inserting hr. |
private static final String | INSERT_PRE_HTMLHTML used when inserting pre. |
private static NavigateLinkAction | nextLinkAction |
private static NavigateLinkAction | previousLinkAction |
private static ActivateLinkAction | activateLinkAction |
private static final Action[] | defaultActions |
Methods Summary |
---|
public java.lang.Object | clone()Creates a copy of the editor kit.
HTMLEditorKit o = (HTMLEditorKit)super.clone();
if (o != null) {
o.input = null;
o.linkHandler = new LinkController();
}
return o;
|
public javax.swing.text.Document | createDefaultDocument()Create an uninitialized text storage model
that is appropriate for this type of editor.
StyleSheet styles = getStyleSheet();
StyleSheet ss = new StyleSheet();
ss.addStyleSheet(styles);
HTMLDocument doc = new HTMLDocument(ss);
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
|
protected void | createInputAttributes(javax.swing.text.Element element, javax.swing.text.MutableAttributeSet set)Copies the key/values in element s AttributeSet into
set . This does not copy component, icon, or element
names attributes. Subclasses may wish to refine what is and what
isn't copied here. But be sure to first remove all the attributes that
are in set .
This is called anytime the caret moves over a different location.
set.removeAttributes(set);
set.addAttributes(element.getAttributes());
set.removeAttribute(StyleConstants.ComposedTextAttribute);
Object o = set.getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) {
HTML.Tag tag = (HTML.Tag)o;
// PENDING: we need a better way to express what shouldn't be
// copied when editing...
if(tag == HTML.Tag.IMG) {
// Remove the related image attributes, src, width, height
set.removeAttribute(HTML.Attribute.SRC);
set.removeAttribute(HTML.Attribute.HEIGHT);
set.removeAttribute(HTML.Attribute.WIDTH);
set.addAttribute(StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
}
else if (tag == HTML.Tag.HR || tag == HTML.Tag.BR) {
// Don't copy HRs or BRs either.
set.addAttribute(StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
}
else if (tag == HTML.Tag.COMMENT) {
// Don't copy COMMENTs either
set.addAttribute(StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
set.removeAttribute(HTML.Attribute.COMMENT);
}
else if (tag == HTML.Tag.INPUT) {
// or INPUT either
set.addAttribute(StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
set.removeAttribute(HTML.Tag.INPUT);
}
else if (tag instanceof HTML.UnknownTag) {
// Don't copy unknowns either:(
set.addAttribute(StyleConstants.NameAttribute,
HTML.Tag.CONTENT);
set.removeAttribute(HTML.Attribute.ENDTAG);
}
}
|
public void | deinstall(javax.swing.JEditorPane c)Called when the kit is being removed from the
JEditorPane. This is used to unregister any
listeners that were attached.
c.removeMouseListener(linkHandler);
c.removeMouseMotionListener(linkHandler);
c.removeCaretListener(nextLinkAction);
super.deinstall(c);
theEditor = null;
|
public javax.accessibility.AccessibleContext | getAccessibleContext()returns the AccessibleContext associated with this editor kit
if (theEditor == null) {
return null;
}
if (accessibleContext == null) {
AccessibleHTML a = new AccessibleHTML(theEditor);
accessibleContext = a.getAccessibleContext();
}
return accessibleContext;
|
public javax.swing.Action[] | getActions()Fetches the command list for the editor. This is
the list of commands supported by the superclass
augmented by the collection of commands defined
locally for style operations.
return TextAction.augmentList(super.getActions(), this.defaultActions);
|
private static java.lang.Object | getAttrValue(javax.swing.text.AttributeSet attr, javax.swing.text.html.HTML$Attribute key)
Enumeration names = attr.getAttributeNames();
while (names.hasMoreElements()) {
Object nextKey = names.nextElement();
Object nextVal = attr.getAttribute(nextKey);
if (nextVal instanceof AttributeSet) {
Object value = getAttrValue((AttributeSet)nextVal, key);
if (value != null) {
return value;
}
} else if (nextKey == key) {
return nextVal;
}
}
return null;
|
private static int | getBodyElementStart(javax.swing.text.JTextComponent comp)
Element rootElement = comp.getDocument().getRootElements()[0];
for (int i = 0; i < rootElement.getElementCount(); i++) {
Element currElement = rootElement.getElement(i);
if("body".equals(currElement.getName())) {
return currElement.getStartOffset();
}
}
return 0;
|
public java.lang.String | getContentType()Get the MIME type of the data that this
kit represents support for. This kit supports
the type text/html .
return "text/html";
|
public java.awt.Cursor | getDefaultCursor()Returns the default cursor.
return defaultCursor;
|
public javax.swing.text.MutableAttributeSet | getInputAttributes()Gets the input attributes used for the styled
editing actions.
if (input == null) {
input = getStyleSheet().addStyle(null, null);
}
return input;
|
public java.awt.Cursor | getLinkCursor()Returns the cursor to use over hyper links.
return linkCursor;
|
protected javax.swing.text.html.HTMLEditorKit$Parser | getParser()Fetch the parser to use for reading HTML streams.
This can be reimplemented to provide a different
parser. The default implementation is loaded dynamically
to avoid the overhead of loading the default parser if
it's not used. The default parser is the HotJava parser
using an HTML 3.2 DTD.
if (defaultParser == null) {
try {
Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
defaultParser = (Parser) c.newInstance();
} catch (Throwable e) {
}
}
return defaultParser;
|
static java.io.InputStream | getResourceAsStream(java.lang.String name)Fetch a resource relative to the HTMLEditorKit classfile.
If this is called on 1.2 the loading will occur under the
protection of a doPrivileged call to allow the HTMLEditorKit
to function when used in an applet.
try {
return ResourceLoader.getResourceAsStream(name);
} catch (Throwable e) {
// If the class doesn't exist or we have some other
// problem we just try to call getResourceAsStream directly.
return HTMLEditorKit.class.getResourceAsStream(name);
}
|
public javax.swing.text.html.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.
if (defaultStyles == null) {
defaultStyles = new StyleSheet();
try {
InputStream is = HTMLEditorKit.getResourceAsStream(DEFAULT_CSS);
Reader r = new BufferedReader(
new InputStreamReader(is, "ISO-8859-1"));
defaultStyles.loadRules(r, null);
r.close();
} catch (Throwable e) {
// on error we simply have no styles... the html
// will look mighty wrong but still function.
}
}
return defaultStyles;
|
public javax.swing.text.ViewFactory | getViewFactory()Fetch a factory that is suitable for producing
views of any models that are produced by this
kit.
return defaultFactory;
|
public void | insertHTML(javax.swing.text.html.HTMLDocument doc, int offset, java.lang.String html, int popDepth, int pushDepth, javax.swing.text.html.HTML$Tag insertTag)Inserts HTML into an existing document.
Parser p = getParser();
if (p == null) {
throw new IOException("Can't load parser");
}
if (offset > doc.getLength()) {
throw new BadLocationException("Invalid location", offset);
}
ParserCallback receiver = doc.getReader(offset, popDepth, pushDepth,
insertTag);
Boolean ignoreCharset = (Boolean)doc.getProperty
("IgnoreCharsetDirective");
p.parse(new StringReader(html), receiver, (ignoreCharset == null) ?
false : ignoreCharset.booleanValue());
receiver.flush();
|
public void | install(javax.swing.JEditorPane c)Called when the kit is being installed into the
a JEditorPane.
c.addMouseListener(linkHandler);
c.addMouseMotionListener(linkHandler);
c.addCaretListener(nextLinkAction);
super.install(c);
theEditor = c;
|
public boolean | isAutoFormSubmission()Indicates whether an html form submission is processed automatically
or only FormSubmitEvent is fired.
return isAutoFormSubmission;
|
public void | read(java.io.Reader in, javax.swing.text.Document doc, int pos)Inserts content from the given stream. If doc is
an instance of HTMLDocument, this will read
HTML 3.2 text. 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.
if (doc instanceof HTMLDocument) {
HTMLDocument hdoc = (HTMLDocument) doc;
Parser p = getParser();
if (p == null) {
throw new IOException("Can't load parser");
}
if (pos > doc.getLength()) {
throw new BadLocationException("Invalid location", pos);
}
ParserCallback receiver = hdoc.getReader(pos);
Boolean ignoreCharset = (Boolean)doc.getProperty("IgnoreCharsetDirective");
p.parse(in, receiver, (ignoreCharset == null) ? false : ignoreCharset.booleanValue());
receiver.flush();
} else {
super.read(in, doc, pos);
}
|
public void | setAutoFormSubmission(boolean isAuto)Specifies if an html form submission is processed
automatically or only FormSubmitEvent is fired.
By default it is set to true.
isAutoFormSubmission = isAuto;
|
public void | setDefaultCursor(java.awt.Cursor cursor)Sets the default cursor.
defaultCursor = cursor;
|
public void | setLinkCursor(java.awt.Cursor cursor)Sets the cursor to use over links.
linkCursor = cursor;
|
public void | setStyleSheet(javax.swing.text.html.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.
This should be reimplemented to provide a finer granularity
if desired.
defaultStyles = s;
|
public void | write(java.io.Writer out, javax.swing.text.Document doc, int pos, int len)Write content from a document to the given stream
in a format appropriate for this kind of content handler.
if (doc instanceof HTMLDocument) {
HTMLWriter w = new HTMLWriter(out, (HTMLDocument)doc, pos, len);
w.write();
} else if (doc instanceof StyledDocument) {
MinimalHTMLWriter w = new MinimalHTMLWriter(out, (StyledDocument)doc, pos, len);
w.write();
} else {
super.write(out, doc, pos, len);
}
|