/** * Sets the short description for this action. * * @param shortDesc The short description for this action. */ public void setShortDescription(String shortDesc) { putValue(SHORT_DESCRIPTION, shortDesc); }
public final void actionPerformed(ActionEvent e) { JTextComponent textComponent = getTextComponent(e); if (textComponent instanceof RTextArea) { RTextArea textArea = (RTextArea)textComponent; if (RTextArea.isRecordingMacro() && isRecordable()) { int mod = e.getModifiers(); String macroID = getMacroID(); actionPerformedImpl(e, textArea);
/** * Returns the icon for this action. * * @return The icon. */ public Icon getIcon() { return (Icon)getValue(SMALL_ICON); }
/** * Constructor. * * @param text The text (name) associated with the action. * @param icon The icon associated with the action. * @param desc The description of the action. * @param mnemonic The mnemonic for the action. * @param accelerator The accelerator key for the action. */ public RecordableTextAction(String text, Icon icon, String desc, Integer mnemonic, KeyStroke accelerator) { super(text); putValue(SMALL_ICON, icon); putValue(SHORT_DESCRIPTION, desc); putValue(ACCELERATOR_KEY, accelerator); putValue(MNEMONIC_KEY, mnemonic); setRecordable(true); }
/** * Notifies all listeners that a caret change has occurred. * * @param e The caret event. */ @Override protected void fireCaretUpdate(CaretEvent e) { // Decide whether we need to repaint the current line background. possiblyUpdateCurrentLineHighlightLocation(); // Now, if there is a highlighted region of text, allow them to cut // and copy. if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) { cutAction.setEnabled(true); copyAction.setEnabled(true); } // Otherwise, if there is no highlighted region, don't let them cut // or copy. The condition here should speed things up, because this // way, we will only enable the actions the first time the selection // becomes nothing. else if (cutAction.isEnabled()) { cutAction.setEnabled(false); copyAction.setEnabled(false); } super.fireCaretUpdate(e); }
cutAction.setProperties(msg, "Action.Cut"); cutAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, mod)); copyAction = new RTextAreaEditorKit.CopyAction(); copyAction.setProperties(msg, "Action.Copy"); copyAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, mod)); pasteAction = new RTextAreaEditorKit.PasteAction(); pasteAction.setProperties(msg, "Action.Paste"); pasteAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, mod)); deleteAction = new RTextAreaEditorKit.DeleteNextCharAction(); deleteAction.setProperties(msg, "Action.Delete"); deleteAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); undoAction = new RTextAreaEditorKit.UndoAction(); undoAction.setProperties(msg, "Action.Undo"); undoAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, mod)); redoAction = new RTextAreaEditorKit.RedoAction(); redoAction.setProperties(msg, "Action.Redo"); redoAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, mod)); selectAllAction = new RTextAreaEditorKit.SelectAllAction(); selectAllAction.setProperties(msg, "Action.SelectAll"); selectAllAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, mod));
/** * Configures the popup menu for this text area. This method is called * right before it is displayed, so a hosting application can do any * custom configuration (configuring actions, adding/removing items, etc.). * <p> * * The default implementation does nothing.<p> * * If you set the popup menu via {@link #setPopupMenu(JPopupMenu)}, you * will want to override this method, especially if you removed any of the * menu items in the default popup menu. * * @param popupMenu The popup menu. This will never be <code>null</code>. * @see #createPopupMenu() * @see #setPopupMenu(JPopupMenu) */ protected void configurePopupMenu(JPopupMenu popupMenu) { boolean canType = isEditable() && isEnabled(); // Since the user can customize the popup menu, these actions may not // have been created. if (undoMenuItem!=null) { undoMenuItem.setEnabled(undoAction.isEnabled() && canType); redoMenuItem.setEnabled(redoAction.isEnabled() && canType); cutMenuItem.setEnabled(cutAction.isEnabled() && canType); pasteMenuItem.setEnabled(pasteAction.isEnabled() && canType); deleteMenuItem.setEnabled(deleteAction.isEnabled() && canType); } }
@Override public void focusGained(FocusEvent e) { Caret c = getCaret(); boolean enabled = c.getDot()!=c.getMark(); cutAction.setEnabled(enabled); copyAction.setEnabled(enabled); undoManager.updateActions(); // To reflect this text area. }
/** * "Plays back" the last recorded macro in this text area. */ public synchronized void playbackLastMacro() { if (currentMacro!=null) { List<MacroRecord> macroRecords = currentMacro.getMacroRecords(); if (!macroRecords.isEmpty()) { Action[] actions = getActions(); undoManager.beginInternalAtomicEdit(); try { for (MacroRecord record : macroRecords) { for (int i=0; i<actions.length; i++) { if ((actions[i] instanceof RecordableTextAction) && record.id.equals( ((RecordableTextAction)actions[i]).getMacroID())) { actions[i].actionPerformed( new ActionEvent(this, ActionEvent.ACTION_PERFORMED, record.actionCommand)); break; } } } } finally { undoManager.endInternalAtomicEdit(); } } } }
/** * Constructor. * * @param text The text (name) associated with the action. * @param icon The icon associated with the action. * @param desc The description of the action. * @param mnemonic The mnemonic for the action. * @param accelerator The accelerator key for the action. */ public RecordableTextAction(String text, Icon icon, String desc, Integer mnemonic, KeyStroke accelerator) { super(text); putValue(SMALL_ICON, icon); putValue(SHORT_DESCRIPTION, desc); putValue(ACCELERATOR_KEY, accelerator); putValue(MNEMONIC_KEY, mnemonic); setRecordable(true); }
/** * Notifies all listeners that a caret change has occurred. * * @param e The caret event. */ protected void fireCaretUpdate(CaretEvent e) { // Decide whether we need to repaint the current line background. possiblyUpdateCurrentLineHighlightLocation(); // Now, if there is a highlighted region of text, allow them to cut // and copy. if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) { cutAction.setEnabled(true); copyAction.setEnabled(true); } // Otherwise, if there is no highlighted region, don't let them cut // or copy. The condition here should speed things up, because this // way, we will only enable the actions the first time the selection // becomes nothing. else if (cutAction.isEnabled()==true) { cutAction.setEnabled(false); copyAction.setEnabled(false); } super.fireCaretUpdate(e); }
@Override public boolean isEnabled() { JTextComponent tc = getTextComponent(null); return (tc==null || tc.isEditable()) ? super.isEnabled() : false; }
@Override public void focusGained(FocusEvent e) { Caret c = getCaret(); boolean enabled = c.getDot()!=c.getMark(); cutAction.setEnabled(enabled); copyAction.setEnabled(enabled); undoManager.updateActions(); // To reflect this text area. }
if ((actions[j] instanceof RecordableTextAction) && record.id.equals( ((RecordableTextAction)actions[j]).getMacroID())) { actions[j].actionPerformed( new ActionEvent(this,
cutAction.setProperties(msg, "Action.Cut"); cutAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, mod)); copyAction = new RTextAreaEditorKit.CopyAction(); copyAction.setProperties(msg, "Action.Copy"); copyAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, mod)); pasteAction = new RTextAreaEditorKit.PasteAction(); pasteAction.setProperties(msg, "Action.Paste"); pasteAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, mod)); deleteAction = new RTextAreaEditorKit.DeleteNextCharAction(); deleteAction.setProperties(msg, "Action.Delete"); deleteAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); undoAction = new RTextAreaEditorKit.UndoAction(); undoAction.setProperties(msg, "Action.Undo"); undoAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, mod)); redoAction = new RTextAreaEditorKit.RedoAction(); redoAction.setProperties(msg, "Action.Redo"); redoAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, mod)); selectAllAction = new RTextAreaEditorKit.SelectAllAction(); selectAllAction.setProperties(msg, "Action.SelectAll"); selectAllAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, mod));
public final void actionPerformed(ActionEvent e) { JTextComponent textComponent = getTextComponent(e); if (textComponent instanceof RTextArea) { RTextArea textArea = (RTextArea)textComponent; if (RTextArea.isRecordingMacro() && isRecordable()) { int mod = e.getModifiers(); String macroID = getMacroID(); actionPerformedImpl(e, textArea);
/** * Sets the accelerator for this action. * * @param accelerator The new accelerator. * @see #getAccelerator() */ public void setAccelerator(KeyStroke accelerator) { putValue(ACCELERATOR_KEY, accelerator); }
/** * Constructor. * * @param text The text (name) associated with the action. * @param icon The icon associated with the action. * @param desc The description of the action. * @param mnemonic The mnemonic for the action. * @param accelerator The accelerator key for the action. */ public RecordableTextAction(String text, Icon icon, String desc, Integer mnemonic, KeyStroke accelerator) { super(text); putValue(SMALL_ICON, icon); putValue(SHORT_DESCRIPTION, desc); putValue(ACCELERATOR_KEY, accelerator); putValue(MNEMONIC_KEY, mnemonic); setRecordable(true); }
/** * Returns the name of this action. * * @return The name of this action. * @see #setName(String) */ public String getName() { return (String)getValue(NAME); }
/** * Notifies all listeners that a caret change has occurred. * * @param e The caret event. */ @Override protected void fireCaretUpdate(CaretEvent e) { // Decide whether we need to repaint the current line background. possiblyUpdateCurrentLineHighlightLocation(); // Now, if there is a highlighted region of text, allow them to cut // and copy. if (e!=null && e.getDot()!=e.getMark()) {// && !cutAction.isEnabled()) { cutAction.setEnabled(true); copyAction.setEnabled(true); } // Otherwise, if there is no highlighted region, don't let them cut // or copy. The condition here should speed things up, because this // way, we will only enable the actions the first time the selection // becomes nothing. else if (cutAction.isEnabled()) { cutAction.setEnabled(false); copyAction.setEnabled(false); } super.fireCaretUpdate(e); }