0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.core.windows;
0043:
0044: import java.awt.Component;
0045: import java.awt.Dimension;
0046: import java.awt.Frame;
0047: import java.awt.KeyboardFocusManager;
0048: import java.awt.Point;
0049: import java.awt.Rectangle;
0050: import java.util.ArrayList;
0051: import java.util.Arrays;
0052: import java.util.Collections;
0053: import java.util.HashSet;
0054: import java.util.Iterator;
0055: import java.util.List;
0056: import java.util.Map;
0057: import java.util.Set;
0058: import java.util.logging.Level;
0059: import java.util.logging.Logger;
0060: import javax.swing.SwingUtilities;
0061:
0062: import org.netbeans.core.windows.model.DockingStatus;
0063: import org.netbeans.core.windows.model.Model;
0064: import org.netbeans.core.windows.model.ModelElement;
0065: import org.netbeans.core.windows.model.ModelFactory;
0066: import org.netbeans.core.windows.view.ControllerHandler;
0067: import org.netbeans.core.windows.view.View;
0068: import org.openide.windows.Mode;
0069: import org.openide.windows.TopComponent;
0070: import org.openide.windows.WindowManager;
0071:
0072: /**
0073: * This class is a central unit of window system. It controls communication
0074: * flows to model, to view, from controller and from API calls.
0075: *
0076: * @author Peter Zavadsky
0077: */
0078: final class Central implements ControllerHandler {
0079:
0080: /** Model of window system. */
0081: private final Model model = ModelFactory.createWindowSystemModel();
0082:
0083: /** Helper class for managing requests to view. */
0084: private final ViewRequestor viewRequestor = new ViewRequestor(this );
0085:
0086: private ModeImpl modeBeingMaximized = null;
0087:
0088: /** Constructor. */
0089: public Central() {
0090: }
0091:
0092: public void topComponentRequestAttention(ModeImpl mode,
0093: TopComponent tc) {
0094: String modeName = getModeName(mode);
0095: viewRequestor.scheduleRequest(new ViewRequest(modeName,
0096: View.TOPCOMPONENT_REQUEST_ATTENTION, tc, tc));
0097: }
0098:
0099: public void topComponentCancelRequestAttention(ModeImpl mode,
0100: TopComponent tc) {
0101: String modeName = getModeName(mode);
0102: viewRequestor.scheduleRequest(new ViewRequest(modeName,
0103: View.TOPCOMPONENT_CANCEL_REQUEST_ATTENTION, tc, tc));
0104: }
0105:
0106: /////////////////////
0107: // Mutators >>
0108: /** Sets visible or invisible window system and requests view accordingly. */
0109: public void setVisible(boolean visible) {
0110: if (isVisible() == visible) {
0111: return;
0112: }
0113:
0114: model.setVisible(visible);
0115:
0116: viewRequestor.scheduleRequest(new ViewRequest(null,
0117: View.CHANGE_VISIBILITY_CHANGED, null, Boolean
0118: .valueOf(visible)));
0119: }
0120:
0121: /** Sets main window bounds (joined[tiled] state) into model and requests view (if needed). */
0122: public void setMainWindowBoundsJoined(
0123: Rectangle mainWindowBoundsJoined) {
0124: if (mainWindowBoundsJoined == null) {
0125: return;
0126: }
0127:
0128: Rectangle old = getMainWindowBoundsJoined();
0129: if (old.equals(mainWindowBoundsJoined)) {
0130: return;
0131: }
0132:
0133: model.setMainWindowBoundsJoined(mainWindowBoundsJoined);
0134:
0135: if (isVisible()) {
0136: viewRequestor.scheduleRequest(new ViewRequest(null,
0137: View.CHANGE_MAIN_WINDOW_BOUNDS_JOINED_CHANGED, old,
0138: mainWindowBoundsJoined));
0139: }
0140: }
0141:
0142: /** Sets main window bounds (separated state) into model and requests view (if needed). */
0143: public void setMainWindowBoundsSeparated(
0144: Rectangle mainWindowBoundsSeparated) {
0145: if (mainWindowBoundsSeparated == null) {
0146: return;
0147: }
0148:
0149: Rectangle old = getMainWindowBoundsSeparated();
0150: if (old.equals(mainWindowBoundsSeparated)) {
0151: return;
0152: }
0153:
0154: model.setMainWindowBoundsSeparated(mainWindowBoundsSeparated);
0155:
0156: if (isVisible()) {
0157: viewRequestor.scheduleRequest(new ViewRequest(null,
0158: View.CHANGE_MAIN_WINDOW_BOUNDS_SEPARATED_CHANGED,
0159: old, mainWindowBoundsSeparated));
0160: }
0161: }
0162:
0163: public void setMainWindowFrameStateJoined(int frameState) {
0164: int old = getMainWindowFrameStateJoined();
0165: if (old == frameState) {
0166: return;
0167: }
0168:
0169: model.setMainWindowFrameStateJoined(frameState);
0170:
0171: if (isVisible()) {
0172: viewRequestor.scheduleRequest(new ViewRequest(null,
0173: View.CHANGE_MAIN_WINDOW_FRAME_STATE_JOINED_CHANGED,
0174: Integer.valueOf(old), Integer.valueOf(frameState)));
0175: }
0176: }
0177:
0178: public void setMainWindowFrameStateSeparated(int frameState) {
0179: int old = getMainWindowFrameStateSeparated();
0180: if (old == frameState) {
0181: return;
0182: }
0183:
0184: model.setMainWindowFrameStateSeparated(frameState);
0185:
0186: if (isVisible()) {
0187: viewRequestor
0188: .scheduleRequest(new ViewRequest(
0189: null,
0190: View.CHANGE_MAIN_WINDOW_FRAME_STATE_SEPARATED_CHANGED,
0191: Integer.valueOf(old), Integer
0192: .valueOf(frameState)));
0193: }
0194: }
0195:
0196: /** Sets active mode into model and requests view (if needed). */
0197: public void setActiveMode(final ModeImpl activeMode) {
0198: //#87843: Do not activate mode when it does not contain any opened TC
0199: if (activeMode != null) {
0200: List<TopComponent> l = activeMode.getOpenedTopComponents();
0201: if (l.size() == 0) {
0202: return;
0203: }
0204: }
0205:
0206: final ModeImpl old = getActiveMode();
0207: if (activeMode == old) {
0208: // kind of workaround to the scenario when a window slides out automatically
0209: // and user clicks in the currently active mode, not allow to exit in such case and fire changes to
0210: // force the slided-out window to disappear.
0211: ModeImpl impl = model.getSlidingMode(Constants.BOTTOM);
0212: boolean bottom = (impl == null || impl
0213: .getSelectedTopComponent() == null);
0214: impl = model.getSlidingMode(Constants.LEFT);
0215: boolean left = (impl == null || impl
0216: .getSelectedTopComponent() == null);
0217: impl = model.getSlidingMode(Constants.RIGHT);
0218: boolean right = (impl == null || impl
0219: .getSelectedTopComponent() == null);
0220: if (bottom && left && right) {
0221: return;
0222: }
0223: }
0224:
0225: model.setActiveMode(activeMode);
0226:
0227: if (isVisible()) {
0228: viewRequestor.scheduleRequest(new ViewRequest(null,
0229: View.CHANGE_ACTIVE_MODE_CHANGED, old, activeMode));
0230: }
0231:
0232: WindowManagerImpl.getInstance().doFirePropertyChange(
0233: WindowManagerImpl.PROP_ACTIVE_MODE, old, activeMode);
0234:
0235: // Notify registry.
0236: // active mode can be null, Active mode info is stored in winsys config (system layer) and modes in
0237: // project layer, that can cause out of synch state when switching projects.
0238: // all subsequent calls should handle the null value correctly.
0239: if (activeMode != null) {
0240: WindowManagerImpl
0241: .notifyRegistryTopComponentActivated(activeMode
0242: .getSelectedTopComponent());
0243: } else {
0244: WindowManagerImpl.notifyRegistryTopComponentActivated(null);
0245: }
0246: }
0247:
0248: /** Sets editor area bounds into model and requests view (if needed). */
0249: public void setEditorAreaBounds(Rectangle editorAreaBounds) {
0250: if (editorAreaBounds == null) {
0251: return;
0252: }
0253:
0254: Rectangle old = getEditorAreaBounds();
0255: if (old.equals(editorAreaBounds)) {
0256: return;
0257: }
0258:
0259: model.setEditorAreaBounds(editorAreaBounds);
0260:
0261: if (isVisible()) {
0262: viewRequestor.scheduleRequest(new ViewRequest(null,
0263: View.CHANGE_EDITOR_AREA_BOUNDS_CHANGED, old,
0264: editorAreaBounds));
0265: }
0266: }
0267:
0268: /** Sets editor area constraints into model and requests view (if needed). */
0269: public void setEditorAreaConstraints(
0270: SplitConstraint[] editorAreaConstraints) {
0271: SplitConstraint[] old = getEditorAreaConstraints();
0272: if (Arrays.equals(old, editorAreaConstraints)) {
0273: return;
0274: }
0275:
0276: model.setEditorAreaConstraints(editorAreaConstraints);
0277:
0278: if (isVisible()) {
0279: viewRequestor.scheduleRequest(new ViewRequest(null,
0280: View.CHANGE_EDITOR_AREA_CONSTRAINTS_CHANGED, old,
0281: editorAreaConstraints));
0282: }
0283: }
0284:
0285: /** Sets editor area state into model and requests view (if needed). */
0286: public void setEditorAreaState(int editorAreaState) {
0287: int old = getEditorAreaState();
0288: if (editorAreaState == old) {
0289: return;
0290: }
0291:
0292: int requiredState = editorAreaState == Constants.EDITOR_AREA_JOINED ? Constants.MODE_STATE_JOINED
0293: : Constants.MODE_STATE_SEPARATED;
0294:
0295: for (Iterator it = getModes().iterator(); it.hasNext();) {
0296: ModeImpl mode = (ModeImpl) it.next();
0297: if (mode.getKind() == Constants.MODE_KIND_VIEW
0298: && mode.getState() != requiredState) {
0299: model.setModeState(mode, requiredState);
0300: // Adjust bounds if necessary.
0301: if (editorAreaState == Constants.EDITOR_AREA_SEPARATED) {
0302: Rectangle bounds = model.getModeBounds(mode);
0303: if (bounds.isEmpty()) {
0304: model.setModeBounds(mode, model
0305: .getModeBoundsSeparatedHelp(mode));
0306: }
0307: }
0308: }
0309: // when switching to SDI, undock sliding windows
0310: // #51992 -start
0311: if (mode.getKind() == Constants.MODE_KIND_SLIDING
0312: && editorAreaState == Constants.EDITOR_AREA_SEPARATED) {
0313: TopComponent[] tcs = mode.getTopComponents();
0314: for (int i = 0; i < tcs.length; i++) {
0315: String tcID = WindowManagerImpl.getInstance()
0316: .findTopComponentID(tcs[i]);
0317: ModeImpl targetMode = model
0318: .getModeTopComponentPreviousMode(mode, tcID);
0319: if ((targetMode == null)
0320: || !model.getModes().contains(targetMode)) {
0321: SplitConstraint[] constraints = model
0322: .getModeTopComponentPreviousConstraints(
0323: mode, tcID);
0324: constraints = constraints == null ? new SplitConstraint[0]
0325: : constraints;
0326: // create mode to dock topcomponent back into
0327: targetMode = WindowManagerImpl
0328: .getInstance()
0329: .createModeImpl(
0330: ModeImpl.getUnusedModeName(),
0331: Constants.MODE_KIND_VIEW, false);
0332: model.setModeState(targetMode, requiredState);
0333: model.addMode(targetMode, constraints);
0334: }
0335: moveTopComponentsIntoMode(targetMode,
0336: new TopComponent[] { tcs[i] });
0337: }
0338: }
0339: // #51992 - end
0340: }
0341:
0342: if (editorAreaState == Constants.EDITOR_AREA_SEPARATED) {
0343: Rectangle editorAreaBounds = model.getEditorAreaBounds();
0344: // Adjust bounds if necessary.
0345: if (editorAreaBounds.isEmpty()) {
0346: model.setEditorAreaBounds(model
0347: .getEditorAreaBoundsHelp());
0348: }
0349:
0350: // Adjust bounds if necessary.
0351: Rectangle mainWindowBoundsSeparated = model
0352: .getMainWindowBoundsSeparated();
0353: if (mainWindowBoundsSeparated.isEmpty()) {
0354: model.setMainWindowBoundsSeparated(model
0355: .getMainWindowBoundsSeparatedHelp());
0356: }
0357: }
0358:
0359: model.setEditorAreaState(editorAreaState);
0360:
0361: if (isVisible()) {
0362: viewRequestor.scheduleRequest(new ViewRequest(null,
0363: View.CHANGE_EDITOR_AREA_STATE_CHANGED, Integer
0364: .valueOf(old), Integer
0365: .valueOf(editorAreaState)));
0366: }
0367:
0368: WindowManagerImpl.getInstance().doFirePropertyChange(
0369: WindowManagerImpl.PROP_EDITOR_AREA_STATE,
0370: Integer.valueOf(old), Integer.valueOf(editorAreaState));
0371: }
0372:
0373: public void setEditorAreaFrameState(int frameState) {
0374: int old = getEditorAreaFrameState();
0375: if (old == frameState) {
0376: return;
0377: }
0378: model.setEditorAreaFrameState(frameState);
0379:
0380: if (isVisible()) {
0381: viewRequestor.scheduleRequest(new ViewRequest(null,
0382: View.CHANGE_EDITOR_AREA_FRAME_STATE_CHANGED,
0383: Integer.valueOf(old), Integer.valueOf(frameState)));
0384: }
0385: }
0386:
0387: /** Sets new maximized mode into model and requests view update (if needed). */
0388: void switchMaximizedMode(ModeImpl newMaximizedMode) {
0389: ModeImpl old = getCurrentMaximizedMode();
0390: if (newMaximizedMode == old) {
0391: return;
0392: }
0393:
0394: WindowManagerImpl wm = WindowManagerImpl.getInstance();
0395: if (null == newMaximizedMode) {
0396: //cancel current maximized mode
0397: if (isViewMaximized()) {
0398: //some non-editor TopComponent is currently maximized
0399:
0400: //restore docking status of other components
0401: if (isEditorMaximized()) {
0402: restoreViews(model.getMaximizedDockingStatus());
0403: } else {
0404: restoreViews(model.getDefaultDockingStatus());
0405: }
0406:
0407: //return the maximized TopComponent to its original mode
0408: ModeImpl currentMaximizedMode = getViewMaximizedMode();
0409: if (currentMaximizedMode.getTopComponents().length == 1) {
0410: TopComponent maximizedTC = currentMaximizedMode
0411: .getTopComponents()[0];
0412: String tcID = wm.findTopComponentID(maximizedTC);
0413: //find the mode where the TopComponent was before its maximization
0414: ModeImpl prevMode = getModeTopComponentPreviousMode(
0415: tcID, currentMaximizedMode);
0416: int prevIndex = model
0417: .getModeTopComponentPreviousIndex(
0418: currentMaximizedMode, tcID);
0419: if (null == prevMode) {
0420: //TODO log a warning here because we somehow lost the previous mode
0421: if ((prevMode == null)
0422: || !model.getModes().contains(prevMode)) {
0423: // mode to return to isn't valid anymore, try constraints
0424: SplitConstraint[] constraints = model
0425: .getModeTopComponentPreviousConstraints(
0426: currentMaximizedMode, tcID);
0427: if (constraints != null) {
0428: // create mode with the same constraints to dock topcomponent back into
0429: prevMode = WindowManagerImpl
0430: .getInstance()
0431: .createModeImpl(
0432: ModeImpl
0433: .getUnusedModeName(),
0434: Constants.MODE_KIND_VIEW,
0435: false);
0436: model.addMode(prevMode, constraints);
0437: }
0438: }
0439:
0440: if (prevMode == null) {
0441: // fallback, previous saved mode not found somehow, use default modes
0442: prevMode = WindowManagerImpl.getInstance()
0443: .getDefaultViewMode();
0444: }
0445: }
0446: prevMode.addOpenedTopComponent(maximizedTC,
0447: prevIndex);
0448: prevMode.setSelectedTopComponent(maximizedTC);
0449: setActiveMode(prevMode);
0450: model.removeMode(currentMaximizedMode);
0451: } else {
0452: Logger.getLogger(Central.class.getName()).log(
0453: Level.WARNING,
0454: "A 'view' mode is maximized but it has wrong number of TopComponents, Mode=["
0455: + currentMaximizedMode.getName()
0456: + "], TC count="
0457: + currentMaximizedMode
0458: .getTopComponents().length);
0459: }
0460: //cancel the maximized mode
0461: setViewMaximizedMode(null);
0462:
0463: } else if (isEditorMaximized()) {
0464: //an editor TopComponent is maximized
0465: model.getMaximizedDockingStatus().mark();
0466: ModeImpl prevActiveMode = getActiveMode();
0467: //restore the docking status of other components
0468: restoreViews(model.getDefaultDockingStatus());
0469:
0470: //cancel the maximized mode
0471: setEditorMaximizedMode(null);
0472:
0473: setActiveMode(prevActiveMode);
0474:
0475: }
0476: } else {
0477: assert !isViewMaximized();
0478:
0479: //set new maximized mode
0480: if (newMaximizedMode.getKind() == Constants.MODE_KIND_EDITOR) {
0481: //the new maximized mode is an editor TopComponent
0482:
0483: //remember the current docking status of opened TopComponents
0484: model.getDefaultDockingStatus().mark();
0485: //slide-out/dock some TopComponents according to their previous state in maximized mode
0486: restoreViews(model.getMaximizedDockingStatus());
0487:
0488: setEditorMaximizedMode(newMaximizedMode);
0489:
0490: } else if (newMaximizedMode.getKind() == Constants.MODE_KIND_VIEW) {
0491: //the new maximized mode is non-editor TopComponent
0492:
0493: //remember the docking status of opened components
0494: if (isEditorMaximized()) {
0495: model.getMaximizedDockingStatus().mark();
0496: } else {
0497: model.getDefaultDockingStatus().mark();
0498: }
0499:
0500: modeBeingMaximized = newMaximizedMode;
0501:
0502: //get the TopComponent that will be maximized
0503: TopComponent tcToMaximize = newMaximizedMode
0504: .getSelectedTopComponent();
0505: String tcID = wm.findTopComponentID(tcToMaximize);
0506: int prevIndex = newMaximizedMode
0507: .getOpenedTopComponents().indexOf(tcToMaximize);
0508:
0509: //create a new mode for the maximization
0510: ModeImpl mode = WindowManagerImpl.getInstance()
0511: .createModeImpl(ModeImpl.getUnusedModeName(),
0512: Constants.MODE_KIND_VIEW, true);
0513: model.addMode(mode, new SplitConstraint[0]);
0514: //the mode has just one TopComponent
0515: mode.addOpenedTopComponent(tcToMaximize);
0516: mode.setSelectedTopComponent(tcToMaximize);
0517: //remember where to put the TopComponent back when un-maximizing
0518: setModeTopComponentPreviousMode(tcID, mode,
0519: newMaximizedMode, prevIndex);
0520:
0521: setViewMaximizedMode(mode);
0522:
0523: //slide-out all other TopComponents (the editor area won't be visible)
0524: slideAllViews();
0525:
0526: setActiveMode(mode);
0527:
0528: modeBeingMaximized = null;
0529: } else {
0530: throw new IllegalArgumentException(
0531: "Cannot maximize a sliding view");
0532: }
0533: }
0534:
0535: if (isVisible()) {
0536: viewRequestor.scheduleRequest(new ViewRequest(null,
0537: View.CHANGE_MAXIMIZED_MODE_CHANGED, old,
0538: getCurrentMaximizedMode()));
0539: }
0540:
0541: WindowManagerImpl.getInstance().doFirePropertyChange(
0542: WindowManagerImpl.PROP_MAXIMIZED_MODE, old,
0543: getCurrentMaximizedMode());
0544: }
0545:
0546: /** Sets editor mode that is currenlty maximized (used when the window system loads) */
0547: void setEditorMaximizedMode(ModeImpl editorMaximizedMode) {
0548: model.setEditorMaximizedMode(editorMaximizedMode);
0549: }
0550:
0551: /** Sets view mode that is currenlty maximized (used when the window system loads) */
0552: void setViewMaximizedMode(ModeImpl viewMaximizedMode) {
0553: model.setViewMaximizedMode(viewMaximizedMode);
0554: }
0555:
0556: /** Sets constraints for mode into model and requests view (if needed). */
0557: public void setModeConstraints(ModeImpl mode,
0558: SplitConstraint[] modeConstraints) {
0559: SplitConstraint[] old = getModeConstraints(mode);
0560: if (Arrays.equals(modeConstraints, old)) {
0561: return;
0562: }
0563:
0564: model.setModeConstraints(mode, modeConstraints);
0565:
0566: if (isVisible()) {
0567: viewRequestor.scheduleRequest(new ViewRequest(null,
0568: View.CHANGE_MODE_CONSTRAINTS_CHANGED, old,
0569: modeConstraints));
0570: }
0571: }
0572:
0573: /** Adds mode into model and requests view (if needed). */
0574: public void addMode(ModeImpl mode, SplitConstraint[] modeConstraints) {
0575: // PENDING which one to use?
0576: // if(getModes().contains(mode)) {
0577: // return;
0578: // }
0579: SplitConstraint[] old = getModeConstraints(mode);
0580: if (modeConstraints == old) {
0581: return;
0582: }
0583:
0584: model.addMode(mode, modeConstraints);
0585:
0586: if (isVisible()) {
0587: viewRequestor.scheduleRequest(new ViewRequest(null,
0588: View.CHANGE_MODE_ADDED, null, mode));
0589: }
0590:
0591: WindowManagerImpl.getInstance().doFirePropertyChange(
0592: WindowManager.PROP_MODES, null, null);
0593: }
0594:
0595: /** Removes mode from model and requests view (if needed). */
0596: public void removeMode(ModeImpl mode) {
0597: if (!getModes().contains(mode)) {
0598: return;
0599: }
0600: // debugLog("removeMode()=" + mode.getDisplayName());
0601: model.removeMode(mode);
0602: if (isVisible()) {
0603: viewRequestor.scheduleRequest(new ViewRequest(null,
0604: View.CHANGE_MODE_REMOVED, null, mode));
0605: }
0606: WindowManagerImpl.getInstance().doFirePropertyChange(
0607: WindowManager.PROP_MODES, null, null);
0608: }
0609:
0610: /** Sets toolbar configuration name and requests view (if needed). */
0611: public void setToolbarConfigName(String toolbarConfigName) {
0612: String old = getToolbarConfigName();
0613: if (old.equals(toolbarConfigName)) {
0614: return;
0615: }
0616:
0617: model.setToolbarConfigName(toolbarConfigName);
0618:
0619: if (isVisible()) {
0620: viewRequestor.scheduleRequest(new ViewRequest(null,
0621: View.CHANGE_TOOLBAR_CONFIGURATION_CHANGED, old,
0622: toolbarConfigName));
0623: }
0624: }
0625:
0626: /** Updates UI. */
0627: public void updateUI() {
0628: // Pure request, no model change.
0629: if (isVisible()) {
0630: viewRequestor.scheduleRequest(new ViewRequest(null,
0631: View.CHANGE_UI_UPDATE, null, null));
0632: }
0633: }
0634:
0635: ////////////////////////////
0636: // Mode specific >>
0637: private void closeMode(ModeImpl mode) {
0638: if (mode == null) {
0639: return;
0640: }
0641:
0642: TopComponent[] tcs = getModeOpenedTopComponents(mode).toArray(
0643: new TopComponent[0]);
0644:
0645: for (int i = 0; i < tcs.length; i++) {
0646: model.addModeClosedTopComponent(mode, tcs[i]);
0647: }
0648:
0649: ModeImpl oldActive = getActiveMode();
0650: ModeImpl newActive;
0651: if (mode == oldActive) {
0652: newActive = setSomeModeActive();
0653: } else {
0654: newActive = oldActive;
0655: }
0656: // debugLog("closeMode()");
0657:
0658: // Remove mode from model if is not permanennt and emptied.
0659: boolean modeRemoved = false;
0660: if (!mode.isPermanent()
0661: && model.getModeTopComponents(mode).isEmpty()) {
0662: // only if no sliding modes' tc points to this mode, then it's ok to remove it.
0663: if (doCheckSlidingModes(mode)) {
0664: // debugLog("do close mode=" + mode.getDisplayName());
0665: model.removeMode(mode);
0666: modeRemoved = true;
0667: }
0668: }
0669:
0670: if (isVisible()) {
0671: viewRequestor.scheduleRequest(new ViewRequest(mode,
0672: View.CHANGE_MODE_CLOSED, null, null));
0673: }
0674:
0675: // Notify closed.
0676: for (int i = 0; i < tcs.length; i++) {
0677: // Notify TopComponent was closed.
0678: WindowManagerImpl.getInstance().notifyTopComponentClosed(
0679: tcs[i]);
0680: }
0681:
0682: if (oldActive != newActive) {
0683: WindowManagerImpl.getInstance().doFirePropertyChange(
0684: WindowManagerImpl.PROP_ACTIVE_MODE, oldActive,
0685: newActive);
0686: }
0687:
0688: if (modeRemoved) {
0689: WindowManagerImpl.getInstance().doFirePropertyChange(
0690: WindowManager.PROP_MODES, null, null);
0691: }
0692:
0693: // Notify new active.
0694: if (newActive != null) {
0695: // Notify registry.
0696: WindowManagerImpl
0697: .notifyRegistryTopComponentActivated(newActive
0698: .getSelectedTopComponent());
0699: } else {
0700: WindowManagerImpl.notifyRegistryTopComponentActivated(null);
0701: }
0702: }
0703:
0704: // XXX TODO Model should handle this on its own.
0705: private ModeImpl setSomeModeActive() {
0706: for (Iterator it = getModes().iterator(); it.hasNext();) {
0707: ModeImpl mode = (ModeImpl) it.next();
0708: if (!mode.getOpenedTopComponents().isEmpty()
0709: && Constants.MODE_KIND_SLIDING != mode.getKind()) {
0710: model.setActiveMode(mode);
0711: return mode;
0712: }
0713: }
0714: model.setActiveMode(null);
0715: return model.getActiveMode();
0716: }
0717:
0718: /** Sets bounds into model and requests view (if needed). */
0719: public void setModeBounds(ModeImpl mode, Rectangle bounds) {
0720: if (bounds == null) {
0721: return;
0722: }
0723:
0724: Rectangle old = getModeBounds(mode);
0725: if (old.equals(bounds)) {
0726: return;
0727: }
0728:
0729: model.setModeBounds(mode, bounds);
0730:
0731: if (isVisible()
0732: && getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) {
0733: viewRequestor.scheduleRequest(new ViewRequest(mode,
0734: View.CHANGE_MODE_BOUNDS_CHANGED, old, bounds));
0735: }
0736:
0737: mode.doFirePropertyChange(ModeImpl.PROP_BOUNDS, old, bounds);
0738: }
0739:
0740: /** Sets frame state. */
0741: public void setModeFrameState(ModeImpl mode, int frameState) {
0742: int old = getModeFrameState(mode);
0743: if (frameState == old) {
0744: return;
0745: }
0746:
0747: model.setModeFrameState(mode, frameState);
0748:
0749: if (isVisible()) {
0750: viewRequestor
0751: .scheduleRequest(new ViewRequest(mode,
0752: View.CHANGE_MODE_FRAME_STATE_CHANGED,
0753: Integer.valueOf(old), Integer
0754: .valueOf(frameState)));
0755: }
0756: }
0757:
0758: /** Sets seleted TopComponent into model and requests view (if needed). */
0759: public void setModeSelectedTopComponent(ModeImpl mode,
0760: TopComponent selected) {
0761: // don't apply check for sliding kind when clearing selection to null
0762: if (mode.getKind() != Constants.MODE_KIND_SLIDING
0763: || selected != null) {
0764: if (!getModeOpenedTopComponents(mode).contains(selected)) {
0765: return;
0766: }
0767: }
0768:
0769: TopComponent old = getModeSelectedTopComponent(mode);
0770: if (selected == old) {
0771: return;
0772: }
0773:
0774: model.setModeSelectedTopComponent(mode, selected);
0775:
0776: if (isVisible()) {
0777: viewRequestor.scheduleRequest(new ViewRequest(mode,
0778: View.CHANGE_MODE_SELECTED_TOPCOMPONENT_CHANGED,
0779: old, selected));
0780: }
0781:
0782: // Notify registry.
0783: if (mode == getActiveMode()) {
0784: WindowManagerImpl
0785: .notifyRegistryTopComponentActivated(selected);
0786: }
0787: }
0788:
0789: /**
0790: * Remember which TopComponent was previously the selected one, used when switching to/from maximized mode.
0791: *
0792: * @param mode
0793: * @param tcId ID of TopComponent that was previously selected.
0794: */
0795: public void setModePreviousSelectedTopComponentID(ModeImpl mode,
0796: String tcId) {
0797: model.setModePreviousSelectedTopComponentID(mode, tcId);
0798: }
0799:
0800: /** Adds opened TopComponent into model and requests view (if needed). */
0801: public void addModeOpenedTopComponent(ModeImpl mode, TopComponent tc) {
0802: if (getModeOpenedTopComponents(mode).contains(tc)) {
0803: return;
0804: }
0805:
0806: // Validate the TopComponent was removed from other modes.
0807: removeTopComponentFromOtherModes(mode, tc);
0808:
0809: model.addModeOpenedTopComponent(mode, tc);
0810:
0811: if (isVisible()) {
0812: viewRequestor.scheduleRequest(new ViewRequest(mode,
0813: View.CHANGE_MODE_TOPCOMPONENT_ADDED, null, tc));
0814: }
0815:
0816: // Notify opened.
0817: WindowManagerImpl.getInstance().notifyTopComponentOpened(tc);
0818: }
0819:
0820: public void insertModeOpenedTopComponent(ModeImpl mode,
0821: TopComponent tc, int index) {
0822: List openedTcs = getModeOpenedTopComponents(mode);
0823: if (index >= 0 && !openedTcs.isEmpty()
0824: && openedTcs.size() > index
0825: && openedTcs.get(index) == tc) {
0826: return;
0827: }
0828:
0829: // Validate the TopComponent was removed from other modes.
0830: removeTopComponentFromOtherModes(mode, tc);
0831:
0832: model.insertModeOpenedTopComponent(mode, tc, index);
0833:
0834: if (isVisible()) {
0835: viewRequestor.scheduleRequest(new ViewRequest(mode,
0836: View.CHANGE_MODE_TOPCOMPONENT_ADDED, // PENDING inserted?
0837: null, tc));
0838: }
0839:
0840: // #102258: Notify opened when opened through openAtTabPosition as well
0841: WindowManagerImpl.getInstance().notifyTopComponentOpened(tc);
0842: }
0843:
0844: public void addModeClosedTopComponent(ModeImpl mode, TopComponent tc) {
0845: boolean opened = getModeOpenedTopComponents(mode).contains(tc);
0846:
0847: if (opened && !tc.canClose()) {
0848: return;
0849: }
0850:
0851: if (containsModeTopComponent(mode, tc) && !opened) {
0852: return;
0853: }
0854:
0855: // Validate the TopComponent was removed from other modes.
0856: removeTopComponentFromOtherModes(mode, tc);
0857:
0858: model.addModeClosedTopComponent(mode, tc);
0859:
0860: ModeImpl oldActive = getActiveMode();
0861: ModeImpl newActive;
0862: if (model.getModeOpenedTopComponents(mode).isEmpty()
0863: && mode == oldActive) {
0864: newActive = setSomeModeActive();
0865: } else {
0866: newActive = oldActive;
0867: }
0868:
0869: // Unmaximize mode if necessary.
0870: if (getCurrentMaximizedMode() == mode
0871: && model.getModeOpenedTopComponents(mode).isEmpty()) {
0872: switchMaximizedMode(null);
0873: }
0874:
0875: if (isVisible() && opened) {
0876: viewRequestor.scheduleRequest(new ViewRequest(mode,
0877: View.CHANGE_MODE_TOPCOMPONENT_REMOVED, null, tc));
0878: }
0879:
0880: if (oldActive != newActive) {
0881: WindowManagerImpl.getInstance().doFirePropertyChange(
0882: WindowManagerImpl.PROP_ACTIVE_MODE, oldActive,
0883: newActive);
0884: }
0885:
0886: if (newActive != null) {
0887: // Notify registry.
0888: WindowManagerImpl
0889: .notifyRegistryTopComponentActivated(newActive
0890: .getSelectedTopComponent());
0891: } else {
0892: WindowManagerImpl.notifyRegistryTopComponentActivated(null);
0893: }
0894:
0895: // Notify closed.
0896: if (opened) {
0897: WindowManagerImpl.getInstance()
0898: .notifyTopComponentClosed(tc);
0899: }
0900: }
0901:
0902: // XXX Could be called only during load phase of window system.
0903: public void addModeUnloadedTopComponent(ModeImpl mode, String tcID) {
0904: model.addModeUnloadedTopComponent(mode, tcID);
0905: }
0906:
0907: // XXX
0908: public void setUnloadedSelectedTopComponent(ModeImpl mode,
0909: String tcID) {
0910: model.setModeUnloadedSelectedTopComponent(mode, tcID);
0911: }
0912:
0913: public void setUnloadedPreviousSelectedTopComponent(ModeImpl mode,
0914: String tcID) {
0915: model.setModeUnloadedPreviousSelectedTopComponent(mode, tcID);
0916: }
0917:
0918: // XXX
0919: public List<String> getModeOpenedTopComponentsIDs(ModeImpl mode) {
0920: return model.getModeOpenedTopComponentsIDs(mode);
0921: }
0922:
0923: // XXX
0924: public List getModeClosedTopComponentsIDs(ModeImpl mode) {
0925: return model.getModeClosedTopComponentsIDs(mode);
0926: }
0927:
0928: // XXX
0929: public List getModeTopComponentsIDs(ModeImpl mode) {
0930: return model.getModeTopComponentsIDs(mode);
0931: }
0932:
0933: /** Helper validation. */
0934: private boolean removeTopComponentFromOtherModes(ModeImpl mode,
0935: TopComponent tc) {
0936: boolean tcRemoved = false;
0937: for (Iterator it = model.getModes().iterator(); it.hasNext();) {
0938: ModeImpl m = (ModeImpl) it.next();
0939: if (m == mode) {
0940: continue;
0941: }
0942:
0943: if (model.containsModeTopComponent(m, tc)) {
0944: tcRemoved = true;
0945: model.removeModeTopComponent(m, tc, null);
0946: // debugLog("removeTopComponentFromOtherModes()");
0947:
0948: // Remove mode from model if is not permanennt and emptied.
0949: boolean modeRemoved = false;
0950: if (!m.isPermanent() && m.isEmpty()
0951: && doCheckSlidingModes(m)
0952: // now the tc is not added to the sliding mode yet, but is *somehow* expected to be..
0953: // maybe needs redesign..
0954: && mode.getKind() != Constants.MODE_KIND_SLIDING
0955: //do not let remove a mode whose only TC is just being maximized
0956: && m != modeBeingMaximized) {
0957: // debugLog("removeTopComponentFromOtherModes() - really removing=" + m.getDisplayName());
0958: model.removeMode(m);
0959: modeRemoved = true;
0960: }
0961:
0962: if (modeRemoved) {
0963: WindowManagerImpl.getInstance()
0964: .doFirePropertyChange(
0965: WindowManager.PROP_MODES, null,
0966: null);
0967: }
0968: }
0969: }
0970:
0971: return tcRemoved;
0972: }
0973:
0974: /** Removed top component from model and requests view (if needed). */
0975: public void removeModeTopComponent(ModeImpl mode, TopComponent tc) {
0976: if (!containsModeTopComponent(mode, tc)) {
0977: return;
0978: }
0979:
0980: boolean viewChange = getModeOpenedTopComponents(mode).contains(
0981: tc);
0982:
0983: if (viewChange && !tc.canClose()) {
0984: return;
0985: }
0986:
0987: TopComponent recentTc = null;
0988: if (mode.getKind() == Constants.MODE_KIND_EDITOR) {
0989: //an editor document is being closed so let's find the most recent editor to select
0990: recentTc = getRecentTopComponent(mode, tc);
0991: }
0992: model.removeModeTopComponent(mode, tc, recentTc);
0993:
0994: ModeImpl oldActive = getActiveMode();
0995: ModeImpl newActive;
0996: if (model.getModeOpenedTopComponents(mode).isEmpty()
0997: && mode == oldActive) {
0998: newActive = setSomeModeActive();
0999: } else {
1000: newActive = oldActive;
1001: }
1002:
1003: // Unmaximize mode if necessary.
1004: if (getCurrentMaximizedMode() == mode
1005: && model.getModeOpenedTopComponents(mode).isEmpty()) {
1006: switchMaximizedMode(null);
1007: }
1008:
1009: // debugLog("removeModeTopComponent()");
1010: // Remove mode from model if is not permanennt and emptied.
1011: boolean modeRemoved = false;
1012: if (!mode.isPermanent()
1013: && model.getModeTopComponents(mode).isEmpty()) {
1014: // remove only if there's no other component in sliding modes that has this one as the previous mode.
1015: //TODO
1016: if (doCheckSlidingModes(mode)) {
1017: // debugLog("removeModeTopComponent() -removing " + mode.getDisplayName());
1018: model.removeMode(mode);
1019: modeRemoved = true;
1020: }
1021: }
1022:
1023: if (viewChange && isVisible()) {
1024: viewRequestor.scheduleRequest(new ViewRequest(mode,
1025: View.CHANGE_MODE_TOPCOMPONENT_REMOVED, null, tc));
1026: }
1027:
1028: // Notify closed.
1029: if (viewChange) {
1030: WindowManagerImpl.getInstance()
1031: .notifyTopComponentClosed(tc);
1032: }
1033:
1034: if (oldActive != newActive) {
1035: WindowManagerImpl.getInstance().doFirePropertyChange(
1036: WindowManagerImpl.PROP_ACTIVE_MODE, oldActive,
1037: newActive);
1038: }
1039:
1040: if (modeRemoved) {
1041: WindowManagerImpl.getInstance().doFirePropertyChange(
1042: WindowManager.PROP_MODES, null, null);
1043: }
1044:
1045: if (newActive != null) {
1046: // Notify registry.
1047: WindowManagerImpl
1048: .notifyRegistryTopComponentActivated(newActive
1049: .getSelectedTopComponent());
1050: } else {
1051: WindowManagerImpl.notifyRegistryTopComponentActivated(null);
1052: }
1053: }
1054:
1055: /**
1056: * Find TopComponent to be selected when the currently selected TC is closed
1057: * in the given mode.
1058: * @param editorMode Editor mode
1059: * @param closedTc TopComponent which is being closed in the given mode.
1060: * @return TopComponent to select or null (e.g. the mode will be empty after close)
1061: */
1062: TopComponent getRecentTopComponent(ModeImpl editorMode,
1063: TopComponent closedTc) {
1064: WindowManagerImpl wm = WindowManagerImpl.getInstance();
1065: TopComponent[] documents = wm.getRecentViewList();
1066:
1067: for (int i = 0; i < documents.length; i++) {
1068: TopComponent tc = documents[i];
1069: if (tc == null) {
1070: continue;
1071: }
1072: ModeImpl mode = (ModeImpl) wm.findMode(tc);
1073: if (mode == null || mode != editorMode || tc == closedTc) {
1074: continue;
1075: }
1076:
1077: return tc;
1078: }
1079: return null;
1080: }
1081:
1082: // remove the mode only if there's no other component in sliding modes that has this one as the previous mode.
1083: private boolean doCheckSlidingModes(ModeImpl mode) {
1084: ModeImpl slid = model.getSlidingMode(Constants.BOTTOM);
1085: if (slid != null) {
1086: TopComponent[] tcs = slid.getTopComponents();
1087: for (int i = 0; i < tcs.length; i++) {
1088: String tcID = WindowManagerImpl.getInstance()
1089: .findTopComponentID(tcs[i]);
1090: ModeImpl impl = model.getModeTopComponentPreviousMode(
1091: slid, tcID);
1092: if (impl == mode) {
1093: return false;
1094: }
1095: }
1096: }
1097: slid = model.getSlidingMode(Constants.LEFT);
1098: if (slid != null) {
1099: TopComponent[] tcs = slid.getTopComponents();
1100: for (int i = 0; i < tcs.length; i++) {
1101: String tcID = WindowManagerImpl.getInstance()
1102: .findTopComponentID(tcs[i]);
1103: ModeImpl impl = model.getModeTopComponentPreviousMode(
1104: slid, tcID);
1105: if (impl == mode) {
1106: return false;
1107: }
1108: }
1109: }
1110: slid = model.getSlidingMode(Constants.RIGHT);
1111: if (slid != null) {
1112: TopComponent[] tcs = slid.getTopComponents();
1113: for (int i = 0; i < tcs.length; i++) {
1114: String tcID = WindowManagerImpl.getInstance()
1115: .findTopComponentID(tcs[i]);
1116: ModeImpl impl = model.getModeTopComponentPreviousMode(
1117: slid, tcID);
1118: if (impl == mode) {
1119: return false;
1120: }
1121: }
1122: }
1123: return true;
1124: }
1125:
1126: // XXX
1127: public void removeModeClosedTopComponentID(ModeImpl mode,
1128: String tcID) {
1129: // It is silent now, has to be used only for closed yet unloaded components!
1130: model.removeModeClosedTopComponentID(mode, tcID);
1131: }
1132:
1133: /// << Mode specific
1134: //////////////////////////////
1135:
1136: // TopComponentGroup>>
1137: public boolean isGroupOpened(TopComponentGroupImpl tcGroup) {
1138: return model.isGroupOpened(tcGroup);
1139: }
1140:
1141: /** Opens TopComponentGroup. */
1142: public void openGroup(TopComponentGroupImpl tcGroup) {
1143: if (isGroupOpened(tcGroup)) {
1144: return;
1145: }
1146:
1147: if (isEditorMaximized() && isViewMaximized())
1148: switchMaximizedMode(null);
1149:
1150: Set<TopComponent> openedBeforeTopComponents = new HashSet<TopComponent>();
1151: Set<TopComponent> tcs = tcGroup.getTopComponents();
1152: for (Iterator<TopComponent> it = tcs.iterator(); it.hasNext();) {
1153: TopComponent tc = it.next();
1154: if (tc.isOpened()) {
1155: openedBeforeTopComponents.add(tc);
1156: }
1157: }
1158:
1159: tcs = tcGroup.getOpeningSet();
1160: HashSet<ModeImpl> openedModes = new HashSet<ModeImpl>(tcs
1161: .size());
1162: List<TopComponent> openedTcs = new ArrayList<TopComponent>();
1163: for (Iterator<TopComponent> it = tcs.iterator(); it.hasNext();) {
1164: TopComponent tc = it.next();
1165: if (!tc.isOpened()) {
1166: WindowManagerImpl wm = WindowManagerImpl.getInstance();
1167: ModeImpl mode = (ModeImpl) wm.findMode(tc);
1168: if (mode == null) {
1169: // Only view TopComponent is in group.
1170: mode = wm.getDefaultViewMode();
1171: } else {
1172: if (mode.getOpenedTopComponentsIDs().isEmpty()) {
1173: openedModes.add(mode);
1174: }
1175: }
1176: model.addModeOpenedTopComponent(mode, tc);
1177: if (tc.getClientProperty(GROUP_SELECTED) != null) {
1178: tc.requestVisible();
1179: }
1180: if (isEditorMaximized()
1181: && mode.getState() != Constants.MODE_STATE_SEPARATED) {
1182: String tcID = wm.findTopComponentID(tc);
1183: if (!isTopComponentDockedInMaximizedMode(tcID)
1184: && mode.getKind() != Constants.MODE_KIND_SLIDING) {
1185: //slide the TopComponent to edgebar and slide it out
1186: slide(tc, mode, getSlideSideForMode(mode));
1187: }
1188: }
1189: openedTcs.add(tc);
1190: }
1191: }
1192:
1193: model.openGroup(tcGroup, new HashSet<TopComponent>(openedTcs),
1194: openedBeforeTopComponents);
1195:
1196: //restore selected TopComponents
1197: for (ModeImpl mode : openedModes) {
1198: TopComponent prevSelTC = mode
1199: .getPreviousSelectedTopComponent();
1200: if (null != prevSelTC)
1201: mode.setSelectedTopComponent(prevSelTC);
1202: }
1203:
1204: if (isVisible()) {
1205: viewRequestor.scheduleRequest(new ViewRequest(tcGroup,
1206: View.CHANGE_TOPCOMPONENT_ARRAY_ADDED, null,
1207: openedTcs.toArray(new TopComponent[0])));
1208: }
1209:
1210: // Notify oepned.
1211: for (TopComponent tc : openedTcs) {
1212: WindowManagerImpl.getInstance()
1213: .notifyTopComponentOpened(tc);
1214: }
1215: }
1216:
1217: /** Used to remember selected group member TC in mode so that it can be
1218: * selected when group is opened.
1219: */
1220: private static final Object GROUP_SELECTED = new Object();
1221:
1222: /** Closes TopComponentGroup. */
1223: public void closeGroup(TopComponentGroupImpl tcGroup) {
1224: if (!isGroupOpened(tcGroup)) {
1225: return;
1226: }
1227:
1228: Set tcs = tcGroup.getClosingSet();
1229: List<TopComponent> closedTcs = new ArrayList<TopComponent>();
1230:
1231: Set<TopComponent> openedTcsByGroup = model
1232: .getGroupOpenedTopComponents(tcGroup);
1233:
1234: // Find out TC which were opened before the group was opened.
1235: Set<TopComponent> openedTcsBefore = model
1236: .getGroupOpenedBeforeTopComponents(tcGroup);
1237:
1238: // Adjust opening flags.
1239: for (Iterator<TopComponent> it = model.getGroupTopComponents(
1240: tcGroup).iterator(); it.hasNext();) {
1241: TopComponent tc = it.next();
1242: boolean wasOpenedBefore = openedTcsBefore.contains(tc);
1243: boolean openedByGroup = openedTcsByGroup.contains(tc);
1244:
1245: if (tc.isOpened()) {
1246: if (!wasOpenedBefore && !openedByGroup) {
1247: // Open by group next time, user opened it while group was opened.
1248: model.addGroupOpeningTopComponent(tcGroup, tc);
1249: }
1250: } else {
1251: if (wasOpenedBefore || openedByGroup) {
1252: // Don't open by group next time, user closed it while group was opened.
1253: model.removeGroupOpeningTopComponent(tcGroup, tc);
1254: }
1255: }
1256: }
1257:
1258: ArrayList<ModeImpl> groupModes = new ArrayList<ModeImpl>(tcs
1259: .size());
1260: //remember which TCs are active
1261: for (Iterator it = tcs.iterator(); it.hasNext();) {
1262: TopComponent tc = (TopComponent) it.next();
1263: if (!tc.isOpened() || openedTcsBefore.contains(tc)) {
1264: continue;
1265: }
1266: ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance()
1267: .findMode(tc);
1268: if (null != mode)
1269: groupModes.add(mode);
1270: }
1271: for (ModeImpl mode : groupModes) {
1272: TopComponent selTC = mode.getSelectedTopComponent();
1273: if (null != selTC) {
1274: String tcId = WindowManagerImpl.getInstance()
1275: .findTopComponentID(selTC);
1276: if (null != tcId)
1277: setModePreviousSelectedTopComponentID(mode, tcId);
1278: }
1279: }
1280:
1281: // Now close those which needed.
1282: for (Iterator it = tcs.iterator(); it.hasNext();) {
1283: TopComponent tc = (TopComponent) it.next();
1284: if (tc.isOpened()) {
1285: // Whether to ignore closing flag.
1286: if (openedTcsBefore.contains(tc)) {
1287: continue;
1288: }
1289:
1290: boolean ignore = false;
1291: for (Iterator it2 = model.getTopComponentGroups()
1292: .iterator(); it2.hasNext();) {
1293: TopComponentGroupImpl group = (TopComponentGroupImpl) it2
1294: .next();
1295: if (group == tcGroup) {
1296: continue;
1297: }
1298: if (group.isOpened()
1299: && group.getOpeningSet().contains(tc)) {
1300: ignore = true;
1301: break;
1302: }
1303: }
1304: if (ignore) {
1305: continue;
1306: }
1307:
1308: // Now you can close it.
1309: ModeImpl mode = (ModeImpl) WindowManagerImpl
1310: .getInstance().findMode(tc);
1311: if (mode != null) {
1312: if (mode.getSelectedTopComponent() == tc) {
1313: tc.putClientProperty(GROUP_SELECTED,
1314: Boolean.TRUE);
1315: } else {
1316: tc.putClientProperty(GROUP_SELECTED, null);
1317: }
1318: model.addModeClosedTopComponent(mode, tc);
1319: closedTcs.add(tc);
1320: }
1321: }
1322: }
1323:
1324: model.closeGroup(tcGroup);
1325:
1326: if (isVisible()) {
1327: viewRequestor.scheduleRequest(new ViewRequest(tcGroup,
1328: View.CHANGE_TOPCOMPONENT_ARRAY_REMOVED, null,
1329: closedTcs.toArray(new TopComponent[0])));
1330: }
1331:
1332: // Notify closed.
1333: for (TopComponent tc : closedTcs) {
1334: WindowManagerImpl.getInstance()
1335: .notifyTopComponentClosed(tc);
1336: }
1337: }
1338:
1339: /** Adds TopComponentGroup into model. */
1340: public void addTopComponentGroup(TopComponentGroupImpl tcGroup) {
1341: model.addTopComponentGroup(tcGroup);
1342: }
1343:
1344: /** Removes TopComponentGroup from model. */
1345: public void removeTopComponentGroup(TopComponentGroupImpl tcGroup) {
1346: model.removeTopComponentGroup(tcGroup);
1347: }
1348:
1349: public boolean addGroupUnloadedTopComponent(
1350: TopComponentGroupImpl tcGroup, String tcID) {
1351: return model.addGroupUnloadedTopComponent(tcGroup, tcID);
1352: }
1353:
1354: public boolean removeGroupUnloadedTopComponent(
1355: TopComponentGroupImpl tcGroup, String tcID) {
1356: return model.removeGroupUnloadedTopComponent(tcGroup, tcID);
1357: }
1358:
1359: /** Adds opening top component for set into model. */
1360: public boolean addGroupUnloadedOpeningTopComponent(
1361: TopComponentGroupImpl tcGroup, String tcID) {
1362: return model.addGroupUnloadedOpeningTopComponent(tcGroup, tcID);
1363: }
1364:
1365: /** Removes opening top component from model. */
1366: public boolean removeGroupUnloadedOpeningTopComponent(
1367: TopComponentGroupImpl tcGroup, String tcID) {
1368: return model.removeGroupUnloadedOpeningTopComponent(tcGroup,
1369: tcID);
1370: }
1371:
1372: /** Adds closing top component for set into model. */
1373: public boolean addGroupUnloadedClosingTopComponent(
1374: TopComponentGroupImpl tcGroup, String tcID) {
1375: return model.addGroupUnloadedClosingTopComponent(tcGroup, tcID);
1376: }
1377:
1378: /** Removes closing top component for set from model. */
1379: public boolean removeGroupUnloadedClosingTopComponent(
1380: TopComponentGroupImpl tcGroup, String tcID) {
1381: return model.removeGroupUnloadedClosingTopComponent(tcGroup,
1382: tcID);
1383: }
1384:
1385: // XXX Just helper for persistence.
1386: public boolean addGroupUnloadedOpenedTopComponent(
1387: TopComponentGroupImpl tcGroup, String tcID) {
1388: if (!isGroupOpened(tcGroup)) {
1389: return false;
1390: }
1391:
1392: return model.addGroupUnloadedOpenedTopComponent(tcGroup, tcID);
1393: }
1394:
1395: // XXX Just helper for persistence
1396: public Set getGroupOpenedTopComponents(TopComponentGroupImpl tcGroup) {
1397: return model.getGroupOpenedTopComponents(tcGroup);
1398: }
1399:
1400: // XXX>>
1401: public Set<String> getGroupTopComponentsIDs(
1402: TopComponentGroupImpl tcGroup) {
1403: return model.getGroupTopComponentsIDs(tcGroup);
1404: }
1405:
1406: public Set<String> getGroupOpeningSetIDs(
1407: TopComponentGroupImpl tcGroup) {
1408: return model.getGroupOpeningSetIDs(tcGroup);
1409: }
1410:
1411: public Set<String> getGroupClosingSetIDs(
1412: TopComponentGroupImpl tcGroup) {
1413: return model.getGroupClosingSetIDs(tcGroup);
1414: }
1415:
1416: public Set<String> getGroupOpenedTopComponentsIDs(
1417: TopComponentGroupImpl tcGroup) {
1418: return model.getGroupOpenedTopComponentsIDs(tcGroup);
1419: }
1420:
1421: // XXX<<
1422: // TopComponentGroup<<
1423: //////////////////////////////
1424:
1425: // Mutators <<
1426: /////////////////////
1427:
1428: /////////////////////
1429: // Accessors>>
1430:
1431: /** Indicates whether windows system shows GUI. */
1432: public boolean isVisible() {
1433: return model.isVisible();
1434: }
1435:
1436: /** Gets <code>Set</code> of all <code>Mode</code>'s. */
1437: public Set<? extends ModeImpl> getModes() {
1438: return model.getModes();
1439: }
1440:
1441: /** Gets main window bounds for joined(tiled) state. */
1442: public Rectangle getMainWindowBoundsJoined() {
1443: return model.getMainWindowBoundsJoined();
1444: }
1445:
1446: /** Gets main window bounds for separated state. */
1447: public Rectangle getMainWindowBoundsSeparated() {
1448: return model.getMainWindowBoundsSeparated();
1449: }
1450:
1451: public int getMainWindowFrameStateJoined() {
1452: return model.getMainWindowFrameStateJoined();
1453: }
1454:
1455: public int getMainWindowFrameStateSeparated() {
1456: return model.getMainWindowFrameStateSeparated();
1457: }
1458:
1459: /** Gets active mode from model. */
1460: public ModeImpl getActiveMode() {
1461: return model.getActiveMode();
1462: }
1463:
1464: /** Gets editor area bounds from model. */
1465: public Rectangle getEditorAreaBounds() {
1466: return model.getEditorAreaBounds();
1467: }
1468:
1469: /** Gets editor area constraints from model. */
1470: public SplitConstraint[] getEditorAreaConstraints() {
1471: return model.getEditorAreaConstraints();
1472: }
1473:
1474: /** Gets editor area state from model. */
1475: public int getEditorAreaState() {
1476: return model.getEditorAreaState();
1477: }
1478:
1479: public int getEditorAreaFrameState() {
1480: return model.getEditorAreaFrameState();
1481: }
1482:
1483: public Component getEditorAreaComponent() {
1484: return viewRequestor.getEditorAreaComponent();
1485: }
1486:
1487: /** Gets mode that is currently maximized (can be an editor or view component). */
1488: ModeImpl getCurrentMaximizedMode() {
1489: if (isViewMaximized())
1490: return model.getViewMaximizedMode();
1491: if (isEditorMaximized())
1492: return model.getEditorMaximizedMode();
1493: return null;
1494: }
1495:
1496: /** Gets editor maximized mode. */
1497: ModeImpl getEditorMaximizedMode() {
1498: return model.getEditorMaximizedMode();
1499: }
1500:
1501: /** Gets view maximized mode. */
1502: ModeImpl getViewMaximizedMode() {
1503: return model.getViewMaximizedMode();
1504: }
1505:
1506: /** Gets constraints for mode from model. */
1507: public SplitConstraint[] getModeConstraints(ModeImpl mode) {
1508: return model.getModeConstraints(mode);
1509: }
1510:
1511: /** Gets toolbar configuration name from model. */
1512: public String getToolbarConfigName() {
1513: return model.getToolbarConfigName();
1514: }
1515:
1516: ////////////////////////////////
1517: /// >> Mode specific
1518: /** Gets programatic name of mode. */
1519: public String getModeName(ModeImpl mode) {
1520: return model.getModeName(mode);
1521: }
1522:
1523: /** Gets bounds. */
1524: public Rectangle getModeBounds(ModeImpl mode) {
1525: return model.getModeBounds(mode);
1526: }
1527:
1528: /** Gets State. */
1529: public int getModeState(ModeImpl mode) {
1530: return model.getModeState(mode);
1531: }
1532:
1533: /** Gets kind. */
1534: public int getModeKind(ModeImpl mode) {
1535: return model.getModeKind(mode);
1536: }
1537:
1538: /** Gets side. */
1539: public String getModeSide(ModeImpl mode) {
1540: return model.getModeSide(mode);
1541: }
1542:
1543: /** Gets frame state. */
1544: public int getModeFrameState(ModeImpl mode) {
1545: return model.getModeFrameState(mode);
1546: }
1547:
1548: /** Gets used defined. */
1549: public boolean isModePermanent(ModeImpl mode) {
1550: return model.isModePermanent(mode);
1551: }
1552:
1553: public boolean isModeEmpty(ModeImpl mode) {
1554: return model.isModeEmpty(mode);
1555: }
1556:
1557: /** */
1558: public boolean containsModeTopComponent(ModeImpl mode,
1559: TopComponent tc) {
1560: return model.containsModeTopComponent(mode, tc);
1561: }
1562:
1563: /** Gets selected TopComponent. */
1564: public TopComponent getModeSelectedTopComponent(ModeImpl mode) {
1565: return model.getModeSelectedTopComponent(mode);
1566: }
1567:
1568: /**
1569: * @return ID of TopComponent that was previously selected in the given mode or null.
1570: */
1571: public String getModePreviousSelectedTopComponentID(ModeImpl mode) {
1572: return model.getModePreviousSelectedTopComponentID(mode);
1573: }
1574:
1575: /** Gets list of top components in this workspace. */
1576: public List<TopComponent> getModeTopComponents(ModeImpl mode) {
1577: return model.getModeTopComponents(mode);
1578: }
1579:
1580: /** Gets list of top components in this workspace. */
1581: public List<TopComponent> getModeOpenedTopComponents(ModeImpl mode) {
1582: return model.getModeOpenedTopComponents(mode);
1583: }
1584:
1585: /** Gets position of top component in given mode. */
1586: public int getModeTopComponentTabPosition(ModeImpl mode,
1587: TopComponent tc) {
1588: return model.getModeOpenedTopComponentTabPosition(mode, tc);
1589: }
1590:
1591: /// << Mode specific
1592: ////////////////////////////////
1593:
1594: ////////////////////////////////////
1595: // TopComponentGroup specific >>
1596: public Set<TopComponentGroupImpl> getTopComponentGroups() {
1597: return model.getTopComponentGroups();
1598: }
1599:
1600: public String getGroupName(TopComponentGroupImpl tcGroup) {
1601: return model.getGroupName(tcGroup);
1602: }
1603:
1604: public Set<TopComponent> getGroupTopComponents(
1605: TopComponentGroupImpl tcGroup) {
1606: return model.getGroupTopComponents(tcGroup);
1607: }
1608:
1609: /** Gets opening top components for group from model. */
1610: public Set<TopComponent> getGroupOpeningTopComponents(
1611: TopComponentGroupImpl tcGroup) {
1612: return model.getGroupOpeningTopComponents(tcGroup);
1613: }
1614:
1615: /** Gets closing top components for group from model. */
1616: public Set getGroupClosingTopComponents(
1617: TopComponentGroupImpl tcGroup) {
1618: return model.getGroupClosingTopComponents(tcGroup);
1619: }
1620:
1621: // TopComponentGroup specific <<
1622: ////////////////////////////////////
1623:
1624: // Accessors<<
1625: /////////////////////
1626:
1627: // Others>>
1628: // PENDING>>
1629: public void topComponentDisplayNameChanged(ModeImpl mode,
1630: TopComponent tc) {
1631: if (isVisible()) {
1632: viewRequestor.scheduleRequest(new ViewRequest(mode,
1633: View.CHANGE_TOPCOMPONENT_DISPLAY_NAME_CHANGED,
1634: null, tc));
1635: }
1636: }
1637:
1638: public void topComponentDisplayNameAnnotation(ModeImpl mode,
1639: TopComponent tc) {
1640: if (isVisible()) {
1641: viewRequestor
1642: .scheduleRequest(new ViewRequest(
1643: mode,
1644: View.CHANGE_TOPCOMPONENT_DISPLAY_NAME_ANNOTATION_CHANGED,
1645: null, tc));
1646: }
1647: }
1648:
1649: // PENDING<<
1650:
1651: public void topComponentToolTipChanged(ModeImpl mode,
1652: TopComponent tc) {
1653: if (isVisible()) {
1654: viewRequestor
1655: .scheduleRequest(new ViewRequest(mode,
1656: View.CHANGE_TOPCOMPONENT_TOOLTIP_CHANGED,
1657: null, tc));
1658: }
1659: }
1660:
1661: public void topComponentIconChanged(ModeImpl mode, TopComponent tc) {
1662: if (isVisible()) {
1663: viewRequestor.scheduleRequest(new ViewRequest(mode,
1664: View.CHANGE_TOPCOMPONENT_ICON_CHANGED, null, tc));
1665: }
1666: }
1667:
1668: public void resetModel() {
1669: model.reset();
1670: }
1671:
1672: // Others<<
1673:
1674: // Compound ones>>
1675: public void attachTopComponentsToSide(TopComponent[] tcs,
1676: ModeImpl attachMode, String side) {
1677: attachTopComponentsToSide(tcs, attachMode, side, true);
1678: }
1679:
1680: /** Creates new mode on side of specified one and puts there the TopComponentS. */
1681: private void attachTopComponentsToSide(TopComponent[] tcs,
1682: ModeImpl attachMode, String side, boolean fireEvents) {
1683: if (tcs == null || tcs.length == 0) {
1684: return;
1685: }
1686:
1687: // New mode. It is necessary to add it yet.
1688: ModeImpl newMode = WindowManagerImpl.getInstance()
1689: .createModeImpl(ModeImpl.getUnusedModeName(),
1690: attachMode.getKind(), false);
1691:
1692: // XXX All others should have the same restriction.
1693: if (!newMode.canContain(tcs[0])) {
1694: return;
1695: }
1696: model.addModeToSide(newMode, attachMode, side);
1697:
1698: attachTopComponentsHelper(tcs, newMode, fireEvents);
1699: }
1700:
1701: /** Creates new mode on side of desktops and puts there the TopComponentS. */
1702: private void attachTopComponentsAroundDesktop(TopComponent[] tcs,
1703: String side, boolean fireEvents) {
1704: if (tcs == null || tcs.length == 0) {
1705: return;
1706: }
1707:
1708: // New mode. It is necessary to add it yet.
1709: ModeImpl newMode = WindowManagerImpl.getInstance()
1710: .createModeImpl(ModeImpl.getUnusedModeName(),
1711: Constants.MODE_KIND_VIEW, false);
1712:
1713: // XXX All others should have the same restriction.
1714: if (!newMode.canContain(tcs[0])) {
1715: return;
1716: }
1717: model.addModeAround(newMode, side);
1718:
1719: attachTopComponentsHelper(tcs, newMode, fireEvents);
1720: }
1721:
1722: /** Creates new mode on side of editor area and puts there the TopComponentS. */
1723: private void attachTopComponentsAroundEditor(TopComponent[] tcs,
1724: String side, boolean fireEvents, int modeKind) {
1725: if (tcs == null || tcs.length == 0) {
1726: return;
1727: }
1728:
1729: // New mode. It is necessary to add it yet.
1730: ModeImpl newMode = WindowManagerImpl.getInstance()
1731: .createModeImpl(ModeImpl.getUnusedModeName(), modeKind,
1732: false);
1733:
1734: // XXX All others should have the same restriction.
1735: if (!newMode.canContain(tcs[0])) {
1736: return;
1737: }
1738: model.addModeAroundEditor(newMode, side);
1739:
1740: attachTopComponentsHelper(tcs, newMode, fireEvents);
1741: }
1742:
1743: private void attachTopComponentsIntoNewMode(TopComponent[] tcs,
1744: Rectangle bounds, int modeKind, int modeState) {
1745: if (tcs == null || tcs.length == 0) {
1746: return;
1747: }
1748:
1749: WindowManagerImpl wmi = WindowManagerImpl.getInstance();
1750: // New mode. It is necessary to add it yet.
1751: ModeImpl newMode = wmi.createModeImpl(ModeImpl
1752: .getUnusedModeName(), modeKind, modeState, false);
1753: newMode.setBounds(bounds);
1754:
1755: // XXX All others should have the same restriction.
1756: if (!newMode.canContain(tcs[0])) {
1757: return;
1758: }
1759:
1760: model.addMode(newMode,
1761: new SplitConstraint[] { new SplitConstraint(
1762: Constants.HORIZONTAL, 100, 0.5f) });
1763:
1764: if (modeState == Constants.MODE_STATE_SEPARATED) {
1765: // for new separate modes, remember previous modes and constraints
1766: // needed for precise docking back
1767: ModeImpl prevMode;
1768: String tcID;
1769: int prevIndex;
1770: for (int i = 0; i < tcs.length; i++) {
1771: prevMode = (ModeImpl) wmi.findMode(tcs[i]);
1772: tcID = wmi.findTopComponentID(tcs[i]);
1773: if (prevMode.getState() == Constants.MODE_STATE_SEPARATED
1774: || prevMode.getKind() == Constants.MODE_KIND_SLIDING) {
1775: prevMode = model.getModeTopComponentPreviousMode(
1776: prevMode, tcID);
1777: }
1778: if (prevMode != null) {
1779: prevIndex = prevMode.getOpenedTopComponentsIDs()
1780: .indexOf(tcID);
1781: model.setModeTopComponentPreviousMode(newMode,
1782: tcID, prevMode, prevIndex);
1783: model.setModeTopComponentPreviousConstraints(
1784: newMode, wmi.findTopComponentID(tcs[i]),
1785: prevMode.getConstraints());
1786: }
1787: }
1788: }
1789:
1790: attachTopComponentsHelper(tcs, newMode, true);
1791: }
1792:
1793: /** Helper method. */
1794: private void attachTopComponentsHelper(TopComponent[] tcs,
1795: ModeImpl newMode, boolean fireEvents) {
1796: for (int i = 0; i < tcs.length; i++) {
1797: TopComponent tc = tcs[i];
1798: removeTopComponentFromOtherModes(newMode, tc);
1799: model.addModeOpenedTopComponent(newMode, tc);
1800: }
1801:
1802: ModeImpl oldActiveMode = getActiveMode();
1803:
1804: model.setActiveMode(newMode);
1805: model.setModeSelectedTopComponent(newMode, tcs[0]);
1806:
1807: if (isVisible()) {
1808: viewRequestor.scheduleRequest(new ViewRequest(tcs[0],
1809: View.CHANGE_TOPCOMPONENT_ATTACHED, null, newMode));
1810: }
1811:
1812: if (!fireEvents) {
1813: return;
1814: }
1815:
1816: // Notify activated.
1817: WindowManagerImpl.notifyRegistryTopComponentActivated(tcs[0]);
1818:
1819: WindowManagerImpl.getInstance().doFirePropertyChange(
1820: WindowManager.PROP_MODES, null, null);
1821:
1822: if (oldActiveMode != newMode) {
1823: WindowManagerImpl.getInstance().doFirePropertyChange(
1824: WindowManagerImpl.PROP_ACTIVE_MODE, oldActiveMode,
1825: newMode);
1826: }
1827:
1828: }
1829:
1830: /** */
1831: public void activateModeTopComponent(ModeImpl mode, TopComponent tc) {
1832: if (!getModeOpenedTopComponents(mode).contains(tc)) {
1833: return;
1834: }
1835:
1836: ModeImpl oldActiveMode = getActiveMode();
1837: //#45650 -some API users call the activation all over again all the time on one item.
1838: // improve performance for such cases.
1839: if (oldActiveMode != null && oldActiveMode.equals(mode)) {
1840: if (tc != null
1841: && tc.equals(model
1842: .getModeSelectedTopComponent(mode))) {
1843: // #82385: do repeat activation if focus is in another window
1844: KeyboardFocusManager kfm = KeyboardFocusManager
1845: .getCurrentKeyboardFocusManager();
1846: if (kfm.getActiveWindow() == SwingUtilities
1847: .getWindowAncestor(tc)) {
1848: //#70173 - activation request came probably from a sliding
1849: //window in 'hover' mode, so let's hide it
1850: slideOutSlidingWindows(mode);
1851: return;
1852: }
1853: }
1854: }
1855: model.setActiveMode(mode);
1856: model.setModeSelectedTopComponent(mode, tc);
1857:
1858: if (isVisible()) {
1859: viewRequestor.scheduleRequest(new ViewRequest(mode,
1860: View.CHANGE_TOPCOMPONENT_ACTIVATED, null, tc));
1861: }
1862:
1863: // Notify registry.
1864: WindowManagerImpl.notifyRegistryTopComponentActivated(tc);
1865:
1866: if (oldActiveMode != mode) {
1867: WindowManagerImpl.getInstance().doFirePropertyChange(
1868: WindowManagerImpl.PROP_ACTIVE_MODE, oldActiveMode,
1869: mode);
1870: }
1871: }
1872:
1873: // Compound ones<<
1874:
1875: /**
1876: * Make sure no sliding window is slided-in.
1877: */
1878: protected void slideOutSlidingWindows(ModeImpl newActiveMode) {
1879: for (ModeImpl mode : getModes()) {
1880: if (!newActiveMode.equals(mode)
1881: && mode.getKind() == Constants.MODE_KIND_SLIDING
1882: && null != mode.getSelectedTopComponent()) {
1883:
1884: setModeSelectedTopComponent(mode, null);
1885: }
1886: }
1887: }
1888:
1889: // Other >>
1890: public boolean isDragInProgress() {
1891: // XXX
1892: return viewRequestor.isDragInProgress();
1893: }
1894:
1895: public Frame getMainWindow() {
1896: // XXX
1897: return viewRequestor.getMainWindow();
1898: }
1899:
1900: public String guessSlideSide(TopComponent tc) {
1901: return viewRequestor.guessSlideSide(tc);
1902: }
1903:
1904: /**
1905: * Find the side (LEFT/RIGHT/BOTTOM) where the TopComponent from the given
1906: * mode should slide to.
1907: *
1908: * @param mode Mode
1909: * @return The slide side for TopComponents from the given mode.
1910: */
1911: String getSlideSideForMode(ModeImpl mode) {
1912: return model.getSlideSideForMode(mode);
1913: }
1914:
1915: /** Tells whether given top component is inside joined mode (in main window)
1916: * or inside separate mode (separate window).
1917: *
1918: * @param the component in question
1919: * @return True when given component is docked, which means lives now
1920: * inside main window. False if component lives inside separate window.
1921: */
1922: public boolean isDocked(TopComponent comp) {
1923: ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance()
1924: .findMode(comp);
1925: return mode != null
1926: && mode.getState() == Constants.MODE_STATE_JOINED;
1927: }
1928:
1929: // Other <<
1930:
1931: // Helper methods
1932: /** Creates model for mode, used internally. */
1933: public void createModeModel(ModeImpl mode, String name, int state,
1934: int kind, boolean permanent) {
1935: model.createModeModel(mode, name, state, kind, permanent);
1936: }
1937:
1938: /** Creates model for top component group, used internally. */
1939: public void createGroupModel(TopComponentGroupImpl tcGroup,
1940: String name, boolean opened) {
1941: model.createGroupModel(tcGroup, name, opened);
1942: }
1943:
1944: // snapshot
1945: /** Creates window system model snapshot, used for requesting view. */
1946: public WindowSystemSnapshot createWindowSystemSnapshot() {
1947: return model.createWindowSystemSnapshot();
1948: }
1949:
1950: ///////////////////////////
1951: // ControllerHandler>>
1952: public void userActivatedMode(ModeImpl mode) {
1953: if (mode != null) {
1954: setActiveMode(mode);
1955: }
1956: }
1957:
1958: public void userActivatedModeWindow(ModeImpl mode) {
1959: if (mode != null) {
1960: setActiveMode(mode);
1961: }
1962: }
1963:
1964: public void userActivatedEditorWindow() {
1965: WindowManagerImpl wm = WindowManagerImpl.getInstance();
1966: TopComponent[] tcs = wm.getRecentViewList();
1967: for (int i = 0; i < tcs.length; i++) {
1968: TopComponent tc = tcs[i];
1969: ModeImpl mode = (ModeImpl) wm.findMode(tc);
1970: if (mode != null
1971: && mode.getKind() == Constants.MODE_KIND_EDITOR
1972: && !mode.getOpenedTopComponents().isEmpty()) {
1973: setActiveMode(mode);
1974: return;
1975: }
1976: }
1977:
1978: ModeImpl mode = wm.getDefaultEditorMode();
1979: if (mode != null && !mode.getOpenedTopComponents().isEmpty()) {
1980: setActiveMode(mode);
1981: } else {
1982: // when someone calls this as a matter of activating editor mode as a fallback, but none is opened,
1983: // do unactivate the current selection.
1984: // #44389
1985: setActiveMode(null);
1986: }
1987: }
1988:
1989: public void userActivatedTopComponent(ModeImpl mode,
1990: TopComponent selected) {
1991: if (mode != null) {
1992: setModeSelectedTopComponent(mode, selected);
1993: }
1994: }
1995:
1996: public void userResizedMainWindow(Rectangle bounds) {
1997: if (getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
1998: model.setMainWindowBoundsJoined(bounds);
1999: } else {
2000: model.setMainWindowBoundsSeparated(bounds);
2001: }
2002: }
2003:
2004: public void userResizedMainWindowBoundsSeparatedHelp(
2005: Rectangle bounds) {
2006: if (getEditorAreaState() == Constants.EDITOR_AREA_JOINED
2007: && getMainWindowBoundsSeparated().isEmpty()) {
2008: model.setMainWindowBoundsUserSeparatedHelp(bounds);
2009: }
2010: }
2011:
2012: public void userResizedEditorArea(Rectangle bounds) {
2013: model.setEditorAreaBounds(bounds);
2014: }
2015:
2016: public void userResizedEditorAreaBoundsHelp(Rectangle bounds) {
2017: if (getEditorAreaState() == Constants.EDITOR_AREA_JOINED
2018: && getEditorAreaBounds().isEmpty()) {
2019: model.setEditorAreaBoundsUserHelp(bounds);
2020: }
2021: }
2022:
2023: public void userResizedModeBounds(ModeImpl mode, Rectangle bounds) {
2024: Rectangle old = model.getModeBounds(mode);
2025: model.setModeBounds(mode, bounds);
2026:
2027: mode.doFirePropertyChange(ModeImpl.PROP_BOUNDS, old, bounds);
2028: }
2029:
2030: public void userResizedModeBoundsSeparatedHelp(ModeImpl mode,
2031: Rectangle bounds) {
2032: model.setModeBoundsSeparatedHelp(mode, bounds);
2033: }
2034:
2035: public void userChangedFrameStateMainWindow(int frameState) {
2036: if (getEditorAreaState() == Constants.EDITOR_AREA_JOINED) {
2037: model.setMainWindowFrameStateJoined(frameState);
2038: } else {
2039: model.setMainWindowFrameStateSeparated(frameState);
2040: }
2041: }
2042:
2043: public void userChangedFrameStateEditorArea(int frameState) {
2044: model.setEditorAreaFrameState(frameState);
2045: }
2046:
2047: public void userChangedFrameStateMode(ModeImpl mode, int frameState) {
2048: model.setModeFrameState(mode, frameState);
2049: }
2050:
2051: public void userChangedSplit(ModelElement[] snapshots,
2052: double[] splitWeights) {
2053: model.setSplitWeights(snapshots, splitWeights);
2054: }
2055:
2056: public void userClosedTopComponent(ModeImpl mode, TopComponent tc) {
2057: if (mode == getCurrentMaximizedMode() && isViewMaximized()) {
2058: switchMaximizedMode(null);
2059: for (Iterator it = getModes().iterator(); it.hasNext();) {
2060: ModeImpl newMode = (ModeImpl) it.next();
2061:
2062: if (newMode.containsTopComponent(tc)) {
2063: userClosedTopComponent(newMode, tc);
2064: return;
2065: }
2066: }
2067: }
2068: TopComponent recentTc = null;
2069: if (mode.getKind() == Constants.MODE_KIND_EDITOR) {
2070: //an editor document is being closed so let's find the most recent editor to select
2071: recentTc = getRecentTopComponent(mode, tc);
2072: }
2073: addModeClosedTopComponent(mode, tc);
2074: if (null != recentTc)
2075: recentTc.requestActive();
2076: }
2077:
2078: public void userClosedMode(ModeImpl mode) {
2079: if (mode != null) {
2080: closeMode(mode);
2081: // Unmaximize if necessary.
2082: if (mode.getOpenedTopComponents().isEmpty()
2083: && mode == getCurrentMaximizedMode()) {
2084: switchMaximizedMode(null);
2085: }
2086: }
2087:
2088: }
2089:
2090: // DnD
2091: public void userDroppedTopComponents(ModeImpl mode,
2092: TopComponent[] tcs) {
2093: updateViewAfterDnD(moveTopComponentsIntoMode(mode, tcs));
2094: }
2095:
2096: public void userDroppedTopComponents(ModeImpl mode,
2097: TopComponent[] tcs, int index) {
2098: updateViewAfterDnD(moveTopComponentsIntoMode(mode, tcs, index));
2099: }
2100:
2101: public void userDroppedTopComponents(ModeImpl mode,
2102: TopComponent[] tcs, String side) {
2103: attachTopComponentsToSide(tcs, mode, side, false);
2104:
2105: updateViewAfterDnD(true);
2106: }
2107:
2108: public void userDroppedTopComponentsIntoEmptyEditor(
2109: TopComponent[] tcs) {
2110: // PENDING
2111: ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance()
2112: .findMode("editor"); // NOI18N
2113: moveTopComponentsIntoMode(mode, tcs);
2114: updateViewAfterDnD(true);
2115: }
2116:
2117: public void userDroppedTopComponentsAround(TopComponent[] tcs,
2118: String side) {
2119: attachTopComponentsAroundDesktop(tcs, side, false);
2120:
2121: updateViewAfterDnD(true);
2122: }
2123:
2124: public void userDroppedTopComponentsAroundEditor(
2125: TopComponent[] tcs, String side, int modeKind) {
2126: attachTopComponentsAroundEditor(tcs, side, false, modeKind);
2127:
2128: updateViewAfterDnD(true);
2129: }
2130:
2131: public void userDroppedTopComponentsIntoFreeArea(
2132: TopComponent[] tcs, Rectangle bounds, int modeKind) {
2133: attachTopComponentsIntoNewMode(tcs, bounds, modeKind,
2134: Constants.MODE_STATE_SEPARATED);
2135: updateViewAfterDnD(true);
2136: }
2137:
2138: public void userUndockedTopComponent(TopComponent tc, ModeImpl mode) {
2139: Point tcLoc = tc.getLocation();
2140: Dimension tcSize = tc.getSize();
2141: SwingUtilities.convertPointToScreen(tcLoc, tc);
2142: Rectangle bounds = new Rectangle(tcLoc, tcSize);
2143: // #89100: update mode kind when undocking view in sliding mode
2144: int modeKind = mode.getKind();
2145: if (modeKind == Constants.MODE_KIND_SLIDING) {
2146: modeKind = Constants.MODE_KIND_VIEW;
2147: }
2148: // #81479: unmaximize only if desirable
2149: if (getCurrentMaximizedMode() == mode
2150: && mode.getOpenedTopComponents().size() == 1
2151: && mode.getOpenedTopComponents().get(0) == tc) {
2152: switchMaximizedMode(null);
2153: }
2154: attachTopComponentsIntoNewMode(new TopComponent[] { tc },
2155: bounds, modeKind, Constants.MODE_STATE_SEPARATED);
2156: updateViewAfterDnD(false);
2157: }
2158:
2159: public void userDockedTopComponent(TopComponent tc, ModeImpl mode) {
2160: ModeImpl dockTo = null;
2161: // find saved previous mode or at least constraints (=the place) to dock back into
2162: String tcID = WindowManagerImpl.getInstance()
2163: .findTopComponentID(tc);
2164: ModeImpl source = (ModeImpl) WindowManagerImpl.getInstance()
2165: .findMode(tc);
2166: dockTo = model.getModeTopComponentPreviousMode(source, tcID);
2167: int dockIndex = model.getModeTopComponentPreviousIndex(source,
2168: tcID);
2169: int modeKind = mode.getKind();
2170:
2171: if ((dockTo == null) || !model.getModes().contains(dockTo)) {
2172: // mode to dock to back isn't valid anymore, try constraints
2173: SplitConstraint[] constraints = model
2174: .getModeTopComponentPreviousConstraints(source,
2175: tcID);
2176: if (constraints != null) {
2177: // create mode with the same constraints to dock topcomponent back into
2178: dockTo = WindowManagerImpl.getInstance()
2179: .createModeImpl(ModeImpl.getUnusedModeName(),
2180: modeKind, false);
2181: model.addMode(dockTo, constraints);
2182: }
2183: }
2184:
2185: if (dockTo == null) {
2186: // fallback, previous saved mode not found somehow, use default modes
2187: dockTo = modeKind == Constants.MODE_KIND_EDITOR ? WindowManagerImpl
2188: .getInstance().getDefaultEditorMode()
2189: : WindowManagerImpl.getInstance()
2190: .getDefaultViewMode();
2191: }
2192: moveTopComponentsIntoMode(dockTo, new TopComponent[] { tc },
2193: dockIndex);
2194: updateViewAfterDnD(false);
2195: }
2196:
2197: private boolean moveTopComponentsIntoMode(ModeImpl mode,
2198: TopComponent[] tcs) {
2199: return moveTopComponentsIntoMode(mode, tcs, -1);
2200: }
2201:
2202: private boolean moveTopComponentsIntoMode(ModeImpl mode,
2203: TopComponent[] tcs, int index) {
2204: boolean moved = false;
2205: boolean intoSliding = mode.getKind() == Constants.MODE_KIND_SLIDING;
2206: boolean intoSeparate = mode.getState() == Constants.MODE_STATE_SEPARATED;
2207: ModeImpl prevMode = null;
2208: for (int i = 0; i < tcs.length; i++) {
2209: TopComponent tc = tcs[i];
2210: String tcID = WindowManagerImpl.getInstance()
2211: .findTopComponentID(tc);
2212: // XXX
2213: if (!mode.canContain(tc)) {
2214: continue;
2215: }
2216: for (Iterator it = model.getModes().iterator(); it
2217: .hasNext();) {
2218: ModeImpl m = (ModeImpl) it.next();
2219: if (model.containsModeTopComponent(m, tc)) {
2220: if (m.getKind() == Constants.MODE_KIND_SLIDING
2221: || m.getState() == Constants.MODE_STATE_SEPARATED) {
2222: prevMode = model
2223: .getModeTopComponentPreviousMode(m,
2224: tcID);
2225: } else {
2226: prevMode = m;
2227: }
2228: break;
2229: }
2230: }
2231: int prevIndex = prevMode != null
2232: && (intoSliding || intoSeparate) ? prevMode
2233: .getOpenedTopComponentsIDs().indexOf(tcID) : -1;
2234: if (removeTopComponentFromOtherModes(mode, tc)) {
2235: moved = true;
2236: }
2237: if (index > -1) {
2238: model.insertModeOpenedTopComponent(mode, tc, index);
2239: } else {
2240: model.addModeOpenedTopComponent(mode, tc);
2241: }
2242: if (prevMode != null && (intoSliding || intoSeparate)) {
2243: // remember previous mode and constraints for precise de-auto-hide
2244: model.setModeTopComponentPreviousMode(mode, tcID,
2245: prevMode, prevIndex);
2246: model.setModeTopComponentPreviousConstraints(mode,
2247: tcID, model.getModeConstraints(prevMode));
2248: }
2249: }
2250: if (!intoSliding) {
2251: // make the target mode active after dragging..
2252: model.setActiveMode(mode);
2253: model
2254: .setModeSelectedTopComponent(mode,
2255: tcs[tcs.length - 1]);
2256: } else {
2257: // don't activate sliding modes, it means the component slides out, that's a bad thing..
2258: // make some other desktop mode active
2259: if (prevMode != null && prevMode == getActiveMode()
2260: && prevMode.getOpenedTopComponents().isEmpty()) {
2261: setSomeModeActive();
2262: }
2263: // check the drop mode if it was already used, if not, assign it some reasonable size,
2264: // according to the current component.
2265: if (mode.getBounds().width == 0
2266: && mode.getBounds().height == 0) {
2267: // now we have the sliding mode in initial state
2268: mode.setBounds(tcs[tcs.length - 1].getBounds());
2269: }
2270: }
2271: return moved;
2272: }
2273:
2274: private void updateViewAfterDnD(boolean unmaximize) {
2275: if (unmaximize) {
2276: switchMaximizedMode(null);
2277: }
2278:
2279: if (isVisible()) {
2280: viewRequestor.scheduleRequest(new ViewRequest(null,
2281: View.CHANGE_DND_PERFORMED, null, null));
2282: FloatingWindowTransparencyManager.getDefault().update();
2283: }
2284: }
2285:
2286: // Sliding
2287:
2288: /** Adds mode into model and requests view (if needed). */
2289: public void addSlidingMode(ModeImpl mode, ModeImpl original,
2290: String side, Map<String, Integer> slideInSizes) {
2291: ModeImpl targetMode = model.getSlidingMode(side);
2292: if (targetMode != null) {
2293: //TODO what to do here.. something there already
2294: return;
2295: }
2296: targetMode = WindowManagerImpl.getInstance().createModeImpl(
2297: ModeImpl.getUnusedModeName(),
2298: Constants.MODE_KIND_SLIDING, false);
2299:
2300: model.addSlidingMode(mode, side, slideInSizes);
2301:
2302: if (isVisible()) {
2303: viewRequestor.scheduleRequest(new ViewRequest(null,
2304: View.CHANGE_MODE_ADDED, null, mode));
2305: }
2306:
2307: WindowManagerImpl.getInstance().doFirePropertyChange(
2308: WindowManager.PROP_MODES, null, null);
2309: }
2310:
2311: public void userEnabledAutoHide(TopComponent tc, ModeImpl source,
2312: String targetSide) {
2313: if (isViewMaximized())
2314: switchMaximizedMode(null);
2315:
2316: String tcID = WindowManagerImpl.getInstance()
2317: .findTopComponentID(tc);
2318: if (isEditorMaximized())
2319: setTopComponentDockedInMaximizedMode(tcID, false);
2320:
2321: slide(tc, source, targetSide);
2322: }
2323:
2324: /**
2325: * Slide out the given TopComponent
2326: */
2327: void slide(TopComponent tc, ModeImpl source, String targetSide) {
2328: ModeImpl targetMode = model.getSlidingMode(targetSide);
2329: if (targetMode == null) {
2330: targetMode = WindowManagerImpl.getInstance()
2331: .createModeImpl(ModeImpl.getUnusedModeName(),
2332: Constants.MODE_KIND_SLIDING, false);
2333: model.addSlidingMode(targetMode, targetSide, null);
2334: model.setModeBounds(targetMode, new Rectangle(tc
2335: .getBounds()));
2336: }
2337:
2338: ModeImpl oldActive = getActiveMode();
2339: moveTopComponentsIntoMode(targetMode, new TopComponent[] { tc });
2340: ModeImpl newActive = getActiveMode();
2341:
2342: if (isVisible()) {
2343: viewRequestor.scheduleRequest(new ViewRequest(null,
2344: View.CHANGE_TOPCOMPONENT_AUTO_HIDE_ENABLED, null,
2345: null));
2346: }
2347:
2348: if (oldActive != newActive) {
2349: WindowManagerImpl.getInstance().doFirePropertyChange(
2350: WindowManagerImpl.PROP_ACTIVE_MODE, oldActive,
2351: newActive);
2352: }
2353:
2354: // Notify new active.
2355: if (newActive != null) {
2356: // Notify registry.
2357: WindowManagerImpl
2358: .notifyRegistryTopComponentActivated(newActive
2359: .getSelectedTopComponent());
2360: } else {
2361: WindowManagerImpl.notifyRegistryTopComponentActivated(null);
2362: }
2363: }
2364:
2365: public void userResizedSlidingMode(ModeImpl mode, Rectangle rect) {
2366: model.setModeBounds(mode, new Rectangle(rect));
2367: //remember user's settings for the slided-in TopComponent size
2368: String side = model.getSlidingModeConstraints(mode);
2369: model.setSlideInSize(side, mode.getSelectedTopComponent(),
2370: Constants.BOTTOM.equals(side) ? rect.height
2371: : rect.width);
2372: if (null != mode.getSelectedTopComponent()) {
2373: String tcID = WindowManagerImpl.getInstance()
2374: .findTopComponentID(mode.getSelectedTopComponent());
2375: model.setTopComponentMaximizedWhenSlidedIn(tcID, false);
2376: }
2377: }
2378:
2379: public void userDisabledAutoHide(TopComponent tc, ModeImpl source) {
2380: // unmaximize if needed
2381: if (isViewMaximized()) {
2382: switchMaximizedMode(null);
2383: }
2384:
2385: String tcID = WindowManagerImpl.getInstance()
2386: .findTopComponentID(tc);
2387: if (isEditorMaximized())
2388: setTopComponentDockedInMaximizedMode(tcID, true);
2389:
2390: unSlide(tc, source);
2391: }
2392:
2393: /**
2394: * Cancel the sliding mode of the given TopComponent.
2395: */
2396: private void unSlide(TopComponent tc, ModeImpl source) {
2397: String tcID = WindowManagerImpl.getInstance()
2398: .findTopComponentID(tc);
2399:
2400: ModeImpl targetMode = model.getModeTopComponentPreviousMode(
2401: source, tcID);
2402: int targetIndex = model.getModeTopComponentPreviousIndex(
2403: source, tcID);
2404:
2405: if ((targetMode == null)
2406: || !model.getModes().contains(targetMode)) {
2407: // mode to return to isn't valid anymore, try constraints
2408: SplitConstraint[] constraints = model
2409: .getModeTopComponentPreviousConstraints(source,
2410: tcID);
2411: if (constraints != null) {
2412: // create mode with the same constraints to dock topcomponent back into
2413: targetMode = WindowManagerImpl.getInstance()
2414: .createModeImpl(ModeImpl.getUnusedModeName(),
2415: source.getKind(), false);
2416: model.addMode(targetMode, constraints);
2417: }
2418: }
2419:
2420: if (targetMode == null) {
2421: // fallback, previous saved mode not found somehow, use default modes
2422: targetMode = source.getKind() == Constants.MODE_KIND_EDITOR ? WindowManagerImpl
2423: .getInstance().getDefaultEditorMode()
2424: : WindowManagerImpl.getInstance()
2425: .getDefaultViewMode();
2426: }
2427:
2428: moveTopComponentsIntoMode(targetMode,
2429: new TopComponent[] { tc }, targetIndex);
2430:
2431: if (source.isEmpty()) {
2432: model.removeMode(source);
2433: }
2434:
2435: if (isVisible()) {
2436: viewRequestor.scheduleRequest(new ViewRequest(null,
2437: View.CHANGE_TOPCOMPONENT_AUTO_HIDE_DISABLED, null,
2438: null));
2439: }
2440: WindowManagerImpl.getInstance().doFirePropertyChange(
2441: WindowManagerImpl.PROP_ACTIVE_MODE, null,
2442: getActiveMode());
2443: }
2444:
2445: /**
2446: * @return The mode where the given TopComponent had been before it was moved to sliding or separate mode.
2447: */
2448: public ModeImpl getModeTopComponentPreviousMode(String tcID,
2449: ModeImpl currentSlidingMode) {
2450: return model.getModeTopComponentPreviousMode(
2451: currentSlidingMode, tcID);
2452: }
2453:
2454: /**
2455: * @return The position (tab index) of the given TopComponent before it was moved to sliding or separate mode.
2456: */
2457: public int getModeTopComponentPreviousIndex(String tcID,
2458: ModeImpl currentSlidingMode) {
2459: return model.getModeTopComponentPreviousIndex(
2460: currentSlidingMode, tcID);
2461: }
2462:
2463: /**
2464: * Remember the mode and position where the given TopComponent was before moving into sliding or separate mode.
2465: *
2466: * @param tcID TopComponent's id
2467: * @param currentSlidingMode The mode where the TopComponent is at the moment.
2468: * @param prevMode The mode where the TopComponent had been before it was moved to the sliding mode.
2469: * @param prevIndex Tab index of the TopComponent before it was moved to the new mode.
2470: */
2471: public void setModeTopComponentPreviousMode(String tcID,
2472: ModeImpl currentSlidingMode, ModeImpl prevMode,
2473: int prevIndex) {
2474: model.setModeTopComponentPreviousMode(currentSlidingMode, tcID,
2475: prevMode, prevIndex);
2476: }
2477:
2478: Map<String, Integer> getSlideInSizes(String side) {
2479: return model.getSlideInSizes(side);
2480: }
2481:
2482: /**
2483: * Set the state of the TopComponent when the editor is maximized.
2484: *
2485: * @param tcID TopComponent id
2486: * @param docked True if the TopComponent should stay docked in maximized editor mode,
2487: * false if it should slide out when the editor is maximized.
2488: */
2489: void setTopComponentDockedInMaximizedMode(String tcID,
2490: boolean docked) {
2491: if (docked)
2492: model.getMaximizedDockingStatus().addDocked(tcID);
2493: else
2494: model.getMaximizedDockingStatus().addSlided(tcID);
2495: }
2496:
2497: /**
2498: * Get the state of the TopComponent when the editor is maximized.
2499: *
2500: * @param tcID TopComponent id.
2501: * @return True if the TopComponent should stay docked in maximized editor mode,
2502: * false if it should slide out when the editor is maximized.
2503: */
2504: boolean isTopComponentDockedInMaximizedMode(String tcID) {
2505: return model.getMaximizedDockingStatus().isDocked(tcID);
2506: }
2507:
2508: /**
2509: * Set the state of the TopComponent when no mode is maximized.
2510: *
2511: * @param tcID TopComponent id
2512: * @param slided True if the TopComponent is slided in the default mode,
2513: * false if it is docked.
2514: */
2515: void setTopComponentSlidedInDefaultMode(String tcID, boolean slided) {
2516: if (slided)
2517: model.getDefaultDockingStatus().addSlided(tcID);
2518: else
2519: model.getDefaultDockingStatus().addDocked(tcID);
2520: }
2521:
2522: /**
2523: * Get the state of the TopComponent when it is slided-in.
2524: *
2525: * @param tcID TopComponent id.
2526: * @return true if the TopComponent is maximized when slided-in.
2527: */
2528: boolean isTopComponentMaximizedWhenSlidedIn(String tcID) {
2529: return model.isTopComponentMaximizedWhenSlidedIn(tcID);
2530: }
2531:
2532: /**
2533: * Set the state of the TopComponent when it is slided-in.
2534: *
2535: * @param tcID TopComponent id.
2536: * @param maximized true if the TopComponent is maximized when slided-in.
2537: */
2538: void setTopComponentMaximizedWhenSlidedIn(String tcID,
2539: boolean maximized) {
2540: model.setTopComponentMaximizedWhenSlidedIn(tcID, maximized);
2541: }
2542:
2543: void userToggledTopComponentSlideInMaximize(String tcID) {
2544: setTopComponentMaximizedWhenSlidedIn(tcID,
2545: !isTopComponentMaximizedWhenSlidedIn(tcID));
2546: if (isVisible()) {
2547: TopComponent tc = WindowManagerImpl.getInstance()
2548: .findTopComponent(tcID);
2549: ModeImpl mode = WindowManagerImpl.getInstance()
2550: .findModeForOpenedID(tcID);
2551: if (null != tc && null != mode && null != mode.getSide()) {
2552: viewRequestor.scheduleRequest(new ViewRequest(tc,
2553: View.CHANGE_MAXIMIZE_TOPCOMPONENT_SLIDE_IN,
2554: null, mode.getSide()));
2555: }
2556: }
2557: }
2558:
2559: /**
2560: * Get the state of the TopComponent when no mode is maximized.
2561: *
2562: * @param tcID TopComponent id.
2563: * @return True if the TopComponent is slided in the default mode,
2564: * false if it is docked.
2565: */
2566: boolean isTopComponentSlidedInDefaultMode(String tcID) {
2567: return model.getDefaultDockingStatus().isSlided(tcID);
2568: }
2569:
2570: boolean isEditorMaximized() {
2571: return null != model.getEditorMaximizedMode();
2572: }
2573:
2574: boolean isViewMaximized() {
2575: return null != model.getViewMaximizedMode();
2576: }
2577:
2578: /**
2579: * Slide-out or dock opened TopComponent according to their previous state.
2580: */
2581: private void restoreViews(DockingStatus viewStatus) {
2582: WindowManagerImpl wm = WindowManagerImpl.getInstance();
2583: Set<? extends Mode> modes = getModes();
2584: for (Iterator<? extends Mode> i = modes.iterator(); i.hasNext();) {
2585: ModeImpl modeImpl = (ModeImpl) i.next();
2586: if (modeImpl.getState() == Constants.MODE_STATE_SEPARATED)
2587: continue;
2588:
2589: if (modeImpl.getKind() == Constants.MODE_KIND_VIEW) {
2590: List<TopComponent> views = getModeOpenedTopComponents(modeImpl);
2591: Collections.reverse(views);
2592: for (Iterator<TopComponent> j = views.iterator(); j
2593: .hasNext();) {
2594: TopComponent tc = j.next();
2595: String tcID = wm.findTopComponentID(tc);
2596: if (viewStatus.shouldSlide(tcID)) {
2597: slide(tc, modeImpl, guessSlideSide(tc));
2598: }
2599: }
2600: } else if (modeImpl.getKind() == Constants.MODE_KIND_SLIDING) {
2601: List<TopComponent> views = getModeOpenedTopComponents(modeImpl);
2602: Collections.reverse(views);
2603: for (Iterator<TopComponent> j = views.iterator(); j
2604: .hasNext();) {
2605: TopComponent tc = j.next();
2606: String tcID = wm.findTopComponentID(tc);
2607: if (viewStatus.shouldDock(tcID)) {
2608: unSlide(tc, modeImpl);
2609: }
2610: }
2611: }
2612: }
2613:
2614: //now that all views are slided/restore make sure the right views are selected in each mode
2615: for (Iterator<? extends Mode> i = modes.iterator(); i.hasNext();) {
2616: ModeImpl modeImpl = (ModeImpl) i.next();
2617: if (modeImpl.getState() == Constants.MODE_STATE_SEPARATED)
2618: continue;
2619:
2620: if (modeImpl.getKind() == Constants.MODE_KIND_VIEW) {
2621: //make sure that the same view is selected as before
2622: TopComponent prevActiveTc = modeImpl
2623: .getPreviousSelectedTopComponent();
2624: if (null != prevActiveTc) {
2625: setModeSelectedTopComponent(modeImpl, prevActiveTc);
2626: }
2627: }
2628: }
2629: }
2630:
2631: /**
2632: * Slide out all non-editor TopComponents.
2633: */
2634: private void slideAllViews() {
2635: Set<? extends Mode> modes = getModes();
2636: for (Iterator<? extends Mode> i = modes.iterator(); i.hasNext();) {
2637: ModeImpl modeImpl = (ModeImpl) i.next();
2638: if (modeImpl.getKind() == Constants.MODE_KIND_VIEW
2639: && modeImpl != getViewMaximizedMode()
2640: && modeImpl.getState() != Constants.MODE_STATE_SEPARATED) {
2641: List<TopComponent> views = getModeOpenedTopComponents(modeImpl);
2642: Collections.reverse(views);
2643: for (Iterator<TopComponent> j = views.iterator(); j
2644: .hasNext();) {
2645: TopComponent tc = j.next();
2646: slide(tc, modeImpl, guessSlideSide(tc));
2647: }
2648: }
2649: }
2650: }
2651:
2652: // ControllerHandler <<
2653: ////////////////////////////
2654:
2655: private static void debugLog(String message) {
2656: Debug.log(Central.class, message);
2657: }
2658: }
|