From: Marc Englund Date: Thu, 8 Nov 2007 07:27:01 +0000 (+0000) Subject: Java 1.4 -ified X-Git-Tag: 6.7.0.beta1~5638 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a433d3f79337b57b3a866056f88e4d8846e9d1f1;p=vaadin-framework.git Java 1.4 -ified svn changeset:2746/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/tests/magi/MyUploader.java b/src/com/itmill/toolkit/tests/magi/MyUploader.java index 94a0856a4f..a55ef4791b 100644 --- a/src/com/itmill/toolkit/tests/magi/MyUploader.java +++ b/src/com/itmill/toolkit/tests/magi/MyUploader.java @@ -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)); } diff --git a/src/com/itmill/toolkit/tests/magi/SelectExample.java b/src/com/itmill/toolkit/tests/magi/SelectExample.java index 2603ef6e45..b5272078ec 100644 --- a/src/com/itmill/toolkit/tests/magi/SelectExample.java +++ b/src/com/itmill/toolkit/tests/magi/SelectExample.java @@ -1,91 +1,103 @@ 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" + - "Class of the Item ID: %s
" + - "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
" + + * "Class of the Item ID: %s
" + "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
" + - "Class of the Item ID: %s
" + - "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() + "
" + + "Class of the Item ID: " + + event.getProperty().getValue().getClass().getName() + + "
" + "Caption: " + + select.getItemCaption(event.getProperty().getValue())); status.setContentMode(Label.CONTENT_XHTML); } }