From: Marko Grönroos Date: Wed, 10 Oct 2007 07:11:54 +0000 (+0000) Subject: Small fixes to ColorPicker and more comments. X-Git-Tag: 6.7.0.beta1~5877 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0b9a233409b847d4e3873b6bc29efeb8199bb8a8;p=vaadin-framework.git Small fixes to ColorPicker and more comments. svn changeset:2475/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/colorpicker/ColorPicker.java b/src/com/itmill/toolkit/demo/colorpicker/ColorPicker.java index 7ad1734219..c2a09d48b2 100644 --- a/src/com/itmill/toolkit/demo/colorpicker/ColorPicker.java +++ b/src/com/itmill/toolkit/demo/colorpicker/ColorPicker.java @@ -22,29 +22,35 @@ public class ColorPicker extends AbstractField { return "colorpicker"; } - /** Encode the property value of the field from RGB components. */ + /** Set the currently selected color. */ public void setColor(String newcolor) { - setValue(new String(newcolor)); + // Sets the color name as the property of the component. + // Setting the property will automatically cause repainting of + // the component with paintContent(). + setValue(newcolor); } - /** Decode the property value of the field to RGB components. */ + /** Retrieve the currently selected color. */ public String getColor() { return (String) getValue(); } - /* Paint (serialize) the component for the client. */ + /** Paint (serialize) the component for the client. */ public void paintContent(PaintTarget target) throws PaintException { // Superclass writes any common attributes in the paint target. super.paintContent(target); - // Set any values as variables of the paint target. + // Add the currently selected color as a variable in the paint target. target.addVariable(this, "colorname", getColor()); } + /** Deserialize changes received from client. */ public void changeVariables(Object source, Map variables) { // Sets the currently selected color if (variables.containsKey("colorname") && !isReadOnly()) { String newValue = (String) variables.get("colorname"); + // Changing the property of the component will + // trigger a ValueChangeEvent setValue(newValue, true); } } diff --git a/src/com/itmill/toolkit/demo/colorpicker/gwt/client/WidgetSet.java b/src/com/itmill/toolkit/demo/colorpicker/gwt/client/WidgetSet.java index 29ab393253..58457aa571 100644 --- a/src/com/itmill/toolkit/demo/colorpicker/gwt/client/WidgetSet.java +++ b/src/com/itmill/toolkit/demo/colorpicker/gwt/client/WidgetSet.java @@ -6,20 +6,24 @@ import com.itmill.toolkit.terminal.gwt.client.DefaultWidgetSet; import com.itmill.toolkit.terminal.gwt.client.UIDL; public class WidgetSet extends DefaultWidgetSet { - public Widget createWidget(UIDL uidl) { - String className = resolveWidgetTypeName(uidl); - if ("com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker" - .equals(className)) - return new ItkColorPicker(); + /** Creates a widget according to its class name. */ + public Widget createWidget(UIDL uidl) { + String className = resolveWidgetTypeName(uidl); + if ("com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker" + .equals(className)) + return new ItkColorPicker(); - return super.createWidget(uidl); - } + // Let the DefaultWidgetSet handle creation of default widgets + return super.createWidget(uidl); + } - protected String resolveWidgetTypeName(UIDL uidl) { - String tag = uidl.getTag(); - if ("colorpicker".equals(tag)) - return "com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker"; + /** Resolves UIDL tag name to class name. */ + protected String resolveWidgetTypeName(UIDL uidl) { + String tag = uidl.getTag(); + if ("colorpicker".equals(tag)) + return "com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker"; - return super.resolveWidgetTypeName(uidl); - } + // Let the DefaultWidgetSet handle resolution of default widgets + return super.resolveWidgetTypeName(uidl); + } } diff --git a/src/com/itmill/toolkit/demo/colorpicker/gwt/client/ui/ItkColorPicker.java b/src/com/itmill/toolkit/demo/colorpicker/gwt/client/ui/ItkColorPicker.java index c1d9f532f0..2b7f4a806b 100644 --- a/src/com/itmill/toolkit/demo/colorpicker/gwt/client/ui/ItkColorPicker.java +++ b/src/com/itmill/toolkit/demo/colorpicker/gwt/client/ui/ItkColorPicker.java @@ -10,7 +10,7 @@ public class ItkColorPicker extends GwtColorPicker implements Paintable { public static final String CLASSNAME = "example-colorpicker"; /** Component identifier in UIDL communications. */ - String uidl_id; + String uidlId; /** Reference to the server connection object. */ ApplicationConnection client; @@ -37,8 +37,8 @@ public class ItkColorPicker extends GwtColorPicker implements Paintable { */ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { // This call should be made first. Ensure correct implementation, - // but don't let container manage caption etc. - if (client.updateComponent(this, uidl, false)) + // and let the containing layout manage caption, etc. + if (client.updateComponent(this, uidl, true)) return; // Save reference to server connection object to be able to send @@ -46,7 +46,7 @@ public class ItkColorPicker extends GwtColorPicker implements Paintable { this.client = client; // Save the UIDL identifier for the component - uidl_id = uidl.getId(); + uidlId = uidl.getId(); // Get value received from server and actualize it in the GWT component setColor(uidl.getStringVariable("colorname")); @@ -64,11 +64,11 @@ public class ItkColorPicker extends GwtColorPicker implements Paintable { // Updating the state to the server can not be done before // the server connection is known, i.e., before updateFromUIDL() // has been called. - if (uidl_id == null || client == null) + if (uidlId == null || client == null) return; // Communicate the user interaction parameters to server. This call will // initiate an AJAX request to the server. - client.updateVariable(uidl_id, "colorname", newcolor, true); + client.updateVariable(uidlId, "colorname", newcolor, true); } } diff --git a/src/com/itmill/toolkit/demo/colorpicker/gwt/public/colorpicker/styles.css b/src/com/itmill/toolkit/demo/colorpicker/gwt/public/colorpicker/styles.css index 01194d1ef6..4c3455ae53 100644 --- a/src/com/itmill/toolkit/demo/colorpicker/gwt/public/colorpicker/styles.css +++ b/src/com/itmill/toolkit/demo/colorpicker/gwt/public/colorpicker/styles.css @@ -1,19 +1,25 @@ -/* Set style for the color picker table. */ +/* Set style for the color picker table. + This assumes that the Grid layout is rendered as a HTML .*/ table.example-colorpicker { border-collapse: collapse; border: 0px; } -/* Set color picker button style. */ -.example-colorpicker button { +/* Set color picker button style. + This does not make assumptions about the HTML element tree as it only uses + the logical class names.*/ +.example-colorpicker .gwt-Button { height: 60px; width: 60px; border: none; padding: 0px; } -/* Set style for the right-hand sample box that shows the currently selected color. */ -td.colorpicker-currentcolorbox { +/* Set style for the right-hand box that shows the currently selected color. + While this may work for other implementations of the HorizontalPanel as well, + it somewhat assumes that the layout is rendered as a table where cells + are
elements. */ +.colorpicker-currentcolorbox { width: 240px; text-align: center; vertical-align: middle !important;