1 19 20 21 package org.netbeans.core.windows.model; 22 23 24 25 import java.awt.Frame ; 26 import java.awt.Rectangle ; 27 import java.lang.ref.Reference ; 28 import java.lang.ref.WeakReference ; 29 import java.util.Collection ; 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 java.util.WeakHashMap ; 37 import java.util.logging.Level ; 38 import java.util.logging.Logger ; 39 import org.netbeans.core.windows.Constants; 40 import org.netbeans.core.windows.ModeImpl; 41 import org.netbeans.core.windows.ModeStructureSnapshot; 42 import org.netbeans.core.windows.SplitConstraint; 43 import org.netbeans.core.windows.TopComponentGroupImpl; 44 import org.netbeans.core.windows.WindowSystemSnapshot; 45 import org.openide.windows.TopComponent; 46 47 48 52 final class DefaultModel implements Model { 53 54 55 private final Map <ModeImpl, ModeModel> mode2model = 56 new WeakHashMap <ModeImpl, ModeModel>(10); 57 58 private final Map <TopComponentGroupImpl, TopComponentGroupModel> group2model = 59 new WeakHashMap <TopComponentGroupImpl, TopComponentGroupModel>(10); 60 61 63 private boolean visible = false; 64 65 66 private final Rectangle mainWindowBoundsJoined = new Rectangle (); 67 68 private final Rectangle mainWindowBoundsSeparated = new Rectangle (); 69 70 private final Rectangle mainWindowBoundsSeparatedHelp = new Rectangle (); 71 72 73 private int mainWindowFrameStateJoined = Frame.NORMAL; 74 75 private int mainWindowFrameStateSeparated = Frame.NORMAL; 76 77 78 private int editorAreaState = Constants.EDITOR_AREA_JOINED; 79 80 private final Rectangle editorAreaBounds = new Rectangle (); 81 82 private final Rectangle editorAreaBoundsHelp = new Rectangle (); 83 84 private int editorAreaFrameState = Frame.NORMAL; 85 86 private String toolbarConfigName = "Standard"; 88 private DockingStatus maximizedDockingStatus = new DockingStatus( this ); 89 90 private DockingStatus defaultDockingStatus = new DefaultDockingStatus( this ); 91 92 private Set <String > slideInMaximizedTopComponents = new HashSet <String >( 3 ); 93 94 95 private ModesSubModel modesSubModel = new ModesSubModel(this); 96 97 98 private final Set <TopComponentGroupImpl> topComponentGroups = 99 new HashSet <TopComponentGroupImpl>(5); 100 101 103 private final Object LOCK_VISIBLE = new Object (); 104 105 private final Object LOCK_MAIN_WINDOW_BOUNDS_JOINED = new Object (); 106 107 private final Object LOCK_MAIN_WINDOW_BOUNDS_SEPARATED = new Object (); 108 109 private final Object LOCK_MAIN_WINDOW_BOUNDS_SEPARATED_HELP = new Object (); 110 111 private final Object LOCK_MAIN_WINDOW_FRAME_STATE_JOINED = new Object (); 112 113 private final Object LOCK_MAIN_WINDOW_FRAME_STATE_SEPARATED = new Object (); 114 115 private final Object LOCK_EDITOR_AREA_STATE = new Object (); 116 117 private final Object LOCK_EDITOR_AREA_FRAME_STATE = new Object (); 118 119 private final Object LOCK_EDITOR_AREA_BOUNDS = new Object (); 120 121 private final Object LOCK_EDITOR_AREA_BOUNDS_HELP = new Object (); 122 123 private final Object LOCK_TOOLBAR_CONFIG = new Object (); 124 125 private final Object LOCK_MODES = new Object (); 126 127 private final Object LOCK_TOPCOMPONENT_GROUPS = new Object (); 128 129 private final Object LOCK_PROJECT_NAME = new Object (); 130 131 132 public DefaultModel() { 133 } 134 135 136 140 public void setVisible(boolean visible) { 141 synchronized(LOCK_VISIBLE) { 142 this.visible = visible; 143 } 144 } 145 146 147 public void setMainWindowBoundsJoined(Rectangle mainWindowBoundsJoined) { 148 if(mainWindowBoundsJoined == null) { 149 return; 150 } 151 152 synchronized(LOCK_MAIN_WINDOW_BOUNDS_JOINED) { 153 this.mainWindowBoundsJoined.setBounds(mainWindowBoundsJoined); 154 } 155 } 156 157 158 public void setMainWindowBoundsSeparated(Rectangle mainWindowBoundsSeparated) { 159 if(mainWindowBoundsSeparated == null) { 160 return; 161 } 162 163 synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED) { 164 this.mainWindowBoundsSeparated.setBounds(mainWindowBoundsSeparated); 165 } 166 } 167 168 169 public void setMainWindowFrameStateJoined(int frameState) { 170 synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_JOINED) { 171 this.mainWindowFrameStateJoined = frameState; 172 } 173 } 174 175 176 public void setMainWindowFrameStateSeparated(int frameState) { 177 synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_SEPARATED) { 178 this.mainWindowFrameStateSeparated = frameState; 179 } 180 } 181 182 183 public void setEditorAreaBounds(Rectangle editorAreaBounds) { 184 if(editorAreaBounds == null) { 185 return; 186 } 187 188 synchronized(LOCK_EDITOR_AREA_BOUNDS) { 189 this.editorAreaBounds.setBounds(editorAreaBounds); 190 } 191 } 192 193 194 public void setEditorAreaState(int editorAreaState) { 195 synchronized(LOCK_EDITOR_AREA_STATE) { 196 this.editorAreaState = editorAreaState; 197 } 198 } 199 200 201 public void setEditorAreaFrameState(int frameState) { 202 synchronized(LOCK_EDITOR_AREA_FRAME_STATE) { 203 this.editorAreaFrameState = frameState; 204 } 205 } 206 207 208 public void setEditorAreaConstraints(SplitConstraint[] editorAreaConstraints) { 209 synchronized(LOCK_MODES) { 210 modesSubModel.setEditorAreaConstraints(editorAreaConstraints); 211 } 212 } 213 214 public void setModeConstraints(ModeImpl mode, SplitConstraint[] constraints) { 215 synchronized(LOCK_MODES) { 216 modesSubModel.removeMode(mode); 218 modesSubModel.addMode(mode, constraints); 219 } 220 } 221 222 223 224 public void addMode(ModeImpl mode, SplitConstraint[] constraints) { 225 synchronized(LOCK_MODES) { 226 modesSubModel.addMode(mode, constraints); 227 } 228 } 229 230 231 232 public void addModeToSide(ModeImpl mode, ModeImpl attachMode, String side) { 234 synchronized(LOCK_MODES) { 235 modesSubModel.addModeToSide(mode, attachMode, side); 236 } 237 } 238 239 public void addModeAround(ModeImpl mode, String side) { 241 synchronized(LOCK_MODES) { 242 modesSubModel.addModeAround(mode, side); 243 } 244 } 245 246 public void addModeAroundEditor(ModeImpl mode, String side) { 248 synchronized(LOCK_MODES) { 249 modesSubModel.addModeAroundEditor(mode, side); 250 } 251 } 252 253 public void addSlidingMode(ModeImpl mode, String side, Map <String ,Integer > slideInSizes) { 254 synchronized(LOCK_MODES) { 255 modesSubModel.addModeSliding(mode, side, slideInSizes); 256 } 257 } 258 259 260 261 public void removeMode(ModeImpl mode) { 262 synchronized(LOCK_MODES) { 263 modesSubModel.removeMode(mode); 264 } 265 } 266 267 268 private Reference <ModeImpl> lastActiveMode = null; 269 public void setActiveMode(ModeImpl activeMode) { 270 if (lastActiveMode != null && lastActiveMode.get() == activeMode) { 271 return; 272 } else { 273 lastActiveMode = new WeakReference <ModeImpl>(activeMode); 274 } 275 synchronized(LOCK_MODES) { 276 boolean success = modesSubModel.setActiveMode(activeMode); 277 if (success) { 278 updateSlidingSelections(activeMode); 279 } 280 } 281 } 282 283 284 public void setEditorMaximizedMode(ModeImpl maximizedMode) { 285 assert null == maximizedMode || maximizedMode.getKind() == Constants.MODE_KIND_EDITOR; 286 synchronized(LOCK_MODES) { 287 modesSubModel.setEditorMaximizedMode(maximizedMode); 288 } 289 } 290 291 292 public void setViewMaximizedMode(ModeImpl maximizedMode) { 293 assert null == maximizedMode || maximizedMode.getKind() == Constants.MODE_KIND_VIEW; 294 synchronized(LOCK_MODES) { 295 modesSubModel.setViewMaximizedMode(maximizedMode); 296 } 297 } 298 299 300 public void setToolbarConfigName(String toolbarConfigName) { 301 synchronized(LOCK_TOOLBAR_CONFIG) { 302 this.toolbarConfigName = toolbarConfigName; 303 } 304 } 305 306 307 public void addTopComponentGroup(TopComponentGroupImpl tcGroup) { 308 synchronized(LOCK_TOPCOMPONENT_GROUPS) { 309 topComponentGroups.add(tcGroup); 310 } 311 } 312 313 public void removeTopComponentGroup(TopComponentGroupImpl tcGroup) { 314 synchronized(LOCK_TOPCOMPONENT_GROUPS) { 315 topComponentGroups.remove(tcGroup); 316 } 317 } 318 319 public void reset() { 320 mode2model.clear(); 321 group2model.clear(); 322 mainWindowFrameStateJoined = Frame.NORMAL; 323 mainWindowFrameStateSeparated = Frame.NORMAL; 324 editorAreaState = Constants.EDITOR_AREA_JOINED; 325 editorAreaFrameState = Frame.NORMAL; 326 toolbarConfigName = "Standard"; modesSubModel = new ModesSubModel(this); 328 topComponentGroups.clear(); 329 maximizedDockingStatus.clear(); 330 defaultDockingStatus.clear(); 331 slideInMaximizedTopComponents.clear(); 332 } 333 334 338 342 public boolean isVisible() { 343 synchronized(LOCK_VISIBLE) { 344 return this.visible; 345 } 346 } 347 348 349 public Rectangle getMainWindowBoundsJoined() { 350 synchronized(LOCK_MAIN_WINDOW_BOUNDS_JOINED) { 351 return (Rectangle )mainWindowBoundsJoined.clone(); 352 } 353 } 354 355 356 public Rectangle getMainWindowBoundsSeparated() { 357 synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED) { 358 return (Rectangle )mainWindowBoundsSeparated.clone(); 359 } 360 } 361 362 public Rectangle getMainWindowBoundsSeparatedHelp() { 363 synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED_HELP) { 364 return (Rectangle )mainWindowBoundsSeparatedHelp.clone(); 365 } 366 } 367 368 369 public int getMainWindowFrameStateJoined() { 370 synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_JOINED) { 371 return mainWindowFrameStateJoined; 372 } 373 } 374 375 376 public int getMainWindowFrameStateSeparated() { 377 synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_SEPARATED) { 378 return mainWindowFrameStateSeparated; 379 } 380 } 381 382 383 public int getEditorAreaState() { 384 synchronized(LOCK_EDITOR_AREA_STATE) { 385 return this.editorAreaState; 386 } 387 } 388 389 390 public int getEditorAreaFrameState() { 391 synchronized(LOCK_EDITOR_AREA_FRAME_STATE) { 392 return this.editorAreaFrameState; 393 } 394 } 395 396 397 public Rectangle getEditorAreaBounds() { 398 synchronized(LOCK_EDITOR_AREA_BOUNDS) { 399 return (Rectangle )this.editorAreaBounds.clone(); 400 } 401 } 402 403 public Rectangle getEditorAreaBoundsHelp() { 404 synchronized(LOCK_EDITOR_AREA_BOUNDS_HELP) { 405 return (Rectangle )this.editorAreaBoundsHelp.clone(); 406 } 407 } 408 409 410 public SplitConstraint[] getEditorAreaConstraints() { 411 synchronized(LOCK_MODES) { 412 return modesSubModel.getEditorAreaConstraints(); 413 } 414 } 415 416 417 public Set <ModeImpl> getModes() { 418 synchronized(LOCK_MODES) { 419 return modesSubModel.getModes(); 420 } 421 } 422 423 public SplitConstraint[] getModeConstraints(ModeImpl mode) { 424 synchronized(LOCK_MODES) { 425 return modesSubModel.getModeConstraints(mode); 426 } 427 } 428 429 public SplitConstraint[] getModelElementConstraints(ModelElement element) { 430 synchronized(LOCK_MODES) { 431 return modesSubModel.getModelElementConstraints(element); 432 } 433 } 434 435 public String getSlidingModeConstraints(ModeImpl mode) { 436 synchronized(LOCK_MODES) { 437 return modesSubModel.getSlidingModeConstraints(mode); 438 } 439 } 440 441 public ModeImpl getSlidingMode(String side) { 442 synchronized(LOCK_MODES) { 443 return modesSubModel.getSlidingMode(side); 444 } 445 } 446 447 448 public ModeImpl getActiveMode() { 449 synchronized(LOCK_MODES) { 450 return modesSubModel.getActiveMode(); 451 } 452 } 453 454 458 public DockingStatus getDefaultDockingStatus() { 459 return defaultDockingStatus; 460 } 461 462 465 public DockingStatus getMaximizedDockingStatus() { 466 return maximizedDockingStatus; 467 } 468 469 470 public ModeImpl getEditorMaximizedMode() { 471 synchronized(LOCK_MODES) { 472 return modesSubModel.getEditorMaximizedMode(); 473 } 474 } 475 476 477 public ModeImpl getViewMaximizedMode() { 478 synchronized(LOCK_MODES) { 479 return modesSubModel.getViewMaximizedMode(); 480 } 481 } 482 483 490 public String getSlideSideForMode( ModeImpl mode ) { 491 synchronized(LOCK_MODES) { 492 return modesSubModel.getSlideSideForMode( mode ); 493 } 494 } 495 496 497 public String getToolbarConfigName() { 498 synchronized(LOCK_TOOLBAR_CONFIG) { 499 return this.toolbarConfigName; 500 } 501 } 502 503 507 public Map <String ,Integer > getSlideInSizes(String side) { 508 synchronized(LOCK_MODES) { 509 return modesSubModel.getSlideInSizes( side ); 510 } 511 } 512 513 514 public void setSlideInSize(String side, TopComponent tc, int size) { 515 synchronized(LOCK_MODES) { 516 modesSubModel.setSlideInSize(side, tc, size); 517 } 518 } 519 520 523 public boolean isTopComponentMaximizedWhenSlidedIn( String tcid ) { 524 return null != tcid && slideInMaximizedTopComponents.contains( tcid ); 525 } 526 527 530 public void setTopComponentMaximizedWhenSlidedIn( String tcid, boolean maximized ) { 531 if( null != tcid ) { 532 if( maximized ) 533 slideInMaximizedTopComponents.add( tcid ); 534 else 535 slideInMaximizedTopComponents.remove( tcid ); 536 } 537 } 538 539 543 544 public void createModeModel(ModeImpl mode, String name, int state, int kind, boolean permanent) { 547 synchronized(mode2model) { 548 ModeModel mm; 549 mm = new DefaultModeModel(name, state, kind, permanent); 550 mode2model.put(mode, mm); 551 } 552 } 553 554 private ModeModel getModelForMode(ModeImpl mode) { 555 synchronized(mode2model) { 556 return (ModeModel)mode2model.get(mode); 557 } 558 } 559 560 562 public void setModeState(ModeImpl mode, int state) { 563 ModeModel modeModel = getModelForMode(mode); 564 if(modeModel != null) { 565 modeModel.setState(state); 566 } 567 } 568 569 570 public void setModeBounds(ModeImpl mode, Rectangle bounds) { 571 ModeModel modeModel = getModelForMode(mode); 572 if(modeModel != null) { 573 modeModel.setBounds(bounds); 574 } 575 } 576 577 578 public void setModeFrameState(ModeImpl mode, int frameState) { 579 ModeModel modeModel = getModelForMode(mode); 580 if(modeModel != null) { 581 modeModel.setFrameState(frameState); 582 } 583 } 584 585 586 public void setModeSelectedTopComponent(ModeImpl mode, TopComponent selected) { 587 ModeModel modeModel = getModelForMode(mode); 588 if(modeModel != null) { 589 modeModel.setSelectedTopComponent(selected); 590 } 591 } 592 593 594 public void setModePreviousSelectedTopComponent(ModeImpl mode, TopComponent prevSelected) { 595 ModeModel modeModel = getModelForMode(mode); 596 if(modeModel != null) { 597 modeModel.setPreviousSelectedTopComponent(prevSelected); 598 } 599 } 600 601 602 public void addModeOpenedTopComponent(ModeImpl mode, TopComponent tc) { 603 ModeModel modeModel = getModelForMode(mode); 604 if(modeModel != null) { 605 modeModel.addOpenedTopComponent(tc); 606 } 607 } 608 609 610 public void insertModeOpenedTopComponent(ModeImpl mode, TopComponent tc, int index) { 611 ModeModel modeModel = getModelForMode(mode); 612 if(modeModel != null) { 613 modeModel.insertOpenedTopComponent(tc, index); 614 } 615 } 616 617 618 public void addModeClosedTopComponent(ModeImpl mode, TopComponent tc) { 619 ModeModel modeModel = getModelForMode(mode); 620 if(modeModel != null) { 621 modeModel.addClosedTopComponent(tc); 622 } 623 } 624 625 public void addModeUnloadedTopComponent(ModeImpl mode, String tcID) { 627 ModeModel modeModel = getModelForMode(mode); 628 if(modeModel != null) { 629 modeModel.addUnloadedTopComponent(tcID); 630 } 631 } 632 633 public void setModeUnloadedSelectedTopComponent(ModeImpl mode, String tcID) { 635 ModeModel modeModel = getModelForMode(mode); 636 if(modeModel != null) { 637 modeModel.setUnloadedSelectedTopComponent(tcID); 638 } 639 } 640 641 public void setModeUnloadedPreviousSelectedTopComponent(ModeImpl mode, String tcID) { 642 ModeModel modeModel = getModelForMode(mode); 643 if(modeModel != null) { 644 modeModel.setUnloadedPreviousSelectedTopComponent(tcID); 645 } 646 } 647 648 649 public void removeModeTopComponent(ModeImpl mode, TopComponent tc) { 650 ModeModel modeModel = getModelForMode(mode); 651 if(modeModel != null) { 652 modeModel.removeTopComponent(tc); 653 } 654 } 655 656 public void removeModeClosedTopComponentID(ModeImpl mode, String tcID) { 658 ModeModel modeModel = getModelForMode(mode); 659 if(modeModel != null) { 660 modeModel.removeClosedTopComponentID(tcID); 661 } 662 } 663 664 667 668 public void setModeTopComponentPreviousConstraints(ModeImpl mode, String tcID, SplitConstraint[] constraints) { 669 ModeModel modeModel = getModelForMode(mode); 670 if(modeModel != null) { 671 modeModel.setTopComponentPreviousConstraints(tcID, constraints); 672 } 673 } 674 675 680 public void setModeTopComponentPreviousMode(ModeImpl mode, String tcID, ModeImpl previousMode, int prevIndex) { 681 ModeModel modeModel = getModelForMode(mode); 682 if(modeModel != null) { 683 modeModel.setTopComponentPreviousMode(tcID, previousMode, prevIndex); 684 } 685 } 686 687 689 public String getModeName(ModeImpl mode) { 690 ModeModel modeModel = getModelForMode(mode); 691 if(modeModel != null) { 692 return modeModel.getName(); 693 } else { 694 return null; 695 } 696 } 697 698 699 public Rectangle getModeBounds(ModeImpl mode) { 700 ModeModel modeModel = getModelForMode(mode); 701 if(modeModel != null) { 702 return modeModel.getBounds(); 703 } else { 704 return null; 705 } 706 } 707 708 public Rectangle getModeBoundsSeparatedHelp(ModeImpl mode) { 709 ModeModel modeModel = getModelForMode(mode); 710 if(modeModel != null) { 711 return modeModel.getBoundsSeparatedHelp(); 712 } else { 713 return null; 714 } 715 } 716 717 718 public int getModeState(ModeImpl mode) { 719 ModeModel modeModel = getModelForMode(mode); 720 if(modeModel != null) { 721 return modeModel.getState(); 722 } else { 723 return -1; 724 } 725 } 726 727 728 public int getModeKind(ModeImpl mode) { 729 ModeModel modeModel = getModelForMode(mode); 730 if(modeModel != null) { 731 return modeModel.getKind(); 732 } else { 733 return -1; 734 } 735 } 736 737 738 public String getModeSide(ModeImpl mode) { 739 String side = modesSubModel.getSlidingModeConstraints(mode); 740 return side; 741 } 742 743 744 public int getModeFrameState(ModeImpl mode) { 745 ModeModel modeModel = getModelForMode(mode); 746 if(modeModel != null) { 747 return modeModel.getFrameState(); 748 } else { 749 return -1; 750 } 751 } 752 753 754 public boolean isModePermanent(ModeImpl mode) { 755 ModeModel modeModel = getModelForMode(mode); 756 if(modeModel != null) { 757 return modeModel.isPermanent(); 758 } else { 759 return false; 760 } 761 } 762 763 764 public boolean isModeEmpty(ModeImpl mode) { 765 ModeModel modeModel = getModelForMode(mode); 766 if(modeModel != null) { 767 return modeModel.isEmpty(); 768 } else { 769 return false; 770 } 771 } 772 773 774 public boolean containsModeTopComponent(ModeImpl mode, TopComponent tc) { 775 ModeModel modeModel = getModelForMode(mode); 776 if(modeModel != null) { 777 return modeModel.containsTopComponent(tc); 778 } else { 779 return false; 780 } 781 } 782 783 784 public TopComponent getModeSelectedTopComponent(ModeImpl mode) { 785 ModeModel modeModel = getModelForMode(mode); 786 if(modeModel != null) { 787 return modeModel.getSelectedTopComponent(); 788 } else { 789 return null; 790 } 791 } 792 793 794 public TopComponent getModePreviousSelectedTopComponent(ModeImpl mode) { 795 ModeModel modeModel = getModelForMode(mode); 796 if(modeModel != null) { 797 return modeModel.getPreviousSelectedTopComponent(); 798 } else { 799 return null; 800 } 801 } 802 803 804 public List <TopComponent> getModeTopComponents(ModeImpl mode) { 805 ModeModel modeModel = getModelForMode(mode); 806 if(modeModel != null) { 807 return modeModel.getTopComponents(); 808 } else { 809 return Collections.emptyList(); 810 } 811 } 812 813 814 public List <TopComponent> getModeOpenedTopComponents(ModeImpl mode) { 815 ModeModel modeModel = getModelForMode(mode); 816 if(modeModel != null) { 817 return modeModel.getOpenedTopComponents(); 818 } else { 819 return Collections.emptyList(); 820 } 821 } 822 823 public List <String > getModeOpenedTopComponentsIDs(ModeImpl mode) { 825 ModeModel modeModel = getModelForMode(mode); 826 if(modeModel != null) { 827 return modeModel.getOpenedTopComponentsIDs(); 828 } else { 829 return Collections.emptyList(); 830 } 831 } 832 833 public List <String > getModeClosedTopComponentsIDs(ModeImpl mode) { 834 ModeModel modeModel = getModelForMode(mode); 835 if(modeModel != null) { 836 return modeModel.getClosedTopComponentsIDs(); 837 } else { 838 return Collections.emptyList(); 839 } 840 } 841 842 public List <String > getModeTopComponentsIDs(ModeImpl mode) { 843 ModeModel modeModel = getModelForMode(mode); 844 if(modeModel != null) { 845 return modeModel.getTopComponentsIDs(); 846 } else { 847 return Collections.emptyList(); 848 } 849 } 850 851 public SplitConstraint[] getModeTopComponentPreviousConstraints(ModeImpl mode, String tcID) { 852 ModeModel modeModel = getModelForMode(mode); 853 return modeModel == null ? null : modeModel.getTopComponentPreviousConstraints(tcID); 854 } 855 856 public ModeImpl getModeTopComponentPreviousMode(ModeImpl mode, String tcID) { 857 ModeModel modeModel = getModelForMode(mode); 858 return modeModel == null ? null : modeModel.getTopComponentPreviousMode(tcID); 859 } 860 861 862 public int getModeTopComponentPreviousIndex(ModeImpl mode, String tcID) { 863 ModeModel modeModel = getModelForMode(mode); 864 return modeModel == null ? null : modeModel.getTopComponentPreviousIndex(tcID); 865 } 866 867 869 870 public void createGroupModel(TopComponentGroupImpl tcGroup, String name, boolean opened) { 873 synchronized(group2model) { 874 TopComponentGroupModel tcgm = new DefaultTopComponentGroupModel(name, opened); 875 group2model.put(tcGroup, tcgm); 876 } 877 } 878 879 private TopComponentGroupModel getModelForGroup(TopComponentGroupImpl tcGroup) { 880 synchronized(group2model) { 881 return (TopComponentGroupModel)group2model.get(tcGroup); 882 } 883 } 884 885 886 public Set <TopComponentGroupImpl> getTopComponentGroups() { 887 synchronized(LOCK_TOPCOMPONENT_GROUPS) { 888 return new HashSet <TopComponentGroupImpl>(topComponentGroups); 889 } 890 } 891 892 893 public String getGroupName(TopComponentGroupImpl tcGroup) { 894 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 895 if(groupModel != null) { 896 return groupModel.getName(); 897 } else { 898 return null; 899 } 900 } 901 902 public void openGroup(TopComponentGroupImpl tcGroup, 903 Collection <TopComponent> openedTopComponents, 904 Collection <TopComponent> openedBeforeTopComponents) { 905 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 906 if(groupModel != null) { 907 groupModel.open(openedTopComponents, openedBeforeTopComponents); 908 } 909 } 910 911 public void closeGroup(TopComponentGroupImpl tcGroup) { 912 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 913 if(groupModel != null) { 914 groupModel.close(); 915 } 916 } 917 918 public boolean isGroupOpened(TopComponentGroupImpl tcGroup) { 919 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 920 if(groupModel != null) { 921 return groupModel.isOpened(); 922 } else { 923 return false; 924 } 925 } 926 927 public Set <TopComponent> getGroupTopComponents(TopComponentGroupImpl tcGroup) { 928 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 929 if(groupModel != null) { 930 return groupModel.getTopComponents(); 931 } else { 932 return Collections.emptySet(); 933 } 934 } 935 936 public Set <TopComponent> getGroupOpenedTopComponents(TopComponentGroupImpl tcGroup) { 937 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 938 if(groupModel != null) { 939 return groupModel.getOpenedTopComponents(); 940 } else { 941 return Collections.emptySet(); 942 } 943 } 944 945 public Set <TopComponent> getGroupOpenedBeforeTopComponents(TopComponentGroupImpl tcGroup) { 946 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 947 if(groupModel != null) { 948 return groupModel.getOpenedBeforeTopComponents(); 949 } else { 950 return Collections.emptySet(); 951 } 952 } 953 954 public Set <TopComponent> getGroupOpeningTopComponents(TopComponentGroupImpl tcGroup) { 955 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 956 if(groupModel != null) { 957 return groupModel.getOpeningTopComponents(); 958 } else { 959 return Collections.emptySet(); 960 } 961 } 962 963 public Set <TopComponent> getGroupClosingTopComponents(TopComponentGroupImpl tcGroup) { 964 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 965 if(groupModel != null) { 966 return groupModel.getClosingTopComponents(); 967 } else { 968 return Collections.emptySet(); 969 } 970 } 971 972 public boolean addGroupUnloadedTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 973 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 974 if(groupModel != null) { 975 return groupModel.addUnloadedTopComponent(tcID); 976 } else { 977 return false; 978 } 979 } 980 981 public boolean removeGroupUnloadedTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 982 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 983 if(groupModel != null) { 984 return groupModel.removeUnloadedTopComponent(tcID); 985 } else { 986 return false; 987 } 988 } 989 990 public boolean addGroupOpeningTopComponent(TopComponentGroupImpl tcGroup, TopComponent tc) { 991 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 992 if(groupModel != null) { 993 return groupModel.addOpeningTopComponent(tc); 994 } else { 995 return false; 996 } 997 } 998 999 public boolean removeGroupOpeningTopComponent(TopComponentGroupImpl tcGroup, TopComponent tc) { 1000 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1001 if(groupModel != null) { 1002 return groupModel.removeOpeningTopComponent(tc); 1003 } else { 1004 return false; 1005 } 1006 } 1007 1008 public boolean addGroupUnloadedOpeningTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1009 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1010 if(groupModel != null) { 1011 return groupModel.addUnloadedOpeningTopComponent(tcID); 1012 } else { 1013 return false; 1014 } 1015 } 1016 1017 public boolean removeGroupUnloadedOpeningTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1018 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1019 if(groupModel != null) { 1020 return groupModel.removeUnloadedOpeningTopComponent(tcID); 1021 } else { 1022 return false; 1023 } 1024 } 1025 1026 public boolean addGroupUnloadedClosingTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1027 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1028 if(groupModel != null) { 1029 return groupModel.addUnloadedClosingTopComponent(tcID); 1030 } else { 1031 return false; 1032 } 1033 } 1034 public boolean removeGroupUnloadedClosingTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1035 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1036 if(groupModel != null) { 1037 return groupModel.removeUnloadedClosingTopComponent(tcID); 1038 } else { 1039 return false; 1040 } 1041 } 1042 public boolean addGroupUnloadedOpenedTopComponent(TopComponentGroupImpl tcGroup, String tcID) { 1044 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1045 if(groupModel != null) { 1046 return groupModel.addUnloadedOpenedTopComponent(tcID); 1047 } else { 1048 return false; 1049 } 1050 } 1051 1052 public Set <String > getGroupTopComponentsIDs(TopComponentGroupImpl tcGroup) { 1054 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1055 if(groupModel != null) { 1056 return groupModel.getTopComponentsIDs(); 1057 } else { 1058 return Collections.emptySet(); 1059 } 1060 } 1061 1062 public Set <String > getGroupOpeningSetIDs(TopComponentGroupImpl tcGroup) { 1063 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1064 if(groupModel != null) { 1065 return groupModel.getOpeningSetIDs(); 1066 } else { 1067 return Collections.emptySet(); 1068 } 1069 } 1070 1071 public Set <String > getGroupClosingSetIDs(TopComponentGroupImpl tcGroup) { 1072 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1073 if(groupModel != null) { 1074 return groupModel.getClosingSetIDs(); 1075 } else { 1076 return Collections.emptySet(); 1077 } 1078 } 1079 1080 public Set <String > getGroupOpenedTopComponentsIDs(TopComponentGroupImpl tcGroup) { 1081 TopComponentGroupModel groupModel = getModelForGroup(tcGroup); 1082 if(groupModel != null) { 1083 return groupModel.getOpenedTopComponentsIDs(); 1084 } else { 1085 return Collections.emptySet(); 1086 } 1087 } 1088 1092 1093 public void setActiveModeForOriginator(ModelElement originator) { 1096 synchronized(LOCK_MODES) { 1097 ModeImpl mode = modesSubModel.getModeForOriginator(originator); 1098 setActiveMode(mode); 1099 } 1100 } 1101 1102 public void setModeSelectedTopComponentForOriginator(ModelElement originator, TopComponent tc) { 1103 ModeImpl mode; 1104 synchronized(LOCK_MODES) { 1105 mode = modesSubModel.getModeForOriginator(originator); 1106 } 1107 1108 setModeSelectedTopComponent(mode, tc); 1109 1110 1111 } 1112 1113 public void setMainWindowBoundsUserSeparatedHelp(Rectangle bounds) { 1114 if(bounds == null) { 1115 return; 1116 } 1117 1118 synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED_HELP) { 1119 this.mainWindowBoundsSeparatedHelp.setBounds(bounds); 1120 } 1121 } 1122 1123 public void setEditorAreaBoundsUserHelp(Rectangle bounds) { 1124 if(bounds == null) { 1125 return; 1126 } 1127 1128 synchronized(LOCK_EDITOR_AREA_BOUNDS_HELP) { 1129 this.editorAreaBoundsHelp.setBounds(bounds); 1130 } 1131 } 1132 1133 public void setModeBoundsSeparatedHelp(ModeImpl mode, Rectangle bounds) { 1134 ModeModel modeModel = getModelForMode(mode); 1135 if(modeModel != null) { 1136 modeModel.setBoundsSeparatedHelp(bounds); 1137 } 1138 } 1139 1140 public void setSplitWeights( ModelElement[] snapshots, double[] splitWeights ) { 1141 synchronized(LOCK_MODES) { 1142 modesSubModel.setSplitWeights(snapshots, splitWeights); 1143 } 1144 } 1145 1146 1149 1150 public WindowSystemSnapshot createWindowSystemSnapshot() { 1151 WindowSystemSnapshot wsms = new WindowSystemSnapshot(); 1152 1153 ModeStructureSnapshot mss = createModeStructureSnapshot(); 1155 wsms.setModeStructureSnapshot(mss); 1156 1157 ModeImpl activeMode = getActiveMode(); 1158 wsms.setActiveModeSnapshot(activeMode == null ? null : mss.findModeSnapshot(activeMode.getName())); 1159 1160 ModeImpl maximizedMode = null != getViewMaximizedMode() ? getViewMaximizedMode() : null; 1161 wsms.setMaximizedModeSnapshot(maximizedMode == null ? null : mss.findModeSnapshot(maximizedMode.getName())); 1162 1163 wsms.setMainWindowBoundsJoined(getMainWindowBoundsJoined()); 1164 wsms.setMainWindowBoundsSeparated(getMainWindowBoundsSeparated()); 1165 wsms.setEditorAreaBounds(getEditorAreaBounds()); 1166 wsms.setEditorAreaState(getEditorAreaState()); 1167 wsms.setEditorAreaFrameState(getEditorAreaFrameState()); 1168 wsms.setMainWindowFrameStateJoined(getMainWindowFrameStateJoined()); 1169 wsms.setMainWindowFrameStateSeparated(getMainWindowFrameStateSeparated()); 1170 wsms.setToolbarConfigurationName(getToolbarConfigName()); 1171 return wsms; 1172 } 1173 1174 1175 private ModeStructureSnapshot createModeStructureSnapshot() { 1176 ModeStructureSnapshot.ElementSnapshot splitRoot; 1177 Set <ModeStructureSnapshot.ModeSnapshot> separateModes; 1178 Set <ModeStructureSnapshot.SlidingModeSnapshot> slidingModes; 1179 synchronized(LOCK_MODES) { 1180 splitRoot = modesSubModel.createSplitSnapshot(); 1181 separateModes = modesSubModel.createSeparateModeSnapshots(); 1182 slidingModes = modesSubModel.createSlidingModeSnapshots(); 1183 } 1184 1185 ModeStructureSnapshot ms = new ModeStructureSnapshot(splitRoot, separateModes, slidingModes); 1186 return ms; 1187 } 1188 1190 1191 private static boolean validateAddingMode(ModeImpl mode) { 1192 if(mode == null) { 1193 Logger.getLogger(DefaultModel.class.getName()).log(Level.WARNING, null, 1194 new java.lang.NullPointerException ("Not allowed null mode")); return false; 1196 } 1197 1198 return true; 1199 } 1200 1201 1205 private void updateSlidingSelections (ModeImpl curActive) { 1206 Set slidingModes = modesSubModel.getSlidingModes(); 1207 ModeImpl curSliding = null; 1208 for (Iterator iter = slidingModes.iterator(); iter.hasNext(); ) { 1209 curSliding = (ModeImpl)iter.next(); 1210 if (!curSliding.equals(curActive)) { 1211 setModeSelectedTopComponent(curSliding, null); 1212 } 1213 } 1214 } 1215 1216 1219 private static class DefaultDockingStatus extends DockingStatus { 1220 public DefaultDockingStatus( Model model ) { 1221 super( model ); 1222 } 1223 1224 1228 public boolean shouldSlide( String tcID ) { 1229 return null != tcID && slided.contains( tcID ); 1230 } 1231 1232 1235 public boolean shouldDock( String tcID ) { 1236 return null != tcID && (docked.contains( tcID ) || (!docked.contains( tcID ) && !slided.contains( tcID ))); 1237 } 1238 1239 public void mark() { 1240 super.mark(); 1241 Set <ModeImpl> modes = model.getModes(); 1242 for( Iterator <ModeImpl> i=modes.iterator(); i.hasNext(); ) { 1243 ModeImpl modeImpl = i.next(); 1244 if( modeImpl.getState() != Constants.MODE_KIND_VIEW ) 1245 continue; 1246 1247 modeImpl.setPreviousSelectedTopComponent( modeImpl.getSelectedTopComponent() ); 1249 } 1250 } 1251 } 1252} 1253 1254 | Popular Tags |