org.jfree.ui.HorizontalAlignment Java Examples

The following examples show how to use org.jfree.ui.HorizontalAlignment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Title.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new title.
 *
 * @param position  the position of the title (<code>null</code> not
 *                  permitted).
 * @param horizontalAlignment  the horizontal alignment of the title (LEFT,
 *                             CENTER or RIGHT, <code>null</code> not
 *                             permitted).
 * @param verticalAlignment  the vertical alignment of the title (TOP,
 *                           MIDDLE or BOTTOM, <code>null</code> not
 *                           permitted).
 * @param padding  the amount of space to leave around the outside of the
 *                 title (<code>null</code> not permitted).
 */
protected Title(RectangleEdge position, 
        HorizontalAlignment horizontalAlignment, 
        VerticalAlignment verticalAlignment, RectangleInsets padding) {

    ParamChecks.nullNotPermitted(position, "position");
    ParamChecks.nullNotPermitted(horizontalAlignment, "horizontalAlignment");
    ParamChecks.nullNotPermitted(verticalAlignment, "verticalAlignment");
    ParamChecks.nullNotPermitted(padding, "padding");

    this.visible = true;
    this.position = position;
    this.horizontalAlignment = horizontalAlignment;
    this.verticalAlignment = verticalAlignment;
    setPadding(padding);
    this.listenerList = new EventListenerList();
    this.notify = true;
}
 
Example #2
Source File: ImageTitle.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new image title with the given image scaled to the given
 * width and height in the given location.
 *
 * @param image  the image ({@code null} not permitted).
 * @param height  the height used to draw the image.
 * @param width  the width used to draw the image.
 * @param position  the title position.
 * @param horizontalAlignment  the horizontal alignment.
 * @param verticalAlignment  the vertical alignment.
 * @param padding  the amount of space to leave around the outside of the
 *                 title.
 */
public ImageTitle(Image image, int height, int width,
                  RectangleEdge position,
                  HorizontalAlignment horizontalAlignment,
                  VerticalAlignment verticalAlignment,
                  RectangleInsets padding) {

    super(position, horizontalAlignment, verticalAlignment, padding);
    if (image == null) {
        throw new NullPointerException("Null 'image' argument.");
    }
    this.image = image;
    setHeight(height);
    setWidth(width);

}
 
Example #3
Source File: ImageTitle.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new image title with the given image scaled to the given
 * width and height in the given location.
 *
 * @param image  the image ({@code null} not permitted).
 * @param height  the height used to draw the image.
 * @param width  the width used to draw the image.
 * @param position  the title position.
 * @param horizontalAlignment  the horizontal alignment.
 * @param verticalAlignment  the vertical alignment.
 * @param padding  the amount of space to leave around the outside of the
 *                 title.
 */
public ImageTitle(Image image, int height, int width,
                  RectangleEdge position,
                  HorizontalAlignment horizontalAlignment,
                  VerticalAlignment verticalAlignment,
                  RectangleInsets padding) {

    super(position, horizontalAlignment, verticalAlignment, padding);
    if (image == null) {
        throw new NullPointerException("Null 'image' argument.");
    }
    this.image = image;
    setHeight(height);
    setWidth(width);

}
 
Example #4
Source File: ImageTitle.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new image title with the given image scaled to the given
 * width and height in the given location.
 *
 * @param image  the image ({@code null} not permitted).
 * @param height  the height used to draw the image.
 * @param width  the width used to draw the image.
 * @param position  the title position.
 * @param horizontalAlignment  the horizontal alignment.
 * @param verticalAlignment  the vertical alignment.
 * @param padding  the amount of space to leave around the outside of the
 *                 title.
 */
public ImageTitle(Image image, int height, int width,
                  RectangleEdge position,
                  HorizontalAlignment horizontalAlignment,
                  VerticalAlignment verticalAlignment,
                  RectangleInsets padding) {

    super(position, horizontalAlignment, verticalAlignment, padding);
    if (image == null) {
        throw new NullPointerException("Null 'image' argument.");
    }
    this.image = image;
    setHeight(height);
    setWidth(width);

}
 
Example #5
Source File: Title.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new title.
 *
 * @param position  the position of the title (<code>null</code> not
 *                  permitted).
 * @param horizontalAlignment  the horizontal alignment of the title (LEFT,
 *                             CENTER or RIGHT, <code>null</code> not
 *                             permitted).
 * @param verticalAlignment  the vertical alignment of the title (TOP,
 *                           MIDDLE or BOTTOM, <code>null</code> not
 *                           permitted).
 * @param padding  the amount of space to leave around the outside of the
 *                 title (<code>null</code> not permitted).
 */
protected Title(RectangleEdge position, 
        HorizontalAlignment horizontalAlignment, 
        VerticalAlignment verticalAlignment, RectangleInsets padding) {

    ParamChecks.nullNotPermitted(position, "position");
    ParamChecks.nullNotPermitted(horizontalAlignment, "horizontalAlignment");
    ParamChecks.nullNotPermitted(verticalAlignment, "verticalAlignment");
    ParamChecks.nullNotPermitted(padding, "padding");

    this.visible = true;
    this.position = position;
    this.horizontalAlignment = horizontalAlignment;
    this.verticalAlignment = verticalAlignment;
    setPadding(padding);
    this.listenerList = new EventListenerList();
    this.notify = true;
}
 
Example #6
Source File: FlowArrangementTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    FlowArrangement f1 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    FlowArrangement f2 = (FlowArrangement) TestUtilities.serialised(f1);
    assertEquals(f1, f2);
}
 
Example #7
Source File: TitleTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    // use the TextTitle class because it is a concrete subclass
    Title t1 = new TextTitle();
    Title t2 = new TextTitle();
    assertEquals(t1, t2);

    t1.setPosition(RectangleEdge.LEFT);
    assertFalse(t1.equals(t2));
    t2.setPosition(RectangleEdge.LEFT);
    assertTrue(t1.equals(t2));

    t1.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    assertFalse(t1.equals(t2));
    t2.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    assertTrue(t1.equals(t2));

    t1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    assertFalse(t1.equals(t2));
    t2.setVerticalAlignment(VerticalAlignment.BOTTOM);
    assertTrue(t1.equals(t2));

    t1.setVisible(false);
    assertFalse(t1.equals(t2));
    t2.setVisible(false);
    assertTrue(t1.equals(t2));
}
 
Example #8
Source File: ColumnArrangement.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Arranges the blocks without any constraints.  This puts all blocks
 * into a single column.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 *
 * @return The size after the arrangement.
 */
protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) {
    double y = 0.0;
    double height = 0.0;
    double maxWidth = 0.0;
    List blocks = container.getBlocks();
    int blockCount = blocks.size();
    if (blockCount > 0) {
        Size2D[] sizes = new Size2D[blocks.size()];
        for (int i = 0; i < blocks.size(); i++) {
            Block block = (Block) blocks.get(i);
            sizes[i] = block.arrange(g2, RectangleConstraint.NONE);
            height = height + sizes[i].getHeight();
            maxWidth = Math.max(sizes[i].width, maxWidth);
            block.setBounds(
                new Rectangle2D.Double(
                    0.0, y, sizes[i].width, sizes[i].height
                )
            );
            y = y + sizes[i].height + this.verticalGap;
        }
        if (blockCount > 1) {
            height = height + this.verticalGap * (blockCount - 1);
        }
        if (this.horizontalAlignment != HorizontalAlignment.LEFT) {
            for (int i = 0; i < blocks.size(); i++) {
                //Block b = (Block) blocks.get(i);
                if (this.horizontalAlignment
                        == HorizontalAlignment.CENTER) {
                    //TODO: shift block right by half
                }
                else if (this.horizontalAlignment
                        == HorizontalAlignment.RIGHT) {
                    //TODO: shift block over to right
                }
            }
        }
    }
    return new Size2D(maxWidth, height);
}
 
Example #9
Source File: JFreeChart.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a rectangle that is aligned to the frame.
 *
 * @param dimensions  the dimensions for the rectangle.
 * @param frame  the frame to align to.
 * @param hAlign  the horizontal alignment.
 * @param vAlign  the vertical alignment.
 *
 * @return A rectangle.
 */
private Rectangle2D createAlignedRectangle2D(Size2D dimensions,
        Rectangle2D frame, HorizontalAlignment hAlign,
        VerticalAlignment vAlign) {
    double x = Double.NaN;
    double y = Double.NaN;
    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();
    }
    else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);
    }
    else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();
    }
    else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);
    }
    else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;
    }

    return new Rectangle2D.Double(x, y, dimensions.width,
            dimensions.height);
}
 
Example #10
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void handleTitleSettings(
		TextTitle title, 
		TitleSettings titleSettings, 
		JRFont titleFont,
		Paint titleForegroundPaint,
		RectangleEdge titleEdge)
{
	JRBaseFont font = new JRBaseFont();
	FontUtil.copyNonNullOwnProperties(titleSettings.getFont(), font);
	FontUtil.copyNonNullOwnProperties(titleFont, font);
	font = new JRBaseFont(getChart(), font);
	title.setFont(getFontUtil().getAwtFont(font, getLocale()));
	
	HorizontalAlignment hAlign = titleSettings.getHorizontalAlignment();
	if (hAlign != null)
		title.setHorizontalAlignment(hAlign);
	
	VerticalAlignment vAlign = titleSettings.getVerticalAlignment();
	if (vAlign != null)
		title.setVerticalAlignment(vAlign);
	
	RectangleInsets padding = titleSettings.getPadding();
	if (padding != null)
		title.setPadding(padding);
	
	if (titleForegroundPaint != null)
		title.setPaint(titleForegroundPaint);

	Paint backPaint = titleSettings.getBackgroundPaint() != null ? titleSettings.getBackgroundPaint().getPaint() : null;
	if (backPaint != null)
		title.setBackgroundPaint(backPaint);
	if (titleEdge != null)
		title.setPosition(titleEdge);
}
 
Example #11
Source File: ColumnArrangement.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Arranges the blocks without any constraints.  This puts all blocks
 * into a single column.
 *
 * @param container  the container.
 * @param g2  the graphics device.
 *
 * @return The size after the arrangement.
 */
protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) {
    double y = 0.0;
    double height = 0.0;
    double maxWidth = 0.0;
    List blocks = container.getBlocks();
    int blockCount = blocks.size();
    if (blockCount > 0) {
        Size2D[] sizes = new Size2D[blocks.size()];
        for (int i = 0; i < blocks.size(); i++) {
            Block block = (Block) blocks.get(i);
            sizes[i] = block.arrange(g2, RectangleConstraint.NONE);
            height = height + sizes[i].getHeight();
            maxWidth = Math.max(sizes[i].width, maxWidth);
            block.setBounds(
                new Rectangle2D.Double(
                    0.0, y, sizes[i].width, sizes[i].height
                )
            );
            y = y + sizes[i].height + this.verticalGap;
        }
        if (blockCount > 1) {
            height = height + this.verticalGap * (blockCount - 1);
        }
        if (this.horizontalAlignment != HorizontalAlignment.LEFT) {
            for (int i = 0; i < blocks.size(); i++) {
                //Block b = (Block) blocks.get(i);
                if (this.horizontalAlignment
                        == HorizontalAlignment.CENTER) {
                    //TODO: shift block right by half
                }
                else if (this.horizontalAlignment
                        == HorizontalAlignment.RIGHT) {
                    //TODO: shift block over to right
                }
            }
        }
    }
    return new Size2D(maxWidth, height);
}
 
Example #12
Source File: FlowArrangementTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    FlowArrangement f1 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    FlowArrangement f2 = (FlowArrangement) TestUtilities.serialised(f1);
    assertEquals(f1, f2);
}
 
Example #13
Source File: FlowArrangementTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    FlowArrangement f1 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    FlowArrangement f2 = (FlowArrangement) TestUtilities.serialised(f1);
    assertEquals(f1, f2);
}
 
Example #14
Source File: Title.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the horizontal alignment for the title and sends a
 * {@link TitleChangeEvent} to all registered listeners.
 *
 * @param alignment  the horizontal alignment (<code>null</code> not
 *                   permitted).
 */
public void setHorizontalAlignment(HorizontalAlignment alignment) {
    ParamChecks.nullNotPermitted(alignment, "alignment");
    if (this.horizontalAlignment != alignment) {
        this.horizontalAlignment = alignment;
        notifyListeners(new TitleChangeEvent(this));
    }
}
 
Example #15
Source File: ColumnArrangementTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    ColumnArrangement c1 = new ColumnArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    ColumnArrangement c2 = new ColumnArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(c1.equals(c2));
    assertTrue(c2.equals(c1));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(c1.equals(c2));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertTrue(c1.equals(c2));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertTrue(c1.equals(c2));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertTrue(c1.equals(c2));
}
 
Example #16
Source File: FlowArrangementTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    FlowArrangement f1 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    FlowArrangement f2 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(f1.equals(f2));
    assertTrue(f2.equals(f1));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(f1.equals(f2));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertTrue(f1.equals(f2));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertTrue(f1.equals(f2));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertTrue(f1.equals(f2));

}
 
Example #17
Source File: ImageTitle.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new image title.
 *
 * @param image  the image ({@code null} not permitted).
 * @param position  the title position.
 * @param horizontalAlignment  the horizontal alignment.
 * @param verticalAlignment  the vertical alignment.
 */
public ImageTitle(Image image, RectangleEdge position,
                  HorizontalAlignment horizontalAlignment,
                  VerticalAlignment verticalAlignment) {

    this(image, image.getHeight(null), image.getWidth(null),
            position, horizontalAlignment, verticalAlignment,
            Title.DEFAULT_PADDING);
}
 
Example #18
Source File: ColumnArrangementTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    FlowArrangement f1 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    FlowArrangement f2 = (FlowArrangement) TestUtilities.serialised(f1);
    assertEquals(f1, f2);
}
 
Example #19
Source File: FlowArrangementTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    FlowArrangement f1 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    FlowArrangement f2 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(f1.equals(f2));
    assertTrue(f2.equals(f1));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(f1.equals(f2));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertTrue(f1.equals(f2));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertTrue(f1.equals(f2));

    f1 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertFalse(f1.equals(f2));
    f2 = new FlowArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertTrue(f1.equals(f2));

}
 
Example #20
Source File: TitleTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    // use the TextTitle class because it is a concrete subclass
    Title t1 = new TextTitle();
    Title t2 = new TextTitle();
    assertEquals(t1, t2);

    t1.setPosition(RectangleEdge.LEFT);
    assertFalse(t1.equals(t2));
    t2.setPosition(RectangleEdge.LEFT);
    assertTrue(t1.equals(t2));

    t1.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    assertFalse(t1.equals(t2));
    t2.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    assertTrue(t1.equals(t2));

    t1.setVerticalAlignment(VerticalAlignment.BOTTOM);
    assertFalse(t1.equals(t2));
    t2.setVerticalAlignment(VerticalAlignment.BOTTOM);
    assertTrue(t1.equals(t2));

    t1.setVisible(false);
    assertFalse(t1.equals(t2));
    t2.setVisible(false);
    assertTrue(t1.equals(t2));
}
 
Example #21
Source File: ColumnArrangementTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    ColumnArrangement c1 = new ColumnArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    ColumnArrangement c2 = new ColumnArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(c1.equals(c2));
    assertTrue(c2.equals(c1));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.TOP, 1.0, 2.0);
    assertTrue(c1.equals(c2));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.0, 2.0);
    assertTrue(c1.equals(c2));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.0);
    assertTrue(c1.equals(c2));

    c1 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertFalse(c1.equals(c2));
    c2 = new ColumnArrangement(HorizontalAlignment.RIGHT,
            VerticalAlignment.BOTTOM, 1.1, 2.2);
    assertTrue(c1.equals(c2));
}
 
Example #22
Source File: ColumnArrangementTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    FlowArrangement f1 = new FlowArrangement(HorizontalAlignment.LEFT,
            VerticalAlignment.TOP, 1.0, 2.0);
    FlowArrangement f2 = (FlowArrangement) TestUtilities.serialised(f1);
    assertEquals(f1, f2);
}
 
Example #23
Source File: ImageTitle.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new image title.
 *
 * @param image  the image ({@code null} not permitted).
 * @param position  the title position.
 * @param horizontalAlignment  the horizontal alignment.
 * @param verticalAlignment  the vertical alignment.
 */
public ImageTitle(Image image, RectangleEdge position,
                  HorizontalAlignment horizontalAlignment,
                  VerticalAlignment verticalAlignment) {

    this(image, image.getHeight(null), image.getWidth(null),
            position, horizontalAlignment, verticalAlignment,
            Title.DEFAULT_PADDING);
}
 
Example #24
Source File: TextTitle.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a the title horizontally within the specified area.  This method
 * will be called from the {@link #draw(Graphics2D, Rectangle2D) draw}
 * method.
 *
 * @param g2  the graphics device.
 * @param area  the area for the title.
 */
protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
    Rectangle2D titleArea = (Rectangle2D) area.clone();
    g2.setFont(this.font);
    g2.setPaint(this.paint);
    TextBlockAnchor anchor = null;
    float x = 0.0f;
    HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
    if (horizontalAlignment == HorizontalAlignment.LEFT) {
        x = (float) titleArea.getX();
        anchor = TextBlockAnchor.TOP_LEFT;
    }
    else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
        x = (float) titleArea.getMaxX();
        anchor = TextBlockAnchor.TOP_RIGHT;
    }
    else if (horizontalAlignment == HorizontalAlignment.CENTER) {
        x = (float) titleArea.getCenterX();
        anchor = TextBlockAnchor.TOP_CENTER;
    }
    float y = 0.0f;
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.TOP) {
        y = (float) titleArea.getY();
    }
    else if (position == RectangleEdge.BOTTOM) {
        y = (float) titleArea.getMaxY();
        if (horizontalAlignment == HorizontalAlignment.LEFT) {
            anchor = TextBlockAnchor.BOTTOM_LEFT;
        }
        else if (horizontalAlignment == HorizontalAlignment.CENTER) {
            anchor = TextBlockAnchor.BOTTOM_CENTER;
        }
        else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
            anchor = TextBlockAnchor.BOTTOM_RIGHT;
        }
    }
    this.content.draw(g2, x, y, anchor);
}
 
Example #25
Source File: Title.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the horizontal alignment for the title and sends a
 * {@link TitleChangeEvent} to all registered listeners.
 *
 * @param alignment  the horizontal alignment (<code>null</code> not
 *                   permitted).
 */
public void setHorizontalAlignment(HorizontalAlignment alignment) {
    ParamChecks.nullNotPermitted(alignment, "alignment");
    if (this.horizontalAlignment != alignment) {
        this.horizontalAlignment = alignment;
        notifyListeners(new TitleChangeEvent(this));
    }
}
 
Example #26
Source File: TextBlock.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the text block, aligning it with the specified anchor point and 
 * rotating it about the specified rotation point.
 * 
 * @param g2  the graphics device.
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the point on the text block that is aligned to the 
 *                anchor point.
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the x-coordinate for the rotation point.
 * @param angle  the rotation (in radians).
 */
public void draw(final Graphics2D g2,
                 final float anchorX, final float anchorY, 
                 final TextBlockAnchor anchor,
                 final float rotateX, final float rotateY, 
                 final double angle) {

    final Size2D d = calculateDimensions(g2);
    final float[] offsets = calculateOffsets(anchor, d.getWidth(), 
            d.getHeight());
    final Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
        TextLine line = (TextLine) iterator.next();
        Size2D dimension = line.calculateDimensions(g2);
        float lineOffset = 0.0f;
        if (this.lineAlignment == HorizontalAlignment.CENTER) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth()) 
                / 2.0f;   
        }
        else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth());   
        }
        line.draw(
            g2, anchorX + offsets[0] + lineOffset, anchorY + offsets[1] + yCursor,
            TextAnchor.TOP_LEFT, rotateX, rotateY, angle
        );
        yCursor = yCursor + (float) dimension.getHeight();
    }
    
}
 
Example #27
Source File: JFreeChartPlotEngine.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates {@link LegendTitle}s for all dimensions from the PlotConfiguration of this Plotter2D.
 * Expects that all {@link ValueSource} s in the provided PlotConfiguration use the same
 * {@link DimensionConfig} s.
 */
private List<LegendTitle> createLegendTitles() {
	List<LegendTitle> legendTitles = new LinkedList<LegendTitle>();
	LegendConfiguration legendConfiguration = plotInstance.getCurrentPlotConfigurationClone().getLegendConfiguration();

	LegendTitle legendTitle = new SmartLegendTitle(this,
			new FlowArrangement(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 30, 2),
			new ColumnArrangement(HorizontalAlignment.LEFT, VerticalAlignment.CENTER, 0, 2));
	legendTitle.setItemPaint(legendConfiguration.getLegendFontColor());

	RectangleEdge position = legendConfiguration.getLegendPosition().getPosition();
	if (position == null) {
		return legendTitles;
	}
	legendTitle.setPosition(position);

	if (legendConfiguration.isShowLegendFrame()) {
		legendTitle.setFrame(new BlockBorder(legendConfiguration.getLegendFrameColor()));
	}
	ColoredBlockContainer wrapper = new ColoredBlockContainer(legendConfiguration.getLegendBackgroundColor());
	wrapper.add(legendTitle.getItemContainer());
	wrapper.setPadding(3, 3, 3, 3);
	legendTitle.setWrapper(wrapper);

	legendTitles.add(legendTitle);
	return legendTitles;
}
 
Example #28
Source File: TextTitle.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new title.
 *
 * @param text  the text for the title (<code>null</code> not permitted).
 * @param font  the title font (<code>null</code> not permitted).
 * @param paint  the title paint (<code>null</code> not permitted).
 * @param position  the title position (<code>null</code> not permitted).
 * @param horizontalAlignment  the horizontal alignment (<code>null</code>
 *                             not permitted).
 * @param verticalAlignment  the vertical alignment (<code>null</code> not
 *                           permitted).
 * @param padding  the space to leave around the outside of the title.
 */
public TextTitle(String text, Font font, Paint paint,
                 RectangleEdge position,
                 HorizontalAlignment horizontalAlignment,
                 VerticalAlignment verticalAlignment,
                 RectangleInsets padding) {

    super(position, horizontalAlignment, verticalAlignment, padding);

    if (text == null) {
        throw new NullPointerException("Null 'text' argument.");
    }
    if (font == null) {
        throw new NullPointerException("Null 'font' argument.");
    }
    if (paint == null) {
        throw new NullPointerException("Null 'paint' argument.");
    }
    this.text = text;
    this.font = font;
    this.paint = paint;
    // the textAlignment and the horizontalAlignment are separate things,
    // but it makes sense for the default textAlignment to match the
    // title's horizontal alignment...
    this.textAlignment = horizontalAlignment;
    this.backgroundPaint = null;
    this.content = null;
    this.toolTipText = null;
    this.urlText = null;

}
 
Example #29
Source File: JFreeChart.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a rectangle that is aligned to the frame.
 *
 * @param dimensions  the dimensions for the rectangle.
 * @param frame  the frame to align to.
 * @param hAlign  the horizontal alignment.
 * @param vAlign  the vertical alignment.
 *
 * @return A rectangle.
 */
private Rectangle2D createAlignedRectangle2D(Size2D dimensions,
        Rectangle2D frame, HorizontalAlignment hAlign,
        VerticalAlignment vAlign) {
    double x = Double.NaN;
    double y = Double.NaN;
    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();
    }
    else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);
    }
    else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();
    }
    else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);
    }
    else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;
    }

    return new Rectangle2D.Double(x, y, dimensions.width,
            dimensions.height);
}
 
Example #30
Source File: ColumnArrangement.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance.
 *
 * @param hAlign  the horizontal alignment (currently ignored).
 * @param vAlign  the vertical alignment (currently ignored).
 * @param hGap  the horizontal gap.
 * @param vGap  the vertical gap.
 */
public ColumnArrangement(HorizontalAlignment hAlign,
                         VerticalAlignment vAlign,
                         double hGap, double vGap) {
    this.horizontalAlignment = hAlign;
    this.verticalAlignment = vAlign;
    this.horizontalGap = hGap;
    this.verticalGap = vGap;
}