001: /*
002: * $Id:$
003: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
004: *
005: * http://izpack.org/
006: * http://izpack.codehaus.org/
007: *
008: * Copyright 2006 Klaus Bartz
009: *
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: */
022: package com.izforge.izpack.gui;
023:
024: import java.awt.Component;
025: import java.awt.Rectangle;
026:
027: /**
028: * Constraints class for the layout manager <code>IzPanelLayout</code>.
029: *
030: */
031: public class IzPanelConstraints implements Cloneable, LayoutConstants {
032:
033: /**
034: * Current defined gaps. Here are the defaults which can be overwritten at the first call to
035: * method getGap. The gap type will be determined by the array index and has to be synchron to
036: * the gap identifier and the indices of array GAP_NAME_LOOK_UP
037: */
038: private int xCellAlignment = IzPanelLayout.DEFAULT_X_ALIGNMENT[0];
039:
040: private int yCellAlignment = IzPanelLayout.DEFAULT_Y_ALIGNMENT[0];
041:
042: private int xPos = 0;
043:
044: private int yPos = NEXT_ROW;
045:
046: private int xWeight = 1;
047:
048: private int yWeight = 1;
049:
050: private int xGap = IzPanelLayout.DEFAULT_X_GAPS[-LABEL_GAP];
051:
052: private int yGap = IzPanelLayout.DEFAULT_Y_GAPS[-LABEL_GAP];
053:
054: private double xStretch = 0.0;
055:
056: private double yStretch = 0.0;
057:
058: private Rectangle bounds;
059:
060: /** for private use by the layout manager */
061: Component component = null;
062:
063: /** for private use by the layout manager */
064: int preferredHeight = 0;
065:
066: /**
067: * Returns the declared stretch value in x direction.
068: *
069: * @return the declared stretch value in x direction
070: */
071: public double getXStretch() {
072: return xStretch;
073: }
074:
075: /**
076: * Sets the given value as stretch value for x direction.
077: *
078: * @param stretch value to be set
079: */
080: public void setXStretch(double stretch) {
081: this .xStretch = stretch;
082: }
083:
084: /**
085: * Returns the declared stretch value in y direction.
086: *
087: * @return the declared stretch value in y direction
088: */
089: public double getYStretch() {
090: return yStretch;
091: }
092:
093: /**
094: * Sets the given value as stretch value for y direction.
095: *
096: * @param stretch value to be set
097: */
098: public void setYStretch(double stretch) {
099: this .yStretch = stretch;
100: }
101:
102: /**
103: * Returns the declared x gap value.
104: *
105: * @return the declared x gap value
106: */
107: public int getXGap() {
108: return xGap;
109: }
110:
111: /**
112: * Sets the given value as x gap.
113: *
114: * @param gap value to be set
115: */
116: public void setXGap(int gap) {
117: xGap = gap;
118: }
119:
120: /**
121: * Returns the declared y gap value.
122: *
123: * @return the declared y gap value
124: */
125: public int getYGap() {
126: return yGap;
127: }
128:
129: /**
130: * Sets the given value as y gap.
131: *
132: * @param gap value to be set
133: */
134: public void setYGap(int gap) {
135: yGap = gap;
136: }
137:
138: /**
139: * Constructor with all existent parameters.
140: *
141: * @param xCellAlignment value to be used as x alignment
142: * @param yCellAlignment value to be used as y alignment
143: * @param xPos x position to be used
144: * @param yPos y position to be used
145: * @param xWeight weight at x direction
146: * @param yWeight weight at y direction
147: * @param xGap gap for x direction
148: * @param yGap gap for y direction
149: * @param xStretch stretch value for the x direction
150: * @param yStretch stretch value for the y direction
151: */
152: public IzPanelConstraints(int xCellAlignment, int yCellAlignment,
153: int xPos, int yPos, int xWeight, int yWeight, int xGap,
154: int yGap, double xStretch, double yStretch) {
155: this .xCellAlignment = xCellAlignment;
156: this .yCellAlignment = yCellAlignment;
157: this .xPos = xPos;
158: this .yPos = yPos;
159: this .xWeight = xWeight;
160: this .yWeight = yWeight;
161: setXGap(xGap);
162: setYGap(yGap);
163: setXStretch(xStretch);
164: setYStretch(yStretch);
165: }
166:
167: /**
168: * Default constructor
169: */
170: public IzPanelConstraints() {
171: super ();
172: }
173:
174: /*
175: * (non-Javadoc)
176: *
177: * @see java.lang.Object#clone()
178: */
179: public Object clone() {
180: try {
181: IzPanelConstraints c = (IzPanelConstraints) super .clone();
182: return c;
183: } catch (CloneNotSupportedException e) {
184: // this shouldn't happen, since we are Cloneable
185: throw new InternalError();
186: }
187: }
188:
189: /**
190: * Returns the alignment for the x direction.
191: *
192: * @return the alignment for the x direction
193: */
194: public int getXCellAlignment() {
195: return xCellAlignment;
196: }
197:
198: /**
199: * Sets the alignment for the x direction. Possible values are LEFT, RIGHT and CENTER.
200: *
201: * @param cellAlignment to be used
202: */
203: public void setXCellAlignment(int cellAlignment) {
204: xCellAlignment = cellAlignment;
205: }
206:
207: /**
208: * Returns the x position (column number).
209: *
210: * @return the x position (column number)
211: */
212: public int getXPos() {
213: return xPos;
214: }
215:
216: /**
217: * Sets the x position to be used.
218: *
219: * @param pos position to be used
220: */
221: public void setXPos(int pos) {
222: xPos = pos;
223: }
224:
225: /**
226: * Returns the weight for the x direction. The weight determines how many cells are occupied by
227: * the component.
228: *
229: * @return the weight for the x direction
230: */
231: public int getXWeight() {
232: return xWeight;
233: }
234:
235: /**
236: * Sets the weight value for the x direction.
237: *
238: * @param weight to be used for the x direction
239: */
240: public void setXWeight(int weight) {
241: xWeight = weight;
242: }
243:
244: /**
245: * Returns the alignment for the y direction.
246: *
247: * @return the alignment for the y direction
248: */
249: public int getYCellAlignment() {
250: return yCellAlignment;
251: }
252:
253: /**
254: * Sets the alignment for the y direction. Possible values are TOP, BOTTOM and CENTER.
255: *
256: * @param cellAlignment to be used
257: */
258: public void setYCellAlignment(int cellAlignment) {
259: yCellAlignment = cellAlignment;
260: }
261:
262: /**
263: * Returns the y position (row number).
264: *
265: * @return the y position (row number)
266: */
267: public int getYPos() {
268: return yPos;
269: }
270:
271: /**
272: * Sets the y position to be used.
273: *
274: * @param pos position to be used
275: */
276: public void setYPos(int pos) {
277: yPos = pos;
278: }
279:
280: /**
281: * Returns the weight for the y direction. The weight determines how many cells are occupied by
282: * the component.
283: *
284: * @return the weight for the y direction
285: */
286: public int getYWeight() {
287: return yWeight;
288: }
289:
290: /**
291: * Sets the weight value for the y direction.
292: *
293: * @param weight to be used for the y direction
294: */
295: public void setYWeight(int weight) {
296: yWeight = weight;
297: }
298:
299: /**
300: * Returns the bounds which should be used by the corresponding component. This will be used by
301: * the layout manager at a fast layouting.
302: *
303: * @return used bounds
304: */
305: public Rectangle getBounds() {
306: if (bounds != null)
307: return (Rectangle) (bounds.clone());
308: return (new Rectangle());
309: }
310:
311: /**
312: * Sets the bounds which should be used for the component.
313: *
314: * @param bounds bounds to be used
315: */
316: public void setBounds(Rectangle bounds) {
317: this .bounds = (Rectangle) bounds.clone();
318: }
319: }
|