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

📄 basictextui.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 *  position is a boundary of two views. 	 * @param a the allocated region to render into	 * @return the bounding box of the given position is returned	 * @exception BadLocationException  if the given position does	 *   not represent a valid location in the associated document	 * @exception IllegalArgumentException for an invalid bias argument	 * @see View#viewToModel	 */	public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException {	    if (view != null) {		return view.modelToView(p0, b0, p1, b1, a);	    }	    return null;	}        /**         * Provides a mapping from the view coordinate space to the logical         * coordinate space of the model.         *         * @param x x coordinate of the view location to convert         * @param y y coordinate of the view location to convert         * @param a the allocated region to render into         * @return the location within the model that best represents the         *    given point in the view         */        public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {            if (view != null) {                int retValue = view.viewToModel(x, y, a, bias);		return retValue;            }            return -1;        }        /**         * Provides a way to determine the next visually represented model          * location that one might place a caret.  Some views may not be visible,         * they might not be in the same order found in the model, or they just         * might not allow access to some of the locations in the model.         *         * @param pos the position to convert >= 0         * @param a the allocated region to render into         * @param direction the direction from the current position that can         *  be thought of as the arrow keys typically found on a keyboard.         *  This may be SwingConstants.WEST, SwingConstants.EAST,          *  SwingConstants.NORTH, or SwingConstants.SOUTH.           * @return the location within the model that best represents the next         *  location visual position.         * @exception BadLocationException         * @exception IllegalArgumentException for an invalid direction         */        public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,                                              int direction,                                             Position.Bias[] biasRet)             throws BadLocationException {            if( view != null ) {                int nextPos = view.getNextVisualPositionFrom(pos, b, a,						     direction, biasRet);		if(nextPos != -1) {		    pos = nextPos;		}		else {		    biasRet[0] = b;		}            }             return pos;        }        /**         * Gives notification that something was inserted into the document         * in a location that this view is responsible for.         *         * @param e the change information from the associated document         * @param a the current allocation of the view         * @param f the factory to use to rebuild if the view has children         */        public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {            if (view != null) {                view.insertUpdate(e, a, f);            }        }                /**         * Gives notification that something was removed from the document         * in a location that this view is responsible for.         *         * @param e the change information from the associated document         * @param a the current allocation of the view         * @param f the factory to use to rebuild if the view has children         */        public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {            if (view != null) {                view.removeUpdate(e, a, f);            }        }        /**         * Gives notification from the document that attributes were changed         * in a location that this view is responsible for.         *         * @param e the change information from the associated document         * @param a the current allocation of the view         * @param f the factory to use to rebuild if the view has children         */        public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {            if (view != null) {                view.changedUpdate(e, a, f);            }        }        /**         * Returns the document model underlying the view.         *         * @return the model         */        public Document getDocument() {            return editor.getDocument();        }                /**         * Returns the starting offset into the model for this view.         *         * @return the starting offset         */        public int getStartOffset() {            if (view != null) {                return view.getStartOffset();            }            return getElement().getStartOffset();        }        /**         * Returns the ending offset into the model for this view.         *         * @return the ending offset         */        public int getEndOffset() {            if (view != null) {                return view.getEndOffset();            }            return getElement().getEndOffset();        }        /**         * Gets the element that this view is mapped to.         *         * @return the view         */        public Element getElement() {            if (view != null) {                return view.getElement();            }            return editor.getDocument().getDefaultRootElement();        }        /**         * Breaks this view on the given axis at the given length.         *         * @param axis may be either X_AXIS or Y_AXIS         * @param len specifies where a break is desired in the span         * @param the current allocation of the view         * @return the fragment of the view that represents the given span         *   if the view can be broken, otherwise null         */        public View breakView(int axis, float len, Shape a) {            throw new Error("Can't break root view");        }        /**         * Determines the resizability of the view along the         * given axis.  A value of 0 or less is not resizable.         *         * @param axis may be either X_AXIS or Y_AXIS         * @return the weight         */        public int getResizeWeight(int axis) {            if (view != null) {                return view.getResizeWeight(axis);            }            return 0;        }        /**         * Sets the view size.         *         * @param width the width         * @param height the height         */        public void setSize(float width, float height) {            if (view != null) {                view.setSize(width, height);            }        }        /**         * Fetches the container hosting the view.  This is useful for         * things like scheduling a repaint, finding out the host          * components font, etc.  The default implementation         * of this is to forward the query to the parent view.         *         * @return the container         */        public Container getContainer() {            return editor;        }                /**         * Fetches the factory to be used for building the         * various view fragments that make up the view that         * represents the model.  This is what determines         * how the model will be represented.  This is implemented         * to fetch the factory provided by the associated         * EditorKit unless that is null, in which case this         * simply returns the BasicTextUI itself which allows         * subclasses to implement a simple factory directly without         * creating extra objects.           *         * @return the factory         */        public ViewFactory getViewFactory() {            EditorKit kit = getEditorKit(editor);            ViewFactory f = kit.getViewFactory();            if (f != null) {                return f;            }            return BasicTextUI.this;        }        private View view;    }    /**     * Handles updates from various places.  If the model is changed,     * this class unregisters as a listener to the old model and      * registers with the new model.  If the document model changes,     * the change is forwarded to the root view.  If the focus     * accelerator changes, a new keystroke is registered to request     * focus.     */    class UpdateHandler implements PropertyChangeListener, DocumentListener, LayoutManager2, UIResource {        // --- PropertyChangeListener methods -----------------------        /**         * This method gets called when a bound property is changed.         * We are looking for document changes on the editor.         */        public final void propertyChange(PropertyChangeEvent evt) {            Object oldValue = evt.getOldValue();            Object newValue = evt.getNewValue();	    String propertyName = evt.getPropertyName();            if ((oldValue instanceof Document) || (newValue instanceof Document)) {                if (oldValue != null) {                    ((Document)oldValue).removeDocumentListener(this);		    i18nView = false;                }                if (newValue != null) {                    ((Document)newValue).addDocumentListener(this);                    if ("document" == propertyName) {                        setView(null);                        BasicTextUI.this.propertyChange(evt);                        modelChanged();                        return;                    }                }                modelChanged();            }	    if ("focusAccelerator" == propertyName) {		updateFocusAcceleratorBinding(true);            } else if ("componentOrientation" == propertyName) {                // Changes in ComponentOrientation require the views to be                // rebuilt.                modelChanged();            } else if ("font" == propertyName) {                modelChanged();            } else if ("dropLocation" == propertyName) {                dropIndexChanged();	    } else if ("editable" == propertyName) {                updateCursor();                modelChanged();	    }            BasicTextUI.this.propertyChange(evt);        }        private void dropIndexChanged() {            if (editor.getDropMode() == DropMode.USE_SELECTION) {                return;            }            JTextComponent.DropLocation dropLocation = editor.getDropLocation();            if (dropLocation == null) {                if (dropCaret != null) {                    dropCaret.deinstall(editor);                    editor.repaint(dropCaret);                    dropCaret = null;                }            } else {                if (dropCaret == null) {                    dropCaret = new BasicCaret();                    dropCaret.install(editor);                    dropCaret.setVisible(true);                }                dropCaret.setDot(dropLocation.getIndex(),                                 dropLocation.getBias());            }        }        // --- DocumentListener methods -----------------------        /**         * The insert notification.  Gets sent to the root of the view structure         * that represents the portion of the model being represented by the         * editor.  The factory is added as an argument to the update so that         * the views can update themselves in a dynamic (not hardcoded) way.         *         * @param e  The change notification from the currently associated         *  document.         * @see DocumentListener#insertUpdate         */        public final void insertUpdate(DocumentEvent e) {	    Document doc = e.getDocument();	    Object o = doc.getProperty("i18n");	    if (o instanceof Boolean) {		Boolean i18nFlag = (Boolean) o;		if (i18nFlag.booleanValue() != i18nView) {		    // i18n flag changed, rebuild the view		    i18nView = i18nFlag.booleanValue();		    modelChanged();		    return;		}	    }	    // normal insert update            Rectangle alloc = (painted) ? getVisibleEditorRect() : null;            rootView.insertUpdate(e, alloc, rootView.getViewFactory());        }        /**         * The remove notification.  Gets sent to the root of the view structure         * that represents the portion of the model being represented by the         * editor.  The factory is added as an argument to the update so that         * the views can update themselves in a dynamic (not hardcoded) way.         *         * @param e  The change notification from the currently associated         *  document.         * @see DocumentListener#removeUpdate         */        public final void removeUpdate(DocumentEvent e) {            Rectangle alloc = (painted) ? getVisibleEditorRect() : null;            rootView.removeUpdate(e, alloc, rootView.getViewFactory());	}        /**         * The change notification.  Gets sent to the root of the view structure         * that represents the portion of the model being represented by the         * editor.  The factory is added as an argument to the update so that         * the views can update themselves in a dynamic (not hardcoded) way.         *         * @param e  The change notification from the currently associated         *  document.         * @see DocumentListener#changeUpdate         */        public final void changedUpdate(DocumentEvent e) {            Rectangle alloc = (painted) ? getVisibleEditorRect() : null;            rootView.changedUpdate(e, alloc, rootView.getViewFactory());        }	// --- LayoutManager2 methods --------------------------------	/**	 * Adds the specified component with the specified name to	 * the layout.	 * @param name the component name	 * @param comp the component to be added	 */	public void addLayoutComponent(String name,

⌨️ 快捷键说明

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