package com.vaadin.tests.layouts.layouttester; import com.vaadin.server.Resource; import com.vaadin.server.ThemeResource; import com.vaadin.server.UserError; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ContentMode; import com.vaadin.tests.components.AbstractReindeerTestUI; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.AbstractOrderedLayout; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.TabSheet; import com.vaadin.ui.VerticalLayout; import com.vaadin.v7.ui.Table; import com.vaadin.v7.ui.TextField; /** * * Base class for Layout tests. */ public abstract class BaseLayoutTestUI extends AbstractReindeerTestUI { protected static final String FOLDER_16_PNG = "../icons/runo/16/folder.png"; protected static final String CALENDAR_32_PNG = "../runo/icons/16/calendar.png"; protected static final String LOCK_16_PNG = "../runo/icons/16/lock.png"; protected static final String GLOBE_16_PNG = "../runo/icons/16/globe.png"; public Alignment[] alignments = new Alignment[] { Alignment.TOP_LEFT, Alignment.TOP_CENTER, Alignment.TOP_RIGHT, Alignment.MIDDLE_LEFT, Alignment.MIDDLE_CENTER, Alignment.MIDDLE_RIGHT, Alignment.BOTTOM_LEFT, Alignment.BOTTOM_CENTER, Alignment.BOTTOM_RIGHT }; public final String[] CAPTIONS = { "", "VeryLongOneWordCaption", "Very long caption of 50 approximately symbols aaaaaaaaaaaa aaaaaa aaa " }; Resource[] ICONS = { new ThemeResource(CALENDAR_32_PNG), new ThemeResource(LOCK_16_PNG), new ThemeResource(GLOBE_16_PNG) }; public AbstractComponent[] components = new AbstractComponent[alignments.length]; protected AbstractOrderedLayout l1; protected AbstractOrderedLayout l2; protected Class extends AbstractLayout> layoutClass; protected VerticalLayout mainLayout = new VerticalLayout(); public BaseLayoutTestUI(Class extends AbstractLayout> layoutClass) { super(); fillComponents(); this.layoutClass = layoutClass; } protected void init() { try { l1 = (AbstractOrderedLayout) layoutClass.newInstance(); l2 = (AbstractOrderedLayout) layoutClass.newInstance(); l1.setMargin(false); l1.setSpacing(false); l2.setMargin(false); l2.setSpacing(false); } catch (InstantiationException | IllegalAccessException e1) { e1.printStackTrace(); } if (layoutClass.equals(HorizontalLayout.class)) { setLayoutMeasures(l1, l2, "600px", "400px"); } else if (layoutClass.equals(VerticalLayout.class)) { setLayoutMeasures(l1, l2, "400px", "400px"); } else { setDefaultForVertical(l1, l2); } } private void fillComponents() { for (int i = 0; i < components.length; i++) { String name = "Field" + i; TextField field = new TextField(alignments[i].getVerticalAlignment() + " " + alignments[i].getHorizontalAlignment()); field.setValue(name); components[i] = field; } } protected AbstractLayout createLabelsFields( Class extends AbstractComponent> compType) { return createLabelsFields(compType, false, null); } protected void getLayoutForLayoutSizing(final String compType) { l2.setSpacing(false); l2.setMargin(false); final AbstractComponent c1 = getTestTable(); final AbstractComponent c2 = getTestTable(); class SetSizeButton extends Button { SetSizeButton(final String size) { super(); setCaption("Set size " + size); addClickListener(event -> { if (compType == "layout") { l2.setHeight(size); l2.setWidth(size); } else if (compType == "component") { c2.setHeight(size); c2.setWidth(size); c2.setCaption("Configured width"); } }); } } Button btn1 = new SetSizeButton("350px"); Button btn2 = new SetSizeButton("-1px"); Button btn3 = new SetSizeButton("75%"); Button btn4 = new SetSizeButton("100%"); Label spacer = new Label( "