KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > model > DefaultModeModel


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 package org.netbeans.core.windows.model;
21
22
23
24 import java.awt.*;
25 import java.util.List JavaDoc;
26
27 import org.netbeans.core.windows.ModeImpl;
28 import org.netbeans.core.windows.SplitConstraint;
29 import org.openide.windows.TopComponent;
30
31
32 /**
33  *
34  * @author Peter Zavadsky
35  */

36 final class DefaultModeModel implements ModeModel {
37
38
39     /** Programatic name of mode. */
40     private final String JavaDoc name;
41
42     private final Rectangle bounds = new Rectangle();
43
44     private final Rectangle boundsSeparetedHelp = new Rectangle();
45
46     /** State of mode: split or separate. */
47     private /*final*/ int state;
48     /** Kind of mode: editor or view. */
49     private final int kind;
50     
51     /** Frame state. */
52     private int frameState;
53
54     /** Permanent property. */
55     private final boolean permanent;
56
57     /** Sub model which manages TopComponents stuff. */
58     private final TopComponentSubModel topComponentSubModel;
59     
60     /** Context of tcx. Lazy initialization, because this will be used only by
61      * sliding kind of modes */

62     private TopComponentContextSubModel topComponentContextSubModel = null;
63
64     // Locks>>
65
/** */
66     private final Object JavaDoc LOCK_STATE = new Object JavaDoc();
67     /** */
68     private final Object JavaDoc LOCK_BOUNDS = new Object JavaDoc();
69     /** */
70     private final Object JavaDoc LOCK_BOUNDS_SEPARATED_HELP = new Object JavaDoc();
71     /** Locks frameState. */
72     private final Object JavaDoc LOCK_FRAMESTATE = new Object JavaDoc();
73     /** Locks top components. */
74     private final Object JavaDoc LOCK_TOPCOMPONENTS = new Object JavaDoc();
75     /** Locks tc contexts */
76     private final Object JavaDoc LOCK_TC_CONTEXTS = new Object JavaDoc();
77     
78     
79     public DefaultModeModel(String JavaDoc name, int state, int kind, boolean permanent) {
80         this.name = name;
81         this.state = state;
82         this.kind = kind;
83         this.permanent = permanent;
84         this.topComponentSubModel = new TopComponentSubModel(kind);
85     }
86
87     /////////////////////////////////////
88
// Mutator methods >>
89
/////////////////////////////////////
90
public void setState(int state) {
91         synchronized(LOCK_STATE) {
92             this.state = state;
93         }
94     }
95     
96     public void removeTopComponent(TopComponent tc) {
97         synchronized(LOCK_TOPCOMPONENTS) {
98             topComponentSubModel.removeTopComponent(tc);
99         }
100     }
101     
102     // XXX
103
public void removeClosedTopComponentID(String JavaDoc tcID) {
104         synchronized(LOCK_TOPCOMPONENTS) {
105             topComponentSubModel.removeClosedTopComponentID(tcID);
106         }
107     }
108     
109     /** Adds opened TopComponent. */
110     public void addOpenedTopComponent(TopComponent tc) {
111         synchronized(LOCK_TOPCOMPONENTS) {
112             topComponentSubModel.addOpenedTopComponent(tc);
113         }
114     }
115     
116     public void insertOpenedTopComponent(TopComponent tc, int index) {
117         synchronized(LOCK_TOPCOMPONENTS) {
118             topComponentSubModel.insertOpenedTopComponent(tc, index);
119         }
120     }
121     
122     public void addClosedTopComponent(TopComponent tc) {
123         synchronized(LOCK_TOPCOMPONENTS) {
124             topComponentSubModel.addClosedTopComponent(tc);
125         }
126     }
127     
128     public void addUnloadedTopComponent(String JavaDoc tcID) {
129         synchronized(LOCK_TOPCOMPONENTS) {
130             topComponentSubModel.addUnloadedTopComponent(tcID);
131         }
132     }
133     
134     public void setUnloadedSelectedTopComponent(String JavaDoc tcID) {
135         synchronized(LOCK_TOPCOMPONENTS) {
136             topComponentSubModel.setUnloadedSelectedTopComponent(tcID);
137         }
138     }
139     
140     public void setUnloadedPreviousSelectedTopComponent(String JavaDoc tcID) {
141         synchronized(LOCK_TOPCOMPONENTS) {
142             topComponentSubModel.setUnloadedPreviousSelectedTopComponent(tcID);
143         }
144     }
145     
146     /** Sets seleted TopComponent. */
147     public void setSelectedTopComponent(TopComponent selected) {
148         synchronized(LOCK_TOPCOMPONENTS) {
149             topComponentSubModel.setSelectedTopComponent(selected);
150         }
151     }
152     
153     public void setPreviousSelectedTopComponent(TopComponent prevSelected) {
154         synchronized(LOCK_TOPCOMPONENTS) {
155             topComponentSubModel.setPreviousSelectedTopComponent(prevSelected);
156         }
157     }
158
159     /** Sets frame state */
160     public void setFrameState(int frameState) {
161         synchronized(LOCK_FRAMESTATE) {
162             this.frameState = frameState;
163         }
164     }
165
166     public void setBounds(Rectangle bounds) {
167         if(bounds == null) {
168             return;
169         }
170         
171         synchronized(LOCK_BOUNDS) {
172             this.bounds.setBounds(bounds);
173         }
174     }
175     
176     public void setBoundsSeparatedHelp(Rectangle boundsSeparatedHelp) {
177         if(bounds == null) {
178             return;
179         }
180         
181         synchronized(LOCK_BOUNDS_SEPARATED_HELP) {
182             this.boundsSeparetedHelp.setBounds(boundsSeparatedHelp);
183         }
184     }
185     /////////////////////////////////////
186
// Mutator methods <<
187
/////////////////////////////////////
188

189
190     /////////////////////////////////////
191
// Accessor methods >>
192
/////////////////////////////////////
193
public String JavaDoc getName() {
194         return name;
195     }
196     
197     public Rectangle getBounds() {
198         synchronized(LOCK_BOUNDS) {
199             return (Rectangle)this.bounds.clone();
200         }
201     }
202     
203     public Rectangle getBoundsSeparatedHelp() {
204         synchronized(LOCK_BOUNDS_SEPARATED_HELP) {
205             return (Rectangle)this.boundsSeparetedHelp.clone();
206         }
207     }
208     
209     public int getState() {
210         synchronized(LOCK_STATE) {
211             return this.state;
212         }
213     }
214     
215     public int getKind() {
216         return this.kind;
217     }
218     
219     /** Gets frame state. */
220     public int getFrameState() {
221         synchronized(LOCK_FRAMESTATE) {
222             return this.frameState;
223         }
224     }
225     
226     public boolean isPermanent() {
227         return this.permanent;
228     }
229     
230     public boolean isEmpty() {
231         synchronized(LOCK_TOPCOMPONENTS) {
232             return topComponentSubModel.isEmpty();
233         }
234     }
235     
236     public boolean containsTopComponent(TopComponent tc) {
237         synchronized(LOCK_TOPCOMPONENTS) {
238             return topComponentSubModel.containsTopComponent(tc);
239         }
240     }
241
242     /** Gets list of top components in this workspace. */
243     public List JavaDoc<TopComponent> getTopComponents() {
244         synchronized(LOCK_TOPCOMPONENTS) {
245             return topComponentSubModel.getTopComponents();
246         }
247     }
248
249
250     /** Gets selected TopComponent. */
251     public TopComponent getSelectedTopComponent() {
252         synchronized(LOCK_TOPCOMPONENTS) {
253             return topComponentSubModel.getSelectedTopComponent();
254         }
255     }
256     /** Gets the top component that was selected before switching to/from maximized mode */
257     public TopComponent getPreviousSelectedTopComponent() {
258         synchronized(LOCK_TOPCOMPONENTS) {
259             return topComponentSubModel.getPreviousSelectedTopComponent();
260         }
261     }
262
263     /** Gets list of top components. */
264     public List JavaDoc<TopComponent> getOpenedTopComponents() {
265         synchronized(LOCK_TOPCOMPONENTS) {
266             return topComponentSubModel.getOpenedTopComponents();
267         }
268     }
269     
270     // XXX
271
public List JavaDoc<String JavaDoc> getOpenedTopComponentsIDs() {
272         synchronized(LOCK_TOPCOMPONENTS) {
273             return topComponentSubModel.getOpenedTopComponentsIDs();
274         }
275     }
276     
277     public List JavaDoc<String JavaDoc> getClosedTopComponentsIDs() {
278         synchronized(LOCK_TOPCOMPONENTS) {
279             return topComponentSubModel.getClosedTopComponentsIDs();
280         }
281     }
282     
283     public List JavaDoc<String JavaDoc> getTopComponentsIDs() {
284         synchronized(LOCK_TOPCOMPONENTS) {
285             return topComponentSubModel.getTopComponentsIDs();
286         }
287     }
288     
289     public SplitConstraint[] getTopComponentPreviousConstraints(String JavaDoc tcID) {
290         synchronized(LOCK_TC_CONTEXTS) {
291             return getContextSubModel().getTopComponentPreviousConstraints(tcID);
292         }
293     }
294     
295     public ModeImpl getTopComponentPreviousMode(String JavaDoc tcID) {
296         synchronized(LOCK_TC_CONTEXTS) {
297             return getContextSubModel().getTopComponentPreviousMode(tcID);
298         }
299     }
300     /** Gets the tab index of the top component in its previous mode */
301     public int getTopComponentPreviousIndex(String JavaDoc tcID) {
302         synchronized(LOCK_TC_CONTEXTS) {
303             return getContextSubModel().getTopComponentPreviousIndex(tcID);
304         }
305     }
306     
307     public void setTopComponentPreviousConstraints(String JavaDoc tcID, SplitConstraint[] constraints) {
308         synchronized(LOCK_TC_CONTEXTS) {
309             getContextSubModel().setTopComponentPreviousConstraints(tcID, constraints);
310         }
311     }
312     
313     public void setTopComponentPreviousMode(String JavaDoc tcID, ModeImpl mode, int prevIndex) {
314         synchronized(LOCK_TC_CONTEXTS) {
315             getContextSubModel().setTopComponentPreviousMode(tcID, mode, prevIndex);
316         }
317     }
318     
319     /////////////////////////////////////
320
// Accessor methods <<
321
/////////////////////////////////////
322

323     private TopComponentContextSubModel getContextSubModel() {
324         if (topComponentContextSubModel == null) {
325             topComponentContextSubModel = new TopComponentContextSubModel();
326         }
327         return topComponentContextSubModel;
328     }
329     
330 }
331
332
Popular Tags