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

« back to all changes in this revision

Viewing changes to core/windows/src/org/netbeans/core/windows/persistence/WindowManagerConfig.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 org.netbeans.core.windows.SplitConstraint;
 
47
 
 
48
import java.awt.*;
 
49
 
 
50
 
 
51
/**
 
52
 * Class of window manager config properties for communication with persistence management.
 
53
 * It keeps data which are read/written from/in .wsmgr xml file.
 
54
 *
 
55
 * @author  Peter Zavadsky
 
56
 */
 
57
public class WindowManagerConfig {
 
58
    /////////////////////
 
59
    // SEPARATED STATE
 
60
    //////////
 
61
    // BEGIN Values specific for initial main window position
 
62
    // Note: Only absolute bounds are saved [x,y,w,h].
 
63
    //////////
 
64
    /** Flag to control horizontal position of main window. If it is true x is
 
65
     undefined. */
 
66
    public boolean centeredHorizontallySeparated;
 
67
    
 
68
    /** Flag to control vertical position of main window . If it is true y is
 
69
     undefined. */
 
70
    public boolean centeredVerticallySeparated;
 
71
    
 
72
    /** Horizontal absolute position of main window. */
 
73
    public int xSeparated;
 
74
    
 
75
    /** Vertical absolute position of main window */
 
76
    public int ySeparated;
 
77
    
 
78
    /** Width of main window. -1 means not set. Either width or relative width
 
79
     should be set. */
 
80
    public int widthSeparated;
 
81
    
 
82
    /** Height of main window. -1 means not set. Either height or relative height
 
83
     should be set. */
 
84
    public int heightSeparated;
 
85
    
 
86
    /** Relative x of main window. -1 means not set. */
 
87
    public float relativeXSeparated;
 
88
    
 
89
    /** Relative y of main window. -1 means not set. */
 
90
    public float relativeYSeparated;
 
91
    
 
92
    /** Relative width of main window. -1 means not set. */
 
93
    public float relativeWidthSeparated;
 
94
    
 
95
    /** Relative height of main window. -1 means not set. */
 
96
    public float relativeHeightSeparated;
 
97
    //////////
 
98
    // END
 
99
    //////////
 
100
    
 
101
    //////////////
 
102
    // JOINED STATE
 
103
    //////////
 
104
    // BEGIN Values specific for initial main window position
 
105
    // Note: Only absolute bounds are saved [x,y,w,h].
 
106
    //////////
 
107
    /** Flag to control horizontal position of main window. If it is true x is
 
108
     undefined. */
 
109
    public boolean centeredHorizontallyJoined;
 
110
    
 
111
    /** Flag to control vertical position of main window . If it is true y is
 
112
     undefined. */
 
113
    public boolean centeredVerticallyJoined;
 
114
    
 
115
    /** Horizontal absolute position of main window. */
 
116
    public int xJoined;
 
117
    
 
118
    /** Vertical absolute position of main window */
 
119
    public int yJoined;
 
120
    
 
121
    /** Width of main window. -1 means not set. Either width or relative width
 
122
     should be set. */
 
123
    public int widthJoined;
 
124
    
 
125
    /** Height of main window. -1 means not set. Either height or relative height
 
126
     should be set. */
 
127
    public int heightJoined;
 
128
    
 
129
    /** Relative x of main window. -1 means not set. */
 
130
    public float relativeXJoined;
 
131
    
 
132
    /** Relative y of main window. -1 means not set. */
 
133
    public float relativeYJoined;
 
134
    
 
135
    /** Relative width of main window. -1 means not set. */
 
136
    public float relativeWidthJoined;
 
137
    
 
138
    /** Relative height of main window. -1 means not set. */
 
139
    public float relativeHeightJoined;
 
140
    
 
141
    /** Minimum allowed width of main window for computing initial size */
 
142
    public int maximizeIfWidthBelowJoined;
 
143
    
 
144
    /** Minimum allowed height of main window for computing initial size */
 
145
    public int maximizeIfHeightBelowJoined;
 
146
    //////////
 
147
    // END
 
148
    //////////
 
149
    /** Frame state of main window when in tiled(joined) state.
 
150
     * Possible values are taken from java.awt.Frame:
 
151
     * NORMAL
 
152
     * ICONIFIED
 
153
     * MAXIMIZED_HORIZ
 
154
     * MAXIMIZED_VERT
 
155
     * MAXIMIZED_BOTH
 
156
     */
 
157
    public int mainWindowFrameStateJoined;
 
158
    /** Frame state of main window when in separated state.
 
159
     * Possible values are taken from java.awt.Frame:
 
160
     * NORMAL
 
161
     * ICONIFIED
 
162
     * MAXIMIZED_HORIZ
 
163
     * MAXIMIZED_VERT
 
164
     * MAXIMIZED_BOTH
 
165
     */
 
166
    public int mainWindowFrameStateSeparated;
 
167
    
 
168
    /** State of editor area: 0 = joined, 1 = separated. */
 
169
    public int editorAreaState;
 
170
    /** Constraints of editor area - path in tree model.
 
171
     * List of <code>Item</code>S. */
 
172
    public SplitConstraint[] editorAreaConstraints;
 
173
    /** Bounds of editor area. */
 
174
    public Rectangle editorAreaBounds;
 
175
    /** Relative bounds of editor area. */
 
176
    public Rectangle editorAreaRelativeBounds;
 
177
    /** Frame state of editor area when in separated 'state'.
 
178
     * Possible values are taken from java.awt.Frame:
 
179
     * NORMAL
 
180
     * ICONIFIED
 
181
     * MAXIMIZED_HORIZ
 
182
     * MAXIMIZED_VERT
 
183
     * MAXIMIZED_BOTH
 
184
     */
 
185
    public int editorAreaFrameState;
 
186
 
 
187
    /** Size of screen. */
 
188
    public Dimension screenSize;
 
189
    /** Name of active mode. */
 
190
    public String activeModeName;
 
191
    /** Name of maximized mode (editor). */
 
192
    public String editorMaximizedModeName;
 
193
    /** Name of maximized mode (view). */
 
194
    public String viewMaximizedModeName;
 
195
    /** Name of toolbar configuration. */
 
196
    public String toolbarConfiguration;
 
197
    /** Preferred size of toolbar icons. */
 
198
    public int preferredToolbarIconSize;
 
199
    /** List of <code>ModeConfig</code>S. */
 
200
    public ModeConfig[] modes;
 
201
    /** List of <code>GroupConfig</code>S. */
 
202
    public GroupConfig[] groups;
 
203
    /** List of TopComponent Ids from recent view list. */
 
204
    public String[] tcIdViewList;
 
205
    
 
206
    /** Creates a new instance of WindowManagerConfig */
 
207
    public WindowManagerConfig() {
 
208
        editorAreaConstraints = new SplitConstraint[0];
 
209
        activeModeName = ""; // NOI18N
 
210
        editorMaximizedModeName = ""; // NOI18N
 
211
        viewMaximizedModeName = ""; // NOI18N
 
212
        toolbarConfiguration = ""; // NOI18N
 
213
        modes = new ModeConfig[0];
 
214
        groups = new GroupConfig[0];
 
215
        tcIdViewList = new String[0];
 
216
    }
 
217
    
 
218
    public boolean equals (Object obj) {
 
219
        if (this == obj) {
 
220
            return true;
 
221
        }
 
222
        if (!(obj instanceof WindowManagerConfig)) {
 
223
            return false;
 
224
        }
 
225
        WindowManagerConfig wmCfg = (WindowManagerConfig) obj;
 
226
        if ((centeredHorizontallySeparated != wmCfg.centeredHorizontallySeparated) ||
 
227
            (centeredVerticallySeparated != wmCfg.centeredVerticallySeparated)) {
 
228
            return false;
 
229
        }
 
230
        if ((xSeparated != wmCfg.xSeparated) ||
 
231
            (ySeparated != wmCfg.ySeparated) ||
 
232
            (widthSeparated != wmCfg.widthSeparated) ||
 
233
            (heightSeparated != wmCfg.heightSeparated)) {
 
234
            return false;
 
235
        }
 
236
        if ((relativeXSeparated != wmCfg.relativeXSeparated) ||
 
237
            (relativeYSeparated != wmCfg.relativeYSeparated)) {
 
238
            return false;
 
239
        }
 
240
        if ((relativeWidthSeparated != wmCfg.relativeWidthSeparated) || 
 
241
            (relativeHeightSeparated != wmCfg.relativeHeightSeparated)) {
 
242
            return false;
 
243
        }
 
244
        
 
245
        if ((centeredHorizontallyJoined != wmCfg.centeredHorizontallyJoined) ||
 
246
            (centeredVerticallyJoined != wmCfg.centeredVerticallyJoined)) {
 
247
            return false;
 
248
        }
 
249
        if ((xJoined != wmCfg.xJoined) ||
 
250
            (yJoined != wmCfg.yJoined) ||
 
251
            (widthJoined != wmCfg.widthJoined) ||
 
252
            (heightJoined != wmCfg.heightJoined)) {
 
253
            return false;
 
254
        }
 
255
        if ((relativeXJoined != wmCfg.relativeXJoined) ||
 
256
            (relativeYJoined != wmCfg.relativeYJoined)) {
 
257
            return false;
 
258
        }
 
259
        if ((relativeWidthJoined != wmCfg.relativeWidthJoined) || 
 
260
            (relativeHeightJoined != wmCfg.relativeHeightJoined)) {
 
261
            return false;
 
262
        }
 
263
        if ((maximizeIfWidthBelowJoined != wmCfg.maximizeIfWidthBelowJoined) || 
 
264
            (maximizeIfHeightBelowJoined != wmCfg.maximizeIfHeightBelowJoined)) {
 
265
            return false;
 
266
        }
 
267
        
 
268
        if (mainWindowFrameStateJoined != wmCfg.mainWindowFrameStateJoined) {
 
269
            return false;
 
270
        }
 
271
        if (mainWindowFrameStateSeparated != wmCfg.mainWindowFrameStateSeparated) {
 
272
            return false;
 
273
        }
 
274
        if (editorAreaState != wmCfg.editorAreaState) {
 
275
            return false;
 
276
        }
 
277
        //Order of editorAreaConstraints array is defined
 
278
        if (editorAreaConstraints.length != wmCfg.editorAreaConstraints.length) {
 
279
            return false;
 
280
        }
 
281
        for (int i = 0; i < editorAreaConstraints.length; i++) {
 
282
            if (!editorAreaConstraints[i].equals(wmCfg.editorAreaConstraints[i])) {
 
283
                return false;
 
284
            }
 
285
        }
 
286
        if ((editorAreaBounds != null) && (wmCfg.editorAreaBounds != null)) {
 
287
            if (!editorAreaBounds.equals(wmCfg.editorAreaBounds)) {
 
288
                return false;
 
289
            }
 
290
        } else if ((editorAreaBounds != null) || (wmCfg.editorAreaBounds != null)) {
 
291
            return false;
 
292
        }
 
293
        if ((editorAreaRelativeBounds != null) && (wmCfg.editorAreaRelativeBounds != null)) {
 
294
            if (!editorAreaRelativeBounds.equals(wmCfg.editorAreaRelativeBounds)) {
 
295
                return false;
 
296
            }
 
297
        } else if ((editorAreaRelativeBounds != null) || (wmCfg.editorAreaRelativeBounds != null)) {
 
298
            return false;
 
299
        }
 
300
        if (editorAreaFrameState != wmCfg.editorAreaFrameState) {
 
301
            return false;
 
302
        }
 
303
        if ((screenSize != null) && (wmCfg.screenSize != null)) {
 
304
            if (!screenSize.equals(wmCfg.screenSize)) {
 
305
                return false;
 
306
            }
 
307
        } else if ((screenSize != null) || (wmCfg.screenSize != null)) {
 
308
            return false;
 
309
        }
 
310
        if (!activeModeName.equals(wmCfg.activeModeName)) {
 
311
            return false;
 
312
        }
 
313
        if (!editorMaximizedModeName.equals(wmCfg.editorMaximizedModeName)) {
 
314
            return false;
 
315
        }
 
316
        if (!viewMaximizedModeName.equals(wmCfg.viewMaximizedModeName)) {
 
317
            return false;
 
318
        }
 
319
        if (!toolbarConfiguration.equals(wmCfg.toolbarConfiguration)) {
 
320
            return false;
 
321
        }
 
322
        if (preferredToolbarIconSize != wmCfg.preferredToolbarIconSize) {
 
323
            return false;
 
324
        }
 
325
        //Order of modes array is NOT defined
 
326
        if (modes.length != wmCfg.modes.length) {
 
327
            return false;
 
328
        }
 
329
        for (int i = 0; i < modes.length; i++) {
 
330
            ModeConfig modeCfg = null;
 
331
            for (int j = 0; j < wmCfg.modes.length; j++) {
 
332
                if (modes[i].name.equals(wmCfg.modes[j].name)) {
 
333
                    modeCfg = wmCfg.modes[j];
 
334
                    break;
 
335
                }
 
336
            }
 
337
            if (modeCfg == null) {
 
338
                return false;
 
339
            }
 
340
            if (!modes[i].equals(modeCfg)) {
 
341
                return false;
 
342
            }
 
343
        }
 
344
        //Order of groups array is NOT defined
 
345
        if (groups.length != wmCfg.groups.length) {
 
346
            return false;
 
347
        }
 
348
        for (int i = 0; i < groups.length; i++) {
 
349
            GroupConfig groupCfg = null;
 
350
            for (int j = 0; j < wmCfg.groups.length; j++) {
 
351
                if (groups[i].name.equals(wmCfg.groups[j].name)) {
 
352
                    groupCfg = wmCfg.groups[j];
 
353
                    break;
 
354
                }
 
355
            }
 
356
            if (groupCfg == null) {
 
357
                return false;
 
358
            }
 
359
            if (!groups[i].equals(groupCfg)) {
 
360
                return false;
 
361
            }
 
362
        }
 
363
        //Order of tcRefConfigs is defined
 
364
        if (tcIdViewList.length != wmCfg.tcIdViewList.length) {
 
365
            return false;
 
366
        }
 
367
        for (int i = 0; i < tcIdViewList.length; i++) {
 
368
            if (!tcIdViewList[i].equals(wmCfg.tcIdViewList[i])) {
 
369
                return false;
 
370
            }
 
371
        }
 
372
        return true;
 
373
    }
 
374
    
 
375
    public int hashCode() {
 
376
        int hash = 17;
 
377
        
 
378
        hash = 37 * hash + (centeredHorizontallySeparated ? 0 : 1);
 
379
        hash = 37 * hash + (centeredVerticallySeparated ? 0 : 1);
 
380
        hash = 37 * hash + xSeparated;
 
381
        hash = 37 * hash + ySeparated;
 
382
        hash = 37 * hash + widthSeparated;
 
383
        hash = 37 * hash + heightSeparated;
 
384
        hash = 37 * hash + Float.floatToIntBits(relativeXSeparated);
 
385
        hash = 37 * hash + Float.floatToIntBits(relativeYSeparated);
 
386
        hash = 37 * hash + Float.floatToIntBits(relativeWidthSeparated);
 
387
        hash = 37 * hash + Float.floatToIntBits(relativeHeightSeparated);
 
388
        
 
389
        hash = 37 * hash + (centeredHorizontallyJoined ? 0 : 1);
 
390
        hash = 37 * hash + (centeredVerticallyJoined ? 0 : 1);
 
391
        hash = 37 * hash + xJoined;
 
392
        hash = 37 * hash + yJoined;
 
393
        hash = 37 * hash + widthJoined;
 
394
        hash = 37 * hash + heightJoined;
 
395
        hash = 37 * hash + Float.floatToIntBits(relativeXJoined);
 
396
        hash = 37 * hash + Float.floatToIntBits(relativeYJoined);
 
397
        hash = 37 * hash + Float.floatToIntBits(relativeWidthJoined);
 
398
        hash = 37 * hash + Float.floatToIntBits(relativeHeightJoined);
 
399
        hash = 37 * hash + maximizeIfWidthBelowJoined;
 
400
        hash = 37 * hash + maximizeIfHeightBelowJoined;
 
401
 
 
402
        hash = 37 * hash + mainWindowFrameStateJoined;
 
403
        hash = 37 * hash + mainWindowFrameStateSeparated;
 
404
        hash = 37 * hash + editorAreaState;
 
405
        for (int i = 0; i < editorAreaConstraints.length; i++) {
 
406
            hash = 37 * hash + editorAreaConstraints[i].hashCode();
 
407
        }
 
408
        if (editorAreaBounds != null) {
 
409
            hash = 37 * hash + editorAreaBounds.hashCode();
 
410
        }
 
411
        if (editorAreaRelativeBounds != null) {
 
412
            hash = 37 * hash + editorAreaRelativeBounds.hashCode();
 
413
        }
 
414
        hash = 37 * hash + editorAreaFrameState;
 
415
        if (screenSize != null) {
 
416
            hash = 37 * hash + screenSize.hashCode();
 
417
        }
 
418
        hash = 37 * hash + activeModeName.hashCode();
 
419
        hash = 37 * hash + editorMaximizedModeName.hashCode();
 
420
        hash = 37 * hash + viewMaximizedModeName.hashCode();
 
421
        hash = 37 * hash + toolbarConfiguration.hashCode();
 
422
        hash = 37 * hash + preferredToolbarIconSize;
 
423
        for (int i = 0; i < modes.length; i++) {
 
424
            hash = 37 * hash + modes[i].hashCode();
 
425
        }
 
426
        for (int i = 0; i < groups.length; i++) {
 
427
            hash = 37 * hash + groups[i].hashCode();
 
428
        }
 
429
        for (int i = 0; i < tcIdViewList.length; i++) {
 
430
            hash = 37 * hash + tcIdViewList[i].hashCode();
 
431
        }
 
432
        return hash;
 
433
    }
 
434
    
 
435
}