1 19 20 package org.openide.util.actions; 21 22 import java.awt.Toolkit ; 23 import java.awt.event.ActionEvent ; 24 import java.util.Set ; 25 import java.util.logging.Logger ; 26 import org.openide.util.WeakSet; 27 28 35 public abstract class CallableSystemAction extends SystemAction implements Presenter.Menu, Presenter.Popup, 36 Presenter.Toolbar { 37 38 static final long serialVersionUID = 2339794599168944156L; 39 40 43 47 private static final Set <Class > warnedAsynchronousActions = new WeakSet<Class >(); 48 private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean( 49 "org.openide.util.actions.CallableSystemAction.synchronousByDefault" 50 ); 51 52 56 public javax.swing.JMenuItem getMenuPresenter() { 57 return org.netbeans.modules.openide.util.AWTBridge.getDefault().createMenuPresenter(this); 58 } 59 60 64 public javax.swing.JMenuItem getPopupPresenter() { 65 return org.netbeans.modules.openide.util.AWTBridge.getDefault().createPopupPresenter(this); 66 } 67 68 72 public java.awt.Component getToolbarPresenter() { 73 return org.netbeans.modules.openide.util.AWTBridge.getDefault().createToolbarPresenter(this); 74 } 75 76 83 public abstract void performAction(); 84 85 90 public void actionPerformed(ActionEvent ev) { 91 if (isEnabled()) { 92 org.netbeans.modules.openide.util.ActionsBridge.doPerformAction( 93 this, 94 new org.netbeans.modules.openide.util.ActionsBridge.ActionRunnable(ev, this, asynchronous()) { 95 public void run() { 96 performAction(); 97 } 98 } 99 ); 100 } else { 101 Toolkit.getDefaultToolkit().beep(); 103 } 104 } 105 106 124 protected boolean asynchronous() { 125 if (warnedAsynchronousActions.add(getClass())) { 126 Logger.getAnonymousLogger().warning( 127 "Warning - " + getClass().getName() + 128 " should override CallableSystemAction.asynchronous() to return false" 129 ); 130 } 131 132 return DEFAULT_ASYNCH; 133 } 134 } 135 | Popular Tags |