From 629810d893e10f8081c6d0fe20e31282a9ec745a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marko=20Gr=C3=B6nroos?= Date: Thu, 4 Sep 2008 08:17:50 +0000 Subject: [PATCH] Reverted mass formatting done in [5331] for book examples. svn changeset:5357/svn branch:trunk --- .../tests/book/BookTestApplication.java | 708 ++++++++---------- .../toolkit/tests/book/ChatApplication.java | 53 +- .../tests/book/DefaultButtonExample.java | 21 +- .../toolkit/tests/book/FormExample.java | 25 +- .../toolkit/tests/book/FormExample2.java | 7 +- .../toolkit/tests/book/MyDynamicResource.java | 35 +- .../itmill/toolkit/tests/book/MyUploader.java | 24 +- .../itmill/toolkit/tests/book/SSNField.java | 13 +- .../toolkit/tests/book/TableCellStyle.java | 44 +- .../toolkit/tests/book/TableEditable.java | 37 +- .../toolkit/tests/book/TableEditableBean.java | 117 ++- .../toolkit/tests/book/TableExample.java | 37 +- .../toolkit/tests/book/TableExample1.java | 34 +- .../toolkit/tests/book/TableExample2.java | 43 +- .../toolkit/tests/book/TableExample3.java | 59 +- .../itmill/toolkit/tests/book/TableHuge.java | 24 +- .../toolkit/tests/book/WindowOpener.java | 16 +- .../tests/book/WindowTestApplication.java | 36 +- 18 files changed, 574 insertions(+), 759 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("" - + examples[i] + "", Label.CONTENT_XHTML)); + grid.addComponent(new Label("" + examples[i] + "", + 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", - Label.CONTENT_XHTML)); + if (param != null && param.equals("simple")) { + main.addComponent(new Label("", 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( - // "

Print this!

\n" - // , Label.CONTENT_XHTML)); + //main.addComponent(new Label("

Print this!

\n", 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("

Hello

\n

This contains some text.

"); - + // 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); - } + } } diff --git a/src/com/itmill/toolkit/tests/book/ChatApplication.java b/src/com/itmill/toolkit/tests/book/ChatApplication.java index 7ff510a26c..eaea83062c 100644 --- a/src/com/itmill/toolkit/tests/book/ChatApplication.java +++ b/src/com/itmill/toolkit/tests/book/ChatApplication.java @@ -1,36 +1,26 @@ package com.itmill.toolkit.tests.book; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - +import java.util.*; import com.itmill.toolkit.Application; -import com.itmill.toolkit.ui.Button; -import com.itmill.toolkit.ui.ProgressIndicator; -import com.itmill.toolkit.ui.Table; -import com.itmill.toolkit.ui.TextField; -import com.itmill.toolkit.ui.Window; +import com.itmill.toolkit.ui.*; import com.itmill.toolkit.ui.Button.ClickEvent; -public class ChatApplication extends Application implements - Button.ClickListener { - /* - * ChatApplication instances of different users. Warning: a hack, not safe, - * because sessions can expire. - */ +public class ChatApplication extends Application implements Button.ClickListener { + /* ChatApplication instances of different users. + * Warning: a hack, not safe, because sessions can expire. */ static List users = new ArrayList(); - + /* Messages as a shared list. */ - static List messages = new ArrayList(); - int localSize = 0; + static List messages = new ArrayList(); + int localSize = 0; /* User interface. */ - Table messageTable = new Table(); - TextField username = new TextField("Username:"); - TextField message = new TextField("Message:"); + Table messageTable = new Table(); + TextField username = new TextField("Username:"); + TextField message = new TextField("Message:"); public void init() { - final Window main = new Window("Chat"); + final Window main = new Window ("Chat"); setMainWindow(main); setTheme("tests-magi"); users.add(this); @@ -41,9 +31,9 @@ public class ChatApplication extends Application implements messageTable.addContainerProperty("Sender", String.class, ""); messageTable.addContainerProperty("Message", String.class, ""); updateTable(); - + main.addComponent(message); - + Button send = new Button("Send"); send.addListener(this); main.addComponent(send); @@ -55,15 +45,14 @@ public class ChatApplication extends Application implements } public void buttonClick(ClickEvent event) { - synchronized (users) { + synchronized(users) { // Create the new message in the shared list. - messages.add(new String[] { - new String((String) username.getValue()), - new String((String) message.getValue()) }); + messages.add(new String[]{new String((String) username.getValue()), + new String((String) message.getValue())}); // Update the message tables for all users. - for (Iterator i = users.iterator(); i.hasNext();) - ((ChatApplication) i.next()).updateTable(); + for (Iterator i = users.iterator();i.hasNext();) + ((ChatApplication)i.next()).updateTable(); } } @@ -73,7 +62,7 @@ public class ChatApplication extends Application implements // Add new messages to the table while (localSize < messages.size()) - messageTable.addItem((Object[]) messages.get(localSize++), - new Integer(localSize - 1)); + messageTable.addItem((Object[])messages.get(localSize++), + new Integer(localSize-1)); } } diff --git a/src/com/itmill/toolkit/tests/book/DefaultButtonExample.java b/src/com/itmill/toolkit/tests/book/DefaultButtonExample.java index 31db87beeb..2ed44785bd 100644 --- a/src/com/itmill/toolkit/tests/book/DefaultButtonExample.java +++ b/src/com/itmill/toolkit/tests/book/DefaultButtonExample.java @@ -7,6 +7,7 @@ package com.itmill.toolkit.tests.book; 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; @@ -24,8 +25,7 @@ public class DefaultButtonExample extends CustomComponent implements Handler { TextField password = new TextField("Password"); 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. Button ok = new Button("OK", this, "okHandler"); @@ -33,12 +33,13 @@ public class DefaultButtonExample extends CustomComponent implements Handler { // Have the unmodified Enter key cause an event Action action_ok = new ShortcutAction("Default key", - ShortcutAction.KeyCode.ENTER, null); + 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 }); + ShortcutAction.KeyCode.C, + new int[] { ShortcutAction.ModifierKey.ALT }); Window window = null; @@ -72,7 +73,7 @@ public class DefaultButtonExample extends CustomComponent implements Handler { */ public Action[] getActions(Object target, Object sender) { System.out.println("getActions()"); - return new Action[] { action_ok, action_cancel }; + return new Action[] {action_ok, action_cancel}; } /** @@ -88,14 +89,14 @@ public class DefaultButtonExample extends CustomComponent implements Handler { public void okHandler() { // Do something: report the click - formlayout.addComponent(new Label("OK clicked. " + "User=" - + username.getValue() + ", password=" + password.getValue())); + 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. User=" - + username.getValue() + ", password=" + password.getValue())); + formlayout.addComponent(new Label("Cancel clicked. User="+username.getValue()+", password="+password.getValue())); } } diff --git a/src/com/itmill/toolkit/tests/book/FormExample.java b/src/com/itmill/toolkit/tests/book/FormExample.java index de7bb91420..2125888004 100644 --- a/src/com/itmill/toolkit/tests/book/FormExample.java +++ b/src/com/itmill/toolkit/tests/book/FormExample.java @@ -30,9 +30,9 @@ import com.itmill.toolkit.ui.TextField; public class FormExample extends CustomComponent { /** Contact information data model. */ public class Contact { - String name = ""; - String address = ""; - int postalCode = 20540; + String name = ""; + String address = ""; + int postalCode = 20540; String city; } @@ -104,10 +104,10 @@ public class FormExample extends CustomComponent { if (pid.equals("name")) return new TextField("Name"); - + if (pid.equals("address")) return new TextField("Street Address"); - + if (pid.equals("postalCode")) { TextField field = new TextField("Postal Code"); field.setColumns(5); @@ -121,8 +121,7 @@ public class FormExample extends CustomComponent { return ((String) value).matches("[0-9]{5}"); } - public void validate(Object value) - throws InvalidValueException { + public void validate(Object value) throws InvalidValueException { if (!isValid(value)) { throw new InvalidValueException( "Postal code must be a number 10000-99999."); @@ -132,7 +131,7 @@ public class FormExample extends CustomComponent { field.addValidator(postalCodeValidator); return field; } - + if (pid.equals("city")) { Select select = new Select("City"); final String cities[] = new String[] { "Amsterdam", "Berlin", @@ -158,8 +157,7 @@ public class FormExample extends CustomComponent { // Set form caption and description texts. form.setCaption("Contact Information"); - form - .setDescription("Please enter valid name and address. Fields marked with * are required."); + form.setDescription("Please enter valid name and address. Fields marked with * are required."); // Use custom field factory to create the fields in the form. form.setFieldFactory(new MyFieldFactory()); @@ -193,7 +191,7 @@ public class FormExample extends CustomComponent { // necessary for the validation of the fields to occur immediately when // the input focus changes and not just on commit. form.setImmediate(true); - + // Set buffering so that commit() must be called for the form // before input is written to the data. (Input is not written // immediately through). @@ -201,8 +199,7 @@ public class FormExample extends CustomComponent { form.setReadThrough(false); // Add Commit and Discard controls to the form. - ExpandLayout footer = new ExpandLayout( - OrderedLayout.ORIENTATION_HORIZONTAL); + ExpandLayout footer = new ExpandLayout(OrderedLayout.ORIENTATION_HORIZONTAL); // The Commit button calls form.commit(). Button commit = new Button("Commit", form, "commit"); @@ -211,7 +208,7 @@ public class FormExample extends CustomComponent { Button discard = new Button("Discard", form, "discard"); footer.addComponent(commit); footer.setComponentAlignment(commit, ExpandLayout.ALIGNMENT_RIGHT, - ExpandLayout.ALIGNMENT_TOP); + ExpandLayout.ALIGNMENT_TOP); footer.setHeight("25px"); footer.addComponent(discard); form.setFooter(footer); diff --git a/src/com/itmill/toolkit/tests/book/FormExample2.java b/src/com/itmill/toolkit/tests/book/FormExample2.java index a44ba15181..8d9c0e86e2 100644 --- a/src/com/itmill/toolkit/tests/book/FormExample2.java +++ b/src/com/itmill/toolkit/tests/book/FormExample2.java @@ -29,7 +29,7 @@ public class FormExample2 extends CustomComponent { public class PersonBean { String name = ""; String city = ""; - + public void setName(String name) { this.name = name; } @@ -91,8 +91,7 @@ public class FormExample2 extends CustomComponent { // Set form caption and description texts form.setCaption("Contact Information"); - form - .setDescription("Please specify name of the person and the city where the person lives in."); + form.setDescription("Please specify name of the person and the city where the person lives in."); // Use the custom field factory to create the fields in the form. form.setFieldFactory(new MyFieldFactory()); @@ -111,7 +110,7 @@ public class FormExample2 extends CustomComponent { order.add("name"); order.add("city"); form.setVisibleItemProperties(order); - + form.getField("name").setRequired(true); form.getField("name").setRequiredError("You must enter a name."); form.getField("city").setRequired(true); diff --git a/src/com/itmill/toolkit/tests/book/MyDynamicResource.java b/src/com/itmill/toolkit/tests/book/MyDynamicResource.java index 4c27700729..34ca740a8f 100644 --- a/src/com/itmill/toolkit/tests/book/MyDynamicResource.java +++ b/src/com/itmill/toolkit/tests/book/MyDynamicResource.java @@ -1,19 +1,12 @@ package com.itmill.toolkit.tests.book; -import java.awt.Color; -import java.awt.Graphics; +import java.awt.*; import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; +import java.io.*; import java.net.URL; import java.util.Map; - import javax.imageio.ImageIO; - -import com.itmill.toolkit.terminal.DownloadStream; -import com.itmill.toolkit.terminal.ParameterHandler; -import com.itmill.toolkit.terminal.URIHandler; +import com.itmill.toolkit.terminal.*; /** * Demonstrates handling URI parameters and the URI itself to create a dynamic @@ -28,7 +21,7 @@ public class MyDynamicResource implements URIHandler, ParameterHandler { public void handleParameters(Map parameters) { // Get and store the passed HTTP parameter. if (parameters.containsKey("text")) - textToDisplay = ((String[]) parameters.get("text"))[0]; + textToDisplay = ((String[])parameters.get("text"))[0]; } /** @@ -43,21 +36,20 @@ public class MyDynamicResource implements URIHandler, ParameterHandler { // URI handlers or the Application to handle the response. if (!relativeUri.startsWith("myresource")) return null; - + // Create an image and draw some background on it. - BufferedImage image = new BufferedImage(200, 200, - BufferedImage.TYPE_INT_RGB); + BufferedImage image = new BufferedImage (200, 200, BufferedImage.TYPE_INT_RGB); Graphics drawable = image.getGraphics(); drawable.setColor(Color.lightGray); - drawable.fillRect(0, 0, 200, 200); + drawable.fillRect(0,0,200,200); drawable.setColor(Color.yellow); - drawable.fillOval(25, 25, 150, 150); + drawable.fillOval(25,25,150,150); drawable.setColor(Color.blue); - drawable.drawRect(0, 0, 199, 199); - + drawable.drawRect(0,0,199,199); + // Use the parameter to create dynamic content. drawable.setColor(Color.black); - drawable.drawString("Text: " + textToDisplay, 75, 100); + drawable.drawString("Text: "+textToDisplay, 75, 100); try { // Write the image to a buffer. @@ -65,9 +57,8 @@ public class MyDynamicResource implements URIHandler, ParameterHandler { ImageIO.write(image, "png", imagebuffer); // Return a stream from the buffer. - ByteArrayInputStream istream = new ByteArrayInputStream(imagebuffer - .toByteArray()); - return new DownloadStream(istream, null, null); + ByteArrayInputStream istream = new ByteArrayInputStream(imagebuffer.toByteArray()); + return new DownloadStream (istream,null,null); } catch (IOException e) { return null; } diff --git a/src/com/itmill/toolkit/tests/book/MyUploader.java b/src/com/itmill/toolkit/tests/book/MyUploader.java index 2702bbf087..a9215f09b5 100644 --- a/src/com/itmill/toolkit/tests/book/MyUploader.java +++ b/src/com/itmill/toolkit/tests/book/MyUploader.java @@ -9,17 +9,13 @@ import java.io.FileOutputStream; import java.io.OutputStream; import com.itmill.toolkit.terminal.FileResource; -import com.itmill.toolkit.ui.CustomComponent; -import com.itmill.toolkit.ui.Embedded; -import com.itmill.toolkit.ui.Label; -import com.itmill.toolkit.ui.Panel; -import com.itmill.toolkit.ui.Upload; +import com.itmill.toolkit.ui.*; -public class MyUploader extends CustomComponent implements - Upload.SucceededListener, Upload.FailedListener, Upload.Receiver { - Panel root; // Root element for contained components. - Panel imagePanel; // Panel that contains the uploaded image. - File file; // File to write to. +public class MyUploader extends CustomComponent +implements Upload.SucceededListener, Upload.FailedListener, Upload.Receiver { + Panel root; // Root element for contained components. + Panel imagePanel; // Panel that contains the uploaded image. + File file; // File to write to. MyUploader() { root = new Panel("My Upload Component"); @@ -34,8 +30,7 @@ public class MyUploader extends CustomComponent implements upload.addListener((Upload.FailedListener) this); root.addComponent(upload); - root.addComponent(new Label( - "Click 'Browse' to select a file and then click 'Upload'.")); + root.addComponent(new Label("Click 'Browse' to select a file and then click 'Upload'.")); // Create a panel for displaying the uploaded file (image). imagePanel = new Panel("Uploaded image"); @@ -64,10 +59,9 @@ public class MyUploader extends CustomComponent implements // Log the upload on screen. root.addComponent(new Label("File " + event.getFilename() + " of type '" + event.getMIMEType() + "' uploaded.")); - + // Display the uploaded file in the image panel. - final FileResource imageResource = new FileResource(file, - getApplication()); + final FileResource imageResource = new FileResource(file, getApplication()); imagePanel.removeAllComponents(); imagePanel.addComponent(new Embedded("", imageResource)); } diff --git a/src/com/itmill/toolkit/tests/book/SSNField.java b/src/com/itmill/toolkit/tests/book/SSNField.java index 9b5a39380b..0659ebb910 100644 --- a/src/com/itmill/toolkit/tests/book/SSNField.java +++ b/src/com/itmill/toolkit/tests/book/SSNField.java @@ -4,6 +4,8 @@ package com.itmill.toolkit.tests.book; +import java.text.MessageFormat; + import com.itmill.toolkit.data.Property; import com.itmill.toolkit.data.Validator; import com.itmill.toolkit.data.Property.ValueChangeEvent; @@ -17,8 +19,7 @@ import com.itmill.toolkit.ui.TextField; public class SSNField extends CustomComponent implements Property.ValueChangeListener { OrderedLayout layout = new FormLayout(); - // new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); //;new - // FormLayout(); + // new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL); //;new FormLayout(); TextField myfield; Label myerror; @@ -39,7 +40,7 @@ public class SSNField extends CustomComponent implements public void validate(Object value) throws InvalidValueException { final String ssn = (String) value; if (ssn.length() == 0) - return; + return; if (ssn.length() != 11) throw new InvalidValueException("Invalid SSN length"); @@ -65,10 +66,8 @@ public class SSNField extends CustomComponent implements /* Create and set the validator object for the field. */ myfield.addValidator(new SSNValidator()); - /* - * ValueChageEvent will be generated immediately when the component - * loses focus. - */ + /* ValueChageEvent will be generated immediately when the component + loses focus. */ myfield.setImmediate(true); /* Listen for ValueChangeEvent events. */ diff --git a/src/com/itmill/toolkit/tests/book/TableCellStyle.java b/src/com/itmill/toolkit/tests/book/TableCellStyle.java index 29190f0f3d..ddb8872a13 100644 --- a/src/com/itmill/toolkit/tests/book/TableCellStyle.java +++ b/src/com/itmill/toolkit/tests/book/TableCellStyle.java @@ -11,48 +11,42 @@ public class TableCellStyle extends CustomComponent { public TableCellStyle() { Table table = new Table("Table with Cell Styles"); table.addStyleName("checkerboard"); - + // Add some columns in the table. In this example, the property IDs // of the container are integers so we can determine the column number // easily. - table.addContainerProperty("0", String.class, null, "", null, null); // Row - // header - for (int i = 0; i < 8; i++) - table.addContainerProperty("" + (i + 1), String.class, null, String - .valueOf((char) (65 + i)), null, null); - + table.addContainerProperty("0", String.class, null, "", null, null); // Row header + for (int i=0; i<8; i++) + table.addContainerProperty(""+(i+1), String.class, null, + String.valueOf((char) (65+i)), null, null); + // Add some items in the table. - table.addItem(new Object[] { "1", "R", "N", "B", "Q", "K", "B", "N", - "R" }, new Integer(0)); - table.addItem(new Object[] { "2", "P", "P", "P", "P", "P", "P", "P", - "P" }, new Integer(1)); - for (int i = 2; i < 6; i++) - table.addItem(new Object[] { String.valueOf(i + 1), "", "", "", "", - "", "", "", "" }, new Integer(i)); - table.addItem(new Object[] { "7", "P", "P", "P", "P", "P", "P", "P", - "P" }, new Integer(6)); - table.addItem(new Object[] { "8", "R", "N", "B", "Q", "K", "B", "N", - "R" }, new Integer(7)); + table.addItem(new Object[]{"1", "R", "N", "B", "Q", "K", "B", "N", "R"}, new Integer(0)); + table.addItem(new Object[]{"2", "P", "P", "P", "P", "P", "P", "P", "P"}, new Integer(1)); + for (int i=2; i<6; i++) + table.addItem(new Object[]{String.valueOf(i+1), "", "", "", "", "", "", "", ""}, new Integer(i)); + table.addItem(new Object[]{"7", "P", "P", "P", "P", "P", "P", "P", "P"}, new Integer(6)); + table.addItem(new Object[]{"8", "R", "N", "B", "Q", "K", "B", "N", "R"}, new Integer(7)); table.setPageLength(8); - + // Set cell style generator table.setCellStyleGenerator(new Table.CellStyleGenerator() { public String getStyle(Object itemId, Object propertyId) { - int row = ((Integer) itemId).intValue(); - int col = Integer.parseInt((String) propertyId); - + int row = ((Integer)itemId).intValue(); + int col = Integer.parseInt((String)propertyId); + // The first column. if (col == 0) return "rowheader"; - + // Other cells. - if ((row + col) % 2 == 1) + if ((row+col)%2 == 1) return "black"; else return "white"; } }); - + setCompositionRoot(table); } } diff --git a/src/com/itmill/toolkit/tests/book/TableEditable.java b/src/com/itmill/toolkit/tests/book/TableEditable.java index 5941d474ba..76c4f4e100 100644 --- a/src/com/itmill/toolkit/tests/book/TableEditable.java +++ b/src/com/itmill/toolkit/tests/book/TableEditable.java @@ -10,45 +10,50 @@ import java.util.GregorianCalendar; import com.itmill.toolkit.data.Property; import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.CheckBox; import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Label; import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.RichTextArea; import com.itmill.toolkit.ui.Table; +import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.Button.ClickEvent; public class TableEditable extends CustomComponent { /* A layout needed for the example. */ OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - + TableEditable() { setCompositionRoot(layout); // Create a table. It is by default not editable. final Table table = new Table(); - + // Define the names and data types of columns. - table.addContainerProperty("Date", Date.class, null); - table.addContainerProperty("Work", Boolean.class, null); - table.addContainerProperty("Comments", String.class, null); - + table.addContainerProperty("Date", Date.class, null); + table.addContainerProperty("Work", Boolean.class, null); + table.addContainerProperty("Comments", String.class, null); + // Add a few items in the table. - for (int i = 0; i < 100; i++) { - Calendar calendar = new GregorianCalendar(2008, 0, 1); + for (int i=0; i<100; i++) { + Calendar calendar = new GregorianCalendar(2008,0,1); calendar.add(Calendar.DAY_OF_YEAR, i); - + // Create the table row. - table.addItem(new Object[] { calendar.getTime(), - new Boolean(false), "" }, new Integer(i)); // Item - // identifier + table.addItem(new Object[] {calendar.getTime(), + new Boolean(false), + ""}, + new Integer(i)); // Item identifier } - + table.setPageLength(8); layout.addComponent(table); - + final CheckBox switchEditable = new CheckBox("Editable"); switchEditable.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - table.setEditable(((Boolean) event.getProperty().getValue()) - .booleanValue()); + table.setEditable(((Boolean)event.getProperty().getValue()).booleanValue()); } }); switchEditable.setImmediate(true); diff --git a/src/com/itmill/toolkit/tests/book/TableEditableBean.java b/src/com/itmill/toolkit/tests/book/TableEditableBean.java index f8fd7ebd8f..1029eabee2 100644 --- a/src/com/itmill/toolkit/tests/book/TableEditableBean.java +++ b/src/com/itmill/toolkit/tests/book/TableEditableBean.java @@ -22,29 +22,29 @@ import com.itmill.toolkit.ui.OrderedLayout; import com.itmill.toolkit.ui.Table; /** - * Shows how to bind a bean to a table and make it editable. + * Shows how to bind a bean to a table and make it editable. */ public class TableEditableBean extends CustomComponent { /** * Let's have a simple example bean. */ - public class MyBean { - boolean selected; - String text; - - public MyBean() { - this.selected = false; - this.text = ""; - } - - public boolean isSelected() { - System.out.println("isSelected() called: " + selected); + public class MyBean { + boolean selected; + String text; + + public MyBean() { + this.selected = false; + this.text = ""; + } + + public boolean isSelected() { + System.out.println("isSelected() called: " + selected); return selected; } public void setSelected(boolean selected) { this.selected = selected; - System.out.println("setSelected1(" + selected + ") called."); + System.out.println("setSelected1("+selected+") called."); } public String getText() { @@ -54,26 +54,26 @@ public class TableEditableBean extends CustomComponent { public void setText(String text) { this.text = text; - System.out.println("setText(" + text + ") called."); + System.out.println("setText("+text+") called."); } - }; + }; /** * Custom field factory that sets the fields as immediate for debugging * purposes. This is not normally necessary, unless you want to have some * interaction that requires it. */ - public class MyFieldFactory extends BaseFieldFactory { - public Field createField(Class type, Component uiContext) { - // Let the BaseFieldFactory create the fields - Field field = super.createField(type, uiContext); - - // ...and just set them as immediate - ((AbstractField) field).setImmediate(true); - + public class MyFieldFactory extends BaseFieldFactory { + public Field createField(Class type, Component uiContext) { + // Let the BaseFieldFactory create the fields + Field field = super.createField(type, uiContext); + + // ...and just set them as immediate + ((AbstractField)field).setImmediate(true); + return field; - } - } + } + } /** * This is a custom container that allows adding BeanItems inside it. The @@ -83,13 +83,13 @@ public class TableEditableBean extends CustomComponent { * Most of the interface methods are implemented with just dummy * implementations, as they are not needed in this example. */ - public class MyContainer implements Container { + public class MyContainer implements Container { Item[] items; - int current = 0; - - public MyContainer() { - items = new Item[100]; // Yeah this is just a test - } + int current = 0; + + public MyContainer() { + items = new Item[100]; // Yeah this is just a test + } public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException { @@ -105,8 +105,8 @@ public class TableEditableBean extends CustomComponent { } /** - * This addItem method is specific for this container and allows adding - * BeanItem objects. The BeanItems must be bound to MyBean objects. + * This addItem method is specific for this container and allows adding + * BeanItem objects. The BeanItems must be bound to MyBean objects. */ public void addItem(BeanItem item) throws UnsupportedOperationException { items[current++] = item; @@ -114,7 +114,7 @@ public class TableEditableBean extends CustomComponent { public boolean containsId(Object itemId) { if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); + int pos = ((Integer)itemId).intValue(); if (pos >= 0 && pos < 100) return items[pos] != null; } @@ -128,10 +128,10 @@ public class TableEditableBean extends CustomComponent { */ public Property getContainerProperty(Object itemId, Object propertyId) { if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); + int pos = ((Integer)itemId).intValue(); if (pos >= 0 && pos < 100) { Item item = items[pos]; - + // The BeanItem provides the property objects for the items. return item.getItemProperty(propertyId); } @@ -143,14 +143,14 @@ public class TableEditableBean extends CustomComponent { public Collection getContainerPropertyIds() { // This container can contain only BeanItems bound to MyBeans. Item item = new BeanItem(new MyBean()); - + // The BeanItem knows how to get the property names from the bean. return item.getItemPropertyIds(); } public Item getItem(Object itemId) { if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); + int pos = ((Integer)itemId).intValue(); if (pos >= 0 && pos < 100) return items[pos]; } @@ -159,7 +159,7 @@ public class TableEditableBean extends CustomComponent { public Collection getItemIds() { Vector ids = new Vector(); - for (int i = 0; i < 100; i++) + for (int i=0; i<100; i++) ids.add(Integer.valueOf(i)); return ids; } @@ -185,51 +185,48 @@ public class TableEditableBean extends CustomComponent { public int size() { return current; } - - } + + } TableEditableBean() { /* A layout needed for the example. */ - OrderedLayout layout = new OrderedLayout( - OrderedLayout.ORIENTATION_VERTICAL); + OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); setCompositionRoot(layout); // Create a table. It is by default not editable. final Table table = new Table(); layout.addComponent(table); table.setPageLength(8); - + // Use the custom container as the data source MyContainer myContainer = new MyContainer(); table.setContainerDataSource(myContainer); - + // Add a few items in the table. - for (int i = 0; i < 5; i++) { + for (int i=0; i<5; i++) { // Create the bean - MyBean item = new MyBean(); - item.setText("MyBean " + i); - - // Have an Item that is bound to the bean - BeanItem bitem = new BeanItem(item); - - // Add the item directly to the container using the custom addItem() + MyBean item = new MyBean(); + item.setText("MyBean " + i); + + // Have an Item that is bound to the bean + BeanItem bitem = new BeanItem(item); + + // Add the item directly to the container using the custom addItem() // method. We could otherwise add it to the Table as well, but // the Container interface of Table does not allow adding items - // as such, just item IDs. - myContainer.addItem(bitem); + // as such, just item IDs. + myContainer.addItem(bitem); } - + // Use custom field factory that sets the checkboxes in immediate mode. // This is just for debugging purposes and is not normally necessary. table.setFieldFactory(new MyFieldFactory()); - // Have a check box to switch the table between normal and editable - // mode. + // Have a check box to switch the table between normal and editable mode. final CheckBox switchEditable = new CheckBox("Editable"); switchEditable.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { - table.setEditable(((Boolean) event.getProperty().getValue()) - .booleanValue()); + table.setEditable(((Boolean)event.getProperty().getValue()).booleanValue()); } }); switchEditable.setImmediate(true); diff --git a/src/com/itmill/toolkit/tests/book/TableExample.java b/src/com/itmill/toolkit/tests/book/TableExample.java index 4d888eaeae..80c5dad3b0 100644 --- a/src/com/itmill/toolkit/tests/book/TableExample.java +++ b/src/com/itmill/toolkit/tests/book/TableExample.java @@ -26,28 +26,22 @@ public class TableExample extends CustomComponent { layout.addComponent(table); /* Define the names, data types, and default values of columns. */ - table.addContainerProperty("First Name", String.class, - "(no first name)"); - table.addContainerProperty("Last Name", String.class, "(no last name)"); - table.addContainerProperty("Year", Integer.class, null); + table.addContainerProperty("First Name", String.class, "(no first name)"); + table.addContainerProperty("Last Name", String.class, "(no last name)"); + table.addContainerProperty("Year", Integer.class, null); /* We use these entries to generate random items in a table. */ - final String[] firstnames = new String[] { "Donald", "Patty", "Sally", - "Douglas" }; - final String[] lastnames = new String[] { "Smith", "Jones", "Adams", - "Knuth" }; + final String[] firstnames = new String[] { "Donald", "Patty", "Sally", "Douglas" }; + final String[] lastnames = new String[] { "Smith", "Jones", "Adams", "Knuth" }; /* Add some items in the table and assign them an Item ID (IID). */ for (int i = 0; i < 1000; i++) { /* Add a randomly generated item in the Table. */ - table - .addItem( - new Object[] { - firstnames[(int) (Math.random() * (firstnames.length - 0.01))], - lastnames[(int) (Math.random() * (lastnames.length - 0.01))], - new Integer( - (int) (1900 + Math.random() * 100)) }, - new Integer(i)); + table.addItem(new Object[] { + firstnames[(int) (Math.random() * (firstnames.length - 0.01))], + lastnames[(int) (Math.random() * (lastnames.length - 0.01))], + new Integer((int) (1900 + Math.random() * 100)) }, + new Integer(i)); } /* Set the number of items visible in the table. */ @@ -59,20 +53,17 @@ public class TableExample extends CustomComponent { /* Allow selecting items from the table. */ table.setSelectable(true); - - /* - * When an item is selected, the selection is sent immediately to - * server. - */ + + /* When an item is selected, the selection is sent immediately to server. */ table.setImmediate(true); - + /* Handle selection change. */ table.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { current.setValue("Selected: " + table.getValue().toString()); } }); - + layout.addComponent(current); } } diff --git a/src/com/itmill/toolkit/tests/book/TableExample1.java b/src/com/itmill/toolkit/tests/book/TableExample1.java index cf9ad1d438..52d1513394 100644 --- a/src/com/itmill/toolkit/tests/book/TableExample1.java +++ b/src/com/itmill/toolkit/tests/book/TableExample1.java @@ -17,29 +17,21 @@ public class TableExample1 extends CustomComponent { /* Create the table with a caption. */ Table table = new Table("This is my Table"); - - /* - * Define the names and data types of columns. The "default value" - * parameter is meaningless here. - */ - table.addContainerProperty("First Name", String.class, null); - table.addContainerProperty("Last Name", String.class, null); - table.addContainerProperty("Year", Integer.class, null); + + /* Define the names and data types of columns. + * The "default value" parameter is meaningless here. */ + table.addContainerProperty("First Name", String.class, null); + table.addContainerProperty("Last Name", String.class, null); + table.addContainerProperty("Year", Integer.class, null); /* Add a few items in the table. */ - table.addItem(new Object[] { "Nicolaus", "Copernicus", - new Integer(1473) }, new Integer(1)); - table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) }, - new Integer(2)); - table.addItem(new Object[] { "Giordano", "Bruno", new Integer(1548) }, - new Integer(3)); - table.addItem(new Object[] { "Galileo", "Galilei", new Integer(1564) }, - new Integer(4)); - table.addItem(new Object[] { "Johannes", "Kepler", new Integer(1571) }, - new Integer(5)); - table.addItem(new Object[] { "Isaac", "Newton", new Integer(1643) }, - new Integer(6)); - + table.addItem(new Object[] {"Nicolaus","Copernicus",new Integer(1473)}, new Integer(1)); + table.addItem(new Object[] {"Tycho", "Brahe", new Integer(1546)}, new Integer(2)); + table.addItem(new Object[] {"Giordano","Bruno", new Integer(1548)}, new Integer(3)); + table.addItem(new Object[] {"Galileo", "Galilei", new Integer(1564)}, new Integer(4)); + table.addItem(new Object[] {"Johannes","Kepler", new Integer(1571)}, new Integer(5)); + table.addItem(new Object[] {"Isaac", "Newton", new Integer(1643)}, new Integer(6)); + /* Set number of visible rows. */ table.setPageLength(5); diff --git a/src/com/itmill/toolkit/tests/book/TableExample2.java b/src/com/itmill/toolkit/tests/book/TableExample2.java index 3472300123..f82c96c68d 100644 --- a/src/com/itmill/toolkit/tests/book/TableExample2.java +++ b/src/com/itmill/toolkit/tests/book/TableExample2.java @@ -14,45 +14,34 @@ import com.itmill.toolkit.ui.Table; public class TableExample2 extends CustomComponent { /* A layout needed for the example. */ OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - + TableExample2() { setCompositionRoot(layout); /* Create the table with a caption. */ final Table table = new Table(); - - /* - * Define the names and data types of columns. The "default value" - * parameter is meaningless here. - */ - table.addContainerProperty("First Name", String.class, null); - table.addContainerProperty("Last Name", String.class, null); - table.addContainerProperty("Year", Integer.class, null); + + /* Define the names and data types of columns. + * The "default value" parameter is meaningless here. */ + table.addContainerProperty("First Name", String.class, null); + table.addContainerProperty("Last Name", String.class, null); + table.addContainerProperty("Year", Integer.class, null); /* Add a few items in the table. */ - table.addItem(new Object[] { "Nicolaus", "Copernicus", - new Integer(1473) }, new Integer(1)); - table.addItem(new Object[] { "Tycho", "Brahe", new Integer(1546) }, - new Integer(2)); - table.addItem(new Object[] { "Giordano", "Bruno", new Integer(1548) }, - new Integer(3)); - table.addItem(new Object[] { "Galileo", "Galilei", new Integer(1564) }, - new Integer(4)); - table.addItem(new Object[] { "Johannes", "Kepler", new Integer(1571) }, - new Integer(5)); - table.addItem(new Object[] { "Isaac", "Newton", new Integer(1643) }, - new Integer(6)); - + table.addItem(new Object[] {"Nicolaus","Copernicus",new Integer(1473)}, new Integer(1)); + table.addItem(new Object[] {"Tycho", "Brahe", new Integer(1546)}, new Integer(2)); + table.addItem(new Object[] {"Giordano","Bruno", new Integer(1548)}, new Integer(3)); + table.addItem(new Object[] {"Galileo", "Galilei", new Integer(1564)}, new Integer(4)); + table.addItem(new Object[] {"Johannes","Kepler", new Integer(1571)}, new Integer(5)); + table.addItem(new Object[] {"Isaac", "Newton", new Integer(1643)}, new Integer(6)); + /* Set number of visible rows. */ table.setPageLength(5); /* Allow selecting items from the table. */ table.setSelectable(true); - - /* - * When an item is selected, the selection is sent immediately to - * server. - */ + + /* When an item is selected, the selection is sent immediately to server. */ table.setImmediate(true); /* Feedback from selection. */ diff --git a/src/com/itmill/toolkit/tests/book/TableExample3.java b/src/com/itmill/toolkit/tests/book/TableExample3.java index 152d0ed4c9..cf20a8bf49 100644 --- a/src/com/itmill/toolkit/tests/book/TableExample3.java +++ b/src/com/itmill/toolkit/tests/book/TableExample3.java @@ -4,11 +4,14 @@ package com.itmill.toolkit.tests.book; +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.data.Property.ValueChangeEvent; import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.CheckBox; import com.itmill.toolkit.ui.CustomComponent; import com.itmill.toolkit.ui.Label; import com.itmill.toolkit.ui.OrderedLayout; +import com.itmill.toolkit.ui.RichTextArea; import com.itmill.toolkit.ui.Table; import com.itmill.toolkit.ui.TextField; import com.itmill.toolkit.ui.Button.ClickEvent; @@ -16,41 +19,37 @@ import com.itmill.toolkit.ui.Button.ClickEvent; public class TableExample3 extends CustomComponent { /* A layout needed for the example. */ OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL); - + TableExample3() { setCompositionRoot(layout); - // Create a table and add a style to allow setting the row height in - // theme. + // Create a table and add a style to allow setting the row height in theme. final Table table = new Table(); table.addStyleName("components-inside"); - - /* - * Define the names and data types of columns. The "default value" - * parameter is meaningless here. - */ - table.addContainerProperty("Sum", Label.class, null); - table.addContainerProperty("Is Transferred", CheckBox.class, null); - table.addContainerProperty("Comments", TextField.class, null); - table.addContainerProperty("Details", Button.class, null); - + + /* Define the names and data types of columns. + * The "default value" parameter is meaningless here. */ + table.addContainerProperty("Sum", Label.class, null); + table.addContainerProperty("Is Transferred", CheckBox.class, null); + table.addContainerProperty("Comments", TextField.class, null); + table.addContainerProperty("Details", Button.class, null); + /* Add a few items in the table. */ - for (int i = 0; i < 100; i++) { + for (int i=0; i<100; i++) { // Create the fields for the current table row - Label sumField = new Label(String.format( - "Sum is $%04.2f
(VAT incl.)", - new Object[] { new Double(Math.random() * 1000) }), - Label.CONTENT_XHTML); + Label sumField = new Label(String.format("Sum is $%04.2f
(VAT incl.)", + new Object[] {new Double(Math.random()*1000)}), + Label.CONTENT_XHTML); CheckBox transferredField = new CheckBox("is transferred"); - + // Multiline text field. This required modifying the height of the // table row. TextField commentsField = new TextField(); commentsField.setRows(3); - + // The Table item identifier for the row. Integer itemId = new Integer(i); - + // Create a button and handle its click. A Button does not know // the item it is contained in, so we have to store the item // ID as user-defined data. @@ -59,16 +58,16 @@ public class TableExample3 extends CustomComponent { detailsField.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { // Get the item identifier from the user-defined data. - Integer itemId = (Integer) event.getButton().getData(); - getWindow().showNotification( - "Link " + itemId.intValue() + " clicked."); - } + Integer itemId = (Integer)event.getButton().getData(); + getWindow().showNotification("Link "+itemId.intValue()+" clicked."); + } }); detailsField.addStyleName("link"); - + // Create the table row. - table.addItem(new Object[] { sumField, transferredField, - commentsField, detailsField }, itemId); + table.addItem(new Object[] {sumField, transferredField, + commentsField, detailsField}, + itemId); } // Show just three rows because they are so high. @@ -76,8 +75,8 @@ public class TableExample3 extends CustomComponent { // Initially show the 50th item in the top of the table. table.setCurrentPageFirstItemIndex(50); - // table.setCurrentPageFirstItemId(initial); - + //table.setCurrentPageFirstItemId(initial); + layout.addComponent(table); } } diff --git a/src/com/itmill/toolkit/tests/book/TableHuge.java b/src/com/itmill/toolkit/tests/book/TableHuge.java index 82975634c1..411153dc18 100644 --- a/src/com/itmill/toolkit/tests/book/TableHuge.java +++ b/src/com/itmill/toolkit/tests/book/TableHuge.java @@ -23,9 +23,9 @@ public class TableHuge extends CustomComponent { * This is a virtual container that generates the items on the fly when * requested. */ - public class HugeContainer implements Container, Indexed { + public class HugeContainer implements Container,Indexed { int numberofitems; - + public HugeContainer(int numberofitems) { this.numberofitems = numberofitems; } @@ -68,8 +68,7 @@ public class TableHuge extends CustomComponent { if (itemId instanceof Integer) { int pos = ((Integer) itemId).intValue(); if (pos >= 0 && pos < numberofitems) { - return new ObjectProperty("This is the item " + pos - + " in the huge table"); + return new ObjectProperty("This is the item "+pos+" in the huge table"); } } return null; @@ -84,11 +83,10 @@ public class TableHuge extends CustomComponent { public Item getItem(Object itemId) { if (itemId instanceof Integer) { - int pos = ((Integer) itemId).intValue(); + int pos = ((Integer)itemId).intValue(); if (pos >= 0 && pos < numberofitems) { Item item = new PropertysetItem(); - item.addItemProperty("id", new ObjectProperty( - "This is the item " + pos + " in the huge table")); + item.addItemProperty("id", new ObjectProperty("This is the item "+pos+" in the huge table")); return item; } } @@ -162,25 +160,25 @@ public class TableHuge extends CustomComponent { } public boolean isLastId(Object itemId) { - return ((Integer) itemId).intValue() == (numberofitems - 1); + return ((Integer) itemId).intValue() == (numberofitems-1); } public Object lastItemId() { - return new Integer(numberofitems - 1); + return new Integer(numberofitems-1); } public Object nextItemId(Object itemId) { int pos = indexOfId(itemId); - if (pos >= numberofitems - 1) + if (pos >= numberofitems-1) return null; - return getIdByIndex(pos + 1); + return getIdByIndex(pos+1); } public Object prevItemId(Object itemId) { int pos = indexOfId(itemId); if (pos <= 0) return null; - return getIdByIndex(pos - 1); + return getIdByIndex(pos-1); } } @@ -188,7 +186,7 @@ public class TableHuge extends CustomComponent { Table table = new Table("HUGE table, REALLY HUGE"); table.setContainerDataSource(new HugeContainer(500000)); table.setPageLength(20); - + setCompositionRoot(table); } } diff --git a/src/com/itmill/toolkit/tests/book/WindowOpener.java b/src/com/itmill/toolkit/tests/book/WindowOpener.java index 002538ae7d..5e5f673fa7 100644 --- a/src/com/itmill/toolkit/tests/book/WindowOpener.java +++ b/src/com/itmill/toolkit/tests/book/WindowOpener.java @@ -12,25 +12,25 @@ import com.itmill.toolkit.ui.Window; import com.itmill.toolkit.ui.Window.CloseEvent; /** Component contains a button that allows opening a window. */ -public class WindowOpener extends CustomComponent implements - Window.CloseListener { - Window mainwindow; // Reference to main window - Window mywindow; // The window to be opened - Button openbutton; // Button for opening the window +public class WindowOpener extends CustomComponent + implements Window.CloseListener { + Window mainwindow; // Reference to main window + Window mywindow; // The window to be opened + Button openbutton; // Button for opening the window Button closebutton; // A button in the window - Label explanation; // A descriptive text + Label explanation; // A descriptive text public WindowOpener(String label, Window main) { mainwindow = main; /* The component consists of a button that opens the window. */ final OrderedLayout layout = new OrderedLayout(); - + openbutton = new Button("Open Window", this, "openButtonClick"); explanation = new Label("Explanation"); layout.addComponent(openbutton); layout.addComponent(explanation); - + setCompositionRoot(layout); } diff --git a/src/com/itmill/toolkit/tests/book/WindowTestApplication.java b/src/com/itmill/toolkit/tests/book/WindowTestApplication.java index 7e97e8d6bf..0affc7a4f6 100644 --- a/src/com/itmill/toolkit/tests/book/WindowTestApplication.java +++ b/src/com/itmill/toolkit/tests/book/WindowTestApplication.java @@ -11,8 +11,8 @@ import com.itmill.toolkit.ui.Window; import com.itmill.toolkit.ui.Button.ClickEvent; public class WindowTestApplication extends Application { - Window anotherpage = null; - HashMap windows = new HashMap(); + Window anotherpage = null; + HashMap windows = new HashMap(); public void init() { final Window main = new Window("Window Test Application"); @@ -36,40 +36,37 @@ public class WindowTestApplication extends Application { new Button.ClickListener() { public void buttonClick(ClickEvent event) { // Open the window. - main.open(new ExternalResource(mywindow.getURL()), - "_new"); + 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())); + new ExternalResource(mywindow.getURL())); link.setTargetName("_new"); 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())); + 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 links to windows that do not yet exist, but are created // dynamically when the URL is called. main.addComponent(new Label("URLs to open item windows:")); final String[] items = new String[] { "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune" }; - + for (int inx = 0; inx < items.length; inx++) { String item = items[inx]; - // We do not create window objects here, but just links to the - // windows + // We do not create window objects here, but just links to the windows String windowUrl = getURL() + "planet-" + item; - main.addComponent(new Label("A window about '" + item - + "': " - + windowUrl + "", Label.CONTENT_XHTML)); + main.addComponent(new Label("A window about '" + item + "': " + windowUrl + + "", Label.CONTENT_XHTML)); } } @@ -79,9 +76,8 @@ public class WindowTestApplication extends Application { if (!windows.containsKey(planetName)) { // Create the window object on the fly. Window newWindow = new Window("Yet Another Page"); - newWindow.addComponent(new Label( - "This window contains details about " + planetName - + ".")); + newWindow.addComponent(new Label("This window contains details about " + + planetName + ".")); windows.put(planetName, newWindow); // We must add the window to the application, it is not done -- 2.39.5