KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Set JavaDoc;
26 import org.netbeans.core.windows.Constants;
27 import org.netbeans.core.windows.ModeImpl;
28
29 /**
30  * This class stores the snapshot of the docking status (docked/slided-out) of TopComponents
31  * when switching to or from maximized mode.
32  *
33  * @author S. Aubrecht
34  */

35 public class DockingStatus {
36     
37     protected Model model;
38     protected List JavaDoc<String JavaDoc> docked = new ArrayList JavaDoc<String JavaDoc>(10);
39     protected List JavaDoc<String JavaDoc> slided = new ArrayList JavaDoc<String JavaDoc>(10);
40     
41     /** Creates a new instance of DockingStatus */
42     DockingStatus( Model model ) {
43         this.model = model;
44     }
45     
46     /**
47      * Remember which TopComponents are docked and which are slided.
48      */

49     public void mark() {
50         Set JavaDoc<ModeImpl> modes = model.getModes();
51         for( Iterator JavaDoc<ModeImpl> i=modes.iterator(); i.hasNext(); ) {
52             ModeImpl modeImpl = i.next();
53             if( modeImpl.getState() == Constants.MODE_STATE_SEPARATED )
54                 continue;
55             
56             List JavaDoc<String JavaDoc> views = model.getModeOpenedTopComponentsIDs( modeImpl );
57             if( modeImpl.getKind() == Constants.MODE_KIND_VIEW ) {
58                 docked.addAll( views );
59                 slided.removeAll( views );
60             } else if( modeImpl.getKind() == Constants.MODE_KIND_SLIDING ) {
61                 docked.removeAll( views );
62                 slided.addAll( views );
63             }
64         }
65     }
66     
67     /**
68      * @return True if the TopComponent should switch to docked status
69      * (Used when switching to/from maximized mode)
70      */

71     public boolean shouldDock( String JavaDoc tcID ) {
72         return null != tcID && docked.contains( tcID );
73     }
74     
75     /**
76      * @return True if the TopComponent should slide-out
77      * (Used when switching to/from maximized mode)
78      */

79     public boolean shouldSlide( String JavaDoc tcID ) {
80         return null != tcID && (slided.contains( tcID )
81                                 //special case for TopComponents not declared in XML layer
82
|| (!slided.contains( tcID ) && !docked.contains( tcID )));
83     }
84     
85     /**
86      * Adds 'docked' TopComponent (used when the window system loads)
87      */

88     public void addDocked( String JavaDoc tcID ) {
89         if( null != tcID ) {
90             docked.add( tcID );
91             slided.remove( tcID );
92         }
93     }
94     
95     /**
96      * Adds 'slided-out' TopComponent (used when the window system loads)
97      */

98     public void addSlided( String JavaDoc tcID ) {
99         if( null != tcID ) {
100             slided.add( tcID );
101             docked.remove( tcID );
102         }
103     }
104     
105     /**
106      * (Used when the window system gets stored)
107      * @return True if the given TopComponent was docked when its snapshot was taken.
108      */

109     public boolean isDocked( String JavaDoc tcID ) {
110         return null != tcID && docked.contains( tcID );
111     }
112     
113     /**
114      * (Used when the window system gets stored)
115      * @return True if the given TopComponent was slided when its snapshot was taken.
116      */

117     public boolean isSlided( String JavaDoc tcID ) {
118         return null != tcID && slided.contains( tcID );
119     }
120     
121     /**
122      * Reset to defaults
123      */

124     void clear() {
125         docked.clear();
126         slided.clear();
127     }
128 }
129
Popular Tags