package javax.swing.text.html;
import javax.accessibility.AccessibleAction;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import javax.swing.text.ElementIterator;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import java.awt.event.ActionEvent;
import javax.swing.text.EditorKit;
import javax.swing.text.AbstractDocument;
import java.awt.event.ComponentEvent;
import javax.swing.JComponent;
import java.awt.Container;
import java.lang.ref.WeakReference;
import javax.swing.SizeRequirements;
import javax.swing.JViewport;
import java.lang.ref.Reference;
import java.awt.event.ComponentListener;
import javax.swing.text.LabelView;
import javax.swing.text.BoxView;
import javax.swing.text.ComponentView;
import javax.swing.text.IconView;
import java.awt.Shape;
import javax.swing.text.View;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.event.HyperlinkEvent;
import javax.swing.plaf.TextUI;
import java.awt.Rectangle;
import java.awt.Point;
import javax.swing.SwingUtilities;
import java.awt.event.MouseEvent;
import javax.swing.text.Position;
import java.io.Serializable;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseAdapter;
import javax.swing.text.JTextComponent;
import java.util.Enumeration;
import javax.swing.text.AttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.Element;
import javax.swing.text.TextAction;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import sun.awt.AppContext;
import javax.swing.text.StyledDocument;
import java.io.Writer;
import java.io.StringReader;
import javax.swing.text.BadLocationException;
import java.io.Reader;
import java.io.IOException;
import javax.swing.text.Document;
import javax.swing.Action;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.ViewFactory;
import java.awt.Cursor;
import javax.accessibility.AccessibleContext;
import javax.swing.JEditorPane;
import javax.accessibility.Accessible;
import javax.swing.text.StyledEditorKit;
public class HTMLEditorKit extends StyledEditorKit implements Accessible
{
private JEditorPane theEditor;
public static final String DEFAULT_CSS = "default.css";
private AccessibleContext accessibleContext;
private static final Cursor MoveCursor;
private static final Cursor DefaultCursor;
private static final ViewFactory defaultFactory;
MutableAttributeSet input;
private static final Object DEFAULT_STYLES_KEY;
private HTMLEditorKit.LinkController linkHandler;
private static HTMLEditorKit.Parser defaultParser;
private Cursor defaultCursor;
private Cursor linkCursor;
private boolean isAutoFormSubmission;
public static final String BOLD_ACTION = "html-bold-action";
public static final String ITALIC_ACTION = "html-italic-action";
public static final String PARA_INDENT_LEFT = "html-para-indent-left";
public static final String PARA_INDENT_RIGHT = "html-para-indent-right";
public static final String FONT_CHANGE_BIGGER = "html-font-bigger";
public static final String FONT_CHANGE_SMALLER = "html-font-smaller";
public static final String COLOR_ACTION = "html-color-action";
public static final String LOGICAL_STYLE_ACTION = "html-logical-style-action";
public static final String IMG_ALIGN_TOP = "html-image-align-top";
public static final String IMG_ALIGN_MIDDLE = "html-image-align-middle";
public static final String IMG_ALIGN_BOTTOM = "html-image-align-bottom";
public static final String IMG_BORDER = "html-image-border";
private static final String INSERT_TABLE_HTML = "
";
private static final String INSERT_UL_HTML = "";
private static final String INSERT_OL_HTML = "
";
private static final String INSERT_HR_HTML = "
";
private static final String INSERT_PRE_HTML = "";
private static final HTMLEditorKit.NavigateLinkAction nextLinkAction;
private static final HTMLEditorKit.NavigateLinkAction previousLinkAction;
private static final HTMLEditorKit.ActivateLinkAction activateLinkAction;
private static final Action[] defaultActions;
private boolean foundLink;
private int prevHypertextOffset;
private Object linkNavigationTag;
public HTMLEditorKit() {
this.linkHandler = new HTMLEditorKit.LinkController();
this.defaultCursor = HTMLEditorKit.DefaultCursor;
this.linkCursor = HTMLEditorKit.MoveCursor;
this.isAutoFormSubmission = true;
this.foundLink = false;
this.prevHypertextOffset = -1;
}
@Override
public String getContentType() {
return "text/html";
}
@Override
public ViewFactory getViewFactory() {
return HTMLEditorKit.defaultFactory;
}
@Override
public Document createDefaultDocument() {
StyleSheet styleSheet = this.getStyleSheet();
StyleSheet styleSheet2 = new StyleSheet();
styleSheet2.addStyleSheet(styleSheet);
HTMLDocument htmlDocument = new HTMLDocument(styleSheet2);
htmlDocument.setParser(this.getParser());
htmlDocument.setAsynchronousLoadPriority(4);
htmlDocument.setTokenThreshold(100);
return htmlDocument;
}
private HTMLEditorKit.Parser ensureParser(HTMLDocument htmlDocument) throws IOException {
HTMLEditorKit.Parser parser = htmlDocument.getParser();
if (parser == null) {
parser = this.getParser();
}
if (parser == null) {
throw new IOException("Can't load parser");
}
return parser;
}
@Override
public void read(Reader in, Document doc, int n) throws IOException, BadLocationException {
if ((doc instanceof HTMLDocument)) {
HTMLDocument htmlDocument = (HTMLDocument)doc;
if (n > doc.getLength()) {
throw new BadLocationException("Invalid location", n);
}
HTMLEditorKit.Parser ensureParser = this.ensureParser(htmlDocument);
HTMLEditorKit.ParserCallback reader = htmlDocument.getReader(n);
Boolean b = (Boolean)doc.getProperty("IgnoreCharsetDirective");
ensureParser.parse(in, reader, b != null && (boolean)b);
reader.flush();
}
else {
super.read(in, doc, n);
}
}
public void insertHTML(HTMLDocument htmlDocument, int offs, String s, int n, int n2, HTML.Tag tag) throws BadLocationException, IOException {
if (offs > htmlDocument.getLength()) {
throw new BadLocationException("Invalid location", offs);
}
HTMLEditorKit.Parser ensureParser = this.ensureParser(htmlDocument);
HTMLEditorKit.ParserCallback reader = htmlDocument.getReader(offs, n, n2, tag);
Boolean b = (Boolean)htmlDocument.getProperty("IgnoreCharsetDirective");
ensureParser.parse(new StringReader(s), reader, b != null && (boolean)b);
reader.flush();
return;
}
@Override
public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {
if ((doc instanceof HTMLDocument)) {
new HTMLWriter(out, (HTMLDocument)doc, pos, len).write();
}
else if ((doc instanceof StyledDocument)) {
new MinimalHTMLWriter(out, (StyledDocument)doc, pos, len).write();
}
else {
super.write(out, doc, pos, len);
}
}
@Override
public void install(JEditorPane editorPane) {
editorPane.addMouseListener(this.linkHandler);
editorPane.addMouseMotionListener(this.linkHandler);
editorPane.addCaretListener(HTMLEditorKit.nextLinkAction);
super.install(editorPane);
this.theEditor = editorPane;
}
@Override
public void deinstall(JEditorPane c) {
c.removeMouseListener(this.linkHandler);
c.removeMouseMotionListener(this.linkHandler);
c.removeCaretListener(HTMLEditorKit.nextLinkAction);
super.deinstall(c);
this.theEditor = null;
}
public void setStyleSheet(StyleSheet value) {
if (value == null) {
AppContext.getAppContext().remove(HTMLEditorKit.DEFAULT_STYLES_KEY);
}
else {
AppContext.getAppContext().put(HTMLEditorKit.DEFAULT_STYLES_KEY, value);
}
}
public StyleSheet getStyleSheet() {
AppContext appContext = AppContext.getAppContext();
StyleSheet value = (StyleSheet)appContext.get(HTMLEditorKit.DEFAULT_STYLES_KEY);
if (value == null) {
value = new StyleSheet();
appContext.put(HTMLEditorKit.DEFAULT_STYLES_KEY, value);
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(getResourceAsStream("default.css"), "ISO-8859-1"));
value.loadRules(bufferedReader, null);
bufferedReader.close();
}
catch (Throwable t) {}
}
return value;
}
static InputStream getResourceAsStream(final String s) {
return (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
@Override
public InputStream run() {
return HTMLEditorKit.class.getResourceAsStream(s);
}
});
}
@Override
public Action[] getActions() {
return TextAction.augmentList(super.getActions(), HTMLEditorKit.defaultActions);
}
@Override
protected void createInputAttributes(Element element, MutableAttributeSet set) {
set.removeAttributes(set);
set.addAttributes(element.getAttributes());
set.removeAttribute(StyleConstants.ComposedTextAttribute);
Object attribute = set.getAttribute(StyleConstants.NameAttribute);
if ((attribute instanceof HTML.Tag)) {
HTML.Tag tag = (HTML.Tag)attribute;
if (tag == HTML.Tag.IMG) {
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) {
set.addAttribute(StyleConstants.NameAttribute, HTML.Tag.CONTENT);
}
else if (tag == HTML.Tag.COMMENT) {
set.addAttribute(StyleConstants.NameAttribute, HTML.Tag.CONTENT);
set.removeAttribute(HTML.Attribute.COMMENT);
}
else if (tag == HTML.Tag.INPUT) {
set.addAttribute(StyleConstants.NameAttribute, HTML.Tag.CONTENT);
set.removeAttribute(HTML.Tag.INPUT);
}
else if ((tag instanceof HTML.UnknownTag)) {
set.addAttribute(StyleConstants.NameAttribute, HTML.Tag.CONTENT);
set.removeAttribute(HTML.Attribute.ENDTAG);
}
}
}
@Override
public MutableAttributeSet getInputAttributes() {
if (this.input == null) {
this.input = this.getStyleSheet().addStyle(null, null);
}
return this.input;
}
public void setDefaultCursor(Cursor defaultCursor) {
this.defaultCursor = defaultCursor;
}
public Cursor getDefaultCursor() {
return this.defaultCursor;
}
public void setLinkCursor(Cursor linkCursor) {
this.linkCursor = linkCursor;
}
public Cursor getLinkCursor() {
return this.linkCursor;
}
public boolean isAutoFormSubmission() {
return this.isAutoFormSubmission;
}
public void setAutoFormSubmission(boolean isAutoFormSubmission) {
this.isAutoFormSubmission = isAutoFormSubmission;
}
@Override
public Object clone() {
HTMLEditorKit htmlEditorKit = (HTMLEditorKit)super.clone();
if (htmlEditorKit != null) {
htmlEditorKit.input = null;
htmlEditorKit.linkHandler = new HTMLEditorKit.LinkController();
return htmlEditorKit;
}
return htmlEditorKit;
}
protected HTMLEditorKit.Parser getParser() {
if (HTMLEditorKit.defaultParser == null) {
try {
HTMLEditorKit.defaultParser = (HTMLEditorKit.Parser)Class.forName("javax.swing.text.html.parser.ParserDelegator").newInstance();
}
catch (Throwable t) {}
}
return HTMLEditorKit.defaultParser;
}
@Override
public AccessibleContext getAccessibleContext() {
if (this.theEditor == null) {
return null;
}
if (this.accessibleContext == null) {
this.accessibleContext = new AccessibleHTML(this.theEditor).getAccessibleContext();
}
return this.accessibleContext;
}
private static Object getAttrValue(AttributeSet set, HTML.Attribute attribute) {
Enumeration