KickJava   Java API By Example, From Geeks To Geeks.

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


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.model;
22
23
24
25 import java.awt.Frame JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import java.lang.ref.Reference JavaDoc;
28 import java.lang.ref.WeakReference JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Collections JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Set JavaDoc;
36 import java.util.WeakHashMap JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39 import org.netbeans.core.windows.Constants;
40 import org.netbeans.core.windows.ModeImpl;
41 import org.netbeans.core.windows.ModeStructureSnapshot;
42 import org.netbeans.core.windows.SplitConstraint;
43 import org.netbeans.core.windows.TopComponentGroupImpl;
44 import org.netbeans.core.windows.WindowSystemSnapshot;
45 import org.openide.windows.TopComponent;
46
47
48 /**
49  *
50  * @author Peter Zavadsky
51  */

52 final class DefaultModel implements Model {
53
54     /** ModeImpl to ModeModel. */
55     private final Map JavaDoc<ModeImpl, ModeModel> mode2model =
56             new WeakHashMap JavaDoc<ModeImpl, ModeModel>(10);
57     /** TopComponentGroup to TopComponentGroupModel. */
58     private final Map JavaDoc<TopComponentGroupImpl, TopComponentGroupModel> group2model =
59             new WeakHashMap JavaDoc<TopComponentGroupImpl, TopComponentGroupModel>(10);
60     
61     /** Whether the current winsys is visible on the screen.
62      * 'The most important' property of all winsys. */

63     private boolean visible = false;
64
65     /** Bounds of main window when the editor area state is joined (tiled). */
66     private final Rectangle JavaDoc mainWindowBoundsJoined = new Rectangle JavaDoc();
67     /** Bounds of main window when the editor area state is separated. */
68     private final Rectangle JavaDoc mainWindowBoundsSeparated = new Rectangle JavaDoc();
69     /** Keeps initial value of separated bounds (helper non-serializable variable). */
70     private final Rectangle JavaDoc mainWindowBoundsSeparatedHelp = new Rectangle JavaDoc();
71
72     /** */
73     private int mainWindowFrameStateJoined = Frame.NORMAL;
74     /** */
75     private int mainWindowFrameStateSeparated = Frame.NORMAL;
76     
77     /** State of editor area. 1 = joined, 2 = separated */
78     private int editorAreaState = Constants.EDITOR_AREA_JOINED;
79     /** Bounds of editor area. */
80     private final Rectangle JavaDoc editorAreaBounds = new Rectangle JavaDoc();
81     /** Keeps initial value of editor area (helper non-serializable variable). */
82     private final Rectangle JavaDoc editorAreaBoundsHelp = new Rectangle JavaDoc();
83     /** */
84     private int editorAreaFrameState = Frame.NORMAL;
85     /** Name of toolbars configuration. */
86     private String JavaDoc toolbarConfigName = "Standard"; // NOI18N
87
/** The docking status (slided-out/docked) for TopComponents in maximized editor mode */
88     private DockingStatus maximizedDockingStatus = new DockingStatus( this );
89     /** The docking status (slided-out/docked) for TopComponents in the default mode (nothing is maximized)*/
90     private DockingStatus defaultDockingStatus = new DefaultDockingStatus( this );
91     /** TopComponents that are maximized when slided-in. */
92     private Set JavaDoc<String JavaDoc> slideInMaximizedTopComponents = new HashSet JavaDoc<String JavaDoc>( 3 );
93     
94     /** Modes structure. */
95     private ModesSubModel modesSubModel = new ModesSubModel(this);
96
97     /** Set of TopComponentGroup's. */
98     private final Set JavaDoc<TopComponentGroupImpl> topComponentGroups =
99             new HashSet JavaDoc<TopComponentGroupImpl>(5);
100     
101     // Locks.
102
/** Lock for visible property. */
103     private final Object JavaDoc LOCK_VISIBLE = new Object JavaDoc();
104     /** Lock for mainWindowBounds property -> joined(tiled) state. */
105     private final Object JavaDoc LOCK_MAIN_WINDOW_BOUNDS_JOINED = new Object JavaDoc();
106     /** Lock for mainWindowBounds property -> separated state. */
107     private final Object JavaDoc LOCK_MAIN_WINDOW_BOUNDS_SEPARATED = new Object JavaDoc();
108     /** */
109     private final Object JavaDoc LOCK_MAIN_WINDOW_BOUNDS_SEPARATED_HELP = new Object JavaDoc();
110     /** */
111     private final Object JavaDoc LOCK_MAIN_WINDOW_FRAME_STATE_JOINED = new Object JavaDoc();
112     /** */
113     private final Object JavaDoc LOCK_MAIN_WINDOW_FRAME_STATE_SEPARATED = new Object JavaDoc();
114     /** Lock for editor area state. */
115     private final Object JavaDoc LOCK_EDITOR_AREA_STATE = new Object JavaDoc();
116     /** */
117     private final Object JavaDoc LOCK_EDITOR_AREA_FRAME_STATE = new Object JavaDoc();
118     /** Lock for editor area bounds. */
119     private final Object JavaDoc LOCK_EDITOR_AREA_BOUNDS = new Object JavaDoc();
120     /** */
121     private final Object JavaDoc LOCK_EDITOR_AREA_BOUNDS_HELP = new Object JavaDoc();
122     /** Lock for toolbarConfigName property. */
123     private final Object JavaDoc LOCK_TOOLBAR_CONFIG = new Object JavaDoc();
124     /** Locks for modes sub model. */
125     private final Object JavaDoc LOCK_MODES = new Object JavaDoc();
126     /** Lock for topComponentGroups property. */
127     private final Object JavaDoc LOCK_TOPCOMPONENT_GROUPS = new Object JavaDoc();
128     
129     private final Object JavaDoc LOCK_PROJECT_NAME = new Object JavaDoc();
130
131     
132     public DefaultModel() {
133     }
134     
135
136     /////////////////////////////////////
137
// Mutator methods >>
138
/////////////////////////////////////
139
/** Sets visibility status. */
140     public void setVisible(boolean visible) {
141         synchronized(LOCK_VISIBLE) {
142             this.visible = visible;
143         }
144     }
145     
146     /** Setter for mainWindowBoundsJoined property. */
147     public void setMainWindowBoundsJoined(Rectangle JavaDoc mainWindowBoundsJoined) {
148         if(mainWindowBoundsJoined == null) {
149             return;
150         }
151         
152         synchronized(LOCK_MAIN_WINDOW_BOUNDS_JOINED) {
153             this.mainWindowBoundsJoined.setBounds(mainWindowBoundsJoined);
154         }
155     }
156     
157     /** Setter for mainWindowBoundsSeparated property. */
158     public void setMainWindowBoundsSeparated(Rectangle JavaDoc mainWindowBoundsSeparated) {
159         if(mainWindowBoundsSeparated == null) {
160             return;
161         }
162         
163         synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED) {
164             this.mainWindowBoundsSeparated.setBounds(mainWindowBoundsSeparated);
165         }
166     }
167     
168     /** Sets frame state of main window when editor area is in tiled(joined) state. */
169     public void setMainWindowFrameStateJoined(int frameState) {
170         synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_JOINED) {
171             this.mainWindowFrameStateJoined = frameState;
172         }
173     }
174     
175     /** Sets frame state of main window when editor area is in separated state. */
176     public void setMainWindowFrameStateSeparated(int frameState) {
177         synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_SEPARATED) {
178             this.mainWindowFrameStateSeparated = frameState;
179         }
180     }
181
182     /** Setter of editorAreaBounds property. */
183     public void setEditorAreaBounds(Rectangle JavaDoc editorAreaBounds) {
184         if(editorAreaBounds == null) {
185             return;
186         }
187         
188         synchronized(LOCK_EDITOR_AREA_BOUNDS) {
189             this.editorAreaBounds.setBounds(editorAreaBounds);
190         }
191     }
192  
193     /** Setter of editorAreaState property. */
194     public void setEditorAreaState(int editorAreaState) {
195         synchronized(LOCK_EDITOR_AREA_STATE) {
196             this.editorAreaState = editorAreaState;
197         }
198     }
199
200     /** */
201     public void setEditorAreaFrameState(int frameState) {
202         synchronized(LOCK_EDITOR_AREA_FRAME_STATE) {
203             this.editorAreaFrameState = frameState;
204         }
205     }
206     
207     /** Sets editor area constraints. */
208     public void setEditorAreaConstraints(SplitConstraint[] editorAreaConstraints) {
209         synchronized(LOCK_MODES) {
210             modesSubModel.setEditorAreaConstraints(editorAreaConstraints);
211         }
212     }
213
214     public void setModeConstraints(ModeImpl mode, SplitConstraint[] constraints) {
215         synchronized(LOCK_MODES) {
216             // PENDING create changeMode method?
217
modesSubModel.removeMode(mode);
218             modesSubModel.addMode(mode, constraints);
219         }
220     }
221     
222     
223     /** Adds mode. */
224     public void addMode(ModeImpl mode, SplitConstraint[] constraints) {
225         synchronized(LOCK_MODES) {
226             modesSubModel.addMode(mode, constraints);
227         }
228     }
229     
230
231     
232     // XXX
233
public void addModeToSide(ModeImpl mode, ModeImpl attachMode, String JavaDoc side) {
234         synchronized(LOCK_MODES) {
235             modesSubModel.addModeToSide(mode, attachMode, side);
236         }
237     }
238     
239     // XXX
240
public void addModeAround(ModeImpl mode, String JavaDoc side) {
241         synchronized(LOCK_MODES) {
242             modesSubModel.addModeAround(mode, side);
243         }
244     }
245     
246     // XXX
247
public void addModeAroundEditor(ModeImpl mode, String JavaDoc side) {
248         synchronized(LOCK_MODES) {
249             modesSubModel.addModeAroundEditor(mode, side);
250         }
251     }
252
253     public void addSlidingMode(ModeImpl mode, String JavaDoc side, Map JavaDoc<String JavaDoc,Integer JavaDoc> slideInSizes) {
254         synchronized(LOCK_MODES) {
255             modesSubModel.addModeSliding(mode, side, slideInSizes);
256         }
257     }
258     
259     
260     /** Removes mode. */
261     public void removeMode(ModeImpl mode) {
262         synchronized(LOCK_MODES) {
263             modesSubModel.removeMode(mode);
264         }
265     }
266
267     /** Sets active mode. */
268     private Reference JavaDoc<ModeImpl> lastActiveMode = null;
269     public void setActiveMode(ModeImpl activeMode) {
270         if (lastActiveMode != null && lastActiveMode.get() == activeMode) {
271             return;
272         } else {
273             lastActiveMode = new WeakReference JavaDoc<ModeImpl>(activeMode);
274         }
275         synchronized(LOCK_MODES) {
276             boolean success = modesSubModel.setActiveMode(activeMode);
277             if (success) {
278                 updateSlidingSelections(activeMode);
279             }
280         }
281     }
282
283     /** Sets editor mode that is currenlty maximized */
284     public void setEditorMaximizedMode(ModeImpl maximizedMode) {
285         assert null == maximizedMode || maximizedMode.getKind() == Constants.MODE_KIND_EDITOR;
286         synchronized(LOCK_MODES) {
287             modesSubModel.setEditorMaximizedMode(maximizedMode);
288         }
289     }
290     
291     /** Sets view mode that is currenlty maximized */
292     public void setViewMaximizedMode(ModeImpl maximizedMode) {
293         assert null == maximizedMode || maximizedMode.getKind() == Constants.MODE_KIND_VIEW;
294         synchronized(LOCK_MODES) {
295             modesSubModel.setViewMaximizedMode(maximizedMode);
296         }
297     }
298
299     /** Setter for toolbarConfigName property. */
300     public void setToolbarConfigName(String JavaDoc toolbarConfigName) {
301         synchronized(LOCK_TOOLBAR_CONFIG) {
302             this.toolbarConfigName = toolbarConfigName;
303         }
304     }
305
306     
307     public void addTopComponentGroup(TopComponentGroupImpl tcGroup) {
308         synchronized(LOCK_TOPCOMPONENT_GROUPS) {
309             topComponentGroups.add(tcGroup);
310         }
311     }
312     
313     public void removeTopComponentGroup(TopComponentGroupImpl tcGroup) {
314         synchronized(LOCK_TOPCOMPONENT_GROUPS) {
315             topComponentGroups.remove(tcGroup);
316         }
317     }
318     
319     public void reset() {
320         mode2model.clear();
321         group2model.clear();
322         mainWindowFrameStateJoined = Frame.NORMAL;
323         mainWindowFrameStateSeparated = Frame.NORMAL;
324         editorAreaState = Constants.EDITOR_AREA_JOINED;
325         editorAreaFrameState = Frame.NORMAL;
326         toolbarConfigName = "Standard"; // NOI18N
327
modesSubModel = new ModesSubModel(this);
328         topComponentGroups.clear();
329         maximizedDockingStatus.clear();
330         defaultDockingStatus.clear();
331         slideInMaximizedTopComponents.clear();
332     }
333     
334     /////////////////////////////////////
335
// Mutator methods <<
336
/////////////////////////////////////
337

338     /////////////////////////////////////
339
// Accessor methods >>
340
/////////////////////////////////////
341
/** Gets visibility status. */
342     public boolean isVisible() {
343         synchronized(LOCK_VISIBLE) {
344             return this.visible;
345         }
346     }
347
348     /** Getter for mainWindowBoundsJoined property. */
349     public Rectangle JavaDoc getMainWindowBoundsJoined() {
350         synchronized(LOCK_MAIN_WINDOW_BOUNDS_JOINED) {
351             return (Rectangle JavaDoc)mainWindowBoundsJoined.clone();
352         }
353     }
354     
355     /** Getter for mainWindowBoundsSeparated property. */
356     public Rectangle JavaDoc getMainWindowBoundsSeparated() {
357         synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED) {
358             return (Rectangle JavaDoc)mainWindowBoundsSeparated.clone();
359         }
360     }
361     
362     public Rectangle JavaDoc getMainWindowBoundsSeparatedHelp() {
363         synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED_HELP) {
364             return (Rectangle JavaDoc)mainWindowBoundsSeparatedHelp.clone();
365         }
366     }
367     
368     /** Gets frame state of main window when editor area is in tiled(joined) state. */
369     public int getMainWindowFrameStateJoined() {
370         synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_JOINED) {
371             return mainWindowFrameStateJoined;
372         }
373     }
374     
375     /** Gets frame state of main window when editor area is in separated state. */
376     public int getMainWindowFrameStateSeparated() {
377         synchronized(LOCK_MAIN_WINDOW_FRAME_STATE_SEPARATED) {
378             return mainWindowFrameStateSeparated;
379         }
380     }
381     
382     /** Getter of editorAreaState property. */
383     public int getEditorAreaState() {
384         synchronized(LOCK_EDITOR_AREA_STATE) {
385             return this.editorAreaState;
386         }
387     }
388     
389     /** */
390     public int getEditorAreaFrameState() {
391         synchronized(LOCK_EDITOR_AREA_FRAME_STATE) {
392             return this.editorAreaFrameState;
393         }
394     }
395     
396     /** Getter of editorAreaBounds property. */
397     public Rectangle JavaDoc getEditorAreaBounds() {
398         synchronized(LOCK_EDITOR_AREA_BOUNDS) {
399             return (Rectangle JavaDoc)this.editorAreaBounds.clone();
400         }
401     }
402     
403     public Rectangle JavaDoc getEditorAreaBoundsHelp() {
404         synchronized(LOCK_EDITOR_AREA_BOUNDS_HELP) {
405             return (Rectangle JavaDoc)this.editorAreaBoundsHelp.clone();
406         }
407     }
408
409     /** Gets editor area constraints. */
410     public SplitConstraint[] getEditorAreaConstraints() {
411         synchronized(LOCK_MODES) {
412             return modesSubModel.getEditorAreaConstraints();
413         }
414     }
415
416     /** Gets set of modes. */
417     public Set JavaDoc<ModeImpl> getModes() {
418         synchronized(LOCK_MODES) {
419             return modesSubModel.getModes();
420         }
421     }
422     
423     public SplitConstraint[] getModeConstraints(ModeImpl mode) {
424         synchronized(LOCK_MODES) {
425             return modesSubModel.getModeConstraints(mode);
426         }
427     }
428     
429     public SplitConstraint[] getModelElementConstraints(ModelElement element) {
430         synchronized(LOCK_MODES) {
431             return modesSubModel.getModelElementConstraints(element);
432         }
433     }
434     
435     public String JavaDoc getSlidingModeConstraints(ModeImpl mode) {
436         synchronized(LOCK_MODES) {
437             return modesSubModel.getSlidingModeConstraints(mode);
438         }
439     }
440     
441     public ModeImpl getSlidingMode(String JavaDoc side) {
442         synchronized(LOCK_MODES) {
443             return modesSubModel.getSlidingMode(side);
444         }
445     }
446     
447     /** Gets active mode. */
448     public ModeImpl getActiveMode() {
449         synchronized(LOCK_MODES) {
450             return modesSubModel.getActiveMode();
451         }
452     }
453
454     /**
455      * @return The docking status (docked/slided) of TopComponents before the window system
456      * switched to maximized mode.
457      */

458     public DockingStatus getDefaultDockingStatus() {
459         return defaultDockingStatus;
460     }
461
462     /**
463      * @return The docking status (docked/slided) of TopComponents in maximized editor mode.
464      */

465     public DockingStatus getMaximizedDockingStatus() {
466         return maximizedDockingStatus;
467     }
468     
469     /** Gets editor maximized mode. */
470     public ModeImpl getEditorMaximizedMode() {
471         synchronized(LOCK_MODES) {
472             return modesSubModel.getEditorMaximizedMode();
473         }
474     }
475     
476     /** Gets view maximized mode. */
477     public ModeImpl getViewMaximizedMode() {
478         synchronized(LOCK_MODES) {
479             return modesSubModel.getViewMaximizedMode();
480         }
481     }
482     
483     /**
484      * Find the side (LEFT/RIGHT/BOTTOM) where the TopComponent from the given
485      * mode should slide to.
486      *
487      * @param mode Mode
488      * @return The slide side for TopComponents from the given mode.
489      */

490     public String JavaDoc getSlideSideForMode( ModeImpl mode ) {
491         synchronized(LOCK_MODES) {
492             return modesSubModel.getSlideSideForMode( mode );
493         }
494     }
495     
496     /** Getter for toolbarConfigName property. */
497     public String JavaDoc getToolbarConfigName() {
498         synchronized(LOCK_TOOLBAR_CONFIG) {
499             return this.toolbarConfigName;
500         }
501     }
502     
503     /**
504      * Gets the sizes (width or height) of TopComponents in the given sliding
505      * side, the key in the Map is TopComponent's ID
506      */

507     public Map JavaDoc<String JavaDoc,Integer JavaDoc> getSlideInSizes(String JavaDoc side) {
508         synchronized(LOCK_MODES) {
509             return modesSubModel.getSlideInSizes( side );
510         }
511     }
512     
513     /** Set the size (width or height of the given TopComponent when it is slided in */
514     public void setSlideInSize(String JavaDoc side, TopComponent tc, int size) {
515         synchronized(LOCK_MODES) {
516             modesSubModel.setSlideInSize(side, tc, size);
517         }
518     }
519     
520     /**
521      * @return True if the given TopComponent is maximized when it is slided-in.
522      */

523     public boolean isTopComponentMaximizedWhenSlidedIn( String JavaDoc tcid ) {
524         return null != tcid && slideInMaximizedTopComponents.contains( tcid );
525     }
526     
527     /**
528      * Set whether the given TopComponent is maximized when it is slided-in.
529      */

530     public void setTopComponentMaximizedWhenSlidedIn( String JavaDoc tcid, boolean maximized ) {
531         if( null != tcid ) {
532             if( maximized )
533                 slideInMaximizedTopComponents.add( tcid );
534             else
535                 slideInMaximizedTopComponents.remove( tcid );
536         }
537     }
538
539     /////////////////////////////////////
540
// Accessor methods <<
541
/////////////////////////////////////
542

543     
544     ///////////////////
545
// Mode specific >>
546
public void createModeModel(ModeImpl mode, String JavaDoc name, int state, int kind, boolean permanent) {
547         synchronized(mode2model) {
548             ModeModel mm;
549             mm = new DefaultModeModel(name, state, kind, permanent);
550             mode2model.put(mode, mm);
551         }
552     }
553
554     private ModeModel getModelForMode(ModeImpl mode) {
555         synchronized(mode2model) {
556             return (ModeModel)mode2model.get(mode);
557         }
558     }
559     
560     // Mutators
561
/** Sets state. */
562     public void setModeState(ModeImpl mode, int state) {
563         ModeModel modeModel = getModelForMode(mode);
564         if(modeModel != null) {
565             modeModel.setState(state);
566         }
567     }
568     
569     /** Sets bounds. */
570     public void setModeBounds(ModeImpl mode, Rectangle JavaDoc bounds) {
571         ModeModel modeModel = getModelForMode(mode);
572         if(modeModel != null) {
573             modeModel.setBounds(bounds);
574         }
575     }
576     
577     /** Sets frame state. */
578     public void setModeFrameState(ModeImpl mode, int frameState) {
579         ModeModel modeModel = getModelForMode(mode);
580         if(modeModel != null) {
581             modeModel.setFrameState(frameState);
582         }
583     }
584     
585     /** Sets seleted TopComponent. */
586     public void setModeSelectedTopComponent(ModeImpl mode, TopComponent selected) {
587         ModeModel modeModel = getModelForMode(mode);
588         if(modeModel != null) {
589             modeModel.setSelectedTopComponent(selected);
590         }
591     }
592     
593     /** Remember which top component was the selected one before switching to/from maximized mode */
594     public void setModePreviousSelectedTopComponent(ModeImpl mode, TopComponent prevSelected) {
595         ModeModel modeModel = getModelForMode(mode);
596         if(modeModel != null) {
597             modeModel.setPreviousSelectedTopComponent(prevSelected);
598         }
599     }
600     
601     /** Adds opened TopComponent. */
602     public void addModeOpenedTopComponent(ModeImpl mode, TopComponent tc) {
603         ModeModel modeModel = getModelForMode(mode);
604         if(modeModel != null) {
605             modeModel.addOpenedTopComponent(tc);
606         }
607     }
608
609     /** Inserts opened TopComponent. */
610     public void insertModeOpenedTopComponent(ModeImpl mode, TopComponent tc, int index) {
611         ModeModel modeModel = getModelForMode(mode);
612         if(modeModel != null) {
613             modeModel.insertOpenedTopComponent(tc, index);
614         }
615     }
616     
617     /** Adds closed TopComponent. */
618     public void addModeClosedTopComponent(ModeImpl mode, TopComponent tc) {
619         ModeModel modeModel = getModelForMode(mode);
620         if(modeModel != null) {
621             modeModel.addClosedTopComponent(tc);
622         }
623     }
624     
625     // XXX
626
public void addModeUnloadedTopComponent(ModeImpl mode, String JavaDoc tcID) {
627         ModeModel modeModel = getModelForMode(mode);
628         if(modeModel != null) {
629             modeModel.addUnloadedTopComponent(tcID);
630         }
631     }
632     
633     // XXX
634
public void setModeUnloadedSelectedTopComponent(ModeImpl mode, String JavaDoc tcID) {
635         ModeModel modeModel = getModelForMode(mode);
636         if(modeModel != null) {
637             modeModel.setUnloadedSelectedTopComponent(tcID);
638         }
639     }
640     
641     public void setModeUnloadedPreviousSelectedTopComponent(ModeImpl mode, String JavaDoc tcID) {
642         ModeModel modeModel = getModelForMode(mode);
643         if(modeModel != null) {
644             modeModel.setUnloadedPreviousSelectedTopComponent(tcID);
645         }
646     }
647     
648     /** */
649     public void removeModeTopComponent(ModeImpl mode, TopComponent tc) {
650         ModeModel modeModel = getModelForMode(mode);
651         if(modeModel != null) {
652             modeModel.removeTopComponent(tc);
653         }
654     }
655     
656     // XXX
657
public void removeModeClosedTopComponentID(ModeImpl mode, String JavaDoc tcID) {
658         ModeModel modeModel = getModelForMode(mode);
659         if(modeModel != null) {
660             modeModel.removeClosedTopComponentID(tcID);
661         }
662     }
663
664     /**
665      * @param mode - sliding mode
666      */

667     
668     public void setModeTopComponentPreviousConstraints(ModeImpl mode, String JavaDoc tcID, SplitConstraint[] constraints) {
669         ModeModel modeModel = getModelForMode(mode);
670         if(modeModel != null) {
671             modeModel.setTopComponentPreviousConstraints(tcID, constraints);
672         }
673     }
674     
675     /**
676      * @param mode - sliding mode
677      * @param previousMode - the original mode.
678      * @param prevIndex - the tab index in the original mode
679      */

680     public void setModeTopComponentPreviousMode(ModeImpl mode, String JavaDoc tcID, ModeImpl previousMode, int prevIndex) {
681         ModeModel modeModel = getModelForMode(mode);
682         if(modeModel != null) {
683             modeModel.setTopComponentPreviousMode(tcID, previousMode, prevIndex);
684         }
685     }
686     
687     // Accessors
688
/** Gets programatic name of mode. */
689     public String JavaDoc getModeName(ModeImpl mode) {
690         ModeModel modeModel = getModelForMode(mode);
691         if(modeModel != null) {
692             return modeModel.getName();
693         } else {
694             return null;
695         }
696     }
697     
698     /** Gets bounds. */
699     public Rectangle JavaDoc getModeBounds(ModeImpl mode) {
700         ModeModel modeModel = getModelForMode(mode);
701         if(modeModel != null) {
702             return modeModel.getBounds();
703         } else {
704             return null;
705         }
706     }
707     
708     public Rectangle JavaDoc getModeBoundsSeparatedHelp(ModeImpl mode) {
709         ModeModel modeModel = getModelForMode(mode);
710         if(modeModel != null) {
711             return modeModel.getBoundsSeparatedHelp();
712         } else {
713             return null;
714         }
715     }
716     
717     /** Gets state. */
718     public int getModeState(ModeImpl mode) {
719         ModeModel modeModel = getModelForMode(mode);
720         if(modeModel != null) {
721             return modeModel.getState();
722         } else {
723             return -1;
724         }
725     }
726     
727     /** Gets kind. */
728     public int getModeKind(ModeImpl mode) {
729         ModeModel modeModel = getModelForMode(mode);
730         if(modeModel != null) {
731             return modeModel.getKind();
732         } else {
733             return -1;
734         }
735     }
736
737     /** Gets side. */
738     public String JavaDoc getModeSide(ModeImpl mode) {
739         String JavaDoc side = modesSubModel.getSlidingModeConstraints(mode);
740         return side;
741     }
742     
743     /** Gets frame state. */
744     public int getModeFrameState(ModeImpl mode) {
745         ModeModel modeModel = getModelForMode(mode);
746         if(modeModel != null) {
747             return modeModel.getFrameState();
748         } else {
749             return -1;
750         }
751     }
752     
753     /** Gets used defined. */
754     public boolean isModePermanent(ModeImpl mode) {
755         ModeModel modeModel = getModelForMode(mode);
756         if(modeModel != null) {
757             return modeModel.isPermanent();
758         } else {
759             return false;
760         }
761     }
762     
763     /** Indicates whether the mode is empty. */
764     public boolean isModeEmpty(ModeImpl mode) {
765         ModeModel modeModel = getModelForMode(mode);
766         if(modeModel != null) {
767             return modeModel.isEmpty();
768         } else {
769             return false;
770         }
771     }
772     
773     /** Indicates whether the mode contains the TopComponent. */
774     public boolean containsModeTopComponent(ModeImpl mode, TopComponent tc) {
775         ModeModel modeModel = getModelForMode(mode);
776         if(modeModel != null) {
777             return modeModel.containsTopComponent(tc);
778         } else {
779             return false;
780         }
781     }
782     
783     /** Gets selected TopComponent. */
784     public TopComponent getModeSelectedTopComponent(ModeImpl mode) {
785         ModeModel modeModel = getModelForMode(mode);
786         if(modeModel != null) {
787             return modeModel.getSelectedTopComponent();
788         } else {
789             return null;
790         }
791     }
792     
793     /** Get the top component that had been the selected one before switching to/from maximzied mode */
794     public TopComponent getModePreviousSelectedTopComponent(ModeImpl mode) {
795         ModeModel modeModel = getModelForMode(mode);
796         if(modeModel != null) {
797             return modeModel.getPreviousSelectedTopComponent();
798         } else {
799             return null;
800         }
801     }
802     
803     /** Gets list of top components. */
804     public List JavaDoc<TopComponent> getModeTopComponents(ModeImpl mode) {
805         ModeModel modeModel = getModelForMode(mode);
806         if(modeModel != null) {
807             return modeModel.getTopComponents();
808         } else {
809             return Collections.emptyList();
810         }
811     }
812     
813     /** Gets list of top components. */
814     public List JavaDoc<TopComponent> getModeOpenedTopComponents(ModeImpl mode) {
815         ModeModel modeModel = getModelForMode(mode);
816         if(modeModel != null) {
817             return modeModel.getOpenedTopComponents();
818         } else {
819             return Collections.emptyList();
820         }
821     }
822     
823     // XXX
824
public List JavaDoc<String JavaDoc> getModeOpenedTopComponentsIDs(ModeImpl mode) {
825         ModeModel modeModel = getModelForMode(mode);
826         if(modeModel != null) {
827             return modeModel.getOpenedTopComponentsIDs();
828         } else {
829             return Collections.emptyList();
830         }
831     }
832     
833     public List JavaDoc<String JavaDoc> getModeClosedTopComponentsIDs(ModeImpl mode) {
834         ModeModel modeModel = getModelForMode(mode);
835         if(modeModel != null) {
836             return modeModel.getClosedTopComponentsIDs();
837         } else {
838             return Collections.emptyList();
839         }
840     }
841     
842     public List JavaDoc<String JavaDoc> getModeTopComponentsIDs(ModeImpl mode) {
843         ModeModel modeModel = getModelForMode(mode);
844         if(modeModel != null) {
845             return modeModel.getTopComponentsIDs();
846         } else {
847             return Collections.emptyList();
848         }
849     }
850     
851     public SplitConstraint[] getModeTopComponentPreviousConstraints(ModeImpl mode, String JavaDoc tcID) {
852         ModeModel modeModel = getModelForMode(mode);
853         return modeModel == null ? null : modeModel.getTopComponentPreviousConstraints(tcID);
854     }
855     
856     public ModeImpl getModeTopComponentPreviousMode(ModeImpl mode, String JavaDoc tcID) {
857         ModeModel modeModel = getModelForMode(mode);
858         return modeModel == null ? null : modeModel.getTopComponentPreviousMode(tcID);
859     }
860     
861     /** Gets the tab index of the given top component before it was moved to sliding/separate mode */
862     public int getModeTopComponentPreviousIndex(ModeImpl mode, String JavaDoc tcID) {
863         ModeModel modeModel = getModelForMode(mode);
864         return modeModel == null ? null : modeModel.getTopComponentPreviousIndex(tcID);
865     }
866     
867     // End of mode specific.
868

869     
870     ////////////////////////////////////
871
// TopComponentGroup specific >>
872
public void createGroupModel(TopComponentGroupImpl tcGroup, String JavaDoc name, boolean opened) {
873         synchronized(group2model) {
874             TopComponentGroupModel tcgm = new DefaultTopComponentGroupModel(name, opened);
875             group2model.put(tcGroup, tcgm);
876         }
877     }
878
879     private TopComponentGroupModel getModelForGroup(TopComponentGroupImpl tcGroup) {
880         synchronized(group2model) {
881             return (TopComponentGroupModel)group2model.get(tcGroup);
882         }
883     }
884
885     
886     public Set JavaDoc<TopComponentGroupImpl> getTopComponentGroups() {
887         synchronized(LOCK_TOPCOMPONENT_GROUPS) {
888             return new HashSet JavaDoc<TopComponentGroupImpl>(topComponentGroups);
889         }
890     }
891
892     /** Gets programatic name of mode. */
893     public String JavaDoc getGroupName(TopComponentGroupImpl tcGroup) {
894         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
895         if(groupModel != null) {
896             return groupModel.getName();
897         } else {
898             return null;
899         }
900     }
901     
902     public void openGroup(TopComponentGroupImpl tcGroup,
903             Collection JavaDoc<TopComponent> openedTopComponents,
904             Collection JavaDoc<TopComponent> openedBeforeTopComponents) {
905         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
906         if(groupModel != null) {
907             groupModel.open(openedTopComponents, openedBeforeTopComponents);
908         }
909     }
910     
911     public void closeGroup(TopComponentGroupImpl tcGroup) {
912         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
913         if(groupModel != null) {
914             groupModel.close();
915         }
916     }
917     
918     public boolean isGroupOpened(TopComponentGroupImpl tcGroup) {
919         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
920         if(groupModel != null) {
921             return groupModel.isOpened();
922         } else {
923             return false;
924         }
925     }
926     
927     public Set JavaDoc<TopComponent> getGroupTopComponents(TopComponentGroupImpl tcGroup) {
928         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
929         if(groupModel != null) {
930             return groupModel.getTopComponents();
931         } else {
932             return Collections.emptySet();
933         }
934     }
935     
936     public Set JavaDoc<TopComponent> getGroupOpenedTopComponents(TopComponentGroupImpl tcGroup) {
937         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
938         if(groupModel != null) {
939             return groupModel.getOpenedTopComponents();
940         } else {
941             return Collections.emptySet();
942         }
943     }
944     
945     public Set JavaDoc<TopComponent> getGroupOpenedBeforeTopComponents(TopComponentGroupImpl tcGroup) {
946         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
947         if(groupModel != null) {
948             return groupModel.getOpenedBeforeTopComponents();
949         } else {
950             return Collections.emptySet();
951         }
952     }
953     
954     public Set JavaDoc<TopComponent> getGroupOpeningTopComponents(TopComponentGroupImpl tcGroup) {
955         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
956         if(groupModel != null) {
957             return groupModel.getOpeningTopComponents();
958         } else {
959             return Collections.emptySet();
960         }
961     }
962     
963     public Set JavaDoc<TopComponent> getGroupClosingTopComponents(TopComponentGroupImpl tcGroup) {
964         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
965         if(groupModel != null) {
966             return groupModel.getClosingTopComponents();
967         } else {
968             return Collections.emptySet();
969         }
970     }
971
972     public boolean addGroupUnloadedTopComponent(TopComponentGroupImpl tcGroup, String JavaDoc tcID) {
973         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
974         if(groupModel != null) {
975             return groupModel.addUnloadedTopComponent(tcID);
976         } else {
977             return false;
978         }
979     }
980     
981     public boolean removeGroupUnloadedTopComponent(TopComponentGroupImpl tcGroup, String JavaDoc tcID) {
982         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
983         if(groupModel != null) {
984             return groupModel.removeUnloadedTopComponent(tcID);
985         } else {
986             return false;
987         }
988     }
989     
990     public boolean addGroupOpeningTopComponent(TopComponentGroupImpl tcGroup, TopComponent tc) {
991         TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
992         if(groupModel != null) {
993             return groupModel.addOpeningTopComponent(tc);
994         } else {
995             return false;
996         }
997     }
998     
999     public boolean removeGroupOpeningTopComponent(TopComponentGroupImpl tcGroup, TopComponent tc) {
1000        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1001        if(groupModel != null) {
1002            return groupModel.removeOpeningTopComponent(tc);
1003        } else {
1004            return false;
1005        }
1006    }
1007    
1008    public boolean addGroupUnloadedOpeningTopComponent(TopComponentGroupImpl tcGroup, String JavaDoc tcID) {
1009        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1010        if(groupModel != null) {
1011            return groupModel.addUnloadedOpeningTopComponent(tcID);
1012        } else {
1013            return false;
1014        }
1015    }
1016    
1017    public boolean removeGroupUnloadedOpeningTopComponent(TopComponentGroupImpl tcGroup, String JavaDoc tcID) {
1018        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1019        if(groupModel != null) {
1020            return groupModel.removeUnloadedOpeningTopComponent(tcID);
1021        } else {
1022            return false;
1023        }
1024    }
1025    
1026    public boolean addGroupUnloadedClosingTopComponent(TopComponentGroupImpl tcGroup, String JavaDoc tcID) {
1027        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1028        if(groupModel != null) {
1029            return groupModel.addUnloadedClosingTopComponent(tcID);
1030        } else {
1031            return false;
1032        }
1033    }
1034    public boolean removeGroupUnloadedClosingTopComponent(TopComponentGroupImpl tcGroup, String JavaDoc tcID) {
1035        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1036        if(groupModel != null) {
1037            return groupModel.removeUnloadedClosingTopComponent(tcID);
1038        } else {
1039            return false;
1040        }
1041    }
1042    // XXX
1043
public boolean addGroupUnloadedOpenedTopComponent(TopComponentGroupImpl tcGroup, String JavaDoc tcID) {
1044        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1045        if(groupModel != null) {
1046            return groupModel.addUnloadedOpenedTopComponent(tcID);
1047        } else {
1048            return false;
1049        }
1050    }
1051    
1052    // XXX>>
1053
public Set JavaDoc<String JavaDoc> getGroupTopComponentsIDs(TopComponentGroupImpl tcGroup) {
1054        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1055        if(groupModel != null) {
1056            return groupModel.getTopComponentsIDs();
1057        } else {
1058            return Collections.emptySet();
1059        }
1060    }
1061    
1062    public Set JavaDoc<String JavaDoc> getGroupOpeningSetIDs(TopComponentGroupImpl tcGroup) {
1063        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1064        if(groupModel != null) {
1065            return groupModel.getOpeningSetIDs();
1066        } else {
1067            return Collections.emptySet();
1068        }
1069    }
1070    
1071    public Set JavaDoc<String JavaDoc> getGroupClosingSetIDs(TopComponentGroupImpl tcGroup) {
1072        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1073        if(groupModel != null) {
1074            return groupModel.getClosingSetIDs();
1075        } else {
1076            return Collections.emptySet();
1077        }
1078    }
1079    
1080    public Set JavaDoc<String JavaDoc> getGroupOpenedTopComponentsIDs(TopComponentGroupImpl tcGroup) {
1081        TopComponentGroupModel groupModel = getModelForGroup(tcGroup);
1082        if(groupModel != null) {
1083            return groupModel.getOpenedTopComponentsIDs();
1084        } else {
1085            return Collections.emptySet();
1086        }
1087    }
1088    // XXX<<
1089
// TopComponentGroup specific <<
1090
////////////////////////////////////
1091

1092    
1093    /////////////////////////
1094
// Controller updates >>
1095
public void setActiveModeForOriginator(ModelElement originator) {
1096        synchronized(LOCK_MODES) {
1097            ModeImpl mode = modesSubModel.getModeForOriginator(originator);
1098            setActiveMode(mode);
1099        }
1100    }
1101    
1102    public void setModeSelectedTopComponentForOriginator(ModelElement originator, TopComponent tc) {
1103        ModeImpl mode;
1104        synchronized(LOCK_MODES) {
1105            mode = modesSubModel.getModeForOriginator(originator);
1106        }
1107        
1108        setModeSelectedTopComponent(mode, tc);
1109
1110
1111    }
1112    
1113    public void setMainWindowBoundsUserSeparatedHelp(Rectangle JavaDoc bounds) {
1114        if(bounds == null) {
1115            return;
1116        }
1117        
1118        synchronized(LOCK_MAIN_WINDOW_BOUNDS_SEPARATED_HELP) {
1119            this.mainWindowBoundsSeparatedHelp.setBounds(bounds);
1120        }
1121    }
1122    
1123    public void setEditorAreaBoundsUserHelp(Rectangle JavaDoc bounds) {
1124        if(bounds == null) {
1125            return;
1126        }
1127        
1128        synchronized(LOCK_EDITOR_AREA_BOUNDS_HELP) {
1129            this.editorAreaBoundsHelp.setBounds(bounds);
1130        }
1131    }
1132    
1133    public void setModeBoundsSeparatedHelp(ModeImpl mode, Rectangle JavaDoc bounds) {
1134        ModeModel modeModel = getModelForMode(mode);
1135        if(modeModel != null) {
1136            modeModel.setBoundsSeparatedHelp(bounds);
1137        }
1138    }
1139    
1140    public void setSplitWeights( ModelElement[] snapshots, double[] splitWeights ) {
1141        synchronized(LOCK_MODES) {
1142            modesSubModel.setSplitWeights(snapshots, splitWeights);
1143        }
1144    }
1145    
1146    // Controller updates <<
1147
/////////////////////////
1148

1149
1150    public WindowSystemSnapshot createWindowSystemSnapshot() {
1151        WindowSystemSnapshot wsms = new WindowSystemSnapshot();
1152
1153        // PENDING
1154
ModeStructureSnapshot mss = createModeStructureSnapshot();
1155        wsms.setModeStructureSnapshot(mss);
1156        
1157        ModeImpl activeMode = getActiveMode();
1158        wsms.setActiveModeSnapshot(activeMode == null ? null : mss.findModeSnapshot(activeMode.getName()));
1159        
1160        ModeImpl maximizedMode = null != getViewMaximizedMode() ? getViewMaximizedMode() : null;
1161        wsms.setMaximizedModeSnapshot(maximizedMode == null ? null : mss.findModeSnapshot(maximizedMode.getName()));
1162
1163        wsms.setMainWindowBoundsJoined(getMainWindowBoundsJoined());
1164        wsms.setMainWindowBoundsSeparated(getMainWindowBoundsSeparated());
1165        wsms.setEditorAreaBounds(getEditorAreaBounds());
1166        wsms.setEditorAreaState(getEditorAreaState());
1167        wsms.setEditorAreaFrameState(getEditorAreaFrameState());
1168        wsms.setMainWindowFrameStateJoined(getMainWindowFrameStateJoined());
1169        wsms.setMainWindowFrameStateSeparated(getMainWindowFrameStateSeparated());
1170        wsms.setToolbarConfigurationName(getToolbarConfigName());
1171        return wsms;
1172    }
1173
1174    /** Creates modes snapshot.. */
1175    private ModeStructureSnapshot createModeStructureSnapshot() {
1176        ModeStructureSnapshot.ElementSnapshot splitRoot;
1177        Set JavaDoc<ModeStructureSnapshot.ModeSnapshot> separateModes;
1178        Set JavaDoc<ModeStructureSnapshot.SlidingModeSnapshot> slidingModes;
1179        synchronized(LOCK_MODES) {
1180            splitRoot = modesSubModel.createSplitSnapshot();
1181            separateModes = modesSubModel.createSeparateModeSnapshots();
1182            slidingModes = modesSubModel.createSlidingModeSnapshots();
1183        }
1184        
1185        ModeStructureSnapshot ms = new ModeStructureSnapshot(splitRoot, separateModes, slidingModes);
1186        return ms;
1187    }
1188    ///////////////////////////////////////////////////
1189

1190    /** Checks whether the mode isn't null. */
1191    private static boolean validateAddingMode(ModeImpl mode) {
1192        if(mode == null) {
1193            Logger.getLogger(DefaultModel.class.getName()).log(Level.WARNING, null,
1194                              new java.lang.NullPointerException JavaDoc("Not allowed null mode")); // NOI18N
1195
return false;
1196        }
1197        
1198        return true;
1199    }
1200    
1201    /** Keeps selected components of sliding modes in sync with given current
1202     * active mode. Sliding mode can have non-null selection (=slide) only if
1203     * it is active mode as well
1204     */

1205    private void updateSlidingSelections (ModeImpl curActive) {
1206        Set JavaDoc slidingModes = modesSubModel.getSlidingModes();
1207        ModeImpl curSliding = null;
1208        for (Iterator JavaDoc iter = slidingModes.iterator(); iter.hasNext(); ) {
1209            curSliding = (ModeImpl)iter.next();
1210            if (!curSliding.equals(curActive)) {
1211                setModeSelectedTopComponent(curSliding, null);
1212            }
1213        }
1214    }
1215
1216    /**
1217     * A special subclass of DockingStatus for default mode when no TopComponent is maximized.
1218     */

1219    private static class DefaultDockingStatus extends DockingStatus {
1220        public DefaultDockingStatus( Model model ) {
1221            super( model );
1222        }
1223        
1224        /**
1225         * When switching back to default mode, only slide those TopComponents
1226         * there were slided-out before.
1227         */

1228        public boolean shouldSlide( String JavaDoc tcID ) {
1229            return null != tcID && slided.contains( tcID );
1230        }
1231
1232        /**
1233         * In default mode all TopComponents are docked by default.
1234         */

1235        public boolean shouldDock( String JavaDoc tcID ) {
1236            return null != tcID && (docked.contains( tcID ) || (!docked.contains( tcID ) && !slided.contains( tcID )));
1237        }
1238        
1239        public void mark() {
1240            super.mark();
1241            Set JavaDoc<ModeImpl> modes = model.getModes();
1242            for( Iterator JavaDoc<ModeImpl> i=modes.iterator(); i.hasNext(); ) {
1243                ModeImpl modeImpl = i.next();
1244                if( modeImpl.getState() != Constants.MODE_KIND_VIEW )
1245                    continue;
1246
1247                //also remember which top component is the selected one
1248
modeImpl.setPreviousSelectedTopComponent( modeImpl.getSelectedTopComponent() );
1249            }
1250        }
1251    }
1252}
1253
1254
Popular Tags