@Override public void setComponentAlignment(Component childComponent, Alignment alignment) { ChildComponentData childData = getState().childData.get(childComponent); if (childData != null) { // Alignments are bit masks childData.alignmentBitmask = alignment.getBitMask(); } else { throw new IllegalArgumentException( "Component must be added to layout before using setComponentAlignment()"); } }
/** * Writes the alignment to the given child element attributes. * * @since 7.6.4 * @param childElement * the child element * @param alignment * the component alignment */ public static void writeAlignment(Element childElement, Alignment alignment) { if (alignment.isMiddle()) { childElement.attr(":middle", true); } else if (alignment.isBottom()) { childElement.attr(":bottom", true); } if (alignment.isCenter()) { childElement.attr(":center", true); } else if (alignment.isRight()) { childElement.attr(":right", true); } }
@Override public Alignment getComponentAlignment(Component childComponent) { ChildComponentData childData = getState().childData.get(childComponent); if (childData == null) { throw new IllegalArgumentException( "The given component is not a child of this layout"); } return new Alignment(childData.alignmentBitmask); }
public void recalculateExpandRatios() { for (Iterator<Component> it = getComponentIterator(); it.hasNext(); ) { setExpandRatio(it.next(), 0.0f); } if (getComponentCount() > 0) { if (alignment.isLeft()) { setExpandRatio(getComponent(getComponentCount() - 1), 1.0f); } else if (alignment.isRight()) { setExpandRatio(getComponent(0), 1.0f); } } } }
removeStyleName(CSS_ALIGNMENT_MIDDLE_RIGHT); if (defaultAlignment.equals(Alignment.BOTTOM_LEFT)) { addStyleName(CSS_ALIGNMENT_BOTTOM_LEFT); } else if (defaultAlignment.equals(Alignment.BOTTOM_CENTER)) { addStyleName(CSS_ALIGNMENT_BOTTOM_CENTER); } else if (defaultAlignment.equals(Alignment.BOTTOM_RIGHT)) { addStyleName(CSS_ALIGNMENT_BOTTOM_RIGHT); } else if (defaultAlignment.equals(Alignment.TOP_LEFT)) { addStyleName(CSS_ALIGNMENT_TOP_LEFT); } else if (defaultAlignment.equals(Alignment.TOP_CENTER)) { addStyleName(CSS_ALIGNMENT_TOP_CENTER); } else if (defaultAlignment.equals(Alignment.TOP_RIGHT)) { addStyleName(CSS_ALIGNMENT_TOP_RIGHT); } else if (defaultAlignment.equals(Alignment.MIDDLE_LEFT)) { addStyleName(CSS_ALIGNMENT_MIDDLE_LEFT); } else if (defaultAlignment.equals(Alignment.MIDDLE_CENTER)) { addStyleName(CSS_ALIGNMENT_MIDDLE_CENTER); } else if (defaultAlignment.equals(Alignment.MIDDLE_RIGHT)) { addStyleName(CSS_ALIGNMENT_MIDDLE_RIGHT);
public static HorizontalLayout horizontalLayout(Alignment alignment, com.vaadin.ui.Component... components) { HorizontalLayout hl = new HorizontalLayout(); hl.setWidth(100, Sizeable.UNITS_PERCENTAGE); hl.setSpacing(true); if (components != null && components.length > 0) { for (com.vaadin.ui.Component c : components) { hl.addComponent(c); hl.setComponentAlignment(c, alignment); } if (alignment.isRight()) { hl.setExpandRatio(hl.getComponent(0), 1.0f); } else if (alignment.isLeft()) { hl.setExpandRatio(hl.getComponent(hl.getComponentCount() - 1), 1.0f); } } return hl; }
@Override public void setComponentAlignment(Component childComponent, Alignment alignment) { ChildComponentData childComponentData = getState().childData .get(childComponent); if (childComponentData == null) { throw new IllegalArgumentException( "Component must be added to layout before using setComponentAlignment()"); } else { if (alignment == null) { childComponentData.alignment = GridLayoutState.ALIGNMENT_DEFAULT .getBitMask(); } else { childComponentData.alignment = alignment.getBitMask(); } } }
@Override public Alignment getComponentAlignment(Component childComponent) { ChildComponentData childComponentData = getState(false).childData .get(childComponent); if (childComponentData == null) { throw new IllegalArgumentException( "The given component is not a child of this layout"); } else { return new Alignment(childComponentData.alignment); } }
private void componentAdded(Component c) { ChildComponentData ccd = new ChildComponentData(); ccd.alignmentBitmask = getDefaultComponentAlignment().getBitMask(); getState().childData.put(c, ccd); }
/** * Read the alignment from the given child component attributes. * * @since 7.6.4 * @param attr * the child component attributes * @return the component alignment */ public static Alignment readAlignment(Attributes attr) { int bitMask = 0; if (attr.hasKey(":middle")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_VERTICAL_CENTER; } else if (attr.hasKey(":bottom")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_BOTTOM; } else { bitMask += AlignmentInfo.Bits.ALIGNMENT_TOP; } if (attr.hasKey(":center")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_HORIZONTAL_CENTER; } else if (attr.hasKey(":right")) { bitMask += AlignmentInfo.Bits.ALIGNMENT_RIGHT; } else { bitMask += AlignmentInfo.Bits.ALIGNMENT_LEFT; } return new Alignment(bitMask); }
/** * <p> * Construct a new area on a grid. * </p> * * @param component * the component connected to the area. * @param column1 * The column of the upper left corner cell of the area. The * leftmost column has index 0. * @param row1 * The row of the upper left corner cell of the area. The * topmost row has index 0. * @param column2 * The column of the lower right corner cell of the area. The * leftmost column has index 0. * @param row2 * The row of the lower right corner cell of the area. The * topmost row has index 0. */ public Area(Component component, int column1, int row1, int column2, int row2) { this.component = component; childData = new ChildComponentData(); childData.alignment = getDefaultComponentAlignment().getBitMask(); childData.column1 = column1; childData.row1 = row1; childData.column2 = column2; childData.row2 = row2; }
/** * Sets opening direction for the popup. At the moment only support values are * {@link com.vaadin.ui.Alignment#BOTTOM_LEFT}, {@link com.vaadin.ui.Alignment#BOTTOM_CENTER} and * {@link com.vaadin.ui.Alignment#BOTTOM_RIGHT}. * * Default is {@link com.vaadin.ui.Alignment#BOTTOM_RIGHT}. */ public void setDirection(final Alignment direction) { if (direction == null) { throw new IllegalArgumentException("direction cannot be null"); } this.direction = direction; getState().direction = direction.getBitMask(); }
/** * Sets opening direction for the popup. At the moment only support values are * {@link com.vaadin.ui.Alignment#BOTTOM_LEFT}, {@link com.vaadin.ui.Alignment#BOTTOM_CENTER} and * {@link com.vaadin.ui.Alignment#BOTTOM_RIGHT}. * * Default is {@link com.vaadin.ui.Alignment#BOTTOM_RIGHT}. */ public void setDirection(final Alignment direction) { if (direction == null) { throw new IllegalArgumentException("direction cannot be null"); } this.direction = direction; getState().direction = direction.getBitMask(); }
/** * Sets opening direction for the popup. At the moment only support values are * {@link Alignment#BOTTOM_LEFT}, {@link Alignment#BOTTOM_CENTER} and * {@link Alignment#BOTTOM_RIGHT}. * * Default is {@link Alignment#BOTTOM_RIGHT}. */ public void setDirection(final Alignment direction) { if (direction == null) { throw new IllegalArgumentException("direction cannot be null"); } this.direction = direction; getState().direction = direction.getBitMask(); }