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;
043:
044: import org.netbeans.core.windows.WindowManagerImpl;
045: import org.netbeans.core.windows.view.dnd.WindowDnDManager;
046: import org.netbeans.core.windows.view.ui.DefaultSeparateContainer;
047: import org.netbeans.core.windows.view.ui.DefaultSplitContainer;
048: import org.netbeans.core.windows.WindowManagerImpl;
049: import org.netbeans.core.windows.view.ui.slides.SlideBarContainer;
050: import org.openide.windows.TopComponent;
051:
052: import java.awt.*;
053: import java.util.ArrayList;
054: import java.util.Arrays;
055: import java.util.List;
056: import javax.swing.JComponent;
057:
058: /**
059: * Class which represents model of mode element for GUI hierarchy.
060: *
061: * @author Peter Zavadsky
062: */
063: public class ModeView extends ViewElement {
064: //mkleint - made protected non-final because of SlidingView constructor..
065: protected ModeContainer container;
066:
067: // PENDING it is valid only for separate mode, consider create of two classes
068: // of view, one for split, and second one for separate mode type.
069: private int frameState;
070:
071: // PENDING devide into two subclasses?
072: // Split mode view constructor
073: public ModeView(Controller controller,
074: WindowDnDManager windowDnDManager, double resizeWeight,
075: int kind, TopComponent[] topComponents,
076: TopComponent selectedTopComponent) {
077: super (controller, resizeWeight);
078:
079: container = new DefaultSplitContainer(this , windowDnDManager,
080: kind);
081:
082: setTopComponents(topComponents, selectedTopComponent);
083: }
084:
085: // Separate mode view constructor
086: public ModeView(Controller controller,
087: WindowDnDManager windowDnDManager, Rectangle bounds,
088: int kind, int frameState, TopComponent[] topComponents,
089: TopComponent selectedTopComponent) {
090: super (controller, 0D);
091:
092: this .frameState = frameState;
093:
094: container = new DefaultSeparateContainer(this ,
095: windowDnDManager, bounds, kind);
096:
097: setTopComponents(topComponents, selectedTopComponent);
098: }
099:
100: /** Specialized constructor for SlidingView.
101: */
102: protected ModeView(Controller controller) {
103: super (controller, 0D);
104: //mkleint - moved to SlidingView - "side" needs to be initialized first..
105: // this.container = new SlideBarContainer(this, windowDnDManager);
106:
107: // setTopComponents(topComponents, selectedTopComponent);
108: }
109:
110: public void setFrameState(int frameState) {
111: // All the timestamping is a a workaround beause of buggy GNOME and of its kind who iconify the windows on leaving the desktop.
112: this .frameState = frameState;
113: Component comp = container.getComponent();
114: if (comp instanceof Frame) {
115: if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
116: timeStamp = System.currentTimeMillis();
117: } else {
118: timeStamp = 0;
119: }
120: }
121: }
122:
123: // public void addTopComponent(TopComponent tc) {
124: // if(getTopComponents().contains(tc)) {
125: // return;
126: // }
127: // container.addTopComponent(tc);
128: // }
129:
130: public void removeTopComponent(TopComponent tc) {
131: if (!getTopComponents().contains(tc)) {
132: return;
133: }
134: container.removeTopComponent(tc);
135: }
136:
137: public void setTopComponents(TopComponent[] tcs, TopComponent select) {
138: container.setTopComponents(tcs, select);
139: }
140:
141: // public void setSelectedTopComponent(TopComponent tc) {
142: // container.setSelectedTopComponent(tc);
143: // }
144:
145: public TopComponent getSelectedTopComponent() {
146: return container.getSelectedTopComponent();
147: }
148:
149: public void setActive(boolean active) {
150: container.setActive(active);
151: }
152:
153: public boolean isActive() {
154: return container.isActive();
155: }
156:
157: public List<TopComponent> getTopComponents() {
158: return new ArrayList<TopComponent>(Arrays.asList(container
159: .getTopComponents()));
160: }
161:
162: public void focusSelectedTopComponent() {
163: container.focusSelectedTopComponent();
164: }
165:
166: public Component getComponent() {
167: return container.getComponent();
168: }
169:
170: public void updateName(TopComponent tc) {
171: container.updateName(tc);
172: }
173:
174: public void updateToolTip(TopComponent tc) {
175: container.updateToolTip(tc);
176: }
177:
178: public void updateIcon(TopComponent tc) {
179: container.updateIcon(tc);
180: }
181:
182: public void requestAttention(TopComponent tc) {
183: container.requestAttention(tc);
184: }
185:
186: public void cancelRequestAttention(TopComponent tc) {
187: container.cancelRequestAttention(tc);
188: }
189:
190: // XXX
191: public void updateFrameState() {
192: Component comp = container.getComponent();
193: if (comp instanceof Frame) {
194: ((Frame) comp).setExtendedState(frameState);
195: }
196: }
197:
198: private long timeStamp = 0;
199:
200: public void setUserStamp(long stamp) {
201: timeStamp = stamp;
202: }
203:
204: public long getUserStamp() {
205: return timeStamp;
206: }
207:
208: private long mainWindowStamp = 0;
209:
210: public void setMainWindowStamp(long stamp) {
211: mainWindowStamp = stamp;
212: }
213:
214: public long getMainWindowStamp() {
215: return mainWindowStamp;
216: }
217:
218: public String toString() {
219: TopComponent selected = container.getSelectedTopComponent();
220: return super .toString()
221: + " [selected=" // NOI18N
222: + (selected == null ? null : WindowManagerImpl
223: .getInstance().getTopComponentDisplayName(
224: selected)) + "]"; // NOI18N
225: }
226:
227: public boolean updateAWTHierarchy(Dimension availableSpace) {
228: // nothing needs to be done here?
229: // System.out.println("ModeView:updateAWTHierarchy=" + availableSpace);
230: Component comp = container.getComponent();
231: boolean result = false;
232: if (comp instanceof JComponent) {
233: //We don't want to force the component to *calculate* its preferred
234: //size, as that is often expensive and we're not interested in the
235: //result anyway
236: Dimension d = (Dimension) ((JComponent) comp)
237: .getClientProperty("lastAvailableSpace"); //NOI18N
238: Dimension currDim = comp.getPreferredSize();
239: if (!availableSpace.equals(d)
240: || !availableSpace.equals(currDim)) {
241: //We will only return true if we actually did something
242: ((JComponent) comp).setPreferredSize(availableSpace);
243: ((JComponent) comp).putClientProperty(
244: "lastAvailableSpace", availableSpace); //NOI18N
245: result = true;
246: }
247: }
248: return result;
249: }
250:
251: }
|