⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmleditorkit.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		} else if (nm.equals(StyleConstants.ComponentElementName)) {		    return new ComponentView(elem);		} else if (nm.equals(StyleConstants.IconElementName)) {		    return new IconView(elem);		}	    }		    // default to text display	    return new LabelView(elem);	}	private static class BodyBlockView extends BlockView implements ComponentListener {	    public BodyBlockView(Element elem) {		super(elem,View.Y_AXIS);	    }	    // reimplement major axis requirements to indicate that the	    // block is flexible for the body element... so that it can	    // be stretched to fill the background properly.	    protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {		r = super.calculateMajorAxisRequirements(axis, r);		r.maximum = Integer.MAX_VALUE;		return r;	    }	    protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {		//idk		//Thread.currentThread().dumpStack();		//idk		Container container = getContainer();		Container parentContainer;		if (container != null		    && (container instanceof javax.swing.JEditorPane) 		    && (parentContainer = container.getParent()) != null		    && (parentContainer instanceof javax.swing.JViewport)) {		    JViewport viewPort = (JViewport)parentContainer;		    Object cachedObject;		    if (cachedViewPort != null) {			if ((cachedObject = cachedViewPort.get()) != null) {			    if (cachedObject != viewPort) { 				((JComponent)cachedObject).removeComponentListener(this);			    }			} else {			    cachedViewPort = null;			}		    }		    if (cachedViewPort == null) {			viewPort.addComponentListener(this);			cachedViewPort = new WeakReference(viewPort);		    }		    int n = getViewCount();		    componentVisibleWidth = viewPort.getExtentSize().width;		    Insets insets = container.getInsets();		    viewVisibleWidth = componentVisibleWidth - insets.left - getLeftInset(); 		    //try to use viewVisibleWidth if it is smaller than targetSpan		    targetSpan = Math.min(targetSpan, viewVisibleWidth);                    Object key = (axis == X_AXIS) ? CSS.Attribute.WIDTH : CSS.Attribute.HEIGHT;		    for (int i = 0; i < n; i++) {			View v = getView(i);			int min = (int) v.getMinimumSpan(axis);			int max = (int) v.getMaximumSpan(axis);                                               // check for percentage span                        AttributeSet a = v.getAttributes();                        CSS.LengthValue lv = (CSS.LengthValue) a.getAttribute(key);                        if ((lv != null) && lv.isPercentage()) {                            // bound the span to the percentage specified                            min = Math.max((int) lv.getValue(targetSpan),min);                            max = min;                        }			if (max < targetSpan) {			    // can't make the child this wide, align it			    float align = v.getAlignment(axis);			    offsets[i] = (int) ((targetSpan - max) * align);			    spans[i] = max;			} else {			    // make it the target width, or as small as it can get.			    offsets[i] = 0;			    spans[i] = Math.max(min, targetSpan);			}		    }		} else {		    if (cachedViewPort != null) {			Object cachedObject;			if ((cachedObject = cachedViewPort.get()) != null) {			    ((JComponent)cachedObject).removeComponentListener(this);			}			cachedViewPort = null;		    }		    super.layoutMinorAxis(targetSpan,axis,offsets,spans);		}	    }	    public void setParent(View parent) {		//if parent == null unregister component listener		if (parent == null) {		    if (cachedViewPort != null) {			Object cachedObject;			if ((cachedObject = cachedViewPort.get()) != null) {			    ((JComponent)cachedObject).removeComponentListener(this);			}			cachedViewPort = null;		    }		}		super.setParent(parent);	    }	    public void componentResized(ComponentEvent e) {		if ( !(e.getSource() instanceof JViewport) ) {		    return;		}		JViewport viewPort = (JViewport)e.getSource();		if (componentVisibleWidth != viewPort.getExtentSize().width) {		    Document doc = getDocument();		    if (doc instanceof AbstractDocument) {			AbstractDocument document = (AbstractDocument)getDocument();			document.readLock();			try {			    layoutChanged(X_AXIS);			    preferenceChanged(null, true, true);			} finally {			    document.readUnlock();			}					    }		}	    }	    public void componentHidden(ComponentEvent e) {	    }	    public void componentMoved(ComponentEvent e) {	    }	    public void componentShown(ComponentEvent e) {	    }	    /*             * we keep weak reference to viewPort if and only if BodyBoxView is listening for ComponentEvents	     * only in that case cachedViewPort is not equal to null.	     * we need to keep this reference in order to remove BodyBoxView from viewPort listeners.	     * 	     */	    private Reference cachedViewPort = null; 	    private boolean isListening = false;	    private int viewVisibleWidth = Integer.MAX_VALUE;	    private int componentVisibleWidth = Integer.MAX_VALUE;	}	    }        // --- Action implementations ------------------------------/** The bold action identifier*/    public static final String	BOLD_ACTION = "html-bold-action";/** The italic action identifier*/    public static final String	ITALIC_ACTION = "html-italic-action";/** The paragraph left indent action identifier*/    public static final String	PARA_INDENT_LEFT = "html-para-indent-left";/** The paragraph right indent action identifier*/    public static final String	PARA_INDENT_RIGHT = "html-para-indent-right";/** The  font size increase to next value action identifier*/    public static final String	FONT_CHANGE_BIGGER = "html-font-bigger";/** The font size decrease to next value action identifier*/    public static final String	FONT_CHANGE_SMALLER = "html-font-smaller";/** The Color choice action identifier     The color is passed as an argument*/    public static final String	COLOR_ACTION = "html-color-action";/** The logical style choice action identifier     The logical style is passed in as an argument*/    public static final String	LOGICAL_STYLE_ACTION = "html-logical-style-action";    /**     * Align images at the top.     */    public static final String	IMG_ALIGN_TOP = "html-image-align-top";    /**     * Align images in the middle.     */    public static final String	IMG_ALIGN_MIDDLE = "html-image-align-middle";    /**     * Align images at the bottom.     */    public static final String	IMG_ALIGN_BOTTOM = "html-image-align-bottom";    /**     * Align images at the border.     */    public static final String	IMG_BORDER = "html-image-border";    /** HTML used when inserting tables. */    private static final String INSERT_TABLE_HTML = "<table border=1><tr><td></td></tr></table>";    /** HTML used when inserting unordered lists. */    private static final String INSERT_UL_HTML = "<ul><li></li></ul>";    /** HTML used when inserting ordered lists. */    private static final String INSERT_OL_HTML = "<ol><li></li></ol>";    /** HTML used when inserting hr. */    private static final String INSERT_HR_HTML = "<hr>";    /** HTML used when inserting pre. */    private static final String INSERT_PRE_HTML = "<pre></pre>";    private static NavigateLinkAction nextLinkAction = 	new NavigateLinkAction("next-link-action");    private static NavigateLinkAction previousLinkAction = 	new NavigateLinkAction("previous-link-action");    private static ActivateLinkAction activateLinkAction = 	new ActivateLinkAction("activate-link-action");	    private static final Action[] defaultActions = {	new InsertHTMLTextAction("InsertTable", INSERT_TABLE_HTML,				 HTML.Tag.BODY, HTML.Tag.TABLE),	new InsertHTMLTextAction("InsertTableRow", INSERT_TABLE_HTML,				 HTML.Tag.TABLE, HTML.Tag.TR,				 HTML.Tag.BODY, HTML.Tag.TABLE),	new InsertHTMLTextAction("InsertTableDataCell", INSERT_TABLE_HTML,				 HTML.Tag.TR, HTML.Tag.TD,				 HTML.Tag.BODY, HTML.Tag.TABLE),	new InsertHTMLTextAction("InsertUnorderedList", INSERT_UL_HTML,				 HTML.Tag.BODY, HTML.Tag.UL),	new InsertHTMLTextAction("InsertUnorderedListItem", INSERT_UL_HTML,				 HTML.Tag.UL, HTML.Tag.LI,				 HTML.Tag.BODY, HTML.Tag.UL),	new InsertHTMLTextAction("InsertOrderedList", INSERT_OL_HTML,				 HTML.Tag.BODY, HTML.Tag.OL),	new InsertHTMLTextAction("InsertOrderedListItem", INSERT_OL_HTML,				 HTML.Tag.OL, HTML.Tag.LI,				 HTML.Tag.BODY, HTML.Tag.OL),	new InsertHRAction(),	new InsertHTMLTextAction("InsertPre", INSERT_PRE_HTML,				 HTML.Tag.BODY, HTML.Tag.PRE),	nextLinkAction, previousLinkAction, activateLinkAction    };    /**     * An abstract Action providing some convenience methods that may     * be useful in inserting HTML into an existing document.     * <p>NOTE: None of the convenience methods obtain a lock on the     * document. If you have another thread modifying the text these     * methods may have inconsistent behavior, or return the wrong thing.     */    public static abstract class HTMLTextAction extends StyledTextAction {	public HTMLTextAction(String name) {	    super(name);	}	/**	 * @return HTMLDocument of <code>e</code>.	 */	protected HTMLDocument getHTMLDocument(JEditorPane e) {	    Document d = e.getDocument();	    if (d instanceof HTMLDocument) {		return (HTMLDocument) d;	    }	    throw new IllegalArgumentException("document must be HTMLDocument");	}	/**	 * @return HTMLEditorKit for <code>e</code>.	 */        protected HTMLEditorKit getHTMLEditorKit(JEditorPane e) {	    EditorKit k = e.getEditorKit();	    if (k instanceof HTMLEditorKit) {		return (HTMLEditorKit) k;	    }	    throw new IllegalArgumentException("EditorKit must be HTMLEditorKit");	}	/**	 * Returns an array of the Elements that contain <code>offset</code>.	 * The first elements corresponds to the root.	 */	protected Element[] getElementsAt(HTMLDocument doc, int offset) {	    return getElementsAt(doc.getDefaultRootElement(), offset, 0);	}	/**	 * Recursive method used by getElementsAt.	 */	private Element[] getElementsAt(Element parent, int offset,					int depth) {	    if (parent.isLeaf()) {		Element[] retValue = new Element[depth + 1];		retValue[depth] = parent;		return retValue;	    }	    Element[] retValue = getElementsAt(parent.getElement			  (parent.getElementIndex(offset)), offset, depth + 1);	    retValue[depth] = parent;	    return retValue;	}	/**	 * Returns number of elements, starting at the deepest leaf, needed	 * to get to an element representing <code>tag</code>. This will	 * return -1 if no elements is found representing <code>tag</code>,	 * or 0 if the parent of the leaf at <code>offset</code> represents	 * <code>tag</code>.	 */	protected int elementCountToTag(HTMLDocument doc, int offset,					HTML.Tag tag) {	    int depth = -1;	    Element e = doc.getCharacterElement(offset);	    while (e != null && e.getAttributes().getAttribute		   (StyleConstants.NameAttribute) != tag) {		e = e.getParentElement();		depth++;	    }	    if (e == null) {		return -1;	    }	    return depth;	}	/**	 * Returns the deepest element at <code>offset</code> matching	 * <code>tag</code>.	 */	protected Element findElementMatchingTag(HTMLDocument doc, int offset,						 HTML.Tag tag) {	    Element e = doc.getDefaultRootElement();	    Element lastMatch = null;	    while (e != null) {		if (e.getAttributes().getAttribute		   (StyleConstants.NameAttribute) == tag) {		    lastMatch = e;		}		e = e.getElement(e.getElementIndex(offset));	    }	    return lastMatch;	}    }    /**     * InsertHTMLTextAction can be used to insert an arbitrary string of HTML     * into an existing HTML document. At least two HTML.Tags need to be     * supplied. The first Tag, parentTag, identifies the parent in     * the document to add the elements to. The second tag, addTag,     * identifies the first tag that should be added to the document as     * seen in the HTML string. One important thing to remember, is that     * the parser is going to generate all the appropriate tags, even if     * they aren't in the HTML string passed in.<p>     * For example, lets say you wanted to create an action to insert     * a table into the body. The parentTag would be HTML.Tag.BODY,     * addTag would be HTML.Tag.TABLE, and the string could be something     * like &lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;.     * <p>There is also an option to supply an alternate parentTag and     * addTag. These will be checked for if there is no parentTag at     * offset.     */    public static class InsertHTMLTextAction extends HTMLTextAction {	public InsertHTMLTextAction(String name, String html,				    HTML.Tag parentTag, HTML.Tag addTag) {	    this(name, html, parentTag, addTag, null, null);	}	public InsertHTMLTextAction(String name, String html,				    HTML.Tag parentTag,				    HTML.Tag addTag,				    HTML.Tag alternateParentTag,				    HTML.Tag alternateAddTag) {	    this(name, html, parentTag, addTag, alternateParentTag,		 alternateAddTag, true);	}	/* public */	InsertHTMLTextAction(String name, String html,				    HTML.Tag parentTag,				    HTML.Tag addTag,				    HTML.Tag alternateParentTag,				    HTML.Tag alternateAddTag,				    boolean adjustSelection) {	    super(name);	    this.html = html;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -