/** * This method is made final here as there's an important processing that * must be done before the real action functionality is performed. It can * include the following: 1. Updating of the target component depending on * the update mask given in action constructor. 2. Possible macro recoding * when the macro recording is turned on. The real action functionality * should be done in the method actionPerformed(ActionEvent evt, * JTextComponent target) which must be redefined by the target action. */ public final void actionPerformed(ActionEvent evt) { JTextComponent target = getTextComponent(evt); if (recording && 0 == (updateMask & NO_RECORDING)) { recordAction(target, evt); } updateComponent(target); actionPerformed(evt, target); }
private String getItemText(JTextComponent target, String actionName, Action a) { String itemText; if (a instanceof BaseAction) { itemText = ((BaseAction)a).getPopupMenuText(target); } else { itemText = actionName; } return itemText; }
public Object getValue(String key){ String actionName = (String)super.getValue(Action.NAME); Object obj = super.getValue(key); if (obj==null){ if (SHORT_DESCRIPTION.equals(key)){ String localizerKey = LOCALE_DESC_PREFIX + actionName; obj = findValue(localizerKey); if (obj==null){ obj = findValue(actionName); if (obj==null) obj = actionName; } }else if (POPUP_MENU_TEXT.equals(key)){ String localizerKey = LOCALE_POPUP_PREFIX + actionName; obj = findValue(localizerKey); if (obj == null){ obj = getValue(SHORT_DESCRIPTION); } } if (obj!=null){ putValue(key, obj); } } return obj; }
private void recordAction( JTextComponent target, ActionEvent evt ) { if( this == target.getKeymap().getDefaultAction() ) { // defaultKeyTyped textBuffer.append( getFilteredActionCommand(evt.getActionCommand()) ); } else { // regular action if( textBuffer.length() > 0 ) { if( macroBuffer.length() > 0 ) macroBuffer.append( ' ' ); macroBuffer.append( encodeText( textBuffer.toString() ) ); textBuffer.setLength( 0 ); } if( macroBuffer.length() > 0 ) macroBuffer.append( ' ' ); String name = (String)getValue( Action.NAME ); macroBuffer.append( encodeActionName( name ) ); } }
public void run() { actionPerformed(evt, target); } });
private void performDefaultAction(ActionEvent evt, JTextComponent target) { BaseAction action = (BaseAction) CslActions.createToggleBlockCommentAction(); if (getValue(FORCE_COMMENT) != null) { action.putValue(FORCE_COMMENT, getValue(FORCE_COMMENT)); } if (getValue(FORCE_UNCOMMENT) != null) { action.putValue(FORCE_UNCOMMENT, getValue(FORCE_UNCOMMENT)); } action.actionPerformed(evt, target); }
ActionEvent newEvt = new ActionEvent( target, 0, new String( new char[] { ch } ) ); if( a instanceof BaseAction ) { ((BaseAction)a).updateComponent(target); ((BaseAction)a).actionPerformed( newEvt, target ); } else { a.actionPerformed( newEvt ); ActionEvent fakeEvt = new ActionEvent( target, 0, "" ); if( a instanceof BaseAction ) { ((BaseAction)a).updateComponent(target); ((BaseAction)a).actionPerformed( fakeEvt, target ); } else { a.actionPerformed( fakeEvt );
item = ((BaseAction)a).getPopupMenuItem(target);
public BaseAction(String name, int updateMask) { super(name); this.updateMask = updateMask; // Initialize short description String key = LOCALE_DESC_PREFIX + name; String desc = LocaleSupport.getString(key); if (desc == null) { desc = LocaleSupport.getString(name, name); } putValue(SHORT_DESCRIPTION, desc); // Initialize menu description key = LOCALE_POPUP_PREFIX + name; String popupMenuText = LocaleSupport.getString(key, desc); putValue(POPUP_MENU_TEXT, popupMenuText); }
String stopRecording( JTextComponent target ) { if( !recording ) return null; if( textBuffer.length() > 0 ) { if( macroBuffer.length() > 0 ) macroBuffer.append( ' ' ); macroBuffer.append( encodeText( textBuffer.toString() ) ); } String retVal = macroBuffer.toString(); recording = false; Utilities.setStatusText( target, "" ); // NOI18N return retVal; }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { for (int i = 0; i < actions.length; i++) { Action a = actions[i]; if (a instanceof BaseAction) { ((BaseAction)a).actionPerformed(evt, target); } else { a.actionPerformed(evt); } } } } }
private void recordAction(JTextComponent target, ActionEvent evt) { if (this == target.getKeymap().getDefaultAction()) { // defaultKeyTyped textBuffer.append(getFilteredActionCommand(evt.getActionCommand())); } else { // regular action if (textBuffer.length() > 0) { if (macroBuffer.length() > 0) macroBuffer.append(' '); macroBuffer.append(encodeText(textBuffer.toString())); textBuffer.setLength(0); } if (macroBuffer.length() > 0) macroBuffer.append(' '); String name = (String) getValue(Action.NAME); macroBuffer.append(encodeActionName(name)); } }
ActionEvent newEvt = new ActionEvent(target, 0, new String(new char[] { ch })); if (a instanceof BaseAction) { ((BaseAction) a).updateComponent(target); ((BaseAction) a).actionPerformed(newEvt, target); ActionEvent fakeEvt = new ActionEvent(target, 0, ""); if (a instanceof BaseAction) { ((BaseAction) a).updateComponent(target); ((BaseAction) a).actionPerformed(fakeEvt, target);
JMenuItem item = null; if (a instanceof BaseAction) { item = ((BaseAction) a).getPopupMenuItem(target);
String stopRecording(JTextComponent target) { if (!recording) return null; if (textBuffer.length() > 0) { if (macroBuffer.length() > 0) macroBuffer.append(' '); macroBuffer.append(encodeText(textBuffer.toString())); } String retVal = macroBuffer.toString(); recording = false; Utilities.setStatusText(target, ""); // NOI18N return retVal; }
/** This method is made final here as there's an important * processing that must be done before the real action * functionality is performed. It can include the following: * 1. Updating of the target component depending on the update * mask given in action constructor. * 2. Possible macro recoding when the macro recording * is turned on. * The real action functionality should be done in * the method actionPerformed(ActionEvent evt, JTextComponent target) * which must be redefined by the target action. */ public final void actionPerformed(final ActionEvent evt) { final JTextComponent target = getTextComponent(evt); if( recording && 0 == (updateMask & NO_RECORDING) ) { recordAction( target, evt ); } updateComponent(target); if (asynchonous()) { RequestProcessor.getDefault().post(new Runnable () { public void run() { actionPerformed(evt, target); } }); } else { actionPerformed(evt, target); } }
public static void performAction(Action a, ActionEvent evt, JTextComponent target) { if (a instanceof BaseAction) { ((BaseAction) a).actionPerformed(evt, target); } else { a.actionPerformed(evt); } }
protected String getItemText(JTextComponent target, String actionName, Action a) { String itemText; if (a instanceof BaseAction) { itemText = ((BaseAction) a).getPopupMenuText(target); } else { itemText = actionName; } return itemText; }