1 19 20 package org.netbeans.core.windows.view; 21 22 23 import java.awt.Dimension ; 24 import java.util.List ; 25 import java.util.logging.Logger ; 26 27 import javax.swing.*; 28 import java.awt.*; 29 import java.util.Arrays ; 30 import java.util.HashSet ; 31 import java.util.Iterator ; 32 import java.util.Set ; 33 import javax.swing.SwingUtilities ; 34 35 import org.openide.awt.ToolbarPool; import org.openide.util.WeakSet; 37 import org.openide.windows.TopComponent; 38 39 import org.netbeans.core.windows.Constants; 40 import org.netbeans.core.windows.Debug; 41 import org.netbeans.core.windows.ModeImpl; 42 import org.netbeans.core.windows.model.ModelElement; 43 import org.netbeans.core.windows.view.dnd.WindowDnDManager; 44 import org.netbeans.core.windows.WindowManagerImpl; 45 import org.netbeans.core.windows.WindowSystemSnapshot; 46 import org.netbeans.core.windows.view.ui.slides.SlideOperation; 47 48 54 class DefaultView implements View, Controller, WindowDnDManager.ViewAccessor { 55 56 57 private final ViewHierarchy hierarchy = new ViewHierarchy(this, new WindowDnDManager(this)); 58 59 private final ControllerHandler controllerHandler; 60 61 private final Set <TopComponent> showingTopComponents = new WeakSet<TopComponent>(10); 62 63 64 private static final boolean DEBUG = Debug.isLoggable(DefaultView.class); 65 66 public DefaultView(ControllerHandler controllerHandler) { 67 this.controllerHandler = controllerHandler; 68 } 69 70 71 public boolean isDragInProgress() { 73 return hierarchy.isDragInProgress(); 74 } 75 76 public Frame getMainWindow() { 78 return hierarchy.getMainWindow(); 79 } 80 81 public Component getEditorAreaComponent() { 82 return hierarchy.getEditorAreaComponent(); 83 } 84 85 public String guessSlideSide (TopComponent comp) { 86 String toReturn = Constants.LEFT; 87 if (hierarchy.getMaximizedModeView() != null) { 88 toReturn = (String )comp.getClientProperty("lastSlideSide"); 90 if (toReturn == null) { 91 toReturn = Constants.LEFT; 93 } 94 } else { 95 Rectangle editorb = hierarchy.getPureEditorAreaBounds(); 96 Point leftTop = new Point(0, 0); 97 SwingUtilities.convertPointToScreen(leftTop, comp); 98 if (editorb.x > leftTop.x) { 99 toReturn = Constants.LEFT; 100 } 101 if ((editorb.x + editorb.width) < leftTop.x) { 102 toReturn = Constants.RIGHT; 103 } 104 if ((editorb.y + editorb.height) < leftTop.y) { 105 toReturn = Constants.BOTTOM; 106 } 107 comp.putClientProperty("lastSlideSide", toReturn); 108 } 109 return toReturn; 110 } 111 112 public void changeGUI(ViewEvent[] viewEvents, WindowSystemSnapshot snapshot) { 113 114 WindowSystemAccessor wsa = ViewHelper.createWindowSystemAccessor(snapshot); 116 117 if(DEBUG) { 118 debugLog("CHANGEGUI()"); debugLog("Structure=" + wsa); debugLog(""); } 122 123 if(wsa != null) { hierarchy.updateViewHierarchy(wsa.getModeStructureAccessor()); 126 } 127 128 Set <TopComponent> oldShowing = new HashSet <TopComponent>(showingTopComponents); 130 Set <TopComponent> newShowing = hierarchy.getShowingTopComponents(); 131 showingTopComponents.clear(); 132 showingTopComponents.addAll(newShowing); 133 134 Set <TopComponent> toShow = new HashSet <TopComponent>(newShowing); 135 toShow.removeAll(oldShowing); 136 for(TopComponent tc: toShow) { 137 WindowManagerImpl.getInstance().componentShowing(tc); 138 } 139 if(DEBUG) { 140 debugLog("ChangeGUI: Checking view events...") ; } 142 143 for(int i = 0; i < viewEvents.length; i++) { 145 ViewEvent viewEvent = viewEvents[i]; 146 int changeType = viewEvent.getType(); 147 if(DEBUG) { 148 debugLog("ViewEvent=" + viewEvent) ; } 150 151 if(changeType == CHANGE_VISIBILITY_CHANGED) { 152 if(DEBUG) { 153 debugLog("Winsys visibility changed, visible=" + viewEvent.getNewValue()) ; } 155 156 windowSystemVisibilityChanged(((Boolean )viewEvent.getNewValue()).booleanValue(), wsa); 157 159 return; 160 } 161 } 162 163 for(int i = 0; i < viewEvents.length; i++) { 165 ViewEvent viewEvent = viewEvents[i]; 166 int changeType = viewEvent.getType(); 167 168 if(changeType == CHANGE_MAIN_WINDOW_BOUNDS_JOINED_CHANGED) { 170 if(DEBUG) { 171 debugLog("Main window bounds joined changed"); } 173 174 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 175 Rectangle bounds = (Rectangle)viewEvent.getNewValue(); 176 if(bounds != null) { 177 hierarchy.getMainWindow().setBounds(bounds); 178 } 179 } 180 } else if(changeType == CHANGE_MAIN_WINDOW_BOUNDS_SEPARATED_CHANGED) { 181 if(DEBUG) { 182 debugLog("Main window bounds separated changed"); } 184 185 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) { 186 Rectangle bounds = (Rectangle)viewEvent.getNewValue(); 187 if(bounds != null) { 188 hierarchy.getMainWindow().setBounds(bounds); 189 } 190 } 191 } else if(changeType == CHANGE_MAIN_WINDOW_FRAME_STATE_JOINED_CHANGED) { 192 if(DEBUG) { 193 debugLog("Main window frame state joined changed"); } 195 196 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 197 hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateJoined()); 198 } 199 } else if(changeType == CHANGE_MAIN_WINDOW_FRAME_STATE_SEPARATED_CHANGED) { 200 if(DEBUG) { 201 debugLog("Main window frame state separated changed"); } 203 204 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) { 205 hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateSeparated()); 206 } 207 } else if(changeType == CHANGE_EDITOR_AREA_STATE_CHANGED) { 208 if(DEBUG) { 209 debugLog("Editor area state changed"); } 211 hierarchy.updateMainWindowBounds(wsa); 213 hierarchy.updateDesktop(wsa); 214 hierarchy.setSeparateModesVisible(true); 215 } else if(changeType == CHANGE_EDITOR_AREA_FRAME_STATE_CHANGED) { 216 if(DEBUG) { 217 debugLog("Editor area frame state changed"); } 219 hierarchy.updateEditorAreaFrameState(wsa.getEditorAreaFrameState()); 220 } else if(changeType == CHANGE_EDITOR_AREA_BOUNDS_CHANGED) { 221 if(DEBUG) { 222 debugLog("Editor area bounds changed"); } 224 225 hierarchy.updateEditorAreaBounds((Rectangle)viewEvent.getNewValue()); 226 } else if(changeType == CHANGE_EDITOR_AREA_CONSTRAINTS_CHANGED) { 227 if(DEBUG) { 228 debugLog("Editor area constraints changed"); } 230 231 hierarchy.updateDesktop(wsa); 232 } else if(changeType == CHANGE_ACTIVE_MODE_CHANGED) { 233 if(DEBUG) { 234 debugLog("Active mode changed, mode=" + viewEvent.getNewValue()); } 236 hierarchy.updateDesktop(wsa); 237 hierarchy.activateMode(wsa.getActiveModeAccessor()); 238 } else if(changeType == CHANGE_TOOLBAR_CONFIGURATION_CHANGED) { 239 if(DEBUG) { 240 debugLog("Toolbar config name changed"); } 242 243 ToolbarPool.getDefault().setConfiguration(wsa.getToolbarConfigurationName()); 244 } else if(changeType == CHANGE_MAXIMIZED_MODE_CHANGED) { 245 if(DEBUG) { 246 debugLog("Maximized mode changed"); } 248 249 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor())); 250 hierarchy.updateDesktop(wsa); 251 hierarchy.activateMode(wsa.getActiveModeAccessor()); 252 } else if(changeType == CHANGE_MODE_ADDED) { 253 if(DEBUG) { 254 debugLog("Mode added"); } 256 257 hierarchy.updateDesktop(wsa); 258 } else if(changeType == CHANGE_MODE_REMOVED) { 259 if(DEBUG) { 260 debugLog("Mode removed"); } 262 263 hierarchy.updateDesktop(wsa); 264 hierarchy.activateMode(wsa.getActiveModeAccessor()); 265 } else if(changeType == CHANGE_MODE_CONSTRAINTS_CHANGED) { 266 if(DEBUG) { 267 debugLog("Mode constraints changed"); } 269 270 hierarchy.updateDesktop(wsa); 271 } else if(changeType == CHANGE_MODE_BOUNDS_CHANGED) { 272 if(DEBUG) { 273 debugLog("Mode bounds changed"); } 275 276 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if(modeView != null) { 278 modeView.getComponent().setBounds((Rectangle)viewEvent.getNewValue()); 279 } 280 } else if(changeType == CHANGE_MODE_FRAME_STATE_CHANGED) { 281 if(DEBUG) { 282 debugLog("Mode state changed"); } 284 285 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if(modeView != null) { 287 modeView.setFrameState(((Integer )viewEvent.getNewValue()).intValue()); 288 modeView.updateFrameState(); 289 } 290 } else if(changeType == CHANGE_MODE_SELECTED_TOPCOMPONENT_CHANGED) { 291 if(DEBUG) { 292 debugLog("Selected topcomponent changed, tc=" + viewEvent.getNewValue()); } 294 295 hierarchy.updateDesktop(wsa); 297 hierarchy.activateMode(wsa.getActiveModeAccessor()); 301 } else if(changeType == CHANGE_MODE_TOPCOMPONENT_ADDED) { 303 if(DEBUG) { 304 debugLog("TopComponent added"); } 306 307 hierarchy.updateDesktop(wsa); 308 hierarchy.setSeparateModesVisible(true); 309 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if (modeView != null) { 311 modeView.updateFrameState(); 315 } 316 } else if(changeType == CHANGE_MODE_TOPCOMPONENT_REMOVED) { 317 if(DEBUG) { 318 debugLog("TopComponent removed"); } 320 321 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor())); 322 hierarchy.updateDesktop(wsa); 323 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if(modeView != null) { 325 modeView.removeTopComponent((TopComponent)viewEvent.getNewValue()); 326 } 327 hierarchy.activateMode(wsa.getActiveModeAccessor()); 328 } else if(changeType == CHANGE_TOPCOMPONENT_DISPLAY_NAME_CHANGED) { 329 if(DEBUG) { 330 debugLog("TopComponent display name changed, tc=" + viewEvent.getNewValue()); } 332 333 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if(modeView != null) { modeView.updateName((TopComponent)viewEvent.getNewValue()); 336 } 337 } else if(changeType == CHANGE_TOPCOMPONENT_DISPLAY_NAME_ANNOTATION_CHANGED) { 338 if(DEBUG) { 339 debugLog("TopComponent display name annotation changed, tc=" + viewEvent.getNewValue()); } 341 342 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if(modeView != null) { modeView.updateName((TopComponent)viewEvent.getNewValue()); 345 } 346 } else if(changeType == CHANGE_TOPCOMPONENT_TOOLTIP_CHANGED) { 347 if(DEBUG) { 348 debugLog("TopComponent tooltip changed, tc=" + viewEvent.getNewValue()); } 350 351 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if(modeView != null) { modeView.updateToolTip((TopComponent)viewEvent.getNewValue()); 354 } 355 } else if(changeType == CHANGE_TOPCOMPONENT_ICON_CHANGED) { 356 if(DEBUG) { 357 debugLog("TopComponent icon changed"); } 359 360 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if(modeView != null) { modeView.updateIcon((TopComponent)viewEvent.getNewValue()); 363 } 364 } else if(changeType == CHANGE_TOPCOMPONENT_ATTACHED) { 365 if(DEBUG) { 366 debugLog("TopComponent attached"); } 368 369 hierarchy.updateDesktop(wsa); 370 hierarchy.activateMode(wsa.getActiveModeAccessor()); 371 } else if(changeType == CHANGE_TOPCOMPONENT_ARRAY_ADDED) { 372 if(DEBUG) { 373 debugLog("TopComponent array added:" + Arrays.asList((TopComponent[])viewEvent.getNewValue())); 375 } 376 hierarchy.updateDesktop(wsa); 377 } else if(changeType == CHANGE_TOPCOMPONENT_ARRAY_REMOVED) { 379 if(DEBUG) { 380 debugLog("TopComponent array removed:" + Arrays.asList((TopComponent[])viewEvent.getNewValue())); 382 } 383 384 hierarchy.updateDesktop(wsa); 385 hierarchy.activateMode(wsa.getActiveModeAccessor()); 386 } else if(changeType == CHANGE_TOPCOMPONENT_ACTIVATED) { 387 if(DEBUG) { 388 debugLog("TopComponent activated, tc=" + viewEvent.getNewValue()); } 390 391 hierarchy.updateDesktop(wsa); 392 hierarchy.activateMode(wsa.getActiveModeAccessor()); 393 } else if(changeType == CHANGE_MODE_CLOSED) { 394 if(DEBUG) { 395 debugLog("Mode closed, mode=" + viewEvent.getSource()); } 397 398 hierarchy.updateDesktop(); 399 } else if(changeType == CHANGE_DND_PERFORMED) { 400 if(DEBUG) { 401 debugLog("DnD performed"); } 403 404 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor())); 405 hierarchy.updateDesktop(); 406 hierarchy.activateMode(wsa.getActiveModeAccessor()); 407 } else if(changeType == CHANGE_UI_UPDATE) { 408 if(DEBUG) { 409 debugLog("UI update"); } 411 412 hierarchy.updateUI(); 413 } else if(changeType == CHANGE_TOPCOMPONENT_AUTO_HIDE_ENABLED || 414 changeType == CHANGE_TOPCOMPONENT_AUTO_HIDE_DISABLED) { 415 if(DEBUG) { 416 debugLog("Top Component Auto Hide changed"); } 418 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor())); 419 hierarchy.updateDesktop(wsa); 420 hierarchy.activateMode(wsa.getActiveModeAccessor()); 421 } else if (changeType == View.TOPCOMPONENT_REQUEST_ATTENTION) { 422 if (DEBUG) { 423 debugLog("Top component request attention"); 424 } 425 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if (modeView != null) { 427 TopComponent tc = (TopComponent) viewEvent.getNewValue(); 428 if (tc == null) { 429 throw new NullPointerException ("Top component is null for attention request"); } 431 modeView.requestAttention (tc); 432 } else { 433 Logger.getLogger(DefaultView.class.getName()).fine( 434 "Could not find mode " + viewEvent.getSource()); 435 } 436 } else if (changeType == View.TOPCOMPONENT_CANCEL_REQUEST_ATTENTION) { 437 if (DEBUG) { 438 debugLog("Top component cancel request attention"); } 440 ModeView modeView = hierarchy.getModeViewForAccessor(wsa.findModeAccessor((String )viewEvent.getSource())); if (modeView != null) { 442 TopComponent tc = (TopComponent) viewEvent.getNewValue(); 443 if (tc == null) { 444 throw new NullPointerException ("Top component is null for attention cancellation request"); } 446 modeView.cancelRequestAttention (tc); 447 } else { 448 Logger.getLogger(DefaultView.class.getName()).fine( 449 "Could not find mode " + viewEvent.getSource()); 450 } 451 } else if (changeType == View.CHANGE_MAXIMIZE_TOPCOMPONENT_SLIDE_IN) { 452 if (DEBUG) { 453 debugLog("Slided-in top component toggle maximize"); } 455 TopComponent tc = (TopComponent)viewEvent.getSource(); 456 String side = (String )viewEvent.getNewValue(); 457 hierarchy.performSlideToggleMaximize( tc, side ); 458 } 459 } 460 461 Set <TopComponent> toHide = new HashSet <TopComponent>(oldShowing); 462 toHide.removeAll(newShowing); 463 for(TopComponent tc: toHide) { 464 WindowManagerImpl.getInstance().componentHidden(tc); 465 } 466 } 467 468 469 private void windowSystemVisibilityChanged(boolean visible, WindowSystemAccessor wsa) { 470 if(visible) { 471 showWindowSystem(wsa); 472 } else { 473 hideWindowSystem(); 474 } 475 } 476 477 478 private void showWindowSystem(final WindowSystemAccessor wsa) { 480 long start = System.currentTimeMillis(); 481 if(DEBUG) { 482 debugLog("ShowWindowSystem--"); } 484 492 hierarchy.getMainWindow().initializeComponents(); 493 ToolbarPool.getDefault().setConfiguration(wsa.getToolbarConfigurationName()); 495 496 if(DEBUG) { 497 debugLog(wsa.getModeStructureAccessor().toString()); 498 } 499 hierarchy.getMainWindow().prepareWindow(); 501 502 if(DEBUG) { 503 debugLog("Init view 4="+(System.currentTimeMillis() - start) + " ms"); } 505 506 507 if(DEBUG) { 508 debugLog("Init view 2="+(System.currentTimeMillis() - start) + " ms"); } 510 511 hierarchy.setSplitModesVisible(true); 512 513 if(DEBUG) { 514 debugLog("Init view 3="+(System.currentTimeMillis() - start) + " ms"); } 516 517 hierarchy.getMainWindow().setVisible(true); 519 520 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 521 hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateJoined()); 522 } else { 523 hierarchy.getMainWindow().setExtendedState(wsa.getMainWindowFrameStateSeparated()); 524 } 525 526 hierarchy.setMaximizedModeView(hierarchy.getModeViewForAccessor(wsa.getMaximizedModeAccessor())); 527 528 hierarchy.updateDesktop(wsa); 530 531 hierarchy.setSeparateModesVisible(true); 533 534 hierarchy.updateEditorAreaFrameState(wsa.getEditorAreaFrameState()); 535 536 hierarchy.updateFrameStates(); 538 539 if(wsa.getEditorAreaState() == Constants.EDITOR_AREA_JOINED) { 541 if(hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) { 543 if (DEBUG) { 544 debugLog("do updateMainWindowBoundsSeparatedHelp"); 545 } 546 updateMainWindowBoundsSeparatedHelp(); 547 updateEditorAreaBoundsHelp(); 548 } 550 } 551 552 hierarchy.activateMode(wsa.getActiveModeAccessor()); 556 557 SwingUtilities.invokeLater(new Runnable () { 562 public void run() { 563 if (DEBUG) { 564 debugLog("Installing main window listeners."); 565 } 566 hierarchy.installMainWindowListeners(); 567 } 568 }); 569 570 if(DEBUG) { 571 debugLog("Init view 5="+(System.currentTimeMillis() - start) + " ms"); } 573 } 574 575 private void hideWindowSystem() { 576 hierarchy.uninstallMainWindowListeners(); 577 578 hierarchy.setSeparateModesVisible(false); 579 hierarchy.getMainWindow().setVisible(false); 580 hierarchy.releaseAll(); 582 } 583 584 public void userActivatedModeView(ModeView modeView) { 587 if(DEBUG) { 588 debugLog("User activated mode view, mode=" + modeView); } 590 591 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 592 ModeImpl mode = getModeForModeAccessor(modeAccessor); 593 controllerHandler.userActivatedMode(mode); 594 } 595 596 public void userActivatedModeWindow(ModeView modeView) { 597 if(DEBUG) { 598 debugLog("User activated mode window, mode=" + modeView); } 600 601 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 602 ModeImpl mode = getModeForModeAccessor(modeAccessor); 603 controllerHandler.userActivatedModeWindow(mode); 604 } 605 606 public void userActivatedEditorWindow() { 607 if(DEBUG) { 608 debugLog("User activated editor window"); } 610 611 controllerHandler.userActivatedEditorWindow(); 612 } 613 614 public void userSelectedTab(ModeView modeView, TopComponent selected) { 615 if(DEBUG) { 616 debugLog("User selected tab, tc=" + WindowManagerImpl.getInstance().getTopComponentDisplayName(selected)); } 618 619 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 620 ModeImpl mode = getModeForModeAccessor(modeAccessor); 621 controllerHandler.userActivatedTopComponent(mode, selected); 622 } 623 624 public void userClosingMode(ModeView modeView) { 625 if(DEBUG) { 626 debugLog("User closing mode="+modeView); } 628 629 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 630 ModeImpl mode = getModeForModeAccessor(modeAccessor); 631 controllerHandler.userClosedMode(mode); 632 } 633 634 private void removeModeViewFromHierarchy(ModeView modeView) { 635 hierarchy.removeModeView(modeView); 636 hierarchy.updateDesktop(); 637 } 638 639 public void userResizedMainWindow(Rectangle bounds) { 640 if(DEBUG) { 641 debugLog("User resized main window"); } 643 644 if(hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) { 646 controllerHandler.userResizedMainWindow(bounds); 647 } 648 649 if(hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) { 651 updateMainWindowBoundsSeparatedHelp(); 653 updateEditorAreaBoundsHelp(); 654 updateSeparateBoundsForView(hierarchy.getSplitRootElement()); 655 } 656 } 657 658 public void userMovedMainWindow(Rectangle bounds) { 659 if(DEBUG) { 660 debugLog("User moved main window"); } 662 663 if (hierarchy.getMainWindow().getExtendedState() != Frame.MAXIMIZED_BOTH) { 665 controllerHandler.userResizedMainWindow(bounds); 666 } 667 } 668 669 public void userResizedEditorArea(Rectangle bounds) { 670 if(DEBUG) { 671 debugLog("User resized editor area"); } 673 674 controllerHandler.userResizedEditorArea(bounds); 675 } 676 677 public void userResizedModeBounds(ModeView modeView, Rectangle bounds) { 678 if(DEBUG) { 679 debugLog("User resized mode"); } 681 682 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 683 if(modeAccessor != null) { 685 ModeImpl mode = getModeForModeAccessor(modeAccessor); 686 controllerHandler.userResizedModeBounds(mode, bounds); 687 } 688 } 689 690 public void userMovedSplit(SplitView splitView, ViewElement[] childrenViews, double[] splitWeights) { 691 if(DEBUG) { 692 debugLog("User moved split"); } 695 696 SplitAccessor splitAccessor = (SplitAccessor)hierarchy.getAccessorForView(splitView); 697 ElementAccessor[] childrenAccessors = new ElementAccessor[childrenViews.length]; 698 for( int i=0; i<childrenViews.length; i++ ) { 699 childrenAccessors[i] = hierarchy.getAccessorForView( childrenViews[i] ); 700 } 701 ViewHelper.setSplitWeights(splitAccessor, childrenAccessors, splitWeights, controllerHandler); 702 703 } 706 707 public void userClosedTopComponent(ModeView modeView, TopComponent tc) { 708 if(DEBUG) { 709 debugLog("User closed topComponent=" + tc); } 711 712 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 713 ModeImpl mode = getModeForModeAccessor(modeAccessor); 714 controllerHandler.userClosedTopComponent(mode, tc); 715 } 716 717 public void userChangedFrameStateMainWindow(int frameState) { 718 if(DEBUG) { 719 debugLog("User changed frame state main window"); } 721 722 controllerHandler.userChangedFrameStateMainWindow(frameState); 723 } 724 725 public void userChangedFrameStateEditorArea(int frameState) { 726 if(DEBUG) { 727 debugLog("User changed frame state editor area"); } 729 controllerHandler.userChangedFrameStateEditorArea(frameState); 730 } 731 732 public void userChangedFrameStateMode(ModeView modeView, int frameState) { 733 if(DEBUG) { 734 debugLog("User changed frame state mode"); } 736 737 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 738 ModeImpl mode = getModeForModeAccessor(modeAccessor); 739 controllerHandler.userChangedFrameStateMode(mode, frameState); 740 } 741 742 public void userDroppedTopComponents(ModeView modeView, TopComponent[] tcs) { 744 if(tcs.length == 0) { 745 return; 746 } 747 748 if(DEBUG) { 749 debugLog("User dropped TopComponent's"); } 751 752 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 753 ModeImpl mode = getModeForModeAccessor(modeAccessor); 754 controllerHandler.userDroppedTopComponents(mode, tcs); 755 } 756 757 public void userDroppedTopComponents(ModeView modeView, TopComponent[] tcs, int index) { 758 if(tcs.length == 0) { 759 return; 760 } 761 762 if(DEBUG) { 763 debugLog("User dropped TopComponent's to index=" + index); } 765 766 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 767 ModeImpl mode = getModeForModeAccessor(modeAccessor); 768 769 int position = Arrays.asList(modeAccessor.getOpenedTopComponents()).indexOf(tcs[0]); 771 if(position > -1 && position <= index) { 772 index--; 773 } 774 775 controllerHandler.userDroppedTopComponents(mode, tcs, index); 776 } 777 778 public void userDroppedTopComponents(ModeView modeView, TopComponent[] tcs, String side) { 779 if(tcs.length == 0) { 780 return; 781 } 782 783 if(DEBUG) { 784 debugLog("User dropped TopComponent's to side=" + side); } 786 787 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 788 ModeImpl mode = getModeForModeAccessor(modeAccessor); 789 controllerHandler.userDroppedTopComponents(mode, tcs, side); 790 } 791 792 public void userDroppedTopComponentsIntoEmptyEditor(TopComponent[] tcs) { 793 if(tcs.length == 0) { 794 return; 795 } 796 797 if(DEBUG) { 798 debugLog("User dropped TopComponent's into empty editor"); } 800 801 controllerHandler.userDroppedTopComponentsIntoEmptyEditor(tcs); 802 } 803 804 public void userDroppedTopComponentsAround(TopComponent[] tcs, String side) { 805 if(tcs.length == 0) { 806 return; 807 } 808 809 if(DEBUG) { 810 debugLog("User dropped TopComponent's around, side=" + side); } 812 813 controllerHandler.userDroppedTopComponentsAround(tcs, side); 814 } 815 816 public void userDroppedTopComponentsAroundEditor(TopComponent[] tcs, String side, int modeKind) { 817 if(tcs.length == 0) { 818 return; 819 } 820 821 if(DEBUG) { 822 debugLog("User dropped TopComponent's around editor, side=" + side); } 824 825 controllerHandler.userDroppedTopComponentsAroundEditor(tcs, side, modeKind); 826 } 827 828 public void userDroppedTopComponentsIntoFreeArea(TopComponent[] tcs, Rectangle bounds, int draggedKind) { 829 if(tcs.length == 0) { 830 return; 831 } 832 833 if(DEBUG) { 834 debugLog("User dropped TopComponent's into free area, bounds=" + bounds); } 836 837 controllerHandler.userDroppedTopComponentsIntoFreeArea(tcs, bounds, draggedKind); 838 } 839 840 842 public void userDisabledAutoHide(ModeView modeView, TopComponent tc) { 843 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 844 ModeImpl mode = getModeForModeAccessor(modeAccessor); 845 controllerHandler.userDisabledAutoHide(tc, mode); 846 } 847 848 public void userEnabledAutoHide(ModeView modeView, TopComponent tc) { 849 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 850 ModeImpl mode = getModeForModeAccessor(modeAccessor); 851 String side = guessSlideSide(tc); 852 controllerHandler.userEnabledAutoHide(tc, mode, side); 853 } 854 855 public void userTriggeredSlideIn(ModeView modeView, SlideOperation operation) { 856 hierarchy.performSlideIn(operation); 857 } 858 859 public void userTriggeredSlideOut(ModeView modeView, SlideOperation operation) { 860 hierarchy.performSlideOut(operation); 861 if (operation.requestsActivation()) { 863 ModeView lastNonSlidingActive = hierarchy.getLastNonSlidingActiveModeView(); 864 ModeImpl mode = null; 865 if (lastNonSlidingActive != null) { 866 mode = getModeForModeAccessor((ModeAccessor)hierarchy.getAccessorForView(lastNonSlidingActive)); 867 } 868 if (mode != null) { 869 controllerHandler.userActivatedMode(mode); 870 } else { 871 controllerHandler.userActivatedEditorWindow(); 873 } 874 } 875 } 876 877 public void userTriggeredSlideIntoDesktop(ModeView modeView, SlideOperation operation) { 878 hierarchy.performSlideIntoDesktop(operation); 879 } 880 881 public void userTriggeredSlideIntoEdge(ModeView modeView, SlideOperation operation) { 882 hierarchy.performSlideIntoEdge(operation); 883 } 884 885 public void userResizedSlidingWindow(ModeView modeView, SlideOperation operation) { 886 ((SlidingView)modeView).setSlideBounds(modeView.getSelectedTopComponent().getBounds()); 887 hierarchy.performSlideResize(operation); 888 ModeAccessor modeAccessor = (ModeAccessor)hierarchy.getAccessorForView(modeView); 889 ModeImpl mode = getModeForModeAccessor(modeAccessor); 890 controllerHandler.userResizedSlidingMode(mode, operation.getFinishBounds()); 891 } 892 893 894 private static ModeImpl getModeForModeAccessor(ModeAccessor accessor) { 895 return accessor == null ? null : accessor.getMode(); 896 } 897 898 private static ModelElement getModelElementForAccessor(ElementAccessor accessor) { 899 return accessor == null ? null : accessor.getOriginator(); 900 } 901 904 private void updateMainWindowBoundsSeparatedHelp() { 906 controllerHandler.userResizedMainWindowBoundsSeparatedHelp( 907 hierarchy.getMainWindow().getPureMainWindowBounds()); 908 } 909 910 private void updateEditorAreaBoundsHelp() { 912 Rectangle bounds = hierarchy.getPureEditorAreaBounds(); 913 controllerHandler.userResizedEditorAreaBoundsHelp(bounds); 914 } 915 916 void updateSeparateBoundsForView(ViewElement view) { 919 if (view.getComponent() instanceof JComponent) { 920 JComponent comp = (JComponent)view.getComponent(); 927 Dimension dim = new Dimension (comp.getSize()); 928 comp.setPreferredSize(dim); 929 comp.putClientProperty("lastAvailableSpace", dim); } 931 if(view instanceof ModeView) { 932 ModeView mv = (ModeView)view; 933 ModeAccessor ma = (ModeAccessor)hierarchy.getAccessorForView(mv); 934 if(ma != null) { 935 Component comp = mv.getComponent(); 936 Rectangle bounds = comp.getBounds(); 937 Point point = new Point(0, 0); 938 SwingUtilities.convertPointToScreen(point, comp); 939 bounds.setLocation(point); 940 941 ModeImpl mode = getModeForModeAccessor(ma); 942 controllerHandler.userResizedModeBoundsSeparatedHelp(mode, bounds); 944 } 945 } else if(view instanceof SplitView) { 946 SplitView sv = (SplitView)view; 947 List children = sv.getChildren(); 948 for( Iterator i=children.iterator(); i.hasNext(); ) { 949 ViewElement child = (ViewElement)i.next(); 950 updateSeparateBoundsForView( child ); 951 } 952 } else if(view instanceof EditorView) { 953 updateEditorAreaBoundsHelp(); 954 } 956 } 957 958 public Set <Component> getModeComponents() { 961 return hierarchy.getModeComponents(); 962 } 963 964 public Set <Component> getSeparateModeFrames() { 965 return hierarchy.getSeparateModeFrames(); 966 } 967 968 public Controller getController() { 969 return this; 970 } 971 972 public Component getSlidingModeComponent(String side) { 973 return hierarchy.getSlidingModeComponent(side); 974 } 975 978 979 private static void debugLog(String message) { 980 Debug.log(DefaultView.class, message); 981 } 982 983 984 } 985 986 | Popular Tags |