1 19 20 package org.netbeans.core.windows; 21 22 import java.awt.*; 23 import java.beans.*; 24 import java.net.URL ; 25 import java.util.*; 26 import java.util.logging.Level ; 27 import java.util.logging.Logger ; 28 import javax.swing.*; 29 import org.netbeans.core.windows.actions.ActionUtils; 30 import org.netbeans.core.windows.persistence.PersistenceManager; 31 import org.openide.nodes.Node; 32 import org.openide.util.*; 33 import org.openide.windows.*; 34 35 43 public final class WindowManagerImpl extends WindowManager implements Workspace { 44 47 49 public static final String PROP_ACTIVE_MODE = "activeMode"; 51 public static final String PROP_MAXIMIZED_MODE = "maximizedMode"; 53 public static final String PROP_EDITOR_AREA_STATE = "editorAreaState"; 55 56 private static final Object LOCK_INIT = new Object (); 57 58 59 private static WindowManagerImpl defaultInstance; 60 61 62 private final Central central = new Central(); 63 64 65 private final PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); 66 67 69 private final RecentViewList recentViewList = new RecentViewList(this); 70 71 72 private TopComponent persistenceShowingTC; 73 74 75 76 private Exclusive exclusive = new Exclusive(); 77 80 public WindowManagerImpl() { 81 synchronized(LOCK_INIT) { 82 if(defaultInstance != null) { 84 throw new IllegalStateException ("Instance already exists"); } 86 defaultInstance = this; 87 } 88 } 89 90 91 public static WindowManagerImpl getInstance() { 92 if (defaultInstance != null) { 93 return defaultInstance; 95 } 96 return (WindowManagerImpl)Lookup.getDefault().lookup(WindowManager.class); 97 } 98 99 public void topComponentRequestAttention(TopComponent tc) { 100 ModeImpl mode = (ModeImpl) findMode(tc); 101 102 central.topComponentRequestAttention(mode, tc); 103 } 104 105 public void topComponentCancelRequestAttention(TopComponent tc) { 106 ModeImpl mode = (ModeImpl) findMode(tc); 107 108 central.topComponentCancelRequestAttention(mode, tc); 109 } 110 111 115 119 public Frame getMainWindow() { 120 assertEventDispatchThreadWeak(); 121 122 return central.getMainWindow(); 123 } 124 125 127 public void updateUI() { 128 assertEventDispatchThreadWeak(); 129 130 central.updateUI(); 131 } 132 133 138 protected synchronized WindowManager.Component createTopComponentManager(TopComponent c) { 139 assertEventDispatchThreadWeak(); 140 141 return null; 142 } 143 144 148 public Workspace createWorkspace(String name, String displayName) { 149 assertEventDispatchThreadWeak(); 150 151 return this; 153 } 154 155 158 public Workspace findWorkspace(String name) { 159 assertEventDispatchThreadWeak(); 160 161 return this; 163 } 164 165 169 public Workspace[] getWorkspaces() { 170 assertEventDispatchThreadWeak(); 171 172 return new Workspace[] {this}; 173 } 174 175 179 public void setWorkspaces(Workspace[] workspaces) { 180 assertEventDispatchThreadWeak(); 181 } 182 183 187 public Workspace getCurrentWorkspace() { 188 assertEventDispatchThreadWeak(); 189 190 return this; 192 } 193 194 195 public TopComponentGroup findTopComponentGroup(String name) { 196 assertEventDispatchThread(); 197 198 for(Iterator it = getTopComponentGroups().iterator(); it.hasNext(); ) { 199 TopComponentGroupImpl group = (TopComponentGroupImpl)it.next(); 200 if(group.getName().equals(name)) { 201 return group; 202 } 203 } 204 205 return null; 206 } 207 208 212 public TopComponent findTopComponent(String tcID) { 213 assertEventDispatchThreadWeak(); 214 215 return getTopComponentForID(tcID); 216 } 217 218 220 public void addPropertyChangeListener(PropertyChangeListener l) { 221 changeSupport.addPropertyChangeListener(l); 222 } 223 224 226 public void removePropertyChangeListener(PropertyChangeListener l) { 227 changeSupport.removePropertyChangeListener(l); 228 } 229 230 234 251 263 264 270 274 public String getName () { 275 return "FakeWorkspace"; } 277 278 282 public String getDisplayName () { 283 return NbBundle.getMessage(WindowManagerImpl.class, "LBL_FakeWorkspace"); 284 } 285 286 288 public Set<? extends Mode> getModes () { 289 return central.getModes(); 290 } 291 292 294 public Rectangle getBounds () { 295 if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 296 return getMainWindowBoundsJoined(); 297 } else { 298 return getMainWindowBoundsSeparated(); 299 } 300 } 301 302 304 public void activate () { 305 } 306 307 313 public Mode createMode(String name, String displayName, URL icon) { 314 if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 315 return new WrapMode (createMode(name, Constants.MODE_KIND_EDITOR, Constants.MODE_STATE_JOINED, false, null)); 316 } else { 317 return createMode(name, Constants.MODE_KIND_VIEW, Constants.MODE_STATE_SEPARATED, false, 319 new SplitConstraint[] { new SplitConstraint(Constants.HORIZONTAL, 1, 0.2)}); 320 } 321 } 322 private static class WrapMode implements Mode { 323 private Mode wrap; 324 325 public WrapMode (Mode wrap) { 326 this.wrap = wrap; 327 } 328 329 public void addPropertyChangeListener (PropertyChangeListener list) { 330 wrap.addPropertyChangeListener (list); 331 } 332 333 public boolean canDock (TopComponent tc) { 334 return wrap.canDock (tc); 335 } 336 337 public boolean dockInto (TopComponent c) { 338 if (c.getClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE) == null) { 339 c.putClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE, Boolean.TRUE); 340 } 341 return wrap.dockInto (c); 342 } 343 344 public Rectangle getBounds () { 345 return wrap.getBounds (); 346 } 347 348 public String getDisplayName () { 349 return wrap.getDisplayName (); 350 } 351 352 public Image getIcon () { 353 return wrap.getIcon (); 354 } 355 356 public String getName () { 357 return wrap.getName (); 358 } 359 360 public TopComponent getSelectedTopComponent () { 361 return wrap.getSelectedTopComponent (); 362 } 363 364 public TopComponent[] getTopComponents () { 365 return wrap.getTopComponents (); 366 } 367 368 public Workspace getWorkspace () { 369 return wrap.getWorkspace (); 370 } 371 372 public void removePropertyChangeListener (PropertyChangeListener list) { 373 wrap.removePropertyChangeListener (list); 374 } 375 376 public void setBounds (Rectangle s) { 377 wrap.setBounds (s); 378 } 379 } 381 385 public Mode findMode(String name) { 386 return findModeImpl(name); 387 } 388 389 393 public Mode findMode(TopComponent tc) { 394 if(tc == null) { 395 return null; 397 } 398 399 for(Iterator it = getModes().iterator(); it.hasNext(); ) { 400 ModeImpl mode = (ModeImpl)it.next(); 401 402 if(mode.containsTopComponent(tc)) { 403 return mode; 404 } 405 } 406 407 return null; 408 } 409 410 413 public void remove () { 414 } 415 419 public void addTopComponentGroup(TopComponentGroupImpl tcGroup) { 422 central.addTopComponentGroup(tcGroup); 423 } 424 425 public void removeTopComponentGroup(TopComponentGroupImpl tcGroup) { 426 central.removeTopComponentGroup(tcGroup); 427 } 428 429 public Set<TopComponentGroupImpl> getTopComponentGroups() { 430 return central.getTopComponentGroups(); 431 } 432 435 436 438 443 public ModeImpl createMode(String name, int kind, int state, boolean permanent, SplitConstraint[] constraints) { 444 ModeImpl mode = (ModeImpl)findMode(name); 446 if(mode != null) { 447 return mode; 448 } 449 450 if(constraints == null && kind != Constants.MODE_KIND_SLIDING) { 452 if(kind == Constants.MODE_KIND_EDITOR) { 453 return getDefaultEditorMode(); 454 } else { 455 return getDefaultViewMode(); 456 } 457 } 458 459 mode = createModeImpl(name, kind, state, permanent); 460 addMode(mode, constraints); 461 return mode; 462 } 463 464 public ModeImpl createSlidingMode(String name, boolean permanent, String side, Map<String ,Integer > slideInSizes) { 465 ModeImpl mode = (ModeImpl)findMode(name); 467 if(mode != null) { 468 return mode; 469 } 470 471 mode = createModeImpl(name, Constants.MODE_KIND_SLIDING, permanent); 472 central.addSlidingMode(mode, null, side, slideInSizes); 473 return mode; 474 } 475 476 477 ModeImpl createModeImpl(String name, int kind, boolean permanent) { 478 int state = getEditorAreaState() == Constants.EDITOR_AREA_JOINED 479 ? Constants.MODE_STATE_JOINED 480 : Constants.MODE_STATE_SEPARATED; 481 return createModeImpl(name, kind, state, permanent); 482 } 483 484 485 ModeImpl createModeImpl(String name, int kind, int state, boolean permanent) { 486 if(name == null) { 487 name = ModeImpl.getUnusedModeName(); 488 } 489 ModeImpl toReturn = ModeImpl.createModeImpl(name, state, kind, permanent); 490 return toReturn; 491 } 492 493 495 ModeImpl getDefaultEditorMode() { 496 ModeImpl mode = findModeImpl("editor"); if(mode == null) { 498 Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.INFO, null, 499 new java.lang.IllegalStateException ("Creating default editor mode. It shouldn\'t happen this way")); ModeImpl newMode = createModeImpl("editor", Constants.MODE_KIND_EDITOR, true); addMode(newMode, new SplitConstraint[0]); 503 return newMode; 504 } else { 505 return mode; 506 } 507 } 508 509 511 ModeImpl getDefaultViewMode() { 512 ModeImpl mode = findModeImpl("explorer"); if(mode == null) { 514 Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.INFO, null, 515 new java.lang.IllegalStateException ("Creating default view mode. It shouldn\'t happen this way")); ModeImpl newMode = createModeImpl("explorer", Constants.MODE_KIND_VIEW, true); addMode(newMode, new SplitConstraint[] { 519 new SplitConstraint(Constants.VERTICAL, 0, 0.7D), 520 new SplitConstraint(Constants.HORIZONTAL, 0, 0.25D) 521 }); 522 return newMode; 523 } else { 524 return mode; 525 } 526 } 527 528 529 ModeImpl getDefaultSlidingMode() { 530 ModeImpl mode = findModeImpl("sliding"); if(mode == null) { 532 Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.INFO, null, 533 new java.lang.IllegalStateException ("Creating default sliding mode. It shouldn\'t happen this way")); ModeImpl newMode = createModeImpl("sliding", Constants.MODE_KIND_SLIDING, true); addMode(newMode, new SplitConstraint[] { 537 new SplitConstraint(Constants.VERTICAL, 0, 0.7D), 538 new SplitConstraint(Constants.HORIZONTAL, 0, 0.25D) 539 }); 540 return newMode; 541 } else { 542 return mode; 543 } 544 } 545 546 private ModeImpl findModeImpl(String name) { 547 if(name == null) { 548 return null; 550 } 551 552 for(Iterator it = getModes().iterator(); it.hasNext(); ) { 553 ModeImpl mode = (ModeImpl)it.next(); 554 if (name.equals(mode.getName())) { 555 return mode; 556 } 557 } 558 559 return null; 560 } 561 562 public TopComponent getSelectedTopComponent(Mode mode) { 564 return central.getModeSelectedTopComponent((ModeImpl)mode); 565 } 566 567 public Rectangle getMainWindowBoundsJoined() { 568 return central.getMainWindowBoundsJoined(); 569 } 570 571 public void setMainWindowBoundsJoined(Rectangle bounds) { 572 central.setMainWindowBoundsJoined(bounds); 573 } 574 575 public Rectangle getMainWindowBoundsSeparated() { 576 return central.getMainWindowBoundsSeparated(); 577 } 578 579 public void setMainWindowBoundsSeparated(Rectangle bounds) { 580 central.setMainWindowBoundsSeparated(bounds); 581 } 582 583 public int getMainWindowFrameStateJoined() { 584 return central.getMainWindowFrameStateJoined(); 585 } 586 587 public void setMainWindowFrameStateJoined(int frameState) { 588 central.setMainWindowFrameStateJoined(frameState); 589 } 590 591 public int getMainWindowFrameStateSeparated() { 592 return central.getMainWindowFrameStateSeparated(); 593 } 594 595 public void setMainWindowFrameStateSeparated(int frameState) { 596 central.setMainWindowFrameStateSeparated(frameState); 597 } 598 599 600 602 public ModeImpl getActiveMode () { 603 return central.getActiveMode(); 604 } 605 606 608 public void setActiveMode(ModeImpl activeMode) { 609 central.setActiveMode(activeMode); 610 } 611 612 public void setEditorAreaBounds(Rectangle editorAreaBounds) { 613 central.setEditorAreaBounds(editorAreaBounds); 614 } 615 616 public Rectangle getEditorAreaBounds() { 617 return central.getEditorAreaBounds(); 618 } 619 620 621 public void setEditorAreaConstraints(SplitConstraint[] editorAreaConstraints) { 622 central.setEditorAreaConstraints(editorAreaConstraints); 623 } 624 625 public java.awt.Component getEditorAreaComponent() { 626 return central.getEditorAreaComponent(); 627 } 628 629 630 public SplitConstraint[] getEditorAreaConstraints() { 631 return central.getEditorAreaConstraints(); 632 } 633 634 635 public void setEditorAreaState(int editorAreaState) { 636 setEditorAreaStateImpl(editorAreaState); 637 } 638 639 void setEditorAreaStateImpl(int editorAreaState) { 641 central.setEditorAreaState(editorAreaState); 642 } 643 644 public int getEditorAreaState() { 645 return central.getEditorAreaState(); 646 } 647 648 public void setEditorAreaFrameState(int editorAreaFrameState) { 649 central.setEditorAreaFrameState(editorAreaFrameState); 650 } 651 652 public int getEditorAreaFrameState() { 653 return central.getEditorAreaFrameState(); 654 } 655 656 660 public void switchMaximizedMode(ModeImpl newMaximizedMode) { 661 central.switchMaximizedMode(newMaximizedMode); 662 } 663 664 665 public void setEditorMaximizedMode(ModeImpl editorMaximizedMode) { 666 central.setEditorMaximizedMode(editorMaximizedMode); 667 } 668 669 670 public void setViewMaximizedMode(ModeImpl viewMaximizedMode) { 671 central.setViewMaximizedMode(viewMaximizedMode); 672 } 673 674 675 public ModeImpl getCurrentMaximizedMode() { 676 return central.getCurrentMaximizedMode(); 677 } 678 679 680 public ModeImpl getEditorMaximizedMode() { 681 return central.getEditorMaximizedMode(); 682 } 683 684 685 public ModeImpl getViewMaximizedMode() { 686 return central.getViewMaximizedMode(); 687 } 688 689 690 public void setModeConstraints(ModeImpl mode, SplitConstraint[] modeConstraints) { 691 central.setModeConstraints(mode, modeConstraints); 692 } 693 694 695 public SplitConstraint[] getModeConstraints(ModeImpl mode) { 696 return central.getModeConstraints(mode); 697 } 698 699 700 private void addMode(ModeImpl mode, SplitConstraint[] modeConstraints) { 701 if (mode.getKind() == Constants.MODE_KIND_SLIDING) { 702 central.addSlidingMode(mode, null, Constants.LEFT, null); 704 } else { 705 central.addMode(mode, modeConstraints); 706 } 707 } 708 709 710 public void removeMode(ModeImpl mode) { 711 if (mode.getKind() == Constants.MODE_KIND_SLIDING) { 712 713 } else { 714 central.removeMode(mode); 715 } 716 } 717 718 719 public void setToolbarConfigName(String toolbarConfigName) { 720 central.setToolbarConfigName(toolbarConfigName); 721 } 722 723 725 public String getToolbarConfigName () { 726 return central.getToolbarConfigName(); 727 } 728 729 731 732 733 734 public void setVisible(boolean visible) { 735 SwingUtilities.invokeLater(exclusive); 736 central.setVisible(visible); 737 } 738 739 740 public boolean isVisible() { 741 return central.isVisible(); 742 } 743 744 745 public void attachTopComponentToSide(TopComponent tc, ModeImpl attachMode, String side) { 746 central.attachTopComponentsToSide(new TopComponent[] {tc}, attachMode, side); 747 } 748 750 boolean isTopComponentPersistentWhenClosed(TopComponent tc) { 751 return PersistenceHandler.getDefault().isTopComponentPersistentWhenClosed(tc); 753 } 754 755 public TopComponent getTopComponentForID(String tcID) { 757 return PersistenceHandler.getDefault().getTopComponentForID(tcID); 758 } 759 760 public boolean isTopComponentAllowedToMoveAnywhere(TopComponent tc) { 761 if(Boolean.TRUE.equals(tc.getClientProperty(Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE))) { 762 return true; 763 } 764 765 return false; 766 } 767 768 public ModeImpl findModeForOpenedID(String tcID) { 770 if(tcID == null) { 771 return null; 772 } 773 774 for(Iterator it = getModes().iterator(); it.hasNext(); ) { 775 ModeImpl mode = (ModeImpl)it.next(); 776 777 if(mode.getOpenedTopComponentsIDs().contains(tcID)) { 778 return mode; 779 } 780 } 781 782 return null; 783 } 784 785 public ModeImpl findModeForClosedID(String tcID) { 787 if(tcID == null) { 788 return null; 789 } 790 791 for(Iterator it = getModes().iterator(); it.hasNext(); ) { 792 ModeImpl mode = (ModeImpl)it.next(); 793 794 if(mode.getClosedTopComponentsIDs().contains(tcID)) { 795 return mode; 796 } 797 } 798 799 return null; 800 } 801 802 private static final boolean NAME_HACK = Boolean.getBoolean("nb.tabnames.html"); 804 812 public String getTopComponentDisplayName(TopComponent tc) { 813 if(tc == null) { 814 return null; 815 } 816 String displayName = tc.getHtmlDisplayName(); 817 if (displayName == null) { 818 displayName = tc.getDisplayName(); 819 } 820 if (displayName == null) { 821 displayName = tc.getName(); 822 } 823 if (NAME_HACK && displayName != null) { 824 if (displayName.endsWith("*")) { 828 829 if (displayName.startsWith("<html>")) { 830 displayName = displayName.substring(6); 831 } 832 833 displayName = "<html><b>" + 834 displayName.substring(0, displayName.length()-2); 835 836 } else { 837 838 int i = displayName.indexOf ("[r/o]"); 839 if (i > 0) { 840 841 if (displayName.startsWith("<html>")) { 842 displayName = displayName.substring(6); 843 i -= 6; 844 } 845 846 int roLength = "[r/o]".length(); 847 String nuName = "<html><font color='#555555'><i>" + displayName.substring (0, i-1); 849 if (i + roLength < displayName.length()) { 850 nuName += displayName.substring(i + roLength); 851 } 852 displayName = nuName; 853 } 854 } 855 } 856 return displayName; 857 } 858 859 Central getCentral() { 861 return central; 862 } 863 864 public boolean isDragInProgress() { 866 return central.isDragInProgress(); 867 } 868 869 876 public String guessSlideSide(TopComponent tc) { 877 return central.guessSlideSide(tc); 878 } 879 880 883 public boolean isDocked (TopComponent comp) { 884 return central.isDocked(comp); 885 } 886 887 895 public void userUndockedTopComponent(TopComponent tc, int modeKind) { 896 if (!isDocked(tc)) { 897 throw new IllegalStateException ("TopComponent is already in floating state: " + tc); 898 } 899 900 central.userUndockedTopComponent(tc, modeKind); 901 } 902 903 910 public void userDockedTopComponent(TopComponent tc, int modeKind) { 911 if (isDocked(tc)) { 912 throw new IllegalStateException ("TopComponent is already inside main window: " + tc); 913 } 914 915 central.userDockedTopComponent(tc, modeKind); 916 } 917 918 public void setRecentViewList(TopComponent[] tcs) { 920 recentViewList.setTopComponents(tcs); 921 } 922 923 public TopComponent[] getRecentViewList() { 924 return recentViewList.getTopComponents(); 925 } 926 928 void doFirePropertyChange(final String propName, 929 final Object oldValue, final Object newValue) { 930 if(SwingUtilities.isEventDispatchThread()) { 934 changeSupport.firePropertyChange(propName, oldValue, newValue); 935 } else { 936 SwingUtilities.invokeLater(new Runnable () { 937 public void run() { 938 changeSupport.firePropertyChange(propName, oldValue, newValue); 939 } 940 }); 941 } 942 } 943 944 946 public org.netbeans.core.windows.persistence.PersistenceObserver getPersistenceObserver() { 947 return PersistenceHandler.getDefault(); 948 } 949 950 951 public void notifyTopComponentOpened(TopComponent tc) { 954 componentOpenNotify(tc); 956 notifyRegistryTopComponentOpened(tc); 958 } 959 960 public void notifyTopComponentClosed(TopComponent tc) { 961 componentCloseNotify(tc); 963 notifyRegistryTopComponentClosed(tc); 965 } 966 969 static void notifyRegistryTopComponentActivated(final TopComponent tc) { 972 ((RegistryImpl)getDefault().getRegistry()).topComponentActivated(tc); 973 974 975 if(SwingUtilities.isEventDispatchThread()) { 977 WindowManagerImpl.getInstance().activateComponent(tc); 978 } else { 979 SwingUtilities.invokeLater(new Runnable () { 980 public void run() { 981 WindowManagerImpl.getInstance().activateComponent(tc); 982 } 983 }); 984 } 985 } 986 987 private static void notifyRegistryTopComponentOpened(TopComponent tc) { 988 ((RegistryImpl)getDefault().getRegistry()).topComponentOpened(tc); 989 } 990 991 private static void notifyRegistryTopComponentClosed(TopComponent tc) { 992 ((RegistryImpl)getDefault().getRegistry()).topComponentClosed(tc); 993 } 994 995 private static void notifyRegistrySelectedNodesChanged(TopComponent tc, Node[] nodes) { 996 ((RegistryImpl)getDefault().getRegistry()).selectedNodesChanged(tc, nodes); 997 } 998 1001 1002 public void componentShowing(TopComponent tc) { 1003 if((tc != null) && (tc != persistenceShowingTC)) { 1004 super.componentShowing(tc); 1005 } 1006 } 1007 1008 1010 void specialPersistenceCompShow(TopComponent tc) { 1011 componentShowing(tc); 1012 persistenceShowingTC = tc; 1013 } 1014 1015 1016 public void componentHidden(TopComponent tc) { 1017 if(tc != null) { 1018 super.componentHidden(tc); 1019 if (tc == persistenceShowingTC) { 1020 persistenceShowingTC = null; 1021 } 1022 } 1023 } 1024 1025 1026 protected void topComponentOpen(TopComponent tc) { 1028 assertEventDispatchThreadWeak(); 1029 1030 if (tc == null) { 1031 throw new IllegalArgumentException ("Cannot open a null " + 1032 "TopComponent"); } 1034 1035 1036 ModeImpl mode = getMode(tc); 1037 1038 if(mode == null) { 1039 mode = getDefaultEditorMode(); 1040 if (tc.getClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE) == null) { 1041 tc.putClientProperty (Constants.TOPCOMPONENT_ALLOW_DOCK_ANYWHERE, Boolean.TRUE); 1042 } 1043 } 1044 boolean alreadyOpened = mode.getOpenedTopComponents().contains( tc ); 1045 1046 ModeImpl maximizedMode = getCurrentMaximizedMode(); 1049 if(maximizedMode != null && mode != maximizedMode 1050 && mode.getKind() != Constants.MODE_KIND_SLIDING 1051 && central.isViewMaximized() ) { 1052 switchMaximizedMode(null); 1053 } 1054 1055 mode.addOpenedTopComponent(tc); 1056 1057 if( central.isEditorMaximized() 1058 && !alreadyOpened 1059 && mode.getState() != Constants.MODE_STATE_SEPARATED ) { 1060 String tcID = findTopComponentID( tc ); 1062 if( !isTopComponentDockedInMaximizedMode( tcID ) && mode.getKind() != Constants.MODE_KIND_SLIDING ) { 1063 central.slide( tc, mode, central.getSlideSideForMode( mode ) ); 1065 1066 topComponentRequestActive( tc ); 1067 } 1068 } 1069 } 1070 1071 protected void topComponentClose(TopComponent tc) { 1072 assertEventDispatchThreadWeak(); 1073 1074 boolean opened = topComponentIsOpened(tc); 1075 if(!opened) { 1076 return; 1077 } 1078 1079 ModeImpl mode = getModeForOpenedTopComponent(tc); 1080 if(mode != null) { 1081 mode.close(tc); 1082 } 1083 } 1084 1085 protected void topComponentRequestActive(TopComponent tc) { 1086 assertEventDispatchThreadWeak(); 1087 1088 ModeImpl mode = getModeForOpenedTopComponent(tc); 1089 if(mode != null) { 1090 central.activateModeTopComponent(mode, tc); 1091 } 1092 } 1093 1094 protected void topComponentRequestVisible(TopComponent tc) { 1095 assertEventDispatchThreadWeak(); 1096 1097 ModeImpl mode = getModeForOpenedTopComponent(tc); 1098 if(mode != null) { 1099 central.setModeSelectedTopComponent(mode, tc); 1100 } 1101 } 1102 1103 protected void topComponentDisplayNameChanged(TopComponent tc, String displayName) { 1104 assertEventDispatchThreadWeak(); 1105 1106 ModeImpl mode = getModeForOpenedTopComponent(tc); 1107 if(mode != null) { 1108 central.topComponentDisplayNameChanged(mode, tc); 1109 } 1110 } 1111 1112 protected void topComponentHtmlDisplayNameChanged(TopComponent tc, String htmlDisplayName) { 1113 topComponentDisplayNameChanged(tc, null); 1115 } 1116 1117 protected void topComponentToolTipChanged(TopComponent tc, String toolTip) { 1118 assertEventDispatchThreadWeak(); 1119 1120 ModeImpl mode = getModeForOpenedTopComponent(tc); 1121 if(mode != null) { 1122 central.topComponentToolTipChanged(mode, tc); 1123 } 1124 } 1125 1126 protected void topComponentIconChanged(TopComponent tc, Image icon) { 1127 assertEventDispatchThreadWeak(); 1128 1129 ModeImpl mode = getModeForOpenedTopComponent(tc); 1130 if(mode != null) { 1131 central.topComponentIconChanged(mode, tc); 1132 } 1133 } 1134 1135 protected void topComponentActivatedNodesChanged(TopComponent tc, Node[] activatedNodes) { 1136 assertEventDispatchThreadWeak(); 1137 1138 notifyRegistrySelectedNodesChanged(tc, activatedNodes); 1139 } 1140 1141 protected boolean topComponentIsOpened(TopComponent tc) { 1142 assertEventDispatchThreadWeak(); 1143 1144 return getModeForOpenedTopComponent(tc) != null; 1145 } 1146 1147 protected Action[] topComponentDefaultActions(TopComponent tc) { 1148 assertEventDispatchThreadWeak(); 1149 1150 return ActionUtils.createDefaultPopupActions(tc); 1151 } 1152 1153 protected String topComponentID (TopComponent tc, String preferredID) { 1154 assertEventDispatchThreadWeak(); 1155 1156 if (preferredID == null) { 1157 Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.WARNING, null, 1158 new java.lang.IllegalStateException ("Assertion failed. " + 1159 tc.getClass().getName() + 1160 ".preferredID method shouldn\'t be overriden to return null. " + 1161 "Please change your impl to return non-null string.")); } 1163 1164 return PersistenceManager.getDefault().getGlobalTopComponentID(tc, preferredID); 1165 } 1166 1167 @Override 1168 public void invokeWhenUIReady(Runnable run) { 1169 exclusive.register(run); 1170 } 1171 1172 @Override 1173 public boolean isEditorTopComponent( TopComponent tc ) { 1174 for( Iterator it = getModes().iterator(); it.hasNext(); ) { 1175 ModeImpl mode = (ModeImpl)it.next(); 1176 1177 if( mode.containsTopComponent( tc ) ) { 1178 return isEditorMode( mode ); 1179 } 1180 } 1181 1182 return false; 1184 } 1185 1186 @Override 1187 public boolean isEditorMode( Mode mode ) { 1188 ModeImpl modeImpl = findModeImpl( mode.getName() ); 1189 return null != modeImpl && modeImpl.getKind() == Constants.MODE_KIND_EDITOR; 1190 } 1191 1192 1194 private static final class Exclusive implements Runnable { 1195 1196 private ArrayList<Runnable > arr = new ArrayList<Runnable >(); 1197 1198 1201 public synchronized void register(Runnable r) { 1202 arr.add(r); 1203 SwingUtilities.invokeLater(this); 1204 } 1205 1206 public void run() { 1207 if (!WindowManagerImpl.getInstance().isVisible()) { 1208 return; 1209 } 1210 1211 ArrayList<Runnable > arrCopy = null; 1212 synchronized (this) { 1213 if (arr.isEmpty()) { 1214 return; 1215 } 1216 1217 arrCopy = arr; 1218 arr = new ArrayList<Runnable >(); 1219 } 1220 1221 for (Runnable r : arrCopy) { 1222 try { 1223 r.run(); 1224 } catch (RuntimeException ex) { 1225 Logger.getLogger(WindowManagerImpl.class.getName()).log( 1226 Level.WARNING, null, ex); 1227 } 1228 } 1229 } 1230 } 1232 public void resetModel() { 1233 central.resetModel(); 1234 RegistryImpl rimpl = (RegistryImpl)componentRegistry(); 1235 rimpl.clear(); 1236 } 1237 1238 1240 1241 private ModeImpl getMode(TopComponent tc) { 1242 return (ModeImpl)findMode(tc); 1243 } 1244 1245 1247 private ModeImpl getModeForOpenedTopComponent(TopComponent tc) { 1248 if(tc == null) { 1249 return null; 1251 } 1252 1253 for(Iterator it = getModes().iterator(); it.hasNext(); ) { 1254 ModeImpl mode = (ModeImpl)it.next(); 1255 1256 if(mode.getOpenedTopComponents().contains(tc)) { 1257 return mode; 1258 } 1259 } 1260 1261 return null; 1262 } 1263 1264 1267 public ModeImpl getPreviousModeForTopComponent(String tcID, ModeImpl slidingMode) { 1268 return getCentral().getModeTopComponentPreviousMode(tcID, slidingMode); 1269 } 1270 1271 1274 public int getPreviousIndexForTopComponent(String tcID, ModeImpl slidingMode) { 1275 return getCentral().getModeTopComponentPreviousIndex(tcID, slidingMode); 1276 1277 } 1278 1279 1287 public void setPreviousModeForTopComponent(String tcID, ModeImpl slidingMode, ModeImpl prevMode, int prevIndex) { 1288 getCentral().setModeTopComponentPreviousMode(tcID, slidingMode, prevMode, prevIndex); 1289 } 1290 1291 1298 public void setTopComponentDockedInMaximizedMode( String tcID, boolean docked ) { 1299 getCentral().setTopComponentDockedInMaximizedMode( tcID, docked ); 1300 } 1301 1302 1309 public boolean isTopComponentDockedInMaximizedMode( String tcID ) { 1310 return getCentral().isTopComponentDockedInMaximizedMode( tcID ); 1311 } 1312 1313 1320 public void setTopComponentSlidedInDefaultMode( String tcID, boolean slided ) { 1321 getCentral().setTopComponentSlidedInDefaultMode( tcID, slided ); 1322 } 1323 1324 1331 public boolean isTopComponentSlidedInDefaultMode( String tcID ) { 1332 return getCentral().isTopComponentSlidedInDefaultMode( tcID ); 1333 } 1334 1335 1341 public boolean isTopComponentMaximizedWhenSlidedIn( String tcID ) { 1342 return getCentral().isTopComponentMaximizedWhenSlidedIn( tcID ); 1343 } 1344 1345 1351 public void setTopComponentMaximizedWhenSlidedIn( String tcID, boolean maximized ) { 1352 getCentral().setTopComponentMaximizedWhenSlidedIn( tcID, maximized ); 1353 } 1354 1355 public void userToggledTopComponentSlideInMaximize( String tcID ) { 1356 getCentral().userToggledTopComponentSlideInMaximize( tcID ); 1357 } 1358 1359 1364 public static boolean isSeparateWindow (Window w) { 1365 if (!(w instanceof RootPaneContainer)) { 1367 return false; 1368 } 1369 JRootPane rp = ((RootPaneContainer) w).getRootPane(); 1371 if (rp == null) { 1372 return false; 1373 } 1374 return rp.getClientProperty(Constants.SEPARATE_WINDOW_PROPERTY) != null; 1375 } 1376 1377 private static final String ASSERTION_ERROR_MESSAGE = "WindowsAPI is required to be called from AWT thread only, see " + "http://core.netbeans.org/proposals/threading/"; 1380 static void assertEventDispatchThread() { 1381 assert SwingUtilities.isEventDispatchThread() : ASSERTION_ERROR_MESSAGE; 1382 } 1383 1384 static void assertEventDispatchThreadWeak() { 1386 if(!SwingUtilities.isEventDispatchThread()) { 1387 Logger.getLogger(WindowManagerImpl.class.getName()).log(Level.WARNING, null, 1388 new java.lang.IllegalStateException ("Assertion failed. " + 1389 ASSERTION_ERROR_MESSAGE)); } 1391 } 1392 1393 1396 public TopComponent[] getEditorTopComponents() { 1397 ArrayList<TopComponent> editors = new ArrayList<TopComponent>(); 1398 Set<? extends Mode> modes = getModes(); 1399 for(Mode mode: modes) { 1400 ModeImpl modeImpl = findModeImpl( mode.getName() ); if( modeImpl.getKind() == Constants.MODE_KIND_EDITOR ) { 1402 editors.addAll( modeImpl.getOpenedTopComponents() ); 1403 } 1404 } 1405 return editors.toArray( new TopComponent[editors.size()] ); 1406 } 1407 1408 1412 public TopComponent getArbitrarySelectedEditorTopComponent() { 1413 Set modes = getModes(); 1414 for( Iterator i=modes.iterator(); i.hasNext(); ) { 1415 Mode mode = (Mode)i.next(); 1416 ModeImpl modeImpl = findModeImpl( mode.getName() ); 1417 if( modeImpl.getKind() == Constants.MODE_KIND_EDITOR ) { 1418 return mode.getSelectedTopComponent(); 1419 } 1420 } 1421 return null; 1422 } 1423 1424 1427 public void deselectEditorTopComponents() { 1428 Set modes = getModes(); 1429 for( Iterator i=modes.iterator(); i.hasNext(); ) { 1430 Mode mode = (Mode)i.next(); 1431 ModeImpl modeImpl = findModeImpl( mode.getName() ); 1432 if( modeImpl.getKind() == Constants.MODE_KIND_EDITOR ) { 1433 TopComponent dummy = new DummyTopComponent(); 1437 modeImpl.addOpenedTopComponent( dummy ); 1438 modeImpl.setSelectedTopComponent( dummy ); 1439 } 1440 } 1441 } 1442 1443 1447 public void closeNonEditorViews() { 1448 Set modes = getModes(); 1449 for( Iterator i=modes.iterator(); i.hasNext(); ) { 1450 Mode mode = (Mode)i.next(); 1451 ModeImpl modeImpl = findModeImpl( mode.getName() ); 1452 if( null != modeImpl && modeImpl.getKind() != Constants.MODE_KIND_EDITOR ) { 1453 java.util.List tcs = modeImpl.getOpenedTopComponents(); 1454 for( Iterator j=tcs.iterator(); j.hasNext(); ) { 1455 TopComponent tc = (TopComponent)j.next(); 1456 tc.close(); 1457 } 1458 } 1459 } 1460 } 1461 1462 1465 private static class DummyTopComponent extends TopComponent { 1466 protected String preferredID() { 1467 return "temp"; 1468 } 1469 1470 public int getPersistenceType() { 1471 return PERSISTENCE_NEVER; 1472 } 1473 } 1474} 1475 1476 | Popular Tags |