KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > AutoSizingPanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * AutoSizingPanel.java
21  *
22  * Created on May 27, 2006, 12:40 AM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.xml.schema.abe;
29
30 import java.awt.Component JavaDoc;
31 import java.awt.Dimension JavaDoc;
32 import java.awt.dnd.Autoscroll JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34
35 /**
36  *
37  * @author girix
38  */

39 public class AutoSizingPanel extends ABEBaseDropPanel{
40     private static final long serialVersionUID = 7526472295622776147L;
41
42     private boolean horizontalScaling = false;
43     private boolean verticalScaling = false;
44     private boolean fixedHeight = false;
45     private boolean fixedWidth = false;
46     private int fixedPanelHeight;
47     private int fixedPanelWidth;
48     
49     private int interComponentSpacing = 0;
50     
51     public AutoSizingPanel(InstanceUIContext context){
52         super(context);
53     }
54     
55     public Dimension JavaDoc getPreferredSize() {
56         int width = 0;
57         int height = 0;
58         for(Component JavaDoc child: this.getComponents()){
59             Dimension JavaDoc dim = child.getPreferredSize();
60             int curW = dim.width;
61             int curH = dim.height;
62             if(horizontalScaling)
63                 width += curW + getInterComponentSpacing();
64             else
65                 width = width < curW ? curW : width;
66             
67             if(verticalScaling)
68                 height += curH + getInterComponentSpacing();
69             else
70                 height = height < curH ? curH : height;
71         }
72
73         if(isFixedHeight()){
74             height = getFixedPanelHeight();
75         }
76         if(isFixedWidth()){
77             width = getFixedPanelWidth();
78         }
79         
80         return new Dimension JavaDoc(width, height);
81     }
82     
83     public Dimension JavaDoc getMinimumSize() {
84         return getPreferredSize();
85     }
86     
87     public boolean isHorizontalScaling() {
88         return horizontalScaling;
89     }
90     
91     public void setHorizontalScaling(boolean horizontalScaling) {
92         this.horizontalScaling = horizontalScaling;
93     }
94     
95     public boolean isVerticalScaling() {
96         return verticalScaling;
97     }
98     
99     public void setVerticalScaling(boolean verticalScaling) {
100         this.verticalScaling = verticalScaling;
101     }
102
103     public boolean isFixedHeight() {
104         return fixedHeight;
105     }
106
107     public void setFixedHeight(boolean fixedHeight) {
108         this.fixedHeight = fixedHeight;
109     }
110
111     public boolean isFixedWidth() {
112         return fixedWidth;
113     }
114
115     public void setFixedWidth(boolean fixedWidth) {
116         this.fixedWidth = fixedWidth;
117     }
118
119     public int getFixedPanelHeight() {
120         return fixedPanelHeight;
121     }
122
123     public void setFixedPanelHeight(int fixedPanelHeight) {
124         this.fixedPanelHeight = fixedPanelHeight;
125     }
126
127     public int getFixedPanelWidth() {
128         return fixedPanelWidth;
129     }
130
131     public void setFixedPanelWidth(int fixedPanelWidth) {
132         this.fixedPanelWidth = fixedPanelWidth;
133     }
134
135     public int getInterComponentSpacing() {
136         return interComponentSpacing;
137     }
138
139     public void setInterComponentSpacing(int interComponentSpacing) {
140         this.interComponentSpacing = interComponentSpacing;
141     }
142
143     public void accept(UIVisitor visitor) {
144         //noop
145
}
146     
147     
148     
149 }
150
Popular Tags