org.jfree.text.TextBlockAnchor Java Examples

The following examples show how to use org.jfree.text.TextBlockAnchor. 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: TextBlockPanel.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Paints the panel.
 *
 * @param g  the graphics device.
 */
public void paintComponent(final Graphics g) {

    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    final Dimension size = getSize();
    final Insets insets = getInsets();
    final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
                                  size.getWidth() - insets.left - insets.right,
                                  size.getHeight() - insets.top - insets.bottom);

    final double x = available.getX();
    final double y = available.getY();
    final float width = (float) available.getWidth();
    final TextBlock block = TextUtilities.createTextBlock(
        this.text, this.font, Color.black, width, new G2TextMeasurer(g2)
    );
    g2.setPaint(Color.black);
    block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0);

}
 
Example #2
Source File: CategoryLabelPosition.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new position record.  The item label anchor is a point
 * relative to the data item (dot, bar or other visual item) on a chart.
 * The item label is aligned by aligning the text anchor with the item
 * label anchor.
 *
 * @param categoryAnchor  the category anchor (<code>null</code> not
 *                        permitted).
 * @param labelAnchor  the label anchor (<code>null</code> not permitted).
 * @param rotationAnchor  the rotation anchor (<code>null</code> not
 *                        permitted).
 * @param angle  the rotation angle (<code>null</code> not permitted).
 * @param widthType  the width type (<code>null</code> not permitted).
 * @param widthRatio  the maximum label width as a percentage (of the
 *                    category space or the range space).
 */
public CategoryLabelPosition(RectangleAnchor categoryAnchor,
        TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, 
        double angle, CategoryLabelWidthType widthType, float widthRatio) {

    ParamChecks.nullNotPermitted(categoryAnchor, "categoryAnchor");
    ParamChecks.nullNotPermitted(labelAnchor, "labelAnchor");
    ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor");
    ParamChecks.nullNotPermitted(widthType, "widthType");

    this.categoryAnchor = categoryAnchor;
    this.labelAnchor = labelAnchor;
    this.rotationAnchor = rotationAnchor;
    this.angle = angle;
    this.widthType = widthType;
    this.widthRatio = widthRatio;

}
 
Example #3
Source File: CategoryLabelPositionsTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    CategoryLabelPositions p1 = new CategoryLabelPositions(
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER));
    CategoryLabelPositions p2 = new CategoryLabelPositions(
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER));
    assertTrue(p1.equals(p2));
    int h1 = p1.hashCode();
    int h2 = p2.hashCode();
    assertEquals(h1, h2);
}
 
Example #4
Source File: Plot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a message to state that there is no data to plot.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
    Shape savedClip = g2.getClip();
    g2.clip(area);
    String message = this.noDataMessage;
    if (message != null) {
        g2.setFont(this.noDataMessageFont);
        g2.setPaint(this.noDataMessagePaint);
        TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont,
                this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
                new G2TextMeasurer(g2));
        block.draw(g2, (float) area.getCenterX(),
                (float) area.getCenterY(), TextBlockAnchor.CENTER);
    }
    g2.setClip(savedClip);
}
 
Example #5
Source File: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TextBlockAnchor asTextBlockAnchor() {
  switch ( this ) {
    case RIGHT:
      return TextBlockAnchor.CENTER_RIGHT;
    case TOP_RIGHT:
      return TextBlockAnchor.TOP_RIGHT;
    case TOP:
      return TextBlockAnchor.TOP_CENTER;
    case TOP_LEFT:
      return TextBlockAnchor.TOP_LEFT;
    case LEFT:
      return TextBlockAnchor.CENTER_LEFT;
    case BOTTOM_LEFT:
      return TextBlockAnchor.BOTTOM_LEFT;
    case BOTTOM:
      return TextBlockAnchor.BOTTOM_CENTER;
    case BOTTOM_RIGHT:
      return TextBlockAnchor.BOTTOM_RIGHT;
    default:
      return null;
  }
}
 
Example #6
Source File: CategoryTickTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    Comparable c1 = "C1";
    TextBlock tb1 = new TextBlock();
    tb1.addLine(new TextLine("Block 1"));
    tb1.addLine(new TextLine("Block 2"));
    TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
    TextAnchor ta1 = TextAnchor.CENTER;

    CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
 
Example #7
Source File: Plot.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a message to state that there is no data to plot.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
    Shape savedClip = g2.getClip();
    g2.clip(area);
    String message = this.noDataMessage;
    if (message != null) {
        g2.setFont(this.noDataMessageFont);
        g2.setPaint(this.noDataMessagePaint);
        TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont, 
                this.noDataMessagePaint, 0.9f * (float) area.getWidth(), 
                new G2TextMeasurer(g2));
        block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(), 
                TextBlockAnchor.CENTER);
    }
    g2.setClip(savedClip);
}
 
Example #8
Source File: CategoryLabelPositions.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance where the category labels angled downwards by the
 * specified amount.
 *
 * @param angle  the rotation angle (should be &lt; Math.PI / 2.0).
 *
 * @return A category label position specification.
 */
public static CategoryLabelPositions createDownRotationLabelPositions(
        double angle) {
    return new CategoryLabelPositions(
        new CategoryLabelPosition(
            RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_RIGHT,
            TextAnchor.BOTTOM_RIGHT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // TOP
        new CategoryLabelPosition(
            RectangleAnchor.TOP, TextBlockAnchor.TOP_LEFT,
            TextAnchor.TOP_LEFT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM
        new CategoryLabelPosition(
            RectangleAnchor.RIGHT, TextBlockAnchor.TOP_RIGHT,
            TextAnchor.TOP_RIGHT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // LEFT
        new CategoryLabelPosition(
            RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_LEFT,
            TextAnchor.BOTTOM_LEFT, angle,
            CategoryLabelWidthType.RANGE, 0.50f) // RIGHT
    );
}
 
Example #9
Source File: CategoryLabelPositions.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance where the category labels angled upwards by the
 * specified amount.
 *
 * @param angle  the rotation angle (should be &lt; Math.PI / 2.0).
 *
 * @return A category label position specification.
 */
public static CategoryLabelPositions createUpRotationLabelPositions(
        double angle) {
    return new CategoryLabelPositions(
        new CategoryLabelPosition(
            RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_LEFT,
            TextAnchor.BOTTOM_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // TOP
        new CategoryLabelPosition(
            RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
            TextAnchor.TOP_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM
        new CategoryLabelPosition(
            RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_RIGHT,
            TextAnchor.BOTTOM_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // LEFT
        new CategoryLabelPosition(
            RectangleAnchor.LEFT, TextBlockAnchor.TOP_LEFT,
            TextAnchor.TOP_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f) // RIGHT
    );
}
 
Example #10
Source File: CategoryLabelPositions.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance where the category labels angled upwards by the 
 * specified amount.
 * 
 * @param angle  the rotation angle (should be < Math.PI / 2.0).
 * 
 * @return A category label position specification.
 */
public static CategoryLabelPositions createUpRotationLabelPositions(
        double angle) {
    return new CategoryLabelPositions(
        new CategoryLabelPosition(
            RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_LEFT, 
            TextAnchor.BOTTOM_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f
        ), // TOP
        new CategoryLabelPosition(
            RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, 
            TextAnchor.TOP_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f
        ), // BOTTOM
        new CategoryLabelPosition(
            RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_RIGHT, 
            TextAnchor.BOTTOM_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f
        ), // LEFT
        new CategoryLabelPosition(
            RectangleAnchor.LEFT, TextBlockAnchor.TOP_LEFT, 
            TextAnchor.TOP_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f
        ) // RIGHT
    );
}
 
Example #11
Source File: CategoryLabelPosition.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new position record.  The item label anchor is a point
 * relative to the data item (dot, bar or other visual item) on a chart.
 * The item label is aligned by aligning the text anchor with the item
 * label anchor.
 *
 * @param categoryAnchor  the category anchor (<code>null</code> not
 *                        permitted).
 * @param labelAnchor  the label anchor (<code>null</code> not permitted).
 * @param rotationAnchor  the rotation anchor (<code>null</code> not
 *                        permitted).
 * @param angle  the rotation angle (<code>null</code> not permitted).
 * @param widthType  the width type (<code>null</code> not permitted).
 * @param widthRatio  the maximum label width as a percentage (of the
 *                    category space or the range space).
 */
public CategoryLabelPosition(RectangleAnchor categoryAnchor,
        TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, 
        double angle, CategoryLabelWidthType widthType, float widthRatio) {

    ParamChecks.nullNotPermitted(categoryAnchor, "categoryAnchor");
    ParamChecks.nullNotPermitted(labelAnchor, "labelAnchor");
    ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor");
    ParamChecks.nullNotPermitted(widthType, "widthType");

    this.categoryAnchor = categoryAnchor;
    this.labelAnchor = labelAnchor;
    this.rotationAnchor = rotationAnchor;
    this.angle = angle;
    this.widthType = widthType;
    this.widthRatio = widthRatio;

}
 
Example #12
Source File: CategoryLabelPositions.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new instance where the category labels angled upwards by the
 * specified amount.
 *
 * @param angle  the rotation angle (should be &lt; Math.PI / 2.0).
 *
 * @return A category label position specification.
 */
public static CategoryLabelPositions createUpRotationLabelPositions(
        double angle) {
    return new CategoryLabelPositions(
        new CategoryLabelPosition(
            RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_LEFT,
            TextAnchor.BOTTOM_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // TOP
        new CategoryLabelPosition(
            RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
            TextAnchor.TOP_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM
        new CategoryLabelPosition(
            RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_RIGHT,
            TextAnchor.BOTTOM_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // LEFT
        new CategoryLabelPosition(
            RectangleAnchor.LEFT, TextBlockAnchor.TOP_LEFT,
            TextAnchor.TOP_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f) // RIGHT
    );
}
 
Example #13
Source File: CategoryLabelPositions.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance where the category labels angled downwards by the
 * specified amount.
 *
 * @param angle  the rotation angle (should be &lt; Math.PI / 2.0).
 *
 * @return A category label position specification.
 */
public static CategoryLabelPositions createDownRotationLabelPositions(
        double angle) {
    return new CategoryLabelPositions(
        new CategoryLabelPosition(
            RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_RIGHT,
            TextAnchor.BOTTOM_RIGHT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // TOP
        new CategoryLabelPosition(
            RectangleAnchor.TOP, TextBlockAnchor.TOP_LEFT,
            TextAnchor.TOP_LEFT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM
        new CategoryLabelPosition(
            RectangleAnchor.RIGHT, TextBlockAnchor.TOP_RIGHT,
            TextAnchor.TOP_RIGHT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // LEFT
        new CategoryLabelPosition(
            RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_LEFT,
            TextAnchor.BOTTOM_LEFT, angle,
            CategoryLabelWidthType.RANGE, 0.50f) // RIGHT
    );
}
 
Example #14
Source File: CategoryTickTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    Comparable c1 = "C1";
    TextBlock tb1 = new TextBlock();
    tb1.addLine(new TextLine("Block 1"));
    tb1.addLine(new TextLine("Block 2"));
    TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
    TextAnchor ta1 = TextAnchor.CENTER;

    CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
    assertTrue(t1.equals(t2));
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
 
Example #15
Source File: CategoryLabelPositionsTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    CategoryLabelPositions p1 = new CategoryLabelPositions(
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER));
    CategoryLabelPositions p2 = new CategoryLabelPositions(
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER));
    assertTrue(p1.equals(p2));
    int h1 = p1.hashCode();
    int h2 = p2.hashCode();
    assertEquals(h1, h2);
}
 
Example #16
Source File: CategoryLabelPosition.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new position record.  The item label anchor is a point
 * relative to the data item (dot, bar or other visual item) on a chart.
 * The item label is aligned by aligning the text anchor with the item
 * label anchor.
 *
 * @param categoryAnchor  the category anchor (<code>null</code> not
 *                        permitted).
 * @param labelAnchor  the label anchor (<code>null</code> not permitted).
 * @param rotationAnchor  the rotation anchor (<code>null</code> not
 *                        permitted).
 * @param angle  the rotation angle (<code>null</code> not permitted).
 * @param widthType  the width type (<code>null</code> not permitted).
 * @param widthRatio  the maximum label width as a percentage (of the
 *                    category space or the range space).
 */
public CategoryLabelPosition(RectangleAnchor categoryAnchor,
        TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, 
        double angle, CategoryLabelWidthType widthType, float widthRatio) {

    ParamChecks.nullNotPermitted(categoryAnchor, "categoryAnchor");
    ParamChecks.nullNotPermitted(labelAnchor, "labelAnchor");
    ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor");
    ParamChecks.nullNotPermitted(widthType, "widthType");

    this.categoryAnchor = categoryAnchor;
    this.labelAnchor = labelAnchor;
    this.rotationAnchor = rotationAnchor;
    this.angle = angle;
    this.widthType = widthType;
    this.widthRatio = widthRatio;

}
 
Example #17
Source File: Plot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a message to state that there is no data to plot.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
    Shape savedClip = g2.getClip();
    g2.clip(area);
    String message = this.noDataMessage;
    if (message != null) {
        g2.setFont(this.noDataMessageFont);
        g2.setPaint(this.noDataMessagePaint);
        TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont,
                this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
                new G2TextMeasurer(g2));
        block.draw(g2, (float) area.getCenterX(),
                (float) area.getCenterY(), TextBlockAnchor.CENTER);
    }
    g2.setClip(savedClip);
}
 
Example #18
Source File: CategoryLabelPositions.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new instance where the category labels angled upwards by the
 * specified amount.
 *
 * @param angle  the rotation angle (should be &lt; Math.PI / 2.0).
 *
 * @return A category label position specification.
 */
public static CategoryLabelPositions createUpRotationLabelPositions(
        double angle) {
    return new CategoryLabelPositions(
        new CategoryLabelPosition(
            RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_LEFT,
            TextAnchor.BOTTOM_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // TOP
        new CategoryLabelPosition(
            RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
            TextAnchor.TOP_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM
        new CategoryLabelPosition(
            RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_RIGHT,
            TextAnchor.BOTTOM_RIGHT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f), // LEFT
        new CategoryLabelPosition(
            RectangleAnchor.LEFT, TextBlockAnchor.TOP_LEFT,
            TextAnchor.TOP_LEFT, -angle,
            CategoryLabelWidthType.RANGE, 0.50f) // RIGHT
    );
}
 
Example #19
Source File: Plot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a message to state that there is no data to plot.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
    Shape savedClip = g2.getClip();
    g2.clip(area);
    String message = this.noDataMessage;
    if (message != null) {
        g2.setFont(this.noDataMessageFont);
        g2.setPaint(this.noDataMessagePaint);
        TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont,
                this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
                new G2TextMeasurer(g2));
        block.draw(g2, (float) area.getCenterX(),
                (float) area.getCenterY(), TextBlockAnchor.CENTER);
    }
    g2.setClip(savedClip);
}
 
Example #20
Source File: CategoryLabelPositionsTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    CategoryLabelPositions p1 = new CategoryLabelPositions(
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER));
    CategoryLabelPositions p2 = new CategoryLabelPositions(
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER),
            new CategoryLabelPosition(RA_TOP, TextBlockAnchor.CENTER));
    assertTrue(p1.equals(p2));
    int h1 = p1.hashCode();
    int h2 = p2.hashCode();
    assertEquals(h1, h2);
}
 
Example #21
Source File: CategoryLabelPosition.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new position record.  The item label anchor is a point
 * relative to the data item (dot, bar or other visual item) on a chart.
 * The item label is aligned by aligning the text anchor with the item
 * label anchor.
 *
 * @param categoryAnchor  the category anchor (<code>null</code> not
 *                        permitted).
 * @param labelAnchor  the label anchor (<code>null</code> not permitted).
 * @param rotationAnchor  the rotation anchor (<code>null</code> not
 *                        permitted).
 * @param angle  the rotation angle (<code>null</code> not permitted).
 * @param widthType  the width type (<code>null</code> not permitted).
 * @param widthRatio  the maximum label width as a percentage (of the
 *                    category space or the range space).
 */
public CategoryLabelPosition(RectangleAnchor categoryAnchor,
        TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, 
        double angle, CategoryLabelWidthType widthType, float widthRatio) {

    ParamChecks.nullNotPermitted(categoryAnchor, "categoryAnchor");
    ParamChecks.nullNotPermitted(labelAnchor, "labelAnchor");
    ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor");
    ParamChecks.nullNotPermitted(widthType, "widthType");

    this.categoryAnchor = categoryAnchor;
    this.labelAnchor = labelAnchor;
    this.rotationAnchor = rotationAnchor;
    this.angle = angle;
    this.widthType = widthType;
    this.widthRatio = widthRatio;

}
 
Example #22
Source File: CategoryLabelPositions.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance where the category labels angled downwards by the
 * specified amount.
 *
 * @param angle  the rotation angle (should be &lt; Math.PI / 2.0).
 *
 * @return A category label position specification.
 */
public static CategoryLabelPositions createDownRotationLabelPositions(
        double angle) {
    return new CategoryLabelPositions(
        new CategoryLabelPosition(
            RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_RIGHT,
            TextAnchor.BOTTOM_RIGHT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // TOP
        new CategoryLabelPosition(
            RectangleAnchor.TOP, TextBlockAnchor.TOP_LEFT,
            TextAnchor.TOP_LEFT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // BOTTOM
        new CategoryLabelPosition(
            RectangleAnchor.RIGHT, TextBlockAnchor.TOP_RIGHT,
            TextAnchor.TOP_RIGHT, angle,
            CategoryLabelWidthType.RANGE, 0.50f), // LEFT
        new CategoryLabelPosition(
            RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_LEFT,
            TextAnchor.BOTTOM_LEFT, angle,
            CategoryLabelWidthType.RANGE, 0.50f) // RIGHT
    );
}
 
Example #23
Source File: CategoryLabelPosition.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new position record.  The item label anchor is a point
 * relative to the data item (dot, bar or other visual item) on a chart.
 * The item label is aligned by aligning the text anchor with the item
 * label anchor.
 *
 * @param categoryAnchor  the category anchor (<code>null</code> not
 *                        permitted).
 * @param labelAnchor  the label anchor (<code>null</code> not permitted).
 * @param rotationAnchor  the rotation anchor (<code>null</code> not
 *                        permitted).
 * @param angle  the rotation angle (<code>null</code> not permitted).
 * @param widthType  the width type (<code>null</code> not permitted).
 * @param widthRatio  the maximum label width as a percentage (of the
 *                    category space or the range space).
 */
public CategoryLabelPosition(RectangleAnchor categoryAnchor,
        TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, 
        double angle, CategoryLabelWidthType widthType, float widthRatio) {

    ParamChecks.nullNotPermitted(categoryAnchor, "categoryAnchor");
    ParamChecks.nullNotPermitted(labelAnchor, "labelAnchor");
    ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor");
    ParamChecks.nullNotPermitted(widthType, "widthType");

    this.categoryAnchor = categoryAnchor;
    this.labelAnchor = labelAnchor;
    this.rotationAnchor = rotationAnchor;
    this.angle = angle;
    this.widthType = widthType;
    this.widthRatio = widthRatio;

}
 
Example #24
Source File: CategoryTick.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new tick.
 *
 * @param category  the category.
 * @param label  the label.
 * @param labelAnchor  the label anchor.
 * @param rotationAnchor  the rotation anchor.
 * @param angle  the rotation angle (in radians).
 */
public CategoryTick(Comparable category,
                    TextBlock label,
                    TextBlockAnchor labelAnchor,
                    TextAnchor rotationAnchor,
                    double angle) {

    super("", TextAnchor.CENTER, rotationAnchor, angle);
    this.category = category;
    this.label = label;
    this.labelAnchor = labelAnchor;

}
 
Example #25
Source File: TextTitle.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a the title vertically 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 drawVertical(Graphics2D g2, Rectangle2D area) {
    Rectangle2D titleArea = (Rectangle2D) area.clone();
    g2.setFont(this.font);
    g2.setPaint(this.paint);
    TextBlockAnchor anchor = null;
    float y = 0.0f;
    VerticalAlignment verticalAlignment = getVerticalAlignment();
    if (verticalAlignment == VerticalAlignment.TOP) {
        y = (float) titleArea.getY();
        anchor = TextBlockAnchor.TOP_RIGHT;
    }
    else if (verticalAlignment == VerticalAlignment.BOTTOM) {
        y = (float) titleArea.getMaxY();
        anchor = TextBlockAnchor.TOP_LEFT;
    }
    else if (verticalAlignment == VerticalAlignment.CENTER) {
        y = (float) titleArea.getCenterY();
        anchor = TextBlockAnchor.TOP_CENTER;
    }
    float x = 0.0f;
    RectangleEdge position = getPosition();
    if (position == RectangleEdge.LEFT) {
        x = (float) titleArea.getX();
    }
    else if (position == RectangleEdge.RIGHT) {
        x = (float) titleArea.getMaxX();
        if (verticalAlignment == VerticalAlignment.TOP) {
            anchor = TextBlockAnchor.BOTTOM_RIGHT;
        }
        else if (verticalAlignment == VerticalAlignment.CENTER) {
            anchor = TextBlockAnchor.BOTTOM_CENTER;
        }
        else if (verticalAlignment == VerticalAlignment.BOTTOM) {
            anchor = TextBlockAnchor.BOTTOM_LEFT;
        }
    }
    this.content.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
}
 
Example #26
Source File: CategoryTick.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new tick.
 *
 * @param category  the category.
 * @param label  the label.
 * @param labelAnchor  the label anchor.
 * @param rotationAnchor  the rotation anchor.
 * @param angle  the rotation angle (in radians).
 */
public CategoryTick(Comparable category,
                    TextBlock label,
                    TextBlockAnchor labelAnchor,
                    TextAnchor rotationAnchor,
                    double angle) {

    super("", TextAnchor.CENTER, rotationAnchor, angle);
    this.category = category;
    this.label = label;
    this.labelAnchor = labelAnchor;

}
 
Example #27
Source File: CategoryLabelPosition.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new position record with default settings.
 */
public CategoryLabelPosition() {
    this(
        RectangleAnchor.CENTER, TextBlockAnchor.BOTTOM_CENTER, 
        TextAnchor.CENTER, 0.0, CategoryLabelWidthType.CATEGORY, 0.95f
    );
}
 
Example #28
Source File: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Used instead of <code>org.jfree.chart.axis.CategoryLabelPosition.createUpRotationLabelPositions</code>.
 * <p>
 * It additionally takes into consideration the axis position.
 *
 * @param axisPosition
 * @param labelAngle
 * @return
 */
protected CategoryLabelPosition createUpRotationCategoryLabelPosition( PlaneDirection axisPosition, double labelAngle ) {
  RectangleAnchor categoryAnchor = axisPosition.opposite().asRectangleAnchor();
  double labelAnchorDirectionAngle = axisPosition.opposite().asAngle() - labelAngle;
  PlaneDirection labelAnchorDirection = getTextAnchorDirectionOfAngle( labelAnchorDirectionAngle );
  TextBlockAnchor labelAnchor = labelAnchorDirection.asTextBlockAnchor();
  TextAnchor rotationAnchor = labelAnchorDirection.asTextAnchor();
  return new CategoryLabelPosition( categoryAnchor, labelAnchor, rotationAnchor, -labelAngle,
      CategoryLabelWidthType.RANGE, 0.50f );
}
 
Example #29
Source File: TextTitle.java    From ccu-historian with GNU General Public License v3.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 #30
Source File: CategoryTickTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Confirm that cloning works.
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    CategoryTick t1 = new CategoryTick("C1", new TextBlock(), 
            TextBlockAnchor.CENTER, TextAnchor.CENTER, 1.5f);
    CategoryTick t2 = (CategoryTick) t1.clone();
    assertTrue(t1 != t2);
    assertTrue(t1.getClass() == t2.getClass());
    assertTrue(t1.equals(t2));
}