1 19 20 package org.netbeans.paint; 21 22 import java.awt.Toolkit ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.io.IOException ; 26 import org.openide.ErrorManager; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.NbBundle; 29 import org.openide.util.WeakListeners; 30 import org.openide.util.actions.CallableSystemAction; 31 import org.openide.windows.TopComponent; 32 33 public final class SaveCanvasAction extends CallableSystemAction implements PropertyChangeListener { 34 35 public SaveCanvasAction() { 36 TopComponent.getRegistry().addPropertyChangeListener( 37 WeakListeners.propertyChange(this, 38 TopComponent.getRegistry())); 39 40 updateEnablement(); 41 } 42 43 public void performAction() { 44 TopComponent tc = TopComponent.getRegistry().getActivated(); 45 if (tc instanceof PaintTopComponent) { 46 try { 47 ((PaintTopComponent) tc).saveAs(); 48 } catch (IOException ioe) { 49 ErrorManager.getDefault().notify(ioe); 50 } 51 } else { 52 Toolkit.getDefaultToolkit().beep(); 57 } 58 } 59 60 public String getName() { 61 return NbBundle.getMessage(SaveCanvasAction.class, "CTL_SaveCanvasAction"); 62 } 63 64 protected String iconResource() { 65 return "org/netbeans/paint/save.PNG"; 66 } 67 68 public HelpCtx getHelpCtx() { 69 return HelpCtx.DEFAULT_HELP; 70 } 71 72 protected boolean asynchronous() { 73 return false; 74 } 75 76 public void propertyChange(PropertyChangeEvent evt) { 77 if (TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())){ 78 updateEnablement(); 79 } 80 } 81 82 private void updateEnablement() { 83 setEnabled(TopComponent.getRegistry().getActivated() instanceof PaintTopComponent); 84 } 85 86 } 87 | Popular Tags |