1 19 20 package org.netbeans.core.windows; 21 22 23 import java.awt.Component ; 24 import java.awt.Dimension ; 25 import java.awt.Frame ; 26 import java.awt.Point ; 27 import java.awt.Rectangle ; 28 import java.util.ArrayList ; 29 import java.util.Arrays ; 30 import java.util.Collections ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Set ; 36 import javax.swing.SwingUtilities ; 37 38 import org.netbeans.core.windows.model.DockingStatus; 39 import org.netbeans.core.windows.model.Model; 40 import org.netbeans.core.windows.model.ModelElement; 41 import org.netbeans.core.windows.model.ModelFactory; 42 import org.netbeans.core.windows.persistence.PersistenceManager; 43 import org.netbeans.core.windows.view.ControllerHandler; 44 import org.netbeans.core.windows.view.View; 45 import org.openide.windows.Mode; 46 import org.openide.windows.TopComponent; 47 import org.openide.windows.WindowManager; 48 49 50 51 57 final class Central implements ControllerHandler { 58 59 60 private final Model model = ModelFactory.createWindowSystemModel(); 61 62 63 private final ViewRequestor viewRequestor = new ViewRequestor(this); 64 65 66 public Central() { 67 } 68 69 70 public void topComponentRequestAttention (ModeImpl mode, TopComponent tc) { 71 String modeName = getModeName(mode); 72 viewRequestor.scheduleRequest ( 73 new ViewRequest(modeName, View.TOPCOMPONENT_REQUEST_ATTENTION, tc, tc)); 74 } 75 76 public void topComponentCancelRequestAttention (ModeImpl mode, TopComponent tc) { 77 String modeName = getModeName(mode); 78 viewRequestor.scheduleRequest ( 79 new ViewRequest(modeName, View.TOPCOMPONENT_CANCEL_REQUEST_ATTENTION, tc, tc)); 80 } 81 82 85 public void setVisible(boolean visible) { 86 if(isVisible() == visible) { 87 return; 88 } 89 90 model.setVisible(visible); 91 92 viewRequestor.scheduleRequest( 93 new ViewRequest(null, View.CHANGE_VISIBILITY_CHANGED, null, Boolean.valueOf(visible))); 94 } 95 96 97 public void setMainWindowBoundsJoined(Rectangle mainWindowBoundsJoined) { 98 if(mainWindowBoundsJoined == null) { 99 return; 100 } 101 102 Rectangle old = getMainWindowBoundsJoined(); 103 if(old.equals(mainWindowBoundsJoined)) { 104 return; 105 } 106 107 model.setMainWindowBoundsJoined(mainWindowBoundsJoined); 108 109 if(isVisible()) { 110 viewRequestor.scheduleRequest( 111 new ViewRequest(null, View.CHANGE_MAIN_WINDOW_BOUNDS_JOINED_CHANGED, 112 old, mainWindowBoundsJoined)); 113 } 114 } 115 116 117 public void setMainWindowBoundsSeparated(Rectangle mainWindowBoundsSeparated) { 118 if(mainWindowBoundsSeparated == null) { 119 return; 120 } 121 122 Rectangle old = getMainWindowBoundsSeparated(); 123 if(old.equals(mainWindowBoundsSeparated)) { 124 return; 125 } 126 127 model.setMainWindowBoundsSeparated(mainWindowBoundsSeparated); 128 129 if(isVisible()) { 130 viewRequestor.scheduleRequest( 131 new ViewRequest(null, View.CHANGE_MAIN_WINDOW_BOUNDS_SEPARATED_CHANGED, 132 old, mainWindowBoundsSeparated)); 133 } 134 } 135 136 public void setMainWindowFrameStateJoined(int frameState) { 137 int old = getMainWindowFrameStateJoined(); 138 if(old == frameState) { 139 return; 140 } 141 142 model.setMainWindowFrameStateJoined(frameState); 143 144 if(isVisible()) { 145 viewRequestor.scheduleRequest(new ViewRequest(null, View.CHANGE_MAIN_WINDOW_FRAME_STATE_JOINED_CHANGED, 146 Integer.valueOf(old), Integer.valueOf(frameState))); 147 } 148 } 149 150 public void setMainWindowFrameStateSeparated(int frameState) { 151 int old = getMainWindowFrameStateSeparated(); 152 if(old == frameState) { 153 return; 154 } 155 156 model.setMainWindowFrameStateSeparated(frameState); 157 158 if(isVisible()) { 159 viewRequestor.scheduleRequest(new ViewRequest(null, View.CHANGE_MAIN_WINDOW_FRAME_STATE_SEPARATED_CHANGED, 160 Integer.valueOf(old), Integer.valueOf(frameState))); 161 } 162 } 163 164 165 public void setActiveMode(final ModeImpl activeMode) { 166 final ModeImpl old = getActiveMode(); 167 if(activeMode == old) { 168 ModeImpl impl = model.getSlidingMode(Constants.BOTTOM); 172 boolean bottom = (impl == null || impl.getSelectedTopComponent() == null); 173 impl = model.getSlidingMode(Constants.LEFT); 174 boolean left = (impl == null || impl.getSelectedTopComponent() == null); 175 impl = model.getSlidingMode(Constants.RIGHT); 176 boolean right = (impl == null || impl.getSelectedTopComponent() == null); 177 if (bottom && left && right) { 178 return; 179 } 180 } 181 182 model.setActiveMode(activeMode); 183 184 if(isVisible()) { 185 viewRequestor.scheduleRequest( 186 new ViewRequest(null, View.CHANGE_ACTIVE_MODE_CHANGED, 187 old, activeMode)); 188 } 189 190 191 192 WindowManagerImpl.getInstance().doFirePropertyChange( 193 WindowManagerImpl.PROP_ACTIVE_MODE, old, activeMode); 194 195 if (activeMode != null) { 200 WindowManagerImpl.notifyRegistryTopComponentActivated( 201 activeMode.getSelectedTopComponent()); 202 } else { 203 WindowManagerImpl.notifyRegistryTopComponentActivated(null); 204 } 205 } 206 207 208 public void setEditorAreaBounds(Rectangle editorAreaBounds) { 209 if(editorAreaBounds == null) { 210 return; 211 } 212 213 Rectangle old = getEditorAreaBounds(); 214 if(old.equals(editorAreaBounds)) { 215 return; 216 } 217 218 model.setEditorAreaBounds(editorAreaBounds); 219 220 if(isVisible()) { 221 viewRequestor.scheduleRequest( 222 new ViewRequest(null, View.CHANGE_EDITOR_AREA_BOUNDS_CHANGED, 223 old, editorAreaBounds)); 224 } 225 } 226 227 228 public void setEditorAreaConstraints(SplitConstraint[] editorAreaConstraints) { 229 SplitConstraint[] old = getEditorAreaConstraints(); 230 if(Arrays.equals(old, editorAreaConstraints)) { 231 return; 232 } 233 234 model.setEditorAreaConstraints(editorAreaConstraints); 235 236 if(isVisible()) { 237 viewRequestor.scheduleRequest( 238 new ViewRequest(null, View.CHANGE_EDITOR_AREA_CONSTRAINTS_CHANGED, 239 old, editorAreaConstraints)); 240 } 241 } 242 243 244 public void setEditorAreaState(int editorAreaState) { 245 int old = getEditorAreaState(); 246 if(editorAreaState == old) { 247 return; 248 } 249 250 int requiredState = editorAreaState == Constants.EDITOR_AREA_JOINED 251 ? Constants.MODE_STATE_JOINED 252 : Constants.MODE_STATE_SEPARATED; 253 254 for(Iterator it = getModes().iterator(); it.hasNext(); ) { 255 ModeImpl mode = (ModeImpl)it.next(); 256 if(mode.getKind() == Constants.MODE_KIND_VIEW 257 && mode.getState() != requiredState) { 258 model.setModeState(mode, requiredState); 259 if(editorAreaState == Constants.EDITOR_AREA_SEPARATED) { 261 Rectangle bounds = model.getModeBounds(mode); 262 if(bounds.isEmpty()) { 263 model.setModeBounds(mode, model.getModeBoundsSeparatedHelp(mode)); 264 } 265 } 266 } 267 if (mode.getKind() == Constants.MODE_KIND_SLIDING && editorAreaState == Constants.EDITOR_AREA_SEPARATED) { 270 TopComponent[] tcs = mode.getTopComponents(); 271 for (int i = 0; i < tcs.length;i++) { 272 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tcs[i]); 273 ModeImpl targetMode = model.getModeTopComponentPreviousMode(mode, tcID); 274 if ((targetMode == null) || !model.getModes().contains(targetMode)) { 275 SplitConstraint[] constraints = model.getModeTopComponentPreviousConstraints(mode, tcID); 276 constraints = constraints == null ? new SplitConstraint[0] : constraints; 277 targetMode = WindowManagerImpl.getInstance().createModeImpl( 279 ModeImpl.getUnusedModeName(), Constants.MODE_KIND_VIEW, false); 280 model.setModeState(targetMode, requiredState); 281 model.addMode(targetMode, constraints); 282 } 283 moveTopComponentsIntoMode(targetMode, new TopComponent[] { tcs[i] } ); 284 } 285 } 286 } 288 289 if(editorAreaState == Constants.EDITOR_AREA_SEPARATED) { 290 Rectangle editorAreaBounds = model.getEditorAreaBounds(); 291 if(editorAreaBounds.isEmpty()) { 293 model.setEditorAreaBounds(model.getEditorAreaBoundsHelp()); 294 } 295 296 Rectangle mainWindowBoundsSeparated = model.getMainWindowBoundsSeparated(); 298 if(mainWindowBoundsSeparated.isEmpty()) { 299 model.setMainWindowBoundsSeparated(model.getMainWindowBoundsSeparatedHelp()); 300 } 301 } 302 303 model.setEditorAreaState(editorAreaState); 304 305 if(isVisible()) { 306 viewRequestor.scheduleRequest( 307 new ViewRequest(null, View.CHANGE_EDITOR_AREA_STATE_CHANGED, 308 Integer.valueOf(old), Integer.valueOf(editorAreaState))); 309 } 310 311 WindowManagerImpl.getInstance().doFirePropertyChange( 312 WindowManagerImpl.PROP_EDITOR_AREA_STATE, Integer.valueOf(old), Integer.valueOf(editorAreaState)); 313 } 314 315 public void setEditorAreaFrameState(int frameState) { 316 int old = getEditorAreaFrameState(); 317 if(old == frameState) { 318 return; 319 } 320 model.setEditorAreaFrameState(frameState); 321 322 if(isVisible()) { 323 viewRequestor.scheduleRequest(new ViewRequest(null, View.CHANGE_EDITOR_AREA_FRAME_STATE_CHANGED, 324 Integer.valueOf(old), Integer.valueOf(frameState))); 325 } 326 } 327 328 329 void switchMaximizedMode(ModeImpl newMaximizedMode) { 330 ModeImpl old = getCurrentMaximizedMode(); 331 if(newMaximizedMode == old) { 332 return; 333 } 334 335 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 336 if( null == newMaximizedMode ) { 337 if( isViewMaximized() ) { 339 341 if( isEditorMaximized() ) { 343 restoreViews( model.getMaximizedDockingStatus() ); 344 } else { 345 restoreViews( model.getDefaultDockingStatus() ); 346 } 347 348 ModeImpl currentMaximizedMode = getViewMaximizedMode(); 350 assert currentMaximizedMode.getTopComponents().length == 1; 351 TopComponent maximizedTC = currentMaximizedMode.getTopComponents()[0]; 352 String tcID = wm.findTopComponentID( maximizedTC ); 353 ModeImpl prevMode = getModeTopComponentPreviousMode( tcID, currentMaximizedMode ); 355 int prevIndex = model.getModeTopComponentPreviousIndex( currentMaximizedMode, tcID ); 356 if( null == prevMode ) { 357 if ((prevMode == null) || !model.getModes().contains(prevMode)) { 359 SplitConstraint[] constraints = model.getModeTopComponentPreviousConstraints(currentMaximizedMode, tcID); 361 if (constraints != null) { 362 prevMode = WindowManagerImpl.getInstance().createModeImpl( 364 ModeImpl.getUnusedModeName(), Constants.MODE_KIND_VIEW, false); 365 model.addMode(prevMode, constraints); 366 } 367 } 368 369 if (prevMode == null) { 370 prevMode = WindowManagerImpl.getInstance().getDefaultViewMode(); 372 } 373 } 374 prevMode.addOpenedTopComponent( maximizedTC, prevIndex ); 375 prevMode.setSelectedTopComponent( maximizedTC ); 376 setActiveMode(prevMode); 377 model.removeMode( currentMaximizedMode ); 378 setViewMaximizedMode( null ); 380 381 } else if( isEditorMaximized() ) { 382 model.getMaximizedDockingStatus().mark(); 384 ModeImpl prevActiveMode = getActiveMode(); 385 restoreViews( model.getDefaultDockingStatus() ); 387 388 setEditorMaximizedMode( null ); 390 391 setActiveMode( prevActiveMode ); 392 393 } 394 } else { 395 assert !isViewMaximized(); 396 397 if( newMaximizedMode.getKind() == Constants.MODE_KIND_EDITOR ) { 399 401 model.getDefaultDockingStatus().mark(); 403 restoreViews( model.getMaximizedDockingStatus() ); 405 406 setEditorMaximizedMode( newMaximizedMode ); 407 408 } else if( newMaximizedMode.getKind() == Constants.MODE_KIND_VIEW ) { 409 411 if( isEditorMaximized() ) { 413 model.getMaximizedDockingStatus().mark(); 414 } else { 415 model.getDefaultDockingStatus().mark(); 416 } 417 418 TopComponent tcToMaximize = newMaximizedMode.getSelectedTopComponent(); 420 String tcID = wm.findTopComponentID( tcToMaximize ); 421 int prevIndex = newMaximizedMode.getOpenedTopComponents().indexOf( tcToMaximize ); 422 423 ModeImpl mode = WindowManagerImpl.getInstance().createModeImpl(ModeImpl.getUnusedModeName(), Constants.MODE_KIND_VIEW, true); 425 model.addMode(mode, new SplitConstraint[0]); 426 mode.addOpenedTopComponent( tcToMaximize ); 428 mode.setSelectedTopComponent( tcToMaximize ); 429 setModeTopComponentPreviousMode( tcID, mode, newMaximizedMode, prevIndex ); 431 432 setViewMaximizedMode( mode ); 433 434 slideAllViews(); 436 437 setActiveMode( mode ); 438 439 } else { 440 throw new IllegalArgumentException ( "Cannot maximize a sliding view" ); 441 } 442 } 443 444 if(isVisible()) { 445 viewRequestor.scheduleRequest( 446 new ViewRequest(null, View.CHANGE_MAXIMIZED_MODE_CHANGED, 447 old, getCurrentMaximizedMode())); 448 } 449 450 WindowManagerImpl.getInstance().doFirePropertyChange( 451 WindowManagerImpl.PROP_MAXIMIZED_MODE, old, getCurrentMaximizedMode()); 452 } 453 454 455 void setEditorMaximizedMode(ModeImpl editorMaximizedMode) { 456 model.setEditorMaximizedMode( editorMaximizedMode ); 457 } 458 459 460 void setViewMaximizedMode(ModeImpl viewMaximizedMode) { 461 model.setViewMaximizedMode( viewMaximizedMode ); 462 } 463 464 465 public void setModeConstraints(ModeImpl mode, SplitConstraint[] modeConstraints) { 466 SplitConstraint[] old = getModeConstraints(mode); 467 if(Arrays.equals(modeConstraints, old)) { 468 return; 469 } 470 471 model.setModeConstraints(mode, modeConstraints); 472 473 if(isVisible()) { 474 viewRequestor.scheduleRequest( 475 new ViewRequest(null, View.CHANGE_MODE_CONSTRAINTS_CHANGED, 476 old, modeConstraints)); 477 } 478 } 479 480 481 public void addMode(ModeImpl mode, SplitConstraint[] modeConstraints) { 482 SplitConstraint[] old = getModeConstraints(mode); 487 if(modeConstraints == old) { 488 return; 489 } 490 491 model.addMode(mode, modeConstraints); 492 493 if(isVisible()) { 494 viewRequestor.scheduleRequest( 495 new ViewRequest(null, View.CHANGE_MODE_ADDED, null, mode)); 496 } 497 498 WindowManagerImpl.getInstance().doFirePropertyChange( 499 WindowManager.PROP_MODES, null, null); 500 } 501 502 503 public void removeMode(ModeImpl mode) { 504 if(!getModes().contains(mode)) { 505 return; 506 } 507 model.removeMode(mode); 509 if(isVisible()) { 510 viewRequestor.scheduleRequest( 511 new ViewRequest(null, View.CHANGE_MODE_REMOVED, null, mode)); 512 } 513 WindowManagerImpl.getInstance().doFirePropertyChange( 514 WindowManager.PROP_MODES, null, null); 515 } 516 517 518 public void setToolbarConfigName(String toolbarConfigName) { 519 String old = getToolbarConfigName(); 520 if(old.equals(toolbarConfigName)) { 521 return; 522 } 523 524 model.setToolbarConfigName(toolbarConfigName); 525 526 if(isVisible()) { 527 viewRequestor.scheduleRequest( 528 new ViewRequest(null, View.CHANGE_TOOLBAR_CONFIGURATION_CHANGED, 529 old, toolbarConfigName)); 530 } 531 } 532 533 534 public void updateUI() { 535 if(isVisible()) { 537 viewRequestor.scheduleRequest(new ViewRequest(null, View.CHANGE_UI_UPDATE, null, null)); 538 } 539 } 540 541 private void closeMode(ModeImpl mode) { 544 if(mode == null) { 545 return; 546 } 547 548 TopComponent[] tcs = getModeOpenedTopComponents(mode).toArray(new TopComponent[0]); 549 550 for(int i = 0; i < tcs.length; i++) { 551 TopComponent tc = tcs[i]; 552 if(WindowManagerImpl.getInstance().isTopComponentPersistentWhenClosed(tc)) { 553 model.addModeClosedTopComponent(mode, tc); 554 } else { 555 model.removeModeTopComponent(mode, tc); 557 String id = WindowManagerImpl.getInstance().findTopComponentID(tc); 558 PersistenceManager.getDefault().removeGlobalTopComponentID(id); 559 } 560 } 561 562 ModeImpl oldActive = getActiveMode(); 563 ModeImpl newActive; 564 if(mode == oldActive) { 565 newActive = setSomeModeActive(); 566 } else { 567 newActive = oldActive; 568 } 569 571 boolean modeRemoved = false; 573 if(!mode.isPermanent() && model.getModeTopComponents(mode).isEmpty()) { 574 if (doCheckSlidingModes(mode)) { 576 model.removeMode(mode); 578 modeRemoved = true; 579 } 580 } 581 582 if(isVisible()) { 583 viewRequestor.scheduleRequest(new ViewRequest(mode, View.CHANGE_MODE_CLOSED, null, null)); 584 } 585 586 for(int i = 0; i < tcs.length; i++) { 588 WindowManagerImpl.getInstance().notifyTopComponentClosed(tcs[i]); 590 } 591 592 if(oldActive != newActive) { 593 WindowManagerImpl.getInstance().doFirePropertyChange( 594 WindowManagerImpl.PROP_ACTIVE_MODE, oldActive, newActive); 595 } 596 597 if(modeRemoved) { 598 WindowManagerImpl.getInstance().doFirePropertyChange( 599 WindowManager.PROP_MODES, null, null); 600 } 601 602 if(newActive != null) { 604 WindowManagerImpl.notifyRegistryTopComponentActivated( 606 newActive.getSelectedTopComponent()); 607 } else { 608 WindowManagerImpl.notifyRegistryTopComponentActivated(null); 609 } 610 } 611 612 private ModeImpl setSomeModeActive() { 614 for(Iterator it = getModes().iterator(); it.hasNext(); ) { 615 ModeImpl mode = (ModeImpl)it.next(); 616 if(!mode.getOpenedTopComponents().isEmpty() && Constants.MODE_KIND_SLIDING != mode.getKind()) { 617 model.setActiveMode(mode); 618 return mode; 619 } 620 } 621 model.setActiveMode(null); 622 return model.getActiveMode(); 623 } 624 625 626 627 public void setModeBounds(ModeImpl mode, Rectangle bounds) { 628 if(bounds == null) { 629 return; 630 } 631 632 Rectangle old = getModeBounds(mode); 633 if(old.equals(bounds)) { 634 return; 635 } 636 637 model.setModeBounds(mode, bounds); 638 639 if(isVisible() && getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) { 640 viewRequestor.scheduleRequest(new ViewRequest( 641 mode, View.CHANGE_MODE_BOUNDS_CHANGED, old, bounds)); 642 } 643 644 mode.doFirePropertyChange(ModeImpl.PROP_BOUNDS, old, bounds); 645 } 646 647 648 public void setModeFrameState(ModeImpl mode, int frameState) { 649 int old = getModeFrameState(mode); 650 if(frameState == old) { 651 return; 652 } 653 654 model.setModeFrameState(mode, frameState); 655 656 if(isVisible()) { 657 viewRequestor.scheduleRequest(new ViewRequest( 658 mode, View.CHANGE_MODE_FRAME_STATE_CHANGED, 659 Integer.valueOf(old), Integer.valueOf(frameState))); 660 } 661 } 662 663 664 public void setModeSelectedTopComponent(ModeImpl mode, TopComponent selected) { 665 if (mode.getKind() != Constants.MODE_KIND_SLIDING || selected != null) { 667 if(!getModeOpenedTopComponents(mode).contains(selected)) { 668 return; 669 } 670 } 671 672 TopComponent old = getModeSelectedTopComponent(mode); 673 if(selected == old) { 674 return; 675 } 676 677 model.setModeSelectedTopComponent(mode, selected); 678 679 if(isVisible()) { 680 viewRequestor.scheduleRequest( 681 new ViewRequest(mode, View.CHANGE_MODE_SELECTED_TOPCOMPONENT_CHANGED, 682 old, selected)); 683 } 684 685 if(mode == getActiveMode()) { 687 WindowManagerImpl.notifyRegistryTopComponentActivated(selected); 688 } 689 } 690 691 697 public void setModePreviousSelectedTopComponent(ModeImpl mode, TopComponent tc) { 698 model.setModePreviousSelectedTopComponent( mode, tc ); 699 } 700 701 702 public void addModeOpenedTopComponent(ModeImpl mode, TopComponent tc) { 703 if(getModeOpenedTopComponents(mode).contains(tc)) { 704 return; 705 } 706 707 removeTopComponentFromOtherModes(mode, tc); 709 710 model.addModeOpenedTopComponent(mode, tc); 711 712 if(isVisible()) { 713 viewRequestor.scheduleRequest( 714 new ViewRequest(mode, View.CHANGE_MODE_TOPCOMPONENT_ADDED, 715 null, tc)); 716 } 717 718 WindowManagerImpl.getInstance().notifyTopComponentOpened(tc); 720 } 721 722 public void insertModeOpenedTopComponent(ModeImpl mode, TopComponent tc, int index) { 723 List openedTcs = getModeOpenedTopComponents(mode); 724 if(index >= 0 && !openedTcs.isEmpty() 725 && openedTcs.size() > index && openedTcs.get(index) == tc) { 726 return; 727 } 728 729 removeTopComponentFromOtherModes(mode, tc); 731 732 model.insertModeOpenedTopComponent(mode, tc, index); 733 734 if(isVisible()) { 735 viewRequestor.scheduleRequest( 736 new ViewRequest(mode, View.CHANGE_MODE_TOPCOMPONENT_ADDED, null, tc)); 738 } 739 } 740 741 public void addModeClosedTopComponent(ModeImpl mode, TopComponent tc) { 742 boolean opened = getModeOpenedTopComponents(mode).contains(tc); 743 744 if(opened && !tc.canClose()) { 745 return; 746 } 747 748 if(containsModeTopComponent(mode,tc) && !opened) { 749 return; 750 } 751 752 removeTopComponentFromOtherModes(mode, tc); 754 755 model.addModeClosedTopComponent(mode, tc); 756 757 ModeImpl oldActive = getActiveMode(); 758 ModeImpl newActive; 759 if(model.getModeOpenedTopComponents(mode).isEmpty() && mode == oldActive) { 760 newActive = setSomeModeActive(); 761 } else { 762 newActive = oldActive; 763 } 764 765 if(getCurrentMaximizedMode() == mode && model.getModeOpenedTopComponents(mode).isEmpty()) { 767 switchMaximizedMode(null); 768 } 769 770 if(isVisible() && opened) { 771 viewRequestor.scheduleRequest( 772 new ViewRequest(mode, View.CHANGE_MODE_TOPCOMPONENT_REMOVED, 773 null, tc)); 774 } 775 776 if(opened) { 778 WindowManagerImpl.getInstance().notifyTopComponentClosed(tc); 779 } 780 781 if(oldActive != newActive) { 782 WindowManagerImpl.getInstance().doFirePropertyChange( 783 WindowManagerImpl.PROP_ACTIVE_MODE, oldActive, newActive); 784 } 785 786 if(newActive != null) { 787 WindowManagerImpl.notifyRegistryTopComponentActivated( 789 newActive.getSelectedTopComponent()); 790 } else { 791 WindowManagerImpl.notifyRegistryTopComponentActivated(null); 792 } 793 } 794 795 public void addModeUnloadedTopComponent(ModeImpl mode, String tcID) { 797 model.addModeUnloadedTopComponent(mode, tcID); 798 } 799 800 public void setUnloadedSelectedTopComponent(ModeImpl mode, String tcID) { 802 model.setModeUnloadedSelectedTopComponent(mode, tcID); 803 } 804 805 public void setUnloadedPreviousSelectedTopComponent(ModeImpl mode, String tcID) { 806 model.setModeUnloadedPreviousSelectedTopComponent(mode, tcID); 807 } 808 809 public List <String > getModeOpenedTopComponentsIDs(ModeImpl mode) { 811 return model.getModeOpenedTopComponentsIDs(mode); 812 } 813 public List getModeClosedTopComponentsIDs(ModeImpl mode) { 815 return model.getModeClosedTopComponentsIDs(mode); 816 } 817 public List getModeTopComponentsIDs(ModeImpl mode) { 819 return model.getModeTopComponentsIDs(mode); 820 } 821 822 823 private boolean removeTopComponentFromOtherModes(ModeImpl mode, TopComponent tc) { 824 boolean tcRemoved = false; 825 for(Iterator it = model.getModes().iterator(); it.hasNext(); ) { 826 ModeImpl m = (ModeImpl)it.next(); 827 if(m == mode) { 828 continue; 829 } 830 831 if(model.containsModeTopComponent(m, tc)) { 832 tcRemoved = true; 833 model.removeModeTopComponent(m, tc); 834 836 boolean modeRemoved = false; 838 if(!m.isPermanent() && m.isEmpty() && doCheckSlidingModes(m) 839 && mode.getKind() != Constants.MODE_KIND_SLIDING) { 842 model.removeMode(m); 844 modeRemoved = true; 845 } 846 847 if(modeRemoved) { 848 WindowManagerImpl.getInstance().doFirePropertyChange( 849 WindowManager.PROP_MODES, null, null); 850 } 851 } 852 } 853 854 return tcRemoved; 855 } 856 857 858 public void removeModeTopComponent(ModeImpl mode, TopComponent tc) { 859 if(!containsModeTopComponent(mode, tc)) { 860 return; 861 } 862 863 boolean viewChange = getModeOpenedTopComponents(mode).contains(tc); 864 865 if(viewChange && !tc.canClose()) { 866 return; 867 } 868 869 model.removeModeTopComponent(mode, tc); 870 String id = WindowManagerImpl.getInstance().findTopComponentID(tc); 871 PersistenceManager.getDefault().removeGlobalTopComponentID(id); 872 873 ModeImpl oldActive = getActiveMode(); 874 ModeImpl newActive; 875 if(model.getModeOpenedTopComponents(mode).isEmpty() && mode == oldActive) { 876 newActive = setSomeModeActive(); 877 } else { 878 newActive = oldActive; 879 } 880 881 if(getCurrentMaximizedMode() == mode && model.getModeOpenedTopComponents(mode).isEmpty()) { 883 switchMaximizedMode(null); 884 } 885 886 boolean modeRemoved = false; 889 if(!mode.isPermanent() && model.getModeTopComponents(mode).isEmpty()) { 890 if (doCheckSlidingModes(mode)) { 893 model.removeMode(mode); 895 modeRemoved = true; 896 } 897 } 898 899 900 901 if(viewChange && isVisible()) { 902 viewRequestor.scheduleRequest(new ViewRequest( 903 mode, View.CHANGE_MODE_TOPCOMPONENT_REMOVED, 904 null, tc)); 905 } 906 907 if(viewChange) { 909 WindowManagerImpl.getInstance().notifyTopComponentClosed(tc); 910 } 911 912 if(oldActive != newActive) { 913 WindowManagerImpl.getInstance().doFirePropertyChange( 914 WindowManagerImpl.PROP_ACTIVE_MODE, oldActive, newActive); 915 } 916 917 if(modeRemoved) { 918 WindowManagerImpl.getInstance().doFirePropertyChange( 919 WindowManager.PROP_MODES, null, null); 920 } 921 922 if(newActive != null) { 923 WindowManagerImpl.notifyRegistryTopComponentActivated( 925 newActive.getSelectedTopComponent()); 926 } else { 927 WindowManagerImpl.notifyRegistryTopComponentActivated( 928 null); 929 } 930 } 931 932 private boolean doCheckSlidingModes(ModeImpl mode) { 934 ModeImpl slid = model.getSlidingMode(Constants.BOTTOM); 935 if (slid != null) { 936 TopComponent[] tcs = slid.getTopComponents(); 937 for (int i = 0; i < tcs.length; i++) { 938 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tcs[i]); 939 ModeImpl impl = model.getModeTopComponentPreviousMode(slid, tcID); 940 if (impl == mode) { 941 return false; 942 } 943 } 944 } 945 slid = model.getSlidingMode(Constants.LEFT); 946 if (slid != null) { 947 TopComponent[] tcs = slid.getTopComponents(); 948 for (int i = 0; i < tcs.length; i++) { 949 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tcs[i]); 950 ModeImpl impl = model.getModeTopComponentPreviousMode(slid, tcID); 951 if (impl == mode) { 952 return false; 953 } 954 } 955 } 956 slid = model.getSlidingMode(Constants.RIGHT); 957 if (slid != null) { 958 TopComponent[] tcs = slid.getTopComponents(); 959 for (int i = 0; i < tcs.length; i++) { 960 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tcs[i]); 961 ModeImpl impl = model.getModeTopComponentPreviousMode(slid, tcID); 962 if (impl == mode) { 963 return false; 964 } 965 } 966 } 967 return true; 968 } 969 970 public void removeModeClosedTopComponentID(ModeImpl mode, String tcID) { 972 model.removeModeClosedTopComponentID(mode, tcID); 974 } 975 978 public boolean isGroupOpened(TopComponentGroupImpl tcGroup) { 980 return model.isGroupOpened(tcGroup); 981 } 982 983 984 public void openGroup(TopComponentGroupImpl tcGroup) { 985 if(isGroupOpened(tcGroup)) { 986 return; 987 } 988 989 if( isEditorMaximized() && isViewMaximized() ) 990 switchMaximizedMode( null ); 991 992 Set <TopComponent> openedBeforeTopComponents = new HashSet <TopComponent>(); 993 Set <TopComponent> tcs = tcGroup.getTopComponents(); 994 for(Iterator <TopComponent> it = tcs.iterator(); it.hasNext(); ) { 995 TopComponent tc = it.next(); 996 if( tc.isOpened() ) { 997 openedBeforeTopComponents.add( tc ); 998 } 999 } 1000 1001 tcs = tcGroup.getOpeningSet(); 1002 HashSet <ModeImpl> openedModes = new HashSet <ModeImpl>( tcs.size() ); 1003 List <TopComponent> openedTcs = new ArrayList <TopComponent>(); 1004 for(Iterator <TopComponent> it = tcs.iterator(); it.hasNext(); ) { 1005 TopComponent tc = it.next(); 1006 if(!tc.isOpened()) { 1007 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 1008 ModeImpl mode = (ModeImpl)wm.findMode(tc); 1009 if(mode == null) { 1010 mode = wm.getDefaultViewMode(); 1012 } else { 1013 if( mode.getOpenedTopComponentsIDs().isEmpty() ) { 1014 openedModes.add( mode ); 1015 } 1016 } 1017 model.addModeOpenedTopComponent(mode, tc); 1018 1019 if( isEditorMaximized() && mode.getState() != Constants.MODE_STATE_SEPARATED ) { 1020 String tcID = wm.findTopComponentID( tc ); 1021 if( !isTopComponentDockedInMaximizedMode( tcID ) && mode.getKind() != Constants.MODE_KIND_SLIDING ) { 1022 slide( tc, mode, getSlideSideForMode( mode ) ); 1024 } 1025 } 1026 openedTcs.add(tc); 1027 } 1028 } 1029 1030 1031 model.openGroup(tcGroup, new HashSet <TopComponent>(openedTcs), openedBeforeTopComponents); 1032 1033 for( ModeImpl mode : openedModes ) { 1035 TopComponent prevSelTC = mode.getPreviousSelectedTopComponent(); 1036 if( null != prevSelTC ) 1037 mode.setSelectedTopComponent( prevSelTC ); 1038 } 1039 1040 if(isVisible()) { 1041 viewRequestor.scheduleRequest(new ViewRequest(tcGroup, 1042 View.CHANGE_TOPCOMPONENT_ARRAY_ADDED, null, 1043 openedTcs.toArray(new TopComponent[0]))); 1044 } 1045 1046 for(TopComponent tc: openedTcs) { 1048 WindowManagerImpl.getInstance().notifyTopComponentOpened(tc); 1049 } 1050 } 1051 1052 1053 public void closeGroup(TopComponentGroupImpl tcGroup) { 1054 if(!isGroupOpened(tcGroup)) { 1055 return; 1056 } 1057 1058 Set tcs = tcGroup.getClosingSet(); 1059 List <TopComponent> closedTcs = new ArrayList <TopComponent>(); 1060 1061 Set <TopComponent> openedTcsByGroup = model.getGroupOpenedTopComponents(tcGroup); 1062 1063 Set <TopComponent> openedTcsBefore = model.getGroupOpenedBeforeTopComponents(tcGroup); 1065 1066 for(Iterator <TopComponent> it = model.getGroupTopComponents(tcGroup).iterator(); it.hasNext(); ) { 1068 TopComponent tc = it.next(); 1069 boolean wasOpenedBefore = openedTcsBefore.contains(tc); 1070 boolean openedByGroup = openedTcsByGroup.contains(tc); 1071 1072 if(tc.isOpened()) { 1073 if(!wasOpenedBefore && !openedByGroup) { 1074 model.addGroupOpeningTopComponent(tcGroup, tc); 1076 } 1077 } else { 1078 if(wasOpenedBefore || openedByGroup) { 1079 model.removeGroupOpeningTopComponent(tcGroup, tc); 1081 } 1082 } 1083 } 1084 1085 ArrayList <ModeImpl> groupModes = new ArrayList <ModeImpl>( tcs.size() ); 1086 for(Iterator it = tcs.iterator(); it.hasNext(); ) { 1088 TopComponent tc = (TopComponent)it.next(); 1089 if( !tc.isOpened() || openedTcsBefore.contains(tc)) { 1090 continue; 1091 } 1092 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc); 1093 if( null != mode ) 1094 groupModes.add( mode ); 1095 } 1096 for( ModeImpl mode : groupModes ) { 1097 TopComponent selTC = mode.getSelectedTopComponent(); 1098 if( null != selTC ) 1099 setModePreviousSelectedTopComponent( mode, selTC ); 1100 } 1101 1102 for(Iterator it = tcs.iterator(); it.hasNext(); ) { 1104 TopComponent tc = (TopComponent)it.next(); 1105 if(tc.isOpened()) { 1106 if(openedTcsBefore.contains(tc)) { 1108 continue; 1109 } 1110 1111 boolean ignore = false; 1112 for(Iterator it2 = model.getTopComponentGroups().iterator(); it2.hasNext(); ) { 1113 TopComponentGroupImpl group = (TopComponentGroupImpl)it2.next(); 1114 if(group == tcGroup) { 1115 continue; 1116 } 1117 if(group.isOpened() && group.getOpeningSet().contains(tc)) { 1118 ignore = true; 1119 break; 1120 } 1121 } 1122 if(ignore) { 1123 continue; 1124 } 1125 1126 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(tc); 1128 if(mode != null) { 1129 if(WindowManagerImpl.getInstance().isTopComponentPersistentWhenClosed(tc)) { 1130 model.addModeClosedTopComponent(mode, tc); 1131 } else { 1132 model.removeModeTopComponent(mode, tc); 1133 String id = WindowManagerImpl.getInstance().findTopComponentID(tc); 1134 PersistenceManager.getDefault().removeGlobalTopComponentID(id); 1135 } 1136 closedTcs.add(tc); 1137 } 1138 } 1139 } 1140 1141 model.closeGroup(tcGroup); 1142 1143 if(isVisible()) { 1144 viewRequestor.scheduleRequest(new ViewRequest(tcGroup, 1145 View.CHANGE_TOPCOMPONENT_ARRAY_REMOVED, null, 1146 closedTcs.toArray(new TopComponent[0]))); 1147 } 1148 1149 for(TopComponent tc: closedTcs) { 1151 WindowManagerImpl.getInstance().notifyTopComponentClosed(tc); 1152 } 1153 } 1154 1155 1156 public void addTopComponentGroup(TopComponentGroupImpl tcGroup) { 1157 model.addTopComponentGroup(tcGroup); 1158 } 1159 1160 1161 public void removeTopComponentGroup(TopComponentGroupImpl tcGroup) { 1162 model.removeTopComponentGroup(tcGroup); 1163 } 1164 1165 public boolean addGroupUnloadedTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1166 return model.addGroupUnloadedTopComponent(tcGroup, tcID); 1167 } 1168 1169 public boolean removeGroupUnloadedTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1170 return model.removeGroupUnloadedTopComponent(tcGroup, tcID); 1171 } 1172 1173 1174 public boolean addGroupUnloadedOpeningTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1175 return model.addGroupUnloadedOpeningTopComponent(tcGroup, tcID); 1176 } 1177 1178 1179 public boolean removeGroupUnloadedOpeningTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1180 return model.removeGroupUnloadedOpeningTopComponent(tcGroup, tcID); 1181 } 1182 1183 1184 public boolean addGroupUnloadedClosingTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1185 return model.addGroupUnloadedClosingTopComponent(tcGroup, tcID); 1186 } 1187 1188 1189 public boolean removeGroupUnloadedClosingTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1190 return model.removeGroupUnloadedClosingTopComponent(tcGroup, tcID); 1191 } 1192 1193 public boolean addGroupUnloadedOpenedTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1195 if(!isGroupOpened(tcGroup)) { 1196 return false; 1197 } 1198 1199 return model.addGroupUnloadedOpenedTopComponent(tcGroup, tcID); 1200 } 1201 1202 public Set getGroupOpenedTopComponents(TopComponentGroupImpl tcGroup) { 1204 return model.getGroupOpenedTopComponents(tcGroup); 1205 } 1206 1207 public Set <String > getGroupTopComponentsIDs(TopComponentGroupImpl tcGroup) { 1209 return model.getGroupTopComponentsIDs(tcGroup); 1210 } 1211 1212 public Set <String > getGroupOpeningSetIDs(TopComponentGroupImpl tcGroup) { 1213 return model.getGroupOpeningSetIDs(tcGroup); 1214 } 1215 1216 public Set <String > getGroupClosingSetIDs(TopComponentGroupImpl tcGroup) { 1217 return model.getGroupClosingSetIDs(tcGroup); 1218 } 1219 1220 public Set <String > getGroupOpenedTopComponentsIDs(TopComponentGroupImpl tcGroup) { 1221 return model.getGroupOpenedTopComponentsIDs(tcGroup); 1222 } 1223 1227 1230 1231 1234 1235 public boolean isVisible() { 1236 return model.isVisible(); 1237 } 1238 1239 1240 public Set <? extends Mode> getModes () { 1241 return model.getModes(); 1242 } 1243 1244 1245 public Rectangle getMainWindowBoundsJoined() { 1246 return model.getMainWindowBoundsJoined(); 1247 } 1248 1249 1250 public Rectangle getMainWindowBoundsSeparated() { 1251 return model.getMainWindowBoundsSeparated(); 1252 } 1253 1254 public int getMainWindowFrameStateJoined() { 1255 return model.getMainWindowFrameStateJoined(); 1256 } 1257 1258 public int getMainWindowFrameStateSeparated() { 1259 return model.getMainWindowFrameStateSeparated(); 1260 } 1261 1262 1263 public ModeImpl getActiveMode () { 1264 return model.getActiveMode(); 1265 } 1266 1267 1268 public Rectangle getEditorAreaBounds() { 1269 return model.getEditorAreaBounds(); 1270 } 1271 1272 1273 public SplitConstraint[] getEditorAreaConstraints() { 1274 return model.getEditorAreaConstraints(); 1275 } 1276 1277 1278 public int getEditorAreaState() { 1279 return model.getEditorAreaState(); 1280 } 1281 1282 public int getEditorAreaFrameState() { 1283 return model.getEditorAreaFrameState(); 1284 } 1285 1286 public Component getEditorAreaComponent() { 1287 return viewRequestor.getEditorAreaComponent(); 1288 } 1289 1290 1291 ModeImpl getCurrentMaximizedMode() { 1292 if( isViewMaximized() ) 1293 return model.getViewMaximizedMode(); 1294 if( isEditorMaximized() ) 1295 return model.getEditorMaximizedMode(); 1296 return null; 1297 } 1298 1299 1300 ModeImpl getEditorMaximizedMode() { 1301 return model.getEditorMaximizedMode(); 1302 } 1303 1304 1305 ModeImpl getViewMaximizedMode() { 1306 return model.getViewMaximizedMode(); 1307 } 1308 1309 1310 public SplitConstraint[] getModeConstraints(ModeImpl mode) { 1311 return model.getModeConstraints(mode); 1312 } 1313 1314 1315 1316 public String getToolbarConfigName () { 1317 return model.getToolbarConfigName(); 1318 } 1319 1320 1323 public String getModeName(ModeImpl mode) { 1324 return model.getModeName(mode); 1325 } 1326 1327 public Rectangle getModeBounds(ModeImpl mode) { 1328 return model.getModeBounds(mode); 1329 } 1330 1331 public int getModeState(ModeImpl mode) { 1332 return model.getModeState(mode); 1333 } 1334 1335 public int getModeKind(ModeImpl mode) { 1336 return model.getModeKind(mode); 1337 } 1338 1339 1340 public String getModeSide(ModeImpl mode) { 1341 return model.getModeSide(mode); 1342 } 1343 1344 1345 public int getModeFrameState(ModeImpl mode) { 1346 return model.getModeFrameState(mode); 1347 } 1348 1349 public boolean isModePermanent(ModeImpl mode) { 1350 return model.isModePermanent(mode); 1351 } 1352 public boolean isModeEmpty(ModeImpl mode) { 1353 return model.isModeEmpty(mode); 1354 } 1355 1356 public boolean containsModeTopComponent(ModeImpl mode, TopComponent tc) { 1357 return model.containsModeTopComponent(mode, tc); 1358 } 1359 1360 public TopComponent getModeSelectedTopComponent(ModeImpl mode) { 1361 return model.getModeSelectedTopComponent(mode); 1362 } 1363 1366 public TopComponent getModePreviousSelectedTopComponent(ModeImpl mode) { 1367 return model.getModePreviousSelectedTopComponent( mode ); 1368 } 1369 1370 public List <TopComponent> getModeTopComponents(ModeImpl mode) { 1371 return model.getModeTopComponents(mode); 1372 } 1373 1374 public List <TopComponent> getModeOpenedTopComponents(ModeImpl mode) { 1375 return model.getModeOpenedTopComponents(mode); 1376 } 1377 1380 public Set <TopComponentGroupImpl> getTopComponentGroups() { 1383 return model.getTopComponentGroups(); 1384 } 1385 1386 public String getGroupName(TopComponentGroupImpl tcGroup) { 1387 return model.getGroupName(tcGroup); 1388 } 1389 1390 public Set <TopComponent> getGroupTopComponents(TopComponentGroupImpl tcGroup) { 1391 return model.getGroupTopComponents(tcGroup); 1392 } 1393 1394 1395 public Set <TopComponent> getGroupOpeningTopComponents(TopComponentGroupImpl tcGroup) { 1396 return model.getGroupOpeningTopComponents(tcGroup); 1397 } 1398 1399 1400 public Set getGroupClosingTopComponents(TopComponentGroupImpl tcGroup) { 1401 return model.getGroupClosingTopComponents(tcGroup); 1402 } 1403 1406 1409 1410 public void topComponentDisplayNameChanged(ModeImpl mode, TopComponent tc) { 1413 if(isVisible()) { 1414 viewRequestor.scheduleRequest(new ViewRequest( 1415 mode, View.CHANGE_TOPCOMPONENT_DISPLAY_NAME_CHANGED, null, tc)); 1416 } 1417 } 1418 1419 public void topComponentDisplayNameAnnotation(ModeImpl mode, TopComponent tc) { 1420 if(isVisible()) { 1421 viewRequestor.scheduleRequest(new ViewRequest( 1422 mode, View.CHANGE_TOPCOMPONENT_DISPLAY_NAME_ANNOTATION_CHANGED, null, tc)); 1423 } 1424 } 1425 1427 public void topComponentToolTipChanged(ModeImpl mode, TopComponent tc) { 1428 if(isVisible()) { 1429 viewRequestor.scheduleRequest(new ViewRequest( 1430 mode, View.CHANGE_TOPCOMPONENT_TOOLTIP_CHANGED, null, tc)); 1431 } 1432 } 1433 1434 public void topComponentIconChanged(ModeImpl mode, TopComponent tc) { 1435 if(isVisible()) { 1436 viewRequestor.scheduleRequest(new ViewRequest( 1437 mode, View.CHANGE_TOPCOMPONENT_ICON_CHANGED, null, tc)); 1438 } 1439 } 1440 1441 public void resetModel() { 1442 model.reset(); 1443 } 1444 1445 1447 1448 public void attachTopComponentsToSide(TopComponent[] tcs, ModeImpl attachMode, String side) { 1450 attachTopComponentsToSide(tcs, attachMode, side, true); 1451 } 1452 1453 1454 private void attachTopComponentsToSide(TopComponent[] tcs, ModeImpl attachMode, String side, boolean fireEvents) { 1455 if(tcs == null || tcs.length == 0) { 1456 return; 1457 } 1458 1459 ModeImpl newMode = WindowManagerImpl.getInstance().createModeImpl( 1461 ModeImpl.getUnusedModeName(), attachMode.getKind(), false); 1462 1463 if(!newMode.canContain(tcs[0])) { 1465 return; 1466 } 1467 model.addModeToSide(newMode, attachMode, side); 1468 1469 attachTopComponentsHelper(tcs, newMode, fireEvents); 1470 } 1471 1472 1473 private void attachTopComponentsAroundDesktop(TopComponent[] tcs, String side, boolean fireEvents) { 1474 if(tcs == null || tcs.length == 0) { 1475 return; 1476 } 1477 1478 ModeImpl newMode = WindowManagerImpl.getInstance().createModeImpl( 1480 ModeImpl.getUnusedModeName(), Constants.MODE_KIND_VIEW, false); 1481 1482 if(!newMode.canContain(tcs[0])) { 1484 return; 1485 } 1486 model.addModeAround(newMode, side); 1487 1488 attachTopComponentsHelper(tcs, newMode, fireEvents); 1489 } 1490 1491 1492 private void attachTopComponentsAroundEditor(TopComponent[] tcs, String side, boolean fireEvents, int modeKind) { 1493 if(tcs == null || tcs.length == 0) { 1494 return; 1495 } 1496 1497 ModeImpl newMode = WindowManagerImpl.getInstance().createModeImpl( 1499 ModeImpl.getUnusedModeName(), modeKind, false); 1500 1501 if(!newMode.canContain(tcs[0])) { 1503 return; 1504 } 1505 model.addModeAroundEditor(newMode, side); 1506 1507 attachTopComponentsHelper(tcs, newMode, fireEvents); 1508 } 1509 1510 private void attachTopComponentsIntoNewMode(TopComponent[] tcs, Rectangle bounds, int modeKind, int modeState) { 1511 if(tcs == null || tcs.length == 0) { 1512 return; 1513 } 1514 1515 WindowManagerImpl wmi = WindowManagerImpl.getInstance(); 1516 ModeImpl newMode = wmi.createModeImpl( 1518 ModeImpl.getUnusedModeName(), modeKind, modeState, false); 1519 newMode.setBounds(bounds); 1520 1521 if(!newMode.canContain(tcs[0])) { 1523 return; 1524 } 1525 1526 model.addMode(newMode, new SplitConstraint[] {new SplitConstraint(Constants.HORIZONTAL, 100, 0.5f)}); 1527 1528 if (modeState == Constants.MODE_STATE_SEPARATED) { 1529 ModeImpl prevMode; 1532 String tcID; 1533 int prevIndex; 1534 for (int i = 0; i < tcs.length; i++) { 1535 prevMode = (ModeImpl) wmi.findMode(tcs[i]); 1536 tcID = wmi.findTopComponentID(tcs[i]); 1537 if (prevMode.getState() == Constants.MODE_STATE_SEPARATED) { 1538 prevMode = model.getModeTopComponentPreviousMode(prevMode, tcID); 1539 } 1540 prevIndex = prevMode.getOpenedTopComponentsIDs().indexOf( tcID ); 1541 if (prevMode != null) { 1542 model.setModeTopComponentPreviousMode(newMode, tcID, prevMode, prevIndex); 1543 model.setModeTopComponentPreviousConstraints(newMode, wmi.findTopComponentID(tcs[i]), prevMode.getConstraints()); 1544 } 1545 } 1546 } 1547 1548 attachTopComponentsHelper(tcs, newMode, true); 1549 } 1550 1551 1552 private void attachTopComponentsHelper(TopComponent[] tcs, ModeImpl newMode, boolean fireEvents) { 1553 for(int i = 0; i < tcs.length; i++) { 1554 TopComponent tc = tcs[i]; 1555 removeTopComponentFromOtherModes(newMode, tc); 1556 model.addModeOpenedTopComponent(newMode, tc); 1557 } 1558 1559 ModeImpl oldActiveMode = getActiveMode(); 1560 1561 model.setActiveMode(newMode); 1562 model.setModeSelectedTopComponent(newMode, tcs[0]); 1563 1564 if(isVisible()) { 1565 viewRequestor.scheduleRequest(new ViewRequest(tcs[0], 1566 View.CHANGE_TOPCOMPONENT_ATTACHED, null, newMode)); 1567 } 1568 1569 if(!fireEvents) { 1570 return; 1571 } 1572 1573 1574 WindowManagerImpl.notifyRegistryTopComponentActivated(tcs[0]); 1576 1577 WindowManagerImpl.getInstance().doFirePropertyChange( 1578 WindowManager.PROP_MODES, null, null); 1579 1580 if(oldActiveMode != newMode) { 1581 WindowManagerImpl.getInstance().doFirePropertyChange( 1582 WindowManagerImpl.PROP_ACTIVE_MODE, oldActiveMode, newMode); 1583 } 1584 1585 1586 } 1587 1588 1589 public void activateModeTopComponent(ModeImpl mode, TopComponent tc) { 1590 if(!getModeOpenedTopComponents(mode).contains(tc)) { 1591 return; 1592 } 1593 1594 ModeImpl oldActiveMode = getActiveMode(); 1595 if (oldActiveMode != null && oldActiveMode.equals(mode)) { 1598 if (tc != null && tc.equals(model.getModeSelectedTopComponent(mode))) { 1599 return; 1600 } 1601 } 1602 model.setActiveMode(mode); 1603 model.setModeSelectedTopComponent(mode, tc); 1604 1605 if(isVisible()) { 1606 viewRequestor.scheduleRequest(new ViewRequest(mode, 1607 View.CHANGE_TOPCOMPONENT_ACTIVATED, null, tc)); 1608 } 1609 1610 WindowManagerImpl.notifyRegistryTopComponentActivated(tc); 1612 1613 if(oldActiveMode != mode) { 1614 WindowManagerImpl.getInstance().doFirePropertyChange( 1615 WindowManagerImpl.PROP_ACTIVE_MODE, oldActiveMode, mode); 1616 } 1617 } 1618 1620 1621 public boolean isDragInProgress() { 1623 return viewRequestor.isDragInProgress(); 1625 } 1626 1627 public Frame getMainWindow() { 1628 return viewRequestor.getMainWindow(); 1630 } 1631 1632 public String guessSlideSide(TopComponent tc) { 1633 return viewRequestor.guessSlideSide(tc); 1634 } 1635 1636 1643 String getSlideSideForMode(ModeImpl mode) { 1644 return model.getSlideSideForMode( mode ); 1645 } 1646 1647 1654 public boolean isDocked (TopComponent comp) { 1655 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode(comp); 1656 return mode != null && mode.getState() == Constants.MODE_STATE_JOINED; 1657 } 1658 1659 1660 1662 1664 public void createModeModel(ModeImpl mode, String name, int state, int kind, boolean permanent) { 1665 model.createModeModel(mode, name, state, kind, permanent); 1666 } 1667 1668 1669 1670 public void createGroupModel(TopComponentGroupImpl tcGroup, String name, boolean opened) { 1671 model.createGroupModel(tcGroup, name, opened); 1672 } 1673 1674 1676 public WindowSystemSnapshot createWindowSystemSnapshot() { 1677 return model.createWindowSystemSnapshot(); 1678 } 1679 1680 1681 public void userActivatedMode(ModeImpl mode) { 1684 if(mode != null) { 1685 setActiveMode(mode); 1686 } 1687 } 1688 1689 public void userActivatedModeWindow(ModeImpl mode) { 1690 if(mode != null) { 1691 setActiveMode(mode); 1692 } 1693 } 1694 1695 public void userActivatedEditorWindow() { 1696 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 1697 TopComponent[] tcs = wm.getRecentViewList(); 1698 for(int i = 0; i < tcs.length; i++) { 1699 TopComponent tc = tcs[i]; 1700 ModeImpl mode = (ModeImpl)wm.findMode(tc); 1701 if(mode != null 1702 && mode.getKind() == Constants.MODE_KIND_EDITOR 1703 && !mode.getOpenedTopComponents().isEmpty()) { 1704 setActiveMode(mode); 1705 return; 1706 } 1707 } 1708 1709 ModeImpl mode = wm.getDefaultEditorMode(); 1710 if(mode != null && !mode.getOpenedTopComponents().isEmpty()) { 1711 setActiveMode(mode); 1712 } else { 1713 setActiveMode(null); 1717 } 1718 } 1719 1720 public void userActivatedTopComponent(ModeImpl mode, TopComponent selected) { 1721 if(mode != null) { 1722 setModeSelectedTopComponent(mode, selected); 1723 } 1724 } 1725 1726 public void userResizedMainWindow(Rectangle bounds) { 1727 if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 1728 model.setMainWindowBoundsJoined(bounds); 1729 } else { 1730 model.setMainWindowBoundsSeparated(bounds); 1731 } 1732 } 1733 1734 public void userResizedMainWindowBoundsSeparatedHelp(Rectangle bounds) { 1735 if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED 1736 && getMainWindowBoundsSeparated().isEmpty()) { 1737 model.setMainWindowBoundsUserSeparatedHelp(bounds); 1738 } 1739 } 1740 1741 public void userResizedEditorArea(Rectangle bounds) { 1742 model.setEditorAreaBounds(bounds); 1743 } 1744 1745 public void userResizedEditorAreaBoundsHelp(Rectangle bounds) { 1746 if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED 1747 && getEditorAreaBounds().isEmpty()) { 1748 model.setEditorAreaBoundsUserHelp(bounds); 1749 } 1750 } 1751 1752 public void userResizedModeBounds(ModeImpl mode, Rectangle bounds) { 1753 Rectangle old = model.getModeBounds(mode); 1754 model.setModeBounds(mode, bounds); 1755 1756 mode.doFirePropertyChange(ModeImpl.PROP_BOUNDS, old, bounds); 1757 } 1758 1759 public void userResizedModeBoundsSeparatedHelp(ModeImpl mode, Rectangle bounds) { 1760 model.setModeBoundsSeparatedHelp(mode, bounds); 1761 } 1762 1763 public void userChangedFrameStateMainWindow(int frameState) { 1764 if(getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 1765 model.setMainWindowFrameStateJoined(frameState); 1766 } else { 1767 model.setMainWindowFrameStateSeparated(frameState); 1768 } 1769 } 1770 1771 public void userChangedFrameStateEditorArea(int frameState) { 1772 model.setEditorAreaFrameState(frameState); 1773 } 1774 1775 public void userChangedFrameStateMode(ModeImpl mode, int frameState) { 1776 model.setModeFrameState(mode, frameState); 1777 } 1778 1779 public void userChangedSplit( ModelElement[] snapshots, double[] splitWeights ) { 1780 model.setSplitWeights( snapshots, splitWeights ); 1781 } 1782 1783 public void userClosedTopComponent(ModeImpl mode, TopComponent tc) { 1784 if(WindowManagerImpl.getInstance().isTopComponentPersistentWhenClosed(tc)) { 1786 addModeClosedTopComponent(mode, tc); 1787 } else { 1788 removeModeTopComponent(mode, tc); 1789 } 1790 1791 if(mode.getOpenedTopComponents().isEmpty() 1793 && mode == getCurrentMaximizedMode()) { 1794 switchMaximizedMode(null); 1795 } 1796 } 1797 1798 public void userClosedMode(ModeImpl mode) { 1799 if(mode != null) { 1800 closeMode(mode); 1801 if(mode.getOpenedTopComponents().isEmpty() 1803 && mode == getCurrentMaximizedMode()) 1804 { 1805 switchMaximizedMode(null); 1806 } 1807 } 1808 1809 } 1810 1811 1812 public void userDroppedTopComponents(ModeImpl mode, TopComponent[] tcs) { 1814 updateViewAfterDnD(moveTopComponentsIntoMode(mode, tcs)); 1815 } 1816 1817 public void userDroppedTopComponents(ModeImpl mode, TopComponent[] tcs, int index) { 1818 updateViewAfterDnD(moveTopComponentsIntoMode(mode, tcs, index)); 1819 } 1820 1821 public void userDroppedTopComponents(ModeImpl mode, TopComponent[] tcs, String side) { 1822 attachTopComponentsToSide(tcs, mode, side, false); 1823 1824 updateViewAfterDnD(true); 1825 } 1826 1827 public void userDroppedTopComponentsIntoEmptyEditor(TopComponent[] tcs) { 1828 ModeImpl mode = (ModeImpl)WindowManagerImpl.getInstance().findMode("editor"); moveTopComponentsIntoMode(mode, tcs); 1831 updateViewAfterDnD(true); 1832 } 1833 1834 public void userDroppedTopComponentsAround(TopComponent[] tcs, String side) { 1835 attachTopComponentsAroundDesktop(tcs, side, false); 1836 1837 updateViewAfterDnD(true); 1838 } 1839 1840 public void userDroppedTopComponentsAroundEditor(TopComponent[] tcs, String side, int modeKind) { 1841 attachTopComponentsAroundEditor(tcs, side, false, modeKind); 1842 1843 updateViewAfterDnD(true); 1844 } 1845 1846 public void userDroppedTopComponentsIntoFreeArea(TopComponent[] tcs, Rectangle bounds, int modeKind) { 1847 attachTopComponentsIntoNewMode(tcs, bounds, modeKind, Constants.MODE_STATE_SEPARATED); 1848 updateViewAfterDnD(true); 1849 } 1850 1851 public void userUndockedTopComponent(TopComponent tc, int modeKind) { 1852 Point tcLoc = tc.getLocation(); 1853 Dimension tcSize = tc.getSize(); 1854 SwingUtilities.convertPointToScreen(tcLoc, tc); 1855 Rectangle bounds = new Rectangle (tcLoc, tcSize); 1856 if (modeKind == Constants.MODE_KIND_SLIDING) { 1858 modeKind = Constants.MODE_KIND_VIEW; 1859 } 1860 attachTopComponentsIntoNewMode(new TopComponent[] { tc }, bounds, modeKind, Constants.MODE_STATE_SEPARATED); 1861 updateViewAfterDnD(true); 1862 } 1863 1864 public void userDockedTopComponent(TopComponent tc, int modeKind) { 1865 ModeImpl dockTo = null; 1866 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tc); 1868 ModeImpl source = (ModeImpl) WindowManagerImpl.getInstance().findMode(tc); 1869 dockTo = model.getModeTopComponentPreviousMode(source, tcID); 1870 int dockIndex = model.getModeTopComponentPreviousIndex(source, tcID); 1871 if ((dockTo == null) || !model.getModes().contains(dockTo)) { 1872 SplitConstraint[] constraints = model.getModeTopComponentPreviousConstraints(source, tcID); 1874 if (constraints != null) { 1875 dockTo = WindowManagerImpl.getInstance().createModeImpl( 1877 ModeImpl.getUnusedModeName(), modeKind, false); 1878 model.addMode(dockTo, constraints); 1879 } 1880 } 1881 if (dockTo == null) { 1882 dockTo = modeKind == Constants.MODE_KIND_EDITOR 1884 ? WindowManagerImpl.getInstance().getDefaultEditorMode() 1885 : WindowManagerImpl.getInstance().getDefaultViewMode(); 1886 } 1887 1888 updateViewAfterDnD(moveTopComponentsIntoMode(dockTo, new TopComponent[] { tc }, dockIndex)); 1889 } 1890 1891 private boolean moveTopComponentsIntoMode(ModeImpl mode, TopComponent[] tcs) { 1892 return moveTopComponentsIntoMode(mode, tcs, -1); 1893 } 1894 1895 private boolean moveTopComponentsIntoMode(ModeImpl mode, TopComponent[] tcs, int index) { 1896 boolean moved = false; 1897 boolean intoSliding = mode.getKind() == Constants.MODE_KIND_SLIDING; 1898 boolean intoSeparate = mode.getState() == Constants.MODE_STATE_SEPARATED; 1899 ModeImpl prevMode = null; 1900 for(int i = 0; i < tcs.length; i++) { 1901 TopComponent tc = tcs[i]; 1902 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tc); 1903 if(!mode.canContain(tc)) { 1905 continue; 1906 } 1907 for(Iterator it = model.getModes().iterator(); it.hasNext(); ) { 1908 ModeImpl m = (ModeImpl)it.next(); 1909 if(model.containsModeTopComponent(m, tc)) { 1910 if (m.getKind() == Constants.MODE_KIND_SLIDING || 1911 m.getState() == Constants.MODE_STATE_SEPARATED) { 1912 prevMode = model.getModeTopComponentPreviousMode(m, tcID); 1913 } else { 1914 prevMode = m; 1915 } 1916 break; 1917 } 1918 } 1919 int prevIndex = prevMode != null && (intoSliding || intoSeparate) ? prevMode.getOpenedTopComponentsIDs().indexOf( tcID ) : -1; 1920 if(removeTopComponentFromOtherModes(mode, tc)) { 1921 moved = true; 1922 } 1923 if (index > -1) { 1924 model.insertModeOpenedTopComponent(mode, tc, index); 1925 } else { 1926 model.addModeOpenedTopComponent(mode, tc); 1927 } 1928 if (prevMode != null && (intoSliding || intoSeparate)) { 1929 model.setModeTopComponentPreviousMode(mode, tcID, prevMode, prevIndex); 1931 model.setModeTopComponentPreviousConstraints(mode, tcID, model.getModeConstraints(prevMode)); 1932 } 1933 } 1934 if (!intoSliding) { 1935 model.setActiveMode(mode); 1937 model.setModeSelectedTopComponent(mode, tcs[tcs.length - 1]); 1938 } else { 1939 if(prevMode != null && prevMode == getActiveMode() 1942 && prevMode.getOpenedTopComponents().isEmpty()) { 1943 setSomeModeActive(); 1944 } 1945 if (mode.getBounds().width == 0 && mode.getBounds().height == 0) { 1948 mode.setBounds(tcs[tcs.length - 1].getBounds()); 1950 } 1951 } 1952 return moved; 1953 } 1954 1955 1956 private void updateViewAfterDnD(boolean unmaximize) { 1957 if( unmaximize ) { 1958 switchMaximizedMode(null); 1959 } 1960 1961 if(isVisible()) { 1962 viewRequestor.scheduleRequest( 1963 new ViewRequest(null, View.CHANGE_DND_PERFORMED, null, null)); 1964 } 1965 } 1966 1967 1968 1970 1971 public void addSlidingMode(ModeImpl mode, ModeImpl original, String side, Map <String ,Integer > slideInSizes) { 1972 ModeImpl targetMode = model.getSlidingMode(side); 1973 if (targetMode != null) { 1974 return; 1976 } 1977 targetMode = WindowManagerImpl.getInstance().createModeImpl( 1978 ModeImpl.getUnusedModeName(), Constants.MODE_KIND_SLIDING, false); 1979 1980 model.addSlidingMode(mode, side, slideInSizes); 1981 1982 if(isVisible()) { 1983 viewRequestor.scheduleRequest( 1984 new ViewRequest(null, View.CHANGE_MODE_ADDED, null, mode)); 1985 } 1986 1987 WindowManagerImpl.getInstance().doFirePropertyChange( 1988 WindowManager.PROP_MODES, null, null); 1989 } 1990 1991 public void userEnabledAutoHide(TopComponent tc, ModeImpl source, String targetSide) { 1992 1993 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tc); 1994 if( isEditorMaximized() ) 1995 setTopComponentDockedInMaximizedMode( tcID, false ); 1996 1997 slide( tc, source, targetSide ); 1998 } 1999 2000 2003 void slide(TopComponent tc, ModeImpl source, String targetSide) { 2004 ModeImpl targetMode = model.getSlidingMode(targetSide); 2005 if (targetMode == null) { 2006 targetMode = WindowManagerImpl.getInstance().createModeImpl( 2007 ModeImpl.getUnusedModeName(), Constants.MODE_KIND_SLIDING, false); 2008 model.addSlidingMode(targetMode, targetSide, null); 2009 model.setModeBounds(targetMode, new Rectangle (tc.getBounds())); 2010 } 2011 2012 ModeImpl oldActive = getActiveMode(); 2013 moveTopComponentsIntoMode(targetMode, new TopComponent[] {tc}); 2014 ModeImpl newActive = getActiveMode(); 2015 2016 if(isVisible()) { 2017 viewRequestor.scheduleRequest( 2018 new ViewRequest(null, View.CHANGE_TOPCOMPONENT_AUTO_HIDE_ENABLED, null, null)); 2019 } 2020 2021 if(oldActive != newActive) { 2022 WindowManagerImpl.getInstance().doFirePropertyChange( 2023 WindowManagerImpl.PROP_ACTIVE_MODE, oldActive, newActive); 2024 } 2025 2026 if(newActive != null) { 2028 WindowManagerImpl.notifyRegistryTopComponentActivated( 2030 newActive.getSelectedTopComponent()); 2031 } else { 2032 WindowManagerImpl.notifyRegistryTopComponentActivated(null); 2033 } 2034 } 2035 2036 public void userResizedSlidingMode(ModeImpl mode, Rectangle rect) { 2037 model.setModeBounds(mode, new Rectangle (rect)); 2038 String side = model.getSlidingModeConstraints( mode ); 2040 model.setSlideInSize( side, 2041 mode.getSelectedTopComponent(), 2042 Constants.BOTTOM.equals( side ) ? rect.height : rect.width ); 2043 if( null != mode.getSelectedTopComponent() ) { 2044 String tcID = WindowManagerImpl.getInstance().findTopComponentID( mode.getSelectedTopComponent() ); 2045 model.setTopComponentMaximizedWhenSlidedIn( tcID, false ); 2046 } 2047 } 2048 2049 2050 public void userDisabledAutoHide(TopComponent tc, ModeImpl source) { 2051 if( isViewMaximized() ) { 2053 switchMaximizedMode(null); 2054 } 2055 2056 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tc); 2057 if( isEditorMaximized() ) 2058 setTopComponentDockedInMaximizedMode( tcID, true ); 2059 2060 unSlide( tc, source ); 2061 } 2062 2063 2066 private void unSlide(TopComponent tc, ModeImpl source) { 2067 String tcID = WindowManagerImpl.getInstance().findTopComponentID(tc); 2068 2069 ModeImpl targetMode = model.getModeTopComponentPreviousMode(source, tcID); 2070 int targetIndex = model.getModeTopComponentPreviousIndex(source, tcID); 2071 2072 if ((targetMode == null) || !model.getModes().contains(targetMode)) { 2073 SplitConstraint[] constraints = model.getModeTopComponentPreviousConstraints(source, tcID); 2075 if (constraints != null) { 2076 targetMode = WindowManagerImpl.getInstance().createModeImpl( 2078 ModeImpl.getUnusedModeName(), source.getKind(), false); 2079 model.addMode(targetMode, constraints); 2080 } 2081 } 2082 2083 if (targetMode == null) { 2084 targetMode = source.getKind() == Constants.MODE_KIND_EDITOR 2086 ? WindowManagerImpl.getInstance().getDefaultEditorMode() 2087 : WindowManagerImpl.getInstance().getDefaultViewMode(); 2088 } 2089 2090 moveTopComponentsIntoMode(targetMode, new TopComponent[] { tc }, targetIndex); 2091 2092 if (source.isEmpty()) { 2093 model.removeMode(source); 2094 } 2095 2096 if(isVisible()) { 2097 viewRequestor.scheduleRequest( 2098 new ViewRequest(null, View.CHANGE_TOPCOMPONENT_AUTO_HIDE_DISABLED, null, null)); 2099 } 2100 WindowManagerImpl.getInstance().doFirePropertyChange( 2101 WindowManagerImpl.PROP_ACTIVE_MODE, null, getActiveMode()); 2102 } 2103 2104 2105 2108 public ModeImpl getModeTopComponentPreviousMode(String tcID, ModeImpl currentSlidingMode) { 2109 return model.getModeTopComponentPreviousMode(currentSlidingMode, tcID); 2110 } 2111 2112 2115 public int getModeTopComponentPreviousIndex(String tcID, ModeImpl currentSlidingMode) { 2116 return model.getModeTopComponentPreviousIndex(currentSlidingMode, tcID); 2117 } 2118 2119 2127 public void setModeTopComponentPreviousMode(String tcID, ModeImpl currentSlidingMode, ModeImpl prevMode, int prevIndex) { 2128 model.setModeTopComponentPreviousMode(currentSlidingMode, tcID, prevMode, prevIndex); 2129 } 2130 2131 Map <String ,Integer > getSlideInSizes( String side ) { 2132 return model.getSlideInSizes( side ); 2133 } 2134 2135 2142 void setTopComponentDockedInMaximizedMode( String tcID, boolean docked ) { 2143 if( docked ) 2144 model.getMaximizedDockingStatus().addDocked( tcID ); 2145 else 2146 model.getMaximizedDockingStatus().addSlided( tcID ); 2147 } 2148 2149 2156 boolean isTopComponentDockedInMaximizedMode( String tcID ) { 2157 return model.getMaximizedDockingStatus().isDocked( tcID ); 2158 } 2159 2160 2167 void setTopComponentSlidedInDefaultMode( String tcID, boolean slided ) { 2168 if( slided ) 2169 model.getDefaultDockingStatus().addSlided( tcID ); 2170 else 2171 model.getDefaultDockingStatus().addDocked( tcID ); 2172 } 2173 2174 2180 boolean isTopComponentMaximizedWhenSlidedIn( String tcID ) { 2181 return model.isTopComponentMaximizedWhenSlidedIn( tcID ); 2182 } 2183 2184 2190 void setTopComponentMaximizedWhenSlidedIn( String tcID, boolean maximized ) { 2191 model.setTopComponentMaximizedWhenSlidedIn( tcID, maximized ); 2192 } 2193 2194 void userToggledTopComponentSlideInMaximize( String tcID ) { 2195 setTopComponentMaximizedWhenSlidedIn( tcID, !isTopComponentMaximizedWhenSlidedIn( tcID ) ); 2196 if( isVisible() ) { 2197 TopComponent tc = WindowManagerImpl.getInstance().findTopComponent( tcID ); 2198 ModeImpl mode = WindowManagerImpl.getInstance().findModeForOpenedID( tcID ); 2199 if( null != tc && null != mode && null != mode.getSide() ) { 2200 viewRequestor.scheduleRequest ( 2201 new ViewRequest(tc, View.CHANGE_MAXIMIZE_TOPCOMPONENT_SLIDE_IN, null, mode.getSide())); 2202 } 2203 } 2204 } 2205 2206 2213 boolean isTopComponentSlidedInDefaultMode( String tcID ) { 2214 return model.getDefaultDockingStatus().isSlided( tcID ); 2215 } 2216 2217 boolean isEditorMaximized() { 2218 return null != model.getEditorMaximizedMode(); 2219 } 2220 2221 boolean isViewMaximized() { 2222 return null != model.getViewMaximizedMode(); 2223 } 2224 2225 2228 private void restoreViews( DockingStatus viewStatus ) { 2229 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 2230 Set <? extends Mode> modes = getModes(); 2231 for( Iterator <? extends Mode> i=modes.iterator(); i.hasNext(); ) { 2232 ModeImpl modeImpl = (ModeImpl)i.next(); 2233 if( modeImpl.getState() == Constants.MODE_STATE_SEPARATED ) 2234 continue; 2235 2236 if( modeImpl.getKind() == Constants.MODE_KIND_VIEW ) { 2237 List <TopComponent> views = getModeOpenedTopComponents( modeImpl ); 2238 Collections.reverse( views ); 2239 for( Iterator <TopComponent> j=views.iterator(); j.hasNext(); ) { 2240 TopComponent tc = j.next(); 2241 String tcID = wm.findTopComponentID( tc ); 2242 if( viewStatus.shouldSlide( tcID ) ) { 2243 slide( tc, modeImpl, guessSlideSide( tc ) ); 2244 } 2245 } 2246 } else if( modeImpl.getKind() == Constants.MODE_KIND_SLIDING ) { 2247 List <TopComponent> views = getModeOpenedTopComponents( modeImpl ); 2248 Collections.reverse( views ); 2249 for( Iterator <TopComponent> j=views.iterator(); j.hasNext(); ) { 2250 TopComponent tc = j.next(); 2251 String tcID = wm.findTopComponentID( tc ); 2252 if( viewStatus.shouldDock( tcID ) ) { 2253 unSlide( tc, modeImpl ); 2254 } 2255 } 2256 } 2257 } 2258 2259 for( Iterator <? extends Mode> i=modes.iterator(); i.hasNext(); ) { 2261 ModeImpl modeImpl = (ModeImpl)i.next(); 2262 if( modeImpl.getState() == Constants.MODE_STATE_SEPARATED ) 2263 continue; 2264 2265 if( modeImpl.getKind() == Constants.MODE_KIND_VIEW ) { 2266 TopComponent prevActiveTc = modeImpl.getPreviousSelectedTopComponent(); 2268 if( null != prevActiveTc ) { 2269 setModeSelectedTopComponent( modeImpl, prevActiveTc ); 2270 } 2271 } 2272 } 2273 } 2274 2275 2278 private void slideAllViews() { 2279 Set <? extends Mode> modes = getModes(); 2280 for( Iterator <? extends Mode> i=modes.iterator(); i.hasNext(); ) { 2281 ModeImpl modeImpl = (ModeImpl)i.next(); 2282 if( modeImpl.getKind() == Constants.MODE_KIND_VIEW 2283 && modeImpl != getViewMaximizedMode() 2284 && modeImpl.getState() != Constants.MODE_STATE_SEPARATED ) { 2285 List <TopComponent> views = getModeOpenedTopComponents( modeImpl ); 2286 Collections.reverse( views ); 2287 for( Iterator <TopComponent> j=views.iterator(); j.hasNext(); ) { 2288 TopComponent tc = j.next(); 2289 slide( tc, modeImpl, guessSlideSide( tc ) ); 2290 } 2291 } 2292 } 2293 } 2294 2295 2298 private static void debugLog(String message) { 2299 Debug.log(Central.class, message); 2300 } 2301} 2302 | Popular Tags |