|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
TableLayoutCell.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
$Id: TableLayoutCell.java,v 1.2 2003/12/23 13:41:57 jstrachan Exp $
|
|
3 |
|
|
4 |
Copyright 2003 (C) James Strachan and Bob Mcwhirter. All Rights Reserved.
|
|
5 |
|
|
6 |
Redistribution and use of this software and associated documentation
|
|
7 |
("Software"), with or without modification, are permitted provided
|
|
8 |
that the following conditions are met:
|
|
9 |
|
|
10 |
1. Redistributions of source code must retain copyright
|
|
11 |
statements and notices. Redistributions must also contain a
|
|
12 |
copy of this document.
|
|
13 |
|
|
14 |
2. Redistributions in binary form must reproduce the
|
|
15 |
above copyright notice, this list of conditions and the
|
|
16 |
following disclaimer in the documentation and/or other
|
|
17 |
materials provided with the distribution.
|
|
18 |
|
|
19 |
3. The name "groovy" must not be used to endorse or promote
|
|
20 |
products derived from this Software without prior written
|
|
21 |
permission of The Codehaus. For written permission,
|
|
22 |
please contact info@codehaus.org.
|
|
23 |
|
|
24 |
4. Products derived from this Software may not be called "groovy"
|
|
25 |
nor may "groovy" appear in their names without prior written
|
|
26 |
permission of The Codehaus. "groovy" is a registered
|
|
27 |
trademark of The Codehaus.
|
|
28 |
|
|
29 |
5. Due credit should be given to The Codehaus -
|
|
30 |
http://groovy.codehaus.org/
|
|
31 |
|
|
32 |
THIS SOFTWARE IS PROVIDED BY THE CODEHAUS AND CONTRIBUTORS
|
|
33 |
``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
|
|
34 |
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
35 |
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
36 |
THE CODEHAUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
37 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
38 |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
39 |
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
40 |
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
41 |
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
42 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
43 |
OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
44 |
|
|
45 |
*/
|
|
46 |
package groovy.swing.impl;
|
|
47 |
|
|
48 |
import java.awt.Component;
|
|
49 |
import java.awt.GridBagConstraints;
|
|
50 |
import java.util.logging.Level;
|
|
51 |
import java.util.logging.Logger;
|
|
52 |
|
|
53 |
/**
|
|
54 |
* Represents a cell in a table layout
|
|
55 |
*
|
|
56 |
* @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
|
|
57 |
* @version $Revision: 1.2 $
|
|
58 |
*/
|
|
59 |
public class TableLayoutCell implements ContainerFacade { |
|
60 |
|
|
61 |
protected static final Logger log = Logger.getLogger(TableLayoutCell.class.getName()); |
|
62 |
|
|
63 |
private TableLayoutRow parent;
|
|
64 |
private Component component;
|
|
65 |
private GridBagConstraints constraints;
|
|
66 |
private String align;
|
|
67 |
private String valign;
|
|
68 |
private int colspan = 1; |
|
69 |
private int rowspan = 1; |
|
70 |
private boolean colfill = false; |
|
71 |
private boolean rowfill = false; |
|
72 |
|
|
73 |
|
|
74 | 0 |
public TableLayoutCell(TableLayoutRow parent) {
|
75 | 0 |
this.parent = parent;
|
76 |
} |
|
77 |
|
|
78 | 0 |
public void addComponent(Component component) { |
79 | 0 |
if (this.component != null) { |
80 | 0 |
log.log(Level.WARNING, "This td cell already has a component: " + component);
|
81 |
} |
|
82 | 0 |
this.component = component;
|
83 | 0 |
parent.addCell(this);
|
84 |
} |
|
85 |
|
|
86 | 0 |
public Component getComponent() {
|
87 | 0 |
return component;
|
88 |
} |
|
89 |
|
|
90 |
/**
|
|
91 |
* Sets the horizontal alignment to a case insensitive value of {LEFT, CENTER, RIGHT}
|
|
92 |
*/
|
|
93 | 0 |
public void setAlign(String align) { |
94 | 0 |
this.align = align;
|
95 |
} |
|
96 |
|
|
97 |
/**
|
|
98 |
* Sets the vertical alignment to a case insensitive value of {TOP, MIDDLE, BOTTOM}
|
|
99 |
*/
|
|
100 | 0 |
public void setValign(String valign) { |
101 | 0 |
this.valign = valign;
|
102 |
} |
|
103 |
|
|
104 |
|
|
105 |
/**
|
|
106 |
* Sets the number of columns that this cell should span. The default value is 1
|
|
107 |
*/
|
|
108 | 0 |
public void setColspan(int colspan) { |
109 | 0 |
this.colspan = colspan;
|
110 |
} |
|
111 |
|
|
112 |
/**
|
|
113 |
* Sets the number of rows that this cell should span. The default value is 1
|
|
114 |
*/
|
|
115 | 0 |
public void setRowspan(int rowspan) { |
116 | 0 |
this.rowspan = rowspan;
|
117 |
} |
|
118 |
|
|
119 |
/**
|
|
120 |
* Returns the colfill.
|
|
121 |
* @return boolean
|
|
122 |
*/
|
|
123 | 0 |
public boolean isColfill() { |
124 | 0 |
return colfill;
|
125 |
} |
|
126 |
|
|
127 |
/**
|
|
128 |
* Returns the rowfill.
|
|
129 |
* @return boolean
|
|
130 |
*/
|
|
131 | 0 |
public boolean isRowfill() { |
132 | 0 |
return rowfill;
|
133 |
} |
|
134 |
|
|
135 |
/**
|
|
136 |
* Sets whether or not this column should allow its component to stretch to fill the space available
|
|
137 |
*/
|
|
138 | 0 |
public void setColfill(boolean colfill) { |
139 | 0 |
this.colfill = colfill;
|
140 |
} |
|
141 |
|
|
142 |
/**
|
|
143 |
* Sets whether or not this row should allow its component to stretch to fill the space available
|
|
144 |
*/
|
|
145 | 0 |
public void setRowfill(boolean rowfill) { |
146 | 0 |
this.rowfill = rowfill;
|
147 |
} |
|
148 |
|
|
149 |
|
|
150 |
/**
|
|
151 |
* @return the constraints of this cell
|
|
152 |
*/
|
|
153 | 0 |
public GridBagConstraints getConstraints() {
|
154 | 0 |
if (constraints == null) { |
155 | 0 |
constraints = createConstraints(); |
156 |
} |
|
157 | 0 |
return constraints;
|
158 |
} |
|
159 |
|
|
160 |
// Implementation methods
|
|
161 |
//-------------------------------------------------------------------------
|
|
162 |
|
|
163 | 0 |
protected GridBagConstraints createConstraints() {
|
164 | 0 |
GridBagConstraints answer = new GridBagConstraints();
|
165 | 0 |
answer.anchor = getAnchor(); |
166 | 0 |
if (colspan < 1) {
|
167 | 0 |
colspan = 1; |
168 |
} |
|
169 | 0 |
if (rowspan < 1) {
|
170 | 0 |
rowspan = 1; |
171 |
} |
|
172 | 0 |
if (isColfill()) {
|
173 | 0 |
answer.fill = isRowfill() |
174 |
? GridBagConstraints.BOTH |
|
175 |
: GridBagConstraints.HORIZONTAL; |
|
176 |
} |
|
177 |
else {
|
|
178 | 0 |
answer.fill = isRowfill() |
179 |
? GridBagConstraints.VERTICAL |
|
180 |
: GridBagConstraints.NONE; |
|
181 |
} |
|
182 | 0 |
answer.weightx = 0.2; |
183 | 0 |
answer.weighty = 0; |
184 | 0 |
answer.gridwidth = colspan; |
185 | 0 |
answer.gridheight = rowspan; |
186 | 0 |
return answer;
|
187 |
} |
|
188 |
|
|
189 |
/**
|
|
190 |
* @return the GridBagConstraints enumeration for achor
|
|
191 |
*/
|
|
192 | 0 |
protected int getAnchor() { |
193 | 0 |
boolean isTop = "top".equalsIgnoreCase(valign); |
194 | 0 |
boolean isBottom = "bottom".equalsIgnoreCase(valign); |
195 |
|
|
196 | 0 |
if ("center".equalsIgnoreCase(align)) { |
197 | 0 |
if (isTop) {
|
198 | 0 |
return GridBagConstraints.NORTH;
|
199 |
} |
|
200 | 0 |
else if (isBottom) { |
201 | 0 |
return GridBagConstraints.SOUTH;
|
202 |
} |
|
203 |
else {
|
|
204 | 0 |
return GridBagConstraints.CENTER;
|
205 |
} |
|
206 |
} |
|
207 | 0 |
else if ("right".equalsIgnoreCase(align)) { |
208 | 0 |
if (isTop) {
|
209 | 0 |
return GridBagConstraints.NORTHEAST;
|
210 |
} |
|
211 | 0 |
else if (isBottom) { |
212 | 0 |
return GridBagConstraints.SOUTHEAST;
|
213 |
} |
|
214 |
else {
|
|
215 | 0 |
return GridBagConstraints.EAST;
|
216 |
} |
|
217 |
} |
|
218 |
else {
|
|
219 |
// defaults to left
|
|
220 | 0 |
if (isTop) {
|
221 | 0 |
return GridBagConstraints.NORTHWEST;
|
222 |
} |
|
223 | 0 |
else if (isBottom) { |
224 | 0 |
return GridBagConstraints.SOUTHWEST;
|
225 |
} |
|
226 |
else {
|
|
227 | 0 |
return GridBagConstraints.WEST;
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
|
|