1 19 20 package org.openide.windows; 21 22 import java.awt.EventQueue ; 23 import java.awt.Frame ; 24 import java.awt.Image ; 25 import java.awt.Window ; 26 import java.beans.PropertyChangeListener ; 27 import java.io.Serializable ; 28 import java.util.Set ; 29 import java.util.logging.Level ; 30 import java.util.logging.Logger ; 31 import javax.swing.SwingUtilities ; 32 import org.openide.nodes.Node; 33 import org.openide.util.Lookup; 34 35 44 public abstract class WindowManager extends Object implements Serializable { 45 47 @Deprecated 48 public static final String PROP_WORKSPACES = "workspaces"; 50 53 @Deprecated 54 public static final String PROP_CURRENT_WORKSPACE = "currentWorkspace"; 56 58 public static final String PROP_MODES = "modes"; 60 61 private static WindowManager dummyInstance; 62 static final long serialVersionUID = -4133918059009277602L; 63 64 65 private TopComponent activeComponent; 66 67 68 private TopComponent.Registry registry; 69 70 76 public static final WindowManager getDefault() { 77 WindowManager wmInstance = Lookup.getDefault().lookup(WindowManager.class); 78 79 return (wmInstance != null) ? wmInstance : getDummyInstance(); 80 } 81 82 private static synchronized WindowManager getDummyInstance() { 83 if (dummyInstance == null) { 84 dummyInstance = new DummyWindowManager(); 85 } 86 87 return dummyInstance; 88 } 89 90 94 public abstract Mode findMode(String name); 95 96 100 public abstract Mode findMode(TopComponent tc); 101 102 104 public abstract Set <? extends Mode> getModes(); 105 106 115 public abstract Frame getMainWindow(); 116 117 120 public abstract void updateUI(); 121 122 126 protected abstract WindowManager.Component createTopComponentManager(TopComponent c); 127 128 131 protected TopComponent.Registry componentRegistry() { 132 return Lookup.getDefault().lookup(TopComponent.Registry.class); 133 } 134 135 138 public synchronized TopComponent.Registry getRegistry() { 139 if (registry != null) { 140 return registry; 141 } 142 143 registry = componentRegistry(); 144 145 return registry; 146 } 147 148 152 @Deprecated 153 public final Workspace createWorkspace(String name) { 154 return createWorkspace(name, name); 155 } 156 157 164 @Deprecated 165 public abstract Workspace createWorkspace(String name, String displayName); 166 167 171 @Deprecated 172 public abstract Workspace findWorkspace(String name); 173 174 178 @Deprecated 179 public abstract Workspace[] getWorkspaces(); 180 181 186 @Deprecated 187 public abstract void setWorkspaces(Workspace[] workspaces); 188 189 194 @Deprecated 195 public abstract Workspace getCurrentWorkspace(); 196 197 200 public abstract TopComponentGroup findTopComponentGroup(String name); 201 202 207 211 public abstract void addPropertyChangeListener(PropertyChangeListener l); 212 213 217 public abstract void removePropertyChangeListener(PropertyChangeListener l); 218 219 225 @Deprecated 226 protected static final Component findComponentManager(TopComponent tc) { 227 return null; 228 } 229 230 236 protected void activateComponent(TopComponent tc) { 237 if (activeComponent == tc) { 239 return; 240 } 241 242 if (activeComponent != null) { 244 try { 245 activeComponent.componentDeactivated(); 246 } catch (RuntimeException re) { 247 IllegalStateException ise = new IllegalStateException ( 248 "[Winsys] TopComponent " + activeComponent +" throws runtime exception from its componentDeactivated() method. Repair it!" 250 ); ise.initCause(re); 252 Logger.getLogger(WindowManager.class.getName()).log(Level.WARNING, null, ise); 253 } 254 } 255 256 activeComponent = tc; 257 258 if (activeComponent != null) { 259 try { 260 activeComponent.componentActivated(); 261 } catch (RuntimeException re) { 262 IllegalStateException ise = new IllegalStateException ( 263 "[Winsys] TopComponent " + activeComponent +" throws runtime exception from its componentActivated() method. Repair it!" 265 ); ise.initCause(re); 267 Logger.getLogger(WindowManager.class.getName()).log(Level.WARNING, null, ise); 268 } 269 } 270 } 271 272 278 protected void componentOpenNotify(TopComponent tc) { 279 try { 280 tc.componentOpened(); 281 } catch (RuntimeException re) { 282 IllegalStateException ise = new IllegalStateException ( 283 "[Winsys] TopComponent " + tc +" throws runtime exception from its componentOpened() method. Repair it!" 285 ); ise.initCause(re); 287 Logger.getLogger(WindowManager.class.getName()).log(Level.WARNING, null, ise); 288 } 289 } 290 291 297 protected void componentCloseNotify(TopComponent tc) { 298 try { 299 tc.componentClosed(); 300 } catch (RuntimeException re) { 301 IllegalStateException ise = new IllegalStateException ( 302 "[Winsys] TopComponent " + tc +" throws runtime exception from its componentClosed() method. Repair it!" 304 ); ise.initCause(re); 306 Logger.getLogger(WindowManager.class.getName()).log(Level.WARNING, null, ise); 307 } 308 309 if (tc == activeComponent) { 310 activateComponent(null); 311 } 312 } 313 314 318 protected void componentShowing(TopComponent tc) { 319 try { 320 tc.componentShowing(); 321 } catch (RuntimeException re) { 322 IllegalStateException ise = new IllegalStateException ( 323 "[Winsys] TopComponent " + tc +" throws runtime exception from its componentShowing() method. Repair it!" 325 ); ise.initCause(re); 327 Logger.getLogger(WindowManager.class.getName()).log(Level.WARNING, null, ise); 328 } 329 } 330 331 335 protected void componentHidden(TopComponent tc) { 336 try { 337 tc.componentHidden(); 338 } catch (RuntimeException re) { 339 IllegalStateException ise = new IllegalStateException ( 340 "[Winsys] TopComponent " + tc +" throws runtime exception from its componentHidden() method. Repair it!" 342 ); ise.initCause(re); 344 Logger.getLogger(WindowManager.class.getName()).log(Level.WARNING, null, ise); 345 } 346 } 347 348 351 protected abstract void topComponentOpen(TopComponent tc); 352 353 356 protected abstract void topComponentClose(TopComponent tc); 357 358 361 protected abstract void topComponentRequestActive(TopComponent tc); 362 363 366 protected abstract void topComponentRequestVisible(TopComponent tc); 367 368 372 protected abstract void topComponentDisplayNameChanged(TopComponent tc, String displayName); 373 374 378 protected abstract void topComponentHtmlDisplayNameChanged(TopComponent tc, String htmlDisplayName); 379 380 384 protected abstract void topComponentToolTipChanged(TopComponent tc, String toolTip); 385 386 390 protected abstract void topComponentIconChanged(TopComponent tc, Image icon); 391 392 396 protected abstract void topComponentActivatedNodesChanged(TopComponent tc, Node[] activatedNodes); 397 398 401 protected abstract boolean topComponentIsOpened(TopComponent tc); 402 403 407 protected abstract javax.swing.Action [] topComponentDefaultActions(TopComponent tc); 408 409 414 protected abstract String topComponentID(TopComponent tc, String preferredID); 415 416 423 protected void topComponentRequestAttention(TopComponent tc) { 424 } 425 426 432 protected void topComponentToFront(TopComponent tc) { 433 Window parentWindow = SwingUtilities.getWindowAncestor(tc); 434 435 if (null != parentWindow) { 437 if (parentWindow instanceof Frame ) { 438 Frame parentFrame = (Frame ) parentWindow; 439 int state = parentFrame.getExtendedState(); 440 441 if ((state & Frame.ICONIFIED) > 0) { 442 parentFrame.setExtendedState(state & ~Frame.ICONIFIED); 443 } 444 } 445 446 parentWindow.toFront(); 447 } 448 } 449 450 457 protected void topComponentCancelRequestAttention(TopComponent tc) { 458 } 459 460 464 public String findTopComponentID(TopComponent tc) { 465 return topComponentID(tc, tc.preferredID()); 466 } 467 468 472 public abstract TopComponent findTopComponent(String tcID); 473 474 504 public void invokeWhenUIReady(Runnable run) { 505 EventQueue.invokeLater(run); 506 } 507 508 518 public boolean isEditorTopComponent( TopComponent tc ) { 519 return false; 520 } 521 522 531 public boolean isEditorMode( Mode mode ) { 532 return false; 533 } 534 535 539 @SuppressWarnings ("deprecation") 540 @Deprecated 541 protected interface Component extends java.io.Serializable { 542 546 @Deprecated 547 long serialVersionUID = 0L; 548 549 550 public void open(); 551 552 556 public void open(Workspace workspace); 557 558 562 public void close(Workspace workspace); 563 564 566 public void requestFocus(); 567 568 575 public void requestVisible(); 576 577 580 public Node[] getActivatedNodes(); 581 582 585 public void setActivatedNodes(Node[] nodes); 586 587 589 public void nameChanged(); 590 591 594 public void setIcon(final Image icon); 595 596 600 public Image getIcon(); 601 602 606 public Set <Workspace> whereOpened(); 607 } 608 } 609 | Popular Tags |