--- /dev/null
+package com.itmill.toolkit.demo.featurebrowser;\r
+\r
+import com.itmill.toolkit.terminal.ExternalResource;\r
+import com.itmill.toolkit.terminal.ThemeResource;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.CheckBox;\r
+import com.itmill.toolkit.ui.CustomComponent;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.Link;\r
+import com.itmill.toolkit.ui.OrderedLayout;\r
+import com.itmill.toolkit.ui.Panel;\r
+import com.itmill.toolkit.ui.Button.ClickEvent;\r
+\r
+/**\r
+ * Shows a few variations of Buttons and Links.\r
+ * \r
+ * @author IT Mill Ltd.\r
+ */\r
+public class ButtonExample extends CustomComponent implements\r
+ Button.ClickListener {\r
+\r
+ Panel status;\r
+\r
+ public ButtonExample() {\r
+\r
+ OrderedLayout main = new OrderedLayout();\r
+ main.setMargin(true);\r
+ setCompositionRoot(main);\r
+\r
+ OrderedLayout horiz = new OrderedLayout(\r
+ OrderedLayout.ORIENTATION_HORIZONTAL);\r
+ main.addComponent(horiz);\r
+ Panel basic = new Panel("Basic buttons");\r
+ basic.setStyleName(Panel.STYLE_LIGHT);\r
+ horiz.addComponent(basic);\r
+ Panel bells = new Panel("+ bells & whistles");\r
+ bells.setStyleName(Panel.STYLE_LIGHT);\r
+ horiz.addComponent(bells);\r
+ status = new Panel("Clicked");\r
+ status.setStyleName(Panel.STYLE_LIGHT);\r
+ horiz.addComponent(status);\r
+\r
+ Button b = new Button("Basic button");\r
+ b.addListener(this);\r
+ basic.addComponent(b);\r
+\r
+ b = new Button("Button w/ icon + tooltip");\r
+ b.addListener(this);\r
+ b.setIcon(new ThemeResource("icons/ok.png"));\r
+ b.setDescription("This button does nothing, fast");\r
+ bells.addComponent(b);\r
+\r
+ b = new CheckBox("CheckBox - a switch-button");\r
+ b.setImmediate(true); // checkboxes are not immediate by default\r
+ b.addListener(this);\r
+ basic.addComponent(b);\r
+\r
+ b = new CheckBox("CheckBox w/ icon + tooltip");\r
+ b.setImmediate(true); // checkboxes are not immediate by default\r
+ b.addListener(this);\r
+ b.setIcon(new ThemeResource("icons/ok.png"));\r
+ b.setDescription("This is a CheckBox");\r
+ bells.addComponent(b);\r
+\r
+ b = new Button("Link-style button");\r
+ b.addListener(this);\r
+ b.setStyleName(Button.STYLE_LINK);\r
+ basic.addComponent(b);\r
+\r
+ b = new Button("Link button w/ icon + tooltip");\r
+ b.addListener(this);\r
+ b.setStyleName(Button.STYLE_LINK);\r
+ b.setIcon(new ThemeResource("icons/ok.png"));\r
+ b.setDescription("Link-style, icon+tootip, no caption");\r
+ bells.addComponent(b);\r
+\r
+ b = new Button();\r
+ b.addListener(this);\r
+ b.setStyleName(Button.STYLE_LINK);\r
+ b.setIcon(new ThemeResource("icons/ok.png"));\r
+ b.setDescription("Link-style, icon+tootip, no caption");\r
+ basic.addComponent(b);\r
+\r
+ Panel links = new Panel("Links");\r
+ links.setStyleName(Panel.STYLE_LIGHT);\r
+ main.addComponent(links);\r
+ Label desc = new Label(\r
+ "The main difference between a Link and"\r
+ + " a link-styled Button is that the Link works client-"\r
+ + " side, whereas the Button works server side.<br/> This means"\r
+ + " that the Button triggers some event on the server,"\r
+ + " while the Link is a normal web-link. <br/><br/>Note that for"\r
+ + " opening new windows, the Link might be a safer "\r
+ + " choice, since popup-blockers might interfer with "\r
+ + " server-initiated window opening.");\r
+ desc.setContentMode(Label.CONTENT_XHTML);\r
+ links.addComponent(desc);\r
+ Link l = new Link("IT Mill home", new ExternalResource(\r
+ "http://www.itmill.com"));\r
+ l.setDescription("Link without target name, opens in this window");\r
+ links.addComponent(l);\r
+\r
+ l = new Link("IT Mill home (new window)", new ExternalResource(\r
+ "http://www.itmill.com"));\r
+ l.setTargetName("_blank");\r
+ l.setDescription("Link with target name, opens in new window");\r
+ links.addComponent(l);\r
+\r
+ l = new Link("IT Mill home (new window, less decor)",\r
+ new ExternalResource("http://www.itmill.com"));\r
+ l.setTargetName("_blank");\r
+ l.setTargetBorder(Link.TARGET_BORDER_MINIMAL);\r
+ l.setTargetName("_blank");\r
+ l\r
+ .setDescription("Link with target name and BORDER_MINIMAL, opens in new window with less decor");\r
+ links.addComponent(l);\r
+\r
+ l = new Link("IT Mill home (new 200x200 window, no decor, icon)",\r
+ new ExternalResource("http://www.itmill.com"), "_blank", 200,\r
+ 200, Link.TARGET_BORDER_NONE);\r
+ l.setTargetName("_blank");\r
+ l\r
+ .setDescription("Link with target name and BORDER_NONE, opens in new window with no decor");\r
+ l.setIcon(new ThemeResource("icons/ok.png"));\r
+ links.addComponent(l);\r
+\r
+ }\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ Button clicked = event.getButton();\r
+ String caption = clicked.getCaption();\r
+ if (caption == null) {\r
+ caption = "<icon>";\r
+ }\r
+ status.removeAllComponents();\r
+ Label l = new Label("Clicked: " + caption + "<br/>" + "Value: "\r
+ + clicked.getValue());\r
+ l.setContentMode(Label.CONTENT_XHTML);\r
+ status.addComponent(l);\r
+\r
+ }\r
+\r
+}\r