From 15fc979fbbc71e1cc7c490ca9830a64294a3615d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marko=20Gr=C3=B6nroos?= Date: Wed, 16 Apr 2008 13:25:19 +0000 Subject: [PATCH] Updates to developer tests. svn changeset:4185/svn branch:trunk --- .../ITMILL/themes/tests-magi/styles.css | 35 +- .../tests/magi/DefaultButtonExample.java | 73 ++-- .../tests/magi/MagiTestApplication.java | 349 ++++++++++++++++-- .../itmill/toolkit/tests/magi/MyUploader.java | 94 +++-- .../toolkit/tests/magi/TableExample.java | 38 +- 5 files changed, 458 insertions(+), 131 deletions(-) diff --git a/WebContent/ITMILL/themes/tests-magi/styles.css b/WebContent/ITMILL/themes/tests-magi/styles.css index 8dbe17dd69..9d704a2191 100644 --- a/WebContent/ITMILL/themes/tests-magi/styles.css +++ b/WebContent/ITMILL/themes/tests-magi/styles.css @@ -20,10 +20,10 @@ table.i-gridlayout-example-gridlayout { /*****************************************************************************/ /* For example_Alignment() */ /*****************************************************************************/ -table.-example-alignment { +table.i-gridlayout-example-alignment { background: blue; } -.-example-alignment td { +.i-gridlayout-example-alignment td { background: white; width: 150px; height: 75px; @@ -38,3 +38,34 @@ table.-example-alignment { vertical-align: top; } +/*****************************************************************************/ +/* For example_ProgressIndicator() */ +/*****************************************************************************/ +.i-progressindicator-invisible { + display: none; +} + +.i-progressindicator-fullwidth { + width: 100px; +} + +/*****************************************************************************/ +/* For example_Spacing() */ +/*****************************************************************************/ +.i-orderedlayout-spacingexample table { + background: blue; +} + +.i-orderedlayout-spacingexample td { + background: white; +} + +/* Set horizontal cell spacing for all OrderedLayouts. */ +.i-orderedlayout-hspacing { + padding-left: 10px; +} + +/* Set horizontal cell spacing in specific layout with "spacingexample" style. */ +.i-orderedlayout-spacingexample .i-orderedlayout-hspacing { + padding-left: 50px; +} diff --git a/src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java b/src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java index c41bbfdc5c..11b7432b2b 100644 --- a/src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java +++ b/src/com/itmill/toolkit/tests/magi/DefaultButtonExample.java @@ -7,50 +7,63 @@ package com.itmill.toolkit.tests.magi; import com.itmill.toolkit.event.Action; import com.itmill.toolkit.event.ShortcutAction; import com.itmill.toolkit.event.Action.Handler; +import com.itmill.toolkit.ui.AbstractField; import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.FormLayout; import com.itmill.toolkit.ui.Label; import com.itmill.toolkit.ui.OrderedLayout; import com.itmill.toolkit.ui.Panel; import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.Window; public class DefaultButtonExample extends CustomComponent implements Handler { // Define and create user interface components Panel panel = new Panel("Login"); - OrderedLayout formlayout = new OrderedLayout( - OrderedLayout.ORIENTATION_VERTICAL); + OrderedLayout formlayout = new FormLayout(); TextField username = new TextField("Username"); TextField password = new TextField("Password"); - OrderedLayout buttons = new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); + OrderedLayout buttons = new FormLayout(); - // Create buttons and define their listener methods. Here we use - // parameterless + // Create buttons and define their listener methods. Here we use parameterless // methods so that we can use same methods for both click events and - // keyboard - // actions. + // keyboard actions. Button ok = new Button("OK", this, "okHandler"); Button cancel = new Button("Cancel", this, "cancelHandler"); - public DefaultButtonExample() { + // Have the unmodified Enter key cause an event + Action action_ok = new ShortcutAction("Default key", + ShortcutAction.KeyCode.ENTER, + null); + + // Have the C key modified with Alt cause an event + Action action_cancel = new ShortcutAction("Alt+C", + ShortcutAction.KeyCode.C, + new int[] { ShortcutAction.ModifierKey.ALT }); + + Window window = null; + + public DefaultButtonExample(Window win) { // Set up the user interface setCompositionRoot(panel); panel.addComponent(formlayout); + formlayout.setOrientation(OrderedLayout.ORIENTATION_VERTICAL); formlayout.addComponent(username); formlayout.addComponent(password); - formlayout.setStyle("form"); formlayout.addComponent(buttons); + buttons.setOrientation(OrderedLayout.ORIENTATION_HORIZONTAL); buttons.addComponent(ok); buttons.addComponent(cancel); // Set focus to username username.focus(); - // Set this object as the action handler for actions related to the Ok - // and Cancel buttons. - // @TODO - // ok.addActionHandler(this); - // cancel.addActionHandler(this); + // Set this object as the action handler + System.out.println("adding ah"); + win.addActionHandler(this); + window = win; + + System.out.println("start done."); } /** @@ -59,21 +72,8 @@ public class DefaultButtonExample extends CustomComponent implements Handler { * buttons. */ public Action[] getActions(Object target, Object sender) { - final Action[] actions = new Action[1]; - - // Set the action for the requested component - if (sender == ok) { - // Bind the unmodified Enter key to the Ok button. - actions[0] = new ShortcutAction("Default key", - ShortcutAction.KeyCode.ENTER, null); - } else if (sender == cancel) { - // Bind "C" key modified with Alt to the Cancel button. - actions[0] = new ShortcutAction("Alt+C", ShortcutAction.KeyCode.C, - new int[] { ShortcutAction.ModifierKey.ALT }); - } else { - return null; - } - return actions; + System.out.println("getActions()"); + return new Action[] {action_ok, action_cancel}; } /** @@ -81,21 +81,22 @@ public class DefaultButtonExample extends CustomComponent implements Handler { * the same listener methods that are called with ButtonClick events. */ public void handleAction(Action action, Object sender, Object target) { - if (target == ok) { + if (action == action_ok) okHandler(); - } - if (target == cancel) { + if (action == action_cancel) cancelHandler(); - } } public void okHandler() { // Do something: report the click - formlayout.addComponent(new Label("OK clicked")); + formlayout.addComponent(new Label("OK clicked. "+ + "User="+username.getValue()+ + ", password="+password.getValue())); + // } public void cancelHandler() { // Do something: report the click - formlayout.addComponent(new Label("Cancel clicked")); + formlayout.addComponent(new Label("Cancel clicked. User="+username.getValue()+", password="+password.getValue())); } } diff --git a/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java b/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java index 3217143b1c..23f9ae64ce 100644 --- a/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java +++ b/src/com/itmill/toolkit/tests/magi/MagiTestApplication.java @@ -21,6 +21,8 @@ import com.itmill.toolkit.terminal.UserError; import com.itmill.toolkit.ui.AbstractSelect; import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.CheckBox; +import com.itmill.toolkit.ui.Component; +import com.itmill.toolkit.ui.CustomLayout; import com.itmill.toolkit.ui.DateField; import com.itmill.toolkit.ui.Embedded; import com.itmill.toolkit.ui.ExpandLayout; @@ -29,8 +31,10 @@ import com.itmill.toolkit.ui.GridLayout; import com.itmill.toolkit.ui.InlineDateField; import com.itmill.toolkit.ui.Label; import com.itmill.toolkit.ui.Link; +import com.itmill.toolkit.ui.NativeSelect; import com.itmill.toolkit.ui.OrderedLayout; import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.ProgressIndicator; import com.itmill.toolkit.ui.Select; import com.itmill.toolkit.ui.TabSheet; import com.itmill.toolkit.ui.Table; @@ -56,17 +60,18 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { public void init() { setTheme("tests-magi"); - + setMainWindow(main); } public DownloadStream handleURI(URL context, String relativeUri) { // Let default implementation handle requests for // application resources. - if (relativeUri.startsWith("APP")) { + if (relativeUri.startsWith("APP")) return super.handleURI(context, relativeUri); - } - + if (relativeUri.startsWith("win-")) + return super.handleURI(context, relativeUri); + String example; String param = null; @@ -96,7 +101,9 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { "upload", "link", "gridlayout", "orderedlayout", "formlayout", "panel", "expandlayout", "tabsheet", "alignment", "alignment/grid", "window", "window/opener", - "window/multiple", "classresource", "usererror" }; + "window/multiple", "classresource", "usererror", + "progress/window", "progress/thread", "progress", + "customlayout", "spacing"}; for (int i = 0; i < examples.length; i++) { main.addComponent(new Label("" + examples[i] + "", @@ -157,6 +164,12 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { example_Window(main, param); } else if (example.equals("classresource")) { example_ClassResource(main, param); + } else if (example.equals("progress")) { + example_ProgressIndicator(main, param); + } else if (example.equals("customlayout")) { + example_CustomLayout(main, param); + } else if (example.equals("spacing")) { + example_Spacing(main, param); } else { ; // main.addComponent(new Label("Unknown test '"+example+"'.")); } @@ -178,7 +191,7 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { } void example_defaultButton(Window main, String param) { - main.addComponent(new DefaultButtonExample()); + main.addComponent(new DefaultButtonExample(main)); } void example_Label(Window main, String param) { @@ -570,30 +583,24 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { layout.setHeight(400, Sizeable.UNITS_PIXELS); /* Define cells and their layouts to create. */ - /* - * FIXME Java 5 -> 1.4 Object cells[][] = { {new Button("Top Left"), - * GridLayout.ALIGNMENT_LEFT, GridLayout.ALIGNMENT_TOP}, {new - * Button("Top Center"), GridLayout.HORIZONTAL_ALIGNMENT_CENTER, - * GridLayout.ALIGNMENT_TOP}, {new Button("Top Right"), - * GridLayout.ALIGNMENT_RIGHT, GridLayout.ALIGNMENT_TOP}, {new - * Button("Center Left"), GridLayout.ALIGNMENT_LEFT, - * GridLayout.VERTICAL_ALIGNMENT_CENTER}, {new Button("Center - * Center"), GridLayout.HORIZONTAL_ALIGNMENT_CENTER, - * GridLayout.VERTICAL_ALIGNMENT_CENTER}, {new Button("Center - * Right"), GridLayout.ALIGNMENT_RIGHT, - * GridLayout.VERTICAL_ALIGNMENT_CENTER}, {new Button("Bottom - * Left"), GridLayout.ALIGNMENT_LEFT, GridLayout.ALIGNMENT_BOTTOM}, - * {new Button("Bottom Center"), - * GridLayout.HORIZONTAL_ALIGNMENT_CENTER, - * GridLayout.ALIGNMENT_BOTTOM}, {new Button("Bottom Right"), - * GridLayout.ALIGNMENT_RIGHT, GridLayout.ALIGNMENT_BOTTOM} }; - * - * for (int i=0; i<9; i++) { OrderedLayout celllayout = new - * OrderedLayout(); celllayout.addComponent((Component) - * cells[i][0]); celllayout.setComponentAlignment((Component) - * cells[i][0], (Integer)cells[i][1], (Integer)cells[i][2]); - * layout.addComponent(celllayout); } - */ + + Object cells[][] = { + {new Button("Top Left"), new Integer(GridLayout.ALIGNMENT_LEFT), new Integer(GridLayout.ALIGNMENT_TOP)}, + {new Button("Top Center"), new Integer(GridLayout.ALIGNMENT_HORIZONTAL_CENTER), new Integer(GridLayout.ALIGNMENT_TOP)}, + {new Button("Top Right"), new Integer(GridLayout.ALIGNMENT_RIGHT), new Integer(GridLayout.ALIGNMENT_TOP)}, + {new Button("Center Left"), new Integer(GridLayout.ALIGNMENT_LEFT), new Integer(GridLayout.ALIGNMENT_VERTICAL_CENTER)}, + {new Button("Center Center"), new Integer(GridLayout.ALIGNMENT_HORIZONTAL_CENTER), new Integer(GridLayout.ALIGNMENT_VERTICAL_CENTER)}, + {new Button("Center Right"), new Integer(GridLayout.ALIGNMENT_RIGHT), new Integer(GridLayout.ALIGNMENT_VERTICAL_CENTER)}, + {new Button("Bottom Left"), new Integer(GridLayout.ALIGNMENT_LEFT), new Integer(GridLayout.ALIGNMENT_BOTTOM)}, + {new Button("Bottom Center"), new Integer(GridLayout.ALIGNMENT_HORIZONTAL_CENTER), new Integer(GridLayout.ALIGNMENT_BOTTOM)}, + {new Button("Bottom Right"), new Integer(GridLayout.ALIGNMENT_RIGHT), new Integer(GridLayout.ALIGNMENT_BOTTOM)}}; + + for (int i=0; i<9; i++) { + OrderedLayout celllayout = new OrderedLayout(); + celllayout.addComponent((Component) cells[i][0]); + celllayout.setComponentAlignment((Component)cells[i][0], ((Integer)cells[i][1]).intValue(), ((Integer)cells[i][2]).intValue()); + layout.addComponent(celllayout); + } } else { final Panel panel = new Panel("A Panel with a Layout"); main.addComponent(panel); @@ -620,6 +627,49 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { } void example_ExpandLayout(Window main, String param) { + if (param != null && param.equals("centered")) { + Label widget = new Label("Here is text"); + + ExpandLayout layout = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + layout.addComponent(widget); + layout.expand(widget); + layout.setComponentAlignment(widget, OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + layout.setWidth(100, Sizeable.UNITS_PERCENTAGE); + layout.setHeight(100, Sizeable.UNITS_PERCENTAGE); + + main.setLayout(layout); + + return; + } else if (param != null && param.equals("window")) { + Window window = new Window("Progress"); + window.setHeight(100, Sizeable.UNITS_PIXELS); + window.setWidth(200, Sizeable.UNITS_PIXELS); + main.addWindow(window); + + ProgressIndicator progress = new ProgressIndicator(new Float(0.4)); + progress.addStyleName("fullwidth"); + progress.setPollingInterval(1000000); + progress.setIndeterminate(false); + + ExpandLayout layout = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + layout.setHeight(100, Sizeable.UNITS_PERCENTAGE); + layout.setComponentAlignment(progress, OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + window.setLayout(layout); + window.addComponent(progress); + + return; + } else if (param != null && param.equals("size")) { + ExpandLayout layout = new ExpandLayout(); + layout.setSizeFull(); + main.setLayout(layout); + + Button button = new Button("This is a button in middle of nowhere"); + layout.addComponent(button); + layout.setComponentAlignment(button, OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + + return; + } + for (int w = 0; w < 2; w++) { final ExpandLayout layout = new ExpandLayout( OrderedLayout.ORIENTATION_VERTICAL); @@ -672,7 +722,53 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { main.addComponent(tabsheet); // main.addComponent(new Embedded("Emb", new ClassResource // ("images/Mercury_small.png", this))); - + } else if (param.equals("expanding")) { + // Create the layout + ExpandLayout expanding = new ExpandLayout(OrderedLayout.ORIENTATION_VERTICAL); + + // It is important to set the expanding layout as the root layout + // of the containing window, in this case the main window, and not + // use addComponent(), which would place the layout inside the + // default root layout. + main.setLayout(expanding); + + // Create a tab sheet that fills the expanding layout + final TabSheet tabsheet = new TabSheet(); + tabsheet.addTab(new Label("Contents of the first tab"), "First Tab", null); + tabsheet.addTab(new Label("Contents of the second tab"), "Second Tab", null); + tabsheet.addTab(new Label("Contents of the third tab"), "Third tab", null); + + // Set the tabsheet to scale to full size inside its container + tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE); + tabsheet.setHeight(100, Sizeable.UNITS_PERCENTAGE); + + // Add the tab sheet to the layout as usual + expanding.addComponent(tabsheet); + + // Set the tab sheet to be the expanding component + expanding.expand(tabsheet); + } else if (param.equals("ordered")) { + // Create the layout + OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); + + // It is important to set the expanding layout as the root layout + // of the containing window, in this case the main window, and not + // use addComponent(), which would place the layout inside the + // default root layout. + main.setLayout(layout); + + // Create a tab sheet that fills the expanding layout + final TabSheet tabsheet = new TabSheet(); + tabsheet.addTab(new Label("Contents of the first tab"), "First Tab", null); + tabsheet.addTab(new Label("Contents of the second tab"), "Second Tab", null); + tabsheet.addTab(new Label("Contents of the third tab"), "Third tab", null); + + // Set the tabsheet to scale to full size inside its container + tabsheet.setWidth(100, Sizeable.UNITS_PERCENTAGE); + //tabsheet().setHeight(100, Sizeable.UNITS_PERCENTAGE); + + // Add the tab sheet to the layout as usual + layout.addComponent(tabsheet); } else { main.addComponent(new TabSheetExample()); } @@ -742,4 +838,195 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { main.addComponent(new Embedded("This is Embedded", new ClassResource( "smiley.jpg", main.getApplication()))); } + + void example_ProgressIndicator(final Window main, String param) { + if (param != null) { + if (param.equals("thread")) { + + // Create the indicator + final ProgressIndicator indicator = new ProgressIndicator(new Float(0.0)); + main.addComponent(indicator); + + // Set polling frequency to 0.5 seconds. + indicator.setPollingInterval(1000); + + //indicator.addStyleName("invisible"); + final Label text = new Label("-- Not running --"); + main.addComponent(text); + + // Add a button to start the progress + final Button button = new Button("Click to start"); + main.addComponent(button); + + // Another thread to do some work + class WorkThread extends Thread { + public void run () { + double current = 0.0; + while (true) { + // Do some "heavy work" + try { + sleep(50); // Sleep for 50 milliseconds + } catch (InterruptedException e) {} + + // Grow the progress value until it reaches 1.0. + current += 0.01; + if (current>1.0) + indicator.setValue(new Float(1.0)); + else + indicator.setValue(new Float(current)); + + // After the progress is full for a while, stop. + if (current > 1.2) { + // Restore the state to initial. + indicator.setValue(new Float(0.0)); + button.setVisible(true); + break; + } + } + } + } + + // Clicking the button creates and runs a work thread + button.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + final WorkThread thread = new WorkThread(); + thread.start(); + + // The button hides until the work is done. + button.setVisible(false); + } + }); + } else if (param.equals("window")) { + // Create a table in the main window to hold items added in the second window + final Table table = new Table(); + table.setPageLength(5); + table.setWidth(100, Sizeable.UNITS_PERCENTAGE); + table.addContainerProperty("Name", String.class, ""); + main.addComponent(table); + + // Create the second window + final Window adderWindow = new Window("Add Items"); + adderWindow.setName("win-adder"); + main.getApplication().addWindow(adderWindow); + + // Create selection component to add items to the table + final NativeSelect select = new NativeSelect("Select item to add"); + select.setImmediate(true); + adderWindow.addComponent(select); + + // Add some items to the selection + String items[] = new String[]{"-- Select --", "Mercury", "Venus", + "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"}; + for (int i=0; i