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.Iterator;
041: import java.util.StringTokenizer;
042:
043: import org.millstone.base.terminal.ClassResource;
044: import org.millstone.base.ui.*;
045: import org.millstone.base.data.*;
046:
047: public class FeatureBrowser extends CustomComponent implements
048: Property.ValueChangeListener {
049:
050: private Tree features;
051: private Feature currentFeature = null;
052: private GridLayout layout;
053: private Component welcome;
054: private boolean initialized = false;
055:
056: private static final String WELCOME_TEXT = "<h3>Welcome to the Millstone feature tour!</h3>"
057: + "In this Millstone application you may view a demonstration of some of its "
058: + "features.<br/>"
059: + "Most of the features can be tested online and include simple example of their "
060: + "usage associated with it.<br/><br/>"
061: + "Start your tour by selecting features from the list on the left.<br/><br/>"
062: + "For more information, point your browser to: <a href=\"http://www.millstone.org\""
063: + " target=\"_new\">www.millstone.org</a>";
064:
065: public void attach() {
066:
067: if (initialized)
068: return;
069: initialized = true;
070:
071: // Configure tree
072: features = new Tree();
073: features.setStyle("menu");
074: features.addContainerProperty("name", String.class, "");
075: features.addContainerProperty("feature", Feature.class, null);
076: features.setItemCaptionPropertyId("name");
077: features.addListener(this );
078: features.setImmediate(true);
079:
080: // Configure component layout
081: layout = new GridLayout(2, 1);
082: setCompositionRoot(layout);
083: OrderedLayout left = new OrderedLayout();
084: left.addComponent(features);
085: Button close = new Button("restart", getApplication(), "close");
086: left.addComponent(close);
087: close.setStyle("link");
088: layout.addComponent(left, 0, 0, 0, 0);
089: Label greeting = new Label(WELCOME_TEXT, Label.CONTENT_XHTML);
090: //welcomePanel = new Panel((String) null);
091: welcome = new Embedded("", new ClassResource(getClass(),
092: "millstone-logo.gif", getApplication()));
093: // welcomePanel.addComponent(greeting);
094: layout.addComponent(welcome, 1, 0, 1, 0);
095:
096: // Test component
097: registerFeature("/UI Components", new UIComponents());
098: registerFeature("/UI Components/Basic/Text Field",
099: new FeatureTextField());
100: registerFeature("/UI Components/Basic/Date Field",
101: new FeatureDateField());
102: registerFeature("/UI Components/Basic/Button",
103: new FeatureButton());
104: registerFeature("/UI Components/Basic/Form", new FeatureForm());
105: registerFeature("/UI Components/Basic/Label",
106: new FeatureLabel());
107: registerFeature("/UI Components/Basic/Link", new FeatureLink());
108: registerFeature("/UI Components/Item Containers/Select",
109: new FeatureSelect());
110: registerFeature("/UI Components/Item Containers/Table",
111: new FeatureTable());
112: registerFeature("/UI Components/Item Containers/Tree",
113: new FeatureTree());
114: registerFeature("/UI Components/Layouts/Ordered Layout",
115: new FeatureOrderedLayout());
116: registerFeature("/UI Components/Layouts/Grid Layout",
117: new FeatureGridLayout());
118: registerFeature("/UI Components/Layouts/Custom Layout",
119: new FeatureCustomLayout());
120: registerFeature("/UI Components/Layouts/Panel",
121: new FeaturePanel());
122: registerFeature("/UI Components/Layouts/Tab Sheet",
123: new FeatureTabSheet());
124: registerFeature("/UI Components/Layouts/Window",
125: new FeatureWindow());
126: registerFeature("/UI Components/Layouts/Frame Window",
127: new FeatureFrameWindow());
128: registerFeature(
129: "/UI Components/Data handling/Embedded Objects",
130: new FeatureEmbedded());
131: registerFeature("/UI Components/Data handling/Upload",
132: new FeatureUpload());
133: registerFeature("/Data Model/Properties",
134: new FeatureProperties());
135: registerFeature("/Data Model/Items", new FeatureItems());
136: registerFeature("/Data Model/Containers",
137: new FeatureContainers());
138: registerFeature("/Data Model/Validators",
139: new FeatureValidators());
140: registerFeature("/Data Model/Buffering", new FeatureBuffering());
141: registerFeature("/Terminal/Server Initiated Events",
142: new FeatureServerEvents());
143: registerFeature("/Terminal/Parameters and URI Handling",
144: new FeatureParameters());
145:
146: // Pre-open all menus
147: for (Iterator i = features.getItemIds().iterator(); i.hasNext();)
148: features.expandItem(i.next());
149: }
150:
151: public void registerFeature(String path, Feature feature) {
152: StringTokenizer st = new StringTokenizer(path, "/");
153: String id = "";
154: String parentId = null;
155: while (st.hasMoreTokens()) {
156: String token = st.nextToken();
157: id += "/" + token;
158: if (!features.containsId(id)) {
159: features.addItem(id);
160: features.setChildrenAllowed(id, false);
161: }
162: features.getContainerProperty(id, "name").setValue(token);
163: if (parentId != null) {
164: features.setChildrenAllowed(parentId, true);
165: features.setParent(id, parentId);
166: }
167: if (!st.hasMoreTokens())
168: features.getContainerProperty(id, "feature").setValue(
169: feature);
170: parentId = id;
171: }
172: }
173:
174: public void valueChange(Property.ValueChangeEvent event) {
175:
176: // Change feature
177: if (event.getProperty() == features) {
178: Object id = features.getValue();
179: if (id != null) {
180: if (features.areChildrenAllowed(id))
181: features.expandItem(id);
182: Property p = features.getContainerProperty(id,
183: "feature");
184: Feature feature = p != null ? ((Feature) p.getValue())
185: : null;
186: if (feature != null) {
187: if (currentFeature != null)
188: layout.removeComponent(currentFeature);
189: currentFeature = feature;
190: layout.removeComponent(1, 0);
191: layout.addComponent(currentFeature, 1, 0);
192: getWindow().setCaption(
193: "Millstone Features / "
194: + features.getContainerProperty(id,
195: "name"));
196: }
197: }
198: }
199: }
200: }
|