123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package com.vaadin.tests.components.caption;
-
- import com.vaadin.server.ThemeResource;
- import com.vaadin.shared.ui.ContentMode;
- import com.vaadin.tests.VaadinClasses;
- import com.vaadin.tests.components.TestBase;
- import com.vaadin.tests.util.Log;
- import com.vaadin.ui.ComboBox;
- import com.vaadin.ui.ComponentContainer;
- import com.vaadin.ui.Embedded;
- import com.vaadin.ui.Label;
- import com.vaadin.ui.VerticalLayout;
-
- public class IconsInCaption extends TestBase {
-
- private static final String TYPE_EMBEDDED = "Embedded";
- private static final String TYPE_CAPTION = "In caption";
-
- private static final String[] icons = new String[] { "arrow-down.png",
- "arrow-left.png", "arrow-right.png", "arrow-up.png",
- "attention.png", "calendar.png", "cancel.png", "document.png",
- "document-add.png", "document-delete.png", "document-doc.png",
- "document-image.png", "document-pdf.png", "document-ppt.png",
- "document-txt.png", "document-web.png", "document-xsl.png",
- "email.png", "email-reply.png", "email-send.png", "folder.png",
- "folder-add.png", "folder-delete.png", "globe.png", "help.png",
- "lock.png", "note.png", "ok.png", "reload.png", "settings.png",
- "trash.png", "trash-full.png", "user.png", "users.png" };
-
- private static final String[] sizes = new String[] { "16", "32", "64" };
-
- private ComponentContainer container = new VerticalLayout();
-
- private Log log = new Log(5);
-
- private ComboBox<Class<? extends ComponentContainer>> containerSelect;
-
- private ComboBox<String> iconTypeSelect;
-
- @Override
- protected void setup() {
- iconTypeSelect = new ComboBox<>("Icon container");
- iconTypeSelect.setItems(TYPE_EMBEDDED, TYPE_CAPTION);
- iconTypeSelect.setEmptySelectionAllowed(false);
- iconTypeSelect.addValueChangeListener(event -> updateContainer());
-
- containerSelect = new ComboBox<>("Container", VaadinClasses
- .getComponentContainersSupportingUnlimitedNumberOfComponents());
- containerSelect.addValueChangeListener(event -> updateContainer());
-
- addComponent(log);
- addComponent(iconTypeSelect);
- addComponent(containerSelect);
- addComponent(container);
-
- iconTypeSelect.setValue(TYPE_CAPTION);
- containerSelect.setValue(VerticalLayout.class);
- }
-
- protected void updateContainer() {
- Class<? extends ComponentContainer> containerClass = containerSelect
- .getValue();
- if (containerClass == null) {
- return;
- }
-
- Object iconType = iconTypeSelect.getValue();
- try {
- ComponentContainer newContainer = createContainer(containerClass,
- iconType);
- replaceComponent(container, newContainer);
- container = newContainer;
- log.log("Container changed to " + containerClass.getName() + "/"
- + iconType);
- } catch (Exception e) {
- log.log("Create container failed for " + containerClass.getName()
- + ": " + e.getMessage());
- e.printStackTrace();
- }
-
- }
-
- private static ComponentContainer createContainer(
- Class<? extends ComponentContainer> containerClass, Object iconType)
- throws InstantiationException, IllegalAccessException {
- ComponentContainer container = containerClass.newInstance();
- for (String size : sizes) {
- Label title = new Label("<h3>" + size + "x" + size + "</h3>",
- ContentMode.HTML);
- container.addComponent(title);
- for (String icon : icons) {
- ThemeResource res = new ThemeResource(
- "../runo/icons/" + size + "/" + icon);
- if (TYPE_CAPTION.equals(iconType)) {
- Label name = new Label();
- name.setCaption(icon);
- name.setIcon(res);
- container.addComponent(name);
- } else if (TYPE_EMBEDDED.equals(iconType)) {
- Embedded e = new Embedded(icon, res);
- container.addComponent(e);
- }
- }
- }
-
- return container;
- }
-
- @Override
- protected String getDescription() {
- return "Test for comparing rendering speed of icons in a caption and in an Embedded component in different component containers.";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 6578;
- }
-
- }
|