]> source.dussan.org Git - vaadin-framework.git/commitdiff
Small fixes to ColorPicker and more comments.
authorMarko Grönroos <magi@iki.fi>
Wed, 10 Oct 2007 07:11:54 +0000 (07:11 +0000)
committerMarko Grönroos <magi@iki.fi>
Wed, 10 Oct 2007 07:11:54 +0000 (07:11 +0000)
svn changeset:2475/svn branch:trunk

src/com/itmill/toolkit/demo/colorpicker/ColorPicker.java
src/com/itmill/toolkit/demo/colorpicker/gwt/client/WidgetSet.java
src/com/itmill/toolkit/demo/colorpicker/gwt/client/ui/ItkColorPicker.java
src/com/itmill/toolkit/demo/colorpicker/gwt/public/colorpicker/styles.css

index 7ad173421915d46622c94fb4bdd0509c4fdd0d7a..c2a09d48b2e0c5bd8b6545d4356d0a9281c617af 100644 (file)
@@ -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);
                }
        }
index 29ab393253c1304104a9009b45b061686305d010..58457aa57169a6293b78463984932023236d7386 100644 (file)
@@ -6,20 +6,24 @@ import com.itmill.toolkit.terminal.gwt.client.DefaultWidgetSet;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
 \r
 public class WidgetSet extends DefaultWidgetSet {\r
-       public Widget createWidget(UIDL uidl) {\r
-               String className = resolveWidgetTypeName(uidl);\r
-               if ("com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker"\r
-                               .equals(className))\r
-                       return new ItkColorPicker();\r
+       /** Creates a widget according to its class name. */\r
+    public Widget createWidget(UIDL uidl) {\r
+       String className = resolveWidgetTypeName(uidl);\r
+       if ("com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker"\r
+                       .equals(className))\r
+               return new ItkColorPicker();\r
 \r
-               return super.createWidget(uidl);\r
-       }\r
+       // Let the DefaultWidgetSet handle creation of default widgets\r
+       return super.createWidget(uidl);\r
+    }\r
 \r
-       protected String resolveWidgetTypeName(UIDL uidl) {\r
-               String tag = uidl.getTag();\r
-               if ("colorpicker".equals(tag))\r
-                       return "com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker";\r
+    /** Resolves UIDL tag name to class name. */\r
+    protected String resolveWidgetTypeName(UIDL uidl) {\r
+       String tag = uidl.getTag();\r
+       if ("colorpicker".equals(tag))\r
+               return "com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker";\r
 \r
-               return super.resolveWidgetTypeName(uidl);\r
-       }\r
+       // Let the DefaultWidgetSet handle resolution of default widgets\r
+       return super.resolveWidgetTypeName(uidl);\r
+    }\r
 }\r
index c1d9f532f058d9192b0833c19ae968717867b302..2b7f4a806bec5731a076b7b3a25ff072b9b12fd3 100644 (file)
@@ -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);
        }
 }
index 01194d1ef65a93e59fab08779408ee5445893232..4c3455ae53ca5f4f5c24ec2f446481ba3c773857 100644 (file)
@@ -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>.*/
 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 <td> elements. */
+.colorpicker-currentcolorbox {
        width: 240px;
        text-align: center;
        vertical-align: middle !important;