1 19 20 package org.netbeans.core.windows.actions; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.Action ; 25 import org.netbeans.core.windows.ModeImpl; 26 import org.netbeans.core.windows.WindowManagerImpl; 27 import org.openide.util.HelpCtx; 28 import org.openide.util.NbBundle; 29 import org.openide.util.actions.CallableSystemAction; 30 import org.openide.windows.TopComponent; 31 import org.openide.windows.WindowManager; 32 33 39 public final class UndockWindowAction extends AbstractAction { 40 41 private final TopComponent tc; 42 43 47 public UndockWindowAction () { 48 this.tc = null; 49 } 50 51 55 public UndockWindowAction (TopComponent tc) { 56 this.tc = tc; 57 } 58 59 public void actionPerformed (ActionEvent e) { 60 WindowManagerImpl wmi = WindowManagerImpl.getInstance(); 62 TopComponent contextTC = getTC2WorkWith(); 63 boolean isDocked = wmi.isDocked(contextTC); 64 int kind = ((ModeImpl)wmi.findMode(contextTC)).getKind(); 65 66 if (isDocked) { 67 wmi.userUndockedTopComponent(contextTC, kind); 68 } else { 69 wmi.userDockedTopComponent(contextTC, kind); 70 } 71 } 72 73 75 public void putValue(String key, Object newValue) { 76 if (Action.ACCELERATOR_KEY.equals(key)) { 77 ActionUtils.putSharedAccelerator("UndockWindowAction", newValue); } else { 79 super.putValue(key, newValue); 80 } 81 } 82 83 85 public Object getValue(String key) { 86 if (Action.ACCELERATOR_KEY.equals(key)) { 87 return ActionUtils.getSharedAccelerator("UndockWindowAction"); } else { 89 return super.getValue(key); 90 } 91 } 92 93 public boolean isEnabled() { 94 updateName(); 95 return getTC2WorkWith() != null; 96 } 97 98 private void updateName() { 99 TopComponent contextTC = getTC2WorkWith(); 100 boolean isDocked = contextTC != null ? WindowManagerImpl.getInstance().isDocked(contextTC) : true; 101 putValue(Action.NAME, 102 NbBundle.getMessage(UndockWindowAction.class, 103 isDocked ? "CTL_UndockWindowAction" : "CTL_UndockWindowAction_Dock")); 104 } 105 106 private TopComponent getTC2WorkWith () { 107 if (tc != null) { 108 return tc; 109 } 110 return WindowManager.getDefault().getRegistry().getActivated(); 111 } 112 113 } 114 | Popular Tags |