]> source.dussan.org Git - vaadin-framework.git/commitdiff
reverting changes committed by accident after epic eclipse/subclicpse fail
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 9 Mar 2010 15:34:26 +0000 (15:34 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 9 Mar 2010 15:34:26 +0000 (15:34 +0000)
svn changeset:11716/svn branch:6.3

src/com/vaadin/ui/CustomLayout.java

index 0baa0dd4682816e9192ae77f897750e2331e3523..26495a3715f9ec80e5767e60501c1992ce7fbea3 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 @ITMillApache2LicenseForJavaFiles@
  */
 
@@ -37,6 +37,8 @@ import com.vaadin.terminal.gwt.client.ui.VCustomLayout;
  * </p>
  * 
  * @author IT Mill Ltd.
+ * @author Duy B. Vo (<a
+ *         href="mailto:devduy@gmail.com?subject=Vaadin">devduy@gmail.com</a>)
  * @version
  * @VERSION@
  * @since 3.0
@@ -56,6 +58,14 @@ public class CustomLayout extends AbstractLayout {
 
     private String templateName = null;
 
+    /**
+     * Default constructor only used by subclasses because the subclasses are
+     * responsible for setting the appropriate fields.
+     */
+    protected CustomLayout() {
+        setWidth(100, UNITS_PERCENTAGE);
+    }
+
     /**
      * Constructs a custom layout with the template given in the stream.
      * 
@@ -68,10 +78,24 @@ public class CustomLayout extends AbstractLayout {
      * @throws IOException
      */
     public CustomLayout(InputStream templateStream) throws IOException {
+        this();
+        initTemplateContentsFromInputStream(templateStream);
+    }
+
+    /**
+     * Constructor for custom layout with given template name. Template file is
+     * fetched from "<theme>/layout/<templateName>".
+     */
+    public CustomLayout(String template) {
+        this();
+        templateName = template;
+    }
 
+    protected void initTemplateContentsFromInputStream(
+            InputStream templateStream) throws IOException {
         InputStreamReader reader = new InputStreamReader(templateStream,
                 "UTF-8");
-        StringBuffer b = new StringBuffer(BUFFER_SIZE);
+        StringBuilder b = new StringBuilder(BUFFER_SIZE);
 
         char[] cbuf = new char[BUFFER_SIZE];
         int offset = 0;
@@ -85,16 +109,6 @@ public class CustomLayout extends AbstractLayout {
         }
 
         templateContents = b.toString();
-        setWidth(100, UNITS_PERCENTAGE);
-    }
-
-    /**
-     * Constructor for custom layout with given template name. Template file is
-     * fetched from "<theme>/layout/<templateName>".
-     */
-    public CustomLayout(String template) {
-        templateName = template;
-        setWidth(100, UNITS_PERCENTAGE);
     }
 
     /**
@@ -246,7 +260,9 @@ public class CustomLayout extends AbstractLayout {
      * 
      * @param name
      *            template name
+     * @deprecated Use {@link #setTemplateName(String)} instead
      */
+    @Deprecated
     @Override
     public void setStyle(String name) {
         setTemplateName(name);
@@ -257,6 +273,11 @@ public class CustomLayout extends AbstractLayout {
         return templateName;
     }
 
+    /** Get the contents of the template */
+    public String getTemplateContents() {
+        return templateContents;
+    }
+
     /**
      * Set the name of the template used to draw custom layout.
      * 
@@ -272,6 +293,17 @@ public class CustomLayout extends AbstractLayout {
         requestRepaint();
     }
 
+    /**
+     * Set the contents of the template used to draw the custom layout.
+     * 
+     * @param templateContents
+     */
+    public void setTemplateContents(String templateContents) {
+        this.templateContents = templateContents;
+        templateName = null;
+        requestRepaint();
+    }
+
     /**
      * Although most layouts support margins, CustomLayout does not. The
      * behaviour of this layout is determined almost completely by the actual