]> source.dussan.org Git - vaadin-framework.git/commitdiff
Java 1.4 -ified
authorMarc Englund <marc.englund@itmill.com>
Thu, 8 Nov 2007 07:17:23 +0000 (07:17 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 8 Nov 2007 07:17:23 +0000 (07:17 +0000)
svn changeset:2745/svn branch:trunk

src/com/itmill/toolkit/tests/TestComponentsAndLayouts.java
src/com/itmill/toolkit/tests/magi/SSNField.java
src/com/itmill/toolkit/tests/magi/TableExample.java

index 6b6081db4b68e17b8f951bcb5efe56441aa8e77c..f6630f0595a9139637c8ae843caa3843ea0fc9e7 100644 (file)
@@ -14,8 +14,31 @@ import com.itmill.toolkit.terminal.ClassResource;
 import com.itmill.toolkit.terminal.ErrorMessage;
 import com.itmill.toolkit.terminal.ExternalResource;
 import com.itmill.toolkit.terminal.UserError;
-
-import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.ui.AbstractComponent;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CheckBox;
+import com.itmill.toolkit.ui.DateField;
+import com.itmill.toolkit.ui.Embedded;
+import com.itmill.toolkit.ui.ExpandLayout;
+import com.itmill.toolkit.ui.GridLayout;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Layout;
+import com.itmill.toolkit.ui.Link;
+import com.itmill.toolkit.ui.NativeSelect;
+import com.itmill.toolkit.ui.OptionGroup;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Panel;
+import com.itmill.toolkit.ui.ProgressIndicator;
+import com.itmill.toolkit.ui.RichTextArea;
+import com.itmill.toolkit.ui.Select;
+import com.itmill.toolkit.ui.Slider;
+import com.itmill.toolkit.ui.TabSheet;
+import com.itmill.toolkit.ui.Table;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Tree;
+import com.itmill.toolkit.ui.TwinColSelect;
+import com.itmill.toolkit.ui.Upload;
+import com.itmill.toolkit.ui.Window;
 import com.itmill.toolkit.ui.Component.Event;
 import com.itmill.toolkit.ui.Component.Listener;
 
@@ -35,10 +58,10 @@ public class TestComponentsAndLayouts extends Application implements Listener,
        SampleDatabase sampleDatabase;
 
        // Example Actions for table
-       private Action ACTION1 = new Action("Upload");
-       private Action ACTION2 = new Action("Download");
-       private Action ACTION3 = new Action("Show history");
-       private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
+       private final Action ACTION1 = new Action("Upload");
+       private final Action ACTION2 = new Action("Download");
+       private final Action ACTION3 = new Action("Show history");
+       private final Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
 
        public void init() {
                sampleDatabase = new SampleDatabase();
@@ -143,7 +166,7 @@ public class TestComponentsAndLayouts extends Application implements Listener,
                optionGroup.setContainerDataSource(getSmallContainer());
                optionGroup.setItemCaptionPropertyId("UNIT");
 
-               ProgressIndicator pi = new ProgressIndicator(50.0f);
+               ProgressIndicator pi = new ProgressIndicator(new Float(50));
                pi.setCaption("ProgressIndicator");
                test(layout, pi);
 
@@ -246,8 +269,9 @@ public class TestComponentsAndLayouts extends Application implements Listener,
                ClassResource res = new ClassResource("m.gif", this);
                ErrorMessage errorMsg = new UserError("User error " + c);
 
-               if ((c.getCaption() == null) || (c.getCaption().length() <= 0))
+               if ((c.getCaption() == null) || (c.getCaption().length() <= 0)) {
                        c.setCaption("Caption " + c);
+               }
                c.setDescription("Description " + c);
                c.setComponentError(errorMsg);
                c.setIcon(res);
@@ -276,8 +300,9 @@ public class TestComponentsAndLayouts extends Application implements Listener,
                test(c);
                layout.addComponent(c);
                // add separator
-               if (!(layout instanceof GridLayout))
+               if (!(layout instanceof GridLayout)) {
                        layout.addComponent(new Label("<HR />", Label.CONTENT_XHTML));
+               }
        }
 
        public void componentEvent(Event event) {
index 062cebec40a2062ada3db36539b1c5979d01b80b..f513e6b97ddaa41756cf70d2dc42a659b0671352 100644 (file)
@@ -1,12 +1,20 @@
 package com.itmill.toolkit.tests.magi;
-import com.itmill.toolkit.ui.*;
-import com.itmill.toolkit.data.*;
+
+import java.text.MessageFormat;
+
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.data.Validator;
 import com.itmill.toolkit.data.Property.ValueChangeEvent;
-import java.text.*;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.TextField;
 
 /* Finnish Social Security Number input field that validates the value. */
-public class SSNField extends CustomComponent implements Property.ValueChangeListener {
-       OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL);
+public class SSNField extends CustomComponent implements
+               Property.ValueChangeListener {
+       OrderedLayout layout = new OrderedLayout(
+                       OrderedLayout.ORIENTATION_HORIZONTAL);
        TextField myfield;
        Label myerror;
 
@@ -26,16 +34,20 @@ public class SSNField extends CustomComponent implements Property.ValueChangeLis
                /** Validate the given SSN. */
                public void validate(Object value) throws InvalidValueException {
                        String ssn = (String) value;
-                       if (ssn.length() != 11)
+                       if (ssn.length() != 11) {
                                throw new InvalidValueException("Invalid SSN length");
-                       
-                       String numbers = ssn.substring(0,6) + ssn.substring(7,10);
-                       int checksum = new Integer(numbers) % 31;
-                       if (!ssn.substring(10).equals("0123456789ABCDEFHJKLMNPRSTUVWXY".substring(checksum,checksum+1)))
+                       }
+
+                       String numbers = ssn.substring(0, 6) + ssn.substring(7, 10);
+                       int checksum = new Integer(numbers).intValue() % 31;
+                       if (!ssn.substring(10).equals(
+                                       "0123456789ABCDEFHJKLMNPRSTUVWXY".substring(checksum,
+                                                       checksum + 1))) {
                                throw new InvalidValueException("Invalid SSN checksum");
+                       }
                }
        }
-       
+
        SSNField() {
                setCompositionRoot(layout);
                layout.setStyle("form");
@@ -44,14 +56,17 @@ public class SSNField extends CustomComponent implements Property.ValueChangeLis
                myfield = new TextField("Social Security Number");
                myfield.setColumns(11);
                myfield.setFormat(new MessageFormat("{0,number,##}"));
-               
+
                /* Create and set the validator object for the field. */
-               SSNValidator ssnvalidator = new SSNValidator ();
+               SSNValidator ssnvalidator = new SSNValidator();
                myfield.addValidator(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. */
                myfield.addListener(this);
 
@@ -66,16 +81,19 @@ public class SSNField extends CustomComponent implements Property.ValueChangeLis
                try {
                        /* Validate the field value. */
                        myfield.validate();
-                       
+
                        /* The value was correct. */
                        myerror.setValue("Ok");
                        myfield.setStyle("");
                } catch (Validator.InvalidValueException e) {
                        /* Report the error message to the user. */
                        myerror.setValue(e.getMessage());
-                       
-                       /* The CSS defines that text field with the "error" class will be colored red. */
+
+                       /*
+                        * The CSS defines that text field with the "error" class will be
+                        * colored red.
+                        */
                        myfield.setStyle("error");
-               }               
+               }
        }
 }
index d9bba06e96ac3d1cd4d8c80cd1cebd0cb379d0d0..e9431d001582c64fca9d6d84bbab7d4b9e494b50 100644 (file)
@@ -1,5 +1,8 @@
 package com.itmill.toolkit.tests.magi;
-import com.itmill.toolkit.ui.*;
+
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Table;
 
 public class TableExample extends CustomComponent {
        /* Create the table with a caption. */
@@ -8,30 +11,38 @@ public class TableExample extends CustomComponent {
        /* A layout needed for the example. */
        OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
 
-       TableExample () {
-               setCompositionRoot (layout);
+       TableExample() {
+               setCompositionRoot(layout);
                layout.addComponent(table);
 
                /* Define the names, data types, and default values of columns. */
-               table.addContainerProperty("First Name", String.class, "(no first name)");
+               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<500; i++) {
+               for (int i = 0; i < 500; 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))],
-                                                                          (int) (1900+Math.random() * 100)}, 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. */
                table.setPageLength(10);
-               
+
                table.setStyle("twincol");
                table.setColumnReorderingAllowed(true);
                table.setColumnCollapsingAllowed(true);