diff options
author | Joonas Lehtinen <joonas.lehtinen@itmill.com> | 2006-11-01 09:11:32 +0000 |
---|---|---|
committer | Joonas Lehtinen <joonas.lehtinen@itmill.com> | 2006-11-01 09:11:32 +0000 |
commit | 13af8cba414fbb6f02ef458a86c5afcad70c5275 (patch) | |
tree | 959ccae1696d9c208124ec3982f166bca6c28f0a /src/com/itmill/toolkit/demo | |
parent | de5565e87dc08be0a577c663bb2e009d0838c872 (diff) | |
download | vaadin-framework-13af8cba414fbb6f02ef458a86c5afcad70c5275.tar.gz vaadin-framework-13af8cba414fbb6f02ef458a86c5afcad70c5275.zip |
Refactoring: Enably -> IT Mill Toolkit
svn changeset:92/svn branch:toolkit
Diffstat (limited to 'src/com/itmill/toolkit/demo')
67 files changed, 5048 insertions, 0 deletions
diff --git a/src/com/itmill/toolkit/demo/Calc.java b/src/com/itmill/toolkit/demo/Calc.java new file mode 100644 index 0000000000..9565e99d00 --- /dev/null +++ b/src/com/itmill/toolkit/demo/Calc.java @@ -0,0 +1,114 @@ +package com.itmill.toolkit.demo; + +import com.itmill.toolkit.ui.*; + +/** <p>An example application implementing a simple web-based calculator. + * using the MillStone UI library. The application opens up a window and + * places the needed UI components (display label, buttons etc.) on it, and + * registers a button click listener for them.</p> + * + * <p>When any of the buttons are pressed the application finds out which + * button was pressed, figures what that button does, and updates the user + * interface accordingly.</p> + * + * @see com.itmill.toolkit.Application + * @see com.itmill.toolkit.ui.Button.ClickListener + */ +public class Calc + extends com.itmill.toolkit.Application + implements Button.ClickListener { + + /** The label used as the display */ + private Label display = null; + + /** Last completed result */ + private double stored = 0.0; + + /** The number being currently edited. */ + private double current = 0.0; + + /** Last activated operation. */ + private String operation = "C"; + + /** Button captions. */ + private static String[] captions = // Captions for the buttons + {"7","8","9","/","4","5","6","*","1","2","3","-","0","=","C","+" }; + + /** <p>Initializes the application. This is the only method a MillStone + * application is required to implement. It's called by the framework + * and it should perform whatever initialization tasks the application + * needs to perform.</p> + * + * <p>In this case we create the main window, the display, the grid to + * hold the buttons, and the buttons themselves.</p> + */ + public void init() { + + /* + * Create a new {@link com.itmill.toolkit.ui.GridLayout GridLayout} + * to hold the UI components needed by the calculator. + */ + GridLayout layout = new GridLayout(4, 5); + + //Create a new label component for displaying the result + display = new Label(Double.toString(current)); + display.setCaption("Result"); + + // Place the label to the top of the previously created grid. + layout.addComponent(display, 0, 0, 3, 0); + + // Create the buttons and place them in the grid + for (int i = 0; i < captions.length; i++) { + layout.addComponent(new Button(captions[i], this)); + } + + /* + * Create the main window with a caption and add it to the + * application. + */ + addWindow(new Window("MillStone calculator", layout)); + + } + + /** <p>The button listener method called any time a button is pressed. + * This method catches all button presses, figures out what the user + * wanted the application to do, and updates the UI accordingly.</p> + * + * <p>The button click event passed to this method contains information + * about which button was pressed. If it was a number, the currently + * edited number is updated. If it was something else, the requested + * operation is performed. In either case the display label is updated + * to include the outcome of the button click.</p> + * + * @param event the button click event specifying which button was + * pressed + */ + public void buttonClick(Button.ClickEvent event) { + + try { + // Number button pressed + current = + current * 10 + + Double.parseDouble(event.getButton().getCaption()); + display.setValue(Double.toString(current)); + } catch (java.lang.NumberFormatException e) { + + // Operation button pressed + if (operation.equals("+")) + stored += current; + if (operation.equals("-")) + stored -= current; + if (operation.equals("*")) + stored *= current; + if (operation.equals("/")) + stored /= current; + if (operation.equals("C")) + stored = current; + if (event.getButton().getCaption().equals("C")) + stored = 0.0; + operation = event.getButton().getCaption(); + current = 0.0; + display.setValue(Double.toString(stored)); + } + } +} diff --git a/src/com/itmill/toolkit/demo/Chat.java b/src/com/itmill/toolkit/demo/Chat.java new file mode 100644 index 0000000000..9bafd960ef --- /dev/null +++ b/src/com/itmill/toolkit/demo/Chat.java @@ -0,0 +1,296 @@ +package com.itmill.toolkit.demo; + +import java.io.*; +import java.util.*; +import java.lang.ref.WeakReference; + +import com.itmill.toolkit.terminal.StreamResource; +import com.itmill.toolkit.ui.*; + +/** Chat example application. + * + * <p>This example application implements Internet chatroom with the + * following features: + * <ul> + * <li>Continuosly streaming chat discussion. This is implemented + * with StreamResource that is kept open during the discussion. + * <li>Dynamically changing frames. + * <li>Chatroom that is implemented with static list of chatters + * referenced by weak references. + * </ul> + * </p> + * + * @see com.itmill.toolkit.Application + * @see com.itmill.toolkit.ui.FrameWindow + * @see com.itmill.toolkit.terminal.StreamResource + */ + +public class Chat + extends com.itmill.toolkit.Application + implements StreamResource.StreamSource, Button.ClickListener { + + /** Linked list of Chat applications who participate the discussion */ + private static LinkedList chatters = new LinkedList(); + + /** Reference (to this application) stored in chatters list */ + private WeakReference listEntry = null; + + /** Writer for writing to open chat stream */ + private PrintWriter chatWriter = null; + + /** Login name / Alias for chat */ + private TextField loginName = new TextField("Your name?", ""); + + /** Login button */ + private Button loginButton = new Button("Enter chat"); + + /** Text to be said to discussion */ + private TextField sayText = new TextField(); + + /** Button for sending the sayTest to discussion */ + private Button say = new Button("Say"); + + /** Button for listing the people in the chatroom */ + private Button listUsers = new Button("List chatters"); + + /** Last time this chat application said something */ + private long idleSince = (new Date()).getTime(); + + /** framewindow for following the discussion and control */ + FrameWindow frames = new FrameWindow("Millstone chat"); + + /** Last messages */ + private static LinkedList lastMessages = new LinkedList(); + + /** Initialize the chat application */ + public void init() { + + // Initialize user interface + say.dependsOn(sayText); + say.addListener((Button.ClickListener) this); + listUsers.addListener((Button.ClickListener) this); + StreamResource chatStream = + new StreamResource(this, "discussion.html", this); + chatStream.setBufferSize(1); + chatStream.setCacheTime(0); + frames.getFrameset().newFrame(chatStream, "chatDiscussion"); + Window controls = + new Window( + "", + new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); + controls.setName("chatControls"); + controls.addComponent(sayText); + sayText.setColumns(40); + controls.addComponent(say); + controls.addComponent(loginName); + loginName.focus(); + controls.addComponent(loginButton); + loginButton.dependsOn(loginName); + loginButton.addListener(this); + controls.addComponent(listUsers); + Button leaveButton = new Button("Leave", this, "leave"); + controls.addComponent(leaveButton); + say.setVisible(false); + sayText.setVisible(false); + frames.getFrameset().newFrame(controls).setAbsoluteSize(60); + frames.getFrameset().setVertical(true); + frames.setName("chatMain"); + setMainWindow(frames); + + // Register chat application + synchronized (chatters) { + chatters.add(listEntry = new WeakReference(this)); + } + } + + /** Handle button actions for login, user listing and saying */ + public void buttonClick(Button.ClickEvent event) { + + // Say something in discussion + if (event.getSource() == say && sayText.toString().length() > 0) { + + // Say something to chatstream + say("<b>" + getUser() + ": </b>" + sayText + "<br>"); + + // Clear the saytext field + sayText.setValue(""); + sayText.focus(); + } + + // List the users + else if (event.getSource() == listUsers) + listUsers(); + + // Login to application + else if ( + event.getSource() == loginButton + && loginName.toString().length() > 0) { + + // Set user name + setUser(loginName.toString()); + + // Hide logins controls + loginName.setVisible(false); + loginButton.setVisible(false); + + // Show say controls + say.setVisible(true); + sayText.setVisible(true); + sayText.focus(); + + // Announce discussion joining + say( + "<i>" + + getUser() + + " joined the discussion (" + + (new Date()).toString() + + ")</i><br>"); + } + } + + /** List chatters to chat stream */ + private void listUsers() { + + // Compose userlist + StringBuffer userlist = new StringBuffer(); + userlist.append( + "<div style=\"background-color: #ffffd0;\"><b>Chatters (" + + (new Date()) + + ")</b><ul>"); + synchronized (chatters) { + for (Iterator i = chatters.iterator(); i.hasNext();) { + try { + Chat c = (Chat) ((WeakReference) i.next()).get(); + String name = (String) c.getUser(); + if (name != null && name.length() > 0) { + userlist.append("<li>" + name); + userlist.append( + " (idle " + + ((new Date()).getTime() - c.idleSince) / 1000 + + "s)"); + } + } catch (NullPointerException ignored) { + } + } + } + userlist.append("</ul></div><script>self.scroll(0,71234);</script>\n"); + + // Print the user list to chatstream + printToStream(userlist.toString()); + } + + /** Print to chatstream and scroll the window */ + private void printToStream(String text) { + if (chatWriter != null) { + chatWriter.println(text); + chatWriter.println("<script>self.scroll(0,71234);</script>\n"); + chatWriter.flush(); + } + } + + /** Say to all chat streams */ + private void say(String text) { + + // Get all the listeners + Object[] listener; + synchronized (chatters) { + listener = chatters.toArray(); + } + + // Put the saytext to listener streams + // Remove dead listeners + for (int i = 0; i < listener.length; i++) { + Chat c = (Chat) ((WeakReference) listener[i]).get(); + if (c != null) + c.printToStream(text); + else + chatters.remove(listener[i]); + } + + // Update idle time + idleSince = (new Date()).getTime(); + + // Update last messages + synchronized (lastMessages) { + lastMessages.addLast(text); + while (lastMessages.size() > 5) + lastMessages.removeFirst(); + } + } + + /** Open chat stream */ + public InputStream getStream() { + + // Close any existing streams + if (chatWriter != null) + chatWriter.close(); + + // Create piped stream + PipedOutputStream chatStream = new PipedOutputStream(); + chatWriter = new PrintWriter(chatStream); + InputStream is = null; + try { + is = new PipedInputStream(chatStream); + } catch (IOException ignored) { + chatWriter = null; + return null; + }; + + // Write headers + printToStream( + "<html><head><title>Discussion " + + (new Date()) + + "</title>" + + "</head><body>\n"); + + // Print last messages + Object[] msgs; + synchronized (lastMessages) { + msgs = lastMessages.toArray(); + } + for (int i = 0; i < msgs.length; i++) + printToStream(msgs[i].toString()); + + // Allways list the users + listUsers(); + + return is; + } + + /** Leave the chat */ + public void leave() { + + // If we have been logged in, say goodbye + if (listEntry != null) { + if (getUser() != null) + say( + "<i>" + + getUser() + + " left the chat (" + + (new Date()) + + ")</i><br>"); + + synchronized (chatters) { + chatters.remove(listEntry); + listEntry = null; + } + } + if (chatWriter != null) + chatWriter.close(); + + // Close the chat frames + if (frames != null) { + frames.getFrameset().removeAllFrames(); + Window restartWin = new Window(); + frames.getFrameset().newFrame(restartWin); + restartWin.addComponent(new Button("Restart chat", this, "close")); + frames = null; + } + } + + /** Make sure that everybody leaves the chat */ + public void finalize() { + leave(); + } + +} diff --git a/src/com/itmill/toolkit/demo/HelloWorld.java b/src/com/itmill/toolkit/demo/HelloWorld.java new file mode 100644 index 0000000000..ca116a54c9 --- /dev/null +++ b/src/com/itmill/toolkit/demo/HelloWorld.java @@ -0,0 +1,43 @@ +package com.itmill.toolkit.demo; + +import com.itmill.toolkit.ui.*; + +/** The classic "hello, world!" example for the MillStone framework. The + * class simply implements the abstract + * {@link com.itmill.toolkit.Application#init() init()} method + * in which it creates a Window and adds a Label to it. + * + * @author IT Mill Ltd. + * @see com.itmill.toolkit.Application + * @see com.itmill.toolkit.ui.Window + * @see com.itmill.toolkit.ui.Label + */ +public class HelloWorld extends com.itmill.toolkit.Application { + + /** The initialization method that is the only requirement for + * inheriting the com.itmill.toolkit.service.Application class. It will + * be automatically called by the framework when a user accesses the + * application. + */ + public void init() { + + /* + * - Create new window for the application + * - Give the window a visible title + * - Set the window to be the main window of the application + */ + Window main = new Window("Hello window"); + setMainWindow(main); + + /* + * - Create a label with the classic text + * - Add the label to the main window + */ + main.addComponent(new Label("Hello World!")); + + /* + * And that's it! The framework will display the main window and its + * contents when the application is accessed with the terminal. + */ + } +} diff --git a/src/com/itmill/toolkit/demo/Login.java b/src/com/itmill/toolkit/demo/Login.java new file mode 100644 index 0000000000..d9949d356a --- /dev/null +++ b/src/com/itmill/toolkit/demo/Login.java @@ -0,0 +1,136 @@ +package com.itmill.toolkit.demo; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.data.*; +import com.itmill.toolkit.ui.*; + +/** <p>Example application demonstrating simple user login.</p> + * + * @author IT Mill Ltd. + * @see com.itmill.toolkit.service.Application + * @see com.itmill.toolkit.ui.Window + * @see com.itmill.toolkit.ui.TextField + * @see com.itmill.toolkit.ui.Button + */ +public class Login + extends Application + implements Property.ValueChangeListener { + + /* Menu for navigating inside the application. */ + private Tree menu = new Tree(); + + /* Contents of the website */ + private String[][] pages = { { "Welcome", "Welcome to out website..." }, { + "Products", "Public product information." }, { + "Contact", "Public contact information." }, { + "CRM", "CRM Database requiring login." }, { + "Intranet", "Internal information database." } + }; + + /* Application layout */ + private GridLayout layout = new GridLayout(2, 1); + + /* Initialize the application */ + public void init() { + + // Create the main window of the application + Window main = new Window("Login example", layout); + setMainWindow(main); + + // Add menu and loginbox to the application + OrderedLayout l = new OrderedLayout(); + layout.addComponent(l, 0, 0); + l.addComponent(menu); + l.addComponent(new LoginBox()); + + // Setup menu + menu.setStyle("menu"); + menu.addListener(this); + menu.setImmediate(true); + addToMenu(new String[] {"Welcome","Products","Contact"}); + } + + // Overriding usetUser method is a simple way of updating application + // privileges when the user is changed + public void setUser(Object user) { + super.setUser(user); + if (user != null) + addToMenu(new String[] {"CRM","Intranet"}); + } + + public void addToMenu(String[] items) { + for (int i=0; i<items.length; i++) { + menu.addItem(items[i]); + menu.setChildrenAllowed(items[i], false); + } + if (menu.getValue()== null) menu.setValue(items[0]); + } + + // Handle menu selection and update visible page + public void valueChange(Property.ValueChangeEvent event) { + layout.removeComponent(1, 0); + String title = (String) menu.getValue(); + for (int i = 0; i < pages.length; i++) + if (pages[i][0].equals(title)) { + Panel p = new Panel(pages[i][0]); + p.addComponent(new Label(pages[i][1])); + p.setStyle("strong"); + layout.addComponent(p, 1, 0); + } + } + + // Simple loginbox component for the application + public class LoginBox + extends CustomComponent + implements Application.UserChangeListener { + + // The components this loginbox is composed of + private TextField loginName = new TextField("Name"); + private Button loginButton = new Button("Enter", this, "login"); + private Panel loginPanel = new Panel("Login"); + private Panel statusPanel = new Panel(); + private Button logoutButton = new Button("Logout", Login.this, "close"); + private Label statusLabel = new Label(); + + // Initialize login component + public LoginBox() { + + // Initialize the component + loginPanel.addComponent(loginName); + loginPanel.addComponent(loginButton); + loginPanel.setStyle("strong"); + loginButton.dependsOn(loginName); + loginName.setColumns(8); + statusPanel.addComponent(statusLabel); + statusPanel.addComponent(logoutButton); + + // Set the status of the loginbox and show correct components + updateStatus(); + + // Listen application user change events + Login.this.addListener(this); + } + + // Login into application + public void login() { + String name = (String) loginName.getValue(); + if (name != null && name.length() > 0) + setUser(name); + loginName.setValue(""); + } + + // Update login status on application user change events + public void applicationUserChanged(Application.UserChangeEvent event) { + updateStatus(); + } + + // Update login status of the component by exposing correct components + private void updateStatus() { + statusLabel.setValue("User: " + getUser()); + if (getUser() != null) + setCompositionRoot(statusPanel); + else + setCompositionRoot(loginPanel); + } + } +} diff --git a/src/com/itmill/toolkit/demo/features/Feature.java b/src/com/itmill/toolkit/demo/features/Feature.java new file mode 100644 index 0000000000..003f884ac1 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/Feature.java @@ -0,0 +1,122 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.terminal.ClassResource; +import com.itmill.toolkit.terminal.Resource; +import com.itmill.toolkit.ui.*; + +public class Feature extends CustomComponent { + + private TabSheet ts; + + private boolean initialized = false; + + private static Resource sampleIcon; + + /** Constuctor for the feature component */ + public Feature() { + ts = new TabSheet(); + setCompositionRoot(ts); + } + + /** Feature component initialization is lazily done when the + * feature is attached to application */ + public void attach() { + + // Check if the feature is already initialized + if (initialized) return; + initialized = true; + + // Optional description with image + String desc = getDescriptionXHTML(); + String title = getTitle(); + if (desc != null && title != null) { + GridLayout gl = new GridLayout(2, 1); + if (getImage() != null) + gl.addComponent( + new Embedded( + "", new ClassResource(getImage(), this.getApplication()))); + gl.addComponent( + new Label( + "<h2>" + title + "</h2>" + desc, + Label.CONTENT_XHTML)); + ts.addTab(gl, "Description", null); + } + + // Demo + Component demo = getDemoComponent(); + if (demo != null) + ts.addTab(demo, "Demo", null); + + // Example source + String example = getExampleSrc(); + if (example != null) { + OrderedLayout l = new OrderedLayout(); + l.addComponent( + new Label( + "<h2>" + getTitle() + " example</h2>", + Label.CONTENT_XHTML)); + l.addComponent(new Label(example, Label.CONTENT_PREFORMATTED)); + ts.addTab(l, "Code Sample", null); + } + } + + /** Get the desctiption of the feature as XHTML fragment */ + protected String getDescriptionXHTML() { + return "<h2>Feature description is under construction</h2>"; + } + + /** Get the title of the feature */ + protected String getTitle() { + return this.getClass().getName(); + } + + /** Get the name of the image file that will be put on description page */ + protected String getImage() { + return null; + } + + /** Get the example application source code */ + protected String getExampleSrc() { + return null; + } + + /** Get the feature demo component */ + protected Component getDemoComponent() { + return null; + } + + /** Get sample icon resource */ + protected Resource getSampleIcon() { + if (sampleIcon == null) sampleIcon = new ClassResource("m.gif",this.getApplication()); + return sampleIcon; + } + +}
\ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/features/FeatureBrowser.java b/src/com/itmill/toolkit/demo/features/FeatureBrowser.java new file mode 100644 index 0000000000..42420041f5 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureBrowser.java @@ -0,0 +1,202 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.util.Iterator; +import java.util.StringTokenizer; + +import com.itmill.toolkit.data.*; +import com.itmill.toolkit.terminal.ClassResource; +import com.itmill.toolkit.ui.*; + +public class FeatureBrowser + extends CustomComponent + implements Property.ValueChangeListener { + + private Tree features; + private Feature currentFeature = null; + private GridLayout layout; + private Component welcome; + private boolean initialized = false; + + private static final String WELCOME_TEXT = + "<h3>Welcome to the Millstone feature tour!</h3>" + + "In this Millstone application you may view a demonstration of some of its " + + "features.<br/>" + + "Most of the features can be tested online and include simple example of their " + + "usage associated with it.<br/><br/>" + + "Start your tour by selecting features from the list on the left.<br/><br/>" + + "For more information, point your browser to: <a href=\"http://www.millstone.org\"" + + " target=\"_new\">www.millstone.org</a>"; + + public void attach() { + + if (initialized) + return; + initialized = true; + + // Configure tree + features = new Tree(); + features.setStyle("menu"); + features.addContainerProperty("name", String.class, ""); + features.addContainerProperty("feature", Feature.class, null); + features.setItemCaptionPropertyId("name"); + features.addListener(this); + features.setImmediate(true); + + // Configure component layout + layout = new GridLayout(2, 1); + setCompositionRoot(layout); + OrderedLayout left = new OrderedLayout(); + left.addComponent(features); + Button close = new Button("restart", getApplication(), "close"); + left.addComponent(close); + close.setStyle("link"); + layout.addComponent(left, 0, 0, 0, 0); + Label greeting = new Label(WELCOME_TEXT, Label.CONTENT_XHTML); + //welcomePanel = new Panel((String) null); + welcome = + new Embedded( + "", + new ClassResource( + getClass(), + "millstone-logo.gif", + getApplication())); + // welcomePanel.addComponent(greeting); + layout.addComponent(welcome, 1, 0, 1, 0); + + // Test component + registerFeature( + "/UI Components", + new UIComponents()); + registerFeature( + "/UI Components/Basic/Text Field", + new FeatureTextField()); + registerFeature( + "/UI Components/Basic/Date Field", + new FeatureDateField()); + registerFeature("/UI Components/Basic/Button", new FeatureButton()); + registerFeature("/UI Components/Basic/Form", new FeatureForm()); + registerFeature("/UI Components/Basic/Label", new FeatureLabel()); + registerFeature("/UI Components/Basic/Link", new FeatureLink()); + registerFeature( + "/UI Components/Item Containers/Select", + new FeatureSelect()); + registerFeature( + "/UI Components/Item Containers/Table", + new FeatureTable()); + registerFeature( + "/UI Components/Item Containers/Tree", + new FeatureTree()); + registerFeature( + "/UI Components/Layouts/Ordered Layout", + new FeatureOrderedLayout()); + registerFeature( + "/UI Components/Layouts/Grid Layout", + new FeatureGridLayout()); + registerFeature( + "/UI Components/Layouts/Custom Layout", + new FeatureCustomLayout()); + registerFeature("/UI Components/Layouts/Panel", new FeaturePanel()); + registerFeature( + "/UI Components/Layouts/Tab Sheet", + new FeatureTabSheet()); + registerFeature("/UI Components/Layouts/Window", new FeatureWindow()); + registerFeature( + "/UI Components/Layouts/Frame Window", + new FeatureFrameWindow()); + registerFeature( + "/UI Components/Data handling/Embedded Objects", + new FeatureEmbedded()); + registerFeature( + "/UI Components/Data handling/Upload", + new FeatureUpload()); + registerFeature("/Data Model/Properties", new FeatureProperties()); + registerFeature("/Data Model/Items", new FeatureItems()); + registerFeature("/Data Model/Containers", new FeatureContainers()); + registerFeature("/Data Model/Validators", new FeatureValidators()); + registerFeature("/Data Model/Buffering", new FeatureBuffering()); + registerFeature( + "/Terminal/Server Initiated Events", + new FeatureServerEvents()); + registerFeature( + "/Terminal/Parameters and URI Handling", + new FeatureParameters()); + + // Pre-open all menus + for (Iterator i=features.getItemIds().iterator(); i.hasNext();) + features.expandItem(i.next()); + } + + public void registerFeature(String path, Feature feature) { + StringTokenizer st = new StringTokenizer(path, "/"); + String id = ""; + String parentId = null; + while (st.hasMoreTokens()) { + String token = st.nextToken(); + id += "/" + token; + if (!features.containsId(id)) { + features.addItem(id); + features.setChildrenAllowed(id, false); + } + features.getContainerProperty(id, "name").setValue(token); + if (parentId != null) { + features.setChildrenAllowed(parentId, true); + features.setParent(id, parentId); + } + if (!st.hasMoreTokens()) + features.getContainerProperty(id, "feature").setValue(feature); + parentId = id; + } + } + + public void valueChange(Property.ValueChangeEvent event) { + + // Change feature + if (event.getProperty() == features) { + Object id = features.getValue(); + if (id != null) { + if (features.areChildrenAllowed(id)) + features.expandItem(id); + Property p = features.getContainerProperty(id, "feature"); + Feature feature = p != null ? ((Feature) p.getValue()) : null; + if (feature != null) { + if (currentFeature != null) + layout.removeComponent(currentFeature); + currentFeature = feature; + layout.removeComponent(1, 0); + layout.addComponent(currentFeature, 1, 0); + getWindow().setCaption( + "Millstone Features / " + + features.getContainerProperty(id, "name")); + } + } + } + } +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureBuffering.java b/src/com/itmill/toolkit/demo/features/FeatureBuffering.java new file mode 100644 index 0000000000..a02215cd36 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureBuffering.java @@ -0,0 +1,68 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +public class FeatureBuffering extends Feature { + protected String getExampleSrc() { + return super.getExampleSrc(); + } + + protected String getTitle() { + return "Buffering"; + } + /** + * @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML() + */ + protected String getDescriptionXHTML() { + return "<p>Millstone data model provides interface for implementing " + + "buffering in data components. The basic idea is that a component " + + "reading their state from data source can implement " + + "Buffered-interface, for storing the value internally. " + + "Buffering provides transactional access " + + "for setting data: data can be put to a component's buffer and " + + "afterwards committed to or discarded by re-reding it from the data source. " + + "The buffering can be used for creating interactive interfaces " + + "as well as caching the data for performance reasons.</p>" + + "<p>Buffered interface contains methods for committing and discarding " + + "changes to an object and support for controlling buffering mode " + + "with read-through and write-through modes. " + + "Read-through mode means that the value read from the buffered " + + "object is constantly up to date with the data source. " + + "Respectively the write-through mode means that all changes to the object are " + + "immediately updated to the data source.</p>"; + } + + /** + * @see com.itmill.toolkit.demo.features.Feature#getImage() + */ + protected String getImage() { + return "buffering.jpg"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureButton.java b/src/com/itmill/toolkit/demo/features/FeatureButton.java new file mode 100644 index 0000000000..584b7c41d1 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureButton.java @@ -0,0 +1,90 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeatureButton extends Feature { + + public FeatureButton() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("Button component"); + Button b = new Button("Caption"); + show.addComponent(b); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(b); + Select themes = (Select) p.getField("style"); + themes + .addItem("link") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("link"); + Form ap = p.createBeanPropertySet(new String[] { "switchMode" }); + p.addProperties("Button Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "Button b = new Button(\"Caption\");\n"; + + } + + /** + * @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML() + */ + protected String getDescriptionXHTML() { + return "In Millstone, boolean input values are represented by buttons. " + + "Buttons may function either as a push buttons or switches. (checkboxes)<br/><br/>" + + "Button can be directly connected to any method of an object, which " + + "is an easy way to trigger events: <code> new Button(\"Play\", myPiano \"playIt\")</code>. " + + "Or in checkbox-mode they can be bound to a boolean proterties and create " + + " simple selectors.<br /><br /> " + + "See the demo and try out how the different properties affect " + + "the presentation of the component."; + } + + protected String getImage() { + return "button.jpg"; + } + + protected String getTitle() { + return "Button"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureContainers.java b/src/com/itmill/toolkit/demo/features/FeatureContainers.java new file mode 100644 index 0000000000..5cc6a32dfe --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureContainers.java @@ -0,0 +1,64 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +public class FeatureContainers extends Feature { + + protected String getTitle() { + return "Container Data Model"; + } + + protected String getDescriptionXHTML() { + return "<p>Container is the most advanced of the data " + + "model supported by Millstone. It provides a very flexible " + + "way of managing set of items that share common properties. Each " + + "item is identified by an item id. " + + "Properties can be requested from container with item " + + "and property ids. Other way of accessing properties is to first " + + "request an item from container and then request its properties " + + "from it. </p>" + + "<p>Container interface was designed with flexibility and " + + "efficiency in mind. It contains inner interfaces for ordering " + + "the items sequentially, indexing the items and accessing them " + + "hierarchically. Those ordering models provide basis for " + + "Table, Tree and Select UI components. As with other data " + + "models, the containers support events for notifying about the " + + "changes.</p>" + + "<p>Set of utilities for converting between container models by " + + "adding external indexing or hierarchy into existing containers. " + + "In memory containers implementing indexed and hierarchical " + + "models provide easy to use tools for setting up in memory data " + + "storages. There is even a hierarchical container for direct " + + "file system access.</p>"; + } + + protected String getImage() { + return "containers.jpg"; + } +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureCustomLayout.java b/src/com/itmill/toolkit/demo/features/FeatureCustomLayout.java new file mode 100644 index 0000000000..c87d6318b7 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureCustomLayout.java @@ -0,0 +1,95 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.net.MalformedURLException; +import java.net.URL; + +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.ui.*; + +public class FeatureCustomLayout extends Feature { + + protected String getDescriptionXHTML() { + return "<p>A container component with freely designed layout and style. The " + + "container consists of items with textually represented locations. Each " + + "item contains one sub-component. The adapter and theme are resposible " + + "for rendering the layout with given style by placing the items on the " + + "screen in defined locations.</p>" + + "<p>The definition of locations is not fixed - the each style can define its " + + "locations in a way that is suitable for it. One typical example would be " + + "to create visual design for a website as a custom layout: the visual design " + + "could define locations for \"menu\", \"body\" and \"title\" for example. " + + "The layout would then be implemented as XLS-template with for given style.</p>" + + "<p>The default theme handles the styles that are not defined by just drawing " + + "the subcomponents with flowlayout.</p>"; + } + + protected String getExampleSrc() { + return "CustomLayout c = new CustomLayout(\"style-name\");\n" + + "c.addComponent(new Label(\"foo\"),\"foo-location\");\n" + + "c.addComponent(new Label(\"bar\"),\"bar-location\");\n"; + } + + protected String getImage() { + return "customlayout.jpg"; + } + + protected String getTitle() { + return "CustomLayout"; + } + + protected Component getDemoComponent() { + OrderedLayout l = new OrderedLayout(); + + l.addComponent( + new Label( + "<p>For demonstration, see GO-Game example application. All of the "+ + "layouting done in the aplication is handled by CustomLayout with \"goroom\"-style "+ + "that is defined in \"gogame\"-theme. The theme is simply created by exteding "+ + "default theme trough theme-inheritance and adding couple of xsl-templates</p>", + Label.CONTENT_UIDL)); + + URL goUrl = null; + try { + goUrl = new URL(getApplication().getURL(), "../go/"); + } catch (MalformedURLException e) { + } + + if (goUrl != null) { + Link link = new Link("Start GO-Game", new ExternalResource(goUrl)); + link.setTargetName("gogame"); + link.setTargetBorder(Link.TARGET_BORDER_NONE); + l.addComponent(link); + } + + return l; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureDateField.java b/src/com/itmill/toolkit/demo/features/FeatureDateField.java new file mode 100644 index 0000000000..74547ce238 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureDateField.java @@ -0,0 +1,136 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.util.Locale; + +import com.itmill.toolkit.data.util.IndexedContainer; +import com.itmill.toolkit.data.util.MethodProperty; +import com.itmill.toolkit.ui.*; + +public class FeatureDateField extends Feature { + + static private IndexedContainer localeContainer; + static { + localeContainer = new IndexedContainer(); + localeContainer.addContainerProperty("name", String.class, ""); + Locale[] locales = Locale.getAvailableLocales(); + for (int i = 0; i < locales.length; i++) + localeContainer.addItem(locales[i]).getItemProperty("name").setValue( + locales[i].getDisplayName()); + } + + public FeatureDateField() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("DateField component"); + DateField df = new DateField("Caption"); + df.setValue(new java.util.Date()); + show.addComponent(df); + l.addComponent(show); + + // Create locale selector + Select selector = new Select("Application Locale",localeContainer); + selector.setItemCaptionPropertyId("name"); + selector.setImmediate(true); + selector.setPropertyDataSource( + new MethodProperty(this.getApplication(), "locale")); + l.addComponent(selector); + + // Properties + PropertyPanel p = new PropertyPanel(df); + Form ap = p.createBeanPropertySet(new String[] { "resolution" }); + ap.replaceWithSelect( + "resolution", + new Object[] { + new Integer(DateField.RESOLUTION_YEAR), + new Integer(DateField.RESOLUTION_MONTH), + new Integer(DateField.RESOLUTION_DAY), + new Integer(DateField.RESOLUTION_HOUR), + new Integer(DateField.RESOLUTION_MIN), + new Integer(DateField.RESOLUTION_SEC), + new Integer(DateField.RESOLUTION_MSEC)}, + new Object[] { + "Year", + "Month", + "Day", + "Hour", + "Minute", + "Second", + "Millisecond" }); + Select themes = (Select) p.getField("style"); + themes + .addItem("text") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("text"); + themes + .addItem("calendar") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("calendar"); + p.addProperties("DateField Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "DateField df = new DateField(\"Caption\");\n" + + "df.setValue(new java.util.Date());\n"; + + } + + protected String getDescriptionXHTML() { + return "<p>Representing Dates and times and providing a way to select " + + "or enter some specific date and/or time is an typical need in " + + "data-entry userinterfaces. Millstone provides a DateField " + + "component that is intuitive to use and yet controllable through " + + "its properties.</p>" + + "<p>The calendar-style allows point-and-click selection "+ + "of dates while text-style shows only minimalistic user interface." + + "Validators may be bound to the component to check and " + + "validate the given input.</p>" + + "<p>On the demo tab you can try out how the different properties affect the " + + "presentation of the component.</p>"; + } + + protected String getImage() { + return "datefield.jpg"; + } + + protected String getTitle() { + return "DateField"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureEmbedded.java b/src/com/itmill/toolkit/demo/features/FeatureEmbedded.java new file mode 100644 index 0000000000..e9c447d385 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureEmbedded.java @@ -0,0 +1,131 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.terminal.ClassResource; +import com.itmill.toolkit.terminal.Sizeable; +import com.itmill.toolkit.ui.*; + +public class FeatureEmbedded extends Feature { + + public FeatureEmbedded() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("Embedded component"); + Embedded emb = new Embedded("Embedded Caption"); + emb.setClassId("clsid:F08DF954-8592-11D1-B16A-00C0F0283628"); + emb.setWidth(100); + emb.setHeight(50); + emb.setParameter("BorderStyle", "1"); + emb.setParameter("MousePointer", "1"); + emb.setParameter("Enabled", "1"); + emb.setParameter("Min", "1"); + emb.setParameter("Max", "10"); + show.addComponent(emb); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(emb); + Form ap = + p.createBeanPropertySet( + new String[] { + "type", + "source", + "width", + "height", + "widthUnits", + "heightUnits", + "codebase", + "codetype", + "archive", + "mimeType", + "standby", + "classId" }); + ap.replaceWithSelect( + "type", + new Object[] { + new Integer(Embedded.TYPE_IMAGE), + new Integer(Embedded.TYPE_OBJECT)}, + new Object[] { "Image", "Object" }); + Object[] units = new Object[Sizeable.UNIT_SYMBOLS.length]; + Object[] symbols = new Object[Sizeable.UNIT_SYMBOLS.length]; + for (int i = 0; i < units.length; i++) { + units[i] = new Integer(i); + symbols[i] = Sizeable.UNIT_SYMBOLS[i]; + } + ap.replaceWithSelect("heightUnits", units, symbols); + ap.replaceWithSelect("widthUnits", units, symbols); + ap.replaceWithSelect( + "source", + new Object[] { + null, + new ClassResource("millstone-logo.gif", getApplication())}, + new Object[] { "null", "Millstone logo" }); + p.addProperties("Embedded Properties", ap); + p.getField("standby").setDescription( + "The text to display while loading the object."); + p.getField("codebase").setDescription( + "root-path used to access resources with relative paths."); + p.getField("codetype").setDescription( + "MIME-type of the code."); + p.getField("classId").setDescription( + "Unique object id. This can be used for example to identify windows components."); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "// Load image from jpg-file, that is in the same package with the application\n" + + "Embedded e = new Embedded(\"Image title\",\n" + + " new ClassResource(\"image.jpg\", getApplication()));"; + } + + protected String getDescriptionXHTML() { + return "<p>The embedding feature allows for adding images, multimedia and other non-specified " + + "content to your application. " + + "The feature has provisions for embedding both applets and Active X controls. " + + "Actual support for embedded media types is left to the terminal.</p>"; + } + + protected String getImage() { + return "embedded.jpg"; + } + + protected String getTitle() { + return "Embedded"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureForm.java b/src/com/itmill/toolkit/demo/features/FeatureForm.java new file mode 100644 index 0000000000..87f70aa340 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureForm.java @@ -0,0 +1,190 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.util.Date; + +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.ui.*; + +public class FeatureForm + extends Feature + implements Property.ValueChangeListener { + + OrderedLayout demo = null; + Form test; + Layout formLayout = null; + Select addField = new Select("Add field"); + Select resetLayout = new Select("Restart"); + + protected Component getDemoComponent() { + + if (demo == null) { + demo = new OrderedLayout(); + createDemo(); + } + + return demo; + } + + private void createDemo() { + + demo.removeAllComponents(); + + // Test form + Panel testPanel = new Panel("Form component"); + if (formLayout == null) + test = new Form(); + else + test = new Form(formLayout); + testPanel.addComponent(test); + demo.addComponent(testPanel); + OrderedLayout actions = + new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + demo.addComponent(actions); + + // form adder + addField.setImmediate(true); + addField.addItem("Add field"); + addField.setNullSelectionItemId("Add field"); + addField.addItem("Text field"); + addField.addItem("Time"); + addField.addItem("Option group"); + addField.addItem("Calendar"); + addField.addListener(this); + actions.addComponent(addField); + + // Layout reset + resetLayout.setImmediate(true); + resetLayout.addItem("Select layout example"); + resetLayout.setNullSelectionItemId("Select layout example"); + resetLayout.addItem("Vertical form (OrderedLayout form-style)"); + resetLayout.addItem("Two columns (2x1 GridLayout)"); + resetLayout.addItem("Flow (OrderedLayout flow-orientation)"); + resetLayout.addListener(this); + actions.addComponent(resetLayout); + + // Properties + PropertyPanel p = new PropertyPanel(test); + p.addProperties("Form special properties", new Form()); + demo.addComponent(p); + } + + public void valueChange(Property.ValueChangeEvent event) { + + if (event.getProperty() == resetLayout) { + + String value = (String) resetLayout.getValue(); + + if (value != null) { + formLayout = null; + + if (value.equals("Two columns (2x1 GridLayout)")) + formLayout = new GridLayout(2, 1); + if (value.equals("Horizontal (OrderedLayout)")) + formLayout = + new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + + createDemo(); + resetLayout.setValue(null); + } + } + + if (event.getProperty() == addField) { + + String value = (String) addField.getValue(); + + if (value != null) { + if (value.equals("Text field")) + test.addField(new Object(), new TextField("Test field")); + if (value.equals("Time")) { + DateField d = new DateField("Time", new Date()); + d.setDescription( + "This is a DateField-component with text-style"); + d.setResolution(DateField.RESOLUTION_MIN); + d.setStyle("text"); + test.addField(new Object(), d); + } + if (value.equals("Calendar")) { + DateField c = new DateField("Calendar", new Date()); + c.setDescription( + "DateField-component with calendar-style and day-resolution"); + c.setStyle("calendar"); + c.setResolution(DateField.RESOLUTION_DAY); + test.addField(new Object(), c); + } + if (value.equals("Option group")) { + Select s = new Select("Options"); + s.setDescription("Select-component with optiongroup-style"); + s.addItem("Linux"); + s.addItem("Windows"); + s.addItem("Solaris"); + s.addItem("Symbian"); + s.setStyle("optiongroup"); + + test.addField(new Object(), s); + } + + addField.setValue(null); + } + } + } + + protected String getDescriptionXHTML() { + return + "<p>Form is a flexible, yet simple container for fields. " + + " It provides support for any layouts and provides buffering interface for" + + " easy connection of commit- and discard buttons. All the form" + + " fields can be customized by adding validators, setting captions and icons, " + + " setting immediateness, etc. Also direct mechanism for replacing existing" + + " fields with selections is given.</p>" + + " <p>Form provides customizable editor for classes implementing" + + " Item-interface. Also the form itself" + + " implements this interface for easier connectivity to other items." + + " To use the form as editor for an item, just connect the item to" + + " form.After the item has been connected to the form," + + " the automatically created fields can be customized and new fields can" + + " be added. If you need to connect a class that does not implement" + + " Item-interface, most properties of any" + + " class following bean pattern, can be accessed trough" + + " BeanItem.</p>" + + " <p>The best example of Form usage is the this feature browser itself; " + + " all the Property-panels in demos are composed of Form-components.</p>"; + } + + + protected String getTitle() { + return "Form"; + } + + protected String getImage() { + return "form.jpg"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureFrameWindow.java b/src/com/itmill/toolkit/demo/features/FeatureFrameWindow.java new file mode 100644 index 0000000000..bf78a5e7ae --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureFrameWindow.java @@ -0,0 +1,171 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.util.HashMap; +import java.util.List; + +import com.itmill.toolkit.ui.*; +import com.itmill.toolkit.ui.Button.ClickEvent; + +public class FeatureFrameWindow + extends Feature + implements Button.ClickListener { + + private Button addButton = new Button("Add to application", this, "addWin"); + private Button removeButton = + new Button("Remove from application", this, "delWin"); + private FrameWindow demoWindow; + private HashMap windowToFramesetMap = new HashMap(); + private int count = 0; + + protected Component getDemoComponent() { + OrderedLayout l = new OrderedLayout(); + demoWindow = new FrameWindow("Feature Test Window"); + demoWindow.getFrameset().newFrame( + createFrame(demoWindow.getFrameset())); + + // Example panel + Panel show = new Panel("Test Window Control"); + ((OrderedLayout) show.getLayout()).setOrientation( + OrderedLayout.ORIENTATION_HORIZONTAL); + show.addComponent(addButton); + show.addComponent(removeButton); + updateWinStatus(); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(demoWindow); + p.dependsOn(addButton); + p.dependsOn(removeButton); + Form ap = + p.createBeanPropertySet( + new String[] { "width", "height", "name", "border", "theme" }); + ap.replaceWithSelect( + "border", + new Object[] { + new Integer(Window.BORDER_DEFAULT), + new Integer(Window.BORDER_NONE), + new Integer(Window.BORDER_MINIMAL)}, + new Object[] { "Default", "None", "Minimal" }); + + p.addProperties("FrameWindow Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getDescriptionXHTML() { + return "<p>This component implements a window that contains a hierarchical set of frames. " + + "Each frame can contain a web-page, window or a set of frames that divides the space " + + "horizontally or vertically.</p>"; + } + + protected String getExampleSrc() { + return "FrameWindow f = new FrameWindow(\"Frame example\");\n" + + "f.getFrameset().newFrame(window);\n" + + "f.getFrameset().newFrame(resource,\"targetName\");\n"; + } + + protected String getImage() { + return "framewindow.jpg"; + } + + protected String getTitle() { + return "FrameWindow"; + } + + public void addWin() { + getApplication().addWindow(demoWindow); + updateWinStatus(); + } + + public void delWin() { + getApplication().removeWindow(demoWindow); + updateWinStatus(); + } + + private void updateWinStatus() { + if (demoWindow.getApplication() == null) { + addButton.setEnabled(true); + removeButton.setEnabled(false); + } else { + addButton.setEnabled(false); + removeButton.setEnabled(true); + } + } + + public void buttonClick(ClickEvent event) { + + if (event.getButton().getCaption().equals("Remove")) { + Window w = event.getButton().getWindow(); + FrameWindow.Frameset fs = + (FrameWindow.Frameset) windowToFramesetMap.get(w); + if (fs == demoWindow.getFrameset() && fs.size() <= 1) { + // Do not remove the last frame + } else if (fs.size() > 1) { + fs.removeFrame(fs.getFrame(w.getName())); + windowToFramesetMap.remove(w); + } else { + FrameWindow.Frameset p = fs.getParentFrameset(); + if (p != demoWindow.getFrameset() || p.size() > 1) + p.removeFrame(fs); + if (p.size() == 0) + p.newFrame(createFrame(p)); + } + } + + if (event.getButton().getCaption().equals("Split")) { + Window w = event.getButton().getWindow(); + FrameWindow.Frameset fs = + (FrameWindow.Frameset) windowToFramesetMap.get(w); + int index = 0; + List l = fs.getFrames(); + while (index < l.size() && fs.getFrame(index).getWindow() != w) + index++; + fs.removeFrame(fs.getFrame(w.getName())); + windowToFramesetMap.remove(w); + if (index > fs.size()) + index = fs.size(); + fs = fs.newFrameset((Math.random() > 0.5), index); + for (int i = 2 + (int) (Math.random() * 2.0); i > 0; i--) + fs.newFrame(createFrame(fs)); + } + } + + private Window createFrame(FrameWindow.Frameset fs) { + Window w = new Window(); + w.addComponent( + new Label("<b>Frame: " + (++count) + "</b>", Label.CONTENT_UIDL)); + w.addComponent(new Button("Split", this)); + w.addComponent(new Button("Remove", this)); + windowToFramesetMap.put(w, fs); + return w; + } +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureGridLayout.java b/src/com/itmill/toolkit/demo/features/FeatureGridLayout.java new file mode 100644 index 0000000000..6f1499bc6b --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureGridLayout.java @@ -0,0 +1,92 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.util.Date; + +import com.itmill.toolkit.ui.*; + +public class FeatureGridLayout extends Feature { + + public FeatureGridLayout() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("GridLayout component"); + GridLayout gl = new GridLayout(3, 3); + DateField cal = new DateField("Test component 1",new Date()); + cal.setStyle("calendar"); + gl.addComponent(cal, 1,0,2,1); + for (int i = 2; i < 7; i++) + gl.addComponent(new TextField("Test component " + i)); + show.addComponent(gl); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(gl); + Form ap = p.createBeanPropertySet(new String[] { "width", "height" }); + ap.addField("new line", new Button("New Line", gl, "newLine")); + ap.addField("space", new Button("Space", gl, "space")); + p.addProperties("GridLayout Features", ap); + p.getField("height").dependsOn(p.getField("add component")); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "GridLayout gl = new GridLayout(2,2);\n" + + "gl.addComponent(new Label(\"Label 1 in GridLayout\"));\n" + + "gl.addComponent(new Label(\"Label 2 in GridLayout\"));\n" + + "gl.addComponent(new Label(\"Label 3 in GridLayout\"));\n" + + "gl.addComponent(new Label(\"Label 4 in GridLayout\"));\n"; + } + /** + * @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML() + */ + protected String getDescriptionXHTML() { + return "<p>This feature provides a container that lays out components " + + "into a grid of given width and height.</p>" + + "<p>On the demo tab you can try out how the different " + + "properties affect the presentation of the component.</p>"; + } + + protected String getImage() { + return "gridlayout.jpg"; + } + + protected String getTitle() { + return "GridLayout"; + } +}
\ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/features/FeatureItems.java b/src/com/itmill/toolkit/demo/features/FeatureItems.java new file mode 100644 index 0000000000..c089c70b3e --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureItems.java @@ -0,0 +1,55 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +public class FeatureItems extends Feature { + + protected String getTitle() { + return "Item Data Model"; + } + + protected String getDescriptionXHTML() { + return "<p>Item is an object, which contains a set of named " + + "properties. Each property is identified by an " + + "id and a reference to the property can be queried from the Item. " + + "Item defines inner-interfaces for maintaining the item property " + + "set and listening the item property set changes.</p>" + + "<p>Items generally represent objects in the object-oriented " + + "model, but with the exception that they are configurable " + + "and provide an event mechanism. The simplest way of utilizing " + + "Item interface is to use existing Item implementations. " + + "Provided utility classes include configurable property set," + + " bean to item adapter and Form UI component.</p>"; + } + + protected String getImage() { + return "items.jpg"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureLabel.java b/src/com/itmill/toolkit/demo/features/FeatureLabel.java new file mode 100644 index 0000000000..2c7f9fc826 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureLabel.java @@ -0,0 +1,101 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeatureLabel extends Feature { + + public FeatureLabel() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("Label component"); + Label lab = new Label("Label text"); + show.addComponent(lab); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(lab); + Form ap = + p.createBeanPropertySet(new String[] { "contentMode", "value" }); + ap.replaceWithSelect( + "contentMode", + new Object[] { + new Integer(Label.CONTENT_PREFORMATTED), + new Integer(Label.CONTENT_TEXT), + new Integer(Label.CONTENT_UIDL), + new Integer(Label.CONTENT_XHTML), + new Integer(Label.CONTENT_XML)}, + new Object[] { + "Preformatted", + "Text", + "UIDL (Must be valid)", + "XHTML Fragment(Must be valid)", + "XML (Subtree with namespace)" }); + p.addProperties("Label Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "Label l = new Label(\"Caption\");\n"; + } + /** + * @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML() + */ + protected String getDescriptionXHTML() { + return "Labels components are for captions and plain text. " + + "By default, it is a light-weight component for presenting " + + "text content in application, but it can be also used to present " + + "formatted information and even XML." + + "<br /><br />" + + "Label can also be directly associated with data property to display " + + "information from different data sources automatically. This makes it " + + "trivial to present the current user in the corner of applications main window. " + + "<br /><br />" + + "On the demo tab you can try out how the different properties affect " + + "the presentation of the component."; + } + + protected String getImage() { + return "label.jpg"; + } + + protected String getTitle() { + return "Label"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureLink.java b/src/com/itmill/toolkit/demo/features/FeatureLink.java new file mode 100644 index 0000000000..7b586c3666 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureLink.java @@ -0,0 +1,95 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.ui.*; + +public class FeatureLink extends Feature { + + public FeatureLink() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("Link component"); + Link lnk = + new Link( + "Link caption", + new ExternalResource("http://www.itmill.com")); + show.addComponent(lnk); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(lnk); + Form ap = + p.createBeanPropertySet( + new String[] { + "targetName", + "targetWidth", + "targetHeight", + "targetBorder" }); + ap.replaceWithSelect( + "targetBorder", + new Object[] { + new Integer(Link.TARGET_BORDER_DEFAULT), + new Integer(Link.TARGET_BORDER_MINIMAL), + new Integer(Link.TARGET_BORDER_NONE)}, + new Object[] { "Default", "Minimal", "None" }); + p.addProperties("Link Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "Link lnk = new Link(\"Link caption\",new ExternalResource(\"http://www.itmill.com\"));\n"; + } + + protected String getDescriptionXHTML() { + return "The link feature allows for making refences to both internal and external resources. " + + "The link can open the new resource in a new window, allowing for control of the newly " + + "opened windows attributes, such as size and border. " + + "<br /><br />" + + " For example you can create an application pop-up or create link to external resources."; + + } + + protected String getImage() { + return "link.jpg"; + } + + protected String getTitle() { + return "Link"; + } +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureOrderedLayout.java b/src/com/itmill/toolkit/demo/features/FeatureOrderedLayout.java new file mode 100644 index 0000000000..7a5acfefac --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureOrderedLayout.java @@ -0,0 +1,103 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeatureOrderedLayout extends Feature { + + public FeatureOrderedLayout() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("OrderedLayout component"); + OrderedLayout ol = new OrderedLayout(); + for (int i=1;i<5; i++) ol.addComponent(new TextField("Test component "+i)); + show.addComponent(ol); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(ol); + Form ap = p.createBeanPropertySet(new String[] { "orientation" }); + ap.replaceWithSelect( + "orientation", + new Object[] { + new Integer(OrderedLayout.ORIENTATION_HORIZONTAL), + new Integer(OrderedLayout.ORIENTATION_VERTICAL)}, + new Object[] { + "Horizontal", + "Vertical"}); + Select themes = (Select) p.getField("style"); + themes + .addItem("form") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("form"); + p.addProperties("OrderedLayout Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "OrderedLayout ol = new OrderedLayout(OrderedLayout.ORIENTATION_FLOW);\n" + + "ol.addComponent(new TextField(\"Textfield caption\"));\n" + + "ol.addComponent(new Label(\"Label\"));\n"; + + } + /** + * @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML() + */ + protected String getDescriptionXHTML() { + return "This feature provides a container for laying out components either " + + "vertically, horizontally or flowingly. The orientation may be changed " + + "during runtime. It also defines a special style for themes to implement called \"form\"" + + "that is used for input forms where the components are layed-out side-by-side " + + "with their captions." + + "<br/><br/>" + + "On the demo tab you can try out how the different properties " + + "affect the presentation of the component."; + } + + protected String getImage() { + return "orderedlayout.jpg"; + } + + protected String getTitle() { + return "OrderedLayout"; + } + +} + +/* This Millstone sample code is public domain. * + * For more information see www.millstone.org. */
\ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/features/FeaturePanel.java b/src/com/itmill/toolkit/demo/features/FeaturePanel.java new file mode 100644 index 0000000000..031eefaa61 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeaturePanel.java @@ -0,0 +1,91 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeaturePanel extends Feature { + + public FeaturePanel() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("Panel caption"); + show.addComponent(new Label("Label in Panel")); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(show); + Form ap = p.createBeanPropertySet(new String[] { "width", "height" }); + Select themes = (Select) p.getField("style"); + themes + .addItem("light") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("light"); + themes + .addItem("strong") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("strong"); + p.addProperties("Panel Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "Panel show = new Panel(\"Panel caption\");\n" + + "show.addComponent(new Label(\"Label in Panel\"));"; + + } + + protected String getDescriptionXHTML() { + return "The Panel is a container for other components, it usually draws a frame around it's "+ + "extremities and may have a caption to clarify the nature of the contained components purpose."+ + "A panel always contains firstly a layout onto which the actual contained components are added, "+ + "this layout may be switched on the fly. <br/><br/>"+ + "On the demo tab you can try out how the different properties "+ + "affect the presentation of the component."; + } + + + protected String getImage() { + return "panel.jpg"; + } + + protected String getTitle() { + return "Panel"; + } + +} + diff --git a/src/com/itmill/toolkit/demo/features/FeatureParameters.java b/src/com/itmill/toolkit/demo/features/FeatureParameters.java new file mode 100644 index 0000000000..9c5887f19f --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureParameters.java @@ -0,0 +1,160 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.net.URL; +import java.util.Iterator; +import java.util.Map; + +import com.itmill.toolkit.terminal.DownloadStream; +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.terminal.ParameterHandler; +import com.itmill.toolkit.terminal.URIHandler; +import com.itmill.toolkit.ui.*; + +public class FeatureParameters + extends Feature + implements URIHandler, ParameterHandler { + + private Label context = new Label(); + private Label relative = new Label(); + private Table params = new Table(); + + public FeatureParameters() { + super(); + params.addContainerProperty("Values", String.class, ""); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + Label info = + new Label( + "To test this feature, try to " + + "add some get parameters to URL. For example if you have " + + "the feature browser installed in your local host, try url: "); + info.setCaption("Usage info"); + l.addComponent(info); + try { + URL u1 = new URL(getApplication().getURL(),"test/uri?test=1&test=2"); + URL u2 = new URL(getApplication().getURL(),"foo/bar?mary=john&count=3"); + + l.addComponent( + new Link(u1.toString(),new ExternalResource(u1))); + l.addComponent(new Label("Or this: ")); + l.addComponent( + new Link(u2.toString(),new ExternalResource(u2))); + } catch (Exception e) { + System.out.println( + "Couldn't get hostname for this machine: " + e.toString()); + e.printStackTrace(); + } + + // URI + Panel p1 = new Panel("URI Handler"); + context.setCaption("Last URI handler context"); + p1.addComponent(context); + relative.setCaption("Last relative URI"); + p1.addComponent(relative); + l.addComponent(p1); + + // Parameters + Panel p2 = new Panel("Parameter Handler"); + params.setCaption("Last parameters"); + params.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); + params.setRowHeaderMode(Table.ROW_HEADER_MODE_ID); + p2.addComponent(params); + l.addComponent(p2); + + return l; + } + + protected String getDescriptionXHTML() { + return "This is a demonstration of how URL parameters can be recieved and handled." + + "Parameters and URL:s can be received trough the windows by registering " + + "URIHandler and ParameterHandler classes window."; + } + + protected String getImage() { + return "parameters.jpg"; + } + + protected String getTitle() { + return "Parameters"; + } + + /** Add URI and parametes handlers to window. + * @see com.itmill.toolkit.ui.Component#attach() + */ + public void attach() { + super.attach(); + getWindow().addURIHandler(this); + getWindow().addParameterHandler(this); + } + + /** Remove all handlers from window + * @see com.itmill.toolkit.ui.Component#detach() + */ + public void detach() { + super.detach(); + getWindow().removeURIHandler(this); + getWindow().removeParameterHandler(this); + } + + /** Update URI + * @see com.itmill.toolkit.terminal.URIHandler#handleURI(URL, String) + */ + public DownloadStream handleURI(URL context, String relativeUri) { + this.context.setValue(context.toString()); + this.relative.setValue(relativeUri); + return null; + } + + /** Update parameters table + * @see com.itmill.toolkit.terminal.ParameterHandler#handleParameters(Map) + */ + public void handleParameters(Map parameters) { + params.removeAllItems(); + for (Iterator i = parameters.keySet().iterator(); i.hasNext();) { + String name = (String) i.next(); + String[] values = (String[]) parameters.get(name); + String v = ""; + for (int j = 0; j < values.length; j++) { + if (v.length() > 0) + v += ", "; + v += "'" + values[j] + "'"; + } + params.addItem(new Object[] { v }, name); + } + } +} + +/* This Millstone sample code is public domain. * + * For more information see www.millstone.org. */
\ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/features/FeatureProperties.java b/src/com/itmill/toolkit/demo/features/FeatureProperties.java new file mode 100644 index 0000000000..52efc42489 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureProperties.java @@ -0,0 +1,70 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +public class FeatureProperties extends Feature { + + protected String getExampleSrc() { + return super.getExampleSrc(); + } + + protected String getTitle() { + return "Property Data Model"; + } + + protected String getDescriptionXHTML() { + return "<p>Millstone data model is one of the core concepts " + + "in the library and Property-interface is the base of that " + + "model. Property provides standardized API for a singe data object " + + "that can be getted and setted. A property is always typed, but can optionally " + + "support data type conversions. Optionally properties can provide " + + "value change events for following the state changes.</p>" + + "<p>The most important function of the Property as well as other " + + "data models is to connect classes implementing the interface directly to " + + "editor and viewer classes. Typically this is used to connect different " + + "data sources to UI components for editing and viewing their contents.</p>" + + "<p>Properties can be utilized either by implementing the interface " + + "or by using some of the existing property implementations. Millstone " + + "includes Property interface implementations for " + + "arbitrary function pairs or Bean-properties as well as simple object " + + "properties.</p>" + + "<p>Many of the UI components also imlement Property interface and allow " + + "setting of other components as their data-source. These UI-components " + + "include TextField, DateField, Select, Table, Button, " + + "Label and Tree.</p>"; + } + + /** + * @see com.itmill.toolkit.demo.features.Feature#getImage() + */ + protected String getImage() { + return "properties.jpg"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureSelect.java b/src/com/itmill/toolkit/demo/features/FeatureSelect.java new file mode 100644 index 0000000000..6b0e4087d2 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureSelect.java @@ -0,0 +1,98 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeatureSelect extends Feature { + + public FeatureSelect() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("Select component"); + Select s = new Select("Select Car"); + s.addItem("Audi"); + s.addItem("BMW"); + s.addItem("Chrysler"); + s.addItem("Volvo"); + show.addComponent(s); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(s); + Select themes = (Select) p.getField("style"); + themes + .addItem("optiongroup") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("optiongroup"); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "Select s = new Select(\"Select Car\");\n"+ + "s.addItem(\"Audi\");\n"+ + "s.addItem(\"BMW\");\n"+ + "s.addItem(\"Chrysler\");\n"+ + "s.addItem(\"Volvo\");\n"; + + } + /** + * @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML() + */ + protected String getDescriptionXHTML() { + return "The select component combines two different modes of item selection. " + + "Firstly it presents the single selection mode, which is usually represented as " + + "either a drop-down menu or a radio-group of switches, secondly it " + + "allows for multiple item selection, this is usually represented as either a " + + "listbox of selectable items or as a group of checkboxes." + + "<br/><br/>" + + "Data source can be associated both with selected item and the list of selections. "+ + "This way you can easily present a selection based on items specified elsewhere in application. " + + "<br/><br/>" + + "On the demo tab you can try out how the different properties affect the" + + " presentation of the component."; + } + + protected String getImage() { + return "select.jpg"; + } + + protected String getTitle() { + return "Select"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureServerEvents.java b/src/com/itmill/toolkit/demo/features/FeatureServerEvents.java new file mode 100644 index 0000000000..cdf371a91d --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureServerEvents.java @@ -0,0 +1,132 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.net.MalformedURLException; +import java.net.URL; + +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.ui.*; + +public class FeatureServerEvents extends Feature { + + protected String getTitle() { + return "Server Events"; + } + + protected Component getDemoComponent() { + OrderedLayout l = new OrderedLayout(); + + l.addComponent( + new Label( + "<h3>Multiplayer GO-Game</h3><p>For demonstration, see GO-Game example application. The application implements a " + + "multi-player board game, where the moved by one player are immediately reflected to " + + "another player.</p>" + + "<p>Updating another players screen is totally automatic, and the programmed " + + "does not need to be avare when the refresh requests are sent to screen by the server. In " + + "web adapter the requests are passed through open HTTP-connection as java-script fragments " + + "that update the windows that need repainting.</p>", + Label.CONTENT_UIDL)); + + URL goUrl = null; + try { + goUrl = new URL(getApplication().getURL(), "../go/"); + } catch (MalformedURLException e) { + } + + if (goUrl != null) { + Link link = new Link("Start GO-Game", new ExternalResource(goUrl)); + link.setTargetName("gogame"); + link.setTargetBorder(Link.TARGET_BORDER_NONE); + l.addComponent(link); + } + + l.addComponent( + new Label( + "<h3>Chat example</h3><p>For some purposes it might be better to create your own "+ + "stream. The easiest way of creating a continuous stream for "+ + "simple purposes is to use StreamResource-class. See chat "+ + "example below, how this technique can be used for creation "+ + "of simple chat program.</p>", + Label.CONTENT_UIDL)); + + URL chatUrl = null; + try { + chatUrl = new URL(getApplication().getURL(), "../chat/"); + } catch (MalformedURLException e) { + } + + if (goUrl != null) { + Link link = new Link("Start chat", new ExternalResource(chatUrl)); + link.setTargetName("chat"); + link.setTargetBorder(Link.TARGET_BORDER_NONE); + l.addComponent(link); + } + + return l; + } + + protected String getDescriptionXHTML() { + return "<p>Millstone component framework supports both transactional and " + + "continuous terminals. This means that either the events from the " + + "terminal are sent together as transactions or the events are " + + "passed immediately when the user initiates them through the user " + + "interface. </p>" + + "<p>WebAdapter converts the Millstone applications to web-environment " + + "by transferring the events as HTTP-parameters and drawing the " + + "pages after the components have received and handled the events. " + + "In the web-environment the web browser is always the active party that " + + "starts the transaction. This is problematic when the server should " + + "notify the user about changes without HTTP-request initiated by the " + + "user.</p>" + + "<h3>WebAdapter Solution</h3>" + + "<p>Millstone solves the problem by combining component frameworks " + + "ability to automatically notify terminal adapter about all visual " + + "changes to HTTP-protocols ability to handle very long and slow " + + "page downloads. WebAdapter provides the web browser with " + + "possibility to keep special server command stream open all the time. " + + "All the visual updates that happen in components causes the " + + "WebAdapter to automatically creates JavaScript that updates the " + + "corresponding web browser window and to send the script immediately " + + "to browser for execution.</p>" + + "<p>The mechanism is fairly complicated, but using the mechanism in " + + "any Millstone application is trivial. Application just needs " + + "to make sure that WebBrowser opens a hidden iframe to location: " + + "<code>?SERVER_COMMANDS=1</code>.</p>" + + "<p>See the example of the usage on Demo-tab to get better understanding " + + "of the mechanism. If you read the example's source code, you will notice that " + + "the program does not contain any support for sending events to client, as " + + "it is completely automatic.</p>"; + } + + protected String getImage() { + return "serverevents.jpg"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureTabSheet.java b/src/com/itmill/toolkit/demo/features/FeatureTabSheet.java new file mode 100644 index 0000000000..ef7ff5b7d7 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureTabSheet.java @@ -0,0 +1,83 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeatureTabSheet extends Feature { + + public FeatureTabSheet() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("TabSheet component"); + + TabSheet ts = new TabSheet(); + ts.addTab(new Label("Tab 1 Body"),"Tab 1 caption",null); + ts.addTab(new Label("Tab 2 Body"),"Tab 2 caption",null); + ts.addTab(new Label("Tab 3 Body"),"Tab 3 caption",null); + + show.addComponent(ts); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(ts); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "TabSheet ts = new TabSheet();"+ + "ts.addTab(new Label(\"Tab 1 Body\"),\"Tab 1 caption\",null);"+ + "ts.addTab(new Label(\"Tab 2 Body\"),\"Tab 2 caption\",null);"+ + "ts.addTab(new Label(\"Tab 3 Body\"),\"Tab 3 caption\",null);"; + } + + protected String getDescriptionXHTML() { + return "A multicomponent container with tabs for switching between them.<br/>"+ + "In the normal case, one would place a layout component on each tab.<br/><br />"+ + "On the demo tab you can try out how the different properties affect "+ + "the presentation of the component."; + } + + protected String getImage() { + return "tabsheet.jpg"; + } + + protected String getTitle() { + return "TabSheet"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureTable.java b/src/com/itmill/toolkit/demo/features/FeatureTable.java new file mode 100644 index 0000000000..013031dabb --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureTable.java @@ -0,0 +1,231 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.event.Action; +import com.itmill.toolkit.ui.*; + +public class FeatureTable extends Feature implements Action.Handler { + + private static final String[] firstnames = + new String[] { + "John", + "Mary", + "Joe", + "Sarah", + "Jeff", + "Jane", + "Peter", + "Marc", + "Josie", + "Linus" }; + private static final String[] lastnames = + new String[] { + "Torvalds", + "Smith", + "Jones", + "Beck", + "Sheridan", + "Picard", + "Hill", + "Fielding", + "Einstein" }; + private static final String[] eyecolors = + new String[] { "Blue", "Green", "Brown" }; + private static final String[] haircolors = + new String[] { "Brown", "Black", "Red", "Blonde" }; + + private Table t; + private boolean actionsActive = false; + private Button actionHandlerSwitch = + new Button("Activate actions", this, "toggleActions"); + + public void toggleActions() { + if (actionsActive) { + t.removeActionHandler(this); + actionsActive = false; + actionHandlerSwitch.setCaption("Activate Actions"); + } else { + t.addActionHandler(this); + actionsActive = true; + actionHandlerSwitch.setCaption("Deactivate Actions"); + } + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Sample table + t = new Table("Most Wanted Persons List"); + t.setPageLength(10); + l.addComponent(t); + + // Add columns to table + t.addContainerProperty("Firstname", String.class, ""); + t.addContainerProperty("Lastname", String.class, ""); + t.addContainerProperty("Age", String.class, ""); + t.addContainerProperty("Eyecolor", String.class, ""); + t.addContainerProperty("Haircolor", String.class, ""); + + // Add random rows to table + for (int j = 0; j < 50; j++) { + Object id = t.addItem( + new Object[] { + firstnames[(int) (Math.random() * (firstnames.length-1))], + lastnames[(int) (Math.random() * (lastnames.length-1))], + new Integer((int) (Math.random() * 80)), + eyecolors[(int) (Math.random() * 3)], + haircolors[(int) (Math.random() * 4)] }, + new Integer(j)); + t.setItemIcon(id,getSampleIcon()); + } + + // Actions + l.addComponent(this.actionHandlerSwitch); + + // Properties + PropertyPanel p = new PropertyPanel(t); + Form ap = + p.createBeanPropertySet( + new String[] { + "pageLength", + "rowHeaderMode", + "selectable", + "columnHeaderMode", + "columnCollapsingAllowed", + "columnReorderingAllowed"}); + ap.replaceWithSelect( + "columnHeaderMode", + new Object[] { + new Integer(Table.COLUMN_HEADER_MODE_EXPLICIT), + new Integer(Table.COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID), + new Integer(Table.COLUMN_HEADER_MODE_HIDDEN), + new Integer(Table.COLUMN_HEADER_MODE_ID)}, + new Object[] { + "Explicit", + "Explicit defaults ID", + "Hidden", + "ID" }); + ap.replaceWithSelect( + "rowHeaderMode", + new Object[] { + new Integer(Table.ROW_HEADER_MODE_EXPLICIT), + new Integer(Table.ROW_HEADER_MODE_EXPLICIT_DEFAULTS_ID), + new Integer(Table.ROW_HEADER_MODE_HIDDEN), + new Integer(Table.ROW_HEADER_MODE_ICON_ONLY), + new Integer(Table.ROW_HEADER_MODE_ID), + new Integer(Table.ROW_HEADER_MODE_INDEX), + new Integer(Table.ROW_HEADER_MODE_ITEM), + new Integer(Table.ROW_HEADER_MODE_PROPERTY)}, + new Object[] { + "Explicit", + "Explicit defaults ID", + "Hidden", + "Icon only", + "ID", + "Index", + "Item", + "Property" }); + Select themes = (Select) p.getField("style"); + themes + .addItem("list") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("list"); + p.addProperties("Table Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "// Sample table\n" + + "t = new Table(\"Most Wanted Persons List\");\n" + + "t.setPageLength(10);\n\n" + + "// Add columns to table\n" + + "t.addContainerProperty(\"Firstname\", String.class, \"\");\n" + + "t.addContainerProperty(\"Lastname\", String.class, \"\");\n" + + "t.addContainerProperty(\"Age\", String.class, \"\");\n" + + "t.addContainerProperty(\"Eyecolor\", String.class, \"\");\n" + + "t.addContainerProperty(\"Haircolor\", String.class, \"\");\n\n" + + "// Add random rows to table\n" + + "for (int j = 0; j < 50; j++) {\n" + + " t.addItem(\n" + + " new Object[] {\n" + + " firstnames[(int) (Math.random() * 9)],\n" + + " lastnames[(int) (Math.random() * 9)],\n" + + " new Integer((int) (Math.random() * 80)),\n" + + " eyecolors[(int) (Math.random() * 3)],\n" + + " haircolors[(int) (Math.random() * 4)] },\n" + + " new Integer(j));\n" + + "}\n"; + } + + protected String getDescriptionXHTML() { + + return "<p>The Table component is designed for displaying large volumes of tabular data, " + + "in multiple pages whenever needed.</p> " + + "<p>Selection of the displayed data is supported both in selecting exclusively one row " + + "or multiple rows at the same time. For each row, there may be a set of actions associated, " + + "depending on the theme these actions may be displayed either as a drop-down " + + "menu for each row or a set of command buttons.</p><p>" + + "Table may be connected to any datasource implementing the <code>Container</code> interface." + + "This way data found in external datasources can be directly presented in the table component." + + "</p><p>" + + "Table implements a number of features and you can test most of them in the table demo tab.</p>"; + } + + protected String getImage() { + return "table.jpg"; + } + + protected String getTitle() { + return "Table"; + } + + private Action ACTION1 = new Action("Action 1"); + private Action ACTION2 = new Action("Action 2"); + private Action ACTION3 = new Action("Action 3"); + + private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 }; + + public Action[] getActions(Object target, Object sender) { + return actions; + } + + public void handleAction(Action action, Object sender, Object target) { + t.setDescription( + "Last action clicked was '" + + action.getCaption() + + "' on item '" + + t.getItem(target).toString() + + "'"); + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureTextField.java b/src/com/itmill/toolkit/demo/features/FeatureTextField.java new file mode 100644 index 0000000000..68766ea57d --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureTextField.java @@ -0,0 +1,97 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeatureTextField extends Feature { + + public FeatureTextField() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Test component + TextField tf = new TextField("Caption"); + Panel test = new Panel("TextField Component Demo"); + test.addComponent(tf); + l.addComponent(test); + + // Properties + PropertyPanel p = new PropertyPanel(tf); + l.addComponent(p); + Form f = + p.createBeanPropertySet( + new String[] { + "columns", + "rows", + "wordwrap", + "writeThrough", + "readThrough", + "nullRepresentation", + "nullSettingAllowed", + "secret" }); + p.addProperties("Text field properties", f); + + return l; + } + + protected String getExampleSrc() { + return "TextField tf = new TextField(\"Caption\");\n" + + "tf.setValue(\"Contents\");"; + } + /** + * @see com.itmill.toolkit.demo.features.Feature#getDescriptionXHTML() + */ + protected String getDescriptionXHTML() { + return "<p>Millstone combines the logic of both the single line text-entry field and the multi-line " + + "text-area into one component. " + + "As with all Data-components of Millstone, the Textfield can also be bound to an " + + "underlying data source, both directly or in a buffered (asynchronous) " + + "mode. In buffered mode its background color will change to indicate " + + "that the value has changed but is not committed.</p>" + + "<p>Furthermore a validators may be bound to the component to " + + "check and validate the given input before it is actually commited." + + "</p>" + + "<p>On the demo tab you can try out how the different properties affect the " + + "presentation of the component.</p>"; + } + + protected String getImage() { + return "textfield.gif"; + } + + protected String getTitle() { + return "TextField"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureTree.java b/src/com/itmill/toolkit/demo/features/FeatureTree.java new file mode 100644 index 0000000000..b832655772 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureTree.java @@ -0,0 +1,206 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.util.Iterator; + +import com.itmill.toolkit.event.Action; +import com.itmill.toolkit.ui.*; + +public class FeatureTree extends Feature implements Action.Handler { + + private static final String[] firstnames = + new String[] { + "John", + "Mary", + "Joe", + "Sarah", + "Jeff", + "Jane", + "Peter", + "Marc", + "Josie", + "Linus" }; + private static final String[] lastnames = + new String[] { + "Torvalds", + "Smith", + "Jones", + "Beck", + "Sheridan", + "Picard", + "Hill", + "Fielding", + "Einstein" }; + + private Tree t; + + private boolean actionsActive = false; + private Button actionHandlerSwitch = + new Button("Activate actions", this, "toggleActions"); + + public FeatureTree() { + super(); + } + + public void toggleActions() { + if (actionsActive) { + t.removeActionHandler(this); + actionsActive = false; + actionHandlerSwitch.setCaption("Activate Actions"); + } else { + t.addActionHandler(this); + actionsActive = true; + actionHandlerSwitch.setCaption("Deactivate Actions"); + } + } + + public void expandAll() { + for (Iterator i = t.rootItemIds().iterator();i.hasNext();) { + t.expandItemsRecursively(i.next()); + } + } + + public void collapseAll() { + for (Iterator i = t.rootItemIds().iterator();i.hasNext();) { + t.collapseItemsRecursively(i.next()); + } + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Create names + Panel show = new Panel("Tree component"); + String[] names = new String[100]; + for (int i = 0; i < names.length; i++) + names[i] = + firstnames[(int) (Math.random() * (firstnames.length - 1))] + + " " + + lastnames[(int) (Math.random() * (lastnames.length - 1))]; + + // Create tree + t = new Tree("Family Tree"); + for (int i = 0; i < 100; i++) { + t.addItem(names[i]); + String parent = names[(int) (Math.random() * (names.length - 1))]; + if (t.containsId(parent)) + t.setParent(names[i], parent); + } + + // Forbid childless people to have children (makes them leaves) + for (int i = 0; i < 100; i++) + if (!t.hasChildren(names[i])) + t.setChildrenAllowed(names[i], false); + + show.addComponent(t); + l.addComponent(show); + + // Actions + l.addComponent(this.actionHandlerSwitch); + + // Expand and Collapse buttons + l.addComponent(new Button("Expand All",this,"expandAll")); + l.addComponent(new Button("Collapse All",this,"collapseAll")); + + // Properties + PropertyPanel p = new PropertyPanel(t); + Form ap = p.createBeanPropertySet(new String[] { "selectable" }); + Select themes = (Select) p.getField("style"); + themes + .addItem("menu") + .getItemProperty(themes.getItemCaptionPropertyId()) + .setValue("menu"); + p.addProperties("Tree Properties", ap); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "// Create tree\n" + + "t = new Tree(\"Family Tree\");\n" + + "for (int i = 0; i < 100; i++) {\n" + + " t.addItem(names[i]);\n" + + " String parent = names[(int) (Math.random() * (names.length - 1))];\n" + + " if (t.containsId(parent)) \n" + + " t.setParent(names[i],parent);\n" + + "}\n\n" + + "// Forbid childless people to have children (makes them leaves)\n" + + "for (int i = 0; i < 100; i++)\n" + + " if (!t.hasChildren(names[i]))\n" + + " t.setChildrenAllowed(names[i], false);\n"; + } + + protected String getDescriptionXHTML() { + return "<p>A tree is a natural way to represent datasets that have" + + " hierarchical relationships, such as filesystems, message " + + "threads or... family trees. Millstone features a versatile " + + "and powerful Tree component that works much like the tree components " + + "of most modern operating systems. </p>" + + "<p>The most prominent use of the Tree component is to " + + "use it for displaying a hierachical menu, like the " + + "menu on the left side of the screen for instance " + + "or to display filesystems or other hierarchical datasets.</p>" + + "<p>The tree component uses <code>Container</code> " + + "datasources much like the Table component, " + + "with the addition that it also utilizes the hierarchy " + + "information maintained by the container. </p><p>On " + + "the demo tab you can try out how the different properties " + + "affect the presentation of the tree component.</p>"; + } + + protected String getImage() { + return "tree.jpg"; + } + + protected String getTitle() { + return "Tree"; + } + + private Action ACTION1 = new Action("Action 1"); + private Action ACTION2 = new Action("Action 2"); + private Action ACTION3 = new Action("Action 3"); + + private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 }; + + public Action[] getActions(Object target, Object sender) { + return actions; + } + + public void handleAction(Action action, Object sender, Object target) { + t.setDescription( + "Last action clicked was '" + + action.getCaption() + + "' on item '" + + target + + "'"); + } +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureUpload.java b/src/com/itmill/toolkit/demo/features/FeatureUpload.java new file mode 100644 index 0000000000..64d89cfb12 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureUpload.java @@ -0,0 +1,179 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +import com.itmill.toolkit.terminal.StreamResource; +import com.itmill.toolkit.ui.Component; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Link; +import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Upload; +import com.itmill.toolkit.ui.Upload.FinishedEvent; + +public class FeatureUpload + extends Feature + implements Upload.FinishedListener { + + Buffer buffer = new Buffer(); + + Panel status = new Panel("Uploaded file:"); + + public FeatureUpload() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + + // Example panel + Panel show = new Panel("Upload component"); + + Upload up = new Upload("Upload a file:", buffer); + up.addListener(this); + + show.addComponent(up); + status.setVisible(false); + l.addComponent(status); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(up); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "Upload u = new Upload(\"Upload a file:\", uploadReceiver);\n\n" + + "public class uploadReceiver \n" + + "implements Upload.receiver, Upload.FinishedListener { \n" + + "\n" + + " java.io.File file;\n" + + " java.io.FileOutputStream fos;\n" + + " public uploadReceiver() {\n" + + " }"; + + } + + protected String getDescriptionXHTML() { + return "This demonstrates the use of the Upload component together with the Link component. " + + "This implementation does not actually store the file to disk, it only keeps it in a buffer. " + + "The example given on the example-tab on the other hand stores the file to disk and binds the link to that file.<br/>" + + "<br/>On the demo tab you can try out how the different properties affect the presentation of the component."; + } + + protected String getImage() { + return "filetransfer.jpg"; + } + + protected String getTitle() { + return "Upload"; + } + + public void uploadFinished(FinishedEvent event) { + status.removeAllComponents(); + if (buffer.getStream() == null) + status.addComponent( + new Label("Upload finished, but output buffer is null!!")); + else { + status.addComponent( + new Label( + "<b>Name:</b> " + event.getFilename(), + Label.CONTENT_XHTML)); + status.addComponent( + new Label( + "<b>Mimetype:</b> " + event.getMIMEType(), + Label.CONTENT_XHTML)); + status.addComponent( + new Label( + "<b>Size:</b> " + event.getLength() + " bytes.", + Label.CONTENT_XHTML)); + + status.addComponent( + new Link( + "Download " + buffer.getFileName(), + new StreamResource( + buffer, + buffer.getFileName(), + getApplication()))); + + status.setVisible(true); + } + } + + public class Buffer + implements StreamResource.StreamSource, Upload.Receiver { + ByteArrayOutputStream outputBuffer = null; + String mimeType; + String fileName; + + public Buffer() { + + } + public InputStream getStream() { + if (outputBuffer == null) + return null; + return new ByteArrayInputStream(outputBuffer.toByteArray()); + } + + /** + * @see com.itmill.toolkit.ui.Upload.Receiver#receiveUpload(String, String) + */ + public OutputStream receiveUpload(String filename, String MIMEType) { + fileName = filename; + mimeType = MIMEType; + outputBuffer = new ByteArrayOutputStream(); + return outputBuffer; + } + + /** + * Returns the fileName. + * @return String + */ + public String getFileName() { + return fileName; + } + + /** + * Returns the mimeType. + * @return String + */ + public String getMimeType() { + return mimeType; + } + + } +}
\ No newline at end of file diff --git a/src/com/itmill/toolkit/demo/features/FeatureValidators.java b/src/com/itmill/toolkit/demo/features/FeatureValidators.java new file mode 100644 index 0000000000..ac19f02b48 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureValidators.java @@ -0,0 +1,60 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +public class FeatureValidators extends Feature { + + protected String getExampleSrc() { + return super.getExampleSrc(); + } + + protected String getTitle() { + return "Validators"; + } + + protected String getDescriptionXHTML() { + return + "<p>Millstone contains simple, yet powerful validation interface, "+ + "that consists of two parts: Validator and Validatable. Validator is "+ + "any class that can check validity of an Object. Validatable is "+ + "a class with configurable validation. "+ + "Validation errors are passed as special exceptions that implement "+ + "ErrorMessage interface. This way the validation errors can be "+ + "automatically added to components.</p>"+ + "<p>Utilities for simple string and null validation are provided, as "+ + "well as combinative validators. The validation interface can also "+ + "be easily implemented by the applications for more complex "+ + "validation needs.</p>"; + } + + protected String getImage() { + return "validators.gif"; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/FeatureWindow.java b/src/com/itmill/toolkit/demo/features/FeatureWindow.java new file mode 100644 index 0000000000..a08b94afdc --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeatureWindow.java @@ -0,0 +1,128 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeatureWindow extends Feature { + Button addButton = new Button("Add to application", this, "addWin"); + Button removeButton = new Button("Remove from application", this, "delWin"); + Window demoWindow; + Form windowProperties; + + public FeatureWindow() { + super(); + } + + protected Component getDemoComponent() { + + OrderedLayout l = new OrderedLayout(); + demoWindow = new Window("Feature Test Window"); + + // Example panel + Panel show = new Panel("Test Window Control"); + ((OrderedLayout) show.getLayout()).setOrientation( + OrderedLayout.ORIENTATION_HORIZONTAL); + show.addComponent(addButton); + show.addComponent(removeButton); + updateWinStatus(); + l.addComponent(show); + + // Properties + PropertyPanel p = new PropertyPanel(demoWindow); + p.dependsOn(addButton); + p.dependsOn(removeButton); + windowProperties = + p.createBeanPropertySet( + new String[] { + "width", + "height", + "name", + "border", + "theme", + "scrollable", + "scrollOffsetX", + "scrollOffsetY" }); + windowProperties.replaceWithSelect( + "border", + new Object[] { + new Integer(Window.BORDER_DEFAULT), + new Integer(Window.BORDER_NONE), + new Integer(Window.BORDER_MINIMAL)}, + new Object[] { "Default", "None", "Minimal" }); + p.addProperties("Window Properties", windowProperties); + l.addComponent(p); + + return l; + } + + protected String getExampleSrc() { + return "Window win = new Window();\n" + + "getApplication().addWindow(win);\n"; + + } + + protected String getDescriptionXHTML() { + return "The window support of Millstone allows for opening and closing windows, " + + "refreshing one window from another (for asynchronous terminals), " + + "resizing windows and scrolling window content. " + + "There are also a number of preset window border styles defined by " + + "this feature."; + } + + protected String getImage() { + return "window.jpg"; + } + + protected String getTitle() { + return "Window"; + } + + public void addWin() { + getApplication().addWindow(demoWindow); + windowProperties.getField("name").setReadOnly(true); + updateWinStatus(); + } + + public void delWin() { + getApplication().removeWindow(demoWindow); + windowProperties.getField("name").setReadOnly(false); + updateWinStatus(); + } + + private void updateWinStatus() { + if (demoWindow.getApplication() == null) { + addButton.setEnabled(true); + removeButton.setEnabled(false); + } else { + addButton.setEnabled(false); + removeButton.setEnabled(true); + } + } +} diff --git a/src/com/itmill/toolkit/demo/features/FeaturesApplication.java b/src/com/itmill/toolkit/demo/features/FeaturesApplication.java new file mode 100644 index 0000000000..a4951b8326 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/FeaturesApplication.java @@ -0,0 +1,41 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import com.itmill.toolkit.ui.*; + +public class FeaturesApplication + extends com.itmill.toolkit.Application { + + public void init() { + Window main = new Window("Millstone Features Tour"); + setMainWindow(main); + main.addComponent(new FeatureBrowser()); + } +} diff --git a/src/com/itmill/toolkit/demo/features/PropertyPanel.java b/src/com/itmill/toolkit/demo/features/PropertyPanel.java new file mode 100644 index 0000000000..b25c66f0f0 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/PropertyPanel.java @@ -0,0 +1,444 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; + +import com.itmill.toolkit.data.*; +import com.itmill.toolkit.data.util.*; +import com.itmill.toolkit.terminal.*; +import com.itmill.toolkit.ui.*; + +public class PropertyPanel + extends Panel + implements Button.ClickListener, Property.ValueChangeListener { + + private Select addComponent; + private OrderedLayout formsLayout = new OrderedLayout(); + private LinkedList forms = new LinkedList(); + private Button setButton = new Button("Set", this); + private Button discardButton = new Button("Discard changes", this); + private Button showAllProperties = + new Button("List of All Properties", this); + private Table allProperties = new Table(); + private Object objectToConfigure; + private BeanItem config; + protected static final int COLUMNS = 3; + + /** Contruct new property panel for configuring given object. */ + public PropertyPanel(Object objectToConfigure) { + super(); + + // Layout + setCaption("Properties"); + addComponent(formsLayout); + + // Target object + this.objectToConfigure = objectToConfigure; + config = new BeanItem(objectToConfigure); + + // Control buttons + OrderedLayout buttons = + new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + buttons.addComponent(setButton); + buttons.addComponent(discardButton); + addComponent(buttons); + + // Add default properties + addBasicComponentProperties(); + if (objectToConfigure instanceof Select) + addSelectProperties(); + if (objectToConfigure instanceof AbstractField + && !(objectToConfigure instanceof Table + || objectToConfigure instanceof Tree)) + addFieldProperties(); + if ((objectToConfigure instanceof AbstractComponentContainer) + && !(objectToConfigure instanceof FrameWindow)) + addComponentContainerProperties(); + + // The list of all properties + addComponent(showAllProperties); + showAllProperties.setSwitchMode(true); + allProperties.setVisible(false); + allProperties.addContainerProperty("Name", String.class, ""); + allProperties.addContainerProperty("Type", String.class, ""); + allProperties.addContainerProperty("R/W", String.class, ""); + allProperties.addContainerProperty("Demo", String.class, ""); + allProperties.setColumnAlignments( + new String[] { + Table.ALIGN_LEFT, + Table.ALIGN_LEFT, + Table.ALIGN_CENTER, + Table.ALIGN_CENTER }); + allProperties.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); + updatePropertyList(); + addComponent(allProperties); + } + + /** Add a formful of properties to property panel */ + public void addProperties(String propertySetCaption, Form properties) { + + // Create new panel containing the form + Panel p = new Panel(); + p.setWidth(600); + p.setCaption(propertySetCaption); + p.setStyle("light"); + p.addComponent(properties); + formsLayout.addComponent(p); + + // Setup buffering + setButton.dependsOn(properties); + discardButton.dependsOn(properties); + properties.setWriteThrough(false); + properties.setReadThrough(true); + + // Maintain property lists + forms.add(properties); + updatePropertyList(); + } + + /** Handle all button clicks for this panel */ + public void buttonClick(Button.ClickEvent event) { + + // Commit all changed on all forms + if (event.getButton() == setButton) { + for (Iterator i = forms.iterator(); i.hasNext();) + ((Form) i.next()).commit(); + } + + // Discard all changed on all forms + if (event.getButton() == discardButton) { + for (Iterator i = forms.iterator(); i.hasNext();) + ((Form) i.next()).discard(); + } + + // Show property list + if (event.getButton() == showAllProperties) { + allProperties.setVisible( + ((Boolean) showAllProperties.getValue()).booleanValue()); + } + } + + /** Recreate property list contents */ + public void updatePropertyList() { + + allProperties.removeAllItems(); + + // Collect demoed properties + HashSet listed = new HashSet(); + for (Iterator i = forms.iterator(); i.hasNext();) + listed.addAll(((Form) i.next()).getItemPropertyIds()); + + // Resolve all properties + BeanInfo info; + try { + info = Introspector.getBeanInfo(objectToConfigure.getClass()); + } catch (IntrospectionException e) { + throw new RuntimeException(e.toString()); + } + PropertyDescriptor[] pd = info.getPropertyDescriptors(); + + // Fill the table + for (int i = 0; i < pd.length; i++) { + allProperties.addItem( + new Object[] { + pd[i].getName(), + pd[i].getPropertyType().getName(), + (pd[i].getWriteMethod() == null ? "R" : "R/W"), + (listed.contains(pd[i].getName()) ? "x" : "")}, + pd[i]); + } + } + + /** Add basic properties implemented most often by abstract component */ + private void addBasicComponentProperties() { + + // Set of properties + Form set = + createBeanPropertySet( + new String[] { + "caption", + "icon", + "componentError", + "description", + "enabled", + "visible", + "style", + "readOnly", + "immediate" }); + + // Icon + set.replaceWithSelect( + "icon", + new Object[] { null, new ThemeResource("icon/files/file.gif")}, + new Object[] { "No icon", "Sample icon" }); + + // Component error + Throwable sampleException; + try { + throw new NullPointerException("sample exception"); + } catch (NullPointerException e) { + sampleException = e; + } + set.replaceWithSelect( + "componentError", + new Object[] { + null, + new UserError("Sample text error message."), + new UserError( + "<h3>Error message formatting</h3><p>Error messages can " + + "contain any UIDL formatting, like: <ul><li><b>Bold" + + "</b></li><li><i>Italic</i></li></ul></p>", + UserError.CONTENT_UIDL, + ErrorMessage.INFORMATION), + new SystemError( + "This is an example of exception error reposting", + sampleException)}, + new Object[] { + "No error", + "Sample text error", + "Sample Formatted error", + "Sample System Error" }); + + // Style + set + .replaceWithSelect( + "style", + new Object[] { null }, + new Object[] { "Default" }) + .setNewItemsAllowed(true); + + // Set up descriptions + set.getField("caption").setDescription( + "Component caption is the title of the component. Usage of the caption is optional and the " + + "exact behavior of the propery is defined by the component. Setting caption null " + + "or empty disables the caption."); + set.getField("enabled").setDescription( + "Enabled property controls the usage of the component. If the component is disabled (enabled=false)," + + " it can not receive any events from the terminal. In most cases it makes the usage" + + " of the component easier, if the component visually looks disbled (for example is grayed), " + + "when it can not be used."); + set.getField("icon").setDescription( + "Icon of the component selects the main icon of the component. The usage of the icon is identical " + + "to caption and in most components caption and icon are kept together. Icons can be " + + "loaded from any resources (see Terminal/Resources for more information). Some components " + + "contain more than just the captions icon. Those icons are controlled through their " + + "own properties."); + set.getField("visible").setDescription( + "Visibility property says if the component is renreded or not. Invisible components are implicitly " + + "disabled, as there is no visible user interface to send event."); + set.getField("description").setDescription( + "Description is designed to allow easy addition of short tooltips, like this. Like the caption," + + " setting description null or empty disables the description."); + set.getField("readOnly").setDescription( + "Those components that have internal state that can be written are settable to readOnly-mode," + + " where the object can only be read, not written."); + set.getField("componentError").setDescription( + "Millstone supports extensive error reporting. One part of the error reporting are component" + + " errors that can be controlled by the programmer. This example only contains couple of " + + "sample errors; to get the full picture, read browse ErrorMessage-interface implementors " + + "API documentation."); + set.getField("immediate").setDescription( + "Not all terminals can send the events immediately to server from all action. Web is the most " + + "typical environment where many events (like textfield changed) are not sent to server, " + + "before they are explicitly submitted. Setting immediate property true (by default this " + + "is false for most components), the programmer can assure that the application is" + + " notified as soon as possible about the value change in this component."); + set.getField("style").setDescription( + "Themes specify the overall looks of the user interface. In addition component can have a set of " + + "styles, that can be visually very different (like datefield calendar- and text-styles), " + + "but contain the same logical functionality. As a rule of thumb, theme specifies if a " + + "component is blue or yellow and style determines how the component is used."); + + // Add created fields to property panel + addProperties("Component Basics", set); + } + + /** Add properties for selecting */ + private void addSelectProperties() { + Form set = + createBeanPropertySet( + new String[] { "multiSelect", "newItemsAllowed" }); + addProperties("Select Properties", set); + + set.getField("multiSelect").setDescription( + "Specified if multiple items can be selected at once."); + set.getField("newItemsAllowed").setDescription( + "Select component (but not Tree or Table) can allow the user to directly " + + "add new items to set of options. The new items are constrained to be " + + "strings and thus feature only applies to simple lists."); + if (objectToConfigure instanceof Tree + || objectToConfigure instanceof Table) + set.removeItemProperty("newItemsAllowed"); + } + + /** Field special properties */ + private void addFieldProperties() { + Form set = new Form(new GridLayout(COLUMNS, 1)); + set.addField("focus", new Button("Focus", objectToConfigure, "focus")); + set.getField("focus").setDescription( + "Focus the cursor to this field. Not all " + + "components and/or terminals support this feature."); + addProperties("Field Features", set); + } + + /** Add and remove some miscellaneous example component to/from component container */ + private void addComponentContainerProperties() { + Form set = new Form(new GridLayout(COLUMNS, 1)); + + addComponent = new Select(); + addComponent.setImmediate(true); + addComponent.addItem("Add component to container"); + addComponent.setNullSelectionItemId("Add field"); + addComponent.addItem("Text field"); + addComponent.addItem("Time"); + addComponent.addItem("Option group"); + addComponent.addItem("Calendar"); + addComponent.addListener(this); + + set.addField("component adder", addComponent); + set.addField( + "remove all components", + new Button( + "Remove all components", + objectToConfigure, + "removeAllComponents")); + + addProperties("ComponentContainer Features", set); + } + + /** Value change listener for listening selections */ + public void valueChange(Property.ValueChangeEvent event) { + + // Adding components to component container + if (event.getProperty() == addComponent) { + String value = (String) addComponent.getValue(); + + if (value != null) { + // TextField component + if (value.equals("Text field")) + ( + ( + AbstractComponentContainer) objectToConfigure) + .addComponent( + new TextField("Test field")); + + // DateField time style + if (value.equals("Time")) { + DateField d = new DateField("Time", new Date()); + d.setDescription( + "This is a DateField-component with text-style"); + d.setResolution(DateField.RESOLUTION_MIN); + d.setStyle("text"); + ( + ( + AbstractComponentContainer) objectToConfigure) + .addComponent( + d); + } + + // Date field calendar style + if (value.equals("Calendar")) { + DateField c = new DateField("Calendar", new Date()); + c.setDescription( + "DateField-component with calendar-style and day-resolution"); + c.setStyle("calendar"); + c.setResolution(DateField.RESOLUTION_DAY); + ( + ( + AbstractComponentContainer) objectToConfigure) + .addComponent( + c); + } + + // Select option group style + if (value.equals("Option group")) { + Select s = new Select("Options"); + s.setDescription("Select-component with optiongroup-style"); + s.addItem("Linux"); + s.addItem("Windows"); + s.addItem("Solaris"); + s.addItem("Symbian"); + s.setStyle("optiongroup"); + + ( + ( + AbstractComponentContainer) objectToConfigure) + .addComponent( + s); + } + + addComponent.setValue(null); + } + } + } + + /** Helper function for creating forms from array of propety names. + */ + protected Form createBeanPropertySet(String names[]) { + + Form set = new Form(new GridLayout(COLUMNS, 1)); + + for (int i = 0; i < names.length; i++) { + Property p = config.getItemProperty(names[i]); + if (p != null) { + set.addItemProperty(names[i], p); + Field f = set.getField(names[i]); + if (f instanceof TextField) { + if (Integer.class.equals(p.getType())) + ((TextField)f).setColumns(4); + else { + ((TextField)f).setNullSettingAllowed(true); + ((TextField)f).setColumns(24); + } + } + } + } + + return set; + } + + /** Find a field from all forms */ + public Field getField(Object propertyId) { + for (Iterator i = forms.iterator(); i.hasNext();) { + Form f = (Form) i.next(); + Field af = f.getField(propertyId); + if (af != null) + return af; + } + return null; + } +} diff --git a/src/com/itmill/toolkit/demo/features/UIComponents.java b/src/com/itmill/toolkit/demo/features/UIComponents.java new file mode 100644 index 0000000000..f51776a0e2 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/UIComponents.java @@ -0,0 +1,45 @@ +/* ************************************************************************* + + IT Mill Toolkit + + Development of Browser User Intarfaces Made Easy + + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* + + This product is distributed under commercial license that can be found + from the product package on license/license.txt. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see license/licensing-guidelines.html + + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com + + ********************************************************************** */ + +package com.itmill.toolkit.demo.features; + +public class UIComponents extends Feature { + + protected String getDescriptionXHTML() { + return ""; + } + + protected String getImage() { + return "ui-components.gif"; + } + + protected String getTitle() { + return ""; + } + +} diff --git a/src/com/itmill/toolkit/demo/features/buffering.jpg b/src/com/itmill/toolkit/demo/features/buffering.jpg Binary files differnew file mode 100644 index 0000000000..23f1e89f29 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/buffering.jpg diff --git a/src/com/itmill/toolkit/demo/features/button.jpg b/src/com/itmill/toolkit/demo/features/button.jpg Binary files differnew file mode 100644 index 0000000000..c7e4bf8e3c --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/button.jpg diff --git a/src/com/itmill/toolkit/demo/features/containers.jpg b/src/com/itmill/toolkit/demo/features/containers.jpg Binary files differnew file mode 100644 index 0000000000..863e1342b1 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/containers.jpg diff --git a/src/com/itmill/toolkit/demo/features/customlayout.jpg b/src/com/itmill/toolkit/demo/features/customlayout.jpg Binary files differnew file mode 100644 index 0000000000..b668b3c27d --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/customlayout.jpg diff --git a/src/com/itmill/toolkit/demo/features/datefield.jpg b/src/com/itmill/toolkit/demo/features/datefield.jpg Binary files differnew file mode 100644 index 0000000000..c035175541 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/datefield.jpg diff --git a/src/com/itmill/toolkit/demo/features/embedded.jpg b/src/com/itmill/toolkit/demo/features/embedded.jpg Binary files differnew file mode 100644 index 0000000000..c428192c44 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/embedded.jpg diff --git a/src/com/itmill/toolkit/demo/features/filetransfer.jpg b/src/com/itmill/toolkit/demo/features/filetransfer.jpg Binary files differnew file mode 100644 index 0000000000..4c2ceb0008 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/filetransfer.jpg diff --git a/src/com/itmill/toolkit/demo/features/form.jpg b/src/com/itmill/toolkit/demo/features/form.jpg Binary files differnew file mode 100644 index 0000000000..d9993bdbe6 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/form.jpg diff --git a/src/com/itmill/toolkit/demo/features/framewindow.jpg b/src/com/itmill/toolkit/demo/features/framewindow.jpg Binary files differnew file mode 100644 index 0000000000..725df76ee3 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/framewindow.jpg diff --git a/src/com/itmill/toolkit/demo/features/gridlayout.jpg b/src/com/itmill/toolkit/demo/features/gridlayout.jpg Binary files differnew file mode 100644 index 0000000000..63f06c3281 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/gridlayout.jpg diff --git a/src/com/itmill/toolkit/demo/features/items.jpg b/src/com/itmill/toolkit/demo/features/items.jpg Binary files differnew file mode 100644 index 0000000000..fb5a38d55e --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/items.jpg diff --git a/src/com/itmill/toolkit/demo/features/label.jpg b/src/com/itmill/toolkit/demo/features/label.jpg Binary files differnew file mode 100644 index 0000000000..402dc4d4c5 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/label.jpg diff --git a/src/com/itmill/toolkit/demo/features/link.jpg b/src/com/itmill/toolkit/demo/features/link.jpg Binary files differnew file mode 100644 index 0000000000..6aaa06e5d4 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/link.jpg diff --git a/src/com/itmill/toolkit/demo/features/m.gif b/src/com/itmill/toolkit/demo/features/m.gif Binary files differnew file mode 100644 index 0000000000..2201bdfc1c --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/m.gif diff --git a/src/com/itmill/toolkit/demo/features/millstone-logo.gif b/src/com/itmill/toolkit/demo/features/millstone-logo.gif Binary files differnew file mode 100644 index 0000000000..05da85723e --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/millstone-logo.gif diff --git a/src/com/itmill/toolkit/demo/features/orderedlayout.jpg b/src/com/itmill/toolkit/demo/features/orderedlayout.jpg Binary files differnew file mode 100644 index 0000000000..1724c7cb62 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/orderedlayout.jpg diff --git a/src/com/itmill/toolkit/demo/features/panel.jpg b/src/com/itmill/toolkit/demo/features/panel.jpg Binary files differnew file mode 100644 index 0000000000..dd06508b30 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/panel.jpg diff --git a/src/com/itmill/toolkit/demo/features/parameters.jpg b/src/com/itmill/toolkit/demo/features/parameters.jpg Binary files differnew file mode 100644 index 0000000000..f4e5fd577c --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/parameters.jpg diff --git a/src/com/itmill/toolkit/demo/features/properties.jpg b/src/com/itmill/toolkit/demo/features/properties.jpg Binary files differnew file mode 100644 index 0000000000..3c2ef430f2 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/properties.jpg diff --git a/src/com/itmill/toolkit/demo/features/select.jpg b/src/com/itmill/toolkit/demo/features/select.jpg Binary files differnew file mode 100644 index 0000000000..1ce629fb68 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/select.jpg diff --git a/src/com/itmill/toolkit/demo/features/serverevents.jpg b/src/com/itmill/toolkit/demo/features/serverevents.jpg Binary files differnew file mode 100644 index 0000000000..36d88a8b35 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/serverevents.jpg diff --git a/src/com/itmill/toolkit/demo/features/table.jpg b/src/com/itmill/toolkit/demo/features/table.jpg Binary files differnew file mode 100644 index 0000000000..fe0f30dbf4 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/table.jpg diff --git a/src/com/itmill/toolkit/demo/features/tabsheet.jpg b/src/com/itmill/toolkit/demo/features/tabsheet.jpg Binary files differnew file mode 100644 index 0000000000..402b2a464a --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/tabsheet.jpg diff --git a/src/com/itmill/toolkit/demo/features/textfield.gif b/src/com/itmill/toolkit/demo/features/textfield.gif Binary files differnew file mode 100644 index 0000000000..58b6e57e32 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/textfield.gif diff --git a/src/com/itmill/toolkit/demo/features/tree.jpg b/src/com/itmill/toolkit/demo/features/tree.jpg Binary files differnew file mode 100644 index 0000000000..d563b90eb4 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/tree.jpg diff --git a/src/com/itmill/toolkit/demo/features/ui-components.gif b/src/com/itmill/toolkit/demo/features/ui-components.gif Binary files differnew file mode 100644 index 0000000000..8f5ef507c0 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/ui-components.gif diff --git a/src/com/itmill/toolkit/demo/features/validators.gif b/src/com/itmill/toolkit/demo/features/validators.gif Binary files differnew file mode 100644 index 0000000000..55faff1796 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/validators.gif diff --git a/src/com/itmill/toolkit/demo/features/window.jpg b/src/com/itmill/toolkit/demo/features/window.jpg Binary files differnew file mode 100644 index 0000000000..c297341523 --- /dev/null +++ b/src/com/itmill/toolkit/demo/features/window.jpg diff --git a/src/com/itmill/toolkit/demo/gogame/Board.java b/src/com/itmill/toolkit/demo/gogame/Board.java new file mode 100644 index 0000000000..db37d1262b --- /dev/null +++ b/src/com/itmill/toolkit/demo/gogame/Board.java @@ -0,0 +1,107 @@ +package com.itmill.toolkit.demo.gogame; + +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.StringTokenizer; + +import com.itmill.toolkit.terminal.PaintException; +import com.itmill.toolkit.terminal.PaintTarget; +import com.itmill.toolkit.ui.AbstractComponent; + +public class Board extends AbstractComponent implements Game.Listener { + + // The game. + private Game game; + + // Players color. + private boolean playerPlaysBlack; + + // Last played coordinates. + private int lastX = -1; + private int lastY = -1; + + /** Creates board for the specified game, assuming the player plays + * the specified color. + */ + public Board(Game game, boolean playerPlaysBlack) { + this.game = game; + this.playerPlaysBlack = playerPlaysBlack; + game.addGameListener(this); + } + + /** Called on variable change. If the 'move' variable is found, a stone + * is placed for the player accordingly. + */ + public void changeVariables(Object source, Map variables) { + if (variables.containsKey("move")) { + StringTokenizer st = + new StringTokenizer((String) variables.get("move"), ","); + try { + int i = Integer.valueOf(st.nextToken()).intValue(); + int j = Integer.valueOf(st.nextToken()).intValue(); + game.addStone(i, j, playerPlaysBlack); + } catch (NumberFormatException ignore) { + } catch (NoSuchElementException ignore) { + } + } + } + + /** Tag for XML output. + */ + public String getTag() { + return "goboard"; + } + + + /** Paint the board to XML. + */ + public void paintContent(PaintTarget target) throws PaintException { + target.addAttribute("xmlns", "GO Sample Namespace"); + target.addAttribute("whitename", game.getWhitePlayer()); + target.addAttribute("blackname", game.getBlackPlayer()); + target.addAttribute("moves", game.getMoves()); + target.addAttribute("whitescaptured", game.getCapturedWhiteStones()); + target.addAttribute("blackscaptured", game.getCapturedBlackStones()); + int[][] state = game.getState(); + for (int j = 0; j < state.length; j++) { + target.startTag("row"); + for (int i = 0; i < state.length; i++) { + target.startTag("col"); + if (state[i][j] == Game.EMPTY) + target.addAttribute("move", "" + i + "," + j); + else { + if (i == lastX && j == lastY) + target.addAttribute( + "stone", + state[i][j] == Game.BLACK + ? "black-last" + : "white-last"); + else + target.addAttribute( + "stone", + state[i][j] == Game.BLACK ? "black" : "white"); + } + target.endTag("col"); + } + target.endTag("row"); + } + + target.addVariable(this, "move", ""); + } + + /** Destructor. + */ + protected void finalize() throws Throwable { + super.finalize(); + if (game != null) + game.removeGameListener(this); + } + + /** Implementing the Game.Listener interface, called when a stone is added. + */ + public void stoneIsAdded(Game game, int i, int j, boolean isBlack) { + lastX = i; + lastY = j; + requestRepaint(); + } +} diff --git a/src/com/itmill/toolkit/demo/gogame/Game.java b/src/com/itmill/toolkit/demo/gogame/Game.java new file mode 100644 index 0000000000..5e5a8d1fe2 --- /dev/null +++ b/src/com/itmill/toolkit/demo/gogame/Game.java @@ -0,0 +1,223 @@ +package com.itmill.toolkit.demo.gogame; + +import java.util.Iterator; +import java.util.LinkedList; + +public class Game { + + // States for the positions on the game board. + /** Empty position. */ + public static final int EMPTY = 0; + /** Black stone. */ + public static final int BLACK = 1; + /** White stone */ + public static final int WHITE = 2; + + // Two-dimentionel array holding the current state of the game. + private int[][] state; + + // List of listeners listening to game events. + private LinkedList listeners = new LinkedList(); + + // Names of the players. + private String blackPlayer; + private String whitePlayer; + + // Number of moves made so far. + private int moves = 0; + + // Number of captured stones + private int captured[] = { 0, 0, 0 }; + + /** Creates a new game with the specified board size and player names. + */ + public Game(int boardSize, String blackPlayer, String whitePlayer) { + + // Assign player names. + this.blackPlayer = blackPlayer; + this.whitePlayer = whitePlayer; + + // Initialize board. + state = new int[boardSize][boardSize]; + for (int i = 0; i < boardSize; i++) + for (int j = 0; j < boardSize; j++) + state[i][j] = EMPTY; + } + + /** Gets the current state of the game as a two-dimentional array + * representing the board, with the states Game.EMPTY, Game.BLACK + * and Game.WHITE. + */ + public int[][] getState() { + return state; + } + + /** Adds a black or white stone to the specified position on the + * board. + */ + public void addStone(int i, int j, boolean isBlack) { + if (state[i][j] == EMPTY) { + state[i][j] = isBlack ? BLACK : WHITE; + moves++; + removeDeadStonesAround(i, j); + for (Iterator li = listeners.iterator(); li.hasNext();) + ((Game.Listener) li.next()).stoneIsAdded(this, i, j, isBlack); + } + } + + /** Adds a listener to the list of listeners + */ + public void addGameListener(Game.Listener listener) { + listeners.add(listener); + } + + /** Removes a listener from the list of listeners. + */ + public void removeGameListener(Game.Listener listener) { + listeners.remove(listener); + } + + /** Interface for implementing a listener listening to Go-game events. + */ + public interface Listener { + /** Called whenever a stone is added to the game. + */ + public void stoneIsAdded(Game game, int i, int j, boolean isBlack); + } + + /** This function returns the state of the game as a string. + */ + public String toString() { + return blackPlayer + + " (Black) vs. " + + whitePlayer + + " (White) (" + + state.length + + "x" + + state[0].length + + ", " + + moves + + " moves done" + + (captured[WHITE] > 0 + ? (", Black has captured " + captured[WHITE] + " stones") + : "") + + (captured[BLACK] > 0 + ? (", White has captured " + captured[BLACK] + " stones") + : "") + + ")"; + } + + /** Gets the black player's name. + */ + public String getBlackPlayer() { + return blackPlayer; + } + + /** Gets the number of moves so far. + */ + public int getMoves() { + return moves; + } + + /** Gets the white player's name. + */ + public String getWhitePlayer() { + return whitePlayer; + } + + /** Remove dead stones. Removes stones that are dead as + * defined by the rules of go. The state is only checked for + * the four stones surrounding the last stone added */ + private void removeDeadStonesAround(int lastx, int lasty) { + + // Remove possible victims of attack + removeIfDead(lastx - 1, lasty, lastx, lasty); + removeIfDead(lastx + 1, lasty, lastx, lasty); + removeIfDead(lastx, lasty + 1, lastx, lasty); + removeIfDead(lastx, lasty - 1, lastx, lasty); + + // Remove stones on suicide + removeIfDead(lastx, lasty, -1, -1); + } + + /** Remove area, if it is dead. This fairly complicated algorithm + * tests if area starting from (x,y) is dead and removes it in + * such case. The last stone (lastx,lasty) is always alive. */ + private void removeIfDead(int x, int y, int lastx, int lasty) { + + // Only check the stones on the board + int width = state.length; + int height = state[0].length; + if (x < 0 || y < 0 || x >= width || y >= width) + return; + + // Not dead if empty of same color than the last stone + int color = state[x][y]; + if (color == EMPTY + || (lastx >= 0 && lasty >= 0 && color == state[lastx][lasty])) + return; + + // Check areas by growing + int checked[][] = new int[state.length][state[0].length]; + checked[x][y] = color; + while (true) { + boolean stillGrowing = false; + for (int i = 0; i < width; i++) + for (int j = 0; j < height; j++) + for (int o = 0; o < 4; o++) + if (checked[i][j] == EMPTY) { + int nx = i; + int ny = j; + switch (o) { + case 0 : + nx++; + break; + case 1 : + nx--; + break; + case 2 : + ny++; + break; + case 3 : + ny--; + break; + } + if (nx >= 0 + && ny >= 0 + && nx < width + && ny < height + && checked[nx][ny] == color) { + checked[i][j] = state[i][j]; + if (checked[i][j] == color) + stillGrowing = true; + else if (checked[i][j] == EMPTY) + + // Freedom found + return; + } + + } + // If the area stops growing and no freedoms found, + // it is dead. Remove it + if (!stillGrowing) { + for (int i = 0; i < width; i++) + for (int j = 0; j < height; j++) + if (checked[i][j] == color) { + state[i][j] = EMPTY; + captured[color]++; + } + return; + } + } + } + + /** Get the number of white stones captures */ + public int getCapturedWhiteStones() { + return captured[WHITE]; + } + + /** Get the number of black stones captures */ + public int getCapturedBlackStones() { + return captured[BLACK]; + } +} diff --git a/src/com/itmill/toolkit/demo/gogame/Go.java b/src/com/itmill/toolkit/demo/gogame/Go.java new file mode 100644 index 0000000000..556f4e5c3d --- /dev/null +++ b/src/com/itmill/toolkit/demo/gogame/Go.java @@ -0,0 +1,168 @@ +package com.itmill.toolkit.demo.gogame; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.data.Item; +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.data.util.IndexedContainer; +import com.itmill.toolkit.event.*; +import com.itmill.toolkit.ui.*; + +/** The classic game 'Go' as an example for the Millstone framework. + * + * @author IT Mill Ltd. + * @see com.itmill.toolkit.Application + */ +public class Go + extends Application + implements Action.Handler, Property.ValueChangeListener { + + /* An IndexedContainer will hold the list of players - it can be + * displayed directly by the 'Table' ui component. */ + private static IndexedContainer players = new IndexedContainer(); + + // This action will be triggered when a player challenges another. + private static Action challengeAction = new Action("Challenge", null); + + // The players can have a current game. + static { + players.addContainerProperty("Current game", Game.class, null); + } + + // The layout + private CustomLayout layout = new CustomLayout("goroom"); + + // Label to be displayed in the login window. + private TextField loginName = new TextField("Who are you stranger?", ""); + + // Button for leaving the game + private Button leaveButton = new Button("Leave game", this, "close"); + + // Button for logging in + private Button loginButton = new Button("Enter game", this, "login"); + + + // A 'Table' ui component will be used to show the list of players. + private Table playersTable; + + // Our Go-board ('Board') component. + private Board board = null; + + /** The initialization method that is the only requirement for + * inheriting the com.itmill.toolkit.service.Application class. It will + * be automatically called by the framework when a user accesses the + * application. + * We'll initialize our components here. + */ + public void init() { + + // Use the GO theme that includes support for goboard component + // and goroom layout + setTheme("gogame"); + + // Initialize main window with created layout + addWindow(new Window("Game of GO",layout)); + + // Xreate a table for showing the players in the IndexedContainer 'players'. + playersTable = new Table("Players", players); + playersTable.setRowHeaderMode(Table.ROW_HEADER_MODE_ID); + playersTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); + playersTable.addActionHandler(this); + playersTable.setPageBufferingEnabled(false); + + // Add the Table and a Button to the main window. + layout.addComponent(playersTable,"players"); + layout.addComponent(leaveButton,"logoutbutton"); + + // Hide game components + leaveButton.setVisible(false); + playersTable.setVisible(false); + + // Add login functionality + layout.addComponent(loginName,"loginname"); + loginButton.dependsOn(loginName); + layout.addComponent(loginButton,"loginbutton"); + } + + /** This function is called when a player tries to log in. + */ + public void login() { + String name = loginName.toString(); + if (name.length() > 0 && !players.containsId(name)) { + + // Login successful + setUser(name); + + // Add user to player list. + Item user = players.addItem(name); + ((Property.ValueChangeNotifier) + user.getItemProperty("Current game")).addListener(this); + + // Update visible components + layout.removeComponent(loginName); + layout.removeComponent(loginButton); + leaveButton.setVisible(true); + playersTable.setVisible(true); + } + } + + // On logout, remove user from the player list + public void close() { + if (getUser() != null) { + + // Remove user from the player list. + players.removeItem(getUser()); + } + super.close(); + } + + + /** Implementing the Action.Handler interface - this function returns + * the available actions. + * @see com.itmill.toolkit.event.Action.Handler + */ + public Action[] getActions(Object target, Object source) { + Property p = players.getContainerProperty(target, "Current game"); + if (p != null && target != null && !target.equals(getUser())) { + Game game = (Game) p.getValue(); + if (game == null) { + return new Action[] { challengeAction }; + } + } + + return new Action[] { + }; + } + + /** Implementing the Action.Handler interface - this function handles + * the specified action. + * @see com.itmill.toolkit.event.Action.Handler + */ + public void handleAction(Action action, Object sender, Object target) { + if (action == challengeAction) { + Property p = players.getContainerProperty(target, "Current game"); + if (p != null && target != null && !target.equals(getUser())) { + Game game = (Game) p.getValue(); + if (game == null) { + game = new Game(9, (String) getUser(), (String) target); + p.setValue(game); + players.getContainerProperty(getUser(), "Current game").setValue( + game); + } + } + } + } + + /** Implementing the Property.ValueChangeListener interface - this function + * is called when a value change event occurs. + * @see com.itmill.toolkit.data.Property.ValueChangeListener + */ + public void valueChange(Property.ValueChangeEvent event) { + if (board != null) + layout.removeComponent(board); + Game game = (Game) event.getProperty().getValue(); + if (game != null) { + board = new Board(game, game.getBlackPlayer() == getUser()); + layout.addComponent(board,"board"); + } + } +} diff --git a/src/com/itmill/toolkit/demo/package.html b/src/com/itmill/toolkit/demo/package.html new file mode 100644 index 0000000000..ebff0df337 --- /dev/null +++ b/src/com/itmill/toolkit/demo/package.html @@ -0,0 +1,33 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head> +</head> + +<body bgcolor="white"> + +<!-- Package summary here --> + +<p>Provides several fully functional MillStone example applications. These +highlight certain aspects of the MillStone framework and how it can be +exploited to produce simple, elegant yet powerful user interface driven +applications.</p> + +<p><ul> +<li><strong>HelloWorld</strong> is the classic example which only prints the +text "Hello, World!" on the screen. +<li><strong>LoginExample</strong> is almost as simple as HelloWorld. It +demonstrates how to use the optional login procedure available to MillStone +applications. +<li><strong>Calc</strong> implements a calculator application which +demonstrates how to build a bit more complicated user interface and how the +application can interact with the usern through that interface. +</u></p> + +<!-- <h2>Package Specification</h2> --> + +<!-- Package spec here --> + +<!-- Put @see and @since tags down here. --> + +</body> +</html> diff --git a/src/com/itmill/toolkit/demo/table/TableDemoApplication.java b/src/com/itmill/toolkit/demo/table/TableDemoApplication.java new file mode 100644 index 0000000000..ecd9f98ca4 --- /dev/null +++ b/src/com/itmill/toolkit/demo/table/TableDemoApplication.java @@ -0,0 +1,148 @@ + +package com.itmill.toolkit.demo.table; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.event.Action; +import com.itmill.toolkit.terminal.ExternalResource; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.DateField; +import com.itmill.toolkit.ui.GridLayout; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Link; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Select; +import com.itmill.toolkit.ui.TabSheet; +import com.itmill.toolkit.ui.Table; +import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.Tree; +import com.itmill.toolkit.ui.Window; + + +public class TableDemoApplication extends Application implements Action.Handler { + + private Table myTable; + private String[] texts = {"Lorem","Ipsum","Dolor","Sit","Amet"}; + private Action deleteAction = new Action("Delete row"); + + public void init() { + Window mainWindow = new Window("Millstone Example"); + setMainWindow(mainWindow); + + GridLayout gl1 = new GridLayout(1,2); + GridLayout gl2 = new GridLayout(2,1); + gl1.addComponent(gl2); + + myTable = new Table("Table caption"); + myTable.setMultiSelect(true); + myTable.setPageLength(10); + myTable.setSelectable(true); + myTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); + + myTable.addContainerProperty("text", String.class, "-"); + myTable.addContainerProperty("number", Integer.class, new Integer(0)); + //myTable.addContainerProperty("date", DateField.class, ""); + myTable.setColumnReorderingAllowed(true); + myTable.setColumnCollapsingAllowed(true); + myTable.addActionHandler(this); + myTable.setRowHeaderMode(Table.ROW_HEADER_MODE_INDEX); + //myTable.setDescription("Table description text."); + + DateField df = new DateField(); + df.setValue(new java.util.Date()); + df.setReadOnly(true); + df.setResolution(DateField.RESOLUTION_DAY); + df.setStyle("text"); + + for(int i=0; i<10000; i++) { + myTable.addItem( + new Object[] { + texts[(int) (Math.random() * 5)], + new Integer((int) (Math.random() * 80))}, + new Integer(i)); + } + + TabSheet ts = new TabSheet(); + + Panel codeSamplePanel = new Panel(); + codeSamplePanel.setCaption("Example panel"); + codeSamplePanel.setDescription("A code example how to implement a Table into your application."); + codeSamplePanel.setStyle("light"); + TextField codeSample = new TextField("Code sample"); + codeSamplePanel.addComponent(codeSample); + ts.addTab(codeSamplePanel, "Code Sample", null); + + Label info = new Label(); + info.setContentMode(Label.CONTENT_XHTML); + info.setValue("<h1>Millstone AjaxAdapter</h1><p>Examples of Millstone components.</p><h2>Table Component demo</h2><p>General info about the component and its properties (static HTML).</p><h3>Third level heading</h3><h4>Subheading</h4><h5>Paragraph heading</h5><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce pharetra congue nunc. Vestibulum odio metus, tristiqueeu, venenatis eget, nonummy vel, mauris.</p><p>Mauris lobortis dictum dolor. Phasellus suscipit. Nam feugiat est in risus.</p>"); + ts.addTab(myTable,"Info", null); + + //mainWindow.addComponent(ts); + //mainWindow.addComponent(info); + //mainWindow.addComponent(myTable); + + /* Theme testing purposes */ + Button b = new Button("Button caption"); + //b.setStyle("link"); + //b.setDescription("Button description text."); + //mainWindow.addComponent(b); + + Link lnk = new Link("Link caption",new ExternalResource("http://www.itmill.com")); + lnk.setDescription("Link description text."); + Panel show = new Panel("Panel caption"); + show.setStyle(""); + show.addComponent(lnk); + show.setWidth(350); + show.setWidthUnits(Panel.UNITS_PIXELS); + show.setHeightUnits(Panel.UNITS_PIXELS); + //mainWindow.addComponent(show); + + gl2.addComponent(info); + gl2.addComponent(show); + gl2.addComponent(codeSamplePanel); + gl1.addComponent(myTable); + gl1.addComponent(b); + mainWindow.addComponent(gl1); + + Select s = new Select("Select Car"); + s.addItem("Audi"); + s.addItem("BMW"); + s.addItem("Chrysler"); + s.addItem("Volvo"); + //show.addComponent(s); + + // Create tree + Tree t = new Tree("Family Tree"); + for (int i = 0; i < 4; i++) { + t.addItem(texts[i]); + String parent = texts[(int) (Math.random() * (texts.length - 1))]; + if (t.containsId(parent)) + t.setParent(texts[i],parent); + } + + // Forbid childless people to have children (makes them leaves) + for (int i = 0; i < 4; i++) { + if (!t.hasChildren(texts[i])) { + t.setChildrenAllowed(texts[i], false); + } + } + //mainWindow.addComponent(t); + + /* + Upload u = new Upload("Upload a file:", new uploadReceiver()); + mainWindow.addComponent(u); + */ + } + + public Action[] getActions(Object arg0, Object arg1) { + Action[] actions = {deleteAction}; + return actions; + } + + public void handleAction(Action arg0, Object arg1, Object arg2) { + if(arg0 != null) { + if(arg0.getCaption() == "Delete row") { + myTable.removeItem(arg2); + } + } + } +} |