Java Code Examples for org.jfree.ui.TextAnchor#TOP_LEFT

The following examples show how to use org.jfree.ui.TextAnchor#TOP_LEFT . 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: 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 < 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 2
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 3
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 4
Source File: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TextAnchor asTextAnchor() {
  switch ( this ) {
    case RIGHT:
      return TextAnchor.CENTER_RIGHT;
    case TOP_RIGHT:
      return TextAnchor.TOP_RIGHT;
    case TOP:
      return TextAnchor.TOP_CENTER;
    case TOP_LEFT:
      return TextAnchor.TOP_LEFT;
    case LEFT:
      return TextAnchor.CENTER_LEFT;
    case BOTTOM_LEFT:
      return TextAnchor.BOTTOM_LEFT;
    case BOTTOM:
      return TextAnchor.BOTTOM_CENTER;
    case BOTTOM_RIGHT:
      return TextAnchor.BOTTOM_RIGHT;
    default:
      return null;
  }
}
 
Example 5
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 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 6
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 7
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 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 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: CrosshairOverlay.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor 
 * point.
 * 
 * @param anchor  the anchor.
 * 
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorV(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 11
Source File: CrosshairOverlay.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor 
 * point.
 * 
 * @param anchor  the anchor.
 * 
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorV(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    return result;
}
 
Example 12
Source File: CrosshairOverlay.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor
 * point.
 *
 * @param anchor  the anchor.
 *
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorH(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    return result;
}
 
Example 13
Source File: CrosshairOverlay.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor
 * point.
 *
 * @param anchor  the anchor.
 *
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorH(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    return result;
}
 
Example 14
Source File: CrosshairOverlay.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the text anchor that is used to align a label to its anchor
 * point.
 *
 * @param anchor  the anchor.
 *
 * @return The text alignment point.
 */
private TextAnchor textAlignPtForLabelAnchorH(RectangleAnchor anchor) {
    TextAnchor result = TextAnchor.CENTER;
    if (anchor.equals(RectangleAnchor.TOP_LEFT)) {
        result = TextAnchor.BOTTOM_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.TOP)) {
        result = TextAnchor.BOTTOM_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.TOP_RIGHT)) {
        result = TextAnchor.BOTTOM_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.LEFT)) {
        result = TextAnchor.HALF_ASCENT_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.RIGHT)) {
        result = TextAnchor.HALF_ASCENT_RIGHT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_LEFT)) {
        result = TextAnchor.TOP_LEFT;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM)) {
        result = TextAnchor.TOP_CENTER;
    }
    else if (anchor.equals(RectangleAnchor.BOTTOM_RIGHT)) {
        result = TextAnchor.TOP_RIGHT;
    }
    return result;
}
 
Example 15
Source File: PolarPlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
 
Example 16
Source File: PolarPlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
 
Example 17
Source File: PolarPlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}
 
Example 18
Source File: TSNEDemo.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	chart = ChartFactory.createScatterPlot("", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);

	final XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true) {
		private static final long serialVersionUID = 1L;

		@Override
		public ItemLabelPosition getPositiveItemLabelPosition(int row, int column) {
			return new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_LEFT);
		}
	};
	final Font font = Font.decode("Helvetica Neue-22");
	renderer.setBaseItemLabelFont(font);
	chart.getXYPlot().setRenderer(renderer);
	// chart.getXYPlot().getDomainAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getDomainAxis().setTickLabelFont(font);
	// chart.getXYPlot().getDomainAxis().setTickUnit(new NumberTickUnit(1))
	// chart.getXYPlot().getRangeAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getRangeAxis().setTickLabelFont(font);
	// chart.getXYPlot().getRangeAxis().setTickUnit(new NumberTickUnit(1))

	chart.getXYPlot().getRenderer().setBaseItemLabelGenerator(new StandardXYItemLabelGenerator() {
		private static final long serialVersionUID = 1L;

		@Override
		public String generateLabel(XYDataset ds, int series, int item) {
			return ((Dataset) ds).getLabel(series, item);
		};
	});
	chart.getXYPlot().getRenderer().setBaseItemLabelsVisible(true);

	chartPanel = new ChartPanel(chart);
	chart.setBackgroundPaint(new java.awt.Color(255, 255, 255, 255));
	chart.getXYPlot().setBackgroundPaint(java.awt.Color.WHITE);
	chart.getXYPlot().setRangeGridlinePaint(java.awt.Color.GRAY);
	chart.getXYPlot().setDomainGridlinePaint(java.awt.Color.GRAY);

	chartPanel.setSize(width, height - 50);
	chartPanel.setPreferredSize(chartPanel.getSize());
	base.add(chartPanel);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run t-SNE");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	iterLabel = new JLabel("                         ");
	final Dimension size = iterLabel.getPreferredSize();
	iterLabel.setMinimumSize(size);
	iterLabel.setPreferredSize(size);
	controls.add(iterLabel);

	updateImage();

	return base;
}
 
Example 19
Source File: MDSDemo.java    From COMP6237 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Component getComponent(int width, int height) throws IOException {
	final JPanel base = new JPanel();
	base.setOpaque(false);
	base.setPreferredSize(new Dimension(width, height));
	base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

	chart = ChartFactory.createScatterPlot("", "", "", dataset, PlotOrientation.VERTICAL, false, false, false);

	final XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true) {
		private static final long serialVersionUID = 1L;

		@Override
		public ItemLabelPosition getPositiveItemLabelPosition(int row, int column) {
			return new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_LEFT);
		}
	};
	final Font font = Font.decode("Helvetica Neue-22");
	renderer.setBaseItemLabelFont(font);
	chart.getXYPlot().setRenderer(renderer);
	// chart.getXYPlot().getDomainAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getDomainAxis().setTickLabelFont(font);
	// chart.getXYPlot().getDomainAxis().setTickUnit(new NumberTickUnit(1))
	// chart.getXYPlot().getRangeAxis().setRange(-0.5, 5.5)
	chart.getXYPlot().getRangeAxis().setTickLabelFont(font);
	// chart.getXYPlot().getRangeAxis().setTickUnit(new NumberTickUnit(1))

	chart.getXYPlot().getRenderer().setBaseItemLabelGenerator(new StandardXYItemLabelGenerator() {
		private static final long serialVersionUID = 1L;

		@Override
		public String generateLabel(XYDataset ds, int series, int item) {
			return ((Dataset) ds).getLabel(series, item);
		};
	});
	chart.getXYPlot().getRenderer().setBaseItemLabelsVisible(true);

	chartPanel = new ChartPanel(chart);
	chart.setBackgroundPaint(new java.awt.Color(255, 255, 255, 255));
	chart.getXYPlot().setBackgroundPaint(java.awt.Color.WHITE);
	chart.getXYPlot().setRangeGridlinePaint(java.awt.Color.GRAY);
	chart.getXYPlot().setDomainGridlinePaint(java.awt.Color.GRAY);

	chartPanel.setSize(width, height - 50);
	chartPanel.setPreferredSize(chartPanel.getSize());
	base.add(chartPanel);

	final JPanel controls = new JPanel();
	controls.setPreferredSize(new Dimension(width, 50));
	controls.setMaximumSize(new Dimension(width, 50));
	controls.setSize(new Dimension(width, 50));

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	controls.add(new JLabel("Distance:"));

	distCombo = new JComboBox<String>();
	distCombo.addItem("Euclidean");
	distCombo.addItem("1-Pearson");
	distCombo.addItem("1-Cosine");
	controls.add(distCombo);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	runBtn = new JButton("Run MDS");
	runBtn.setActionCommand("button.run");
	runBtn.addActionListener(this);
	controls.add(runBtn);

	controls.add(new JSeparator(SwingConstants.VERTICAL));

	cnclBtn = new JButton("Cancel");
	cnclBtn.setEnabled(false);
	cnclBtn.setActionCommand("button.cancel");
	cnclBtn.addActionListener(this);
	controls.add(cnclBtn);

	base.add(controls);

	controls.add(new JSeparator(SwingConstants.VERTICAL));
	iterLabel = new JLabel("                         ");
	final Dimension size = iterLabel.getPreferredSize();
	iterLabel.setMinimumSize(size);
	iterLabel.setPreferredSize(size);
	controls.add(iterLabel);

	updateImage();

	return base;
}
 
Example 20
Source File: PolarPlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Calculate the text position for the given degrees.
 *
 * @param angleDegrees  the angle in degrees.
 * 
 * @return The optimal text anchor.
 * @since 1.0.14
 */
protected TextAnchor calculateTextAnchor(double angleDegrees) {
    TextAnchor ta = TextAnchor.CENTER;

    // normalize angle
    double offset = this.angleOffset;
    while (offset < 0.0) {
        offset += 360.0;
    }
    double normalizedAngle = (((this.counterClockwise ? -1 : 1)
            * angleDegrees) + offset) % 360;
    while (this.counterClockwise && (normalizedAngle < 0.0)) {
        normalizedAngle += 360.0;
    }

    if (normalizedAngle == 0.0) {
        ta = TextAnchor.CENTER_LEFT;
    }
    else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) {
        ta = TextAnchor.TOP_LEFT;
    }
    else if (normalizedAngle == 90.0) {
        ta = TextAnchor.TOP_CENTER;
    }
    else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) {
        ta = TextAnchor.TOP_RIGHT;
    }
    else if (normalizedAngle == 180) {
        ta = TextAnchor.CENTER_RIGHT;
    }
    else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) {
        ta = TextAnchor.BOTTOM_RIGHT;
    }
    else if (normalizedAngle == 270) {
        ta = TextAnchor.BOTTOM_CENTER;
    }
    else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) {
        ta = TextAnchor.BOTTOM_LEFT;
    }
    return ta;
}