/** * Sets a new horizontalAlignment alignment. Used to position the content at the left, right, or center. * * @param horizontal new horizontalAlignment alignment */ public void setHorizontalAlignment(HorizontalAlignment horizontal) { HorizontalAlignment old = this.getHorizontalAlignment(); this.horizontalAlignment = horizontal; setDirty(true); firePropertyChange("horizontalAlignment", old, getHorizontalAlignment()); }
/** * Sets the current whitespace insets. * @param insets new insets */ public void setInsets(Insets insets) { Insets old = this.getInsets(); this.insets = insets; setDirty(true); firePropertyChange("insets", old, getInsets()); }
/** * Sets a new verticalAlignment alignment. Used to position the content at the top, bottom, or center. * * @param vertical new verticalAlignment alignment */ public void setVerticalAlignment(VerticalAlignment vertical) { VerticalAlignment old = this.getVerticalAlignment(); this.verticalAlignment = vertical; setDirty(true); firePropertyChange("verticalAlignment", old, getVerticalAlignment()); }
/** * Sets if the content should be stretched horizontally to fill all available horizontalAlignment * space (minus the left and right insets). * * @param fillHorizontal new horizontal stretch value */ public void setFillHorizontal(boolean fillHorizontal) { boolean old = this.isFillHorizontal(); this.fillHorizontal = fillHorizontal; setDirty(true); firePropertyChange("fillHorizontal", old, isFillHorizontal()); }
@Test @Override public void testDefaults() { super.testDefaults(); AbstractLayoutPainter alp = (AbstractLayoutPainter) p; assertThat(alp.getHorizontalAlignment(), is(AbstractLayoutPainter.HorizontalAlignment.CENTER)); assertThat(alp.getInsets(), is(new Insets(0, 0, 0, 0))); assertThat(alp.getVerticalAlignment(), is(AbstractLayoutPainter.VerticalAlignment.CENTER)); assertThat(alp.isFillHorizontal(), is(false)); assertThat(alp.isFillVertical(), is(false)); } }
/** * A protected method used by subclasses to calculate the final position of the * content. This will position the content using the fillHorizontal, fillVertical * horizontalAlignment, and verticalAlignment properties. This method * is typically called by subclasses in their doPaint() methods. * * @param contentWidth The width of the content to be painted * @param contentHeight The height of the content to be painted * @param width the width of the area that the content will be positioned in * @param height the height of the area that the content will be positioned in * @return the rectangle for the content to be painted in */ protected Rectangle calculateLayout(final int contentWidth, final int contentHeight, final int width, final int height) { Rectangle rect = new Rectangle(); rect.width = contentWidth; rect.height = contentHeight; if (isFillHorizontal()) { rect.width = width - insets.left - insets.right; } if (isFillVertical()) { rect.height = height - insets.top - insets.bottom; } rect.x = calculateX(rect.width, width); rect.y = calculateY(rect.height, height); return rect; }
/** * Sets if the content should be stretched vertically to fill all available verticalAlignment * space (minus the top and bottom insets). * * @param verticalStretch new verticalAlignment stretch value */ public void setFillVertical(boolean verticalStretch) { boolean old = this.isFillVertical(); this.fillVertical = verticalStretch; setDirty(true); firePropertyChange("fillVertical", old, isFillVertical()); }
private int calculateY(final int imgHeight, final int height) { int y = 0; if(getVerticalAlignment() == VerticalAlignment.TOP) { y = 0; y+= insets.top; } if(getVerticalAlignment() == VerticalAlignment.CENTER) { y = (height-imgHeight)/2; y += insets.top; } if(getVerticalAlignment() == VerticalAlignment.BOTTOM) { y = height-imgHeight; y-= insets.bottom; } return y; }
private int calculateX(final int imgWidth, final int width) { int x = 0; if(getHorizontalAlignment() == HorizontalAlignment.LEFT) { x = 0; x+= insets.left; } if(getHorizontalAlignment() == HorizontalAlignment.CENTER) { x = (width-imgWidth)/2; x += insets.left; } if(getHorizontalAlignment() == HorizontalAlignment.RIGHT) { x = width-imgWidth; x-= insets.right; } return x; } }
assertThat(alp.getHorizontalAlignment(), is(AbstractLayoutPainter.HorizontalAlignment.CENTER)); assertThat(alp.getInsets(), is(new Insets(0, 0, 0, 0))); assertThat(alp.getVerticalAlignment(), is(AbstractLayoutPainter.VerticalAlignment.CENTER)); assertThat(alp.isFillHorizontal(), is(true)); assertThat(alp.isFillVertical(), is(true));
/** * A protected method used by subclasses to calculate the final position of the * content. This will position the content using the fillHorizontal, fillVertical * horizontalAlignment, and verticalAlignment properties. This method * is typically called by subclasses in their doPaint() methods. * * @param contentWidth The width of the content to be painted * @param contentHeight The height of the content to be painted * @param width the width of the area that the content will be positioned in * @param height the height of the area that the content will be positioned in * @return the rectangle for the content to be painted in */ protected final Rectangle calculateLayout(final int contentWidth, final int contentHeight, final int width, final int height) { Rectangle rect = new Rectangle(); rect.width = contentWidth; rect.height = contentHeight; if(isFillHorizontal()) { rect.width = width - insets.left - insets.right; } if(isFillVertical()) { rect.height = height - insets.top - insets.bottom; } rect.x = calculateX(rect.width, width); rect.y = calculateY(rect.height, height); return rect; }
/** * Sets if the content should be stretched horizontally to fill all available horizontalAlignment * space (minus the left and right insets). * * * @param fillHorizontal new horizonal stretch value */ public void setFillHorizontal(boolean fillHorizontal) { boolean old = this.isFillHorizontal(); this.fillHorizontal = fillHorizontal; setDirty(true); firePropertyChange("horizontalStretch",old,this.fillHorizontal); }
/** * Sets if the content should be stretched vertically to fill all available verticalAlignment * space (minus the top and bottom insets). * * @param verticalStretch new verticalAlignment stretch value */ public void setFillVertical(boolean verticalStretch) { boolean old = this.isFillVertical(); this.fillVertical = verticalStretch; setDirty(true); firePropertyChange("fillVertical", old, isFillVertical()); }
private int calculateY(final int imgHeight, final int height) { int y = 0; if(getVerticalAlignment() == VerticalAlignment.TOP) { y = 0; y+= insets.top; } if(getVerticalAlignment() == VerticalAlignment.CENTER) { y = (height-imgHeight)/2; y += insets.top; } if(getVerticalAlignment() == VerticalAlignment.BOTTOM) { y = height-imgHeight; y-= insets.bottom; } return y; }
private int calculateX(final int imgWidth, final int width) { int x = 0; if(getHorizontalAlignment() == HorizontalAlignment.LEFT) { x = 0; x+= insets.left; } if(getHorizontalAlignment() == HorizontalAlignment.CENTER) { x = (width-imgWidth)/2; x += insets.left; } if(getHorizontalAlignment() == HorizontalAlignment.RIGHT) { x = width-imgWidth; x-= insets.right; } return x; } }
assertThat(alp.getHorizontalAlignment(), is(AbstractLayoutPainter.HorizontalAlignment.CENTER)); assertThat(alp.getInsets(), is(new Insets(0, 0, 0, 0))); assertThat(alp.getVerticalAlignment(), is(AbstractLayoutPainter.VerticalAlignment.CENTER)); assertThat(alp.isFillHorizontal(), is(false)); assertThat(alp.isFillVertical(), is(false));
/** * A protected method used by subclasses to calculate the final position of the * content. This will position the content using the fillHorizontal, fillVertical * horizontalAlignment, and verticalAlignment properties. This method * is typically called by subclasses in their doPaint() methods. * * @param contentWidth The width of the content to be painted * @param contentHeight The height of the content to be painted * @param width the width of the area that the content will be positioned in * @param height the height of the area that the content will be positioned in * @return the rectangle for the content to be painted in */ protected final Rectangle calculateLayout(final int contentWidth, final int contentHeight, final int width, final int height) { Rectangle rect = new Rectangle(); rect.width = contentWidth; rect.height = contentHeight; if(isFillHorizontal()) { rect.width = width - insets.left - insets.right; } if(isFillVertical()) { rect.height = height - insets.top - insets.bottom; } rect.x = calculateX(rect.width, width); rect.y = calculateY(rect.height, height); return rect; }
/** * Sets a new verticalAlignment alignment. Used to position the content at the top, bottom, or center. * * @param vertical new verticalAlignment alignment */ public void setVerticalAlignment(VerticalAlignment vertical) { VerticalAlignment old = this.getVerticalAlignment(); this.verticalAlignment = vertical; setDirty(true); firePropertyChange("vertical",old,this.verticalAlignment); }
/** * Sets if the content should be stretched horizontally to fill all available horizontalAlignment * space (minus the left and right insets). * * @param fillHorizontal new horizontal stretch value */ public void setFillHorizontal(boolean fillHorizontal) { boolean old = this.isFillHorizontal(); this.fillHorizontal = fillHorizontal; setDirty(true); firePropertyChange("fillHorizontal", old, isFillHorizontal()); }
/** * Sets the current whitespace insets. * @param insets new insets */ public void setInsets(Insets insets) { Insets old = this.getInsets(); this.insets = insets; setDirty(true); firePropertyChange("insets",old,this.insets); }