KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > persistence > ModeConfig


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.persistence;
22
23
24 import java.awt.Rectangle JavaDoc;
25 import org.netbeans.core.windows.SplitConstraint;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29
30
31 /**
32  * Class of mode config properties for communication with persistence management.
33  * It keeps data which are read/written from/in .wsmode xml file.
34  *
35  * @author Peter Zavadsky
36  */

37 public class ModeConfig {
38
39     /** Name of mode. Supposed to be internally for mode identification. */
40     public String JavaDoc name;
41
42     /** State of mode: 0 = split, 1 = separate. */
43     public int state;
44
45     /** Kind of mode: 0 = editor, 1 = view, 2 - sliding */
46     public int kind;
47     
48     /** side for sliding kind*/
49     public String JavaDoc side;
50     
51     /** Constraints of mode - path in tree model */
52     public SplitConstraint[] constraints;
53     
54     //Part for separate state
55
public Rectangle JavaDoc bounds;
56     public Rectangle JavaDoc relativeBounds;
57     
58     public int frameState;
59     
60     //Common part
61
/** Id of selected top component. */
62     public String JavaDoc selectedTopComponentID;
63     
64     public boolean permanent = true;
65     
66     /** Array of TCRefConfigs. */
67     public TCRefConfig[] tcRefConfigs;
68     
69     /** TopComponent ID -> slided-in size (width or height) - applies to sliding modes only*/
70     public Map JavaDoc<String JavaDoc,Integer JavaDoc> slideInSizes;
71     
72     /** ID of top component that was selected before switching to/from maximized mode */
73     public String JavaDoc previousSelectedTopComponentID;
74     
75     /** Creates a new instance of ModeConfig */
76     public ModeConfig() {
77         name = ""; // NOI18N
78
constraints = new SplitConstraint[0];
79         selectedTopComponentID = ""; // NOI18N
80
tcRefConfigs = new TCRefConfig[0];
81         previousSelectedTopComponentID = ""; // NOI18N
82
}
83     
84     public boolean equals (Object JavaDoc obj) {
85         if (this == obj) {
86             return true;
87         }
88         if (!(obj instanceof ModeConfig)) {
89             return false;
90         }
91         ModeConfig modeCfg = (ModeConfig) obj;
92         if (!name.equals(modeCfg.name)) {
93             return false;
94         }
95         if ((state != modeCfg.state) || (kind != modeCfg.kind)) {
96             return false;
97         }
98         if (null != side && !side.equals( modeCfg.side ) ) {
99             return false;
100         } else if( null == side && null != modeCfg.side ) {
101             return false;
102         }
103         //Order of constraints array is defined
104
if (constraints.length != modeCfg.constraints.length) {
105             return false;
106         }
107         for (int i = 0; i < constraints.length; i++) {
108             if (!constraints[i].equals(modeCfg.constraints[i])) {
109                 return false;
110             }
111         }
112         if ((bounds != null) && (modeCfg.bounds != null)) {
113             if (!bounds.equals(modeCfg.bounds)) {
114                 return false;
115             }
116         } else if ((bounds != null) || (modeCfg.bounds != null)) {
117             return false;
118         }
119         if ((relativeBounds != null) && (modeCfg.relativeBounds != null)) {
120             if (!relativeBounds.equals(modeCfg.relativeBounds)) {
121                 return false;
122             }
123         } else if ((relativeBounds != null) || (modeCfg.relativeBounds != null)) {
124             return false;
125         }
126         if (frameState != modeCfg.frameState) {
127             return false;
128         }
129         if (!selectedTopComponentID.equals(modeCfg.selectedTopComponentID)) {
130             return false;
131         }
132         if (permanent != modeCfg.permanent) {
133             return false;
134         }
135         //Order of tcRefConfigs is defined
136
if (tcRefConfigs.length != modeCfg.tcRefConfigs.length) {
137             return false;
138         }
139         for (int i = 0; i < tcRefConfigs.length; i++) {
140             if (!tcRefConfigs[i].equals(modeCfg.tcRefConfigs[i])) {
141                 return false;
142             }
143         }
144         if( null != slideInSizes && null != modeCfg.slideInSizes ) {
145             if( slideInSizes.size() != modeCfg.slideInSizes.size() )
146                 return false;
147             for (Iterator JavaDoc<String JavaDoc> i=slideInSizes.keySet().iterator(); i.hasNext(); ) {
148                 String JavaDoc tcId = i.next();
149                 if( !slideInSizes.get(tcId).equals(modeCfg.slideInSizes.get(tcId)) )
150                     return false;
151             }
152         } else if( null != slideInSizes || null != modeCfg.slideInSizes ) {
153             return false;
154         }
155         if (!previousSelectedTopComponentID.equals(modeCfg.previousSelectedTopComponentID)) {
156             return false;
157         }
158         return true;
159     }
160     
161     public int hashCode() {
162         int hash = 17;
163         hash = 37 * hash + name.hashCode();
164         hash = 37 * hash + state;
165         hash = 37 * hash + kind;
166         if (side != null) {
167             hash = 37 * hash + side.hashCode();
168         }
169         for (int i = 0; i < constraints.length; i++) {
170             hash = 37 * hash + constraints[i].hashCode();
171         }
172         if (bounds != null) {
173             hash = 37 * hash + bounds.hashCode();
174         }
175         if (relativeBounds != null) {
176             hash = 37 * hash + relativeBounds.hashCode();
177         }
178         hash = 37 * hash + frameState;
179         hash = 37 * hash + selectedTopComponentID.hashCode();
180         hash = 37 * hash + (permanent ? 0 : 1);
181         for (int i = 0; i < tcRefConfigs.length; i++) {
182             hash = 37 * hash + tcRefConfigs[i].hashCode();
183         }
184         if( null != slideInSizes ) {
185             for (Iterator JavaDoc<String JavaDoc> i=slideInSizes.keySet().iterator(); i.hasNext(); ) {
186                 Object JavaDoc key = i.next();
187                 hash = 37 * hash + key.hashCode();
188                 hash = 37 * hash + slideInSizes.get(key).hashCode();
189             }
190         }
191         hash = 37 * hash + previousSelectedTopComponentID.hashCode();
192         return hash;
193     }
194     
195 }
196
Popular Tags