diff options
Diffstat (limited to 'src/com/itmill/toolkit/demo/features/FeatureUpload.java')
-rw-r--r-- | src/com/itmill/toolkit/demo/features/FeatureUpload.java | 115 |
1 files changed, 53 insertions, 62 deletions
diff --git a/src/com/itmill/toolkit/demo/features/FeatureUpload.java b/src/com/itmill/toolkit/demo/features/FeatureUpload.java index 544921fa59..e27e550737 100644 --- a/src/com/itmill/toolkit/demo/features/FeatureUpload.java +++ b/src/com/itmill/toolkit/demo/features/FeatureUpload.java @@ -1,30 +1,30 @@ /* ************************************************************************* - IT Mill Toolkit + IT Mill Toolkit - Development of Browser User Interfaces Made Easy + Development of Browser User Interfaces Made Easy - Copyright (C) 2000-2006 IT Mill Ltd - - ************************************************************************* + Copyright (C) 2000-2006 IT Mill Ltd + + ************************************************************************* - This product is distributed under commercial license that can be found - from the product package on license.pdf. Use of this product might - require purchasing a commercial license from IT Mill Ltd. For guidelines - on usage, see licensing-guidelines.html + This product is distributed under commercial license that can be found + from the product package on license.pdf. Use of this product might + require purchasing a commercial license from IT Mill Ltd. For guidelines + on usage, see licensing-guidelines.html - ************************************************************************* - - For more information, contact: - - IT Mill Ltd phone: +358 2 4802 7180 - Ruukinkatu 2-4 fax: +358 2 4802 7181 - 20540, Turku email: info@itmill.com - Finland company www: www.itmill.com - - Primary source for information and releases: www.itmill.com + ************************************************************************* + + For more information, contact: + + IT Mill Ltd phone: +358 2 4802 7180 + Ruukinkatu 2-4 fax: +358 2 4802 7181 + 20540, Turku email: info@itmill.com + Finland company www: www.itmill.com + + Primary source for information and releases: www.itmill.com - ********************************************************************** */ + ********************************************************************** */ package com.itmill.toolkit.demo.features; @@ -42,9 +42,7 @@ import com.itmill.toolkit.ui.Panel; import com.itmill.toolkit.ui.Upload; import com.itmill.toolkit.ui.Upload.FinishedEvent; -public class FeatureUpload - extends Feature - implements Upload.FinishedListener { +public class FeatureUpload extends Feature implements Upload.FinishedListener { Buffer buffer = new Buffer(); @@ -70,29 +68,26 @@ public class FeatureUpload l.addComponent(show); // Properties - PropertyPanel p = new PropertyPanel(up); - l.addComponent(p); + propertyPanel = new PropertyPanel(up); - return l; + return l; } protected String getExampleSrc() { return "Upload u = new Upload(\"Upload a file:\", uploadReceiver);\n\n" - + "public class uploadReceiver \n" - + "implements Upload.receiver, Upload.FinishedListener { \n" - + "\n" - + " java.io.File file;\n" - + " java.io.FileOutputStream fos;\n" - + " public uploadReceiver() {\n" - + " }"; + + "public class uploadReceiver \n" + + "implements Upload.receiver, Upload.FinishedListener { \n" + + "\n" + " java.io.File file;\n" + + " java.io.FileOutputStream fos;\n" + + " public uploadReceiver() {\n" + " }"; } protected String getDescriptionXHTML() { return "This demonstrates the use of the Upload component together with the Link component. " - + "This implementation does not actually store the file to disk, it only keeps it in a buffer. " - + "The example given on the example-tab on the other hand stores the file to disk and binds the link to that file.<br/>" - + "<br/>On the demo tab you can try out how the different properties affect the presentation of the component."; + + "This implementation does not actually store the file to disk, it only keeps it in a buffer. " + + "The example given on the example-tab on the other hand stores the file to disk and binds the link to that file.<br/>" + + "<br/>On the demo tab you can try out how the different properties affect the presentation of the component."; } protected String getImage() { @@ -106,43 +101,36 @@ public class FeatureUpload public void uploadFinished(FinishedEvent event) { status.removeAllComponents(); if (buffer.getStream() == null) - status.addComponent( - new Label("Upload finished, but output buffer is null!!")); + status.addComponent(new Label( + "Upload finished, but output buffer is null!!")); else { - status.addComponent( - new Label( - "<b>Name:</b> " + event.getFilename(), - Label.CONTENT_XHTML)); - status.addComponent( - new Label( - "<b>Mimetype:</b> " + event.getMIMEType(), - Label.CONTENT_XHTML)); - status.addComponent( - new Label( - "<b>Size:</b> " + event.getLength() + " bytes.", - Label.CONTENT_XHTML)); - - status.addComponent( - new Link( - "Download " + buffer.getFileName(), - new StreamResource( - buffer, - buffer.getFileName(), - getApplication()))); - + status + .addComponent(new Label("<b>Name:</b> " + + event.getFilename(), Label.CONTENT_XHTML)); + status.addComponent(new Label("<b>Mimetype:</b> " + + event.getMIMEType(), Label.CONTENT_XHTML)); + status.addComponent(new Label("<b>Size:</b> " + event.getLength() + + " bytes.", Label.CONTENT_XHTML)); + + status.addComponent(new Link("Download " + buffer.getFileName(), + new StreamResource(buffer, buffer.getFileName(), + getApplication()))); + status.setVisible(true); } } - public class Buffer - implements StreamResource.StreamSource, Upload.Receiver { + public class Buffer implements StreamResource.StreamSource, Upload.Receiver { ByteArrayOutputStream outputBuffer = null; + String mimeType; + String fileName; public Buffer() { } + public InputStream getStream() { if (outputBuffer == null) return null; @@ -150,7 +138,8 @@ public class FeatureUpload } /** - * @see com.itmill.toolkit.ui.Upload.Receiver#receiveUpload(String, String) + * @see com.itmill.toolkit.ui.Upload.Receiver#receiveUpload(String, + * String) */ public OutputStream receiveUpload(String filename, String MIMEType) { fileName = filename; @@ -161,6 +150,7 @@ public class FeatureUpload /** * Returns the fileName. + * * @return String */ public String getFileName() { @@ -169,6 +159,7 @@ public class FeatureUpload /** * Returns the mimeType. + * * @return String */ public String getMimeType() { |