diff options
author | Marko Grönroos <magi@iki.fi> | 2008-09-04 08:17:50 +0000 |
---|---|---|
committer | Marko Grönroos <magi@iki.fi> | 2008-09-04 08:17:50 +0000 |
commit | 629810d893e10f8081c6d0fe20e31282a9ec745a (patch) | |
tree | f4d77c35b353d41e7040a18884f41086315a4808 /src/com/itmill/toolkit/tests/book/BookTestApplication.java | |
parent | 5841f744cdf39a0ccd92ca178943c00242334cc6 (diff) | |
download | vaadin-framework-629810d893e10f8081c6d0fe20e31282a9ec745a.tar.gz vaadin-framework-629810d893e10f8081c6d0fe20e31282a9ec745a.zip |
Reverted mass formatting done in [5331] for book examples.
svn changeset:5357/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/tests/book/BookTestApplication.java')
-rw-r--r-- | src/com/itmill/toolkit/tests/book/BookTestApplication.java | 708 |
1 files changed, 296 insertions, 412 deletions
diff --git a/src/com/itmill/toolkit/tests/book/BookTestApplication.java b/src/com/itmill/toolkit/tests/book/BookTestApplication.java index 4583beb04f..db84225e07 100644 --- a/src/com/itmill/toolkit/tests/book/BookTestApplication.java +++ b/src/com/itmill/toolkit/tests/book/BookTestApplication.java @@ -73,38 +73,36 @@ public class BookTestApplication extends com.itmill.toolkit.Application { StreamResource strres; OrderedLayout ol; int getwincount = 0; - + public void init() { setTheme("tests-book"); - + setMainWindow(main); // Demo the use of parameter and URI handlers main.addParameterHandler(new MyParameterHandler()); main.addURIHandler(new MyURIHandler()); - + MyDynamicResource myresource = new MyDynamicResource(); main.addParameterHandler(myresource); main.addURIHandler(myresource); main.addURIHandler(new BookTestURIHandler()); } - + class MyParameterHandler implements ParameterHandler { public void handleParameters(Map parameters) { // Print out the parameters to standard output for (Iterator it = parameters.keySet().iterator(); it.hasNext();) { - String key = (String) it.next(); + String key = (String) it.next(); String value = ((String[]) parameters.get(key))[0]; - System.out.println("Key: " + key + ", value: " + value); + System.out.println("Key: "+key+", value: "+value); } } } - class MyURIHandler implements URIHandler { public DownloadStream handleURI(URL context, String relativeUri) { - System.out.println("Context: " + context.toString() - + ", relative: " + relativeUri); + System.out.println("Context: "+context.toString()+", relative: "+relativeUri); return null; // Let the Application provide the response } } @@ -129,10 +127,10 @@ public class BookTestApplication extends com.itmill.toolkit.Application { final Window child = (Window) cwi.next(); main.removeWindow(child); } - + // The index is listed inside a grid layout main.setLayout(new OrderedLayout()); - GridLayout grid = new GridLayout(4, 4); + GridLayout grid = new GridLayout(4,4); grid.addStyleName("index"); main.addComponent(grid); @@ -141,22 +139,19 @@ public class BookTestApplication extends com.itmill.toolkit.Application { "labelcontent", "tree", "embedded", "textfield", "textfieldvalidation", "datefield", "button", "select/select", "select/native", "select/optiongroup", - "select/twincol", "filterselect", "validator", "table", - "table/select", "table/component", "table/paging", - "table/editable", "upload", "link", "gridlayout", - "orderedlayout", "formlayout", "form", "form/simple", - "form/layout", "panel", "expandlayout", - "expandlayout/root", "tabsheet", "alignment", - "alignment/grid", "window", "window/opener", + "select/twincol", "filterselect", "validator", "table", "table/select", "table/component", "table/paging", "table/editable", + "upload", "link", "gridlayout", "orderedlayout", + "formlayout", "form", "form/simple", "form/layout", "panel", "expandlayout", "expandlayout/root", "tabsheet", + "alignment", "alignment/grid", "window", "window/opener", "window/multiple", "classresource", "usererror", "progress/window", "progress/thread", "progress", "customlayout", "spacing", "margin", "clientinfo", "fillinform/templates", "notification", "print", - "richtextfield", "querycontainer", "menubar" }; + "richtextfield", "querycontainer", "menubar"}; for (int i = 0; i < examples.length; i++) { - grid.addComponent(new Label("<a href='" - + context.toString() + examples[i] + "'>" - + examples[i] + "</a>", Label.CONTENT_XHTML)); + grid.addComponent(new Label("<a href='" + context.toString() + + examples[i] + "'>" + examples[i] + "</a>", + Label.CONTENT_XHTML)); } return null; } @@ -238,14 +233,13 @@ public class BookTestApplication extends com.itmill.toolkit.Application { } else if (example.equals("menubar")) { example_MenuBar(main, param); } else { - ; // main.addComponent(new - // Label("Unknown test '"+example+"'.")); + ; // main.addComponent(new Label("Unknown test '"+example+"'.")); } return null; } } - + /* * public Window getWindow(String name) { Window superwin = * super.getWindow(name); if (superwin != null) return superwin; @@ -316,14 +310,10 @@ public class BookTestApplication extends com.itmill.toolkit.Application { 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[] { "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(); @@ -354,52 +344,48 @@ public class BookTestApplication extends com.itmill.toolkit.Application { tree.expandItemsRecursively(planet); } } - - // Horizontal layout with the tree on the left and a details panel on - // the right. - final ExpandLayout horlayout = new ExpandLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); + + // Horizontal layout with the tree on the left and a details panel on the right. + final ExpandLayout horlayout = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); horlayout.addStyleName("treeexample"); horlayout.setSizeFull(); - + final Panel treepanel = new Panel("The Planets and Major Moons"); treepanel.addComponent(tree); horlayout.addComponent(treepanel); - + final Panel detailspanel = new Panel("Details"); horlayout.addComponent(detailspanel); horlayout.expand(detailspanel); - + final OrderedLayout detailslayout = new OrderedLayout(); detailspanel.setLayout(detailslayout); - - // Allow null selection - this is the default actually. - tree.setNullSelectionAllowed(true); - - // When a tree item (planet or moon) is clicked, open the item in - // Details view. - tree.setImmediate(true); - tree.addListener(new ValueChangeListener() { - String lastselected = null; - - public void valueChange(ValueChangeEvent event) { - String planet = (String) tree.getValue(); - - // Reselect a selected item if it is unselected by clicking it. - if (planet == null) { - planet = lastselected; - tree.setValue(planet); - } - lastselected = planet; - + + // Allow null selection - this is the default actually. + tree.setNullSelectionAllowed(true); + + // When a tree item (planet or moon) is clicked, open the item in Details view. + tree.setImmediate(true); + tree.addListener(new ValueChangeListener() { + String lastselected = null; + + public void valueChange(ValueChangeEvent event) { + String planet = (String) tree.getValue(); + + // Reselect a selected item if it is unselected by clicking it. + if (planet == null) { + planet = lastselected; + tree.setValue(planet); + } + lastselected = planet; + detailspanel.setCaption("Details on " + planet); detailslayout.removeAllComponents(); - + // Put some stuff in the Details view. detailslayout.addComponent(new Label("Where is the cat?")); - detailslayout.addComponent(new Label("The cat is in " + planet - + ".")); - + detailslayout.addComponent(new Label("The cat is in " + planet + ".")); + } }); @@ -541,9 +527,8 @@ public class BookTestApplication extends com.itmill.toolkit.Application { } void example_DateField(Window main, String param) { - OrderedLayout layout = new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); - + OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + /* Create a DateField with the calendar style. */ final DateField popupdate = new PopupDateField("Popup calendar field"); @@ -554,9 +539,8 @@ public class BookTestApplication extends com.itmill.toolkit.Application { popupdate.setValue(new java.util.Date()); /* Create a DateField with the calendar style. */ - final DateField inlinedate = new InlineDateField( - "Inline calendar field"); - + final DateField inlinedate = new InlineDateField("Inline calendar field"); + /* Set locale of the DateField to American English. */ inlinedate.setLocale(new Locale("en", "US")); @@ -578,7 +562,7 @@ public class BookTestApplication extends com.itmill.toolkit.Application { form.setCaption("My Form"); form.setRequired(true); main.addComponent(form); - + TextField text = new TextField("This is a required text field"); text.setRequired(true); text.setImmediate(true); @@ -593,7 +577,7 @@ public class BookTestApplication extends com.itmill.toolkit.Application { return "pagingtable"; } } - + void example_Table(Window main, String param) { if (param != null) { if (param.equals("select")) { @@ -613,11 +597,11 @@ public class BookTestApplication extends com.itmill.toolkit.Application { } else if (param.equals("paging")) { PagingTable table = new PagingTable(); table.addContainerProperty("Column 1", String.class, null); - for (int i = 0; i < 100; i++) - table.addItem(new Object[] { "Item " + i }, new Integer(i)); + for (int i=0; i<100; i++) + table.addItem(new Object[]{"Item "+i}, new Integer(i)); main.addComponent(table); } - } else + }else main.addComponent(new TableExample1()); } @@ -719,10 +703,9 @@ public class BookTestApplication extends com.itmill.toolkit.Application { void example_GridLayout(Window main, String param) { if (param.equals("embedded")) { - final GridLayout grid = new GridLayout(3, 3); - for (int i = 0; i < 3 * 3; i++) { - ClassResource img = new ClassResource("smiley.jpg", main - .getApplication()); + final GridLayout grid = new GridLayout(3,3); + for (int i=0; i<3*3; i++) { + ClassResource img = new ClassResource("smiley.jpg", main.getApplication()); Embedded embedded = new Embedded("", img); grid.addComponent(embedded); } @@ -767,56 +750,25 @@ public class BookTestApplication extends com.itmill.toolkit.Application { layout.setHeight(400, Sizeable.UNITS_PIXELS); /* Define cells and their layouts to create. */ - - Object cells[][] = { - { new Button("Top Left"), - new Integer(OrderedLayout.ALIGNMENT_LEFT), - new Integer(OrderedLayout.ALIGNMENT_TOP) }, - { - new Label("Top Center"), - new Integer( - OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER), - new Integer(OrderedLayout.ALIGNMENT_TOP) }, - { new Label("Top Right"), - new Integer(OrderedLayout.ALIGNMENT_RIGHT), - new Integer(OrderedLayout.ALIGNMENT_TOP) }, - { - new Button("Center Left"), - new Integer(OrderedLayout.ALIGNMENT_LEFT), - new Integer(OrderedLayout.ALIGNMENT_VERTICAL_CENTER) }, - { - new Button("Center Center"), - new Integer( - OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER), - new Integer(OrderedLayout.ALIGNMENT_VERTICAL_CENTER) }, - { - new Button("Center Right"), - new Integer(OrderedLayout.ALIGNMENT_RIGHT), - new Integer(OrderedLayout.ALIGNMENT_VERTICAL_CENTER) }, - { new Button("Bottom Left"), - new Integer(OrderedLayout.ALIGNMENT_LEFT), - new Integer(OrderedLayout.ALIGNMENT_BOTTOM) }, - { - new Button("Bottom Center"), - new Integer( - OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER), - new Integer(OrderedLayout.ALIGNMENT_BOTTOM) }, - { new Button("Bottom Right"), - new Integer(OrderedLayout.ALIGNMENT_RIGHT), - new Integer(OrderedLayout.ALIGNMENT_BOTTOM) } }; - - for (int i = 0; i < 9; i++) { - ExpandLayout celllayout = new ExpandLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); - 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); - // layout.setComponentAlignment((Component)cells[i][0], - // ((Integer)cells[i][1]).intValue(), - // ((Integer)cells[i][2]).intValue()); - } + + Object cells[][] = { + {new Button("Top Left"), new Integer(OrderedLayout.ALIGNMENT_LEFT), new Integer(OrderedLayout.ALIGNMENT_TOP)}, + {new Label ("Top Center"), new Integer(OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER), new Integer(OrderedLayout.ALIGNMENT_TOP)}, + {new Label ("Top Right"), new Integer(OrderedLayout.ALIGNMENT_RIGHT), new Integer(OrderedLayout.ALIGNMENT_TOP)}, + {new Button("Center Left"), new Integer(OrderedLayout.ALIGNMENT_LEFT), new Integer(OrderedLayout.ALIGNMENT_VERTICAL_CENTER)}, + {new Button("Center Center"), new Integer(OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER), new Integer(OrderedLayout.ALIGNMENT_VERTICAL_CENTER)}, + {new Button("Center Right"), new Integer(OrderedLayout.ALIGNMENT_RIGHT), new Integer(OrderedLayout.ALIGNMENT_VERTICAL_CENTER)}, + {new Button("Bottom Left"), new Integer(OrderedLayout.ALIGNMENT_LEFT), new Integer(OrderedLayout.ALIGNMENT_BOTTOM)}, + {new Button("Bottom Center"), new Integer(OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER), new Integer(OrderedLayout.ALIGNMENT_BOTTOM)}, + {new Button("Bottom Right"), new Integer(OrderedLayout.ALIGNMENT_RIGHT), new Integer(OrderedLayout.ALIGNMENT_BOTTOM)}}; + + for (int i=0; i<9; i++) { + ExpandLayout celllayout = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + 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); + //layout.setComponentAlignment((Component)cells[i][0], ((Integer)cells[i][1]).intValue(), ((Integer)cells[i][2]).intValue()); + } } else { final Panel panel = new Panel("A Panel with a Layout"); main.addComponent(panel); @@ -848,94 +800,78 @@ public class BookTestApplication extends com.itmill.toolkit.Application { } else if (param != null && param.equals("layout")) { Form form = new Form(); form.setCaption("Form Caption"); - form - .setDescription("This is a description of the Form that is " - + "displayed in the upper part of the form. You normally enter some " - + "descriptive text about the form and its use here."); - - // Add a field directly to the layout. This field will not be bound - // to - // the data source Item of the form. + form.setDescription("This is a description of the Form that is " + + "displayed in the upper part of the form. You normally enter some " + + "descriptive text about the form and its use here."); + + // Add a field directly to the layout. This field will not be bound to + // the data source Item of the form. form.getLayout().addComponent(new TextField("A Field")); - + // Add a field and bind it to an named item property. form.addField("another", new TextField("Another Field")); - - form.setComponentError(new UserError( - "This is the error indicator of the Form.")); + + form.setComponentError(new UserError("This is the error indicator of the Form.")); // Set the footer layout and add some text. form.setFooter(new OrderedLayout()); - form - .getFooter() - .addComponent( - new Label( - "This is the footer area of the Form. " - + "You can use any layout here. This is nice for buttons.")); - - // Add an Ok (commit), Reset (discard), and Cancel buttons for the - // form. - ExpandLayout okbar = new ExpandLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); + form.getFooter().addComponent(new Label("This is the footer area of the Form. "+ + "You can use any layout here. This is nice for buttons.")); + + // Add an Ok (commit), Reset (discard), and Cancel buttons for the form. + ExpandLayout okbar = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); okbar.setHeight("25px"); Button okbutton = new Button("OK", form, "commit"); okbar.addComponent(okbutton); - okbar.setComponentAlignment(okbutton, ExpandLayout.ALIGNMENT_RIGHT, - ExpandLayout.ALIGNMENT_TOP); + okbar.setComponentAlignment(okbutton, ExpandLayout.ALIGNMENT_RIGHT, ExpandLayout.ALIGNMENT_TOP); okbar.addComponent(new Button("Reset", form, "discard")); okbar.addComponent(new Button("Cancel")); form.getFooter().addComponent(okbar); - + main.addComponent(form); - } else + } else main.addComponent(new FormExample()); } 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); + + 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.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); + + ExpandLayout layout = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); layout.setHeight(100, Sizeable.UNITS_PERCENTAGE); - layout.setComponentAlignment(progress, - OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, - OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + layout.setComponentAlignment(progress, OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, OrderedLayout.ALIGNMENT_VERTICAL_CENTER); window.setLayout(layout); window.addComponent(progress); - + return; } else if (param != null && param.equals("root")) { final Window mainwin = main; - + // Layout to switch to final OrderedLayout expand2 = new OrderedLayout(); expand2.addComponent(new Label("I am layout too.")); - + // Original layout final OrderedLayout expand1 = new OrderedLayout(); Button switchButton = new Button("Switch to other layout"); @@ -947,7 +883,7 @@ public class BookTestApplication extends com.itmill.toolkit.Application { }); expand1.addComponent(switchButton); main.setLayout(expand1); - + return; } else if (param != null && param.equals("size")) { ExpandLayout layout = new ExpandLayout(); @@ -956,10 +892,8 @@ public class BookTestApplication extends com.itmill.toolkit.Application { 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); - + layout.setComponentAlignment(button, OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + return; } @@ -979,8 +913,8 @@ public class BookTestApplication extends com.itmill.toolkit.Application { /* * FIXME Java 5 -> 1.4 for (int i=0; i<5; i++) * table.addContainerProperty("col "+(i+1), Integer.class, 0); for - * (int j=0; j<20; j++) table.addItem(new Object[]{1j,2j,3j,4j,5j}, - * j); + * (int j=0; j<20; j++) table.addItem(new + * Object[]{1*j,2*j,3*j,4*j,5*j}, j); */ layout.addComponent(table); @@ -1017,24 +951,20 @@ public class BookTestApplication extends com.itmill.toolkit.Application { // ("images/Mercury_small.png", this))); } else if (param.equals("expanding")) { // Create the layout - ExpandLayout expanding = new ExpandLayout( - OrderedLayout.ORIENTATION_VERTICAL); - + 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); - + 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); @@ -1046,27 +976,23 @@ public class BookTestApplication extends com.itmill.toolkit.Application { expanding.expand(tabsheet); } else if (param.equals("ordered")) { // Create the layout - OrderedLayout layout = new OrderedLayout( - OrderedLayout.ORIENTATION_VERTICAL); - + 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); - + 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); + //tabsheet().setHeight(100, Sizeable.UNITS_PERCENTAGE); // Add the tab sheet to the layout as usual layout.addComponent(tabsheet); @@ -1139,45 +1065,43 @@ public class BookTestApplication 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)); + 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"); + + //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() { + public void run () { double current = 0.0; while (true) { // Do some "heavy work" try { sleep(50); // Sleep for 50 milliseconds - } catch (InterruptedException e) { - } - + } catch (InterruptedException e) {} + // Grow the progress value until it reaches 1.0. current += 0.01; - if (current > 1.0) + if (current>1.0) indicator.setValue(new Float(1.0)); - else + else indicator.setValue(new Float(current)); - + // After the progress is full for a while, stop. if (current > 1.2) { // Restore the state to initial. @@ -1188,20 +1112,19 @@ public class BookTestApplication extends com.itmill.toolkit.Application { } } } - + // 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 + // 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); @@ -1214,38 +1137,33 @@ public class BookTestApplication extends com.itmill.toolkit.Application { main.getApplication().addWindow(adderWindow); // Create selection component to add items to the table - final NativeSelect select = new NativeSelect( - "Select item to add"); + 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 < items.length; i++) + String items[] = new String[]{"-- Select --", "Mercury", "Venus", + "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"}; + for (int i=0; i<items.length; i++) select.addItem(items[i]); select.setNullSelectionItemId(items[0]); - + // When an item is selected in the second window, add // table in the main window select.addListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - // If the selected value is something else but null - // selection item. + // If the selected value is something else but null selection item. if (select.getValue() != null) { - // Add the selected item to the table in the main - // window - table.addItem(new Object[] { select.getValue() }, - new Integer(table.size())); + // Add the selected item to the table in the main window + table.addItem(new Object[]{select.getValue()}, new Integer(table.size())); } } }); // Link to open the selection window Link link = new Link("Click to open second window", - new ExternalResource(adderWindow.getURL()), "_new", 50, - 200, Link.TARGET_BORDER_DEFAULT); + new ExternalResource(adderWindow.getURL()), + "_new", 50, 200, Link.TARGET_BORDER_DEFAULT); main.addComponent(link); // Enable polling to update the main window @@ -1253,53 +1171,41 @@ public class BookTestApplication extends com.itmill.toolkit.Application { poller.addStyleName("invisible"); main.addComponent(poller); } else if (param.equals("centered")) { - /* - * GridLayout grid = new GridLayout(3,3); main.setLayout(grid); - * grid().setWidth(100, Sizeable.UNITS_PERCENTAGE); - * - * ExpandLayout layout2 = new - * ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); - * layout2().setWidth(50, Sizeable.UNITS_PERCENTAGE); - * - * ProgressIndicator poller = new ProgressIndicator(new - * Float(0.4)); poller.setPollingInterval(1000000); - * poller.setIndeterminate(false); layout2.addComponent(poller); - * - * grid.addComponent(layout2, 1, 1); - */ - - // ExpandLayout layout2 = new - // ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); - /* - * ProgressIndicator poller = new ProgressIndicator(new - * Float(0.4)); poller.setPollingInterval(1000000); - * poller.setIndeterminate(false); - */ - /* - * layout2.addComponent(poller); layout2().setWidth(50, - * Sizeable.UNITS_PERCENTAGE); - */ - - // layout.setComponentAlignment(poller, - // OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, - // OrderedLayout.ALIGNMENT_VERTICAL_CENTER); - /* - * GridLayout grid = new GridLayout(1,1); - * grid.addComponent(layout2, 0, 0); grid().setWidth(100, - * Sizeable.UNITS_PERCENTAGE); - */ - - /* - * GridLayout layout = new GridLayout(1,1); - * //OrderedLayout.ORIENTATION_HORIZONTAL); - * layout.addComponent(poller); //layout.expand(poller); - * layout.setComponentAlignment(poller, - * OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, - * OrderedLayout.ALIGNMENT_VERTICAL_CENTER); - * layout().setWidth(100, Sizeable.UNITS_PERCENTAGE); - * layout().setHeight(100, Sizeable.UNITS_PERCENTAGE); - */ - +/* GridLayout grid = new GridLayout(3,3); + main.setLayout(grid); + grid().setWidth(100, Sizeable.UNITS_PERCENTAGE); + + ExpandLayout layout2 = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + layout2().setWidth(50, Sizeable.UNITS_PERCENTAGE); + + ProgressIndicator poller = new ProgressIndicator(new Float(0.4)); + poller.setPollingInterval(1000000); + poller.setIndeterminate(false); + layout2.addComponent(poller); + + grid.addComponent(layout2, 1, 1); + */ + + //ExpandLayout layout2 = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + + /*ProgressIndicator poller = new ProgressIndicator(new Float(0.4)); + poller.setPollingInterval(1000000); + poller.setIndeterminate(false);*/ + /*layout2.addComponent(poller); + layout2().setWidth(50, Sizeable.UNITS_PERCENTAGE);*/ + + //layout.setComponentAlignment(poller, OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + /*GridLayout grid = new GridLayout(1,1); + grid.addComponent(layout2, 0, 0); + grid().setWidth(100, Sizeable.UNITS_PERCENTAGE);*/ + + /*GridLayout layout = new GridLayout(1,1); //OrderedLayout.ORIENTATION_HORIZONTAL); + layout.addComponent(poller); + //layout.expand(poller); + layout.setComponentAlignment(poller, OrderedLayout.ALIGNMENT_HORIZONTAL_CENTER, OrderedLayout.ALIGNMENT_VERTICAL_CENTER); + layout().setWidth(100, Sizeable.UNITS_PERCENTAGE); + layout().setHeight(100, Sizeable.UNITS_PERCENTAGE);*/ + } } else { ProgressIndicator poller = new ProgressIndicator(new Float(0.0)); @@ -1308,30 +1214,30 @@ public class BookTestApplication extends com.itmill.toolkit.Application { main.addComponent(poller); } } - + void example_CustomLayout(final Window main, String param) { Window sub = new Window("Login"); sub.setModal(true); main.addWindow(sub); - + // Create the custom layout and set it as the root layout of // the containing window. final CustomLayout custom = new CustomLayout("layoutname"); sub.setLayout(custom); - + // Create components and bind them to the location tags // in the custom layout. TextField username = new TextField(); custom.addComponent(username, "username"); - + TextField password = new TextField(); custom.addComponent(password, "password"); - + final Button ok = new Button("Login"); custom.addComponent(ok, "okbutton"); - + final Button deny = new Button("No can do!"); - + Button.ClickListener listener = new Button.ClickListener() { public void buttonClick(ClickEvent event) { // Switch between ok and deny @@ -1342,9 +1248,9 @@ public class BookTestApplication extends com.itmill.toolkit.Application { System.out.println("Changing to ok button."); custom.addComponent(ok, "okbutton"); } - } - }; - + } + }; + ok.addListener(listener); deny.addListener(listener); } @@ -1353,56 +1259,51 @@ public class BookTestApplication extends com.itmill.toolkit.Application { OrderedLayout containinglayout = new OrderedLayout(); main.setLayout(containinglayout); - GridLayout grid = new GridLayout(4, 3); + GridLayout grid = new GridLayout(4,3); grid.addStyleName("spacingexample"); containinglayout.addComponent(grid); grid.addComponent(new Label(""), 0, 0); grid.addComponent(new Label(""), 1, 0); - - grid.addComponent(new Label("No spacing:"), 0, 1); - OrderedLayout layout1 = new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); - grid.addComponent(layout1, 1, 1); + + grid.addComponent(new Label("No spacing:"),0,1); + OrderedLayout layout1 = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + grid.addComponent(layout1,1,1); layout1.addStyleName("spacingexample"); layout1.addComponent(new Button("Component 1")); layout1.addComponent(new Button("Component 2")); layout1.addComponent(new Button("Component 3")); - + grid.addComponent(new Label("Horizontal spacing:"), 0, 2); - OrderedLayout layout2 = new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); - grid.addComponent(layout2, 1, 2); + OrderedLayout layout2 = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); + grid.addComponent(layout2,1,2); layout2.addStyleName("spacingexample"); layout2.setSpacing(true); layout2.addComponent(new Button("Component 1")); layout2.addComponent(new Button("Component 2")); layout2.addComponent(new Button("Component 3")); - grid.addComponent(new Label("No spacing:"), 2, 0); - OrderedLayout layout3 = new OrderedLayout( - OrderedLayout.ORIENTATION_VERTICAL); - grid.addComponent(layout3, 2, 1, 2, 2); + grid.addComponent(new Label("No spacing:"),2,0); + OrderedLayout layout3 = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); + grid.addComponent(layout3,2,1,2,2); layout3.addStyleName("spacingexample"); layout3.addComponent(new Button("Component 1")); layout3.addComponent(new Button("Component 2")); layout3.addComponent(new Button("Component 3")); - grid.addComponent(new Label("Vertical spacing:"), 3, 0); - OrderedLayout layout4 = new OrderedLayout( - OrderedLayout.ORIENTATION_VERTICAL); - grid.addComponent(layout4, 3, 1, 3, 2); + grid.addComponent(new Label("Vertical spacing:"),3,0); + OrderedLayout layout4 = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); + grid.addComponent(layout4,3,1,3,2); layout4.addStyleName("spacingexample"); layout4.setSpacing(true); layout4.addComponent(new Button("Component 1")); layout4.addComponent(new Button("Component 2")); layout4.addComponent(new Button("Component 3")); - } +} void example_Margin(final Window main, String param) { - OrderedLayout hor = new OrderedLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); + OrderedLayout hor = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); main.setLayout(hor); - + OrderedLayout containinglayout = new OrderedLayout(); hor.addComponent(containinglayout); @@ -1416,16 +1317,15 @@ public class BookTestApplication extends com.itmill.toolkit.Application { // Create a layout OrderedLayout layout2 = new OrderedLayout(); - containinglayout.addComponent(new Label( - "Layout with a special margin element:")); + containinglayout.addComponent(new Label("Layout with a special margin element:")); containinglayout.addComponent(layout2); - + // Set style name for the layout to allow styling it layout2.addStyleName("marginexample2"); - + // Have margin on all sides around the layout layout2.setMargin(true); - + // Put something inside the layout layout2.addComponent(new Button("Component 1")); layout2.addComponent(new Button("Component 2")); @@ -1435,59 +1335,55 @@ public class BookTestApplication extends com.itmill.toolkit.Application { void example_ClientInfo(final Window main, String param) { // Get the client identification string WebApplicationContext context2 = (WebApplicationContext) getContext(); - String browserApplication = context2.getBrowser() - .getBrowserApplication(); - + String browserApplication = context2.getBrowser().getBrowserApplication(); + // Add a browser-dependent style name for the main window if (browserApplication.indexOf("Firefox/2") != -1) main.addStyleName("firefox2"); - + // Display the client identification string main.addComponent(new Label(browserApplication)); } void example_FillInForm(final Window main, String param) { - if (param.equals("templates")) { - // Create a custom layout from the fill-in-form.html template. - CustomLayout fillinlayout = new CustomLayout("fill-in-form"); - - // The style will set the display to be "inline". - fillinlayout.addStyleName("fillinlayout"); - - // Create the fields that occur in the text. - TextField field1 = new TextField(); - TextField field2 = new TextField(); - fillinlayout.addComponent(field1, "q1"); - fillinlayout.addComponent(field2, "q2"); - - main.addComponent(fillinlayout); - } else { - String fillintext = "The <q1> is mightier than <q2>."; - int pos = 0; - while (pos < fillintext.length()) { - int nexttag = fillintext.indexOf("<", pos); - if (nexttag == -1) { - - } - } - } + if (param.equals("templates")) { + // Create a custom layout from the fill-in-form.html template. + CustomLayout fillinlayout = new CustomLayout("fill-in-form"); + + // The style will set the display to be "inline". + fillinlayout.addStyleName("fillinlayout"); + + // Create the fields that occur in the text. + TextField field1 = new TextField(); + TextField field2 = new TextField(); + fillinlayout.addComponent(field1, "q1"); + fillinlayout.addComponent(field2, "q2"); + + main.addComponent(fillinlayout); + } else { + String fillintext = "The <q1> is mightier than <q2>."; + int pos = 0; + while (pos < fillintext.length()) { + int nexttag = fillintext.indexOf("<", pos); + if (nexttag == -1) { + + } + } + } } void example_Notification(final Window main, String param) { final Window sub1 = new Window(""); main.addWindow(sub1); - + sub1.showNotification("The default notification"); - - // Notification notif = new Notification("Title"); + + //Notification notif = new Notification("Title"); } void example_Print(final Window main, String param) { - if (param != null && param.equals("simple")) { - main - .addComponent(new Label( - "<input type='button' onClick='print()' value='Click to Print'/>", - Label.CONTENT_XHTML)); + if (param != null && param.equals("simple")) { + main.addComponent(new Label("<input type='button' onClick='print()' value='Click to Print'/>", Label.CONTENT_XHTML)); return; } @@ -1498,36 +1394,33 @@ public class BookTestApplication extends com.itmill.toolkit.Application { public void buttonClick(ClickEvent event) { // Create a window that contains stuff you want to print. Window printWindow = new Window("Window to Print"); - + // Have some content to print. - printWindow.addComponent(new Label( - "Here's some dynamic content.")); - + printWindow.addComponent(new Label("Here's some dynamic content.")); + // To execute the print() JavaScript, we need to run it // from a custom layout. CustomLayout scriptLayout = new CustomLayout("printpage"); - printWindow.addComponent(scriptLayout); - + printWindow.addComponent (scriptLayout); + // Add the printing window as an application-level window. main.getApplication().addWindow(printWindow); - + // Open the printing window as a new browser window main.open(new ExternalResource(printWindow.getURL()), "_new"); - } + } }); - // main.addComponent(new Label( - // "<p>Print this!</p>\n<script type='text/javascript'>print();</script>" - // , Label.CONTENT_XHTML)); + //main.addComponent(new Label("<p>Print this!</p>\n<script type='text/javascript'>print();</script>", Label.CONTENT_XHTML)); } void example_RichTextField(final Window main, String param) { // Create the rich text area final RichTextArea rtarea = new RichTextArea(); - + // Set initial content as HTML rtarea.setValue("<h1>Hello</h1>\n<p>This contains some text.</p>"); - + // Show the text edited in the rich text area as HTML. final Button show = new Button("Show HTML"); final Label html = new Label((String) rtarea.getValue()); @@ -1546,39 +1439,33 @@ public class BookTestApplication extends com.itmill.toolkit.Application { try { // Create a database connection Class.forName("org.hsqldb.jdbcDriver"); - final Connection connection = DriverManager.getConnection( - "jdbc:hsqldb:mem:qcexample", "sa", ""); - + final Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:qcexample", "sa", ""); + // Create an example table and put some data in it. Statement st = connection.createStatement(); - st - .executeQuery("CREATE TABLE Prisoners (id INTEGER, name VARCHAR)"); + st.executeQuery("CREATE TABLE Prisoners (id INTEGER, name VARCHAR)"); st.close(); - for (int i = 0; i < 100; i++) { + for (int i=0; i<100; i++) { st = connection.createStatement(); - st.executeQuery("INSERT INTO Prisoners (id, name) VALUES (" + i - + ",'I am number " + (i + 1) + "')"); + st.executeQuery("INSERT INTO Prisoners (id, name) VALUES ("+i+",'I am number "+(i+1)+"')"); st.close(); } - + // Query the database - final QueryContainer qc = new QueryContainer( - "SELECT id,name FROM Prisoners", connection); - + final QueryContainer qc = new QueryContainer("SELECT id,name FROM Prisoners", connection); + // Create a component for selecting a query result item. Select select = new Select("Select an item"); - - // The items shown in the selection component are obtained from the - // query. + + // The items shown in the selection component are obtained from the query. select.setContainerDataSource(qc); - - // The item captions are obtained from a field in the query result. + + // The item captions are obtained from a field in the query result. select.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY); - - // Set the name of the field from which the item captions are - // obtained. + + // Set the name of the field from which the item captions are obtained. select.setItemCaptionPropertyId("name"); - + // When selection changes, display the selected item. select.setImmediate(true); final Label selection = new Label("Currently selected: -"); @@ -1586,19 +1473,17 @@ public class BookTestApplication extends com.itmill.toolkit.Application { public void valueChange(ValueChangeEvent event) { // Get the item id of the currently selected item Integer itemId = (Integer) event.getProperty().getValue(); - - // Use the item ID to get the actual row from the query - // result. + + // Use the item ID to get the actual row from the query result. Item qrItem = qc.getItem(itemId); - + // Display the item ID - selection.setValue("Currently selected: result row " - + itemId.intValue() + " (id=" - + qrItem.getItemProperty("id") + ", " + "name=" - + qrItem.getItemProperty("name") + ")"); + selection.setValue("Currently selected: result row "+itemId.intValue() + + " (id="+qrItem.getItemProperty("id")+", " + + "name="+qrItem.getItemProperty("name")+")"); } }); - + main.addComponent(select); main.addComponent(selection); } catch (SQLException e) { @@ -1612,19 +1497,18 @@ public class BookTestApplication extends com.itmill.toolkit.Application { // Create a menu bar final MenuBar menubar = new MenuBar(); main.addComponent(menubar); - + // A feedback component final Label selection = new Label(""); main.addComponent(selection); - + // Define a common menu command for all the menu items. MenuBar.Command mycommand = new MenuBar.Command() { public void menuSelected(MenuItem selectedItem) { - selection.setValue("Ordered a " + selectedItem.getText() - + " from menu."); - } + selection.setValue("Ordered a " + selectedItem.getText() + " from menu."); + } }; - + // Put some items in the menu hierarchically MenuBar.MenuItem beverages = menubar.addItem("Beverages", null, null); MenuBar.MenuItem hot_beverages = beverages.addItem("Hot", null, null); @@ -1632,14 +1516,14 @@ public class BookTestApplication extends com.itmill.toolkit.Application { hot_beverages.addItem("Coffee", null, mycommand); MenuBar.MenuItem cold_beverages = beverages.addItem("Cold", null, null); cold_beverages.addItem("Milk", null, mycommand); - + // Another top-level item MenuBar.MenuItem snacks = menubar.addItem("Snacks", null, null); snacks.addItem("Weisswurst", null, mycommand); snacks.addItem("Salami", null, mycommand); - + // Yet another top-level item MenuBar.MenuItem services = menubar.addItem("Services", null, null); services.addItem("Car Service", null, mycommand); - } + } } |