summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2010-01-19 09:35:44 +0000
committerHenri Sara <henri.sara@itmill.com>2010-01-19 09:35:44 +0000
commit3939120d5348d177abb231ecac5c0b3808cf5f48 (patch)
treebf5b13d716f0816c30ae99eb4722e13e822acbef /src
parentdcdef2d8481f22041520bf50b5ae3011d08bd349 (diff)
downloadvaadin-framework-3939120d5348d177abb231ecac5c0b3808cf5f48.tar.gz
vaadin-framework-3939120d5348d177abb231ecac5c0b3808cf5f48.zip
#3940 Setter for CustomLayout template contents
svn changeset:10800/svn branch:6.3
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/ui/CustomLayout.java67
1 files changed, 48 insertions, 19 deletions
diff --git a/src/com/vaadin/ui/CustomLayout.java b/src/com/vaadin/ui/CustomLayout.java
index cae427763c..26495a3715 100644
--- a/src/com/vaadin/ui/CustomLayout.java
+++ b/src/com/vaadin/ui/CustomLayout.java
@@ -1,19 +1,19 @@
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.vaadin.ui;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VCustomLayout;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
+import com.vaadin.terminal.PaintException;
+import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.ui.VCustomLayout;
+
/**
* <p>
* A container component with freely designed layout and style. The layout
@@ -37,6 +37,8 @@ import java.util.Iterator;
* </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
@@ -57,6 +59,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.
*
* @param templateStream
@@ -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,19 +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 VAADIN/themes/themename/layouts/templatename.html - see
- * {@link #setTemplateName(String)} for details.
- *
- * @see #setTemplateName(String)
- */
- public CustomLayout(String template) {
- templateName = template;
- setWidth(100, UNITS_PERCENTAGE);
}
/**
@@ -249,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);
@@ -260,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.
*
@@ -276,6 +294,17 @@ public class CustomLayout extends AbstractLayout {
}
/**
+ * 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
* template.