KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > windows > view > ui > MultiSplitCell


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.view.ui;
21
22 import java.awt.Component JavaDoc;
23 import org.netbeans.core.windows.view.ViewElement;
24
25 /**
26  * A wrapper class for a component displayed in MultiSplitPane.
27  */

28 class MultiSplitCell {
29
30     private ViewElement view;
31     //normalized resize weight, used internally only
32
private double normalizedResizeWeight = 0.0;
33     private double initialSplitWeight;
34     //the size (widht or height) required by this component, used when resizing all split components
35
private int requiredSize = -1;
36     private boolean dirty = false;
37     private boolean isHorizontalSplit;
38     
39     MultiSplitCell( ViewElement view, double initialSplitWeight, boolean isHorizontalSplit ) {
40         this.view = view;
41         this.initialSplitWeight = initialSplitWeight;
42         this.isHorizontalSplit = isHorizontalSplit;
43     }
44
45     public boolean equals( Object JavaDoc o ) {
46         if( o instanceof MultiSplitCell ) {
47             MultiSplitCell cell = (MultiSplitCell)o;
48             return getComponent().equals( cell.getComponent() );
49         }
50         return super.equals( o );
51     }
52     
53     boolean isDirty() {
54         return dirty;
55     }
56     
57     void setDirty( boolean isDirty ) {
58         this.dirty = isDirty;
59     }
60     
61     void maybeResetToInitialSize( int newSize ) {
62         if( -1 == requiredSize ) {
63             requiredSize = getSize();
64             if( requiredSize <= 0 || requiredSize >= newSize ) {
65                 requiredSize = (int)(newSize * initialSplitWeight + 0.5);
66             }
67             dirty = true;
68         }
69     }
70     
71     double getResizeWeight() {
72         return view.getResizeWeight();
73     }
74     
75     Component JavaDoc getComponent() {
76         return view.getComponent();
77     }
78
79     /**
80      * @param dividerSize The width of splitter bar.
81      * @return The minimum size of this cell. If this cell is a split cell then the
82      * result is a sum of minimum sizes of all children cells.
83      */

84     int getMinimumSize() {
85         if( isHorizontalSplit )
86             return getComponent().getMinimumSize().width;
87         return getComponent().getMinimumSize().height;
88     }
89     
90     int getRequiredSize() {
91         if( -1 == requiredSize ) {
92             if( isHorizontalSplit )
93                 return getComponent().getPreferredSize().width;
94             return getComponent().getPreferredSize().height;
95         }
96         return requiredSize;
97     }
98     /**
99      * Adjust cell's dimensions.
100      */

101     void layout( int x, int y, int width, int height ) {
102         if( isHorizontalSplit ) {
103             dirty |= x != getLocation() || requiredSize != width;
104             requiredSize = width;
105         } else {
106             dirty |= y != getLocation() || requiredSize != height;
107             requiredSize = height;
108         }
109         getComponent().setBounds( x, y, width, height );
110     }
111     
112     void setRequiredSize( int newRequiredSize ) {
113         dirty |= newRequiredSize != requiredSize;
114         this.requiredSize = newRequiredSize;
115     }
116     
117     int getLocation() {
118         if( isHorizontalSplit )
119             return getComponent().getLocation().x;
120         return getComponent().getLocation().y;
121     }
122     
123     int getSize() {
124         if( isHorizontalSplit )
125             return getComponent().getSize().width;
126         return getComponent().getSize().height;
127     }
128     
129     double getNormalizedResizeWeight() {
130         return normalizedResizeWeight;
131     }
132     
133     void setNormalizedResizeWeight( double newNormalizedResizeWeight ) {
134         this.normalizedResizeWeight = newNormalizedResizeWeight;
135     }
136     
137     ViewElement getViewElement() {
138         return view;
139     }
140 }
141
Popular Tags