001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.examples.features;
039:
040: import java.util.Date;
041:
042: import org.millstone.base.ui.*;
043: import org.millstone.base.data.Property;
044:
045: public class FeatureForm extends Feature implements
046: Property.ValueChangeListener {
047:
048: OrderedLayout demo = null;
049: Form test;
050: Layout formLayout = null;
051: Select addField = new Select("Add field");
052: Select resetLayout = new Select("Restart");
053:
054: protected Component getDemoComponent() {
055:
056: if (demo == null) {
057: demo = new OrderedLayout();
058: createDemo();
059: }
060:
061: return demo;
062: }
063:
064: private void createDemo() {
065:
066: demo.removeAllComponents();
067:
068: // Test form
069: Panel testPanel = new Panel("Form component");
070: if (formLayout == null)
071: test = new Form();
072: else
073: test = new Form(formLayout);
074: testPanel.addComponent(test);
075: demo.addComponent(testPanel);
076: OrderedLayout actions = new OrderedLayout(
077: OrderedLayout.ORIENTATION_HORIZONTAL);
078: demo.addComponent(actions);
079:
080: // form adder
081: addField.setImmediate(true);
082: addField.addItem("Add field");
083: addField.setNullSelectionItemId("Add field");
084: addField.addItem("Text field");
085: addField.addItem("Time");
086: addField.addItem("Option group");
087: addField.addItem("Calendar");
088: addField.addListener(this );
089: actions.addComponent(addField);
090:
091: // Layout reset
092: resetLayout.setImmediate(true);
093: resetLayout.addItem("Select layout example");
094: resetLayout.setNullSelectionItemId("Select layout example");
095: resetLayout.addItem("Vertical form (OrderedLayout form-style)");
096: resetLayout.addItem("Two columns (2x1 GridLayout)");
097: resetLayout.addItem("Flow (OrderedLayout flow-orientation)");
098: resetLayout.addListener(this );
099: actions.addComponent(resetLayout);
100:
101: // Properties
102: PropertyPanel p = new PropertyPanel(test);
103: p.addProperties("Form special properties", new Form());
104: demo.addComponent(p);
105: }
106:
107: public void valueChange(Property.ValueChangeEvent event) {
108:
109: if (event.getProperty() == resetLayout) {
110:
111: String value = (String) resetLayout.getValue();
112:
113: if (value != null) {
114: formLayout = null;
115:
116: if (value.equals("Two columns (2x1 GridLayout)"))
117: formLayout = new GridLayout(2, 1);
118: if (value.equals("Horizontal (OrderedLayout)"))
119: formLayout = new OrderedLayout(
120: OrderedLayout.ORIENTATION_HORIZONTAL);
121:
122: createDemo();
123: resetLayout.setValue(null);
124: }
125: }
126:
127: if (event.getProperty() == addField) {
128:
129: String value = (String) addField.getValue();
130:
131: if (value != null) {
132: if (value.equals("Text field"))
133: test.addField(new Object(), new TextField(
134: "Test field"));
135: if (value.equals("Time")) {
136: DateField d = new DateField("Time", new Date());
137: d
138: .setDescription("This is a DateField-component with text-style");
139: d.setResolution(DateField.RESOLUTION_MIN);
140: d.setStyle("text");
141: test.addField(new Object(), d);
142: }
143: if (value.equals("Calendar")) {
144: DateField c = new DateField("Calendar", new Date());
145: c
146: .setDescription("DateField-component with calendar-style and day-resolution");
147: c.setStyle("calendar");
148: c.setResolution(DateField.RESOLUTION_DAY);
149: test.addField(new Object(), c);
150: }
151: if (value.equals("Option group")) {
152: Select s = new Select("Options");
153: s
154: .setDescription("Select-component with optiongroup-style");
155: s.addItem("Linux");
156: s.addItem("Windows");
157: s.addItem("Solaris");
158: s.addItem("Symbian");
159: s.setStyle("optiongroup");
160:
161: test.addField(new Object(), s);
162: }
163:
164: addField.setValue(null);
165: }
166: }
167: }
168:
169: protected String getDescriptionXHTML() {
170: return "<p>Form is a flexible, yet simple container for fields. "
171: + " It provides support for any layouts and provides buffering interface for"
172: + " easy connection of commit- and discard buttons. All the form"
173: + " fields can be customized by adding validators, setting captions and icons, "
174: + " setting immediateness, etc. Also direct mechanism for replacing existing"
175: + " fields with selections is given.</p>"
176: + " <p>Form provides customizable editor for classes implementing"
177: + " Item-interface. Also the form itself"
178: + " implements this interface for easier connectivity to other items."
179: + " To use the form as editor for an item, just connect the item to"
180: + " form.After the item has been connected to the form,"
181: + " the automatically created fields can be customized and new fields can"
182: + " be added. If you need to connect a class that does not implement"
183: + " Item-interface, most properties of any"
184: + " class following bean pattern, can be accessed trough"
185: + " BeanItem.</p>"
186: + " <p>The best example of Form usage is the this feature browser itself; "
187: + " all the Property-panels in demos are composed of Form-components.</p>";
188: }
189:
190: protected String getTitle() {
191: return "Form";
192: }
193:
194: protected String getImage() {
195: return "form.jpg";
196: }
197:
198: }
|