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

📄 ekit.java

📁 JTREE的例子
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                try {                    int offs = target.getCaretPosition();                    offs = Utilities.getNextWord(target, offs);                    if (select) {                        target.moveCaretPosition(offs);                    } else {                        target.setCaretPosition(offs);                    }                } catch (BadLocationException bl) {                    target.getToolkit().beep();                }            }        }        private boolean select;    }    /*     * Position the caret to the beginning of the line.     * @see DefaultEditorKit#beginLineAction     * @see DefaultEditorKit#selectBeginLineAction     * @see DefaultEditorKit#getActions     */    static class BeginLineAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        BeginLineAction(String nm, boolean select) {            super(nm);            this.select = select;        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                try {                    int offs = target.getCaretPosition();                    int begOffs = Utilities.getRowStart(target, offs);                    if (select) {                        target.moveCaretPosition(begOffs);                    } else {                        target.setCaretPosition(begOffs);                    }                } catch (BadLocationException bl) {                    target.getToolkit().beep();                }            }        }        private boolean select;    }    /*     * Position the caret to the end of the line.     * @see DefaultEditorKit#endLineAction     * @see DefaultEditorKit#selectEndLineAction     * @see DefaultEditorKit#getActions     */    static class EndLineAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        EndLineAction(String nm, boolean select) {            super(nm);            this.select = select;        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {//System.out.println("endline");            JTextComponent target = getTextComponent(e);            if (target != null) {                try {                    int offs = target.getCaretPosition();                    int endOffs = Utilities.getRowEnd(target, offs);                    if (select) {                        target.moveCaretPosition(endOffs);                    } else {                        target.setCaretPosition(endOffs);                    }                } catch (BadLocationException bl) {                    target.getToolkit().beep();                }            }        }        private boolean select;    }    /*     * Position the caret to the beginning of the paragraph.     * @see DefaultEditorKit#beginParagraphAction     * @see DefaultEditorKit#selectBeginParagraphAction     * @see DefaultEditorKit#getActions     */    static class BeginParagraphAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        BeginParagraphAction(String nm, boolean select) {            super(nm);            this.select = select;        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                int offs = target.getCaretPosition();                Element elem = Utilities.getParagraphElement(target, offs);                offs = elem.getStartOffset();                if (select) {                    target.moveCaretPosition(offs);                } else {                    target.setCaretPosition(offs);                }            }        }        private boolean select;    }    /*     * Position the caret to the end of the paragraph.     * @see DefaultEditorKit#endParagraphAction     * @see DefaultEditorKit#selectEndParagraphAction     * @see DefaultEditorKit#getActions     */    static class EndParagraphAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        EndParagraphAction(String nm, boolean select) {            super(nm);            this.select = select;        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                int offs = target.getCaretPosition();                Element elem = Utilities.getParagraphElement(target, offs);                offs = Math.min(target.getDocument().getLength(),				elem.getEndOffset());                if (select) {                    target.moveCaretPosition(offs);                } else {                    target.setCaretPosition(offs);                }            }        }        private boolean select;    }    /*     * Move the caret to the begining of the document.     * @see DefaultEditorKit#beginAction     * @see DefaultEditorKit#getActions     */    static class BeginAction extends TextAction {        /* Create this object with the appropriate identifier. */        BeginAction(String nm, boolean select) {            super(nm);            this.select = select;        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                if (select) {                    target.moveCaretPosition(0);                } else {                    target.setCaretPosition(0);                }            }        }        private boolean select;    }    /*     * Move the caret to the end of the document.     * @see DefaultEditorKit#endAction     * @see DefaultEditorKit#getActions     */    static class EndAction extends TextAction {        /* Create this object with the appropriate identifier. */        EndAction(String nm, boolean select) {            super(nm);            this.select = select;        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                Document doc = target.getDocument();                int dot = doc.getLength();                if (select) {                    target.moveCaretPosition(dot);                } else {                    target.setCaretPosition(dot);                }            }        }        private boolean select;    }    /*     * Select the word around the caret     * @see DefaultEditorKit#endAction     * @see DefaultEditorKit#getActions     */    static class SelectWordAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        SelectWordAction() {            super(selectWordAction);            start = new BeginWordAction("pigdog", false);            end = new EndWordAction("pigdog", true);        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            start.actionPerformed(e);            end.actionPerformed(e);        }        private Action start;        private Action end;    }    /*     * Select the line around the caret     * @see DefaultEditorKit#endAction     * @see DefaultEditorKit#getActions     */    static class SelectLineAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        SelectLineAction() {            super(selectLineAction);            start = new BeginLineAction("pigdog", false);            end = new EndLineAction("pigdog", true);        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            start.actionPerformed(e);            end.actionPerformed(e);        }        private Action start;        private Action end;    }    /*     * Select the paragraph around the caret     * @see DefaultEditorKit#endAction     * @see DefaultEditorKit#getActions     */    static class SelectParagraphAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        SelectParagraphAction() {            super(selectParagraphAction);            start = new BeginParagraphAction("pigdog", false);            end = new EndParagraphAction("pigdog", true);        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            start.actionPerformed(e);            end.actionPerformed(e);        }        private Action start;        private Action end;    }    /*     * Select the entire document     * @see DefaultEditorKit#endAction     * @see DefaultEditorKit#getActions     */    static class SelectAllAction extends TextAction {        /**         * Create this action with the appropriate identifier.         * @param nm  the name of the action, Action.NAME.         * @param select whether to extend the selection when         *  changing the caret position.         */        SelectAllAction() {            super(selectAllAction);        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                Document doc = target.getDocument();                target.setCaretPosition(0);                target.moveCaretPosition(doc.getLength());            }        }    }    /*     * Remove the selection, if any.     * @see DefaultEditorKit#unselectAction     * @see DefaultEditorKit#getActions     */    static class UnselectAction extends TextAction {        /**         * Create this action with the appropriate identifier.         */        UnselectAction() {            super(unselectAction);        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                target.setCaretPosition(target.getCaretPosition());            }        }    }    /*     * Toggles the ComponentOrientation of the text component.     * @see DefaultEditorKit#toggleComponentOrientationAction     * @see DefaultEditorKit#getActions     */    static class ToggleComponentOrientationAction extends TextAction {        /**         * Create this action with the appropriate identifier.         */        ToggleComponentOrientationAction() {            super(toggleComponentOrientationAction);        }        /** The operation to perform when this action is triggered. */        public void actionPerformed(ActionEvent e) {            JTextComponent target = getTextComponent(e);            if (target != null) {                ComponentOrientation last = target.getComponentOrientation();                ComponentOrientation next;                if( last == ComponentOrientation.RIGHT_TO_LEFT )                    next = ComponentOrientation.LEFT_TO_RIGHT;                else                    next = ComponentOrientation.RIGHT_TO_LEFT;                target.setComponentOrientation(next);                target.repaint();            }        }    }}

⌨️ 快捷键说明

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