KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > gui > IzPanelLayout


1 /*
2  * $Id:$
3  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
4  *
5  * http://www.izforge.com/izpack/
6  * http://developer.berlios.de/projects/izpack/
7  *
8  * Copyright 2006 Klaus Bartz
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */

22 package com.izforge.izpack.gui;
23
24 import java.awt.Component JavaDoc;
25 import java.awt.Container JavaDoc;
26 import java.awt.Dimension JavaDoc;
27 import java.awt.Insets JavaDoc;
28 import java.awt.LayoutManager JavaDoc;
29 import java.awt.LayoutManager2 JavaDoc;
30 import java.awt.Rectangle JavaDoc;
31 import java.util.ArrayList JavaDoc;
32
33 import javax.swing.JCheckBox JavaDoc;
34 import javax.swing.JComponent JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import javax.swing.JRadioButton JavaDoc;
37 import javax.swing.JScrollPane JavaDoc;
38 import javax.swing.JTextArea JavaDoc;
39 import javax.swing.text.JTextComponent JavaDoc;
40
41 import com.izforge.izpack.panels.PathSelectionPanel;
42 import com.izforge.izpack.util.MultiLineLabel;
43
44 /**
45  * This is a special layout manager for IzPanels.
46  *
47  * @author Klaus Bartz
48  *
49  */

50 public class IzPanelLayout implements LayoutManager JavaDoc, LayoutManager2 JavaDoc, LayoutConstants
51 {
52
53     /** holds all the components and layout constraints. */
54     private ArrayList JavaDoc components = new ArrayList JavaDoc();
55
56     /** Maximum rows to handle symbolic values like NEXT_ROW in constraints. */
57     private int currentYPos = 0;
58
59     /** Current column to handle symbolic values like NEXT_COLUMN in constraints. */
60     private int currentXPos = -1;
61
62     /** Dimension object with prefered size. Will be computed new if invalidateLayout will be called. */
63     private Dimension JavaDoc prefLayoutDim;
64
65     private Dimension JavaDoc oldParentSize;
66
67     private Insets JavaDoc oldParentInsets;
68
69     private int columnFillOutRule;
70
71     private double[] overallYStretch = { -1.0, 0.0};
72
73     protected static int[] DEFAULT_Y_GAPS = { -1, 0, 5, 5, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 15, 12,
74             9, 6, 3, 0};
75
76     protected static int[] DEFAULT_X_GAPS = { -1, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 15,
77             12, 9, 6, 3, 0};
78
79     protected static int[] DEFAULT_X_ALIGNMENT = { LEFT, LEFT, LEFT, LEFT};
80
81     protected static int[] DEFAULT_Y_ALIGNMENT = { CENTER, CENTER, CENTER, CENTER};
82
83     /** Array with some default constraints. */
84     private static IzPanelConstraints DEFAULT_CONSTRAINTS[] = {
85             // Default constraints for labels.
86
new IzPanelConstraints(DEFAULT_LABEL_ALIGNMENT, DEFAULT_LABEL_ALIGNMENT, NEXT_COLUMN,
87                     CURRENT_ROW, 1, 1, AUTOMATIC_GAP, AUTOMATIC_GAP, 0.0, 0.0),
88             // Default constraints for text fields.
89
new IzPanelConstraints(DEFAULT_TEXT_ALIGNMENT, DEFAULT_TEXT_ALIGNMENT, NEXT_COLUMN,
90                     CURRENT_ROW, 1, 1, AUTOMATIC_GAP, AUTOMATIC_GAP, 0.0, 0.0),
91             // Default constraints for other controls using two columns if possible.
92
new IzPanelConstraints(DEFAULT_CONTROL_ALIGNMENT, DEFAULT_CONTROL_ALIGNMENT,
93                     NEXT_COLUMN, CURRENT_ROW, 1, 1, AUTOMATIC_GAP, AUTOMATIC_GAP, 0.0, 0.0),
94             // Default constraints for full line controls.
95
new IzPanelConstraints(DEFAULT_LABEL_ALIGNMENT, DEFAULT_LABEL_ALIGNMENT, 0, NEXT_ROW,
96                     Byte.MAX_VALUE, Byte.MAX_VALUE, AUTOMATIC_GAP, AUTOMATIC_GAP,
97                     FULL_LINE_STRETCH, 0.0),
98             // Default constraints for constraints for controls/container which are variable in x
99
// and y dimension.
100
new IzPanelConstraints(DEFAULT_LABEL_ALIGNMENT, DEFAULT_LABEL_ALIGNMENT, 0, NEXT_ROW,
101                     Byte.MAX_VALUE, Byte.MAX_VALUE, AUTOMATIC_GAP, AUTOMATIC_GAP,
102                     FULL_LINE_STRETCH, FULL_COLUMN_STRETCH),
103             // Default constraints for x filler.
104
new IzPanelConstraints(DEFAULT_LABEL_ALIGNMENT, DEFAULT_LABEL_ALIGNMENT, NEXT_COLUMN,
105                     CURRENT_ROW, 1, 1, 0, 0, 0.0, 0.0),
106             // Default constraints for y filler.
107
new IzPanelConstraints(DEFAULT_LABEL_ALIGNMENT, DEFAULT_LABEL_ALIGNMENT, 0, NEXT_ROW,
108                     1, 1, 0, 0, 0.0, 0.0),
109             // Default constraints for other controls using the full line.
110
new IzPanelConstraints(DEFAULT_CONTROL_ALIGNMENT, DEFAULT_CONTROL_ALIGNMENT, 0,
111                     NEXT_ROW, Byte.MAX_VALUE, Byte.MAX_VALUE, AUTOMATIC_GAP, AUTOMATIC_GAP,
112                     FULL_LINE_STRETCH, 0.0),
113
114     };
115
116     /** Anchor to be used for the controls in all panels. */
117     private static int ANCHOR = CENTER;
118
119     private static int X_STRETCH_TYPE = RELATIVE_STRETCH;
120
121     private static int Y_STRETCH_TYPE = RELATIVE_STRETCH;
122
123     private static double FULL_LINE_STRETCH_DEFAULT = 1.0;
124
125     private static double FULL_COLUMN_STRETCH_DEFAULT = 1.0;
126
127     private static int DEFAULT_TEXTFIELD_LENGTH = 12;
128
129     private static final int[][] GAP_INTERMEDIAER_LOOKUP = {
130             { LABEL_GAP, LABEL_TO_TEXT_GAP, LABEL_TO_CONTROL_GAP, LABEL_GAP, LABEL_TO_CONTROL_GAP,
131                     LABEL_GAP, LABEL_GAP},
132             { TEXT_TO_LABEL_GAP, TEXT_GAP, TEXT_TO_CONTROL_GAP, TEXT_TO_LABEL_GAP,
133                     TEXT_TO_CONTROL_GAP, TEXT_GAP, TEXT_GAP},
134             { CONTROL_TO_LABEL_GAP, CONTROL_TO_TEXT_GAP, CONTROL_GAP, CONTROL_TO_LABEL_GAP,
135                     CONTROL_GAP, CONTROL_GAP, CONTROL_GAP},
136             { LABEL_GAP, LABEL_TO_TEXT_GAP, LABEL_TO_CONTROL_GAP, LABEL_GAP, LABEL_TO_CONTROL_GAP,
137                     LABEL_GAP, LABEL_GAP},
138             { CONTROL_TO_LABEL_GAP, CONTROL_TO_TEXT_GAP, CONTROL_GAP, CONTROL_TO_LABEL_GAP,
139                     CONTROL_GAP, CONTROL_GAP, CONTROL_GAP},
140             { NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP},
141             { NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP},
142             { NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP, NO_GAP}};
143
144     /**
145      * Default constructor
146      */

147     public IzPanelLayout()
148     {
149         this(NO_FILL_OUT_COLUMN);
150     }
151
152     /**
153      * Creates an layout manager which consider the given column fill out rule. Valid rules are
154      * NO_FILL_OUT_COLUMN, FILL_OUT_COLUMN_WIDTH, FILL_OUT_HEIGHT and FILL_OUT_COLUMN_SIZE
155      *
156      * @param colFillOutRule
157      */

158     public IzPanelLayout(int colFillOutRule)
159     {
160         super();
161         columnFillOutRule = colFillOutRule;
162     }
163
164     /**
165      * Returns the y gap for the given constraint dependant on the next y constraint.
166      *
167      * @param curConst constraint of the component for which the gap should be returnd
168      * @param nextYConst constraint of the component which is the next in y direction
169      * @return the y gap
170      */

171     private static int getYGap(IzPanelConstraints curConst, IzPanelConstraints nextYConst)
172     {
173
174         Class JavaDoc nextClass = (nextYConst != null) ? nextYConst.component.getClass()
175                 : FillerComponent.class;
176         int interId = GAP_INTERMEDIAER_LOOKUP[getIntermediarId(curConst.component.getClass(), null)][getIntermediarId(
177                 nextClass, null)];
178         if (interId < 0) interId = -interId;
179         return (DEFAULT_Y_GAPS[interId]);
180
181     }
182
183     /**
184      * Returns the x gap for the given constraint dependant on the next x constraint.
185      *
186      * @param curConst constraint of the component for which the gap should be returnd
187      * @param nextXConst constraint of the component which is the next in x direction
188      * @return the x gap
189      */

190     private static int getXGap(IzPanelConstraints curConst, IzPanelConstraints nextXConst)
191     {
192
193         Class JavaDoc nextClass = (nextXConst != null) ? nextXConst.component.getClass()
194                 : FillerComponent.class;
195         int interId = GAP_INTERMEDIAER_LOOKUP[getIntermediarId(curConst.component.getClass(), null)][getIntermediarId(
196                 nextClass, null)];
197         if (interId < 0) interId = -interId;
198         return (DEFAULT_X_GAPS[interId]);
199
200     }
201
202     /**
203      * Returns an index depending on the class type. Only for internal use.
204      *
205      * @param clazz class for which the index should be returned
206      * @param comp component for which the index should be returned
207      * @return an index depending on the class type
208      */

209     private static int getIntermediarId(Class JavaDoc clazz, Component JavaDoc comp)
210     {
211
212         if (comp != null)
213         {
214             if (MultiLineLabel.class.isAssignableFrom(clazz)
215                     || LabelFactory.FullLineLabel.class.isAssignableFrom(clazz))
216                 return (FULL_LINE_COMPONENT_CONSTRAINT);
217             if (PathSelectionPanel.class.isAssignableFrom(clazz)
218                     || JCheckBox JavaDoc.class.isAssignableFrom(clazz)
219                     || JRadioButton JavaDoc.class.isAssignableFrom(clazz))
220                 return (FULL_LINE_CONTROL_CONSTRAINT);
221             if (FillerComponent.class.isAssignableFrom(clazz)
222                     || javax.swing.Box.Filler.class.isAssignableFrom(clazz))
223             {
224                 Dimension JavaDoc size = comp.getPreferredSize();
225                 if (size.height >= Short.MAX_VALUE || size.height <= 0)
226                 {
227                     size.height = 0;
228                     comp.setSize(size);
229                     return (XDUMMY_CONSTRAINT);
230                 }
231                 else if (size.width >= Short.MAX_VALUE || size.width <= 0)
232                 {
233                     size.width = 0;
234                     comp.setSize(size);
235                     return (YDUMMY_CONSTRAINT);
236                 }
237             }
238         }
239         if (JScrollPane JavaDoc.class.isAssignableFrom(clazz)) return (XY_VARIABLE_CONSTRAINT);
240         if (JLabel JavaDoc.class.isAssignableFrom(clazz)) return (LABEL_CONSTRAINT);
241         if (JTextComponent JavaDoc.class.isAssignableFrom(clazz)) return (TEXT_CONSTRAINT);
242         if (FillerComponent.class.isAssignableFrom(clazz)) return (XDUMMY_CONSTRAINT);
243         if (javax.swing.Box.Filler.class.isAssignableFrom(clazz)) return (XDUMMY_CONSTRAINT);
244         return (CONTROL_CONSTRAINT); // Other controls.
245
}
246
247     /*
248      * (non-Javadoc)
249      *
250      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
251      */

252     public void addLayoutComponent(String JavaDoc name, Component JavaDoc comp)
253     {
254         // Has to be implemented, but not supported in this class.
255
}
256
257     /*
258      * (non-Javadoc)
259      *
260      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
261      */

262     public void removeLayoutComponent(Component JavaDoc comp)
263     {
264         // Has to be implemented, but not supported in this class.
265
}
266
267     /*
268      * (non-Javadoc)
269      *
270      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
271      */

272     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc parent)
273     {
274         return preferredLayoutSize(parent);
275     }
276
277     /*
278      * (non-Javadoc)
279      *
280      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
281      */

282     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc parent)
283     {
284         return (determineSize());
285     }
286
287     /**
288      * Method which determine minimum with and height of this layout. The size will be stored after
289      * cumputing in a class member. With a call to invalidateLayout this will be deleted and at the
290      * next call to this method the values are computed again.
291      *
292      * @return current minimum size
293      */

294     private Dimension JavaDoc determineSize()
295     {
296         if (prefLayoutDim == null)
297         {
298             int width = minimumAllColumnsWidth();
299             int height = minimumOverallHeight();
300             prefLayoutDim = new Dimension JavaDoc(width, height);
301         }
302         return (Dimension JavaDoc) (prefLayoutDim.clone());
303     }
304
305     /**
306      * Returns the number of rows that need to be laid out.
307      *
308      * @return the number of rows that need to be laid out
309      */

310     private int rows()
311     {
312         int maxRows = 0;
313         for (int i = 0; i < components.size(); ++i)
314         {
315             int curRows = ((ArrayList JavaDoc) components.get(i)).size();
316             if (curRows > maxRows) maxRows = curRows;
317
318         }
319         return (maxRows);
320     }
321
322     /**
323      * Returns the number of columns that need to be laid out.
324      *
325      * @return the number of columns that need to be laid out
326      */

327     private int columns()
328     {
329         return (components.size());
330     }
331
332     /**
333      * Minimum height of all rows.
334      *
335      * @return minimum height of all rows
336      */

337     private int minimumOverallHeight()
338     {
339         int height = 0;
340
341         for (int i = 0; i < rows(); i++)
342         {
343             height += rowHeight(i);
344         }
345
346         return (height);
347     }
348
349     /**
350      * Measures and returns the minimum height required to render the components in the indicated
351      * row.
352      *
353      * @param row the index of the row to measure
354      * @return minimum height of a row
355      */

356     private int rowHeight(int row)
357     {
358         int height = 0;
359         for (int i = 0; i < components.size(); ++i)
360         {
361             int curHeight = getCellSize(i, row, null).height;
362             if (curHeight > height) height = curHeight;
363         }
364         return (height);
365     }
366
367     /**
368      * Measures and returns the minimum height required to render the components in the indicated
369      * row.
370      *
371      * @param row the index of the row to measure
372      * @param maxOverallHeight
373      * @param minOverallHeight
374      * @return minimum height of a row
375      */

376     private int rowHeight(int row, int minOverallHeight, int maxOverallHeight)
377     {
378         // First determine minimum row height and whether there is a y stretch or not.
379
int height = 0;
380         double[] yStretch = getOverallYStretch();
381         if (yStretch[0] <= 0.0) return (rowHeight(row));
382         double maxStretch = 0.0;
383         double[] stretchParts = new double[components.size()];
384         for (int i = 0; i < components.size(); ++i)
385         {
386             IzPanelConstraints constraints = getConstraints(i, row);
387             double stretch = constraints.getYStretch();
388             stretchParts[i] = stretch;
389             if (stretch > maxStretch) maxStretch = stretch;
390             int curHeight = getCellSize(i, row, constraints).height;
391             if (curHeight > height) height = curHeight;
392         }
393         if (maxOverallHeight <= minOverallHeight) return (height);
394         // We have a y stretch and place. Let us disperse it.
395
int pixels = (int) (maxOverallHeight - yStretch[1] - minOverallHeight);
396         int stretchPart = (int) (pixels * maxStretch);
397         if (stretchPart > 0)
398         {
399             for (int i = 0; i < components.size(); ++i)
400             {
401                 if (stretchParts[i] < 0.00000001) continue;
402                 IzPanelConstraints constraints = getConstraints(i, row);
403                 Dimension JavaDoc size = constraints.component.getPreferredSize();
404                 if (size.height + stretchPart * stretchParts[i] < height)
405                     size.height = (int) (height + stretchPart * stretchParts[i]);
406                 else
407                     size.height = height + stretchPart;
408                 if (constraints.component instanceof JScrollPane JavaDoc)
409                 { // This is a hack for text areas which uses word wrap. At tests
410
// they have a preferred width of 100 pixel which breaks the layout.
411

412                     if (((JScrollPane JavaDoc) constraints.component).getViewport().getView() instanceof JTextArea JavaDoc)
413                     {
414                         if (((JTextArea JavaDoc) ((JScrollPane JavaDoc) constraints.component).getViewport()
415                                 .getView()).getLineWrap()) size.width = 1000;
416                     }
417                 }
418                 ((JComponent JavaDoc) constraints.component).setPreferredSize(size);
419
420             }
421             height += stretchPart;
422
423         }
424         return (height);
425     }
426
427     /**
428      * Returns the sum of the maximum y stretch of each row.
429      *
430      * @return the sum of the maximum y stretch of each row
431      */

432     private double[] getOverallYStretch()
433     {
434         if (overallYStretch[0] >= 0.0) return (overallYStretch); // Stretch already computed.
435
overallYStretch[0] = 0.0;
436         for (int row = 0; row < rows(); ++row)
437         {
438             double maxStretch = 0.0;
439             double maxGap = 0.0;
440             for (int i = 0; i < components.size(); ++i)
441             {
442                 IzPanelConstraints constraints = getConstraints(i, row);
443                 resolveDefaultSettings(i, row);
444                 if (constraints.getYStretch() == FULL_COLUMN_STRETCH)
445                     constraints.setYStretch(IzPanelLayout.getFullColumnStretch());
446                 double curStretch = constraints.getYStretch();
447                 if (curStretch > maxStretch) maxStretch = curStretch;
448                 double curYGap = constraints.getYGap();
449                 if (curYGap > maxGap) maxGap = curYGap;
450             }
451             overallYStretch[0] += maxStretch;
452             overallYStretch[1] += maxGap;
453         }
454         // Modify y stretch depending on the current Y-Stretch type.
455
if (overallYStretch[0] > 0.0)
456         {
457             switch (IzPanelLayout.getYStretchType())
458             {
459             case RELATIVE_STRETCH:
460                 break;
461             case ABSOLUTE_STRETCH:
462                 overallYStretch[0] = 1.0;
463                 break;
464             case NO_STRETCH:
465             default:
466                 overallYStretch[0] = 0.0;
467                 break;
468             }
469         }
470
471         return (overallYStretch);
472     }
473
474     /**
475      * Measures and returns the minimum size required to render the component in the indicated row
476      * and column. The constraints can be null.
477      *
478      * @param row the index of the row to measure
479      * @param column the column of the component
480      * @param constraints constraints of current component
481      * @return size of the given cell
482      */

483     private Dimension JavaDoc getCellSize(int column, int row, IzPanelConstraints constraints)
484     {
485         Dimension JavaDoc retval = new Dimension JavaDoc();
486         Component JavaDoc component;
487
488         try
489         {
490             if (constraints == null) constraints = getConstraints(column, row);
491             if (constraints != null)
492             {
493                 component = constraints.component;
494                 // Some components returns the needed size with getPreferredSize
495
// some with getMinimumSize. Therefore following code...
496
Dimension JavaDoc dim = component.getPreferredSize();
497                 Dimension JavaDoc dim2 = component.getMinimumSize();
498                 retval.height = (dim.height > dim2.height) ? dim.height : dim2.height;
499                 retval.width = (dim.width > dim2.width) ? dim.width : dim2.width;
500                 if (component instanceof JScrollPane JavaDoc)
501                 { // But at a JScrollPane we have to use the minimum size because
502
// preferred size is the size of the view.
503
retval.height = dim2.height;
504                     retval.width = dim2.width;
505                 }
506                 if (needsReEvaluation(component)) retval.width = 0;
507
508             }
509         }
510         catch (Throwable JavaDoc exception)
511         {
512             // ----------------------------------------------------
513
// we might get an exception if one of the array list is
514
// shorter, because we index out of bounds. If there
515
// is nothing there then the height is 0, nothing
516
// further to worry about!
517
// ----------------------------------------------------
518
}
519
520         return (retval);
521     }
522
523     /**
524      * Returns the minimum width of the column requested. This contains not the gaps.
525      *
526      * @param column the columns to measure
527      *
528      * @return the minimum width required to fit the components in this column
529      */

530     private int minimumColumnWidth(int column)
531     {
532         int maxWidth = 0;
533         Dimension JavaDoc[] cs = new Dimension JavaDoc[rows()];
534         for (int i = 0; i < rows(); ++i)
535         {
536             IzPanelConstraints constraints = getConstraints(column, i);
537             cs[i] = getCellSize(column, i, constraints);
538             if (constraints.getXWeight() <= 1) if (maxWidth < cs[i].width) maxWidth = cs[i].width;
539         }
540         if (maxWidth == 0)
541         {
542             for (int i = 0; i < rows(); ++i)
543             {
544                 if (maxWidth < cs[i].width) maxWidth = cs[i].width;
545             }
546         }
547         return (maxWidth);
548     }
549
550     /**
551      * Returns the minimum width needed by all columns.
552      *
553      * @return the minimum width needed by all columns
554      */

555     private int minimumAllColumnsWidth()
556     {
557         int width = 0;
558         for (int i = 0; i < this.components.size(); ++i)
559             width += minimumColumnWidth(i);
560         return (width);
561     }
562
563     /**
564      * Returns the constraint object of the component at the given place.
565      *
566      * @param col column of the component
567      * @param row row of the component
568      * @return the constraint object of the component at the given place
569      */

570     private IzPanelConstraints getConstraints(int col, int row)
571     {
572         if (col >= columns() || row >= rows()) return (null);
573         Object JavaDoc obj = components.get(col);
574         if (obj != null && obj instanceof ArrayList JavaDoc)
575         {
576             try
577             {
578                 obj = ((ArrayList JavaDoc) components.get(col)).get(row);
579             }
580             catch (Throwable JavaDoc t)
581             {
582                 obj = null;
583             }
584             if (obj != null) return ((IzPanelConstraints) obj);
585             // no constraints is possible if no valid component
586
// was added under this component.
587
// Put dummy components into the array.
588

589             ArrayList JavaDoc colA = (ArrayList JavaDoc) components.get(col);
590             for (int curRow = colA.size(); row >= curRow; ++curRow)
591             {
592
593                 IzPanelConstraints currentConst = IzPanelLayout
594                         .getDefaultConstraint(XDUMMY_CONSTRAINT);
595                 currentConst.setXPos(col);
596                 currentConst.setYPos(curRow);
597                 currentConst.component = new FillerComponent();
598                 try
599                 {
600                     ((ArrayList JavaDoc) components.get(col)).add(row, currentConst);
601                 }
602                 catch (Throwable JavaDoc t)
603                 {
604                     return (null);
605                 }
606             }
607             return (getConstraints(col, row));
608         }
609         return (null);
610     }
611
612     private int getAdaptedXPos(int xpos, int curWidth, Dimension JavaDoc curDim,
613             IzPanelConstraints currentConst)
614     {
615         int adaptedXPos = xpos;// currentConst.getXGap();
616
if ((columnFillOutRule & FILL_OUT_COLUMN_WIDTH) > 0) return (adaptedXPos);
617         switch (currentConst.getXCellAlignment())
618         {
619         case LEFT:
620             break;
621         case RIGHT:
622             adaptedXPos += curWidth - curDim.width;
623             break;
624         case CENTER:
625         default:
626             adaptedXPos += (curWidth - curDim.width) / 2;
627             break;
628
629         }
630         return (adaptedXPos);
631     }
632
633     private int getAdaptedYPos(int ypos, int curHeight, Dimension JavaDoc curDim,
634             IzPanelConstraints currentConst)
635     {
636         int adaptedYPos = ypos;// + currentConst.getYGap();
637
if ((columnFillOutRule & FILL_OUT_COLUMN_HEIGHT) > 0) return (adaptedYPos);
638         int height = curDim.height;
639         switch (currentConst.getYCellAlignment())
640         {
641         case TOP:
642             break;
643         case BOTTOM:
644             adaptedYPos += curHeight - height;
645             break;
646         case CENTER:
647         default:
648             adaptedYPos += (curHeight - height) / 2;
649             break;
650
651         }
652         if (adaptedYPos < ypos) return (ypos);
653         return (adaptedYPos);
654     }
655
656     private void resolveDefaultSettings(int col, int row)
657     {
658         IzPanelConstraints currentConst = getConstraints(col, row);
659         IzPanelConstraints nextYConst = getConstraints(col, row + 1);
660         IzPanelConstraints nextXConst = getConstraints(col + 1, row);
661         if (currentConst == null) return;
662         int gap = currentConst.getYGap();
663         if (gap == AUTOMATIC_GAP)
664         { // Automatic gap; determine now.
665
currentConst.setYGap(getYGap(currentConst, nextYConst));
666         }
667         else if (gap < 0)
668         {
669             currentConst.setYGap(DEFAULT_Y_GAPS[-gap]);
670         }
671         gap = currentConst.getXGap();
672         if (gap == AUTOMATIC_GAP)
673         { // Automatic gap; determine now.
674
currentConst.setXGap(getXGap(currentConst, nextXConst));
675         }
676         else if (gap < 0)
677         {
678             currentConst.setXGap(DEFAULT_X_GAPS[-gap]);
679         }
680
681         if (currentConst.getXCellAlignment() < 0)
682         {
683             currentConst.setXCellAlignment(DEFAULT_X_ALIGNMENT[-currentConst.getXCellAlignment()]);
684         }
685         if (currentConst.getYCellAlignment() < 0)
686         {
687             currentConst.setYCellAlignment(DEFAULT_Y_ALIGNMENT[-currentConst.getYCellAlignment()]);
688         }
689
690     }
691
692     /*
693      * (non-Javadoc)
694      *
695      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
696      */

697     public void layoutContainer(Container JavaDoc parent)
698     {
699         if (!needNewLayout(parent))
700         {
701             fastLayoutContainer(parent);
702             return;
703         }
704         prefLayoutDim = null;
705         preferredLayoutSize(parent);
706         Dimension JavaDoc realSizeDim = parent.getSize();
707         Insets JavaDoc insets = parent.getInsets();
708
709         int rowHeight = 0;
710         int onceAgain = 0;
711         int[] generellOffset = new int[] { 0, 0};
712         // int generellYOffset = 0;
713
// int generellXOffset = 0;
714
int maxWidth = 0;
715         int overallHeight = 0;
716         int anchorNeedsReEval = 0;
717         Rectangle JavaDoc curRect = new Rectangle JavaDoc();
718         int minOverallHeight = minimumOverallHeight();
719         int maxOverallHeight = realSizeDim.height - insets.top - insets.bottom;
720         while (anchorNeedsReEval < 2)
721         {
722             int ypos = insets.top;
723
724             int row = 0;
725             int minWidth = 0xffff;
726             int minHeight = 0xffff;
727             maxWidth = 0;
728             overallHeight = 0;
729             while (row < rows())
730             {
731                 int outerRowHeight = 0;
732                 int xpos = insets.left;
733                 // rowHeight = rowHeight(row, minOverallHeight, maxOverallHeight);
734
int col = 0;
735                 IzPanelConstraints[] colConstraints = new IzPanelConstraints[columns()];
736                 int usedWidth = 0;
737                 Dimension JavaDoc curDim;
738                 while (col < columns())
739                 {
740                     if (col == 0) rowHeight = rowHeight(row, minOverallHeight, maxOverallHeight);
741                     IzPanelConstraints currentConst = getConstraints(col, row);
742                     colConstraints[col] = currentConst;
743                     Component JavaDoc currentComp = currentConst.component;
744                     curDim = currentComp.getPreferredSize();
745                     int curWidth = minimumColumnWidth(col);
746                     col++;
747                     if (currentConst.getXWeight() > 1)
748                     {
749                         int weight = currentConst.getXWeight();
750                         while (weight > 1 && col < columns())
751                         {
752                             colConstraints[col] = getConstraints(col, row);
753                             if (!(colConstraints[col].component instanceof FillerComponent)) break;
754                             curWidth += minimumColumnWidth(col);
755                             col++;
756                             weight--;
757                         }
758                     }
759                     // width known
760
int adaptedXPos = getAdaptedXPos(xpos, curWidth, curDim, currentConst);
761                     int adaptedYPos = getAdaptedYPos(ypos, rowHeight, curDim, currentConst);
762                     // currentComp.setBounds(adaptedXPos + generellOffset[0], adaptedYPos
763
// + currentConst.getYGap() + generellOffset[1], curWidth, rowHeight);
764
// + generellOffset[1], curWidth, rowHeight);
765
int useWidth = curDim.width;
766                     int useHeight = curDim.height;
767                     if ((columnFillOutRule & FILL_OUT_COLUMN_WIDTH) > 0) useWidth = curWidth;
768                     if ((columnFillOutRule & FILL_OUT_COLUMN_HEIGHT) > 0) useHeight = rowHeight;
769                     if (curWidth < useWidth) useWidth = curWidth;
770                     // First setBounds using computed offsets and the size which exist previous.
771
currentComp.setBounds(adaptedXPos + generellOffset[0], adaptedYPos
772                             + generellOffset[1], useWidth, useHeight);
773                     currentComp.getBounds(curRect);
774                     if (!(currentComp instanceof FillerComponent))
775                     {
776                         if (curRect.x < minWidth) minWidth = curRect.x;
777                         if (curRect.y < minHeight) minHeight = curRect.y;
778                     }
779                     int curMax = (int) curRect.getMaxX();
780                     if (curMax - minWidth > maxWidth) maxWidth = curMax - minWidth;
781                     curMax = (int) curRect.getMaxY();
782                     currentConst.setBounds(curRect);
783                     if (curMax - minHeight > overallHeight) overallHeight = curMax - minHeight;
784                     // xpos += currentComp.getSize().width + currentConst.getXGap();
785
xpos += curWidth + currentConst.getXGap();
786                     usedWidth += curWidth;
787                     if (outerRowHeight < rowHeight + currentConst.getYGap())
788                         outerRowHeight = rowHeight + currentConst.getYGap();
789                 }
790                 // Now we have made a row, but may be there are place across or/and a component
791
// needs a reevaluation.
792
double rowStretch = 0.0;
793                 int i;
794                 // Determine hole stretch of this row.
795
for (i = 0; i < colConstraints.length; ++i)
796                 {
797                     if (colConstraints[i].getXStretch() == FULL_LINE_STRETCH)
798                         colConstraints[i].setXStretch(IzPanelLayout.getFullLineStretch());
799                     rowStretch += colConstraints[i].getXStretch();
800                 }
801                 // Modify rowStretch depending on the current X-Stretch type.
802
if (rowStretch > 0.0)
803                 {
804                     switch (IzPanelLayout.getXStretchType())
805                     {
806                     case RELATIVE_STRETCH:
807                         break;
808                     case ABSOLUTE_STRETCH:
809                         rowStretch = 1.0;
810                         break;
811                     case NO_STRETCH:
812                     default:
813                         rowStretch = 0.0;
814                         break;
815                     }
816                 }
817                 if (realSizeDim.width - insets.right != xpos && rowStretch > 0.0)
818                 { // Compute only if there is space to share and at least one control should be
819
// stretched.
820
int pixel = realSizeDim.width - insets.right - xpos; // How many pixel we
821
// can use for stretching.
822
int offset = 0;
823                     int oldOnceAgain = onceAgain;
824                     for (i = 0; i < colConstraints.length; ++i)
825                     {
826                         int curPixel = (int) ((colConstraints[i].getXStretch() / rowStretch) * pixel);
827
828                         Rectangle JavaDoc curBounds = colConstraints[i].component.getBounds();
829                         int newWidth = curPixel + curBounds.width;
830                         colConstraints[i].component.setBounds(curBounds.x + offset, curBounds.y,
831                                 newWidth, curBounds.height);
832                         colConstraints[i].component.getBounds(curRect);
833                         if (curRect.x > 0 && curRect.x < minWidth) minWidth = curRect.x;
834                         if (curRect.y > 0 && curRect.y < minHeight) minHeight = curRect.y;
835                         int curMax = (int) curRect.getMaxX();
836                         if (curMax - minWidth > maxWidth) maxWidth = curMax - minWidth;
837                         curMax = (int) curRect.getMaxY();
838                         colConstraints[i].setBounds(curRect);
839
840                         if (curMax - minHeight > overallHeight) overallHeight = curMax - minHeight;
841
842                         offset += curPixel;
843                         if (needsReEvaluation(colConstraints[i].component))
844                         {
845                             if (oldOnceAgain == onceAgain) onceAgain++;
846                         }
847                     }
848
849                 }
850                 // Seems so that height has changed. Reevaluate only one time else it is possible
851
// to go in a endless loop.
852

853                 if (onceAgain == 1) continue;
854                 onceAgain = 0;
855                 ypos += outerRowHeight;
856                 row++;
857             }
858             anchorNeedsReEval += resolveGenerellOffsets(generellOffset, realSizeDim, insets,
859                     maxWidth, overallHeight);
860
861         }
862     }
863
864     private void fastLayoutContainer(Container JavaDoc parent)
865     {
866         for (int row = 0; row < rows(); ++row)
867         {
868             for (int col = 0; col < columns(); ++col)
869             {
870                 IzPanelConstraints currentConst = getConstraints(col, row);
871                 if (currentConst != null)
872                     currentConst.component.setBounds(currentConst.getBounds());
873
874             }
875
876         }
877     }
878
879     private boolean needNewLayout(Container JavaDoc parent)
880     {
881         Dimension JavaDoc ops = oldParentSize;
882         Insets JavaDoc opi = oldParentInsets;
883         oldParentSize = parent.getSize();
884         oldParentInsets = parent.getInsets();
885         if (opi == null || opi == null) return (true);
886         if (ops.equals(parent.getSize()) && opi.equals(parent.getInsets())) return (false);
887         return (true);
888
889     }
890
891     private int resolveGenerellOffsets(int[] generellOffset, Dimension JavaDoc realSizeDim, Insets JavaDoc insets,
892             int maxWidth, int overallHeight)
893     {
894         int retval = 1;
895         switch (getAnchor())
896         {
897         case CENTER:
898             generellOffset[0] = (realSizeDim.width - insets.left - insets.right - maxWidth) / 2;
899             generellOffset[1] = (realSizeDim.height - insets.top - insets.bottom - overallHeight) / 2;
900             break;
901         case WEST:
902             generellOffset[0] = 0;
903             generellOffset[1] = (realSizeDim.height - insets.top - insets.bottom - overallHeight) / 2;
904             break;
905         case EAST:
906             generellOffset[0] = realSizeDim.width - insets.left - insets.right - maxWidth;
907             generellOffset[1] = (realSizeDim.height - insets.top - insets.bottom - overallHeight) / 2;
908             break;
909         case NORTH:
910             generellOffset[0] = (realSizeDim.width - insets.left - insets.right - maxWidth) / 2;
911             generellOffset[1] = 0;
912             break;
913         case SOUTH:
914             generellOffset[0] = (realSizeDim.width - insets.left - insets.right - maxWidth) / 2;
915             generellOffset[1] = realSizeDim.height - insets.top - insets.bottom - overallHeight;
916             break;
917         case NORTH_WEST:
918             generellOffset[0] = 0;
919             generellOffset[1] = 0;
920             retval = 2;
921             break;
922         case NORTH_EAST:
923             generellOffset[0] = realSizeDim.width - insets.left - insets.right - maxWidth;
924             generellOffset[1] = 0;
925             break;
926         case SOUTH_WEST:
927             generellOffset[0] = 0;
928             generellOffset[1] = realSizeDim.height - insets.top - insets.bottom - overallHeight;
929             break;
930         case SOUTH_EAST:
931             generellOffset[0] = realSizeDim.width - insets.left - insets.right - maxWidth;
932             generellOffset[1] = realSizeDim.height - insets.top - insets.bottom - overallHeight;
933             break;
934
935         }
936         if(generellOffset[0] < 0 ) generellOffset[0] = 0;
937         if(generellOffset[1] < 0 ) generellOffset[1] = 0;
938         return (retval);
939     }
940
941     /**
942      * Returns whether the type of component needs potential a reevaluation or not.
943      *
944      * @param comp component to check
945      * @return whether the type of component needs potential a reevaluation or not
946      */

947     private boolean needsReEvaluation(Component JavaDoc comp)
948     {
949         if ((comp instanceof com.izforge.izpack.util.MultiLineLabel)
950                 || (comp instanceof com.izforge.izpack.panels.PathSelectionPanel)) return (true);
951         return (false);
952     }
953
954     /*
955      * (non-Javadoc)
956      *
957      * @see java.awt.LayoutManager2#getLayoutAlignmentX(java.awt.Container)
958      */

959     public float getLayoutAlignmentX(Container JavaDoc target)
960     {
961         return 0;
962     }
963
964     /*
965      * (non-Javadoc)
966      *
967      * @see java.awt.LayoutManager2#getLayoutAlignmentY(java.awt.Container)
968      */

969     public float getLayoutAlignmentY(Container JavaDoc target)
970     {
971         return 0;
972     }
973
974     /*
975      * (non-Javadoc)
976      *
977      * @see java.awt.LayoutManager2#invalidateLayout(java.awt.Container)
978      */

979     public void invalidateLayout(Container JavaDoc target)
980     {
981         // prefLayoutDim = null;
982
}
983
984     /*
985      * (non-Javadoc)
986      *
987      * @see java.awt.LayoutManager2#maximumLayoutSize(java.awt.Container)
988      */

989     public Dimension JavaDoc maximumLayoutSize(Container JavaDoc target)
990     {
991         return (minimumLayoutSize(target));
992     }
993
994     /*
995      * (non-Javadoc)
996      *
997      * @see java.awt.LayoutManager2#addLayoutComponent(java.awt.Component, java.lang.Object)
998      */

999     public void addLayoutComponent(Component JavaDoc comp, Object JavaDoc constraints)
1000    {
1001        if (comp == null) throw new NullPointerException JavaDoc("component has to be not null");
1002        IzPanelConstraints cc;
1003        if (!(constraints instanceof IzPanelConstraints))
1004        {
1005            if ((comp instanceof FillerComponent)
1006                    && ((FillerComponent) comp).getConstraints() != null)
1007                cc = (IzPanelConstraints) ((FillerComponent) comp).getConstraints().clone();
1008            else
1009                cc = (IzPanelConstraints) IzPanelLayout.DEFAULT_CONSTRAINTS[getIntermediarId(comp
1010                        .getClass(), comp)].clone();
1011            if (NEXT_LINE.equals(constraints))
1012            {
1013                cc.setXPos(0);
1014                cc.setYPos(NEXT_ROW);
1015            }
1016        }
1017        else
1018            cc = (IzPanelConstraints) ((IzPanelConstraints) constraints).clone();
1019        cc.component = comp;
1020        int i;
1021        // Modify positions if constraint value is one of the symbolic ints.
1022
int yPos = cc.getYPos();
1023        if (yPos == LayoutConstants.NEXT_ROW) yPos = currentYPos + 1;
1024        if (yPos == LayoutConstants.CURRENT_ROW) yPos = currentYPos;
1025        cc.setYPos(yPos);
1026        int xPos = cc.getXPos();
1027        if (xPos == LayoutConstants.NEXT_COLUMN) xPos = currentXPos + 1;
1028        if (xPos == LayoutConstants.CURRENT_COLUMN) xPos = currentXPos;
1029        cc.setXPos(xPos);
1030        // Now we know real x and y position. If needed, expand array or
1031
// array of array.
1032
int perfCol = cc.getXWeight() < Byte.MAX_VALUE ? cc.getXWeight() : 1;
1033        if (components.size() < cc.getXPos() + perfCol)
1034        {
1035            for (i = components.size() - 1; i < cc.getXPos() + perfCol - 1; ++i)
1036                components.add(new ArrayList JavaDoc());
1037        }
1038        IzPanelConstraints curConst = cc;
1039        for (int j = 0; j < perfCol; ++j)
1040        {
1041            ArrayList JavaDoc xComp = (ArrayList JavaDoc) components.get(xPos);
1042            if (xComp.size() < yPos)
1043            {
1044                for (i = xComp.size() - 1; i < yPos - 1; ++i)
1045                {
1046                    IzPanelConstraints dc = getDefaultConstraint(XDUMMY_CONSTRAINT);
1047                    dc.component = new FillerComponent();
1048                    xComp.add(dc);
1049
1050                }
1051            }
1052
1053            xComp.add(yPos, curConst);
1054            if (j < perfCol - 1)
1055            {
1056                curConst = getDefaultConstraint(XDUMMY_CONSTRAINT);
1057                curConst.component = new FillerComponent();
1058                xPos++;
1059            }
1060        }
1061        int xcsize = ((ArrayList JavaDoc) components.get(xPos)).size() - 1;
1062        if (currentYPos < xcsize) currentYPos = xcsize;
1063        currentXPos = xPos;
1064
1065    }
1066
1067    /**
1068     * Creates an invisible, component with a defined width. This component will be placed in the
1069     * given cell of an IzPackLayout. If no constraint will be set (the default) a default
1070     * constraint with NEXT_COLUMN and CURRENT_ROW will be used. This component has the height 0.
1071     * The height of the row will be determined by other components in the same row.
1072     *
1073     * @param width the width of the invisible component
1074     * @return the component
1075     */

1076    public static Component JavaDoc createHorizontalStrut(int width)
1077    {
1078        return (new FillerComponent(new Dimension JavaDoc(width, 0)));
1079    }
1080
1081    /**
1082     * Creates an invisible, component with a defined height. This component will be placed in the
1083     * given cell of an IzPackLayout. If no constraint will be set (the default) a default
1084     * constraint with column 0 and NEXT_ROW will be used. If the next component also uses NEXT_ROW,
1085     * this strut goes over the hole width with the declared height. If more components are in the
1086     * row, the highest of them determines the height of the row. This component has the width 0.
1087     * The width of a row will be determined by other rows.
1088     *
1089     * @param height the height of the invisible component, in pixels >= 0
1090     * @return the component
1091     */

1092    public static Component JavaDoc createVerticalStrut(int height)
1093    {
1094        return (new FillerComponent(new Dimension JavaDoc(0, height)));
1095    }
1096
1097    /**
1098     * Returns a filler component which has self the size 0|0. Additional there is a constraints
1099     * which has the x position 0,y position NEXT_ROW, x and y weight 10, x-stretch 1.0 and the y
1100     * gap PARAGRAPH_GAP. Add the returned component to the IzPanel. Use NEXT_LINE (or NEXT_ROW in
1101     * the constraints) for the next added control, else the layout will be confused.
1102     *
1103     * @return a filler component with the height of the defined paragraph gap
1104     */

1105    public static Component JavaDoc createParagraphGap()
1106    {
1107        return (createGap(PARAGRAPH_GAP, VERTICAL));
1108    }
1109
1110    /**
1111     * Returns a filler component which has self the size 0|0. Additional there is a constraints
1112     * which has the x position 0,y position NEXT_ROW, x and y weight 10, x-stretch 1.0 and the y
1113     * gap FILLER&lt;given filler number&gt;_GAP. Add the returned component to the IzPanel. Use
1114     * NEXT_LINE (or NEXT_ROW in the constraints) for the next added control, else the layout will
1115     * be confused. Attention! fillerNumber determines not directly the size of filler else the
1116     * filler type. The size can be determined in the config file as modifier in the info section
1117     * defining from filler1YGap to filler5YGap.
1118     *
1119     * @param fillerNumber number of the filler which should be used
1120     * @return a filler component with the height of the defined paragraph gap
1121     */

1122    public static Component JavaDoc createVerticalFiller(int fillerNumber)
1123    {
1124        // The symbolic numbers all are negative. Therefore a higher filler needs
1125
// a less number.
1126
return (createGap(FILLER1_GAP + 1 - fillerNumber, VERTICAL));
1127    }
1128
1129    /**
1130     * Returns a filler component which has self the size 0|0. Additional there is a constraints
1131     * which has the position NEXT_COLUMN ,y position CURRENT_ROW, x and y weight 1, stretch 0.0 and
1132     * the gap FILLER&lt;given filler number&gt;_GAP. Add the returned component to the IzPanel.
1133     * Attention! fillerNumber determines not directly the size of filler else the filler type. The
1134     * size can be determined in the config file as modifier in the info section defining from
1135     * filler1XGap to filler5XGap.
1136     *
1137     * @param fillerNumber number of the filler which should be used
1138     * @return a filler component with the width of the defined paragraph gap
1139     */

1140    public static Component JavaDoc createHorizontalFiller(int fillerNumber)
1141    {
1142        // The symbolic numbers all are negative. Therefore a higher filler needs
1143
// a less number.
1144
return (createGap(FILLER1_GAP + 1 - fillerNumber, HORIZONTAL));
1145    }
1146
1147    /**
1148     * Returns a filler component which has self the size 0|0. Additional there is a constraints
1149     * which has the gap defined for the given gap type. If direction is HORIZONTAL, the x position
1150     * is NEXT_COLUMN ,y position CURRENT_ROW, x and y weight 1, stretch 0.0. If direction is
1151     * VERTICAL, the x position will by 0,y position NEXT_ROW, x and y weight 10, x-stretch 1.0. Add
1152     * the returned component to the IzPanel. The result will be that a gap will be inserted into
1153     * the layout at the current place with the width equal to the defined paragraph gap.
1154     *
1155     * @param gapType type of gap to be used
1156     * @param direction direction to be used
1157     *
1158     * @return a filler component with the width of the defined paragraph gap
1159     */

1160
1161    public static Component JavaDoc createGap(int gapType, int direction)
1162    {
1163        if (direction == HORIZONTAL)
1164            return (new FillerComponent(new Dimension JavaDoc(0, 0), new IzPanelConstraints(
1165                    DEFAULT_CONTROL_ALIGNMENT, DEFAULT_CONTROL_ALIGNMENT, NEXT_COLUMN, CURRENT_ROW,
1166                    1, 1, gapType, 0, 0.0, 0.0)));
1167        return (new FillerComponent(new Dimension JavaDoc(0, 0), new IzPanelConstraints(
1168                DEFAULT_CONTROL_ALIGNMENT, DEFAULT_CONTROL_ALIGNMENT, 0, NEXT_ROW, 10, 10, 0,
1169                gapType, 1.0, 0.0)));
1170    }
1171
1172    /**
1173     * Returns the constraint for the given type. Valid types are declared in the interface
1174     * <code>LayoutConstraints</code>. Possible are LABEL_CONSTRAINT, TEXT_CONSTRAINT and
1175     * CONTROL_CONSTRAINT.
1176     *
1177     * @param type for which the constraint should be returned
1178     * @return a copy of the default constraint for the given type
1179     */

1180    public static IzPanelConstraints getDefaultConstraint(int type)
1181    {
1182        return ((IzPanelConstraints) DEFAULT_CONSTRAINTS[type].clone());
1183    }
1184
1185    /**
1186     * Component which will be used as placeholder if not extern component will be set or as filler
1187     * for struts.
1188     *
1189     * @author Klaus Bartz
1190     *
1191     */

1192    public static class FillerComponent extends Component JavaDoc
1193    {
1194
1195        private Dimension JavaDoc size;
1196
1197        private IzPanelConstraints constraints;
1198
1199        /**
1200         * Default constructor creating an filler with the size 0|0.
1201         */

1202        public FillerComponent()
1203        {
1204            this(new Dimension JavaDoc(0, 0));
1205        }
1206
1207        /**
1208         * Constructor with giving the filler a size.
1209         *
1210         * @param size dimension to be used as size for this filler.
1211         */

1212        public FillerComponent(Dimension JavaDoc size)
1213        {
1214            this(size, null);
1215        }
1216
1217        /**
1218         * Constructor with giving the filler a size and set the constraints.
1219         *
1220         * @param size
1221         * @param constraints
1222         */

1223        public FillerComponent(Dimension JavaDoc size, IzPanelConstraints constraints)
1224        {
1225            super();
1226            this.size = size;
1227            this.constraints = constraints;
1228        }
1229
1230        public Dimension JavaDoc getMinimumSize()
1231        {
1232            return (Dimension JavaDoc) (size.clone());
1233        }
1234
1235        /*
1236         * (non-Javadoc)
1237         *
1238         * @see java.awt.Component#getPreferredSize()
1239         */

1240        public Dimension JavaDoc getPreferredSize()
1241        {
1242            return getMinimumSize();
1243        }
1244
1245        /*
1246         * (non-Javadoc)
1247         *
1248         * @see java.awt.Component#getMaximumSize()
1249         */

1250        public Dimension JavaDoc getMaximumSize()
1251        {
1252            return getMinimumSize();
1253        }
1254
1255        /*
1256         * (non-Javadoc)
1257         *
1258         * @see java.awt.Component#getBounds()
1259         */

1260        public Rectangle JavaDoc getBounds()
1261        {
1262            return (getBounds(new Rectangle JavaDoc()));
1263        }
1264
1265        /*
1266         * (non-Javadoc)
1267         *
1268         * @see java.awt.Component#getBounds(java.awt.Rectangle)
1269         */

1270        public Rectangle JavaDoc getBounds(Rectangle JavaDoc rect)
1271        {
1272            Rectangle JavaDoc rv = (rect != null) ? rect : new Rectangle JavaDoc();
1273            rv.setBounds(0, 0, size.width, size.height);
1274            return (rv);
1275        }
1276
1277        /**
1278         * Returns the constraints defined for this component. Often this will be null.
1279         *
1280         * @return the constraints defined for this component
1281         */

1282        public IzPanelConstraints getConstraints()
1283        {
1284            return constraints;
1285        }
1286
1287        /**
1288         * Sets the constraints which should be used by this component.
1289         *
1290         * @param constraints constraints to be used
1291         */

1292        public void setConstraints(IzPanelConstraints constraints)
1293        {
1294            this.constraints = constraints;
1295        }
1296    }
1297
1298    /**
1299     * Returns the anchor constant.
1300     *
1301     * @return the anchor constant
1302     */

1303    public static int getAnchor()
1304    {
1305        return ANCHOR;
1306    }
1307
1308    /**
1309     * Sets the anchor constant.
1310     *
1311     * @param anchor symbolic constant to be used
1312     */

1313    public static void setAnchor(int anchor)
1314    {
1315        ANCHOR = anchor;
1316    }
1317
1318    /**
1319     * Returns the current used type of stretching for the X-direction. Possible values are NO,
1320     * RELATIVE and ABSOLUTE.
1321     *
1322     * @return the current used type of stretching for the X-direction
1323     */

1324    public static int getXStretchType()
1325    {
1326        return X_STRETCH_TYPE;
1327    }
1328
1329    /**
1330     * Sets the type of stretching to be used for the X-Direction. Possible values are NO, RELATIVE
1331     * and ABSOLUTE.
1332     *
1333     * @param x_stretch constant to be used for stretch type
1334     */

1335    public static void setXStretchType(int x_stretch)
1336    {
1337        X_STRETCH_TYPE = x_stretch;
1338    }
1339
1340    /**
1341     * Returns the current used type of stretching for the Y-direction. Possible values are NO,
1342     * RELATIVE and ABSOLUTE.
1343     *
1344     * @return the current used type of stretching for the Y-direction
1345     */

1346    public static int getYStretchType()
1347    {
1348        return Y_STRETCH_TYPE;
1349    }
1350
1351    /**
1352     * Sets the type of stretching to be used for the Y-Direction. Possible values are NO, RELATIVE
1353     * and ABSOLUTE.
1354     *
1355     * @param y_stretch constant to be used for stretch type
1356     */

1357    public static void setYStretchType(int y_stretch)
1358    {
1359        Y_STRETCH_TYPE = y_stretch;
1360    }
1361
1362    /**
1363     * Returns the value which should be used stretching to a full line.
1364     *
1365     * @return the value which should be used stretching to a full line
1366     */

1367    public static double getFullLineStretch()
1368    {
1369        return FULL_LINE_STRETCH_DEFAULT;
1370    }
1371
1372    /**
1373     * Sets the value which should be used as default for stretching to a full line.
1374     *
1375     * @param fullLineStretch value to be used as full line stretching default
1376     */

1377    public static void setFullLineStretch(double fullLineStretch)
1378    {
1379        FULL_LINE_STRETCH_DEFAULT = fullLineStretch;
1380
1381    }
1382
1383    /**
1384     * Returns the value which should be used stretching to a full column.
1385     *
1386     * @return the value which should be used stretching to a full column
1387     */

1388    public static double getFullColumnStretch()
1389    {
1390        return FULL_COLUMN_STRETCH_DEFAULT;
1391    }
1392
1393    /**
1394     * Sets the value which should be used as default for stretching to a full column.
1395     *
1396     * @param fullStretch value to be used as full column stretching default
1397     */

1398    public static void setFullColumnStretch(double fullStretch)
1399    {
1400        FULL_COLUMN_STRETCH_DEFAULT = fullStretch;
1401
1402    }
1403
1404    /**
1405     * Verifies whether a gap id is valid or not. If the id is less than zero, the sign will be
1406     * removed. If the id is out of range, an IndexOutOfBoundsException will be thrown. The return
1407     * value is the verified unsigned id.
1408     *
1409     * @param gapId to be verified
1410     * @return the verified gap id
1411     */

1412    public static int verifyGapId(int gapId)
1413    {
1414        if (gapId < 0) gapId = -gapId;
1415        if (gapId >= DEFAULT_X_GAPS.length)
1416            throw new IndexOutOfBoundsException JavaDoc("gapId is not in the default gap container.");
1417        return (gapId);
1418    }
1419
1420    /**
1421     * Returns the default x gap for the given gap id.
1422     *
1423     * @param gapId for which the default x gap should be returned
1424     * @return the default x gap for the given gap id
1425     */

1426    public static int getDefaultXGap(int gapId)
1427    {
1428        gapId = verifyGapId(gapId);
1429        return DEFAULT_X_GAPS[gapId];
1430    }
1431
1432    /**
1433     * Set the gap for the given gap id for the x default gaps.
1434     *
1435     * @param gap to be used as default
1436     * @param gapId for which the default should be set
1437     */

1438    public static void setDefaultXGap(int gap, int gapId)
1439    {
1440        gapId = verifyGapId(gapId);
1441        DEFAULT_X_GAPS[gapId] = gap;
1442    }
1443
1444    /**
1445     * Returns the default y gap for the given gap id.
1446     *
1447     * @param gapId for which the default y gap should be returned
1448     * @return the default x gap for the given gap id
1449     */

1450    public static int getDefaultYGap(int gapId)
1451    {
1452        gapId = verifyGapId(gapId);
1453        return DEFAULT_Y_GAPS[gapId];
1454    }
1455
1456    /**
1457     * Set the gap for the given gap id for the y default gaps.
1458     *
1459     * @param gap to be used as default
1460     * @param gapId for which the default should be set
1461     */

1462    public static void setDefaultYGap(int gap, int gapId)
1463    {
1464        gapId = verifyGapId(gapId);
1465        DEFAULT_Y_GAPS[gapId] = gap;
1466    }
1467
1468    /**
1469     * Returns the default length used by textfields.
1470     *
1471     * @return the default length used by textfields
1472     */

1473    public static int getDefaultTextfieldLength()
1474    {
1475        return DEFAULT_TEXTFIELD_LENGTH;
1476    }
1477
1478    /**
1479     * Sets the value for the default length of textfields.
1480     *
1481     * @param val to be set as default length for textfields
1482     */

1483    public static void setDefaultTextfieldLength(int val)
1484    {
1485        DEFAULT_TEXTFIELD_LENGTH = val;
1486    }
1487
1488}
1489
Popular Tags