1 19 20 21 package org.netbeans.core.windows.actions; 22 23 24 import org.openide.util.NbBundle; 25 import org.openide.util.WeakListeners; 26 import org.openide.windows.TopComponent; 27 28 import javax.swing.*; 29 import java.beans.PropertyChangeEvent ; 30 import java.beans.PropertyChangeListener ; 31 32 33 36 public class CloseWindowAction extends AbstractAction 37 implements PropertyChangeListener { 38 39 public CloseWindowAction() { 40 putValue(NAME, NbBundle.getMessage(CloseWindowAction.class, "CTL_CloseWindowAction")); 41 TopComponent.getRegistry().addPropertyChangeListener( 42 WeakListeners.propertyChange(this, TopComponent.getRegistry())); 43 updateEnabled(); 44 } 45 46 private TopComponent tc; 47 public CloseWindowAction(TopComponent topcomp) { 49 tc = topcomp; 50 putValue(Action.NAME, NbBundle.getMessage(ActionUtils.class, 53 "LBL_CloseWindowAction")); setEnabled(true); 55 } 56 57 58 59 public void actionPerformed(java.awt.event.ActionEvent ev) { 60 TopComponent topC = tc; 61 if (topC == null) { 62 topC = TopComponent.getRegistry().getActivated(); 64 } 65 if(topC != null) { 66 ActionUtils.closeWindow(topC); 67 } 68 } 69 70 public void propertyChange(PropertyChangeEvent evt) { 71 if(TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) { 72 updateEnabled(); 73 } 74 } 75 76 private void updateEnabled() { 77 setEnabled(TopComponent.getRegistry().getActivated() != null); 78 } 79 80 83 public void putValue(String key, Object newValue) { 84 if (Action.ACCELERATOR_KEY.equals(key)) { 85 ActionUtils.putSharedAccelerator("CloseWindow", newValue); 86 } else { 87 super.putValue(key, newValue); 88 } 89 } 90 91 94 public Object getValue(String key) { 95 if (Action.ACCELERATOR_KEY.equals(key)) { 96 return ActionUtils.getSharedAccelerator("CloseWindow"); 97 } else { 98 return super.getValue(key); 99 } 100 } 101 102 } 103 104 | Popular Tags |