?? htmleditorkit.java
字號:
return r1.contains(x, y); } catch (BadLocationException ble) { } } return true; } /** * Calls linkActivated on the associated JEditorPane * if the given position represents a link.<p>This is implemented * to forward to the method with the same name, but with the following * args both == -1. * * @param pos the position * @param editor the editor pane */ protected void activateLink(int pos, JEditorPane editor) { activateLink(pos, editor, -1, -1); } /** * Calls linkActivated on the associated JEditorPane * if the given position represents a link. If this was the result * of a mouse click, <code>x</code> and * <code>y</code> will give the location of the mouse, otherwise * they will be < 0. * * @param pos the position * @param html the editor pane */ void activateLink(int pos, JEditorPane html, int x, int y) { Document doc = html.getDocument(); if (doc instanceof HTMLDocument) { HTMLDocument hdoc = (HTMLDocument) doc; Element e = hdoc.getCharacterElement(pos); AttributeSet a = e.getAttributes(); AttributeSet anchor = (AttributeSet)a.getAttribute(HTML.Tag.A); HyperlinkEvent linkEvent = null; String description; if (anchor == null) { href = getMapHREF(html, hdoc, e, a, pos, x, y); } else { href = (String)anchor.getAttribute(HTML.Attribute.HREF); } if (href != null) { linkEvent = createHyperlinkEvent(html, hdoc, href, anchor, e); } if (linkEvent != null) { html.fireHyperlinkUpdate(linkEvent); } } } /** * Creates and returns a new instance of HyperlinkEvent. If * <code>hdoc</code> is a frame document a HTMLFrameHyperlinkEvent * will be created. */ HyperlinkEvent createHyperlinkEvent(JEditorPane html, HTMLDocument hdoc, String href, AttributeSet anchor, Element element) { URL u; try { URL base = hdoc.getBase(); u = new URL(base, href); // Following is a workaround for 1.2, in which // new URL("file://...", "#...") causes the filename to // be lost. if (href != null && "file".equals(u.getProtocol()) && href.startsWith("#")) { String baseFile = base.getFile(); String newFile = u.getFile(); if (baseFile != null && newFile != null && !newFile.startsWith(baseFile)) { u = new URL(base, baseFile + href); } } } catch (MalformedURLException m) { u = null; } HyperlinkEvent linkEvent = null; if (!hdoc.isFrameDocument()) { linkEvent = new HyperlinkEvent(html, HyperlinkEvent.EventType. ACTIVATED, u, href, element); } else { String target = (anchor != null) ? (String)anchor.getAttribute(HTML.Attribute.TARGET) : null; if ((target == null) || (target.equals(""))) { target = hdoc.getBaseTarget(); } if ((target == null) || (target.equals(""))) { target = "_self"; } linkEvent = new HTMLFrameHyperlinkEvent(html, HyperlinkEvent. EventType.ACTIVATED, u, href, element, target); } return linkEvent; } void fireEvents(JEditorPane editor, HTMLDocument doc, String href, Element lastElem) { if (this.href != null) { // fire an exited event on the old link URL u; try { u = new URL(doc.getBase(), this.href); } catch (MalformedURLException m) { u = null; } HyperlinkEvent exit = new HyperlinkEvent(editor, HyperlinkEvent.EventType.EXITED, u, this.href, lastElem); editor.fireHyperlinkUpdate(exit); } if (href != null) { // fire an entered event on the new link URL u; try { u = new URL(doc.getBase(), href); } catch (MalformedURLException m) { u = null; } HyperlinkEvent entered = new HyperlinkEvent(editor, HyperlinkEvent.EventType.ENTERED, u, href, curElem); editor.fireHyperlinkUpdate(entered); } } } /** * Interface to be supported by the parser. This enables * providing a different parser while reusing some of the * implementation provided by this editor kit. */ public static abstract class Parser { /** * Parse the given stream and drive the given callback * with the results of the parse. This method should * be implemented to be thread-safe. */ public abstract void parse(Reader r, ParserCallback cb, boolean ignoreCharSet) throws IOException; } /** * The result of parsing drives these callback methods. * The open and close actions should be balanced. The * <code>flush</code> method will be the last method * called, to give the receiver a chance to flush any * pending data into the document. * <p>Refer to DocumentParser, the default parser used, for further * information on the contents of the AttributeSets, the positions, and * other info. * * @see javax.swing.text.html.parser.DocumentParser */ public static class ParserCallback { /** * This is passed as an attribute in the attributeset to indicate * the element is implied eg, the string '<>foo<\t>' * contains an implied html element and an implied body element. * * @since 1.3 */ public static final Object IMPLIED = "_implied_"; public void flush() throws BadLocationException { } public void handleText(char[] data, int pos) { } public void handleComment(char[] data, int pos) { } public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) { } public void handleEndTag(HTML.Tag t, int pos) { } public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos) { } public void handleError(String errorMsg, int pos){ } /** * This is invoked after the stream has been parsed, but before * <code>flush</code>. <code>eol</code> will be one of \n, \r * or \r\n, which ever is encountered the most in parsing the * stream. * * @since 1.3 */ public void handleEndOfLineString(String eol) { } } /** * A factory to build views for HTML. The following * table describes what this factory will build by * default. * * <table summary="Describes the tag and view created by this factory by default"> * <tr> * <th align=left>Tag<th align=left>View created * </tr><tr> * <td>HTML.Tag.CONTENT<td>InlineView * </tr><tr> * <td>HTML.Tag.IMPLIED<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.P<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.H1<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.H2<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.H3<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.H4<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.H5<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.H6<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.DT<td>javax.swing.text.html.ParagraphView * </tr><tr> * <td>HTML.Tag.MENU<td>ListView * </tr><tr> * <td>HTML.Tag.DIR<td>ListView * </tr><tr> * <td>HTML.Tag.UL<td>ListView * </tr><tr> * <td>HTML.Tag.OL<td>ListView * </tr><tr> * <td>HTML.Tag.LI<td>BlockView * </tr><tr> * <td>HTML.Tag.DL<td>BlockView * </tr><tr> * <td>HTML.Tag.DD<td>BlockView * </tr><tr> * <td>HTML.Tag.BODY<td>BlockView * </tr><tr> * <td>HTML.Tag.HTML<td>BlockView * </tr><tr> * <td>HTML.Tag.CENTER<td>BlockView * </tr><tr> * <td>HTML.Tag.DIV<td>BlockView * </tr><tr> * <td>HTML.Tag.BLOCKQUOTE<td>BlockView * </tr><tr> * <td>HTML.Tag.PRE<td>BlockView * </tr><tr> * <td>HTML.Tag.BLOCKQUOTE<td>BlockView * </tr><tr> * <td>HTML.Tag.PRE<td>BlockView * </tr><tr> * <td>HTML.Tag.IMG<td>ImageView * </tr><tr> * <td>HTML.Tag.HR<td>HRuleView * </tr><tr> * <td>HTML.Tag.BR<td>BRView * </tr><tr> * <td>HTML.Tag.TABLE<td>javax.swing.text.html.TableView * </tr><tr> * <td>HTML.Tag.INPUT<td>FormView * </tr><tr> * <td>HTML.Tag.SELECT<td>FormView * </tr><tr> * <td>HTML.Tag.TEXTAREA<td>FormView * </tr><tr> * <td>HTML.Tag.OBJECT<td>ObjectView * </tr><tr> * <td>HTML.Tag.FRAMESET<td>FrameSetView * </tr><tr> * <td>HTML.Tag.FRAME<td>FrameView * </tr> * </table> */ public static class HTMLFactory implements ViewFactory { /** * Creates a view from an element. * * @param elem the element * @return the view */ public View create(Element elem) { Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute); if (o instanceof HTML.Tag) { HTML.Tag kind = (HTML.Tag) o; if (kind == HTML.Tag.CONTENT) { return new InlineView(elem); } else if (kind == HTML.Tag.IMPLIED) { String ws = (String) elem.getAttributes().getAttribute( CSS.Attribute.WHITE_SPACE); if ((ws != null) && ws.equals("pre")) { return new LineView(elem); } return new javax.swing.text.html.ParagraphView(elem); } else if ((kind == HTML.Tag.P) || (kind == HTML.Tag.H1) || (kind == HTML.Tag.H2) || (kind == HTML.Tag.H3) || (kind == HTML.Tag.H4) || (kind == HTML.Tag.H5) || (kind == HTML.Tag.H6) || (kind == HTML.Tag.DT)) { // paragraph return new javax.swing.text.html.ParagraphView(elem); } else if ((kind == HTML.Tag.MENU) || (kind == HTML.Tag.DIR) || (kind == HTML.Tag.UL) || (kind == HTML.Tag.OL)) { return new ListView(elem); } else if (kind == HTML.Tag.BODY) { return new BodyBlockView(elem); } else if (kind == HTML.Tag.HTML) { return new BlockView(elem, View.Y_AXIS); } else if ((kind == HTML.Tag.LI) || (kind == HTML.Tag.CENTER) || (kind == HTML.Tag.DL) || (kind == HTML.Tag.DD) || (kind == HTML.Tag.DIV) || (kind == HTML.Tag.BLOCKQUOTE) || (kind == HTML.Tag.PRE) || (kind == HTML.Tag.FORM)) { // vertical box return new BlockView(elem, View.Y_AXIS); } else if (kind == HTML.Tag.NOFRAMES) { return new NoFramesView(elem, View.Y_AXIS); } else if (kind==HTML.Tag.IMG) { return new ImageView(elem); } else if (kind == HTML.Tag.ISINDEX) { return new IsindexView(elem); } else if (kind == HTML.Tag.HR) { return new HRuleView(elem); } else if (kind == HTML.Tag.BR) { return new BRView(elem); } else if (kind == HTML.Tag.TABLE) { return new javax.swing.text.html.TableView(elem); } else if ((kind == HTML.Tag.INPUT) || (kind == HTML.Tag.SELECT) || (kind == HTML.Tag.TEXTAREA)) { return new FormView(elem); } else if (kind == HTML.Tag.OBJECT) { return new ObjectView(elem); } else if (kind == HTML.Tag.FRAMESET) { if (elem.getAttributes().isDefined(HTML.Attribute.ROWS)) { return new FrameSetView(elem, View.Y_AXIS); } else if (elem.getAttributes().isDefined(HTML.Attribute.COLS)) { return new FrameSetView(elem, View.X_AXIS); } throw new RuntimeException("Can't build a" + kind + ", " + elem + ":" + "no ROWS or COLS defined."); } else if (kind == HTML.Tag.FRAME) { return new FrameView(elem); } else if (kind instanceof HTML.UnknownTag) { return new HiddenTagView(elem); } else if (kind == HTML.Tag.COMMENT) { return new CommentView(elem); } else if (kind == HTML.Tag.HEAD) { // Make the head never visible, and never load its // children. For Cursor positioning, // getNextVisualPositionFrom is overriden to always return // the end offset of the element. return new BlockView(elem, View.X_AXIS) { public float getPreferredSpan(int axis) { return 0; } public float getMinimumSpan(int axis) { return 0; } public float getMaximumSpan(int axis) { return 0; } protected void loadChildren(ViewFactory f) { }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -