📄 ekit.java
字号:
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 scrollOffset; int selectedIndex; Rectangle visible = new Rectangle(); Rectangle r; target.computeVisibleRect(visible); scrollOffset = visible.y; visible.y -= visible.height; if(visible.y < 0) visible.y = 0; scrollOffset = scrollOffset - visible.y; target.scrollRectToVisible(visible); selectedIndex = target.getCaretPosition(); try { if(selectedIndex != -1) { r = target.modelToView(selectedIndex); if (scrollOffset == 0 && visible.y == 0 && r.y > 0) { r.y = 0; } else { r.y -= scrollOffset; } selectedIndex = target.viewToModel(new Point(r.x,r.y)); Document doc = target.getDocument(); if ((selectedIndex != 0) && (selectedIndex > (doc.getLength()-1))) { selectedIndex = doc.getLength()-1; } if(selectedIndex < 0) { selectedIndex = 0; } if (select) target.moveCaretPosition(selectedIndex); else target.setCaretPosition(selectedIndex); } } catch(BadLocationException bl) { target.getToolkit().beep(); } } } private boolean select; } /** * Pages down vertically. The select version of this action extends * the selection, instead of simply moving the caret. * * @see DefaultEditorKit#pageDownAction * @see DefaultEditorKit#selectPageDownAction * @see DefaultEditorKit#getActions */ static class PageDownAction extends TextAction { /* Create this object with the appropriate identifier. */ PageDownAction(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 scrollOffset; int selectedIndex; Rectangle visible = new Rectangle(); Rectangle r; target.computeVisibleRect(visible); scrollOffset = visible.y; visible.y += visible.height; int maxHeight = target.getHeight(); if((visible.y+visible.height) > maxHeight) visible.y = (maxHeight - visible.height); scrollOffset = visible.y - scrollOffset; target.scrollRectToVisible(visible); selectedIndex = target.getCaretPosition(); try { if(selectedIndex != -1) { r = target.modelToView(selectedIndex); r.y += scrollOffset; if (scrollOffset == 0 && (visible.y + visible.height == maxHeight)) { r.y = visible.y + visible.height; } selectedIndex = target.viewToModel(new Point(r.x,r.y)); Document doc = target.getDocument(); if ((selectedIndex != 0) && (selectedIndex > (doc.getLength()-1))) { selectedIndex = doc.getLength()-1; } if (selectedIndex < 0) { selectedIndex = 0; } if (select) target.moveCaretPosition(selectedIndex); else target.setCaretPosition(selectedIndex); } } catch(BadLocationException bl) { target.getToolkit().beep(); } } } private boolean select; } /** * Pages one view to the left or right. */ static class PageAction extends TextAction { /** Create this object with the appropriate identifier. */ public PageAction(String nm, boolean left, boolean select) { super(nm); this.select = select; this.left = left; } /** The operation to perform when this action is triggered. */ public void actionPerformed(ActionEvent e) { JTextComponent target = getTextComponent(e); if (target != null) { int selectedIndex; Rectangle visible = new Rectangle(); target.computeVisibleRect(visible); if (left) { visible.x = Math.max(0, visible.x - visible.width); } else { visible.x += visible.width; } target.scrollRectToVisible(visible); selectedIndex = target.getCaretPosition(); if(selectedIndex != -1) { if (left) { selectedIndex = target.viewToModel (new Point(visible.x, visible.y)); } else { selectedIndex = target.viewToModel (new Point(visible.x + visible.width - 1, visible.y + visible.height - 1)); } Document doc = target.getDocument(); if ((selectedIndex != 0) && (selectedIndex > (doc.getLength()-1))) { selectedIndex = doc.getLength()-1; } else if(selectedIndex < 0) { selectedIndex = 0; } if (select) target.moveCaretPosition(selectedIndex); else target.setCaretPosition(selectedIndex); } } } private boolean select; private boolean left; } static class DumpModelAction extends TextAction { DumpModelAction() { super("dump-model"); } public void actionPerformed(ActionEvent e) { JTextComponent target = getTextComponent(e); if (target != null) { Document d = target.getDocument(); if (d instanceof AbstractDocument) { ((AbstractDocument) d).dump(System.err); } } } } /* * Action to move the selection by way of the * getNextVisualPositionFrom method. Constructor indicates direction * to use. */ public static class NextVisualPositionAction extends TextAction { private int b; protected boolean select; public void actionPerformed(ActionEvent e) { JTextComponent editorpane = getTextComponent(e); if(editorpane != null) { Caret caret = editorpane.getCaret(); int i = caret.getDot(); javax.swing.text.Position.Bias abias[] = new javax.swing.text.Position.Bias[1]; try { Point point = null; switch(b) { case 1: // '\001' 上 case 5: // '\005' 下 point = caret.getMagicCaretPosition(); if(point == null) { Rectangle rectangle = editorpane.modelToView(i); point = new Point(rectangle.x, rectangle.y); } if(b == 1) { i = Utilities.getPositionAbove(editorpane, i, point.x); if(i < 0) i = 0; } else { i = Utilities.getPositionBelow(editorpane, i, point.x); } break; case 3: // '\003' 右 case 7: // '\007' 左 i = editorpane.getUI().getNextVisualPositionFrom(editorpane, i, javax.swing.text.Position.Bias.Forward, b, abias); break; } if(select) caret.moveDot(i); else caret.setDot(i); if(b == 1 || b == 5) caret.setMagicCaretPosition(point); } catch(BadLocationException badlocationexception) { } } } public NextVisualPositionAction(String s, boolean flag, int i) { super(s); select = flag; b = i; } } /* * Position the caret to the beginning of the word. * @see DefaultEditorKit#beginWordAction * @see DefaultEditorKit#selectBeginWordAction * @see DefaultEditorKit#getActions */ static class BeginWordAction 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. */ BeginWordAction(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.getWordStart(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 word. * @see DefaultEditorKit#endWordAction * @see DefaultEditorKit#selectEndWordAction * @see DefaultEditorKit#getActions */ static class EndWordAction 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. */ EndWordAction(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 endOffs = Utilities.getWordEnd(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 previousning of the word. * @see DefaultEditorKit#previousWordAction * @see DefaultEditorKit#selectPreviousWordAction * @see DefaultEditorKit#getActions */ static class PreviousWordAction 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. */ PreviousWordAction(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(); offs = Utilities.getPreviousWord(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 next of the word. * @see DefaultEditorKit#nextWordAction * @see DefaultEditorKit#selectNextWordAction * @see DefaultEditorKit#getActions */ static class NextWordAction 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. */ NextWordAction(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) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -