aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2007-08-14 11:18:44 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2007-08-14 11:18:44 +0000
commit58be97d056c5e33287e539ce0b20e81f0468e75d (patch)
tree98bf8a82ec5f14fb12ad2ee94f2a068dd472101a
parent13903183b60dba27ac903e3c2bd44db820b73481 (diff)
downloadvaadin-framework-58be97d056c5e33287e539ce0b20e81f0468e75d.tar.gz
vaadin-framework-58be97d056c5e33287e539ce0b20e81f0468e75d.zip
support for multiple style names
svn changeset:2004/svn branch:trunk
-rwxr-xr-xsrc/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java4
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java12
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java2
-rw-r--r--src/com/itmill/toolkit/ui/AbstractComponent.java38
-rw-r--r--src/com/itmill/toolkit/ui/Component.java28
-rw-r--r--src/com/itmill/toolkit/ui/CustomComponent.java17
-rw-r--r--src/com/itmill/toolkit/ui/CustomLayout.java9
7 files changed, 89 insertions, 21 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
index 535605532a..e9db2b64fd 100755
--- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
@@ -387,6 +387,10 @@ public class ApplicationConnection implements EntryPoint, FocusListener {
component.setVisible(visible);
if (!visible)
return true;
+
+ // add additional styles as css classes
+ if(uidl.hasAttribute("style"))
+ component.addStyleName(uidl.getStringAttribute("style"));
return false;
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
index e1a3e6e148..05d10eb997 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
@@ -32,7 +32,7 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
private HashMap widgetToCaptionWrapper = new HashMap();
/** Currently rendered style */
- String currentStyle;
+ String currentTemplate;
/** Unexecuted scripts loaded from the template */
private String scripts = "";
@@ -115,16 +115,16 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
private void updateHTML(UIDL uidl, ApplicationConnection client) {
// Update only if style has changed
- String newStyle = uidl.getStringAttribute("style");
- if (currentStyle != null && currentStyle.equals(newStyle))
+ String newTemplate = uidl.getStringAttribute("template");
+ if (currentTemplate != null && currentTemplate.equals(newTemplate))
return;
// Get the HTML-template from client
- String template = client.getResource("layout/" + newStyle + ".html");
+ String template = client.getResource("layout/" + newTemplate + ".html");
if (template == null) {
- template = "Layout file layout/" + newStyle + ".html is missing.";
+ template = "Layout file layout/" + newTemplate + ".html is missing.";
} else {
- currentStyle = newStyle;
+ currentTemplate = newTemplate;
}
// Connect body of the template to DOM
diff --git a/src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java b/src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java
index 17fb67a620..a755ca9c65 100644
--- a/src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java
+++ b/src/com/itmill/toolkit/terminal/gwt/server/JsonPaintTarget.java
@@ -469,7 +469,7 @@ public class JsonPaintTarget implements PaintTarget {
tag.addAttribute("\"" + name + "\": \"" + escapeJSON(value) + "\"");
- if (customLayoutArgumentsOpen && "style".equals(name))
+ if (customLayoutArgumentsOpen && "template".equals(name))
getPreCachedResources().add("layout/" + value + ".html");
if(name.equals("locale"))
diff --git a/src/com/itmill/toolkit/ui/AbstractComponent.java b/src/com/itmill/toolkit/ui/AbstractComponent.java
index 6c2a04f170..9015169e43 100644
--- a/src/com/itmill/toolkit/ui/AbstractComponent.java
+++ b/src/com/itmill/toolkit/ui/AbstractComponent.java
@@ -33,7 +33,9 @@ import com.itmill.toolkit.event.EventRouter;
import com.itmill.toolkit.event.MethodEventSource;
import com.itmill.toolkit.terminal.*;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
@@ -55,11 +57,11 @@ import java.lang.reflect.Method;
public abstract class AbstractComponent implements Component, MethodEventSource {
/* Private members ************************************************* */
-
+
/**
- * Look-and-feel style of the component.
+ * Style names.
*/
- private String style;
+ private ArrayList styles;
/**
* Caption text.
@@ -159,7 +161,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* default documentation from implemented interface.
*/
public String getStyle() {
- return this.style;
+ String s = "";
+ if(styles != null) {
+ for(Iterator it = styles.iterator();it.hasNext();)
+ s += " " + (String) it.next();
+ }
+ return s;
}
/*
@@ -167,10 +174,27 @@ public abstract class AbstractComponent implements Component, MethodEventSource
* default documentation from implemented interface.
*/
public void setStyle(String style) {
- this.style = style;
+ if(this.styles == null) {
+ styles = new ArrayList();
+ }
+ styles.clear();
+ styles.add(style);
requestRepaint();
}
-
+
+ public void addStyleName(String style) {
+ if(this.styles == null) {
+ styles = new ArrayList();
+ }
+ if(! styles.contains(style))
+ this.styles.add(style);
+ requestRepaint();
+ }
+
+ public void removeStyleName(String style) {
+ styles.remove(style);
+ }
+
/*
* Get's the component's caption. Don't add a JavaDoc comment here, we use
* the default documentation from implemented interface.
@@ -516,7 +540,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
public final void paint(PaintTarget target) throws PaintException {
if (!target.startTag(this, this.getTag())) {
- if (getStyle() != null && getStyle().length() > 0)
+ if (styles != null && styles.size() > 0)
target.addAttribute("style", getStyle());
if (isReadOnly())
target.addAttribute("readonly", true);
diff --git a/src/com/itmill/toolkit/ui/Component.java b/src/com/itmill/toolkit/ui/Component.java
index dc686f5f05..234b8d9836 100644
--- a/src/com/itmill/toolkit/ui/Component.java
+++ b/src/com/itmill/toolkit/ui/Component.java
@@ -51,21 +51,41 @@ import java.util.Locale;
public interface Component extends Paintable, VariableOwner {
/**
- * Gets the look-and-feel style of the component.
- *
+ * Gets style for component. Multiple styles are joined with spaces.
+ *
* @return the component's styleValue of property style.
*/
public String getStyle();
/**
- * Sets the look-and-feel style of the component. This method will trigger a
+ * Sets and replaces all previous style names of the component. This method will trigger a
* {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
*
* @param style
* the new style of the component.
*/
public void setStyle(String style);
-
+
+ /**
+ * Adds style name to component. Handeling additional style names is terminal spesicif,
+ * but in web browser enviroment they will most likely become CSS classes as given on server side.
+ *
+ * This method will trigger a
+ * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
+ *
+ * @param style
+ * the new style to be added to the component
+ */
+ public void addStyleName(String style);
+
+ /**
+ * Removes given style name from component.
+ *
+ * @param style
+ * the style to be removed
+ */
+ public void removeStyleName(String style);
+
/**
* <p>
* Tests if the component is enabled or not. All the variable change events
diff --git a/src/com/itmill/toolkit/ui/CustomComponent.java b/src/com/itmill/toolkit/ui/CustomComponent.java
index 3aebcfeb6b..abf546641f 100644
--- a/src/com/itmill/toolkit/ui/CustomComponent.java
+++ b/src/com/itmill/toolkit/ui/CustomComponent.java
@@ -519,4 +519,21 @@ public class CustomComponent implements Component {
this.componentType = componentType;
}
+ /**
+ * Custom component does not implement custom styles by default.
+ *
+ * @see com.itmill.toolkit.ui.Component#getStyle()
+ */
+ public void addStyleName(String style) {
+ }
+
+ /**
+ * Custom component does not implement custom styles by default.
+ *
+ * @see com.itmill.toolkit.ui.Component#getStyle()
+ */
+ public void removeStyleName(String style) {
+
+ }
+
}
diff --git a/src/com/itmill/toolkit/ui/CustomLayout.java b/src/com/itmill/toolkit/ui/CustomLayout.java
index 06ec7f4f10..c0b598d42e 100644
--- a/src/com/itmill/toolkit/ui/CustomLayout.java
+++ b/src/com/itmill/toolkit/ui/CustomLayout.java
@@ -67,12 +67,14 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
* Custom layout slots containing the components.
*/
private HashMap slots = new HashMap();
+
+ private String templateName;
/**
- * Constructor for custom layout with given style.
+ * Constructor for custom layout with given template name.
*/
- public CustomLayout(String style) {
- setStyle(style);
+ public CustomLayout(String template) {
+ templateName = template;
}
/**
@@ -172,6 +174,7 @@ public class CustomLayout extends AbstractComponentContainer implements Layout {
*/
public void paintContent(PaintTarget target) throws PaintException {
+ target.addAttribute("template", templateName);
// Adds all items in all the locations
for (Iterator i = slots.keySet().iterator(); i.hasNext();) {