]> source.dussan.org Git - vaadin-framework.git/commitdiff
Sampler; sample modifications
authorMarc Englund <marc.englund@itmill.com>
Thu, 5 Feb 2009 14:37:01 +0000 (14:37 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 5 Feb 2009 14:37:01 +0000 (14:37 +0000)
svn changeset:6742/svn branch:trunk

src/com/itmill/toolkit/demo/sampler/features/panels/PanelLightExample.java
src/com/itmill/toolkit/demo/sampler/features/text/LabelRichExample.java
src/com/itmill/toolkit/demo/sampler/features/text/RichTextEditor.java
src/com/itmill/toolkit/demo/sampler/features/text/TextArea.java
src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java
src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingle.java
src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingleExample.java

index be49cdacad0f83159e23124681c353ff4234c8ec..d4dadb4914cd8271c27c3a52be7d6bf2f4f48a7f 100644 (file)
@@ -40,10 +40,10 @@ public class PanelLightExample extends VerticalLayout implements ClickListener {
     }\r
 \r
     public void buttonClick(ClickEvent event) {\r
-        if (panel.getCaption().equals("")) {\r
-            panel.setCaption("This is a standard Panel");\r
+        if (panel.getCaption() == null) {\r
+            panel.setCaption("This is a light Panel");\r
         } else {\r
-            panel.setCaption("");\r
+            panel.setCaption(null);\r
         }\r
     }\r
 }\r
index 354747162f299acaaa9d2d34cd28978215e66c89..191247f81bfbd33d3e34cd34e1653fbf32bf0a2a 100644 (file)
@@ -16,6 +16,7 @@ public class LabelRichExample extends VerticalLayout implements ClickListener {
 \r
     public LabelRichExample() {\r
         setSpacing(true);\r
+        setSizeUndefined(); // let layout grow with content\r
 \r
         richText = new Label("<h1>Rich text label example</h1>"\r
                 + "<p>In this example, the content mode is set to "\r
@@ -25,20 +26,21 @@ public class LabelRichExample extends VerticalLayout implements ClickListener {
 \r
         addComponent(richText);\r
 \r
-        b = new Button("Edit label");\r
+        b = new Button("Edit");\r
         b.addListener(this);\r
         addComponent(b);\r
+        setComponentAlignment(b, "right");\r
     }\r
 \r
     public void buttonClick(ClickEvent event) {\r
         if (getComponentIterator().next() == richText) {\r
             editor.setValue(richText.getValue());\r
             replaceComponent(richText, editor);\r
-            b.setCaption("Show label");\r
+            b.setCaption("Apply");\r
         } else {\r
             richText.setValue(editor.getValue());\r
             replaceComponent(editor, richText);\r
-            b.setCaption("Edit label");\r
+            b.setCaption("Edit");\r
         }\r
     }\r
 \r
index 4af2b6f70f769584a40d0dae9f6ada9a89cdeead..8878584034e7a073925b6d9aab82cbc0bc1b9c2e 100644 (file)
@@ -4,7 +4,7 @@ import com.itmill.toolkit.demo.sampler.APIResource;
 import com.itmill.toolkit.demo.sampler.Feature;\r
 import com.itmill.toolkit.demo.sampler.NamedExternalResource;\r
 import com.itmill.toolkit.ui.Component;\r
-import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.RichTextArea;\r
 \r
 public class RichTextEditor extends Feature {\r
     @Override\r
@@ -15,20 +15,19 @@ public class RichTextEditor extends Feature {
     @Override\r
     public String getDescription() {\r
         return "A RichTextArea component allows editing XHTML"\r
-                + " content. Click the edit button to open the"\r
+                + " content. <br/>Click the edit button to open the"\r
                 + " editor and the show button to show the edited"\r
                 + " result as an XHTML label.";\r
     }\r
 \r
     @Override\r
     public APIResource[] getRelatedAPI() {\r
-        return new APIResource[] { new APIResource(Label.class) };\r
+        return new APIResource[] { new APIResource(RichTextArea.class) };\r
     }\r
 \r
     @Override\r
     public Class[] getRelatedFeatures() {\r
-        return new Class[] { LabelPlain.class, LabelPreformatted.class,\r
-                LabelRich.class, TextFieldSingle.class, TextArea.class };\r
+        return new Class[] { TextArea.class, LabelRich.class };\r
     }\r
 \r
     @Override\r
index 52611d9d7ce1d609e23a7bb469fc9de40f789769..474a8620e4e3698b7a19e77750039dc3fb203a3d 100644 (file)
@@ -15,14 +15,9 @@ public class TextArea extends Feature {
     public String getDescription() {\r
         return "A multi-line Textfield component allows you to input"\r
                 + " several lines of text."\r
-                + "<br>In this example the text will be shown in a"\r
-                + " label component after you press enter."\r
                 + "<br>The amount of columns and lines can be set, and both are set here to"\r
                 + " 20 characters. Note that this only affects the width and height of the"\r
-                + " component, not the allowed length of input."\r
-                + "<br>For sensitive data input, the textfield can"\r
-                + " also be set into secret mode where the input will not be"\r
-                + " echoed to display.";\r
+                + " component, not the allowed length of input.";\r
     }\r
 \r
     @Override\r
index f99226df2323c0d5c24311939e654d18fa443bdf..c031e499bf12d42758eb1821e65984816223adf3 100644 (file)
@@ -2,34 +2,33 @@ package com.itmill.toolkit.demo.sampler.features.text;
 \r
 import com.itmill.toolkit.data.Property;\r
 import com.itmill.toolkit.data.Property.ValueChangeEvent;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.HorizontalLayout;\r
 import com.itmill.toolkit.ui.Label;\r
 import com.itmill.toolkit.ui.TextField;\r
-import com.itmill.toolkit.ui.VerticalLayout;\r
 \r
-public class TextAreaExample extends VerticalLayout implements\r
+public class TextAreaExample extends HorizontalLayout implements\r
         Property.ValueChangeListener {\r
 \r
+    private static final String initialText = "The quick brown fox jumps over the lazy dog.";\r
+\r
     private Label plainText;\r
-    private final TextField editor = new TextField();\r
+    private final TextField editor;\r
 \r
     public TextAreaExample() {\r
         setSpacing(true);\r
 \r
-        plainText = new Label("Initial text.\n"\r
-                + "\nPlease note that within a textarea,"\r
-                + "\nthe enter key will not dispatch the"\r
-                + "\nchanges to the server. To fire a"\r
-                + "\nvaluechange event, you must deactivate"\r
-                + "\nthe textarea.");\r
-        plainText.setContentMode(Label.CONTENT_PREFORMATTED);\r
-\r
+        editor = new TextField("", initialText);\r
         editor.addListener(this);\r
         editor.setImmediate(true);\r
         editor.setColumns(20);\r
         editor.setRows(20);\r
-        // editor.setSecret(true);\r
-\r
         addComponent(editor);\r
+\r
+        addComponent(new Button(">>"));\r
+\r
+        plainText = new Label(initialText);\r
+        plainText.setContentMode(Label.CONTENT_XHTML);\r
         addComponent(plainText);\r
     }\r
 \r
@@ -38,6 +37,11 @@ public class TextAreaExample extends VerticalLayout implements
      * label component\r
      */\r
     public void valueChange(ValueChangeEvent event) {\r
-        plainText.setValue(editor.getValue());\r
+        String text = (String) editor.getValue();\r
+        if (text != null) {\r
+            // replace newline with BR, because we're using Label.CONTENT_XHTML\r
+            text = text.replaceAll("\n", "<br/>");\r
+        }\r
+        plainText.setValue(text);\r
     }\r
 }\r
index aeacafb54b3b50a064a7db9c28ae0d134f6a8e1c..50b910a456e0051c4f2c09543033d91e9f10ba64 100644 (file)
@@ -2,8 +2,9 @@ package com.itmill.toolkit.demo.sampler.features.text;
 \r
 import com.itmill.toolkit.demo.sampler.APIResource;\r
 import com.itmill.toolkit.demo.sampler.Feature;\r
+import com.itmill.toolkit.demo.sampler.FeatureSet;\r
 import com.itmill.toolkit.demo.sampler.NamedExternalResource;\r
-import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.TextField;\r
 \r
 public class TextFieldSingle extends Feature {\r
     @Override\r
@@ -14,26 +15,20 @@ public class TextFieldSingle extends Feature {
     @Override\r
     public String getDescription() {\r
         return "A single line Textfield component allows you to input"\r
-                + " one line of text."\r
-                + "<br>In this example the text will be shown in a"\r
-                + " label component after you press enter."\r
-                + "<br>The amount of columns can be set, and is set here to"\r
-                + " 5 characters. Note that this only affects the width of the"\r
-                + " component, not the allowed length of input."\r
-                + "<br>For sensitive data input, the textfield can"\r
+                + " one line of text.<br/>"\r
+                + "<br/>For sensitive data input, the textfield can"\r
                 + " also be set into secret mode where the input will not be"\r
                 + " echoed to display.";\r
     }\r
 \r
     @Override\r
     public APIResource[] getRelatedAPI() {\r
-        return new APIResource[] { new APIResource(Label.class) };\r
+        return new APIResource[] { new APIResource(TextField.class) };\r
     }\r
 \r
     @Override\r
     public Class[] getRelatedFeatures() {\r
-        return new Class[] { LabelPlain.class, LabelPreformatted.class,\r
-                RichTextEditor.class };\r
+        return new Class[] { FeatureSet.Texts.class };\r
     }\r
 \r
     @Override\r
index 1095fc94eec549501c6fe80ea866d21174e55c30..a8f01c9870c322c7aa51a187cdb3f0210fdf297e 100644 (file)
@@ -2,28 +2,22 @@ package com.itmill.toolkit.demo.sampler.features.text;
 \r
 import com.itmill.toolkit.data.Property;\r
 import com.itmill.toolkit.data.Property.ValueChangeEvent;\r
-import com.itmill.toolkit.ui.Label;\r
 import com.itmill.toolkit.ui.TextField;\r
 import com.itmill.toolkit.ui.VerticalLayout;\r
 \r
 public class TextFieldSingleExample extends VerticalLayout implements\r
         Property.ValueChangeListener {\r
 \r
-    private Label plainText;\r
-    private final TextField editor = new TextField();\r
+    private final TextField editor = new TextField("Echo this:");\r
 \r
     public TextFieldSingleExample() {\r
         setSpacing(true);\r
 \r
-        plainText = new Label("Initial text");\r
-        plainText.setContentMode(Label.CONTENT_TEXT);\r
-\r
         editor.addListener(this);\r
         editor.setImmediate(true);\r
-        editor.setColumns(5);\r
-        // editor.setSecret(true);\r
+        // editor.setColumns(5); // guarantees that at least 5 chars fit\r
+        // editor.setSecret(true); // e.g. for passwords\r
 \r
-        addComponent(plainText);\r
         addComponent(editor);\r
     }\r
 \r
@@ -32,6 +26,7 @@ public class TextFieldSingleExample extends VerticalLayout implements
      * label component\r
      */\r
     public void valueChange(ValueChangeEvent event) {\r
-        plainText.setValue(editor.getValue());\r
+        // Show the new value we received\r
+        getWindow().showNotification((String) editor.getValue());\r
     }\r
 }\r