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 attributeNames = set.getAttributeNames();
        while (attributeNames.hasMoreElements()) {
            Object nextElement = attributeNames.nextElement();
            Object attribute2 = set.getAttribute(nextElement);
            if ((attribute2 instanceof AttributeSet)) {
                Object attrValue = getAttrValue((AttributeSet)attribute2, attribute);
                if (attrValue != null) {
                    return attrValue;
                }
                continue;
            }
            else {
                if (nextElement == attribute) {
                    return attribute2;
                }
                continue;
            }
        }
        return null;
    }
    
    private static int getBodyElementStart(JTextComponent textComponent) {
        Element element = textComponent.getDocument().getRootElements()[0];
        int i = 0;
        while (i < element.getElementCount()) {
            Element element2 = element.getElement(i);
            if ("body".equals(element2.getName())) {
                return element2.getStartOffset();
            }
            ++i;
        }
        return 0;
    }
    
    static Object access$200(AttributeSet set, HTML.Attribute attribute) {
        return getAttrValue(set, attribute);
    }
    
    static int access$400(JTextComponent textComponent) {
        return getBodyElementStart(textComponent);
    }
    
    static {
        MoveCursor = Cursor.getPredefinedCursor(12);
        DefaultCursor = Cursor.getPredefinedCursor(0);
        defaultFactory = new HTMLEditorKit.HTMLFactory();
        DEFAULT_STYLES_KEY = new Object();
        HTMLEditorKit.defaultParser = null;
        nextLinkAction = new HTMLEditorKit.NavigateLinkAction("next-link-action");
        previousLinkAction = new HTMLEditorKit.NavigateLinkAction("previous-link-action");
        activateLinkAction = new HTMLEditorKit.ActivateLinkAction("activate-link-action");
        defaultActions = new Action[] { new HTMLEditorKit.InsertHTMLTextAction("InsertTable", "
", HTML.Tag.BODY, HTML.Tag.TABLE), new HTMLEditorKit.InsertHTMLTextAction("InsertTableRow", "
", HTML.Tag.TABLE, HTML.Tag.TR, HTML.Tag.BODY, HTML.Tag.TABLE), new HTMLEditorKit.InsertHTMLTextAction("InsertTableDataCell", "
", HTML.Tag.TR, HTML.Tag.TD, HTML.Tag.BODY, HTML.Tag.TABLE), new HTMLEditorKit.InsertHTMLTextAction("InsertUnorderedList", "", HTML.Tag.BODY, HTML.Tag.UL), new HTMLEditorKit.InsertHTMLTextAction("InsertUnorderedListItem", "", HTML.Tag.UL, HTML.Tag.LI, HTML.Tag.BODY, HTML.Tag.UL), new HTMLEditorKit.InsertHTMLTextAction("InsertOrderedList", "
", HTML.Tag.BODY, HTML.Tag.OL), new HTMLEditorKit.InsertHTMLTextAction("InsertOrderedListItem", "
", HTML.Tag.OL, HTML.Tag.LI, HTML.Tag.BODY, HTML.Tag.OL), new HTMLEditorKit.InsertHRAction(), new HTMLEditorKit.InsertHTMLTextAction("InsertPre", "
", HTML.Tag.BODY, HTML.Tag.PRE), HTMLEditorKit.nextLinkAction, HTMLEditorKit.previousLinkAction, HTMLEditorKit.activateLinkAction, new HTMLEditorKit.BeginAction("caret-begin", false), new HTMLEditorKit.BeginAction("selection-begin", true) };
    }
    
    public static class LinkController extends MouseAdapter implements MouseMotionListener, Serializable
    {
        private Element curElem;
        private boolean curElemImage;
        private String href;
        private transient Position.Bias[] bias;
        private int curOffset;
        
        public LinkController() {
            this.curElem = null;
            this.curElemImage = false;
            this.href = null;
            this.bias = new Position.Bias[1];
        }
        
        @Override
        public void mouseClicked(MouseEvent anEvent) {
            JEditorPane editorPane = (JEditorPane)anEvent.getSource();
            if (!editorPane.isEditable() && editorPane.isEnabled() && SwingUtilities.isLeftMouseButton(anEvent)) {
                int viewToModel = editorPane.viewToModel(new Point(anEvent.getX(), anEvent.getY()));
                if (viewToModel >= 0) {
                    this.activateLink(viewToModel, editorPane, anEvent);
                }
            }
        }
        
        @Override
        public void mouseDragged(MouseEvent mouseEvent) {
        }
        
        @Override
        public void mouseMoved(MouseEvent mouseEvent) {
            JEditorPane editorPane = (JEditorPane)mouseEvent.getSource();
            if (!editorPane.isEnabled()) {
                return;
            }
            HTMLEditorKit htmlEditorKit = (HTMLEditorKit)editorPane.getEditorKit();
            boolean n = true;
            Cursor cursor = htmlEditorKit.getDefaultCursor();
            if (!editorPane.isEditable()) {
                int viewToModel = editorPane.getUI().viewToModel(editorPane, new Point(mouseEvent.getX(), mouseEvent.getY()), this.bias);
                if (this.bias[0] == Position.Bias.Backward && viewToModel > 0) {
                    --viewToModel;
                }
                if (viewToModel >= 0 && editorPane.getDocument() instanceof HTMLDocument) {
                    HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
                    Element characterElement = htmlDocument.getCharacterElement(viewToModel);
                    if (!this.doesElementContainLocation(editorPane, characterElement, viewToModel, mouseEvent.getX(), mouseEvent.getY())) {
                        characterElement = null;
                    }
                    if (this.curElem != characterElement || this.curElemImage) {
                        Element curElem = this.curElem;
                        this.curElem = characterElement;
                        String mapHREF = null;
                        this.curElemImage = false;
                        if (characterElement != null) {
                            AttributeSet attributes = characterElement.getAttributes();
                            AttributeSet set = (AttributeSet)attributes.getAttribute(HTML.Tag.A);
                            if (set == null) {
                                this.curElemImage = (attributes.getAttribute(StyleConstants.NameAttribute) == HTML.Tag.IMG);
                                if (this.curElemImage) {
                                    mapHREF = this.getMapHREF(editorPane, htmlDocument, characterElement, attributes, viewToModel, mouseEvent.getX(), mouseEvent.getY());
                                }
                            }
                            else {
                                mapHREF = (String)set.getAttribute(HTML.Attribute.HREF);
                            }
                        }
                        if (mapHREF != this.href) {
                            this.fireEvents(editorPane, htmlDocument, mapHREF, curElem, mouseEvent);
                            if ((this.href = mapHREF) != null) {
                                cursor = htmlEditorKit.getLinkCursor();
                            }
                        }
                        else {
                            n = false;
                        }
                    }
                    else {
                        n = false;
                    }
                    this.curOffset = viewToModel;
                }
            }
            if (n && editorPane.getCursor() != cursor) {
                editorPane.setCursor(cursor);
            }
            return;
        }
        
        private String getMapHREF(JEditorPane editorPane, HTMLDocument htmlDocument, Element element, AttributeSet set, int n, int n2, int n3) {
            Object attribute = set.getAttribute(HTML.Attribute.USEMAP);
            if (attribute != null && attribute instanceof String) {
                Map map = htmlDocument.getMap((String)attribute);
                if (map != null && n < htmlDocument.getLength()) {
                    TextUI ui = editorPane.getUI();
                    Rectangle bounds;
                    try {
                        Rectangle modelToView = ui.modelToView(editorPane, n, Position.Bias.Forward);
                        Rectangle modelToView2 = ui.modelToView(editorPane, n + 1, Position.Bias.Backward);
                        bounds = modelToView.getBounds();
                        bounds.add((modelToView2 instanceof Rectangle) ? ((Rectangle)modelToView2) : modelToView2.getBounds());
                    }
                    catch (BadLocationException ex) {
                        bounds = null;
                    }
                    if (bounds != null) {
                        AttributeSet area = map.getArea(n2 - bounds.x, n3 - bounds.y, bounds.width, bounds.height);
                        if (area != null) {
                            return (String)area.getAttribute(HTML.Attribute.HREF);
                        }
                    }
                }
            }
            return null;
        }
        
        private boolean doesElementContainLocation(JEditorPane editorPane, Element element, int n, int x, int y) {
            if (element != null && n > 0 && element.getStartOffset() == n) {
                try {
                    TextUI ui = editorPane.getUI();
                    Rectangle modelToView = ui.modelToView(editorPane, n, Position.Bias.Forward);
                    if (modelToView == null) {
                        return false;
                    }
                    Rectangle rectangle = (modelToView instanceof Rectangle) ? ((Rectangle)modelToView) : modelToView.getBounds();
                    Rectangle modelToView2 = ui.modelToView(editorPane, element.getEndOffset(), Position.Bias.Backward);
                    if (modelToView2 != null) {
                        rectangle.add((modelToView2 instanceof Rectangle) ? ((Rectangle)modelToView2) : modelToView2.getBounds());
                    }
                    return rectangle.contains(x, y);
                }
                catch (BadLocationException ex) {}
            }
            return true;
        }
        
        protected void activateLink(int n, JEditorPane editorPane) {
            this.activateLink(n, editorPane, null);
        }
        
        void activateLink(int pos, JEditorPane editorPane, MouseEvent mouseEvent) {
            Document document = editorPane.getDocument();
            if ((document instanceof HTMLDocument)) {
                HTMLDocument htmlDocument = (HTMLDocument)document;
                Element characterElement = htmlDocument.getCharacterElement(pos);
                AttributeSet attributes = characterElement.getAttributes();
                AttributeSet set = (AttributeSet)attributes.getAttribute(HTML.Tag.A);
                HyperlinkEvent hyperlinkEvent = null;
                int x = -1;
                int y = -1;
                if (mouseEvent != null) {
                    x = mouseEvent.getX();
                    y = mouseEvent.getY();
                }
                if (set == null) {
                    this.href = this.getMapHREF(editorPane, htmlDocument, characterElement, attributes, pos, x, y);
                }
                else {
                    this.href = (String)set.getAttribute(HTML.Attribute.HREF);
                }
                if (this.href != null) {
                    hyperlinkEvent = this.createHyperlinkEvent(editorPane, htmlDocument, this.href, set, characterElement, mouseEvent);
                }
                if (hyperlinkEvent != null) {
                    editorPane.fireHyperlinkUpdate(hyperlinkEvent);
                }
            }
        }
        
        HyperlinkEvent createHyperlinkEvent(JEditorPane source, HTMLDocument htmlDocument, String desc, AttributeSet set, Element sourceElement, MouseEvent inputEvent) {
            URL u;
            try {
                URL base = htmlDocument.getBase();
                u = new URL(base, desc);
                if (desc != null && "file".equals(u.getProtocol()) && desc.startsWith("#")) {
                    String file = base.getFile();
                    String file2 = u.getFile();
                    if (file != null && file2 != null && !file2.startsWith(file)) {
                        u = new URL(base, file + desc);
                    }
                }
            }
            catch (MalformedURLException ex) {
                u = null;
            }
            if (!htmlDocument.isFrameDocument()) {
                return new HyperlinkEvent(source, HyperlinkEvent.EventType.ACTIVATED, u, desc, sourceElement, inputEvent);
            }
            String baseTarget = (set != null) ? ((String)set.getAttribute(HTML.Attribute.TARGET)) : null;
            if (baseTarget == null || baseTarget.equals("")) {
                baseTarget = htmlDocument.getBaseTarget();
            }
            if (baseTarget == null || baseTarget.equals("")) {
                baseTarget = "_self";
            }
            return new HTMLFrameHyperlinkEvent(source, HyperlinkEvent.EventType.ACTIVATED, u, desc, sourceElement, inputEvent, baseTarget);
        }
        
        void fireEvents(JEditorPane editorPane, HTMLDocument htmlDocument, String s, Element sourceElement, MouseEvent mouseEvent) {
            if (this.href != null) {
                URL u;
                try {
                    u = new URL(htmlDocument.getBase(), this.href);
                }
                catch (MalformedURLException ex) {
                    u = null;
                }
                editorPane.fireHyperlinkUpdate(new HyperlinkEvent(editorPane, HyperlinkEvent.EventType.EXITED, u, this.href, sourceElement, mouseEvent));
            }
            if (s != null) {
                Object u2;
                try {
                    u2 = new URL(htmlDocument.getBase(), s);
                }
                catch (MalformedURLException ex2) {
                    u2 = null;
                }
                editorPane.fireHyperlinkUpdate(new HyperlinkEvent(editorPane, HyperlinkEvent.EventType.ENTERED, u2, s, this.curElem, mouseEvent));
            }
        }
    }
    
    public abstract static class Parser
    {
        public abstract void parse(Reader p0, HTMLEditorKit.ParserCallback p1, boolean p2) throws IOException;
    }
    
    public static class ParserCallback
    {
        public static final Object IMPLIED;
        
        public void flush() throws BadLocationException {
        }
        
        public void handleText(char[] array, int n) {
        }
        
        public void handleComment(char[] array, int n) {
        }
        
        public void handleStartTag(HTML.Tag tag, MutableAttributeSet set, int n) {
        }
        
        public void handleEndTag(HTML.Tag tag, int n) {
        }
        
        public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet set, int n) {
        }
        
        public void handleError(String s, int n) {
        }
        
        public void handleEndOfLineString(String s) {
        }
        
        static {
            IMPLIED = "_implied_";
        }
    }
    
    public static class HTMLFactory implements ViewFactory
    {
        @Override
        public View create(Element element) {
            AttributeSet attributes = element.getAttributes();
            Object attribute = attributes.getAttribute("$ename");
            Object o = (attribute != null) ? null : attributes.getAttribute(StyleConstants.NameAttribute);
            if ((o instanceof HTML.Tag)) {
                HTML.Tag obj = (HTML.Tag)o;
                if (obj == HTML.Tag.CONTENT) {
                    return new InlineView(element);
                }
                if (obj == HTML.Tag.IMPLIED) {
                    String s = (String)element.getAttributes().getAttribute(CSS.Attribute.WHITE_SPACE);
                    if (s != null && s.equals("pre")) {
                        return new LineView(element);
                    }
                    return new ParagraphView(element);
                }
                else {
                    if (obj == HTML.Tag.P || obj == HTML.Tag.H1 || obj == HTML.Tag.H2 || obj == HTML.Tag.H3 || obj == HTML.Tag.H4 || obj == HTML.Tag.H5 || obj == HTML.Tag.H6 || obj == HTML.Tag.DT) {
                        return new ParagraphView(element);
                    }
                    if (obj == HTML.Tag.MENU || obj == HTML.Tag.DIR || obj == HTML.Tag.UL || obj == HTML.Tag.OL) {
                        return new ListView(element);
                    }
                    if (obj == HTML.Tag.BODY) {
                        return new BodyBlockView(element);
                    }
                    if (obj == HTML.Tag.HTML) {
                        return new BlockView(element, 1);
                    }
                    if (obj == HTML.Tag.LI || obj == HTML.Tag.CENTER || obj == HTML.Tag.DL || obj == HTML.Tag.DD || obj == HTML.Tag.DIV || obj == HTML.Tag.BLOCKQUOTE || obj == HTML.Tag.PRE || obj == HTML.Tag.FORM) {
                        return new BlockView(element, 1);
                    }
                    if (obj == HTML.Tag.NOFRAMES) {
                        return new NoFramesView(element, 1);
                    }
                    if (obj == HTML.Tag.IMG) {
                        return new ImageView(element);
                    }
                    if (obj == HTML.Tag.ISINDEX) {
                        return new IsindexView(element);
                    }
                    if (obj == HTML.Tag.HR) {
                        return new HRuleView(element);
                    }
                    if (obj == HTML.Tag.BR) {
                        return new BRView(element);
                    }
                    if (obj == HTML.Tag.TABLE) {
                        return new TableView(element);
                    }
                    if (obj == HTML.Tag.INPUT || obj == HTML.Tag.SELECT || obj == HTML.Tag.TEXTAREA) {
                        return new FormView(element);
                    }
                    if (obj == HTML.Tag.OBJECT) {
                        return new ObjectView(element);
                    }
                    if (obj == HTML.Tag.FRAMESET) {
                        if (element.getAttributes().isDefined(HTML.Attribute.ROWS)) {
                            return new FrameSetView(element, 1);
                        }
                        if (element.getAttributes().isDefined(HTML.Attribute.COLS)) {
                            return new FrameSetView(element, 0);
                        }
                        throw new RuntimeException("Can't build a" + obj + ", " + element + ":no ROWS or COLS defined.");
                    }
                    else {
                        if (obj == HTML.Tag.FRAME) {
                            return new FrameView(element);
                        }
                        if ((obj instanceof HTML.UnknownTag)) {
                            return new HiddenTagView(element);
                        }
                        if (obj == HTML.Tag.COMMENT) {
                            return new CommentView(element);
                        }
                        if (obj == HTML.Tag.HEAD) {
                            return new BlockView(element, 0) {
                                @Override
                                public float getPreferredSpan(int n) {
                                    return 0.0f;
                                }
                                
                                @Override
                                public float getMinimumSpan(int n) {
                                    return 0.0f;
                                }
                                
                                @Override
                                public float getMaximumSpan(int n) {
                                    return 0.0f;
                                }
                                
                                @Override
                                protected void loadChildren(ViewFactory viewFactory) {
                                }
                                
                                @Override
                                public Shape modelToView(int n, Shape shape, Position.Bias bias) throws BadLocationException {
                                    return shape;
                                }
                                
                                @Override
                                public int getNextVisualPositionFrom(int n, Position.Bias bias, Shape shape, int n2, Position.Bias[] array) {
                                    return this.getElement().getEndOffset();
                                }
                            };
                        }
                        if (obj == HTML.Tag.TITLE || obj == HTML.Tag.META || obj == HTML.Tag.LINK || obj == HTML.Tag.STYLE || obj == HTML.Tag.SCRIPT || obj == HTML.Tag.AREA || obj == HTML.Tag.MAP || obj == HTML.Tag.PARAM || obj == HTML.Tag.APPLET) {
                            return new HiddenTagView(element);
                        }
                    }
                }
            }
            String s2 = (attribute != null) ? ((String)attribute) : element.getName();
            if (s2 != null) {
                if (s2.equals("content")) {
                    return new LabelView(element);
                }
                if (s2.equals("paragraph")) {
                    return new ParagraphView(element);
                }
                if (s2.equals("section")) {
                    return new BoxView(element, 1);
                }
                if (s2.equals("component")) {
                    return new ComponentView(element);
                }
                if (s2.equals("icon")) {
                    return new IconView(element);
                }
            }
            return new LabelView(element);
        }
        
        static class BodyBlockView extends BlockView implements ComponentListener
        {
            private Reference cachedViewPort;
            private boolean isListening;
            private int viewVisibleWidth;
            private int componentVisibleWidth;
            
            public BodyBlockView(Element element) {
                super(element, 1);
                this.cachedViewPort = null;
                this.isListening = false;
                this.viewVisibleWidth = Integer.MAX_VALUE;
                this.componentVisibleWidth = Integer.MAX_VALUE;
            }
            
            @Override
            protected SizeRequirements calculateMajorAxisRequirements(int n, SizeRequirements calculateMajorAxisRequirements) {
                calculateMajorAxisRequirements = super.calculateMajorAxisRequirements(n, calculateMajorAxisRequirements);
                calculateMajorAxisRequirements.maximum = Integer.MAX_VALUE;
                return calculateMajorAxisRequirements;
            }
            
            @Override
            protected void layoutMinorAxis(int min, int n, int[] array, int[] array2) {
                Container container = this.getContainer();
                Container parent;
                if (container != null && container instanceof JEditorPane && (parent = container.getParent()) != null && parent instanceof JViewport) {
                    JViewport referent = (JViewport)parent;
                    if (this.cachedViewPort != null) {
                        JViewport viewport2 = (JViewport)this.cachedViewPort.get();
                        if (viewport2 != null) {
                            if (viewport2 != referent) {
                                viewport2.removeComponentListener(this);
                            }
                        }
                        else {
                            this.cachedViewPort = null;
                        }
                    }
                    if (this.cachedViewPort == null) {
                        referent.addComponentListener(this);
                        this.cachedViewPort = new WeakReference(referent);
                    }
                    this.componentVisibleWidth = referent.getExtentSize().width;
                    if (this.componentVisibleWidth > 0) {
                        this.viewVisibleWidth = this.componentVisibleWidth - container.getInsets().left - this.getLeftInset();
                        min = Math.min(min, this.viewVisibleWidth);
                    }
                }
                else if (this.cachedViewPort != null) {
                    JViewport viewport = (JViewport)this.cachedViewPort.get();
                    if (viewport != null) {
                        viewport.removeComponentListener(this);
                    }
                    this.cachedViewPort = null;
                }
                super.layoutMinorAxis(min, n, array, array2);
            }
            
            @Override
            public void setParent(View parent) {
                if (parent == null && this.cachedViewPort != null) {
                    Object value;
                    if ((value = this.cachedViewPort.get()) != null) {
                        ((JComponent)value).removeComponentListener(this);
                    }
                    this.cachedViewPort = null;
                }
                super.setParent(parent);
            }
            
            @Override
            public void componentResized(ComponentEvent componentEvent) {
                if (!(componentEvent.getSource() instanceof JViewport)) {
                    return;
                }
                if (this.componentVisibleWidth != ((JViewport)componentEvent.getSource()).getExtentSize().width && this.getDocument() instanceof AbstractDocument) {
                    AbstractDocument abstractDocument = (AbstractDocument)this.getDocument();
                    abstractDocument.readLock();
                    try {
                        this.layoutChanged(0);
                        this.preferenceChanged(null, true, true);
                    }
                    finally {
                        abstractDocument.readUnlock();
                    }
                }
                return;
            }
            
            @Override
            public void componentHidden(ComponentEvent componentEvent) {
            }
            
            @Override
            public void componentMoved(ComponentEvent componentEvent) {
            }
            
            @Override
            public void componentShown(ComponentEvent componentEvent) {
            }
        }
    }
    
    public abstract static class HTMLTextAction extends StyledEditorKit.StyledTextAction
    {
        public HTMLTextAction(String nm) {
            super(nm);
        }
        
        protected HTMLDocument getHTMLDocument(JEditorPane editorPane) {
            Document document = editorPane.getDocument();
            if ((document instanceof HTMLDocument)) {
                return (HTMLDocument)document;
            }
            throw new IllegalArgumentException("document must be HTMLDocument");
        }
        
        protected HTMLEditorKit getHTMLEditorKit(JEditorPane editorPane) {
            EditorKit editorKit = editorPane.getEditorKit();
            if ((editorKit instanceof HTMLEditorKit)) {
                return (HTMLEditorKit)editorKit;
            }
            throw new IllegalArgumentException("EditorKit must be HTMLEditorKit");
        }
        
        protected Element[] getElementsAt(HTMLDocument htmlDocument, int n) {
            return this.getElementsAt(htmlDocument.getDefaultRootElement(), n, 0);
        }
        
        private Element[] getElementsAt(Element element, int n, int n2) {
            if (element.isLeaf()) {
                Element[] array = new Element[n2 + 1];
                array[n2] = element;
                return array;
            }
            Element[] elements = this.getElementsAt(element.getElement(element.getElementIndex(n)), n, n2 + 1);
            elements[n2] = element;
            return elements;
        }
        
        protected int elementCountToTag(HTMLDocument htmlDocument, int pos, HTML.Tag tag) {
            int n;
            Element element;
            for (n = -1, element = htmlDocument.getCharacterElement(pos); element != null && element.getAttributes().getAttribute(StyleConstants.NameAttribute) != tag; element = element.getParentElement(), ++n) {}
            if (element == null) {
                return -1;
            }
            return n;
        }
        
        protected Element findElementMatchingTag(HTMLDocument htmlDocument, int n, HTML.Tag tag) {
            Element element = htmlDocument.getDefaultRootElement();
            Element element2 = null;
            while (element != null) {
                if (element.getAttributes().getAttribute(StyleConstants.NameAttribute) == tag) {
                    element2 = element;
                }
                element = element.getElement(element.getElementIndex(n));
            }
            return element2;
        }
    }
    
    public static class InsertHTMLTextAction extends HTMLEditorKit.HTMLTextAction
    {
        protected String html;
        protected HTML.Tag parentTag;
        protected HTML.Tag addTag;
        protected HTML.Tag alternateParentTag;
        protected HTML.Tag alternateAddTag;
        boolean adjustSelection;
        
        public InsertHTMLTextAction(String s, String s2, HTML.Tag tag, HTML.Tag tag2) {
            this(s, s2, tag, tag2, null, null);
        }
        
        public InsertHTMLTextAction(String s, String s2, HTML.Tag tag, HTML.Tag tag2, HTML.Tag tag3, HTML.Tag tag4) {
            this(s, s2, tag, tag2, tag3, tag4, true);
        }
        
        InsertHTMLTextAction(String s, String html, HTML.Tag parentTag, HTML.Tag addTag, HTML.Tag alternateParentTag, HTML.Tag alternateAddTag, boolean adjustSelection) {
            super(s);
            this.html = html;
            this.parentTag = parentTag;
            this.addTag = addTag;
            this.alternateParentTag = alternateParentTag;
            this.alternateAddTag = alternateAddTag;
            this.adjustSelection = adjustSelection;
        }
        
        protected void insertHTML(JEditorPane editorPane, HTMLDocument htmlDocument, int n, String s, int n2, int n3, HTML.Tag tag) {
            try {
                this.getHTMLEditorKit(editorPane).insertHTML(htmlDocument, n, s, n2, n3, tag);
            }
            catch (IOException obj) {
                throw new RuntimeException("Unable to insert: " + obj);
            }
            catch (BadLocationException obj2) {
                throw new RuntimeException("Unable to insert: " + obj2);
            }
        }
        
        protected void insertAtBoundary(JEditorPane editorPane, HTMLDocument htmlDocument, int n, Element element, String s, HTML.Tag tag, HTML.Tag tag2) {
            this.insertAtBoundry(editorPane, htmlDocument, n, element, s, tag, tag2);
        }
        
        @Deprecated
        protected void insertAtBoundry(JEditorPane editorPane, HTMLDocument htmlDocument, int n, Element element, String s, HTML.Tag tag, HTML.Tag tag2) {
            int n2 = n == 0;
            Element element2;
            if (n > 0 || element == null) {
                Element element3;
                for (element3 = htmlDocument.getDefaultRootElement(); element3 != null && element3.getStartOffset() != n && !element3.isLeaf(); element3 = element3.getElement(element3.getElementIndex(n))) {}
                element2 = ((element3 != null) ? element3.getParentElement() : null);
            }
            else {
                element2 = element;
            }
            if (element2 != null) {
                int n3 = 0;
                int n4 = 0;
                if (n2 && element != null) {
                    for (Element element6 = element2; element6 != null && !element6.isLeaf(); element6 = element6.getElement(element6.getElementIndex(n)), ++n3) {}
                }
                else {
                    Element element4 = element2;
                    --n;
                    while (element4 != null && !element4.isLeaf()) {
                        element4 = element4.getElement(element4.getElementIndex(n));
                        ++n3;
                    }
                    Element element5 = element2;
                    ++n;
                    while (element5 != null && element5 != element) {
                        element5 = element5.getElement(element5.getElementIndex(n));
                        ++n4;
                    }
                }
                this.insertHTML(editorPane, htmlDocument, n, s, Math.max(0, n3 - 1), n4, tag2);
            }
        }
        
        boolean insertIntoTag(JEditorPane editorPane, HTMLDocument htmlDocument, int n, HTML.Tag tag, HTML.Tag tag2) {
            Element elementMatchingTag = this.findElementMatchingTag(htmlDocument, n, tag);
            if (elementMatchingTag != null && elementMatchingTag.getStartOffset() == n) {
                this.insertAtBoundary(editorPane, htmlDocument, n, elementMatchingTag, this.html, tag, tag2);
                return true;
            }
            if (n > 0) {
                int elementCountToTag = this.elementCountToTag(htmlDocument, n - 1, tag);
                if (elementCountToTag != -1) {
                    this.insertHTML(editorPane, htmlDocument, n, this.html, elementCountToTag, 0, tag2);
                    return true;
                }
            }
            return false;
        }
        
        void adjustSelection(JEditorPane editorPane, HTMLDocument htmlDocument, int n, int n2) {
            int length = htmlDocument.getLength();
            if (length != n2 && n < length) {
                if (n > 0) {
                    String text;
                    try {
                        text = htmlDocument.getText(n - 1, 1);
                    }
                    catch (BadLocationException ex) {
                        text = null;
                    }
                    if (text != null && text.length() > 0 && text.charAt(0) == '\n') {
                        editorPane.select(n, n);
                    }
                    else {
                        editorPane.select(n + 1, n + 1);
                    }
                }
                else {
                    editorPane.select(1, 1);
                }
            }
        }
        
        @Override
        public void actionPerformed(ActionEvent e) {
            JEditorPane editor = this.getEditor(e);
            if (editor != null) {
                HTMLDocument htmlDocument = this.getHTMLDocument(editor);
                int selectionStart = editor.getSelectionStart();
                int length = htmlDocument.getLength();
                int n = this.insertIntoTag(editor, htmlDocument, selectionStart, this.parentTag, this.addTag) || this.alternateParentTag == null || this.insertIntoTag(editor, htmlDocument, selectionStart, this.alternateParentTag, this.alternateAddTag);
                if (this.adjustSelection && n) {
                    this.adjustSelection(editor, htmlDocument, selectionStart, length);
                }
            }
        }
    }
    
    static class InsertHRAction extends HTMLEditorKit.InsertHTMLTextAction
    {
        InsertHRAction() {
            super("InsertHR", "
", null, HTML.Tag.IMPLIED, null, null, false); } @Override public void actionPerformed(ActionEvent e) { JEditorPane editor = this.getEditor(e); if (editor != null) { Element paragraphElement = this.getHTMLDocument(editor).getParagraphElement(editor.getSelectionStart()); if (paragraphElement.getParentElement() != null) { this.parentTag = (HTML.Tag)paragraphElement.getParentElement().getAttributes().getAttribute(StyleConstants.NameAttribute); super.actionPerformed(e); } } } } static class NavigateLinkAction extends TextAction implements CaretListener { private static final HTMLEditorKit.NavigateLinkAction.FocusHighlightPainter focusPainter; private final boolean focusBack; public NavigateLinkAction(String s) { super(s); this.focusBack = "previous-link-action".equals(s); } @Override public void caretUpdate(CaretEvent caretEvent) { Object source = caretEvent.getSource(); if ((source instanceof JTextComponent)) { JTextComponent textComponent = (JTextComponent)source; HTMLEditorKit htmlEditorKit = this.getHTMLEditorKit(textComponent); if (htmlEditorKit != null && htmlEditorKit.foundLink) { htmlEditorKit.foundLink = false; textComponent.getAccessibleContext().firePropertyChange("AccessibleHypertextOffset", Integer.valueOf(htmlEditorKit.prevHypertextOffset), Integer.valueOf(caretEvent.getDot())); } } } @Override public void actionPerformed(ActionEvent e) { JTextComponent textComponent = this.getTextComponent(e); if (textComponent == null || textComponent.isEditable()) { return; } Document document = textComponent.getDocument(); HTMLEditorKit htmlEditorKit = this.getHTMLEditorKit(textComponent); if (document == null || htmlEditorKit == null) { return; } ElementIterator elementIterator = new ElementIterator(document); int caretPosition = textComponent.getCaretPosition(); int startOffset = -1; int endOffset = -1; Element next; while ((next = elementIterator.next()) != null) { String name = next.getName(); Object access$200 = HTMLEditorKit.access$200(next.getAttributes(), HTML.Attribute.HREF); if (!name.equals(HTML.Tag.OBJECT.toString()) && access$200 == null) { continue; } int startOffset2 = next.getStartOffset(); if (this.focusBack) { if (startOffset2 >= caretPosition && startOffset >= 0) { htmlEditorKit.foundLink = true; textComponent.setCaretPosition(startOffset); this.moveCaretPosition(textComponent, htmlEditorKit, startOffset, endOffset); htmlEditorKit.prevHypertextOffset = startOffset; return; } } else if (startOffset2 > caretPosition) { htmlEditorKit.foundLink = true; textComponent.setCaretPosition(startOffset2); this.moveCaretPosition(textComponent, htmlEditorKit, startOffset2, next.getEndOffset()); htmlEditorKit.prevHypertextOffset = startOffset2; return; } startOffset = next.getStartOffset(); endOffset = next.getEndOffset(); } if (this.focusBack && startOffset >= 0) { htmlEditorKit.foundLink = true; textComponent.setCaretPosition(startOffset); this.moveCaretPosition(textComponent, htmlEditorKit, startOffset, endOffset); htmlEditorKit.prevHypertextOffset = startOffset; } return; } private void moveCaretPosition(JTextComponent textComponent, HTMLEditorKit htmlEditorKit, int n, int n2) { Highlighter highlighter = textComponent.getHighlighter(); if (highlighter != null) { int min = Math.min(n2, n); int max = Math.max(n2, n); try { if (htmlEditorKit.linkNavigationTag != null) { highlighter.changeHighlight(htmlEditorKit.linkNavigationTag, min, max); } else { htmlEditorKit.linkNavigationTag = highlighter.addHighlight(min, max, HTMLEditorKit.NavigateLinkAction.focusPainter); } } catch (BadLocationException ex) {} } } private HTMLEditorKit getHTMLEditorKit(JTextComponent textComponent) { if ((textComponent instanceof JEditorPane)) { EditorKit editorKit = ((JEditorPane)textComponent).getEditorKit(); if ((editorKit instanceof HTMLEditorKit)) { return (HTMLEditorKit)editorKit; } } return null; } static { focusPainter = new HTMLEditorKit.NavigateLinkAction.FocusHighlightPainter(null); } static class FocusHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter { FocusHighlightPainter(Color c) { super(c); } @Override public Shape paintLayer(Graphics graphics, int p6, int p7, Shape a, JTextComponent textComponent, View view) { Color color = this.getColor(); if (color == null) { graphics.setColor(textComponent.getSelectionColor()); } else { graphics.setColor(color); } if (p6 == view.getStartOffset() && p7 == view.getEndOffset()) { Rectangle bounds; if ((a instanceof Rectangle)) { bounds = (Rectangle)a; } else { bounds = a.getBounds(); } graphics.drawRect(bounds.x, bounds.y, bounds.width - 1, bounds.height); return bounds; } else { try { Shape modelToView = view.modelToView(p6, Position.Bias.Forward, p7, Position.Bias.Backward, a); Rectangle rectangle = (modelToView instanceof Rectangle) ? ((Rectangle)modelToView) : modelToView.getBounds(); graphics.drawRect(rectangle.x, rectangle.y, rectangle.width - 1, rectangle.height); return rectangle; } catch (BadLocationException ex) { return null; } } } } } static class ActivateLinkAction extends TextAction { public ActivateLinkAction(String name) { super(name); } private void activateLink(String spec, HTMLDocument htmlDocument, JEditorPane source, int pos) { try { URL u = new URL((URL)htmlDocument.getProperty("stream"), spec); source.fireHyperlinkUpdate(new HyperlinkEvent(source, HyperlinkEvent.EventType.ACTIVATED, u, u.toExternalForm(), htmlDocument.getCharacterElement(pos))); } catch (MalformedURLException ex) {} } private void doObjectAction(JEditorPane editorPane, Element element) { View view = this.getView(editorPane, element); if (view != null && view instanceof ObjectView) { Component component = ((ObjectView)view).getComponent(); if (component != null && component instanceof Accessible) { AccessibleContext accessibleContext = component.getAccessibleContext(); if (accessibleContext != null) { AccessibleAction accessibleAction = accessibleContext.getAccessibleAction(); if (accessibleAction != null) { accessibleAction.doAccessibleAction(0); } } } } } private View getRootView(JEditorPane editorPane) { return editorPane.getUI().getRootView(editorPane); } private View getView(JEditorPane editorPane, Element element) { Object lock = this.lock(editorPane); try { View rootView = this.getRootView(editorPane); int startOffset = element.getStartOffset(); if (rootView != null) { return this.getView(rootView, element, startOffset); } return null; } finally { this.unlock(lock); } } private View getView(View view, Element element, int pos) { if (view.getElement() == element) { return view; } int viewIndex = view.getViewIndex(pos, Position.Bias.Forward); if (viewIndex != -1 && viewIndex < view.getViewCount()) { return this.getView(view.getView(viewIndex), element, pos); } return null; } private Object lock(JEditorPane editorPane) { Document document = editorPane.getDocument(); if ((document instanceof AbstractDocument)) { ((AbstractDocument)document).readLock(); return document; } return null; } private void unlock(Object o) { if (o != null) { ((AbstractDocument)o).readUnlock(); } } @Override public void actionPerformed(ActionEvent e) { JTextComponent textComponent = this.getTextComponent(e); if (textComponent.isEditable() || !(textComponent instanceof JEditorPane)) { return; } JEditorPane editorPane = (JEditorPane)textComponent; Document document = editorPane.getDocument(); if (document == null || !(document instanceof HTMLDocument)) { return; } HTMLDocument document2 = (HTMLDocument)document; ElementIterator elementIterator = new ElementIterator(document2); int caretPosition = editorPane.getCaretPosition(); Element next; while ((next = elementIterator.next()) != null) { String name = next.getName(); AttributeSet attributes = next.getAttributes(); Object access$200 = HTMLEditorKit.access$200(attributes, HTML.Attribute.HREF); if (access$200 != null) { if (caretPosition >= next.getStartOffset() && caretPosition <= next.getEndOffset()) { this.activateLink((String)access$200, document2, editorPane, caretPosition); return; } continue; } else { if (name.equals(HTML.Tag.OBJECT.toString()) && HTMLEditorKit.access$200(attributes, HTML.Attribute.CLASSID) != null && caretPosition >= next.getStartOffset() && caretPosition <= next.getEndOffset()) { this.doObjectAction(editorPane, next); return; } continue; } } return; } } static class BeginAction extends TextAction { private boolean select; BeginAction(String name, boolean select) { super(name); this.select = select; } @Override public void actionPerformed(ActionEvent e) { JTextComponent textComponent = this.getTextComponent(e); int access$400 = HTMLEditorKit.access$400(textComponent); if (textComponent != null) { if (this.select) { textComponent.moveCaretPosition(access$400); } else { textComponent.setCaretPosition(access$400); } } } } }