From e232f030886c505d945dce0a5e621c5886f58199 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marko=20Gr=C3=B6nroos?= Date: Fri, 14 Dec 2007 15:43:44 +0000 Subject: [PATCH] Development. svn changeset:3244/svn branch:trunk --- .../ITMILL/themes/tests-magi/img/smiley.jpg | Bin 0 -> 1411 bytes .../ITMILL/themes/tests-magi/styles.css | 8 +- .../tests/magi/MagiTestApplication.java | 101 +++++++++++++----- .../tests/magi/WindowTestApplication.java | 72 +++++++++++++ 4 files changed, 151 insertions(+), 30 deletions(-) create mode 100644 WebContent/ITMILL/themes/tests-magi/img/smiley.jpg create mode 100644 src/com/itmill/toolkit/tests/magi/WindowTestApplication.java diff --git a/WebContent/ITMILL/themes/tests-magi/img/smiley.jpg b/WebContent/ITMILL/themes/tests-magi/img/smiley.jpg new file mode 100644 index 0000000000000000000000000000000000000000..dc1a399c762a58c57a95753637ab961e920fa163 GIT binary patch literal 1411 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<c1}I=;VrF4wW9Q)H;sz?% zD!{d!pzFb!U9xX3zTPI5o8roG<0MW4oqZMDikqloVbuf*=gfJ(V&YTRE(2~ znmD<{#3dx9RMpfqG__1j&CD$#!?(53k=fkc)!NaP`lZ}U%G*RsT{&8vt#_9= zTyo>PaQ1VGcEY2^57)o7zb}1#^ZoMtsgIg6*RJKNFF2s0^{VpjGx58VIB&PIxAxy& zn`ipcF4Hv9=feK{O-*5U^eRIQANej{d|L6)B!}mJav$&B&zE)V)QOjGZ2}w%wv{v9 z%5^xYy?iQ%^VGtpUvE9u+sVbK-nG=zFJ_~ra{WJnc#i)J7gjI)&+uTM{y()T6?MMa z-*2(r`S#TEH_PWO(>5_)GFZFgz=9P0say2iLJzgB)s6a;Ywx~q@AfU#C*Qt(GR->U z^RBc|6@>%pDm^8(RpFKo>V>kRe(vl07pwL*_nKJWZ_l(0*|~l{cItj!81wgCn2U;D zVZ^cExKGJebIpU=L$+lmh4*>fIc_7=pwi^PsPRC^xQWkEp-Iv+h*MkX&3}gUipxH` z=YG1LizaS&O{hNw?W{Y#3%|m{ z-}Rp%=RZRW+w0%j=l|XOob>PfZ@s#U&+?@Itle++Ui<91du91=XK9D{@@;=Ct-tBi z^suU+7?bzHOdIaWZd^1?HpcBb!*c6#rUOE4UGEPcU6JK|=k}E?H%h%zyTU4-^d6bu zFUaJf!qD)-L)k(lp@~B^LR3Yjc|}Fn@h5ve{Ac*qo-*5OXaBR~VI^}HfBJloYpt3k z>kif~ZO_X+-??X8vlsoNz9!B+apB$btFnTgpWNJZcX6cwXO782fka1}4KI)RG2Y~T z6dU~1JHx~~?6uA(-J>^TIRw`wxxEVgeu9lH;7O~-n#b);+?(?b9lP&ydF>jV$DiKj bCV3?K9(n7^pmFla1IBAz8f%Z#|Gx" + examples[i] + "", @@ -117,6 +118,8 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { example_TextField(main, param); } else if (example.equals("textfieldvalidation")) { example_TextFieldValidation(main, param); + } else if (example.equals("usererror")) { + example_UserError(main, param); } else if (example.equals("datefield")) { example_DateField(main, param); } else if (example.equals("button")) { @@ -226,18 +229,14 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { void example_Tree(Window main, String param) { final Object[][] planets = new Object[][] { - new Object[] { "Mercury" }, - new Object[] { "Venus" }, - new Object[] { "Earth", "The Moon" }, - new Object[] { "Mars", "Phobos", "Deimos" }, - new Object[] { "Jupiter", "Io", "Europa", "Ganymedes", - "Callisto" }, - new Object[] { "Saturn", "Titan", "Tethys", "Dione", "Rhea", - "Iapetus" }, - new Object[] { "Uranus", "Miranda", "Ariel", "Umbriel", - "Titania", "Oberon" }, - new Object[] { "Neptune", "Triton", "Proteus", "Nereid", - "Larissa" } }; + new Object[] {"Mercury"}, + new Object[] {"Venus"}, + new Object[] {"Earth", "The Moon"}, + new Object[] {"Mars", "Phobos", "Deimos"}, + new Object[] {"Jupiter", "Io", "Europa", "Ganymedes", "Callisto"}, + new Object[] {"Saturn", "Titan", "Tethys", "Dione", "Rhea", "Iapetus"}, + new Object[] {"Uranus", "Miranda", "Ariel", "Umbriel", "Titania", "Oberon"}, + new Object[] {"Neptune", "Triton", "Proteus", "Nereid", "Larissa"}}; final Tree tree = new Tree("The Planets and Major Moons"); @@ -364,6 +363,48 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { }); } + void example_UserError(final Window main, String param) { + if (param != null) { + if (param.equals("form")) { + + final FormLayout layout = new FormLayout(); + main.addComponent(layout); + + final TextField textfield = new TextField("Enter name"); + layout.addComponent(textfield); + textfield.setComponentError(null); + + final Button button = new Button("Click me!"); + layout.addComponent(button); + + button.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + if (((String)textfield.getValue()).length() == 0) + textfield.setComponentError(new UserError("Must not be empty")); + else // Clear the error + textfield.setComponentError(null); + } + }); + } + } else { + final TextField textfield = new TextField("Enter name"); + main.addComponent(textfield); + textfield.setComponentError(null); + + final Button button = new Button("Click me!"); + main.addComponent(button); + + button.addListener(new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + if (((String)textfield.getValue()).length() == 0) + textfield.setComponentError(new UserError("Must not be empty")); + else // Clear the error + textfield.setComponentError(null); + } + }); + } + } + void example_DateField(Window main, String param) { /* Create a DateField with the calendar style. */ final DateField date = new DateField("Here is a calendar field"); @@ -459,11 +500,20 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { } void example_Panel(Window main, String param) { + // Create a panel with a caption. final Panel panel = new Panel("Contact Information"); + + // Create a layout inside the panel final OrderedLayout form = new FormLayout(); + + // Set the layout as the root layout of the panel + panel.setLayout(form); + + // Add some components form.addComponent(new TextField("Name")); form.addComponent(new TextField("Email")); + // Add the panel to the main window final ClassResource icon = new ClassResource("smiley.jpg", main .getApplication()); form.addComponent(new Embedded("Image", icon)); @@ -491,8 +541,8 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { /* Add some components of various shapes. */ grid.addComponent(new Button("3x1 button"), 1, 1, 3, 1); grid.addComponent(new Label("1x2 cell"), 1, 2, 1, 3); - final DateField date = new DateField("A 2x2 date field"); - date.setStyleName("calendar"); + final InlineDateField date = new InlineDateField("A 2x2 date field"); + date.setResolution(DateField.RESOLUTION_DAY); grid.addComponent(date, 2, 2, 3, 3); main.addComponent(grid); @@ -506,6 +556,7 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { // OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); main.setLayout(layout); layout.addStyleName("example-alignment"); + layout.getSize().setWidth(400, Size.UNITS_PIXELS); layout.getSize().setHeight(400, Size.UNITS_PIXELS); @@ -624,8 +675,7 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { image.addStyleName("omaimage"); main.addComponent(image); - final EmbeddedButton button = new EmbeddedButton(new ClassResource( - "smiley.jpg", this)); + final EmbeddedButton button = new EmbeddedButton(new ClassResource("smiley.jpg", this)); main.addComponent(button); } @@ -644,11 +694,10 @@ public class MagiTestApplication extends com.itmill.toolkit.Application { /* Add link to the second window in the main window. */ main.addComponent(new Label("Second window: middle-click to open", - Label.CONTENT_XHTML)); - main.addComponent(new Label( - "The second window can be accessed through URL: " - + mywindow.getURL())); + + mywindow.getURL() + "'>middle-click to open", + Label.CONTENT_XHTML)); + main.addComponent(new Label("The second window can be accessed through URL: " + + mywindow.getURL())); } return; } diff --git a/src/com/itmill/toolkit/tests/magi/WindowTestApplication.java b/src/com/itmill/toolkit/tests/magi/WindowTestApplication.java new file mode 100644 index 0000000000..9d866a48f6 --- /dev/null +++ b/src/com/itmill/toolkit/tests/magi/WindowTestApplication.java @@ -0,0 +1,72 @@ +package com.itmill.toolkit.tests.magi; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.ui.*; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.terminal.*; + +public class WindowTestApplication extends Application { + Window anotherpage = null; + + public void init() { + final Window main = new Window ("Window Test Application"); + setMainWindow(main); + setTheme("tests-magi"); + + /* Create a new window. */ + final Window mywindow = new Window("Second Window"); + + /* Manually set the name of the window. */ + mywindow.setName("mywindow"); + + /* Add some content to the window. */ + mywindow.addComponent(new Label("This is a second window.")); + + /* Add the window to the application. */ + addWindow(mywindow); + + /* Add a button to open a new window. */ + main.addComponent(new Button("Click to open new window", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + // Open the window. + main.open(new ExternalResource(mywindow.getURL()), "_new"); + } + })); + + /* Add a link to the second window. */ + Link link = new Link("Click to open second window", + new ExternalResource(mywindow.getURL())); + link.setTargetName("_new"); + //link.setTargetHeight(300); + //link.setTargetWidth(300); + //link.setTargetBorder(Link.TARGET_BORDER_DEFAULT); + main.addComponent(link); + + /* Add the link manually inside a Label. */ + main.addComponent(new Label("Second window: click to open", + Label.CONTENT_XHTML)); + main.addComponent(new Label("The second window can be accessed through URL: " + + mywindow.getURL())); + + /* Add link to the yet another window that does not yet exist. */ + main.addComponent(new Label("Yet another window: click to open", + Label.CONTENT_XHTML)); + main.addComponent(new Label("The yet another window can be accessed through URL: " + + getURL()+"anotherpage/")); + } + + public Window getWindow(String name) { + if (name.equals("anotherpage")) { + if (anotherpage == null) { + anotherpage = new Window("Yet Another Page"); + anotherpage.addComponent(new Label("This is a yet another window.")); + } + return anotherpage; + } + return super.getWindow(name); + } + +} -- 2.39.5