You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ThemeChangeOnTheFly.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.themes;
  17. import com.vaadin.annotations.Theme;
  18. import com.vaadin.server.ThemeResource;
  19. import com.vaadin.server.VaadinRequest;
  20. import com.vaadin.tests.components.AbstractTestUIWithLog;
  21. import com.vaadin.tests.util.PersonContainer;
  22. import com.vaadin.ui.Button;
  23. import com.vaadin.ui.Button.ClickEvent;
  24. import com.vaadin.ui.Button.ClickListener;
  25. import com.vaadin.ui.GridLayout;
  26. import com.vaadin.ui.HorizontalLayout;
  27. import com.vaadin.ui.Image;
  28. import com.vaadin.ui.Label;
  29. import com.vaadin.ui.Table;
  30. @Theme("reindeer")
  31. public class ThemeChangeOnTheFly extends AbstractTestUIWithLog {
  32. @Override
  33. protected void setup(VaadinRequest request) {
  34. Button inject = new Button("Inject blue background");
  35. inject.addClickListener(new ClickListener() {
  36. @Override
  37. public void buttonClick(ClickEvent event) {
  38. getPage().getStyles().add(
  39. ".v-app { background: blue !important;}");
  40. }
  41. });
  42. addComponent(inject);
  43. GridLayout gl = new GridLayout(2, 4);
  44. gl.setCaption("Change theme by clicking a button");
  45. for (final String theme : new String[] { "reindeer", "runo",
  46. "chameleon", "base", null }) {
  47. Button b = new Button(theme);
  48. b.setId(theme + "");
  49. b.addClickListener(new ClickListener() {
  50. @Override
  51. public void buttonClick(ClickEvent event) {
  52. getUI().setTheme(theme);
  53. }
  54. });
  55. gl.addComponent(b);
  56. }
  57. Table t = new Table();
  58. PersonContainer pc = PersonContainer.createWithTestData();
  59. pc.addNestedContainerBean("address");
  60. t.setContainerDataSource(pc);
  61. gl.addComponent(t, 0, 3, 1, 3);
  62. gl.setRowExpandRatio(3, 1);
  63. gl.setWidth("500px");
  64. gl.setHeight("800px");
  65. HorizontalLayout images = new HorizontalLayout();
  66. images.setSpacing(true);
  67. Label l = new Label("Chameleon theme image in caption");
  68. l.setIcon(new ThemeResource("img/magnifier.png"));
  69. images.addComponent(l);
  70. Image image = new Image("Runo theme image", new ThemeResource(
  71. "icons/64/ok.png"));
  72. images.addComponent(image);
  73. image = new Image("Reindeer theme image", new ThemeResource(
  74. "button/img/left-focus.png"));
  75. images.addComponent(image);
  76. addComponent(images);
  77. addComponent(gl);
  78. getLayout().setSpacing(true);
  79. }
  80. @Override
  81. protected String getTestDescription() {
  82. return "Test that you can change theme on the fly";
  83. }
  84. @Override
  85. protected Integer getTicketNumber() {
  86. return 2874;
  87. }
  88. }