Java Code Examples for java.awt.geom.Point2D#equals()

The following examples show how to use java.awt.geom.Point2D#equals() . 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: Outlier.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Compares this object with the specified object for order, based on
 * the outlier's point.
 *
 * @param   o the Object to be compared.
 * @return A negative integer, zero, or a positive integer as this object
 *      is less than, equal to, or greater than the specified object.
 *
 */
@Override
public int compareTo(Object o) {
    Outlier outlier = (Outlier) o;
    Point2D p1 = getPoint();
    Point2D p2 = outlier.getPoint();
    if (p1.equals(p2)) {
        return 0;
    }
    else if ((p1.getX() < p2.getX()) || (p1.getY() < p2.getY())) {
        return -1;
    }
    else {
        return 1;
    }
}
 
Example 2
Source File: WindDirection.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, LCD.getMinY() + 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, LCD.getMaxY() - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example 3
Source File: DisplaySingle.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, getHeight() - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example 4
Source File: LinearBargraph.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, LCD.getMinY() + 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, LCD.getMaxY() - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example 5
Source File: DigitialRadial.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, LCD.getMinY() + 1.0);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, LCD.getMaxY() - 1);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example 6
Source File: AbstractPolygon2D.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean bordersPoint2D(Point2D Point2D) {
    boolean borders = false;

    Iterator<Point2D> it = point2Ds.iterator();
    for (int i = 0; i < length; i++) {
        Point2D point = it.next();
        if (point.equals(Point2D)) {
            borders = true;
        }
    }
    return borders;
}
 
Example 7
Source File: Path2DCopyConstructor.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testGetCurrentPoint(Path2D pathA, Path2D pathB) {
    final Point2D ptA = pathA.getCurrentPoint();
    final Point2D ptB = pathA.getCurrentPoint();
    if (((ptA == null) && (ptB != null))
        || ((ptA != null) && !ptA.equals(ptB)))
    {
        throw new IllegalStateException("getCurrentPoint() are not equals ["
            + ptA + "|" + ptB + "] !");
    }
    log("testGetCurrentPoint: passed.");
}
 
Example 8
Source File: Path2DCopyConstructor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void testGetCurrentPoint(Path2D pathA, Path2D pathB) {
    final Point2D ptA = pathA.getCurrentPoint();
    final Point2D ptB = pathA.getCurrentPoint();
    if (((ptA == null) && (ptB != null))
        || ((ptA != null) && !ptA.equals(ptB)))
    {
        throw new IllegalStateException("getCurrentPoint() are not equals ["
            + ptA + "|" + ptB + "] !");
    }
    log("testGetCurrentPoint: passed.");
}
 
Example 9
Source File: Outlier.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Compares this object with the specified object for order, based on
 * the outlier's point.
 *
 * @param   o the Object to be compared.
 * @return A negative integer, zero, or a positive integer as this object
 *      is less than, equal to, or greater than the specified object.
 *
 */
public int compareTo(Object o) {
    Outlier outlier = (Outlier) o;
    Point2D p1 = getPoint();
    Point2D p2 = outlier.getPoint();
    if (p1.equals(p2)) {
        return 0;
    } 
    else if ((p1.getX() < p2.getX()) || (p1.getY() < p2.getY())) {
        return -1;
    } 
    else {
        return 1;
    } 
}
 
Example 10
Source File: Outlier.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compares this object with the specified object for order, based on
 * the outlier's point.
 *
 * @param   o the Object to be compared.
 * @return A negative integer, zero, or a positive integer as this object
 *      is less than, equal to, or greater than the specified object.
 *
 */
public int compareTo(Object o) {
    Outlier outlier = (Outlier) o;
    Point2D p1 = getPoint();
    Point2D p2 = outlier.getPoint();
    if (p1.equals(p2)) {
        return 0;
    } 
    else if ((p1.getX() < p2.getX()) || (p1.getY() < p2.getY())) {
        return -1;
    } 
    else {
        return 1;
    } 
}
 
Example 11
Source File: DisplayRectangular.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Paint createCustomLcdBackgroundPaint(final Color[] LCD_COLORS) {
    int offset = 1;
    if (isFrameVisible()) {
        offset = 19;
    }
    final Point2D FOREGROUND_START = new Point2D.Double(0.0, offset);
    final Point2D FOREGROUND_STOP = new Point2D.Double(0.0, getHeight() - offset);
    if (FOREGROUND_START.equals(FOREGROUND_STOP)) {
        FOREGROUND_STOP.setLocation(0.0, FOREGROUND_START.getY() + 1);
    }

    final float[] FOREGROUND_FRACTIONS = {
        0.0f,
        0.03f,
        0.49f,
        0.5f,
        1.0f
    };

    final Color[] FOREGROUND_COLORS = {
        LCD_COLORS[0],
        LCD_COLORS[1],
        LCD_COLORS[2],
        LCD_COLORS[3],
        LCD_COLORS[4]
    };

    return new LinearGradientPaint(FOREGROUND_START, FOREGROUND_STOP, FOREGROUND_FRACTIONS, FOREGROUND_COLORS);
}
 
Example 12
Source File: Path2DCopyConstructor.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testGetCurrentPoint(Path2D pathA, Path2D pathB) {
    final Point2D ptA = pathA.getCurrentPoint();
    final Point2D ptB = pathA.getCurrentPoint();
    if (((ptA == null) && (ptB != null))
        || ((ptA != null) && !ptA.equals(ptB)))
    {
        throw new IllegalStateException("getCurrentPoint() are not equals ["
            + ptA + "|" + ptB + "] !");
    }
    log("testGetCurrentPoint: passed.");
}
 
Example 13
Source File: LinearGradientPaint.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a {@code LinearGradientPaint}.
 *
 * @param start the gradient axis start {@code Point2D} in user space
 * @param end the gradient axis end {@code Point2D} in user space
 * @param fractions numbers ranging from 0.0 to 1.0 specifying the
 *                  distribution of colors along the gradient
 * @param colors array of colors corresponding to each fractional value
 * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
 *                    or {@code REPEAT}
 * @param colorSpace which color space to use for interpolation,
 *                   either {@code SRGB} or {@code LINEAR_RGB}
 * @param gradientTransform transform to apply to the gradient
 *
 * @throws NullPointerException
 * if one of the points is null,
 * or {@code fractions} array is null,
 * or {@code colors} array is null,
 * or {@code cycleMethod} is null,
 * or {@code colorSpace} is null,
 * or {@code gradientTransform} is null
 * @throws IllegalArgumentException
 * if start and end points are the same points,
 * or {@code fractions.length != colors.length},
 * or {@code colors} is less than 2 in size,
 * or a {@code fractions} value is less than 0.0 or greater than 1.0,
 * or the {@code fractions} are not provided in strictly increasing order
 */
@ConstructorProperties({ "startPoint", "endPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" })
public LinearGradientPaint(Point2D start, Point2D end,
                           float[] fractions, Color[] colors,
                           CycleMethod cycleMethod,
                           ColorSpaceType colorSpace,
                           AffineTransform gradientTransform)
{
    super(fractions, colors, cycleMethod, colorSpace, gradientTransform);

    // check input parameters
    if (start == null || end == null) {
        throw new NullPointerException("Start and end points must be" +
                                       "non-null");
    }

    if (start.equals(end)) {
        throw new IllegalArgumentException("Start point cannot equal" +
                                           "endpoint");
    }

    // copy the points...
    this.start = new Point2D.Double(start.getX(), start.getY());
    this.end = new Point2D.Double(end.getX(), end.getY());
}
 
Example 14
Source File: GeoJsonPolygon.java    From bboxdb with Apache License 2.0 4 votes vote down vote up
/**
 * Build the JSON representation
 * @param repair 
 * @return
 */
protected JSONObject buildJSON() {
	final JSONObject featureJson = new JSONObject();
	featureJson.put(JSON_TYPE, JSON_FEATURE);
	featureJson.put(JSON_ID, id);

	final JSONObject geometryJson = new JSONObject();
	final JSONArray coordinateJson = new JSONArray();

	geometryJson.put(JSON_COORDINATES, coordinateJson);
	featureJson.put(JSON_GEOMETRY, geometryJson);

	if(pointList.isEmpty()) {
		// Nothing to add
	} else {
		final Point2D firstPoint = pointList.get(0);
		final Point2D lastPoint = pointList.get(pointList.size() - 1);

		if(pointList.size() == 1) {
			geometryJson.put(JSON_TYPE, JSON_TYPE_POINT);
			coordinateJson.put(firstPoint.getX());
			coordinateJson.put(firstPoint.getY());
		} else if(! firstPoint.equals(lastPoint)) {
			geometryJson.put(JSON_TYPE, JSON_TYPE_LINESTRING);
			addCoordinatesToJSON(coordinateJson);
		} else {
			geometryJson.put(JSON_TYPE, JSON_TYPE_POLYGON);
			final JSONArray pointsJson = new JSONArray();
			addCoordinatesToJSON(pointsJson);
			coordinateJson.put(pointsJson);
		}
	}

	final JSONObject propertiesJson = new JSONObject();
	featureJson.put(JSON_PROPERTIES, propertiesJson);
	for(final Entry<String, String> entry : properties.entrySet()) {
		final String key = entry.getKey();
		final String value = entry.getValue();
		propertiesJson.put(key, value);
	}
	
	return featureJson;
}
 
Example 15
Source File: DrawPaint.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected Paint createLinearGradientPaint(GradientPaint fill, Graphics2D graphics) {
        // TODO: we need to find the two points for gradient - the problem is, which point at the outline
        // do you take? My solution would be to apply the gradient rotation to the shape in reverse
        // and then scan the shape for the largest possible horizontal distance

        double angle = fill.getGradientAngle();
        if (!fill.isRotatedWithShape()) {
            angle -= shape.getRotation();
        }

        Rectangle2D anchor = DrawShape.getAnchor(graphics, shape);
        final double h = anchor.getHeight(), w = anchor.getWidth(), x = anchor.getX(), y = anchor.getY();

        AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(angle), anchor.getCenterX(), anchor.getCenterY());

        double diagonal = Math.sqrt(h * h + w * w);
        Point2D p1 = new Point2D.Double(x + w / 2 - diagonal / 2, y + h / 2);
        p1 = at.transform(p1, null);

        Point2D p2 = new Point2D.Double(x + w, y + h / 2);
        p2 = at.transform(p2, null);

//        snapToAnchor(p1, anchor);
//        snapToAnchor(p2, anchor);

        if (p1.equals(p2)) {
            // gradient paint on the same point throws an exception ... and doesn't make sense
            return null;
        }

        float[] fractions = fill.getGradientFractions();
        Color[] colors = new Color[fractions.length];

        int i = 0;
        for (ColorStyle fc : fill.getGradientColors()) {
            // if fc is null, use transparent color to get color of background
            colors[i++] = (fc == null) ? TRANSPARENT : applyColorTransform(fc);
        }

        return new LinearGradientPaint(p1, p2, fractions, colors);
    }
 
Example 16
Source File: LinearGradientPaint.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a {@code LinearGradientPaint}.
 *
 * @param start the gradient axis start {@code Point2D} in user space
 * @param end the gradient axis end {@code Point2D} in user space
 * @param fractions numbers ranging from 0.0 to 1.0 specifying the
 *                  distribution of colors along the gradient
 * @param colors array of colors corresponding to each fractional value
 * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
 *                    or {@code REPEAT}
 * @param colorSpace which color space to use for interpolation,
 *                   either {@code SRGB} or {@code LINEAR_RGB}
 * @param gradientTransform transform to apply to the gradient
 *
 * @throws NullPointerException
 * if one of the points is null,
 * or {@code fractions} array is null,
 * or {@code colors} array is null,
 * or {@code cycleMethod} is null,
 * or {@code colorSpace} is null,
 * or {@code gradientTransform} is null
 * @throws IllegalArgumentException
 * if start and end points are the same points,
 * or {@code fractions.length != colors.length},
 * or {@code colors} is less than 2 in size,
 * or a {@code fractions} value is less than 0.0 or greater than 1.0,
 * or the {@code fractions} are not provided in strictly increasing order
 */
@ConstructorProperties({ "startPoint", "endPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" })
public LinearGradientPaint(Point2D start, Point2D end,
                           float[] fractions, Color[] colors,
                           CycleMethod cycleMethod,
                           ColorSpaceType colorSpace,
                           AffineTransform gradientTransform)
{
    super(fractions, colors, cycleMethod, colorSpace, gradientTransform);

    // check input parameters
    if (start == null || end == null) {
        throw new NullPointerException("Start and end points must be" +
                                       "non-null");
    }

    if (start.equals(end)) {
        throw new IllegalArgumentException("Start point cannot equal" +
                                           "endpoint");
    }

    // copy the points...
    this.start = new Point2D.Double(start.getX(), start.getY());
    this.end = new Point2D.Double(end.getX(), end.getY());
}
 
Example 17
Source File: LinearGradientPaint.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a {@code LinearGradientPaint}.
 *
 * @param start the gradient axis start {@code Point2D} in user space
 * @param end the gradient axis end {@code Point2D} in user space
 * @param fractions numbers ranging from 0.0 to 1.0 specifying the
 *                  distribution of colors along the gradient
 * @param colors array of colors corresponding to each fractional value
 * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
 *                    or {@code REPEAT}
 * @param colorSpace which color space to use for interpolation,
 *                   either {@code SRGB} or {@code LINEAR_RGB}
 * @param gradientTransform transform to apply to the gradient
 *
 * @throws NullPointerException
 * if one of the points is null,
 * or {@code fractions} array is null,
 * or {@code colors} array is null,
 * or {@code cycleMethod} is null,
 * or {@code colorSpace} is null,
 * or {@code gradientTransform} is null
 * @throws IllegalArgumentException
 * if start and end points are the same points,
 * or {@code fractions.length != colors.length},
 * or {@code colors} is less than 2 in size,
 * or a {@code fractions} value is less than 0.0 or greater than 1.0,
 * or the {@code fractions} are not provided in strictly increasing order
 */
@ConstructorProperties({ "startPoint", "endPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" })
public LinearGradientPaint(Point2D start, Point2D end,
                           float[] fractions, Color[] colors,
                           CycleMethod cycleMethod,
                           ColorSpaceType colorSpace,
                           AffineTransform gradientTransform)
{
    super(fractions, colors, cycleMethod, colorSpace, gradientTransform);

    // check input parameters
    if (start == null || end == null) {
        throw new NullPointerException("Start and end points must be" +
                                       "non-null");
    }

    if (start.equals(end)) {
        throw new IllegalArgumentException("Start point cannot equal" +
                                           "endpoint");
    }

    // copy the points...
    this.start = new Point2D.Double(start.getX(), start.getY());
    this.end = new Point2D.Double(end.getX(), end.getY());
}
 
Example 18
Source File: LinearGradientPaint.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a {@code LinearGradientPaint}.
 *
 * @param start the gradient axis start {@code Point2D} in user space
 * @param end the gradient axis end {@code Point2D} in user space
 * @param fractions numbers ranging from 0.0 to 1.0 specifying the
 *                  distribution of colors along the gradient
 * @param colors array of colors corresponding to each fractional value
 * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
 *                    or {@code REPEAT}
 * @param colorSpace which color space to use for interpolation,
 *                   either {@code SRGB} or {@code LINEAR_RGB}
 * @param gradientTransform transform to apply to the gradient
 *
 * @throws NullPointerException
 * if one of the points is null,
 * or {@code fractions} array is null,
 * or {@code colors} array is null,
 * or {@code cycleMethod} is null,
 * or {@code colorSpace} is null,
 * or {@code gradientTransform} is null
 * @throws IllegalArgumentException
 * if start and end points are the same points,
 * or {@code fractions.length != colors.length},
 * or {@code colors} is less than 2 in size,
 * or a {@code fractions} value is less than 0.0 or greater than 1.0,
 * or the {@code fractions} are not provided in strictly increasing order
 */
@ConstructorProperties({ "startPoint", "endPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" })
public LinearGradientPaint(Point2D start, Point2D end,
                           float[] fractions, Color[] colors,
                           CycleMethod cycleMethod,
                           ColorSpaceType colorSpace,
                           AffineTransform gradientTransform)
{
    super(fractions, colors, cycleMethod, colorSpace, gradientTransform);

    // check input parameters
    if (start == null || end == null) {
        throw new NullPointerException("Start and end points must be" +
                                       "non-null");
    }

    if (start.equals(end)) {
        throw new IllegalArgumentException("Start point cannot equal" +
                                           "endpoint");
    }

    // copy the points...
    this.start = new Point2D.Double(start.getX(), start.getY());
    this.end = new Point2D.Double(end.getX(), end.getY());
}
 
Example 19
Source File: LinearGradientPaint.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a {@code LinearGradientPaint}.
 *
 * @param start the gradient axis start {@code Point2D} in user space
 * @param end the gradient axis end {@code Point2D} in user space
 * @param fractions numbers ranging from 0.0 to 1.0 specifying the
 *                  distribution of colors along the gradient
 * @param colors array of colors corresponding to each fractional value
 * @param cycleMethod either {@code NO_CYCLE}, {@code REFLECT},
 *                    or {@code REPEAT}
 * @param colorSpace which color space to use for interpolation,
 *                   either {@code SRGB} or {@code LINEAR_RGB}
 * @param gradientTransform transform to apply to the gradient
 *
 * @throws NullPointerException
 * if one of the points is null,
 * or {@code fractions} array is null,
 * or {@code colors} array is null,
 * or {@code cycleMethod} is null,
 * or {@code colorSpace} is null,
 * or {@code gradientTransform} is null
 * @throws IllegalArgumentException
 * if start and end points are the same points,
 * or {@code fractions.length != colors.length},
 * or {@code colors} is less than 2 in size,
 * or a {@code fractions} value is less than 0.0 or greater than 1.0,
 * or the {@code fractions} are not provided in strictly increasing order
 */
@ConstructorProperties({ "startPoint", "endPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" })
public LinearGradientPaint(Point2D start, Point2D end,
                           float[] fractions, Color[] colors,
                           CycleMethod cycleMethod,
                           ColorSpaceType colorSpace,
                           AffineTransform gradientTransform)
{
    super(fractions, colors, cycleMethod, colorSpace, gradientTransform);

    // check input parameters
    if (start == null || end == null) {
        throw new NullPointerException("Start and end points must be" +
                                       "non-null");
    }

    if (start.equals(end)) {
        throw new IllegalArgumentException("Start point cannot equal" +
                                           "endpoint");
    }

    // copy the points...
    this.start = new Point2D.Double(start.getX(), start.getY());
    this.end = new Point2D.Double(end.getX(), end.getY());
}
 
Example 20
Source File: StandardCategoryAxis3D.java    From orson-charts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the axis between the two points {@code pt0} and {@code pt1} in 
 * Java2D space.
 * 
 * @param g2  the graphics target ({@code null} not permitted).
 * @param pt0  the starting point for the axis ({@code null} not 
 *     permitted).
 * @param pt1  the ending point for the axis ({@code null} not 
 *     permitted).
 * @param opposingPt  a point on the opposite side of the line from the 
 *         labels ({@code null} not permitted).
 * @param tickData  the tick data, contains positioning anchors calculated 
 *     by the 3D engine ({@code null} not permitted).
 * @param info  an object to be populated with rendering info 
 *     ({@code null} permitted).
 * @param hinting  perform element hinting?
 */
@Override
public void draw(Graphics2D g2, Point2D pt0, Point2D pt1, 
        Point2D opposingPt, List<TickData> tickData, RenderingInfo info,
        boolean hinting) {
    
    if (!isVisible()) {
        return;
    }
    if (pt0.equals(pt1)) { // if the axis starts and ends on the same point
        return;            // there is nothing we can draw
    }
    
    // draw the axis line (if you want no line, setting the line color
    // to fully transparent will achieve this)
    g2.setStroke(getLineStroke());
    g2.setPaint(getLineColor());
    Line2D axisLine = new Line2D.Float(pt0, pt1);
    g2.draw(axisLine);
 
    // draw the tick marks - during this pass we will also find the maximum
    // tick label width
    g2.setPaint(this.tickMarkPaint);
    g2.setStroke(this.tickMarkStroke);
    g2.setFont(getTickLabelFont());
    double maxTickLabelWidth = 0.0;
    for (TickData t : tickData) {
        if (this.tickMarkLength > 0.0) {
            Line2D tickLine = Utils2D.createPerpendicularLine(axisLine, 
                    t.getAnchorPt(), this.tickMarkLength, opposingPt);
            g2.draw(tickLine);
        }
        String tickLabel = t.getKeyLabel();
        maxTickLabelWidth = Math.max(maxTickLabelWidth, 
                g2.getFontMetrics().stringWidth(tickLabel));
    }

    double maxTickLabelDim = maxTickLabelWidth;
    if (getTickLabelsVisible()) {
        g2.setPaint(getTickLabelColor());
        if (this.tickLabelOrientation.equals(
                LabelOrientation.PERPENDICULAR)) {
            drawPerpendicularTickLabels(g2, axisLine, opposingPt, tickData,
                    info, hinting);
        } else if (this.tickLabelOrientation.equals(
                LabelOrientation.PARALLEL)) {
            maxTickLabelDim = drawParallelTickLabels(g2, axisLine, 
                    opposingPt, tickData, maxTickLabelWidth, info, hinting);
        }
    } else {
        maxTickLabelDim = 0.0;
    }

    // draw the axis label if there is one
    if (getLabel() != null) {
        Shape labelBounds = drawAxisLabel(getLabel(), g2, axisLine, 
                opposingPt, maxTickLabelDim + this.tickMarkLength 
                + this.tickLabelOffset + getLabelOffset(), info, hinting);
    }
}