~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to core/windows/src/org/netbeans/core/windows/persistence/ModeConfig.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
6
 * The contents of this file are subject to the terms of either the GNU
 
7
 * General Public License Version 2 only ("GPL") or the Common
 
8
 * Development and Distribution License("CDDL") (collectively, the
 
9
 * "License"). You may not use this file except in compliance with the
 
10
 * License. You can obtain a copy of the License at
 
11
 * http://www.netbeans.org/cddl-gplv2.html
 
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
 
13
 * specific language governing permissions and limitations under the
 
14
 * License.  When distributing the software, include this License Header
 
15
 * Notice in each file and include the License file at
 
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
 
17
 * particular file as subject to the "Classpath" exception as provided
 
18
 * by Sun in the GPL Version 2 section of the License file that
 
19
 * accompanied this code. If applicable, add the following below the
 
20
 * License Header, with the fields enclosed by brackets [] replaced by
 
21
 * your own identifying information:
 
22
 * "Portions Copyrighted [year] [name of copyright owner]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * The Original Software is NetBeans. The Initial Developer of the Original
 
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
 
28
 * Microsystems, Inc. All Rights Reserved.
 
29
 *
 
30
 * If you wish your version of this file to be governed by only the CDDL
 
31
 * or only the GPL Version 2, indicate your decision by adding
 
32
 * "[Contributor] elects to include this software in this distribution
 
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
 
34
 * single choice of license, a recipient has the option to distribute
 
35
 * your version of this file under either the CDDL, the GPL Version 2 or
 
36
 * to extend the choice of license to its licensees as provided above.
 
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
 
38
 * Version 2 license, then the option applies only if the new code is
 
39
 * made subject to such option by the copyright holder.
 
40
 */
 
41
 
 
42
 
 
43
package org.netbeans.core.windows.persistence;
 
44
 
 
45
 
 
46
import java.awt.Rectangle;
 
47
import org.netbeans.core.windows.SplitConstraint;
 
48
 
 
49
import java.util.Iterator;
 
50
import java.util.Map;
 
51
 
 
52
 
 
53
/**
 
54
 * Class of mode config properties for communication with persistence management.
 
55
 * It keeps data which are read/written from/in .wsmode xml file.
 
56
 *
 
57
 * @author  Peter Zavadsky
 
58
 */
 
59
public class ModeConfig {
 
60
 
 
61
    /** Name of mode. Supposed to be internally for mode identification. */
 
62
    public String name;
 
63
 
 
64
    /** State of mode: 0 = split, 1 = separate. */
 
65
    public int state;
 
66
 
 
67
    /** Kind of mode: 0 = editor, 1 = view, 2 - sliding */
 
68
    public int kind;
 
69
    
 
70
    /** side for sliding kind*/
 
71
    public String side;
 
72
    
 
73
    /** Constraints of mode - path in tree model */
 
74
    public SplitConstraint[] constraints;
 
75
    
 
76
    //Part for separate state
 
77
    public Rectangle bounds;
 
78
    public Rectangle relativeBounds;
 
79
    
 
80
    public int frameState;
 
81
    
 
82
    //Common part
 
83
    /** Id of selected top component. */
 
84
    public String selectedTopComponentID;
 
85
    
 
86
    public boolean permanent = true;
 
87
    
 
88
    /** Array of TCRefConfigs. */
 
89
    public TCRefConfig[] tcRefConfigs;
 
90
    
 
91
    /** TopComponent ID -> slided-in size (width or height) - applies to sliding modes only*/
 
92
    public Map<String,Integer> slideInSizes;
 
93
    
 
94
    /** ID of top component that was selected before switching to/from maximized mode */
 
95
    public String previousSelectedTopComponentID;
 
96
    
 
97
    /** Creates a new instance of ModeConfig */
 
98
    public ModeConfig() {
 
99
        name = ""; // NOI18N
 
100
        constraints = new SplitConstraint[0];
 
101
        selectedTopComponentID = ""; // NOI18N
 
102
        tcRefConfigs = new TCRefConfig[0];
 
103
        previousSelectedTopComponentID = ""; // NOI18N
 
104
    }
 
105
    
 
106
    public boolean equals (Object obj) {
 
107
        if (this == obj) {
 
108
            return true;
 
109
        }
 
110
        if (!(obj instanceof ModeConfig)) {
 
111
            return false;
 
112
        }
 
113
        ModeConfig modeCfg = (ModeConfig) obj;
 
114
        if (!name.equals(modeCfg.name)) {
 
115
            return false;
 
116
        }
 
117
        if ((state != modeCfg.state) || (kind != modeCfg.kind)) {
 
118
            return false;
 
119
        }
 
120
        if (null != side && !side.equals( modeCfg.side ) ) {
 
121
            return false;
 
122
        } else if( null == side && null != modeCfg.side ) {
 
123
            return false;
 
124
        }
 
125
        //Order of constraints array is defined
 
126
        if (constraints.length != modeCfg.constraints.length) {
 
127
            return false;
 
128
        }
 
129
        for (int i = 0; i < constraints.length; i++) {
 
130
            if (!constraints[i].equals(modeCfg.constraints[i])) {
 
131
                return false;
 
132
            }
 
133
        }
 
134
        if ((bounds != null) && (modeCfg.bounds != null)) {
 
135
            if (!bounds.equals(modeCfg.bounds)) {
 
136
                return false;
 
137
            }
 
138
        } else if ((bounds != null) || (modeCfg.bounds != null)) {
 
139
            return false;
 
140
        }
 
141
        if ((relativeBounds != null) && (modeCfg.relativeBounds != null)) {
 
142
            if (!relativeBounds.equals(modeCfg.relativeBounds)) {
 
143
                return false;
 
144
            }
 
145
        } else if ((relativeBounds != null) || (modeCfg.relativeBounds != null)) {
 
146
            return false;
 
147
        }
 
148
        if (frameState != modeCfg.frameState) {
 
149
            return false;
 
150
        }
 
151
        if (!selectedTopComponentID.equals(modeCfg.selectedTopComponentID)) {
 
152
            return false;
 
153
        }
 
154
        if (permanent != modeCfg.permanent) {
 
155
            return false;
 
156
        }
 
157
        //Order of tcRefConfigs is defined
 
158
        if (tcRefConfigs.length != modeCfg.tcRefConfigs.length) {
 
159
            return false;
 
160
        }
 
161
        for (int i = 0; i < tcRefConfigs.length; i++) {
 
162
            if (!tcRefConfigs[i].equals(modeCfg.tcRefConfigs[i])) {
 
163
                return false;
 
164
            }
 
165
        }
 
166
        if( null != slideInSizes && null != modeCfg.slideInSizes ) {
 
167
            if( slideInSizes.size() != modeCfg.slideInSizes.size() )
 
168
                return false;
 
169
            for (Iterator<String> i=slideInSizes.keySet().iterator(); i.hasNext(); ) {
 
170
                String tcId = i.next();
 
171
                if( !slideInSizes.get(tcId).equals(modeCfg.slideInSizes.get(tcId)) )
 
172
                    return false;
 
173
            }
 
174
        } else if( null != slideInSizes || null != modeCfg.slideInSizes ) {
 
175
            return false;
 
176
        }
 
177
        if (!previousSelectedTopComponentID.equals(modeCfg.previousSelectedTopComponentID)) {
 
178
            return false;
 
179
        }
 
180
        return true;
 
181
    }
 
182
    
 
183
    public int hashCode() {
 
184
        int hash = 17;
 
185
        hash = 37 * hash + name.hashCode();
 
186
        hash = 37 * hash + state;
 
187
        hash = 37 * hash + kind;
 
188
        if (side != null) {
 
189
            hash = 37 * hash + side.hashCode();
 
190
        }
 
191
        for (int i = 0; i < constraints.length; i++) {
 
192
            hash = 37 * hash + constraints[i].hashCode();
 
193
        }
 
194
        if (bounds != null) {
 
195
            hash = 37 * hash + bounds.hashCode();
 
196
        }
 
197
        if (relativeBounds != null) {
 
198
            hash = 37 * hash + relativeBounds.hashCode();
 
199
        }
 
200
        hash = 37 * hash + frameState;
 
201
        hash = 37 * hash + selectedTopComponentID.hashCode();
 
202
        hash = 37 * hash + (permanent ? 0 : 1);
 
203
        for (int i = 0; i < tcRefConfigs.length; i++) {
 
204
            hash = 37 * hash + tcRefConfigs[i].hashCode();
 
205
        }
 
206
        if( null != slideInSizes ) {
 
207
            for (Iterator<String> i=slideInSizes.keySet().iterator(); i.hasNext(); ) {
 
208
                Object key = i.next();
 
209
                hash = 37 * hash + key.hashCode();
 
210
                hash = 37 * hash + slideInSizes.get(key).hashCode();
 
211
            }
 
212
        }
 
213
        hash = 37 * hash + previousSelectedTopComponentID.hashCode();
 
214
        return hash;
 
215
    }
 
216
    
 
217
}