KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ModeView


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.core.windows.view;
22
23
24 import org.netbeans.core.windows.WindowManagerImpl;
25 import org.netbeans.core.windows.view.dnd.WindowDnDManager;
26 import org.netbeans.core.windows.view.ui.DefaultSeparateContainer;
27 import org.netbeans.core.windows.view.ui.DefaultSplitContainer;
28 import org.netbeans.core.windows.WindowManagerImpl;
29 import org.netbeans.core.windows.view.ui.slides.SlideBarContainer;
30 import org.openide.windows.TopComponent;
31
32 import java.awt.*;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Arrays JavaDoc;
35 import java.util.List JavaDoc;
36 import javax.swing.JComponent JavaDoc;
37
38
39 /**
40  * Class which represents model of mode element for GUI hierarchy.
41  *
42  * @author Peter Zavadsky
43  */

44 public class ModeView extends ViewElement {
45     //mkleint - made protected non-final because of SlidingView constructor..
46
protected ModeContainer container;
47
48     // PENDING it is valid only for separate mode, consider create of two classes
49
// of view, one for split, and second one for separate mode type.
50
private int frameState;
51
52     // PENDING devide into two subclasses?
53
// Split mode view constructor
54
public ModeView(Controller controller, WindowDnDManager windowDnDManager,
55     double resizeWeight, int kind, TopComponent[] topComponents, TopComponent selectedTopComponent) {
56         super(controller, resizeWeight);
57         
58         container = new DefaultSplitContainer(this, windowDnDManager, kind);
59         
60         setTopComponents(topComponents, selectedTopComponent);
61     }
62     
63     // Separate mode view constructor
64
public ModeView(Controller controller, WindowDnDManager windowDnDManager, Rectangle bounds, int kind, int frameState,
65     TopComponent[] topComponents, TopComponent selectedTopComponent) {
66         super(controller, 0D);
67         
68         this.frameState = frameState;
69         
70         container = new DefaultSeparateContainer(this, windowDnDManager, bounds, kind);
71         
72         setTopComponents(topComponents, selectedTopComponent);
73     }
74
75     /** Specialized constructor for SlidingView.
76      */

77     protected ModeView(Controller controller) {
78     super(controller, 0D);
79         //mkleint - moved to SlidingView - "side" needs to be initialized first..
80
// this.container = new SlideBarContainer(this, windowDnDManager);
81

82 // setTopComponents(topComponents, selectedTopComponent);
83
}
84     
85     
86     public void setFrameState(int frameState) {
87      // All the timestamping is a a workaround beause of buggy GNOME and of its kind who iconify the windows on leaving the desktop.
88
this.frameState = frameState;
89         Component comp = container.getComponent();
90         if(comp instanceof Frame) {
91             if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) {
92                 timeStamp = System.currentTimeMillis();
93             } else {
94                 timeStamp = 0;
95             }
96         }
97     }
98
99     
100 // public void addTopComponent(TopComponent tc) {
101
// if(getTopComponents().contains(tc)) {
102
// return;
103
// }
104
// container.addTopComponent(tc);
105
// }
106

107     public void removeTopComponent(TopComponent tc) {
108         if(!getTopComponents().contains(tc)) {
109             return;
110         }
111         container.removeTopComponent(tc);
112     }
113     
114     public void setTopComponents(TopComponent[] tcs, TopComponent select) {
115         container.setTopComponents(tcs, select);
116     }
117     
118 // public void setSelectedTopComponent(TopComponent tc) {
119
// container.setSelectedTopComponent(tc);
120
// }
121

122     public TopComponent getSelectedTopComponent() {
123         return container.getSelectedTopComponent();
124     }
125     
126     public void setActive(boolean active) {
127         container.setActive(active);
128     }
129     
130     public boolean isActive() {
131         return container.isActive();
132     }
133     
134     public List JavaDoc<TopComponent> getTopComponents() {
135         return new ArrayList JavaDoc<TopComponent>(Arrays.asList(container.getTopComponents()));
136     }
137     
138     public void focusSelectedTopComponent() {
139         container.focusSelectedTopComponent();
140     }
141     
142     public Component getComponent() {
143         return container.getComponent();
144     }
145     
146     public void updateName(TopComponent tc) {
147         container.updateName(tc);
148     }
149     
150     public void updateToolTip(TopComponent tc) {
151         container.updateToolTip(tc);
152     }
153     
154     public void updateIcon(TopComponent tc) {
155         container.updateIcon(tc);
156     }
157     
158     public void requestAttention (TopComponent tc) {
159         container.requestAttention(tc);
160     }
161
162     public void cancelRequestAttention (TopComponent tc) {
163         container.cancelRequestAttention(tc);
164     }
165
166     // XXX
167
public void updateFrameState() {
168         Component comp = container.getComponent();
169         if(comp instanceof Frame) {
170             ((Frame)comp).setExtendedState(frameState);
171         }
172     }
173     
174     private long timeStamp = 0;
175     
176     public void setUserStamp(long stamp) {
177         timeStamp = stamp;
178     }
179     
180     public long getUserStamp() {
181         return timeStamp;
182     }
183     
184     private long mainWindowStamp = 0;
185     
186     public void setMainWindowStamp(long stamp) {
187         mainWindowStamp = stamp;
188     }
189     
190     public long getMainWindowStamp() {
191         return mainWindowStamp;
192     }
193     
194     public String JavaDoc toString() {
195         TopComponent selected = container.getSelectedTopComponent();
196         return super.toString() + " [selected=" // NOI18N
197
+ (selected == null ? null : WindowManagerImpl.getInstance().getTopComponentDisplayName(selected)) + "]"; // NOI18N
198
}
199
200     public boolean updateAWTHierarchy(Dimension availableSpace) {
201         // nothing needs to be done here?
202
// System.out.println("ModeView:updateAWTHierarchy=" + availableSpace);
203
Component comp = container.getComponent();
204         boolean result = false;
205         if (comp instanceof JComponent JavaDoc) {
206             //We don't want to force the component to *calculate* its preferred
207
//size, as that is often expensive and we're not interested in the
208
//result anyway
209
Dimension d = (Dimension) ((JComponent JavaDoc) comp).getClientProperty ("lastAvailableSpace"); //NOI18N
210
Dimension currDim = comp.getPreferredSize();
211             if (!availableSpace.equals(d) || !availableSpace.equals(currDim)) {
212                 //We will only return true if we actually did something
213
((JComponent JavaDoc)comp).setPreferredSize(availableSpace);
214                 ((JComponent JavaDoc)comp).putClientProperty("lastAvailableSpace", availableSpace); //NOI18N
215
result = true;
216             }
217         }
218         return result;
219     }
220     
221     
222 }
223
224
Popular Tags