diff options
author | Artur Signell <artur@vaadin.com> | 2012-08-30 17:24:36 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-08-30 17:24:36 +0300 |
commit | 7b25b3886ea95bc6495506fbe9472e45fcbde684 (patch) | |
tree | 0b93cb65dab437feb46720659a63b8f1ef48f7f4 /uitest/src/com/vaadin/tests/themes | |
parent | 8941056349e302e687e40e94c13709e75f256d73 (diff) | |
download | vaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.tar.gz vaadin-framework-7b25b3886ea95bc6495506fbe9472e45fcbde684.zip |
Renamed tests -> uitest and tests/testbench -> uitest/src (#9299)
Diffstat (limited to 'uitest/src/com/vaadin/tests/themes')
-rw-r--r-- | uitest/src/com/vaadin/tests/themes/ButtonsTest.java | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/themes/ButtonsTest.java b/uitest/src/com/vaadin/tests/themes/ButtonsTest.java new file mode 100644 index 0000000000..39b43f3516 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/ButtonsTest.java @@ -0,0 +1,173 @@ +package com.vaadin.tests.themes; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.UserError; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.UI; +import com.vaadin.ui.UI.LegacyWindow; + +@SuppressWarnings("serial") +public class ButtonsTest extends com.vaadin.Application.LegacyApplication { + + final UI.LegacyWindow main = new LegacyWindow("Button states & themes"); + + CheckBox styleToggle; + CheckBox iconToggle; + CheckBox nativeToggle; + CheckBox themeToggle; + boolean largeIcons = false; + boolean nativeButtons = false; + + final HorizontalLayout toggles = new HorizontalLayout(); + + @Override + public void init() { + setMainWindow(main); + setTheme("reindeer"); + + themeToggle = new CheckBox("Runo theme"); + themeToggle.addListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + if (getTheme() == "reindeer") { + setTheme("runo"); + } else { + setTheme("reindeer"); + } + } + }); + themeToggle.setStyleName("small"); + themeToggle.setImmediate(true); + + styleToggle = new CheckBox("Black style"); + styleToggle.addListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + if (!main.getContent().getStyleName().contains("black")) { + main.getContent().setStyleName("black"); + } else { + main.getContent().setStyleName(""); + } + } + }); + styleToggle.setImmediate(true); + styleToggle.setStyleName("small"); + + iconToggle = new CheckBox("64x icons"); + iconToggle.addListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + largeIcons = !largeIcons; + recreateAll(); + } + }); + iconToggle.setImmediate(true); + iconToggle.setStyleName("small"); + + nativeToggle = new CheckBox("Native buttons"); + nativeToggle.addListener(new ValueChangeListener() { + + @Override + public void valueChange(ValueChangeEvent event) { + nativeButtons = !nativeButtons; + recreateAll(); + } + }); + nativeToggle.setImmediate(true); + nativeToggle.setStyleName("small"); + + toggles.setSpacing(true); + toggles.addComponent(themeToggle); + toggles.addComponent(styleToggle); + toggles.addComponent(iconToggle); + toggles.addComponent(nativeToggle); + main.addComponent(toggles); + + recreateAll(); + + } + + private void recreateAll() { + main.removeAllComponents(); + main.addComponent(toggles); + + main.addComponent(buildButtons(false, false, false, false)); + main.addComponent(buildButtons(false, false, true, false)); + main.addComponent(buildButtons(false, true, false, false)); + main.addComponent(buildButtons(false, true, true, false)); + main.addComponent(buildButtons(true, false, false, false)); + main.addComponent(buildButtons(true, false, true, false)); + main.addComponent(buildButtons(true, true, false, false)); + main.addComponent(buildButtons(true, true, true, false)); + + main.addComponent(buildButtons(false, false, false, true)); + main.addComponent(buildButtons(false, false, true, true)); + main.addComponent(buildButtons(false, true, false, true)); + main.addComponent(buildButtons(false, true, true, true)); + main.addComponent(buildButtons(true, false, false, true)); + main.addComponent(buildButtons(true, false, true, true)); + main.addComponent(buildButtons(true, true, false, true)); + main.addComponent(buildButtons(true, true, true, true)); + + final Button b = new Button("Tabindex"); + b.setTabIndex(1); + main.addComponent(b); + + Button c = new Button("toggle enabled", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + b.setEnabled(!b.isEnabled()); + } + }); + main.addComponent(c); + } + + private Layout buildButtons(boolean disabled, boolean icon, boolean error, + boolean sized) { + + String[] buttonStyles = new String[] { "Normal", "Primary", "Small", + "Link" }; + + HorizontalLayout hl = new HorizontalLayout(); + hl.setSpacing(true); + hl.setMargin(true); + + for (int i = 0; i < buttonStyles.length; i++) { + Button b; + if (nativeButtons) { + b = new NativeButton(buttonStyles[i] + " style"); + } else { + b = new Button(buttonStyles[i] + " style"); + } + b.setStyleName(buttonStyles[i].toLowerCase()); + if (icon) { + b.setIcon(new ThemeResource("../runo/icons/" + + (largeIcons ? "64" : "16") + "/document.png")); + } + if (error) { + b.setComponentError(new UserError("Error")); + } + if (disabled) { + b.setEnabled(false); + } + if (sized) { + b.setWidth("250px"); + b.setCaption(b.getCaption() + " (250px)"); + } + hl.addComponent(b); + } + + return hl; + } + +} |