From: Teppo Kurki Date: Tue, 13 Jan 2009 14:13:57 +0000 (+0000) Subject: Added Label, TextField and RichTextArea examples. X-Git-Tag: 6.7.0.beta1~3342 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e2e047b8b5d31cd81208fd45c51b77979964d682;p=vaadin-framework.git Added Label, TextField and RichTextArea examples. svn changeset:6522/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java index e3b365b55d..97d6137942 100644 --- a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java +++ b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java @@ -42,6 +42,12 @@ import com.itmill.toolkit.demo.sampler.features.selects.TwinColumnSelect; import com.itmill.toolkit.demo.sampler.features.tabsheets.TabSheetDisabled; import com.itmill.toolkit.demo.sampler.features.tabsheets.TabSheetIcons; import com.itmill.toolkit.demo.sampler.features.tabsheets.TabSheetScrolling; +import com.itmill.toolkit.demo.sampler.features.text.LabelPlain; +import com.itmill.toolkit.demo.sampler.features.text.LabelPreformatted; +import com.itmill.toolkit.demo.sampler.features.text.LabelRich; +import com.itmill.toolkit.demo.sampler.features.text.RichTextEditor; +import com.itmill.toolkit.demo.sampler.features.text.TextArea; +import com.itmill.toolkit.demo.sampler.features.text.TextFieldSingle; import com.itmill.toolkit.demo.sampler.features.windows.WindowChild; import com.itmill.toolkit.demo.sampler.features.windows.WindowChildAutosize; import com.itmill.toolkit.demo.sampler.features.windows.WindowChildModal; @@ -97,6 +103,7 @@ public class FeatureSet extends Feature { new Panels(), // // new Forms(), not done yet new Windows(), // + new Texts(), // }); } } @@ -237,6 +244,20 @@ public class FeatureSet extends Feature { } } + public static class Texts extends FeatureSet { + public Texts() { + super("Texts", new Feature[] { + // + new LabelPlain(), // + new LabelPreformatted(), // + new LabelRich(), // + new RichTextEditor(), // + new TextFieldSingle(), // + new TextArea(), // + }); + } + } + // ---------------------------------------------------------- /* * FeatureSet implementation follows. diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlain.java b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlain.java new file mode 100644 index 0000000000..b65c5ff538 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlain.java @@ -0,0 +1,42 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.demo.sampler.APIResource; +import com.itmill.toolkit.demo.sampler.Feature; +import com.itmill.toolkit.demo.sampler.NamedExternalResource; +import com.itmill.toolkit.ui.Label; + +public class LabelPlain extends Feature { + @Override + public String getName() { + return "Label - Plain text"; + } + + @Override + public String getDescription() { + return "A label is a simple component that allows you to add" + + " optionally formatted text components to your" + + " application." + + "
In this example the content mode is set to" + + " CONTENT_TEXT, meaning that the label will contain" + + " only plain text."; + + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Label.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LabelPreformatted.class, LabelRich.class, + TextFieldSingle.class, TextArea.class, RichTextEditor.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlain.png b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlain.png new file mode 100644 index 0000000000..6865b1bf5b Binary files /dev/null and b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlain.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlainExample.java b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlainExample.java new file mode 100644 index 0000000000..7d2ce6c3ce --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPlainExample.java @@ -0,0 +1,20 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.VerticalLayout; + +public class LabelPlainExample extends VerticalLayout { + + public LabelPlainExample() { + setSpacing(true); + + Label plainText = new Label("This is an example of a Label" + + " component. The content mode of this label is set" + + " to CONTENT_TEXT. This means that it will display" + + " the content text as is. HTML and XML special characters" + + " (<,>,&) are escaped properly to allow displaying them."); + plainText.setContentMode(Label.CONTENT_TEXT); + + addComponent(plainText); + } +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformatted.java b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformatted.java new file mode 100644 index 0000000000..7658991dc6 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformatted.java @@ -0,0 +1,42 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.demo.sampler.APIResource; +import com.itmill.toolkit.demo.sampler.Feature; +import com.itmill.toolkit.demo.sampler.NamedExternalResource; +import com.itmill.toolkit.ui.Label; + +public class LabelPreformatted extends Feature { + @Override + public String getName() { + return "Label - Preformatted"; + } + + @Override + public String getDescription() { + return "A label is a simple component that allows you to add" + + " optionally formatted text components to your" + + " application." + + "
In this example the content mode is set to" + + " CONTENT_PREFORMATTED. The text for this content type" + + " is by default rendered with fixed-width font. Line breaks" + + " can be inserted with \\n and tabulator characters with \\t."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Label.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LabelPlain.class, LabelRich.class, + TextFieldSingle.class, TextArea.class, RichTextEditor.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformatted.png b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformatted.png new file mode 100644 index 0000000000..d033a4b436 Binary files /dev/null and b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformatted.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformattedExample.java b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformattedExample.java new file mode 100644 index 0000000000..2794982c89 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/LabelPreformattedExample.java @@ -0,0 +1,25 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.VerticalLayout; + +public class LabelPreformattedExample extends VerticalLayout { + + public LabelPreformattedExample() { + setSpacing(true); + + Label preformattedText = new Label( + "This is an example of a Label component.\n" + + "\nThe content mode of this label is set" + + "\nto CONTENT_PREFORMATTED. This means" + + "\nthat it will display the content text" + + "\nusing a fixed-width font. You also have" + + "\nto insert the line breaks yourself.\n" + + "\n\tHTML and XML special characters" + + "\n\t(<,>,&) are escaped properly to" + + "\n\tallow displaying them."); + preformattedText.setContentMode(Label.CONTENT_PREFORMATTED); + + addComponent(preformattedText); + } +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelRich.java b/src/com/itmill/toolkit/demo/sampler/features/text/LabelRich.java new file mode 100644 index 0000000000..2772effd13 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/LabelRich.java @@ -0,0 +1,41 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.demo.sampler.APIResource; +import com.itmill.toolkit.demo.sampler.Feature; +import com.itmill.toolkit.demo.sampler.NamedExternalResource; +import com.itmill.toolkit.ui.Label; + +public class LabelRich extends Feature { + @Override + public String getName() { + return "Label - Rich text"; + } + + @Override + public String getDescription() { + return "A label is a simple component that allows you to add" + + " optionally formatted text components to your" + + " application." + + "
In this example the content mode is set to" + + " CONTENT_XHTML. This content mode assumes that the" + + " content set to the label will be valid XHTML."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Label.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LabelPlain.class, LabelPreformatted.class, + RichTextEditor.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelRich.png b/src/com/itmill/toolkit/demo/sampler/features/text/LabelRich.png new file mode 100644 index 0000000000..b1ba9fa202 Binary files /dev/null and b/src/com/itmill/toolkit/demo/sampler/features/text/LabelRich.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/LabelRichExample.java b/src/com/itmill/toolkit/demo/sampler/features/text/LabelRichExample.java new file mode 100644 index 0000000000..354747162f --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/LabelRichExample.java @@ -0,0 +1,45 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.RichTextArea; +import com.itmill.toolkit.ui.VerticalLayout; +import com.itmill.toolkit.ui.Button.ClickEvent; +import com.itmill.toolkit.ui.Button.ClickListener; + +public class LabelRichExample extends VerticalLayout implements ClickListener { + + private Button b; + private Label richText; + + private final RichTextArea editor = new RichTextArea(); + + public LabelRichExample() { + setSpacing(true); + + richText = new Label("

Rich text label example

" + + "

In this example, the content mode is set to " + + "CONTENT_XHTML.

" + + "

This text can be edited with the Edit-button

"); + richText.setContentMode(Label.CONTENT_XHTML); + + addComponent(richText); + + b = new Button("Edit label"); + b.addListener(this); + addComponent(b); + } + + public void buttonClick(ClickEvent event) { + if (getComponentIterator().next() == richText) { + editor.setValue(richText.getValue()); + replaceComponent(richText, editor); + b.setCaption("Show label"); + } else { + richText.setValue(editor.getValue()); + replaceComponent(editor, richText); + b.setCaption("Edit label"); + } + } + +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/RichTextEditor.java b/src/com/itmill/toolkit/demo/sampler/features/text/RichTextEditor.java new file mode 100644 index 0000000000..4af2b6f70f --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/RichTextEditor.java @@ -0,0 +1,44 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.demo.sampler.APIResource; +import com.itmill.toolkit.demo.sampler.Feature; +import com.itmill.toolkit.demo.sampler.NamedExternalResource; +import com.itmill.toolkit.ui.Component; +import com.itmill.toolkit.ui.Label; + +public class RichTextEditor extends Feature { + @Override + public String getName() { + return "Rich text area"; + } + + @Override + public String getDescription() { + return "A RichTextArea component allows editing XHTML" + + " content. Click the edit button to open the" + + " editor and the show button to show the edited" + + " result as an XHTML label."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Label.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LabelPlain.class, LabelPreformatted.class, + LabelRich.class, TextFieldSingle.class, TextArea.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Component getExample() { + return new LabelRichExample(); + } +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/RichTextEditor.png b/src/com/itmill/toolkit/demo/sampler/features/text/RichTextEditor.png new file mode 100644 index 0000000000..140d0ee2fd Binary files /dev/null and b/src/com/itmill/toolkit/demo/sampler/features/text/RichTextEditor.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/TextArea.java b/src/com/itmill/toolkit/demo/sampler/features/text/TextArea.java new file mode 100644 index 0000000000..52611d9d7c --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/TextArea.java @@ -0,0 +1,45 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.demo.sampler.APIResource; +import com.itmill.toolkit.demo.sampler.Feature; +import com.itmill.toolkit.demo.sampler.NamedExternalResource; +import com.itmill.toolkit.ui.Label; + +public class TextArea extends Feature { + @Override + public String getName() { + return "Textarea"; + } + + @Override + public String getDescription() { + return "A multi-line Textfield component allows you to input" + + " several lines of text." + + "
In this example the text will be shown in a" + + " label component after you press enter." + + "
The amount of columns and lines can be set, and both are set here to" + + " 20 characters. Note that this only affects the width and height of the" + + " component, not the allowed length of input." + + "
For sensitive data input, the textfield can" + + " also be set into secret mode where the input will not be" + + " echoed to display."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Label.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LabelPlain.class, LabelPreformatted.class, + RichTextEditor.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/TextArea.png b/src/com/itmill/toolkit/demo/sampler/features/text/TextArea.png new file mode 100644 index 0000000000..cfd04ba696 Binary files /dev/null and b/src/com/itmill/toolkit/demo/sampler/features/text/TextArea.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java b/src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java new file mode 100644 index 0000000000..f99226df23 --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java @@ -0,0 +1,43 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.VerticalLayout; + +public class TextAreaExample extends VerticalLayout implements + Property.ValueChangeListener { + + private Label plainText; + private final TextField editor = new TextField(); + + public TextAreaExample() { + setSpacing(true); + + plainText = new Label("Initial text.\n" + + "\nPlease note that within a textarea," + + "\nthe enter key will not dispatch the" + + "\nchanges to the server. To fire a" + + "\nvaluechange event, you must deactivate" + + "\nthe textarea."); + plainText.setContentMode(Label.CONTENT_PREFORMATTED); + + editor.addListener(this); + editor.setImmediate(true); + editor.setColumns(20); + editor.setRows(20); + // editor.setSecret(true); + + addComponent(editor); + addComponent(plainText); + } + + /* + * Catch the valuechange event of the textfield and update the value of the + * label component + */ + public void valueChange(ValueChangeEvent event) { + plainText.setValue(editor.getValue()); + } +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingle.java b/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingle.java new file mode 100644 index 0000000000..aeacafb54b --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingle.java @@ -0,0 +1,45 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.demo.sampler.APIResource; +import com.itmill.toolkit.demo.sampler.Feature; +import com.itmill.toolkit.demo.sampler.NamedExternalResource; +import com.itmill.toolkit.ui.Label; + +public class TextFieldSingle extends Feature { + @Override + public String getName() { + return "Textfield"; + } + + @Override + public String getDescription() { + return "A single line Textfield component allows you to input" + + " one line of text." + + "
In this example the text will be shown in a" + + " label component after you press enter." + + "
The amount of columns can be set, and is set here to" + + " 5 characters. Note that this only affects the width of the" + + " component, not the allowed length of input." + + "
For sensitive data input, the textfield can" + + " also be set into secret mode where the input will not be" + + " echoed to display."; + } + + @Override + public APIResource[] getRelatedAPI() { + return new APIResource[] { new APIResource(Label.class) }; + } + + @Override + public Class[] getRelatedFeatures() { + return new Class[] { LabelPlain.class, LabelPreformatted.class, + RichTextEditor.class }; + } + + @Override + public NamedExternalResource[] getRelatedResources() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingle.png b/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingle.png new file mode 100644 index 0000000000..2782e57b01 Binary files /dev/null and b/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingle.png differ diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingleExample.java b/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingleExample.java new file mode 100644 index 0000000000..1095fc94ee --- /dev/null +++ b/src/com/itmill/toolkit/demo/sampler/features/text/TextFieldSingleExample.java @@ -0,0 +1,37 @@ +package com.itmill.toolkit.demo.sampler.features.text; + +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.VerticalLayout; + +public class TextFieldSingleExample extends VerticalLayout implements + Property.ValueChangeListener { + + private Label plainText; + private final TextField editor = new TextField(); + + public TextFieldSingleExample() { + setSpacing(true); + + plainText = new Label("Initial text"); + plainText.setContentMode(Label.CONTENT_TEXT); + + editor.addListener(this); + editor.setImmediate(true); + editor.setColumns(5); + // editor.setSecret(true); + + addComponent(plainText); + addComponent(editor); + } + + /* + * Catch the valuechange event of the textfield and update the value of the + * label component + */ + public void valueChange(ValueChangeEvent event) { + plainText.setValue(editor.getValue()); + } +}