Permalink
Browse files

IZPACK-363 : Imroved layout possibilities on UserInputPanel

- Added factory to create layout constraints
- Replaced new TwoColumnContraints() calls with factory calls

git-svn-id: http://svn.codehaus.org/izpack@2956 7d736ef5-cfd4-0310-9c9a-b52d5c14b761
  • Loading branch information...
1 parent bfb8f38 commit 7a521ccd6ce0dd1a0664eaae12fd5bba5571d231 fbuehlmann committed Mar 1, 2010
@@ -115,13 +115,22 @@ specify the details for one panel instance. The tag name for this is
The ``<panel>`` tag uses the following attributes:
-**order** ``- required``
+**order** ``- required / optional``
This is the order number of the user input panel for which this specification
should be used. Counting starts at 0 and increments by 1 for each instance of
the user input panel. So if a spec should be used for the second occurrence
-of the user input panel use ``order="1"``.
+of the user input panel use ``order="1"``. This attribute is required if no
+``id="unique.identifier"`` is set.
+
+
+**id** ``- optional / required``
+
+
+This is the id of the user input panel for which this specification
+should be used. This id links to the panel specification in the install.xml file.
+If no ``order`` attribute is specified the ``id`` attribute is required.
**layout** ``- optional``
@@ -133,6 +142,23 @@ want to experiment with this attribute and see which you like best. The
default is ``left``.
+**border** ``- optional``
+
+
+Normally the user input is shown with a small border. To prevent this border set this
+attribute to ``false``. The default is ``true``.
+
+
+**column_width** ``- optional``
+
+
+This can be used to set the column width of the two column layout. This value is in percent
+of the whole size.
+If it is set to ``0``, which is the default, the with will be set automatically.
+It it is set to ``50`` the gap between the left and right column is in the middle
+of the panel. This makes it possible to make a centered layout.
+
+
Concepts and XML Elements Common to All Fields
------------------------------------------------------------
@@ -157,6 +183,45 @@ right.
Each UI element is specified with a ``<field>`` tag. The ``type`` attribute
is used to specify what kind of field you want to place. Obviously, the
``type`` attribute is not optional.
+In addition there are multiple layout attributes for the field tag.
+``label_position``
+Can be used to change the default position of the label which is usually ``west``
+It takes the arguments ``west``, ``westonly``, ``both``, ``eastonly``, ``east``
+``label_align``
+Can be used to change the default alignment of the label which is usually ``left``
+It takes the argument ``left``, ``center``, ``right``
+``label_indent``
+Controls the indent of the label which is usually ``false``.
+It takes the arguments ``true``, ``false``
+
+``control_position``
+Can be used to change the default position of the control which is usually ``east``
+It takes the arguments ``west``, ``westonly``, ``both``, ``eastonly``, ``east``
+``control_align``
+Can be used to change the default alignment of the control which is usually ``left``
+It takes the argument ``left``, ``center``, ``right``
+``control_indent``
+Controls the indent of the control which is usually ``false``.
+It takes the arguments ``true``, ``false``
+
+**Examples**
+
+In the following example, the the label and the control will be shown on it's own row.
+
+::
+
+ <field type="text" variable="value1">
+ <spec txt="The label" id="" size="20" set="default value" label_both="both" control_position="both" />
+ </field>
+
+In the following example, the label is right aligned to the control.
+
+::
+
+ <field type="text" variable="value1">
+ <spec txt="The label" id="" size="20" set="default value" label_align="right" />
+ </field>
+
Each field that takes user input must also specify the variable that should
@@ -1,22 +1,19 @@
/*
* IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
*
- * http://izpack.org/
- * http://izpack.codehaus.org/
+ * http://izpack.org/ http://izpack.codehaus.org/
*
* Copyright 2002 Elmar Grom
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
*/
package com.izforge.izpack.gui;
@@ -25,7 +22,7 @@
/**
* The constraints class to use with <code>TwoColumnLayout</code>.
- *
+ *
* @author Elmar Grom
* @version 0.0.1 / 11/15/02
* @see com.izforge.izpack.gui.TwoColumnLayout
@@ -55,18 +52,16 @@
/**
* Indicates where to place the associated component. <code>NORTH</code> will place the
- * component in the title margin. </code>WEST</code> will place the component in the left
- * column and <code>EAST</code> will place it in the right column. If <code>BOTH</code> is
- * used, the component will straddle both columns. <code>WESTONLY</code> and <code>EASTONLY</code>
- * will place the element accordingly but make sure that nothing is placed in the opposite
- * column.
+ * component in the title margin. </code>WEST</code> will place the component in the left column
+ * and <code>EAST</code> will place it in the right column. If <code>BOTH</code> is used, the
+ * component will straddle both columns. <code>WESTONLY</code> and <code>EASTONLY</code> will
+ * place the element accordingly but make sure that nothing is placed in the opposite column.
*/
public int position = WEST;
/**
* How to align the associated component, <code>LEFT</code>, <code>CENTER</code> or
- * <code>RIGHT</code>. Note that this setting only taks effect in the component is placed in
- * the title margin.
+ * <code>RIGHT</code>.
*/
public int align = LEFT;
@@ -88,9 +83,10 @@
/**
* Creates a copy of this two column constraint.
- *
+ *
* @return a copy of this <code>TwoColumnConstraints</code>
*/
+ @Override
public Object clone()
{
TwoColumnConstraints newObject = new TwoColumnConstraints();
@@ -0,0 +1,188 @@
+/**
+ * File Name: TwoColumnConstraintsFactory.java
+ *
+ * Version: $Id: $
+ */
+
+package com.izforge.izpack.gui;
+
+import com.izforge.izpack.adaptator.IXMLElement;
+
+public class TwoColumnConstraintsFactory
+{
+
+ private static final String ALIGNMENT = "align";
+
+ private static final String LABEL_ALIGNMENT = "label_align";
+
+ private static final String CONTROL_ALIGNMENT = "control_align";
+
+ private static final String LABEL_POSITION = "label_position";
+
+ private static final String CONTROL_POSITION = "control_position";
+
+ private static final String LABEL_INDENT = "label_indent";
+
+ private static final String CONTROL_INDENT = "control_indent";
+
+ private static final String LEFT = "left";
+
+ private static final String CENTER = "center";
+
+ private static final String RIGHT = "right";
+
+ private static final String WEST = "west";
+
+ private static final String WESTONLY = "westonly";
+
+ private static final String EAST = "east";
+
+ private static final String EASTONLY = "eastonly";
+
+ private static final String BOTH = "both";
+
+ private static final String TRUE = "true";
+
+ private static final String FALSE = "false";
+
+ public static TwoColumnConstraints createTextConstraint(IXMLElement field)
+ {
+ return createTextConstraint(field, TwoColumnConstraints.BOTH, false, false);
+ }
+
+ public static TwoColumnConstraints createLabelConstraint(IXMLElement field)
+ {
+ return createLabelConstraint(field, TwoColumnConstraints.WEST, false, false);
+ }
+
+ public static TwoColumnConstraints createControlConstraint(IXMLElement field)
+ {
+ return createControlConstraint(field, TwoColumnConstraints.EAST, false, false);
+ }
+
+ public static TwoColumnConstraints createTextConstraint(IXMLElement field, int position, boolean indent,
+ boolean stretch)
+ {
+ TwoColumnConstraints constraint = new TwoColumnConstraints();
+ constraint.position = position;
+ constraint.indent = indent;
+ constraint.stretch = stretch;
+ constraint.align = TwoColumnConstraints.LEFT;
+ overrideTextDefaults(constraint, field);
+ return constraint;
+ }
+
+ public static TwoColumnConstraints createControlConstraint(IXMLElement field, int position, boolean indent,
+ boolean stretch)
+ {
+ TwoColumnConstraints constraint = new TwoColumnConstraints();
+ constraint.position = position;
+ constraint.indent = indent;
+ constraint.stretch = stretch;
+ constraint.align = TwoColumnConstraints.LEFT;
+ overrideControlDefaults(constraint, field);
+ return constraint;
+ }
+
+ public static TwoColumnConstraints createLabelConstraint(IXMLElement field, int position, boolean indent,
+ boolean stretch)
+ {
+ TwoColumnConstraints constraint = new TwoColumnConstraints();
+ constraint.position = position;
+ constraint.indent = indent;
+ constraint.stretch = stretch;
+ constraint.align = TwoColumnConstraints.LEFT;
+ overrideLabelDefaults(constraint, field);
+ return constraint;
+ }
+
+ private static void overrideTextDefaults(TwoColumnConstraints constraint, IXMLElement field)
+ {
+ if (field != null)
+ {
+ overrideAlignment(constraint, field.getAttribute(ALIGNMENT));
+ overrideAlignment(constraint, field.getAttribute(LABEL_ALIGNMENT));
+ }
+ }
+
+ private static void overrideLabelDefaults(TwoColumnConstraints constraint, IXMLElement field)
+ {
+ if (field != null)
+ {
+ overrideAlignment(constraint, field.getAttribute(LABEL_ALIGNMENT));
+ overridePosition(constraint, field.getAttribute(LABEL_POSITION));
+ overrideIndent(constraint, field.getAttribute(LABEL_INDENT));
+ }
+ }
+
+ private static void overrideControlDefaults(TwoColumnConstraints constraint, IXMLElement field)
+ {
+ if (field != null)
+ {
+ overrideAlignment(constraint, field.getAttribute(CONTROL_ALIGNMENT));
+ overridePosition(constraint, field.getAttribute(CONTROL_POSITION));
+ overrideIndent(constraint, field.getAttribute(CONTROL_INDENT));
+ }
+ }
+
+ private static void overrideAlignment(TwoColumnConstraints constraint, String value)
+ {
+ if (value != null)
+ {
+ if (value.equalsIgnoreCase(LEFT))
+ {
+ constraint.align = TwoColumnConstraints.LEFT;
+ }
+ else if (value.equalsIgnoreCase(CENTER))
+ {
+ constraint.align = TwoColumnConstraints.CENTER;
+ }
+ else if (value.equalsIgnoreCase(RIGHT))
+ {
+ constraint.align = TwoColumnConstraints.RIGHT;
+ }
+ }
+ }
+
+ private static void overridePosition(TwoColumnConstraints constraint, String value)
+ {
+ if (value != null)
+ {
+ if (value.equalsIgnoreCase(WEST))
+ {
+ constraint.position = TwoColumnConstraints.WEST;
+ }
+ else if (value.equalsIgnoreCase(EAST))
+ {
+ constraint.position = TwoColumnConstraints.EAST;
+ }
+ else if (value.equalsIgnoreCase(BOTH))
+ {
+ constraint.position = TwoColumnConstraints.BOTH;
+ }
+ else if (value.equalsIgnoreCase(WESTONLY))
+ {
+ constraint.position = TwoColumnConstraints.WESTONLY;
+ }
+ else if (value.equalsIgnoreCase(EASTONLY))
+ {
+ constraint.position = TwoColumnConstraints.EASTONLY;
+ }
+ }
+ }
+
+ private static void overrideIndent(TwoColumnConstraints constraint, String value)
+ {
+ if (value != null)
+ {
+ if (value.equalsIgnoreCase(TRUE))
+ {
+ constraint.indent = true;
+ }
+ else if (value.equalsIgnoreCase(FALSE))
+ {
+ constraint.indent = false;
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7a521cc

Please sign in to comment.