001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2006 Klaus Bartz
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021: package com.izforge.izpack.installer;
022:
023: import java.awt.GridBagConstraints;
024: import java.awt.GridBagLayout;
025: import java.awt.Insets;
026: import java.awt.LayoutManager2;
027:
028: import javax.swing.JComponent;
029:
030: import com.izforge.izpack.gui.IzPanelConstraints;
031: import com.izforge.izpack.gui.IzPanelLayout;
032: import com.izforge.izpack.gui.LayoutConstants;
033: import com.izforge.izpack.installer.IzPanel.Filler;
034:
035: /**
036: * This class manages the layout for IzPanels. The layout related methods in IzPanel delegates the
037: * work to this class. Use the layout helper directly because the delegating methods in IzPanel will
038: * be removed in the future.<br>
039: * This layout helper works with a GridBagLayout or a IzPanelLayout as layout manager. The layout
040: * manager has to be set at calling the method <code>startLayout</code>. This method has to be
041: * called before the first add of a component to the IzPanel.<br>
042: *
043: *
044: * @author Klaus Bartz
045: *
046: */
047: public class LayoutHelper implements LayoutConstants {
048:
049: JComponent parent;
050:
051: /** Indicates whether grid bag layout was started or not */
052: protected boolean layoutStarted = false;
053:
054: /** The default grid bag constraint. */
055: protected Object defaultConstraints;
056:
057: /** Current x position of grid. */
058: protected int gridxCounter = -1;
059:
060: /** Current y position of grid. */
061: protected int gridyCounter = -1;
062:
063: /** internal layout */
064: protected LayoutManager2 izPanelLayout;
065:
066: /**
067: * Layout anchor declared in the xml file with the guiprefs modifier "layoutAnchor"
068: */
069: protected static int ANCHOR = -1;
070:
071: protected static int X_STRETCH_TYPE = -1;
072:
073: protected static int Y_STRETCH_TYPE = -1;
074:
075: protected static double FULL_LINE_STRETCH_DEFAULT = -1.0;
076:
077: protected static double FULL_COLUMN_STRETCH_DEFAULT = -1.0;
078:
079: protected static Double INITIAL_STRETCH_DEFAULT = 1.0;
080:
081: protected static Double DOUBLE_ZERO = 0.0;
082:
083: /**
084: * Look-up table for gap identifier to gap names for the x direction. The gap names can be used
085: * in the XML installation configuration file. Be aware that case sensitivity should be used.
086: */
087: public final static String[] X_GAP_NAME_LOOK_UP = {
088: "INTERNAL_USED", "labelXGap", "textXGab", "controlXGap",
089: "paragraphXGap", "labelToTextXGap", "labelToControlXGap",
090: "textToLabelXGap", "controlToLabelXGap",
091: "controlToTextXGap", "textToControlXGap", "firstXGap",
092: "INTERNAL_USED", "INTERNAL_USED", "filler1XGap",
093: "filler2XGap", "filler3XGap", "filler4XGap", "filler5XGap" };
094:
095: /**
096: * Look-up table for gap identifier to gap names for the y direction. The gap names can be used
097: * in the XML installation configuration file. Be aware that case sensitivity should be used.
098: */
099: public final static String[] Y_GAP_NAME_LOOK_UP = {
100: "INTERNAL_USED", "labelYGap", "textYGab", "controlYGap",
101: "paragraphYGap", "labelToTextYGap", "labelToControlYGap",
102: "textToLabelYGap", "controlToLabelYGap",
103: "controlToTextYGap", "textToControlYGap", "firstYGap",
104: "INTERNAL_USED", "INTERNAL_USED", "filler1YGap",
105: "filler2YGap", "filler3YGap", "filler4YGap", "filler5YGap" };
106:
107: /** Identifier of x gap for all default x gaps. */
108: public final static String ALL_X_GAP = "allXGap";
109:
110: /** Identifier of x gap for all default y gaps. */
111: public final static String ALL_Y_GAP = "allYGap";
112:
113: /**
114: * Only useable constructor. Creates a layout manager for special purpose.
115: *
116: * @param parent for which this layout manager will be used
117: */
118: public LayoutHelper(JComponent parent) {
119: this ();
120: this .parent = parent;
121: izPanelLayout = new GridBagLayout();
122: parent.setLayout(izPanelLayout);
123: gridyCounter++;
124: }
125:
126: /**
127: * The default constructor is only useable by derived classes.
128: */
129: protected LayoutHelper() {
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: return (izPanelLayout instanceof GridBagLayout);
140: }
141:
142: /**
143: * Returns whether the used layout is an IzPanelLayout or not.
144: *
145: * @return whether the used layout is an IzPanelLayout or not
146: */
147: private boolean isIzPanel() {
148: return (izPanelLayout instanceof IzPanelLayout);
149: }
150:
151: // ------------------- Common Layout stuff -------------------- START ---
152:
153: /**
154: * Start layout determining. If it is needed, a dummy component will be created as first row.
155: * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
156: * "SOUTH" or "SOUTHWEST". The earlier used value "BOTTOM" and the declaration via the IzPack
157: * variable <code>IzPanel.LayoutType</code> are also supported.
158: *
159: * @param layout layout to be used by this layout helper
160: */
161: public void startLayout(LayoutManager2 layout) {
162: if (layoutStarted)
163: return;
164: izPanelLayout = layout;
165: if (isGridBag()) {
166: startGridBagLayout();
167: return;
168: }
169: // TODO: impl for IzPanelLayout
170: if (isIzPanel())
171: startIzPanelLayout();
172: }
173:
174: /**
175: * Special start method for IzPanelLayout. Called from <code>startLayout</code>.
176: */
177: private void startIzPanelLayout() {
178: IzPanelLayout.setAnchor(getAnchor());
179: IzPanelLayout.setXStretchType(getXStretchType());
180: IzPanelLayout.setYStretchType(getYStretchType());
181: IzPanelLayout.setFullLineStretch(getFullLineStretch());
182: IzPanelLayout.setFullColumnStretch(getFullColumnStretch());
183: getXGap(LABEL_GAP); // This call triggers resolving external setting if not already done.
184: getYGap(LABEL_GAP); // This call triggers resolving external setting if not already done.
185: parent.setLayout(izPanelLayout);
186: // parent.add(IzPanelLayout.createGap(TOP_GAP, VERTICAL));
187: }
188:
189: /**
190: * Complete layout determining. If it is needed, a dummy component will be created as last row.
191: * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
192: * "NORTH" or "NORTHWEST". The earlier used value "TOP" and the declaration via the IzPack
193: * variable <code>IzPanel.LayoutType</code> are also supported.
194: */
195: public void completeLayout() {
196: if (isGridBag()) {
197: completeGridBagLayout();
198: }
199: // TODO: impl for IzPanelLayout
200: }
201:
202: /**
203: * Returns the default constraints of this panel.
204: *
205: * @return the default constraints of this panel
206: */
207: public Object getDefaultConstraints() {
208: startLayout(izPanelLayout);
209: return defaultConstraints;
210: }
211:
212: /**
213: * Sets the default constraints of this panel to the given object.
214: *
215: * @param constraints which should be set as default for this object
216: */
217: public void setDefaultConstraints(Object constraints) {
218:
219: startLayout(izPanelLayout);
220: if ((isGridBag() && !(constraints instanceof GridBagConstraints))
221: || (isIzPanel() && !(constraints instanceof IzPanelConstraints)))
222: throw new IllegalArgumentException(
223: "Layout and constraints have to be from the same type.");
224: defaultConstraints = constraints;
225: }
226:
227: /**
228: * Resets the grid counters which are used at getNextXConstraints and getNextYConstraints.
229: */
230: public void resetGridCounter() {
231: gridxCounter = -1;
232: gridyCounter = -1;
233: }
234:
235: /**
236: * Returns a newly created constraints with the given values and the values from the default
237: * constraints for the other parameters.
238: *
239: * @param gridx value to be used for the new constraint
240: * @param gridy value to be used for the new constraint
241: * @return newly created constraints with the given values and the values from the default
242: * constraints for the other parameters
243: */
244: public Object getNewConstraints(int gridx, int gridy) {
245: if (isGridBag()) {
246: GridBagConstraints retval = (GridBagConstraints) ((GridBagConstraints) getDefaultConstraints())
247: .clone();
248: retval.gridx = gridx;
249: retval.gridy = gridy;
250: return (retval);
251: }
252: if (isIzPanel()) {
253: IzPanelConstraints retval = (IzPanelConstraints) ((IzPanelConstraints) getDefaultConstraints())
254: .clone();
255: retval.setXPos(gridx);
256: retval.setYPos(gridy);
257: return (retval);
258: }
259: return (null);
260: }
261:
262: /**
263: * Returns a newly created constraints with the given values and the values from the
264: * defaultGridBagConstraints for the other parameters.
265: *
266: * @param gridx value to be used for the new constraint
267: * @param gridy value to be used for the new constraint
268: * @param gridwidth value to be used for the new constraint
269: * @param gridheight value to be used for the new constraint
270: * @return newly created constraints with the given values and the values from the default
271: * constraints for the other parameters
272: */
273: public Object getNewConstraints(int gridx, int gridy,
274: int gridwidth, int gridheight) {
275: Object retval = getNewConstraints(gridx, gridy);
276: if (isGridBag()) {
277: GridBagConstraints gbc = (GridBagConstraints) retval;
278: gbc.gridwidth = gridwidth;
279: gbc.gridheight = gridheight;
280: }
281: if (isIzPanel()) {
282: IzPanelConstraints gbc = (IzPanelConstraints) retval;
283: gbc.setXWeight(gridwidth);
284: gbc.setYWeight(gridheight);
285: }
286: return (retval);
287: }
288:
289: /**
290: * Returns a newly created constraints for the next column of the current layout row.
291: *
292: * @return a newly created constraints for the next column of the current layout row
293: *
294: */
295: public Object getNextXConstraints() {
296: gridxCounter++;
297: return (getNewConstraints(gridxCounter, gridyCounter));
298: }
299:
300: /**
301: * Returns a newly created constraints with column 0 for the next row.
302: *
303: * @return a newly created constraints with column 0 for the next row
304: *
305: */
306: public Object getNextYConstraints() {
307: gridyCounter++;
308: gridxCounter = 0;
309: return (getNewConstraints(0, gridyCounter));
310: }
311:
312: /**
313: * Returns a newly created constraints with column 0 for the next row using the given
314: * parameters.
315: *
316: * @param gridwidth width for this constraint
317: * @param gridheight height for this constraint
318: * @return a newly created constraints with column 0 for the next row using the given parameters
319: */
320: public Object getNextYConstraints(int gridwidth, int gridheight) {
321: gridyCounter++;
322: gridxCounter = 0;
323: return (getNewConstraints(0, gridyCounter, gridwidth,
324: gridheight));
325: }
326:
327: // ------------------- Common Layout stuff -------------------- END ---
328:
329: // ------------------- GridBag Layout stuff -------------------- START ---
330: /**
331: * Start layout determining. If it is needed, a dummy component will be created as first row.
332: * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
333: * "SOUTH" or "SOUTHWEST". The earlier used value "BOTTOM" and the declaration via the IzPack
334: * variable <code>IzPanel.LayoutType</code> are also supported.
335: */
336: private void startGridBagLayout() {
337: if (layoutStarted)
338: return;
339: layoutStarted = true;
340: if (izPanelLayout == null
341: || !(izPanelLayout instanceof GridBagLayout))
342: izPanelLayout = new GridBagLayout();
343: GridBagConstraints dgbc = new GridBagConstraints();
344: dgbc.insets = new Insets(0, 0, getYGap(LABEL_GAP), 0);
345: dgbc.anchor = GridBagConstraints.WEST;
346: defaultConstraints = dgbc;
347: parent.setLayout(izPanelLayout);
348: switch (getAnchor()) {
349: case SOUTH:
350: case SOUTH_WEST:
351: // Make a header to push the rest to the bottom.
352: Filler dummy = new Filler();
353: GridBagConstraints gbConstraint = (GridBagConstraints) getNextYConstraints();
354: gbConstraint.weighty = 1.0;
355: gbConstraint.fill = GridBagConstraints.BOTH;
356: gbConstraint.anchor = GridBagConstraints.WEST;
357: parent.add(dummy, gbConstraint);
358: break;
359: default:
360: break;
361: }
362: // TODO: impl for layout type CENTER, ...
363: }
364:
365: /**
366: * Complete layout determining. If it is needed, a dummy component will be created as last row.
367: * This will be done, if the IzPack guiprefs modifier with the key "layoutAnchor" has the value
368: * "NORTH" or "NORTHWEST". The earlier used value "TOP" and the declaration via the IzPack
369: * variable <code>IzPanel.LayoutType</code> are also supported.
370: */
371: private void completeGridBagLayout() {
372: switch (getAnchor()) {
373: case NORTH:
374: case NORTH_WEST:
375: // Make a footer to push the rest to the top.
376: Filler dummy = new Filler();
377: GridBagConstraints gbConstraint = (GridBagConstraints) getNextYConstraints();
378: gbConstraint.weighty = 1.0;
379: gbConstraint.fill = GridBagConstraints.BOTH;
380: gbConstraint.anchor = GridBagConstraints.WEST;
381: parent.add(dummy, gbConstraint);
382: break;
383: default:
384: break;
385: }
386: }
387:
388: /**
389: * Returns the anchor as value declared in GridBagConstraints. Possible are NORTH, NORTHWEST,
390: * SOUTH, SOUTHWEST and CENTER. The values can be configured in the xml description file with
391: * the variable "IzPanel.LayoutType". The old values "TOP" and "BOTTOM" from the xml file are
392: * mapped to NORTH and SOUTH.
393: *
394: * @return the anchor defined in the IzPanel.LayoutType variable.
395: */
396: public static int getAnchor() {
397: if (ANCHOR >= 0)
398: return (ANCHOR);
399: AutomatedInstallData idata = AutomatedInstallData.getInstance();
400: String todo;
401: if (idata instanceof InstallData
402: && ((InstallData) idata).guiPrefs.modifier
403: .containsKey("layoutAnchor"))
404: todo = ((InstallData) idata).guiPrefs.modifier
405: .get("layoutAnchor");
406: else
407: todo = idata.getVariable("IzPanel.LayoutType");
408: if (todo == null) // No command, no work.
409: ANCHOR = CENTER;
410: else if ("EAST".equalsIgnoreCase(todo))
411: ANCHOR = EAST;
412: else if ("WEST".equalsIgnoreCase(todo))
413: ANCHOR = WEST;
414: else if ("TOP".equalsIgnoreCase(todo)
415: || "NORTH".equalsIgnoreCase(todo))
416: ANCHOR = NORTH;
417: else if ("BOTTOM".equalsIgnoreCase(todo)
418: || "SOUTH".equalsIgnoreCase(todo))
419: ANCHOR = SOUTH;
420: else if ("SOUTHWEST".equalsIgnoreCase(todo)
421: || "SOUTH_WEST".equalsIgnoreCase(todo))
422: ANCHOR = SOUTH_WEST;
423: else if ("SOUTHEAST".equalsIgnoreCase(todo)
424: || "SOUTH_EAST".equalsIgnoreCase(todo))
425: ANCHOR = SOUTH_EAST;
426: else if ("NORTHWEST".equalsIgnoreCase(todo)
427: || "NORTH_WEST".equalsIgnoreCase(todo))
428: ANCHOR = NORTH_WEST;
429: else if ("NORTHEAST".equalsIgnoreCase(todo)
430: || "NORTH_EAST".equalsIgnoreCase(todo))
431: ANCHOR = NORTH_EAST;
432: else if ("CENTER".equalsIgnoreCase(todo))
433: ANCHOR = CENTER;
434: return (ANCHOR);
435: }
436:
437: /**
438: * Returns the gap which should be used between the given gui objects for the x direction. The
439: * value will be configurable by guiprefs modifiers. Valid values are all entries in the static
440: * String array X_GAP_NAME_LOOK_UP of this class. There are constant ints for the indexes of
441: * this array.
442: *
443: * @param gapId index in array GAP_NAME_LOOK_UP for the needed gap
444: *
445: * @return the gap depend on the xml-configurable guiprefs modifier
446: */
447: public static int getXGap(int gapId) {
448: gapId = IzPanelLayout.verifyGapId(gapId);
449: if (IzPanelLayout.getDefaultXGap(GAP_LOAD_MARKER) >= 0)
450: return (IzPanelLayout.getDefaultXGap(gapId));
451: AutomatedInstallData idata = AutomatedInstallData.getInstance();
452: if (!(idata instanceof InstallData))
453: return (IzPanelLayout.getDefaultXGap(gapId));
454: String var = null;
455: InstallData id = (InstallData) idata;
456: int commonDefault = -1;
457: if (id.guiPrefs.modifier.containsKey(ALL_X_GAP)) {
458: try {
459: commonDefault = Integer.parseInt(id.guiPrefs.modifier
460: .get(ALL_X_GAP));
461: } catch (NumberFormatException nfe) {
462: // Do nothing else use the default value.
463: // Need to set it again at this position??
464: }
465:
466: }
467: for (int i = 0; i < X_GAP_NAME_LOOK_UP.length; ++i) {
468: int currentDefault = 0;
469: if (commonDefault >= 0) {
470: currentDefault = commonDefault;
471: } else {
472: var = id.guiPrefs.modifier.get(X_GAP_NAME_LOOK_UP[i]);
473: if (var != null) {
474: try {
475: currentDefault = Integer.parseInt(var);
476: } catch (NumberFormatException nfe) {
477: // Do nothing else use the default value.
478: // Need to set it again at this position??
479: }
480: }
481: }
482: IzPanelLayout.setDefaultXGap(currentDefault, i);
483: }
484: IzPanelLayout.setDefaultXGap(0, GAP_LOAD_MARKER); // Mark external settings allready
485: // loaded.
486: return (IzPanelLayout.getDefaultXGap(gapId));
487: }
488:
489: /**
490: * Returns the gap which should be used between the given gui objects for the y direction. The
491: * value will be configurable by guiprefs modifiers. Valid values are all entries in the static
492: * String array Y_GAP_NAME_LOOK_UP of this class. There are constant ints for the indexes of
493: * this array.
494: *
495: * @param gapId index in array GAP_NAME_LOOK_UP for the needed gap
496: *
497: * @return the gap depend on the xml-configurable guiprefs modifier
498: */
499: public static int getYGap(int gapId) {
500: gapId = IzPanelLayout.verifyGapId(gapId);
501: if (IzPanelLayout.getDefaultYGap(GAP_LOAD_MARKER) >= 0)
502: return (IzPanelLayout.getDefaultYGap(gapId));
503: AutomatedInstallData idata = AutomatedInstallData.getInstance();
504: if (!(idata instanceof InstallData))
505: return (IzPanelLayout.getDefaultYGap(gapId));
506: String var = null;
507: InstallData id = (InstallData) idata;
508: int commonDefault = -1;
509: if (id.guiPrefs.modifier.containsKey(ALL_Y_GAP)) {
510: try {
511: commonDefault = Integer.parseInt(id.guiPrefs.modifier
512: .get(ALL_Y_GAP));
513: } catch (NumberFormatException nfe) {
514: // Do nothing else use the default value.
515: // Need to set it again at this position??
516: }
517:
518: }
519: for (int i = 0; i < Y_GAP_NAME_LOOK_UP.length; ++i) {
520: int currentDefault = 0;
521: if (commonDefault >= 0) {
522: currentDefault = commonDefault;
523: } else {
524: var = id.guiPrefs.modifier.get(Y_GAP_NAME_LOOK_UP[i]);
525: if (var != null) {
526: try {
527: currentDefault = Integer.parseInt(var);
528: } catch (NumberFormatException nfe) {
529: // Do nothing else use the default value.
530: // Need to set it again at this position??
531: }
532: }
533: }
534: IzPanelLayout.setDefaultYGap(currentDefault, i);
535: }
536: IzPanelLayout.setDefaultYGap(0, GAP_LOAD_MARKER); // Mark external settings allready
537: // loaded.
538: return (IzPanelLayout.getDefaultYGap(gapId));
539: }
540:
541: /**
542: * Returns the used stretch type for the x direction. Possible are NO_STRETCH, RELATIVE_STRETCH
543: * and ABSOLUTE_STRETCH. The stretch type will be used at rows where one or more components has
544: * a stretch value greater than 0.0 in the constraints. If NO_STRETCH is used, no stretch will
545: * be performed. If ABSOLUTE_STRETCH is used, parts of the unused area are given to the
546: * components depending on the unmodified stretch value. At RELATIVE_STRETCH first the hole
547: * stretch for a row will be computed. Relative to this value the unused area will be splited.<br>
548: * The default type is ABSOLUTE_STRETCH. With the modifier "layoutXStretchType" of the "info"
549: * section of the installation configuration file this can be changed.
550: *
551: * @return used stretch type
552: */
553: public static int getXStretchType() {
554: if (X_STRETCH_TYPE > -1)
555: return (X_STRETCH_TYPE);
556: X_STRETCH_TYPE = ABSOLUTE_STRETCH;
557: String var = ((String) getModifierValue(null,
558: "RELATIVE_STRETCH", null, "layoutXStretchType"));
559: if (var != null) {
560: if ("RELATIVE_STRETCH".equalsIgnoreCase(var)
561: || "RELATIVE".equalsIgnoreCase(var))
562: X_STRETCH_TYPE = RELATIVE_STRETCH;
563: else if ("ABSOLUTE_STRETCH".equalsIgnoreCase(var)
564: || "ABSOLUTE".equalsIgnoreCase(var))
565: X_STRETCH_TYPE = ABSOLUTE_STRETCH;
566: else if ("NO_STRETCH".equalsIgnoreCase(var)
567: || "NO".equalsIgnoreCase(var))
568: X_STRETCH_TYPE = NO_STRETCH;
569: }
570: return (X_STRETCH_TYPE);
571: }
572:
573: /**
574: * Returns the used stretch type for the y direction. Possible are NO_STRETCH, RELATIVE_STRETCH
575: * and ABSOLUTE_STRETCH. The stretch type will be used at rows where one or more components has
576: * a stretch value greater than 0.0 in the constraints. If NO_STRETCH is used, no stretch will
577: * be performed. If ABSOLUTE_STRETCH is used, parts of the unused area are given to the
578: * components depending on the unmodified stretch value. At RELATIVE_STRETCH first the hole
579: * stretch for a row will be computed. Relative to this value the unused area will be splited.<br>
580: * The default type is ABSOLUTE_STRETCH. With the modifier "layoutYStretchType" of the "info"
581: * section of the installation configuration file this can be changed.
582: *
583: * @return used stretch type
584: */
585: public static int getYStretchType() {
586: if (Y_STRETCH_TYPE > -1)
587: return (Y_STRETCH_TYPE);
588: Y_STRETCH_TYPE = ABSOLUTE_STRETCH;
589: String var = ((String) getModifierValue(null,
590: "RELATIVE_STRETCH", null, "layoutYStretchType"));
591: if (var != null) {
592: if ("RELATIVE_STRETCH".equalsIgnoreCase(var)
593: || "RELATIVE".equalsIgnoreCase(var))
594: Y_STRETCH_TYPE = RELATIVE_STRETCH;
595: else if ("ABSOLUTE_STRETCH".equalsIgnoreCase(var)
596: || "ABSOLUTE".equalsIgnoreCase(var))
597: Y_STRETCH_TYPE = ABSOLUTE_STRETCH;
598: else if ("NO_STRETCH".equalsIgnoreCase(var)
599: || "NO".equalsIgnoreCase(var))
600: Y_STRETCH_TYPE = NO_STRETCH;
601: }
602: return (Y_STRETCH_TYPE);
603: }
604:
605: /**
606: * Returns the default value for stretching to a full line. With the modifier
607: * "layoutFullLineStretch" of the "info" section of the installation configuration file this can
608: * be changed. Valid are doubles for the value. This setting is possible to give panels a chance
609: * to center the controls in x direction also a control uses stretching.
610: *
611: * @return the default value for stretching to a full line
612: */
613:
614: public static double getFullLineStretch() {
615: FULL_LINE_STRETCH_DEFAULT = (Double) getModifierValue(
616: FULL_LINE_STRETCH_DEFAULT, INITIAL_STRETCH_DEFAULT,
617: DOUBLE_ZERO, "layoutFullLineStretch");
618: return (FULL_LINE_STRETCH_DEFAULT);
619: }
620:
621: /**
622: * Returns the default value for stretching to a full column. With the modifier
623: * "layoutFullColumnStretch" of the "info" section of the installation configuration file this
624: * can be changed. Valid are doubles for the value. This setting is possible to give panels a
625: * chance to center the controls in y direction also a control uses stretching.
626: *
627: * @return the default value for stretching to a full column
628: */
629:
630: public static double getFullColumnStretch() {
631: FULL_COLUMN_STRETCH_DEFAULT = (Double) getModifierValue(
632: FULL_COLUMN_STRETCH_DEFAULT, INITIAL_STRETCH_DEFAULT,
633: DOUBLE_ZERO, "layoutFullColumnStretch");
634: return (FULL_COLUMN_STRETCH_DEFAULT);
635: }
636:
637: private static Object getModifierValue(Object currentVal,
638: Object defaultVal, Object readLimit, String key) {
639: if (defaultVal instanceof Integer)
640: if ((Integer) currentVal >= (Integer) readLimit)
641: return (currentVal);
642: if (defaultVal instanceof Double) {
643: if ((Double) currentVal >= (Double) readLimit)
644: return (currentVal);
645: }
646: Object retval = defaultVal;
647: AutomatedInstallData idata = AutomatedInstallData.getInstance();
648: if (!(idata instanceof InstallData))
649: return (retval);
650: String var = null;
651: if (((InstallData) idata).guiPrefs.modifier.containsKey(key)) {
652: var = ((InstallData) idata).guiPrefs.modifier.get(key);
653: if (var != null) {
654: try {
655: if (defaultVal instanceof Integer)
656: return (Integer.parseInt(var));
657: if (defaultVal instanceof Double) {
658: return (Double.parseDouble(var));
659: }
660: return (var);
661: } catch (NumberFormatException nfe) {
662: // Do nothing else use the default value.
663: // Need to set it again at this position??
664: }
665: }
666: }
667: return (retval);
668: }
669:
670: /**
671: * Returns the layout manager which current used by this layout helper. The layout manager
672: * implements LayoutManager2. It can be a GridBagLayout or a IzPanelLayout.
673: *
674: * @return current used layout manager
675: */
676: public LayoutManager2 getLayout() {
677: return izPanelLayout;
678: }
679:
680: /**
681: * Sets the given layout manager for this layout helper to be used.
682: *
683: * @param izPanelLayout layout manager to be used
684: */
685: public void setLayout(LayoutManager2 izPanelLayout) {
686: this.izPanelLayout = izPanelLayout;
687: }
688:
689: }
|