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

src/com/itmill/toolkit/tests/magi/MyUploader.java
src/com/itmill/toolkit/tests/magi/SelectExample.java

index 94a0856a4f60688f8e71335f9b91708d3d6d2472..a55ef4791b0d68d64c43321b4aa9cf723e9713e5 100644 (file)
@@ -1,53 +1,64 @@
 package com.itmill.toolkit.tests.magi;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
-import com.itmill.toolkit.ui.*;
-import com.itmill.toolkit.terminal.*;
 
-public class MyUploader extends CustomComponent implements Upload.FinishedListener {
+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;
+
+public class MyUploader extends CustomComponent implements
+               Upload.FinishedListener {
        MyUploadReceiver uploadReceiver; /* Upload receiver object. */
-       Panel                    root;           /* Root element for contained components. */
-       Panel                    imagePanel;     /* Panel that contains the uploaded image. */
-       
+       Panel root; /* Root element for contained components. */
+       Panel imagePanel; /* Panel that contains the uploaded image. */
+
        /* Custom upload receiver that has to be implemented for Upload. */
        class MyUploadReceiver implements Upload.Receiver {
                java.io.File file; /* File to write to. */
                java.io.FileOutputStream fos; /* Output stream to write to. */
-               
+
                public OutputStream receiveUpload(String filename, String MIMEType) {
-                       file = new File("/tmp/uploads/"+filename);
+                       file = new File("/tmp/uploads/" + filename);
                        try {
                                /* Open the file for writing. */
                                fos = new FileOutputStream(file);
                        } catch (java.io.FileNotFoundException e) {
-                               return null; /* Error while opening the file. Not reported here. */
+                               return null; /*
+                                                                * Error while opening the file. Not reported
+                                                                * here.
+                                                                */
                        }
-                       
+
                        return fos; /* Return the output stream. */
                }
 
-               public File getFile () {
+               public File getFile() {
                        return file;
                }
        }
 
-       MyUploader () {
+       MyUploader() {
                root = new Panel("My Upload Component");
                setCompositionRoot(root);
-               
+
                /* Create the upload receiver required by Upload. */
                uploadReceiver = new MyUploadReceiver();
-               
+
                /* Create the Upload component. */
-               Upload upload = new Upload ("Upload", uploadReceiver);
-               
+               Upload upload = new Upload("Upload", uploadReceiver);
+
                /* Listen for Upload.FinishedEvent events. */
                upload.addListener(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");
                imagePanel.addComponent(new Label("No image uploaded yet"));
@@ -57,12 +68,12 @@ public class MyUploader extends CustomComponent implements Upload.FinishedListen
        /* This is called when the upload is finished. */
        public void uploadFinished(Upload.FinishedEvent event) {
                /* Log the upload on screen. */
-               root.addComponent(new Label(String.format("File %s of type '%s' uploaded.",
-                                                                                                       event.getFilename(),
-                                                                                                       event.getMIMEType())));
-               
+               root.addComponent(new Label("File " + event.getFilename()
+                               + " of type '" + event.getMIMEType() + "' uploaded."));
+
                /* Display the uploaded file in the image panel. */
-               FileResource imageResource = new FileResource (uploadReceiver.getFile(), getApplication());
+               FileResource imageResource = new FileResource(uploadReceiver.getFile(),
+                               getApplication());
                imagePanel.removeAllComponents();
                imagePanel.addComponent(new Embedded("", imageResource));
        }
index 2603ef6e45527e39e1934ceeaad050d4b549d1aa..b5272078ec48144617702a9e2b8bee72d181f7ec 100644 (file)
 package com.itmill.toolkit.tests.magi;
-import com.itmill.toolkit.ui.*;
-import com.itmill.toolkit.data.*;
-import com.itmill.toolkit.*;
+
+import com.itmill.toolkit.Application;
+import com.itmill.toolkit.data.Property;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Select;
 
 /* Let us add an implementation of the ValueChangeListener interface. */
-public class SelectExample extends CustomComponent implements Property.ValueChangeListener {
-       
+public class SelectExample extends CustomComponent implements
+               Property.ValueChangeListener {
+
        class Planet extends Object {
                String planetName;
-               Planet (String name) {
+
+               Planet(String name) {
                        planetName = name;
                }
-               public String toString () {
+
+               public String toString() {
                        return "The Planet " + planetName;
                }
        }
-       
+
        /* Create the Select object with a caption. */
-       Select select = new Select(/*"This is a Select component that allows adding new items"*/);
+       Select select = new Select(/*
+        * "This is a Select component that allows
+        * adding new items"
+        */);
 
        OrderedLayout layout = new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL);
        Label status = new Label("");
-       
-       SelectExample (Application application) {
-               setCompositionRoot (layout);
+
+       SelectExample(Application application) {
+               setCompositionRoot(layout);
                layout.addComponent(select);
 
                /* Fill the component with some items. */
-               final String[] planets = new String[] {"Mercury", "Venus", "Earth", "Mars",
-                                                                                          "Jupiter", "Saturn", "Uranus", "Neptune"};
-               
-               for (int i=0; i<planets.length; i++) {
+               final String[] planets = new String[] { "Mercury", "Venus", "Earth",
+                               "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };
+
+               for (int i = 0; i < planets.length; i++) {
                        select.addItem(planets[i]);
 
                        /* Create an item with an Integer as the Item ID. */
-                       //select.addItem(i);
-                       
-                       //select.addItem(new Planet(planets[i]));
-                       
+                       // select.addItem(i);
+                       // select.addItem(new Planet(planets[i]));
                        /* Set the visible caption of the item. */
-                       //select.setItemCaption(i, planets[i]);
-                       
-                       /* ClassResource icon = new ClassResource ("images/"+planets[i]+"_symbol.png", application);
-                       layout.addComponent(new Embedded ("Icon", icon));
-                       select.setItemIcon(i, icon); */
+                       // select.setItemCaption(i, planets[i]);
+                       /*
+                        * ClassResource icon = new ClassResource
+                        * ("images/"+planets[i]+"_symbol.png", application);
+                        * layout.addComponent(new Embedded ("Icon", icon));
+                        * select.setItemIcon(i, icon);
+                        */
                }
 
-               /* By default, the change event is not triggered immediately
-                * when the selection changes. This enables it. */
+               /*
+                * By default, the change event is not triggered immediately when the
+                * selection changes. This enables it.
+                */
                select.setImmediate(true);
-               
+
                /* Listen for changes in the selection. */
                select.addListener(this);
 
                select.setStyle("twincol");
                select.setMultiSelect(true);
-               //select.setNewItemsAllowed(true);
-               //int a=1;
-               
-               //select.setItemCaptionMode(Select.ITEM_CAPTION_MODE_ICON_ONLY);
+               // select.setNewItemsAllowed(true);
+               // int a=1;
+
+               // select.setItemCaptionMode(Select.ITEM_CAPTION_MODE_ICON_ONLY);
                select.setNullSelectionItemId("-- select something --");
-               
+
                layout.addComponent(status);
 
                /*
-               status.setValue(String.format("Currently selected item ID: %s<br/>" +
-                                 "Class of the Item ID: %s<br/>" +
-                                 "Caption: %s",
-                                 select.getValue(),
-                                 select.getValue().getClass().getName(),
-                                 select.getItemCaption(select.getValue())));
-               status.setContentMode(Label.CONTENT_XHTML);
-                                 */
-               
+                * status.setValue(String.format("Currently selected item ID: %s<br/>" +
+                * "Class of the Item ID: %s<br/>" + "Caption: %s", select.getValue(),
+                * select.getValue().getClass().getName(),
+                * select.getItemCaption(select.getValue())));
+                * status.setContentMode(Label.CONTENT_XHTML);
+                */
+
        }
 
        /* Respond to change in the selection. */
        public void valueChange(Property.ValueChangeEvent event) {
-               /* The event.getProperty() returns the component. The currently
-                * selected item is the property of the component, retrievable with getValue().*/
-               if(true) {
-                       status.setValue(String.format("Currently selected item ID: %s<br/>" +
-                                                                         "Class of the Item ID: %s<br/>" +
-                                                                         "Caption: %s",
-                                                                         event.getProperty().getValue(),
-                                                                         event.getProperty().getValue().getClass().getName(),
-                                                                         select.getItemCaption(event.getProperty().getValue())));
+               /*
+                * The event.getProperty() returns the component. The currently selected
+                * item is the property of the component, retrievable with getValue().
+                */
+               if (true) {
+                       status.setValue("Currently selected item ID: "
+                                       + event.getProperty().getValue() + "<br/>"
+                                       + "Class of the Item ID: "
+                                       + event.getProperty().getValue().getClass().getName()
+                                       + "<br/>" + "Caption: "
+                                       + select.getItemCaption(event.getProperty().getValue()));
                        status.setContentMode(Label.CONTENT_XHTML);
                }
        }