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.slides;
043:
044: import java.awt.BorderLayout;
045: import java.awt.Component;
046: import java.awt.Dimension;
047: import java.awt.Insets;
048: import java.awt.Point;
049: import java.awt.Rectangle;
050: import java.awt.Shape;
051: import java.awt.Window;
052: import javax.swing.JPanel;
053: import javax.swing.SwingUtilities;
054: import javax.swing.border.Border;
055: import javax.swing.border.EmptyBorder;
056: import org.netbeans.core.windows.Constants;
057: import org.netbeans.core.windows.WindowManagerImpl;
058: import org.netbeans.core.windows.view.ModeView;
059: import org.netbeans.core.windows.view.SlidingView;
060: import org.netbeans.core.windows.view.ViewElement;
061: import org.netbeans.core.windows.view.dnd.WindowDnDManager;
062: import org.netbeans.core.windows.view.ui.AbstractModeContainer;
063: import org.netbeans.core.windows.view.ui.ModeComponent;
064: import org.netbeans.core.windows.view.dnd.TopComponentDroppable;
065: import org.netbeans.core.windows.view.ui.Tabbed;
066: import org.openide.windows.TopComponent;
067:
068: /*
069: * SlideBarContainer.java
070: *
071: * @author Dafe Simonek
072: */
073: public final class SlideBarContainer extends AbstractModeContainer {
074:
075: /** panel displaying content of this container */
076: VisualPanel panel;
077:
078: /** Creates a new instance of SlideBarContainer */
079: public SlideBarContainer(ModeView modeView,
080: WindowDnDManager windowDnDManager) {
081: super (modeView, windowDnDManager, Constants.MODE_KIND_SLIDING);
082:
083: panel = new VisualPanel(this );
084: panel.setBorder(computeBorder(getSlidingView().getSide()));
085: panel.add(this .tabbedHandler.getComponent(),
086: BorderLayout.CENTER);
087: }
088:
089: private SlidingView getSlidingView() {
090: return (SlidingView) super .getModeView();
091: }
092:
093: public void requestAttention(TopComponent tc) {
094: tabbedHandler.requestAttention(tc);
095: }
096:
097: public void cancelRequestAttention(TopComponent tc) {
098: tabbedHandler.cancelRequestAttention(tc);
099: }
100:
101: public void setTopComponents(TopComponent[] tcs,
102: TopComponent selected) {
103: super .setTopComponents(tcs, selected);
104: }
105:
106: public Rectangle getTabBounds(int tabIndex) {
107: return tabbedHandler.getTabBounds(tabIndex);
108: }
109:
110: protected Component getModeComponent() {
111: return panel;
112: }
113:
114: protected Tabbed createTabbed() {
115: return new TabbedSlideAdapter(((SlidingView) modeView)
116: .getSide());
117: }
118:
119: protected boolean isAttachingPossible() {
120: return false;
121: }
122:
123: protected TopComponentDroppable getModeDroppable() {
124: return panel;
125: }
126:
127: protected void updateActive(boolean active) {
128: // #48588 - when in SDI, slidein needs to front the editor frame.
129: if (active) {
130: Window window = SwingUtilities.getWindowAncestor(panel);
131: if (window != null
132: && !window.isActive()
133: && WindowManagerImpl.getInstance()
134: .getEditorAreaState() == Constants.EDITOR_AREA_SEPARATED) {
135: window.toFront();
136: }
137: }
138: }
139:
140: public boolean isActive() {
141: Window window = SwingUtilities.getWindowAncestor(panel);
142: // #54791 - just a doublecheck, IMHO should not happen anymore
143: // after the winsys reenetrancy fix.
144: return window == null ? false : window.isActive();
145: }
146:
147: protected void updateTitle(String title) {
148: // XXX - we have no title?
149: }
150:
151: /** Builds empty border around slide bar. Computes its correct size
152: * based on given orientation
153: */
154: private static Border computeBorder(String orientation) {
155: int bottom = 0, left = 0, right = 0, top = 0;
156: if (Constants.LEFT.equals(orientation)) {
157: top = 1;
158: left = 1;
159: bottom = 1;
160: right = 2;
161: }
162: if (Constants.BOTTOM.equals(orientation)) {
163: top = 2;
164: left = 1;
165: bottom = 1;
166: right = 1;
167: }
168: if (Constants.RIGHT.equals(orientation)) {
169: top = 1;
170: left = 2;
171: bottom = 1;
172: right = 1;
173: }
174: return new EmptyBorder(top, left, bottom, right);
175: }
176:
177: /** Component enclosing slide boxes, implements needed interfaces to talk
178: * to rest of winsys
179: */
180: private static class VisualPanel extends JPanel implements
181: ModeComponent, TopComponentDroppable {
182:
183: private final SlideBarContainer modeContainer;
184:
185: public VisualPanel(SlideBarContainer modeContainer) {
186: super (new BorderLayout());
187: this .modeContainer = modeContainer;
188: // To be able to activate on mouse click.
189: enableEvents(java.awt.AWTEvent.MOUSE_EVENT_MASK);
190: }
191:
192: public ModeView getModeView() {
193: return modeContainer.getModeView();
194: }
195:
196: public int getKind() {
197: return modeContainer.getKind();
198: }
199:
200: // TopComponentDroppable>>
201: public Shape getIndicationForLocation(Point location) {
202: return modeContainer.getIndicationForLocation(location);
203: }
204:
205: public Object getConstraintForLocation(Point location) {
206: return modeContainer.getConstraintForLocation(location);
207: }
208:
209: public Component getDropComponent() {
210: return modeContainer.getDropComponent();
211: }
212:
213: public ViewElement getDropViewElement() {
214: return modeContainer.getDropModeView();
215: }
216:
217: public boolean canDrop(TopComponent transfer, Point location) {
218: return modeContainer.canDrop(transfer);
219: }
220:
221: public boolean supportsKind(int kind, TopComponent transfer) {
222: if (Constants.SWITCH_MODE_ADD_NO_RESTRICT
223: || WindowManagerImpl.getInstance()
224: .isTopComponentAllowedToMoveAnywhere(
225: transfer)) {
226: return true;
227: }
228: boolean isNonEditor = kind == Constants.MODE_KIND_VIEW
229: || kind == Constants.MODE_KIND_SLIDING;
230: boolean this IsNonEditor = getKind() == Constants.MODE_KIND_VIEW
231: || getKind() == Constants.MODE_KIND_SLIDING;
232:
233: return (isNonEditor == this IsNonEditor);
234: }
235:
236: // TopComponentDroppable<<
237:
238: public Dimension getMinimumSize() {
239: if (modeContainer.getTopComponents().length == 0) {
240: // have minimum size, to avoid gridbag layout to place the empty component at [0,0] location.
241: // clashes with the dnd
242: Border b = getBorder();
243: if (null != b) {
244: Insets insets = b.getBorderInsets(this );
245: return new Dimension(Math.max(1, insets.left
246: + insets.right), Math.max(1, insets.top
247: + insets.bottom));
248: }
249: return new Dimension(1, 1);
250: }
251: Dimension retValue;
252: retValue = super .getMinimumSize();
253: return retValue;
254: }
255:
256: } // End of VisualPanel
257:
258: }
|