1 19 20 package org.netbeans.modules.loadgenerator.actions; 21 22 import java.awt.event.ActionEvent ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import javax.swing.AbstractAction ; 26 import javax.swing.ImageIcon ; 27 import org.netbeans.modules.loadgenerator.api.EngineManager; 28 import org.netbeans.modules.loadgenerator.spi.Engine; 29 import org.openide.util.Lookup; 30 import org.openide.util.Utilities; 31 import org.openide.util.WeakListeners; 32 33 37 public class LoadAction extends AbstractAction { 38 private static final String ICON = "org/netbeans/modules/openfile/openFile.png"; private static final String PROP_ENABLED = "enabled"; 41 private Engine provider = null; 42 43 private PropertyChangeListener listener = new PropertyChangeListener () { 44 public void propertyChange(PropertyChangeEvent evt) { 45 firePropertyChange(PROP_ENABLED, evt.getOldValue(), evt.getNewValue()); 48 } 49 }; 50 51 52 public LoadAction(final Engine provider) { 53 super("Start ...", new ImageIcon (Utilities.loadImage(ICON))); 54 55 this.provider = provider; 56 this.provider.addPropertyChangeListener(Engine.STATE, WeakListeners.propertyChange(listener, provider)); 57 } 58 59 public void actionPerformed(ActionEvent e) { 60 EngineManager manager = Lookup.getDefault().lookup(EngineManager.class); 61 manager.startNewProcess(provider); 62 } 63 64 public boolean isEnabled() { 65 return provider.isReady(); 66 } 67 } 68 | Popular Tags |