001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.core.windows.view.ui;
043:
044: import org.netbeans.core.windows.Constants;
045: import org.netbeans.core.windows.WindowManagerImpl;
046: import org.netbeans.core.windows.view.ModeView;
047: import org.netbeans.core.windows.view.ViewElement;
048: import org.netbeans.core.windows.view.dnd.TopComponentDroppable;
049: import org.netbeans.core.windows.view.dnd.WindowDnDManager;
050: import org.netbeans.core.windows.view.ui.tabcontrol.TabbedAdapter;
051: import org.openide.windows.TopComponent;
052:
053: import javax.swing.*;
054: import java.awt.*;
055:
056: /**
057: * Implementation of <code>ModeContainer</code> for joined mode kind.
058: *
059: * @author Peter Zavadsky
060: */
061: public final class DefaultSplitContainer extends AbstractModeContainer {
062:
063: /** JPanel instance representing split mode. */
064: private final JPanel panel;
065:
066: /** Creates a DefaultSeparateContainer. */
067: public DefaultSplitContainer(ModeView modeView,
068: WindowDnDManager windowDnDManager, int kind) {
069: super (modeView, windowDnDManager, kind);
070:
071: panel = new ModePanel(this );
072:
073: panel.add(this .tabbedHandler.getComponent(),
074: BorderLayout.CENTER);
075:
076: // To be able to move split dividers.
077: panel.setMinimumSize(new Dimension(1, 1));
078: }
079:
080: public void requestAttention(TopComponent tc) {
081: tabbedHandler.requestAttention(tc);
082: }
083:
084: public void cancelRequestAttention(TopComponent tc) {
085: tabbedHandler.cancelRequestAttention(tc);
086: }
087:
088: /** */
089: protected Component getModeComponent() {
090: return panel;
091: }
092:
093: protected Tabbed createTabbed() {
094: Tabbed tabbed;
095: if (getKind() == Constants.MODE_KIND_EDITOR) {
096: tabbed = new TabbedAdapter(Constants.MODE_KIND_EDITOR);
097: } else {
098: tabbed = new TabbedAdapter(Constants.MODE_KIND_VIEW);
099: }
100: return tabbed;
101: }
102:
103: protected void updateTitle(String title) {
104: // no op
105: }
106:
107: protected void updateActive(boolean active) {
108: if (active) {
109: Window window = SwingUtilities.getWindowAncestor(panel);
110: if (window != null
111: && !window.isActive()
112: && WindowManagerImpl.getInstance()
113: .getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) {
114: // only front in SDI, in MID assume that it's either active or user doens't want it active..
115: window.toFront();
116: }
117: }
118: }
119:
120: public boolean isActive() {
121: Window window = SwingUtilities.getWindowAncestor(panel);
122: // #54791 and #56613 - just a doublecheck, IMHO should not happen anymore
123: // after the winsys reenetrancy fix.
124: return window != null ? window.isActive() : false;
125: }
126:
127: protected boolean isAttachingPossible() {
128: return true;
129: }
130:
131: protected TopComponentDroppable getModeDroppable() {
132: return (ModePanel) panel;
133: }
134:
135: /** */
136: private static class ModePanel extends JPanel implements
137: ModeComponent, TopComponentDroppable {
138:
139: private final AbstractModeContainer abstractModeContainer;
140:
141: public ModePanel(AbstractModeContainer abstractModeContainer) {
142: super (new BorderLayout());
143: this .abstractModeContainer = abstractModeContainer;
144: // To be able to activate on mouse click.
145: enableEvents(java.awt.AWTEvent.MOUSE_EVENT_MASK);
146: // Color fillC = (Color)UIManager.get("nb_workplace_fill"); //NOI18N
147: // if (fillC != null) setBackground (fillC);
148: }
149:
150: public ModeView getModeView() {
151: return abstractModeContainer.getModeView();
152: }
153:
154: public int getKind() {
155: return abstractModeContainer.getKind();
156: }
157:
158: // TopComponentDroppable>>
159: public Shape getIndicationForLocation(Point location) {
160: return abstractModeContainer
161: .getIndicationForLocation(location);
162: }
163:
164: public Object getConstraintForLocation(Point location) {
165: return abstractModeContainer
166: .getConstraintForLocation(location);
167: }
168:
169: public Component getDropComponent() {
170: return abstractModeContainer.getDropComponent();
171: }
172:
173: public ViewElement getDropViewElement() {
174: return abstractModeContainer.getDropModeView();
175: }
176:
177: public boolean canDrop(TopComponent transfer, Point location) {
178: return abstractModeContainer.canDrop(transfer);
179: }
180:
181: public boolean supportsKind(int kind, TopComponent transfer) {
182: if (Constants.SWITCH_MODE_ADD_NO_RESTRICT
183: || WindowManagerImpl.getInstance()
184: .isTopComponentAllowedToMoveAnywhere(
185: transfer)) {
186: return true;
187: }
188:
189: boolean isNonEditor = kind == Constants.MODE_KIND_VIEW
190: || kind == Constants.MODE_KIND_SLIDING;
191: boolean this IsNonEditor = getKind() == Constants.MODE_KIND_VIEW
192: || getKind() == Constants.MODE_KIND_SLIDING;
193:
194: return (isNonEditor == this IsNonEditor);
195:
196: }
197: // TopComponentDroppable<<
198: } // End of ModePanel.
199: }
|