/** * If a key is being grabbed, this method should be called with * the appropriate key event. It executes the grab action with * the typed character as the parameter. */ protected void handleGrabAction(KeyEvent evt) { // Clear it *before* it is executed so that executeAction() // resets the repeat count ActionListener _grabAction = grabAction; grabAction = null; executeAction(_grabAction,evt.getSource(), String.valueOf(evt.getKeyChar())); }
/** * Returns the name of the specified text area action. * @param listener The action listener */ public static String getActionName(ActionListener listener) { Enumeration enu = getActions(); while(enu.hasMoreElements()) { String name = (String)enu.nextElement(); ActionListener _listener = getAction(name); if(_listener == listener) return name; } return null; }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); String str = evt.getActionCommand(); int repeatCount = textArea.getInputHandler().getRepeatCount(); if(textArea.isEditable()) { StringBuffer buf = new StringBuffer(); for(int i = 0; i < repeatCount; i++) buf.append(str); textArea.overwriteSetSelectedText(buf.toString()); } else { textArea.getToolkit().beep(); } } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); textArea.getInputHandler().setRepeatEnabled(true); String actionCommand = evt.getActionCommand(); if(actionCommand != null) { textArea.getInputHandler().setRepeatCount( Integer.parseInt(actionCommand)); } } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); doIt(textArea); } protected abstract void doIt(JEditTextArea ta);
inputHandler.keyTyped(evt); break; case KeyEvent.KEY_PRESSED: inputHandler.keyPressed(evt); break; case KeyEvent.KEY_RELEASED: inputHandler.keyReleased(evt); break;
/** * Places the selected text into the clipboard. */ public void copy() { if(selectionStart != selectionEnd) { Clipboard clipboard = getToolkit().getSystemClipboard(); String selection = getSelectedText(); int repeatCount = inputHandler.getRepeatCount(); StringBuffer buf = new StringBuffer(); for(int i = 0; i < repeatCount; i++) buf.append(selection); clipboard.setContents(new StringSelection(buf.toString()),null); } }
DEFAULTS.inputHandler.addDefaultKeyBindings(); DEFAULTS.document = new SyntaxDocument(); DEFAULTS.editable = true;
public static final ActionListener REMOVE_TAB=new TAction() { protected void doIt(JEditTextArea textArea) { if(!textArea.isEditable()) { textArea.getToolkit().beep(); return; } int[] start=new int[]{textArea.getSelectionStart()}, end=new int[]{textArea.getSelectionEnd()}; textArea.setText(decreaseIndentation(textArea.getText(),start,end)); textArea.setSelectionStart(start[0]); textArea.setSelectionEnd(end[0]); }};
public static final ActionListener INSERT_TAB=new TAction() { protected void doIt(JEditTextArea textArea) { if(!textArea.isEditable()) { textArea.getToolkit().beep(); return; } int[] start=new int[]{textArea.getSelectionStart()}, end=new int[]{textArea.getSelectionEnd()}; if (start[0]!=end[0]) { textArea.setText(increaseIndentation(textArea.getText(),start,end)); textArea.setSelectionStart(start[0]); textArea.setSelectionEnd(end[0]); } else textArea.overwriteSetSelectedText("\t"); }}; public static final ActionListener REMOVE_TAB=new TAction() { protected void doIt(JEditTextArea textArea) {
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); textArea.setSelectionRectangular( !textArea.isSelectionRectangular()); } }
.replace('\r','\n'); int repeatCount = inputHandler.getRepeatCount(); StringBuffer buf = new StringBuffer(); for(int i = 0; i < repeatCount; i++)
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); textArea.setOverwriteEnabled( !textArea.isOverwriteEnabled()); } }
int _repeatCount = getRepeatCount();
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); if(!textArea.isEditable()) { textArea.getToolkit().beep(); return; } textArea.setSelectedText("\n"); } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); if(select) textArea.select(textArea.getMarkPosition(),0); else textArea.setCaretPosition(0); } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); int caret = textArea.getCaretPosition(); if(caret == 0) { textArea.getToolkit().beep(); return; } if(select) textArea.select(textArea.getMarkPosition(), caret - 1); else textArea.setCaretPosition(caret - 1); } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); if(select) textArea.select(textArea.getMarkPosition(), textArea.getDocumentLength()); else textArea.setCaretPosition(textArea .getDocumentLength()); } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); int caret = textArea.getCaretPosition(); if(caret == textArea.getDocumentLength()) { textArea.getToolkit().beep(); return; } if(select) textArea.select(textArea.getMarkPosition(), caret + 1); else textArea.setCaretPosition(caret + 1); } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); int firstLine = textArea.getFirstLine(); int visibleLines = textArea.getVisibleLines(); int line = textArea.getCaretLine(); if(firstLine < visibleLines) firstLine = visibleLines; textArea.setFirstLine(firstLine - visibleLines); int caret = textArea.getLineStartOffset( Math.max(0,line - visibleLines)); if(select) textArea.select(textArea.getMarkPosition(),caret); else textArea.setCaretPosition(caret); } }