KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > installer > LayoutHelper


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.installer;
23
24 import java.awt.GridBagConstraints JavaDoc;
25 import java.awt.GridBagLayout JavaDoc;
26 import java.awt.Insets JavaDoc;
27 import java.awt.LayoutManager2 JavaDoc;
28
29 import javax.swing.JComponent JavaDoc;
30
31 import com.izforge.izpack.gui.IzPanelConstraints;
32 import com.izforge.izpack.gui.IzPanelLayout;
33 import com.izforge.izpack.gui.LayoutConstants;
34 import com.izforge.izpack.installer.IzPanel.Filler;
35
36 /**
37  * This class manages the layout for IzPanels. The layout related methods in IzPanel delegates the
38  * work to this class. Use the layout helper directly because the delegating methods in IzPanel will
39  * be removed in the future.<br>
40  * This layout helper works with a GridBagLayout or a IzPanelLayout as layout manager. The layout
41  * manager has to be set at calling the method <code>startLayout</code>. This method has to be
42  * called before the first add of a component to the IzPanel.<br>
43  *
44  *
45  * @author Klaus Bartz
46  *
47  */

48 public class LayoutHelper implements LayoutConstants
49 {
50
51     JComponent JavaDoc parent;
52
53     /** Indicates whether grid bag layout was started or not */
54     protected boolean layoutStarted = false;
55
56     /** The default grid bag constraint. */
57     protected Object JavaDoc defaultConstraints;
58
59     /** Current x position of grid. */
60     protected int gridxCounter = -1;
61
62     /** Current y position of grid. */
63     protected int gridyCounter = -1;
64
65     /** internal layout */
66     protected LayoutManager2 JavaDoc izPanelLayout;
67
68     /**
69      * Layout anchor declared in the xml file with the guiprefs modifier "layoutAnchor"
70      */

71     protected static int ANCHOR = -1;
72
73     protected static int X_STRETCH_TYPE = -1;
74
75     protected static int Y_STRETCH_TYPE = -1;
76
77     protected static double FULL_LINE_STRETCH_DEFAULT = -1.0;
78
79     protected static double FULL_COLUMN_STRETCH_DEFAULT = -1.0;
80
81     protected static Double JavaDoc INITIAL_STRETCH_DEFAULT = new Double JavaDoc(1.0);
82
83     protected static Double JavaDoc DOUBLE_ZERO = new Double JavaDoc(0.0);
84
85     /**
86      * Look-up table for gap identifier to gap names for the x direction. The gap names can be used
87      * in the XML installation configuration file. Be aware that case sensitivity should be used.
88      */

89     public final static String JavaDoc[] X_GAP_NAME_LOOK_UP = { "INTERNAL_USED", "labelXGap", "textXGab",
90             "controlXGap", "paragraphXGap", "labelToTextXGap", "labelToControlXGap",
91             "textToLabelXGap", "controlToLabelXGap", "controlToTextXGap", "textToControlXGap",
92             "firstXGap", "INTERNAL_USED", "INTERNAL_USED", "filler1XGap", "filler2XGap",
93             "filler3XGap", "filler4XGap", "filler5XGap"};
94
95     /**
96      * Look-up table for gap identifier to gap names for the y direction. The gap names can be used
97      * in the XML installation configuration file. Be aware that case sensitivity should be used.
98      */

99     public final static String JavaDoc[] Y_GAP_NAME_LOOK_UP = { "INTERNAL_USED", "labelYGap", "textYGab",
100             "controlYGap", "paragraphYGap", "labelToTextYGap", "labelToControlYGap",
101             "textToLabelYGap", "controlToLabelYGap", "controlToTextYGap", "textToControlYGap",
102             "firstYGap", "INTERNAL_USED", "INTERNAL_USED", "filler1YGap", "filler2YGap",
103             "filler3YGap", "filler4YGap", "filler5YGap"};
104
105     /** Identifier of x gap for all default x gaps. */
106     public final static String JavaDoc ALL_X_GAP = "allXGap";
107
108     /** Identifier of x gap for all default y gaps. */
109     public final static String JavaDoc ALL_Y_GAP = "allYGap";
110
111     /**
112      * Only useable constructor. Creates a layout manager for special purpose.
113      *
114      * @param parent for which this layout manager will be used
115      */

116     public LayoutHelper(JComponent JavaDoc parent)
117     {
118         this();
119         this.parent = parent;
120         izPanelLayout = new GridBagLayout JavaDoc();
121         parent.setLayout(izPanelLayout);
122         gridyCounter++;
123     }
124
125     /**
126      * The default constructor is only useable by derived classes.
127      */

128     protected LayoutHelper()
129     {
130         super();
131     }
132
133     /**
134      * Returns whether the used layout is a GridBagLayout or not.
135      *
136      * @return whether the used layout is a GridBagLayout or not
137      */

138     private boolean isGridBag()
139     {
140         return (izPanelLayout instanceof GridBagLayout JavaDoc);
141     }
142
143     /**
144      * Returns whether the used layout is an IzPanelLayout or not.
145      *
146      * @return whether the used layout is an IzPanelLayout or not
147      */

148     private boolean isIzPanel()
149     {
150         return (izPanelLayout instanceof IzPanelLayout);
151     }
152
153     // ------------------- Common Layout stuff -------------------- START ---
154

155     /**
156      * Start layout determining. If it is needed, a dummy component will be created as first row.
157      * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
158      * "SOUTH" or "SOUTHWEST". The earlier used value "BOTTOM" and the declaration via the IzPack
159      * variable <code>IzPanel.LayoutType</code> are also supported.
160      *
161      * @param layout layout to be used by this layout helper
162      */

163     public void startLayout(LayoutManager2 JavaDoc layout)
164     {
165         if (layoutStarted) return;
166         izPanelLayout = layout;
167         if (isGridBag())
168         {
169             startGridBagLayout();
170             return;
171         }
172         // TODO: impl for IzPanelLayout
173
if (isIzPanel()) startIzPanelLayout();
174     }
175
176     /**
177      * Special start method for IzPanelLayout. Called from <code>startLayout</code>.
178      */

179     private void startIzPanelLayout()
180     {
181         IzPanelLayout.setAnchor(getAnchor());
182         IzPanelLayout.setXStretchType(getXStretchType());
183         IzPanelLayout.setYStretchType(getYStretchType());
184         IzPanelLayout.setFullLineStretch(getFullLineStretch());
185         IzPanelLayout.setFullColumnStretch(getFullColumnStretch());
186         getXGap(LABEL_GAP); // This call triggers resolving external setting if not already done.
187
getYGap(LABEL_GAP); // This call triggers resolving external setting if not already done.
188
parent.setLayout(izPanelLayout);
189         // parent.add(IzPanelLayout.createGap(TOP_GAP, VERTICAL));
190
}
191
192     /**
193      * Complete layout determining. If it is needed, a dummy component will be created as last row.
194      * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
195      * "NORTH" or "NORTHWEST". The earlier used value "TOP" and the declaration via the IzPack
196      * variable <code>IzPanel.LayoutType</code> are also supported.
197      */

198     public void completeLayout()
199     {
200         if (isGridBag())
201         {
202             completeGridBagLayout();
203             return;
204         }
205         // TODO: impl for IzPanelLayout
206
}
207
208     /**
209      * Returns the default constraints of this panel.
210      *
211      * @return the default constraints of this panel
212      */

213     public Object JavaDoc getDefaultConstraints()
214     {
215         startLayout(izPanelLayout);
216         return defaultConstraints;
217     }
218
219     /**
220      * Sets the default constraints of this panel to the given object.
221      *
222      * @param constraints which should be set as default for this object
223      */

224     public void setDefaultConstraints(Object JavaDoc constraints)
225     {
226
227         startLayout(izPanelLayout);
228         if ((isGridBag() && !(constraints instanceof GridBagConstraints JavaDoc))
229                 || (isIzPanel() && !(constraints instanceof IzPanelConstraints)))
230             throw new IllegalArgumentException JavaDoc(
231                     "Layout and constraints have to be from the same type.");
232         defaultConstraints = constraints;
233     }
234
235     /**
236      * Resets the grid counters which are used at getNextXConstraints and getNextYConstraints.
237      */

238     public void resetGridCounter()
239     {
240         gridxCounter = -1;
241         gridyCounter = -1;
242     }
243
244     /**
245      * Returns a newly created constraints with the given values and the values from the default
246      * constraints for the other parameters.
247      *
248      * @param gridx value to be used for the new constraint
249      * @param gridy value to be used for the new constraint
250      * @return newly created constraints with the given values and the values from the default
251      * constraints for the other parameters
252      */

253     public Object JavaDoc getNewConstraints(int gridx, int gridy)
254     {
255         if (isGridBag())
256         {
257             GridBagConstraints JavaDoc retval = (GridBagConstraints JavaDoc) ((GridBagConstraints JavaDoc) getDefaultConstraints())
258                     .clone();
259             retval.gridx = gridx;
260             retval.gridy = gridy;
261             return (retval);
262         }
263         if (isIzPanel())
264         {
265             IzPanelConstraints retval = (IzPanelConstraints) ((IzPanelConstraints) getDefaultConstraints())
266                     .clone();
267             retval.setXPos(gridx);
268             retval.setYPos(gridy);
269             return (retval);
270         }
271         return (null);
272     }
273
274     /**
275      * Returns a newly created constraints with the given values and the values from the
276      * defaultGridBagConstraints for the other parameters.
277      *
278      * @param gridx value to be used for the new constraint
279      * @param gridy value to be used for the new constraint
280      * @param gridwidth value to be used for the new constraint
281      * @param gridheight value to be used for the new constraint
282      * @return newly created constraints with the given values and the values from the default
283      * constraints for the other parameters
284      */

285     public Object JavaDoc getNewConstraints(int gridx, int gridy, int gridwidth, int gridheight)
286     {
287         Object JavaDoc retval = getNewConstraints(gridx, gridy);
288         if (isGridBag())
289         {
290             GridBagConstraints JavaDoc gbc = (GridBagConstraints JavaDoc) retval;
291             gbc.gridwidth = gridwidth;
292             gbc.gridheight = gridheight;
293         }
294         if (isIzPanel())
295         {
296             IzPanelConstraints gbc = (IzPanelConstraints) retval;
297             gbc.setXWeight(gridwidth);
298             gbc.setYWeight(gridheight);
299         }
300         return (retval);
301     }
302
303     /**
304      * Returns a newly created constraints for the next column of the current layout row.
305      *
306      * @return a newly created constraints for the next column of the current layout row
307      *
308      */

309     public Object JavaDoc getNextXConstraints()
310     {
311         gridxCounter++;
312         return (getNewConstraints(gridxCounter, gridyCounter));
313     }
314
315     /**
316      * Returns a newly created constraints with column 0 for the next row.
317      *
318      * @return a newly created constraints with column 0 for the next row
319      *
320      */

321     public Object JavaDoc getNextYConstraints()
322     {
323         gridyCounter++;
324         gridxCounter = 0;
325         return (getNewConstraints(0, gridyCounter));
326     }
327
328     /**
329      * Returns a newly created constraints with column 0 for the next row using the given
330      * parameters.
331      *
332      * @param gridwidth width for this constraint
333      * @param gridheight height for this constraint
334      * @return a newly created constraints with column 0 for the next row using the given parameters
335      */

336     public Object JavaDoc getNextYConstraints(int gridwidth, int gridheight)
337     {
338         gridyCounter++;
339         gridxCounter = 0;
340         return (getNewConstraints(0, gridyCounter, gridwidth, gridheight));
341     }
342
343     // ------------------- Common Layout stuff -------------------- END ---
344

345     // ------------------- GridBag Layout stuff -------------------- START ---
346
/**
347      * Start layout determining. If it is needed, a dummy component will be created as first row.
348      * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
349      * "SOUTH" or "SOUTHWEST". The earlier used value "BOTTOM" and the declaration via the IzPack
350      * variable <code>IzPanel.LayoutType</code> are also supported.
351      */

352     private void startGridBagLayout()
353     {
354         if (layoutStarted) return;
355         layoutStarted = true;
356         if (izPanelLayout == null || !(izPanelLayout instanceof GridBagLayout JavaDoc))
357             izPanelLayout = new GridBagLayout JavaDoc();
358         GridBagConstraints JavaDoc dgbc = new GridBagConstraints JavaDoc();
359         dgbc.insets = new Insets JavaDoc(0, 0, getYGap(LABEL_GAP), 0);
360         dgbc.anchor = GridBagConstraints.WEST;
361         defaultConstraints = dgbc;
362         parent.setLayout(izPanelLayout);
363         switch (getAnchor())
364         {
365         case SOUTH:
366         case SOUTH_WEST:
367             // Make a header to push the rest to the bottom.
368
Filler dummy = new Filler();
369             GridBagConstraints JavaDoc gbConstraint = (GridBagConstraints JavaDoc) getNextYConstraints();
370             gbConstraint.weighty = 1.0;
371             gbConstraint.fill = GridBagConstraints.BOTH;
372             gbConstraint.anchor = GridBagConstraints.WEST;
373             parent.add(dummy, gbConstraint);
374             break;
375         default:
376             break;
377         }
378         // TODO: impl for layout type CENTER, ...
379
}
380
381     /**
382      * Complete layout determining. If it is needed, a dummy component will be created as last row.
383      * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
384      * "NORTH" or "NORTHWEST". The earlier used value "TOP" and the declaration via the IzPack
385      * variable <code>IzPanel.LayoutType</code> are also supported.
386      */

387     private void completeGridBagLayout()
388     {
389         switch (getAnchor())
390         {
391         case NORTH:
392         case NORTH_WEST:
393             // Make a footer to push the rest to the top.
394
Filler dummy = new Filler();
395             GridBagConstraints JavaDoc gbConstraint = (GridBagConstraints JavaDoc) getNextYConstraints();
396             gbConstraint.weighty = 1.0;
397             gbConstraint.fill = GridBagConstraints.BOTH;
398             gbConstraint.anchor = GridBagConstraints.WEST;
399             parent.add(dummy, gbConstraint);
400             break;
401         default:
402             break;
403         }
404     }
405
406     /**
407      * Returns the anchor as value declared in GridBagConstraints. Possible are NORTH, NORTHWEST,
408      * SOUTH, SOUTHWEST and CENTER. The values can be configured in the xml description file with
409      * the variable "IzPanel.LayoutType". The old values "TOP" and "BOTTOM" from the xml file are
410      * mapped to NORTH and SOUTH.
411      *
412      * @return the anchor defined in the IzPanel.LayoutType variable.
413      */

414     public static int getAnchor()
415     {
416         if (ANCHOR >= 0) return (ANCHOR);
417         AutomatedInstallData idata = AutomatedInstallData.getInstance();
418         String JavaDoc todo;
419         if (idata instanceof InstallData
420                 && ((InstallData) idata).guiPrefs.modifier.containsKey("layoutAnchor"))
421             todo = (String JavaDoc) ((InstallData) idata).guiPrefs.modifier.get("layoutAnchor");
422         else
423             todo = idata.getVariable("IzPanel.LayoutType");
424         if (todo == null) // No command, no work.
425
ANCHOR = CENTER;
426         else if ("EAST".equalsIgnoreCase(todo))
427             ANCHOR = EAST;
428         else if ("WEST".equalsIgnoreCase(todo))
429             ANCHOR = WEST;
430         else if ("TOP".equalsIgnoreCase(todo) || "NORTH".equalsIgnoreCase(todo))
431             ANCHOR = NORTH;
432         else if ("BOTTOM".equalsIgnoreCase(todo) || "SOUTH".equalsIgnoreCase(todo))
433             ANCHOR = SOUTH;
434         else if ("SOUTHWEST".equalsIgnoreCase(todo) || "SOUTH_WEST".equalsIgnoreCase(todo))
435             ANCHOR = SOUTH_WEST;
436         else if ("SOUTHEAST".equalsIgnoreCase(todo) || "SOUTH_EAST".equalsIgnoreCase(todo))
437             ANCHOR = SOUTH_EAST;
438         else if ("NORTHWEST".equalsIgnoreCase(todo) || "NORTH_WEST".equalsIgnoreCase(todo))
439             ANCHOR = NORTH_WEST;
440         else if ("NORTHEAST".equalsIgnoreCase(todo) || "NORTH_EAST".equalsIgnoreCase(todo))
441             ANCHOR = NORTH_EAST;
442         else if ("CENTER".equalsIgnoreCase(todo)) ANCHOR = CENTER;
443         return (ANCHOR);
444     }
445
446     /**
447      * Returns the gap which should be used between the given gui objects for the x direction. The
448      * value will be configurable by guiprefs modifiers. Valid values are all entries in the static
449      * String array X_GAP_NAME_LOOK_UP of this class. There are constant ints for the indexes of
450      * this array.
451      *
452      * @param gapId index in array GAP_NAME_LOOK_UP for the needed gap
453      *
454      * @return the gap depend on the xml-configurable guiprefs modifier
455      */

456     public static int getXGap(int gapId)
457     {
458         gapId = IzPanelLayout.verifyGapId(gapId);
459         if (IzPanelLayout.getDefaultXGap(GAP_LOAD_MARKER) >= 0)
460             return (IzPanelLayout.getDefaultXGap(gapId));
461         AutomatedInstallData idata = AutomatedInstallData.getInstance();
462         if (!(idata instanceof InstallData)) return (IzPanelLayout.getDefaultXGap(gapId));
463         String JavaDoc var = null;
464         InstallData id = (InstallData) idata;
465         int commonDefault = -1;
466         if (id.guiPrefs.modifier.containsKey(ALL_X_GAP))
467         {
468             try
469             {
470                 commonDefault = Integer.parseInt((String JavaDoc) id.guiPrefs.modifier.get(ALL_X_GAP));
471             }
472             catch (NumberFormatException JavaDoc nfe)
473             {
474                 // Do nothing else use the default value.
475
// Need to set it again at this position??
476
}
477
478         }
479         for (int i = 0; i < X_GAP_NAME_LOOK_UP.length; ++i)
480         {
481             int currentDefault = 0;
482             if (commonDefault >= 0)
483             {
484                 currentDefault = commonDefault;
485             }
486             else
487             {
488                 var = (String JavaDoc) id.guiPrefs.modifier.get(X_GAP_NAME_LOOK_UP[i]);
489                 if (var != null)
490                 {
491                     try
492                     {
493                         currentDefault = Integer.parseInt(var);
494                     }
495                     catch (NumberFormatException JavaDoc nfe)
496                     {
497                         // Do nothing else use the default value.
498
// Need to set it again at this position??
499
}
500                 }
501             }
502             IzPanelLayout.setDefaultXGap(currentDefault, i);
503         }
504         IzPanelLayout.setDefaultXGap(0, GAP_LOAD_MARKER); // Mark external settings allready
505
// loaded.
506
return (IzPanelLayout.getDefaultXGap(gapId));
507     }
508
509     /**
510      * Returns the gap which should be used between the given gui objects for the y direction. The
511      * value will be configurable by guiprefs modifiers. Valid values are all entries in the static
512      * String array Y_GAP_NAME_LOOK_UP of this class. There are constant ints for the indexes of
513      * this array.
514      *
515      * @param gapId index in array GAP_NAME_LOOK_UP for the needed gap
516      *
517      * @return the gap depend on the xml-configurable guiprefs modifier
518      */

519     public static int getYGap(int gapId)
520     {
521         gapId = IzPanelLayout.verifyGapId(gapId);
522         if (IzPanelLayout.getDefaultYGap(GAP_LOAD_MARKER) >= 0)
523             return (IzPanelLayout.getDefaultYGap(gapId));
524         AutomatedInstallData idata = AutomatedInstallData.getInstance();
525         if (!(idata instanceof InstallData)) return (IzPanelLayout.getDefaultYGap(gapId));
526         String JavaDoc var = null;
527         InstallData id = (InstallData) idata;
528         int commonDefault = -1;
529         if (id.guiPrefs.modifier.containsKey(ALL_Y_GAP))
530         {
531             try
532             {
533                 commonDefault = Integer.parseInt((String JavaDoc) id.guiPrefs.modifier.get(ALL_Y_GAP));
534             }
535             catch (NumberFormatException JavaDoc nfe)
536             {
537                 // Do nothing else use the default value.
538
// Need to set it again at this position??
539
}
540
541         }
542         for (int i = 0; i < Y_GAP_NAME_LOOK_UP.length; ++i)
543         {
544             int currentDefault = 0;
545             if (commonDefault >= 0)
546             {
547                 currentDefault = commonDefault;
548             }
549             else
550             {
551                 var = (String JavaDoc) id.guiPrefs.modifier.get(Y_GAP_NAME_LOOK_UP[i]);
552                 if (var != null)
553                 {
554                     try
555                     {
556                         currentDefault = Integer.parseInt(var);
557                     }
558                     catch (NumberFormatException JavaDoc nfe)
559                     {
560                         // Do nothing else use the default value.
561
// Need to set it again at this position??
562
}
563                 }
564             }
565             IzPanelLayout.setDefaultYGap(currentDefault, i);
566         }
567         IzPanelLayout.setDefaultYGap(0, GAP_LOAD_MARKER); // Mark external settings allready
568
// loaded.
569
return (IzPanelLayout.getDefaultYGap(gapId));
570     }
571
572     /**
573      * Returns the used stretch type for the x direction. Possible are NO_STRETCH, RELATIVE_STRETCH
574      * and ABSOLUTE_STRETCH. The stretch type will be used at rows where one or more components has
575      * a stretch value greater than 0.0 in the constraints. If NO_STRETCH is used, no stretch will
576      * be performed. If ABSOLUTE_STRETCH is used, parts of the unused area are given to the
577      * components depending on the unmodified stretch value. At RELATIVE_STRETCH first the hole
578      * stretch for a row will be computed. Relative to this value the unused area will be splited.<br>
579      * The default type is ABSOLUTE_STRETCH. With the modifier "layoutXStretchType" of the "info"
580      * section of the installation configuration file this can be changed.
581      *
582      * @return used stretch type
583      */

584     public static int getXStretchType()
585     {
586         if (X_STRETCH_TYPE > -1) return (X_STRETCH_TYPE);
587         X_STRETCH_TYPE = ABSOLUTE_STRETCH;
588         String JavaDoc var = ((String JavaDoc) getModifierValue(null, "RELATIVE_STRETCH", null,
589                 "layoutXStretchType"));
590         if (var != null)
591         {
592             if ("RELATIVE_STRETCH".equalsIgnoreCase(var) || "RELATIVE".equalsIgnoreCase(var))
593                 X_STRETCH_TYPE = RELATIVE_STRETCH;
594             else if ("ABSOLUTE_STRETCH".equalsIgnoreCase(var) || "ABSOLUTE".equalsIgnoreCase(var))
595                 X_STRETCH_TYPE = ABSOLUTE_STRETCH;
596             else if ("NO_STRETCH".equalsIgnoreCase(var) || "NO".equalsIgnoreCase(var))
597                 X_STRETCH_TYPE = NO_STRETCH;
598         }
599         return (X_STRETCH_TYPE);
600     }
601
602     /**
603      * Returns the used stretch type for the y direction. Possible are NO_STRETCH, RELATIVE_STRETCH
604      * and ABSOLUTE_STRETCH. The stretch type will be used at rows where one or more components has
605      * a stretch value greater than 0.0 in the constraints. If NO_STRETCH is used, no stretch will
606      * be performed. If ABSOLUTE_STRETCH is used, parts of the unused area are given to the
607      * components depending on the unmodified stretch value. At RELATIVE_STRETCH first the hole
608      * stretch for a row will be computed. Relative to this value the unused area will be splited.<br>
609      * The default type is ABSOLUTE_STRETCH. With the modifier "layoutYStretchType" of the "info"
610      * section of the installation configuration file this can be changed.
611      *
612      * @return used stretch type
613      */

614     public static int getYStretchType()
615     {
616         if (Y_STRETCH_TYPE > -1) return (Y_STRETCH_TYPE);
617         Y_STRETCH_TYPE = ABSOLUTE_STRETCH;
618         String JavaDoc var = ((String JavaDoc) getModifierValue(null, "RELATIVE_STRETCH", null,
619                 "layoutYStretchType"));
620         if (var != null)
621         {
622             if ("RELATIVE_STRETCH".equalsIgnoreCase(var) || "RELATIVE".equalsIgnoreCase(var))
623                 Y_STRETCH_TYPE = RELATIVE_STRETCH;
624             else if ("ABSOLUTE_STRETCH".equalsIgnoreCase(var) || "ABSOLUTE".equalsIgnoreCase(var))
625                 Y_STRETCH_TYPE = ABSOLUTE_STRETCH;
626             else if ("NO_STRETCH".equalsIgnoreCase(var) || "NO".equalsIgnoreCase(var))
627                 Y_STRETCH_TYPE = NO_STRETCH;
628         }
629         return (Y_STRETCH_TYPE);
630     }
631
632     /**
633      * Returns the default value for stretching to a full line. With the modifier
634      * "layoutFullLineStretch" of the "info" section of the installation configuration file this can
635      * be changed. Valid are doubles for the value. This setting is possible to give panels a chance
636      * to center the controls in x direction also a control uses stretching.
637      *
638      * @return the default value for stretching to a full line
639      */

640
641     public static double getFullLineStretch()
642     {
643         FULL_LINE_STRETCH_DEFAULT = ((Double JavaDoc) getModifierValue(
644                 new Double JavaDoc(FULL_LINE_STRETCH_DEFAULT), INITIAL_STRETCH_DEFAULT, DOUBLE_ZERO,
645                 "layoutFullLineStretch")).doubleValue();
646         return (FULL_LINE_STRETCH_DEFAULT);
647     }
648
649     /**
650      * Returns the default value for stretching to a full column. With the modifier
651      * "layoutFullColumnStretch" of the "info" section of the installation configuration file this
652      * can be changed. Valid are doubles for the value. This setting is possible to give panels a
653      * chance to center the controls in y direction also a control uses stretching.
654      *
655      * @return the default value for stretching to a full column
656      */

657
658     public static double getFullColumnStretch()
659     {
660         FULL_COLUMN_STRETCH_DEFAULT = ((Double JavaDoc) getModifierValue(new Double JavaDoc(
661                 FULL_COLUMN_STRETCH_DEFAULT), INITIAL_STRETCH_DEFAULT, DOUBLE_ZERO,
662                 "layoutFullColumnStretch")).doubleValue();
663         return (FULL_COLUMN_STRETCH_DEFAULT);
664     }
665
666     private static Object JavaDoc getModifierValue(Object JavaDoc currentVal, Object JavaDoc defaultVal, Object JavaDoc readLimit,
667             String JavaDoc key)
668     {
669         if (defaultVal instanceof Integer JavaDoc)
670             if (((Integer JavaDoc) currentVal).intValue() >= ((Integer JavaDoc) readLimit).intValue())
671                 return (currentVal);
672         if (defaultVal instanceof Double JavaDoc)
673         {
674             if (((Double JavaDoc) currentVal).doubleValue() >= ((Double JavaDoc) readLimit).doubleValue())
675                 return (currentVal);
676         }
677         Object JavaDoc retval = defaultVal;
678         AutomatedInstallData idata = AutomatedInstallData.getInstance();
679         if (!(idata instanceof InstallData)) return (retval);
680         String JavaDoc var = null;
681         if (((InstallData) idata).guiPrefs.modifier.containsKey(key))
682         {
683             var = (String JavaDoc) ((InstallData) idata).guiPrefs.modifier.get(key);
684             if (var != null)
685             {
686                 try
687                 {
688                     if (defaultVal instanceof Integer JavaDoc) return (new Integer JavaDoc(Integer.parseInt(var)));
689                     if (defaultVal instanceof Double JavaDoc) { return (new Double JavaDoc(Double.parseDouble(var))); }
690                     return (var);
691                 }
692                 catch (NumberFormatException JavaDoc nfe)
693                 {
694                     // Do nothing else use the default value.
695
// Need to set it again at this position??
696
}
697             }
698         }
699         return (retval);
700     }
701
702     /**
703      * Returns the layout manager which current used by this layout helper. The layout manager
704      * implements LayoutManager2. It can be a GridBagLayout or a IzPanelLayout.
705      *
706      * @return current used layout manager
707      */

708     public LayoutManager2 JavaDoc getLayout()
709     {
710         return izPanelLayout;
711     }
712
713     /**
714      * Sets the given layout manager for this layout helper to be used.
715      *
716      * @param izPanelLayout layout manager to be used
717      */

718     public void setLayout(LayoutManager2 JavaDoc izPanelLayout)
719     {
720         this.izPanelLayout = izPanelLayout;
721     }
722
723 }
724
Popular Tags