Java Code Examples for java.awt.geom.Point2D.getX()

The following are Jave code examples for showing how to use getX() of the java.awt.geom.Point2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cuttlefish   File: GraphMouseImpl.java   View Source Code Vote up 6 votes
public void mouseDragged(MouseEvent e) {
	Point2D p = e.getPoint();
	Point2D s = renderer.screenToWorld(p);

	if (isPanning && mouseInMode(Mode.TRANSFORMING)) {
		dx = p.getX() - panStart.getX();
		dy = p.getY() - panStart.getY();
		renderer.translate(dx, dy);
		panStart.setLocation(p);
	}

	if (isMoving) {

		if (oldPosition == null)
			oldPosition = grabbed.getPosition();
		grabbed.setPosition(s);
	}

	if (isCreatingEdge) {
		renderer.getEdgeRenderer()
				.drawEdgeToPoint(grabbed.getPosition(), s);
	}
}
 
Example 2
Project: s-store   File: GraphVisualizationPanel.java   View Source Code Vote up 6 votes
public void centerVisualization(V vertex, final boolean immediate) {
    if (vertex != null) {
        Layout<V,E> layout = this.getGraphLayout();
        Point2D q = layout.transform(vertex);
        Point2D lvc = this.getRenderContext().getMultiLayerTransformer().inverseTransform(this.getCenter());
        final int steps = (immediate ? 1 : 10);
        final double dx = (lvc.getX() - q.getX()) / steps;
        final double dy = (lvc.getY() - q.getY()) / steps;

        new Thread() {
            public void run() {
                MutableTransformer transformer = GraphVisualizationPanel.this.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT); 
                for (int i = 0; i < steps; i++) {
                    transformer.translate(dx, dy);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                    }
                }
            }
        }.start();
    }
}
 
Example 3
Project: cuttlefish   File: IntersectingShapePickSupport.java   View Source Code Vote up 5 votes
public static boolean containsPoint(Edge edge, Point2D p, double scaleFactor) {
	Shape edgeShape = null;

	if (edge.getShape().equalsIgnoreCase(Constants.LINE_STRAIGHT)) {
		edgeShape = new Line2D.Double(edge.getSource().getPosition(), edge
				.getTarget().getPosition());

	} else if (edge.getShape().equalsIgnoreCase(Constants.LINE_CURVED)) {
		Point2D from = edge.getSource().getPosition();
		Point2D to = edge.getTarget().getPosition();
		double fx = from.getX();
		double fy = from.getY();
		double tx = to.getX();
		double ty = to.getY();
		double a = Utilities.calculateAngle(from, to);
		double h = EdgeRenderer.QUADCURVE_CTRL_POINT.getY() / scaleFactor;

		// Calculate Control Point
		double cx = (fx + tx) / 2 - h * Math.sin(a);
		double cy = (fy + ty) / 2 + h * Math.cos(a);

		edgeShape = new QuadCurve2D.Double(fx, fy, cx, cy, tx, ty);

	} else if (edge.getShape().equalsIgnoreCase(Constants.LINE_LOOP)) {
		// TODO: Calculate shape for loop to enable picking of loop edges
	}

	// Create a small rectangular area around point, and use it
	// to check for intersection with the line of the edge
	double pickRadius = 1;
	double px = p.getX();
	double py = p.getY();
	Rectangle2D pickArea = new Rectangle2D.Double(px - pickRadius, py
			- pickRadius, 2 * pickRadius, 2 * pickRadius);

	return edgeShape.intersects(pickArea);
}
 
Example 4
Project: parabuild-ci   File: BoxAndWhiskerRenderer.java   View Source Code Vote up 5 votes
/**
 * Draws two dots to represent the average value of more than one outlier.
 * 
 * @param point  the location
 * @param boxWidth  the box width.
 * @param oRadius  the radius.
 * @param g2  the graphics device.
 */
private void drawMultipleEllipse(Point2D point, double boxWidth, 
                                 double oRadius, Graphics2D g2)  {
                                     
    Ellipse2D dot1 = new Ellipse2D.Double(point.getX() - (boxWidth / 2) 
            + oRadius, point.getY(), oRadius, oRadius);
    Ellipse2D dot2 = new Ellipse2D.Double(point.getX() + (boxWidth / 2), 
            point.getY(), oRadius, oRadius);
    g2.draw(dot1);
    g2.draw(dot2);
}
 
Example 5
Project: rapidminer   File: CustomLegendGraphic.java   View Source Code Vote up 5 votes
private static LinearGradientPaint getTranslatedLinearGradientPaint(LinearGradientPaint gradient, Point2D startPoint,
		Point2D endPoint, boolean vertical) {
	if (vertical) {
		return new LinearGradientPaint(0f, (float) startPoint.getY(), 0f, (float) endPoint.getY(),
				gradient.getFractions(), gradient.getColors());
	} else {
		return new LinearGradientPaint((float) startPoint.getX(), 0f, (float) endPoint.getX(), 0f,
				gradient.getFractions(), gradient.getColors());
	}
}
 
Example 6
Project: MaxSim   File: SplineConnectionWidget.java   View Source Code Vote up 5 votes
private static Point2D besselTangent(double delta_ib, double delta_i, Point2D p0, Point2D p1 , Point2D p2){
    double alpha_i = delta_ib/(delta_ib+delta_i);
    
    double x = (1-alpha_i)/delta_ib * (p1.getX() - p0.getX())
            + alpha_i/delta_i * (p2.getX()-p1.getX());
    double y = (1-alpha_i)/delta_ib * (p1.getY() - p0.getY())
            + alpha_i/delta_i * (p2.getY()-p1.getY());
   
    return new Point2D.Double(x,y);
}
 
Example 7
Project: UaicNlpToolkit   File: PathOrderBox.java   View Source Code Vote up 5 votes
public PathOrderBox(GraphNode parent, GraphNode child, int index, Point2D middle, Graphics2D g2d, int displayIndex) {
    parentGraphNode = parent;
    childGraphNode = child;
    this.index = index;
    this.displayIndex = displayIndex;
    Rectangle2D bounds = g2d.getFont().getStringBounds(Integer.toString(index), g2d.getFontRenderContext());
    rect = new RoundRectangle2D.Double(middle.getX() - bounds.getWidth() / 2 - 5, middle.getY() - bounds.getHeight() / 2, bounds.getWidth() + 10, bounds.getHeight(), bounds.getHeight() - 1, bounds.getHeight() - 1);
}
 
Example 8
Project: cuttlefish   File: LabelRenderer.java   View Source Code Vote up 5 votes
private void drawLabel(Vertex v) {
	String text = v.getLabel();
	float[] c = v.getBorderColor().getColorComponents(null);
	Point2D pos = v.getPosition();
	double x = pos.getX() + v.getSize() / scaleFactor;
	double y = pos.getY() + (v.getSize() + VERTEX_LABEL_OFFSET)
			/ scaleFactor;
	pos.setLocation(x, y);

	gl.glColor3f(c[0], c[1], c[2]);
	renderText(text, pos);
}
 
Example 9
Project: OpenJSharp   File: LayoutPathImpl.java   View Source Code Vote up 5 votes
public boolean pointToPath(Point2D pt, Point2D result) {
    result.setLocation(pt);
    if (tx != null) {
        try {
            tx.inverseTransform(pt, result);
        }
        catch (NoninvertibleTransformException ex) {
        }
    }
    return result.getX() > 0;
}
 
Example 10
Project: vexillo   File: Symbol.java   View Source Code Vote up 5 votes
private static void coArcTo(GeneralPath p, double x2, double y2, double x3, double y3) {
	Point2D p1 = p.getCurrentPoint();
	double x1 = p1.getX();
	double y1 = p1.getY();
	boolean xe = (x1 == x2 && x2 == x3);
	boolean ye = (y1 == y2 && y2 == y3);
	if (xe && ye) return;
	if (xe || ye) { p.lineTo(x3, y3); return; }
	double d = arcHK(x1, y1, x2, y2, x3, y3);
	double h = arcH(x1, y1, x2, y2, x3, y3) / d;
	double k = arcK(x1, y1, x2, y2, x3, y3) / d;
	if (Double.isNaN(h) || Double.isInfinite(h)) { p.lineTo(x3, y3); return; }
	if (Double.isNaN(k) || Double.isInfinite(k)) { p.lineTo(x3, y3); return; }
	double r = Math.hypot(k - y1, x1 - h);
	double a1 = Math.toDegrees(Math.atan2(k - y1, x1 - h));
	double a2 = Math.toDegrees(Math.atan2(k - y2, x2 - h));
	double a3 = Math.toDegrees(Math.atan2(k - y3, x3 - h));
	Arc2D.Double arc = new Arc2D.Double();
	arc.x = h - r;
	arc.y = k - r;
	arc.width = r + r;
	arc.height = r + r;
	arc.start = a1;
	if ((a1 <= a2 && a2 <= a3) || (a3 <= a2 && a2 <= a1)) {
		arc.extent = a3 - a1;
	} else if (a3 <= a1) {
		arc.extent = a3 - a1 + 360;
	} else {
		arc.extent = a3 - a1 - 360;
	}
	p.append(arc, true);
}
 
Example 11
Project: geomapapp   File: XYGraph.java   View Source Code Vote up 5 votes
public double getXAt( Point2D p ) {
	Insets insets = axes.getInsets();
	Rectangle r = getVisibleRect();
	double w = (double)(r.width - insets.left - insets.right);
	if( tracksWidth  || scPane==null) {
		return xRange[0] + (xRange[1]-xRange[0])*(p.getX()-(double)insets.left)/w;
	} else {
		return xRange[0] + (p.getX()-(double)insets.left) / (xScale*zoom);
	}
}
 
Example 12
Project: litiengine   File: GeometricUtilities.java   View Source Code Vote up 5 votes
public static Point2D getMidPoint(final Point2D p1, final Point2D p2) {
  final Point2D mid = new Point2D.Double();
  final double x = (p1.getX() + p2.getX()) / 2;
  final double y = (p1.getY() + p2.getY()) / 2;
  mid.setLocation(x, y);
  return mid;

}
 
Example 13
Project: ramus   File: Group.java   View Source Code Vote up 5 votes
public void setTranslate(Point2D translate, List<Side> dragSides,
                         Diagram diagram) {
    if (dragSides.size() == 0)
        this.translate = translate;
    else {
        Rectangle2D rect = getRectangle();

        Component component = diagram.getComponent(bounds[0]);

        double minWidth = component.getMinWidth();
        double minHieght = component.getMinHeight();

        if (dragSides.indexOf(Side.RIGHT) >= 0) {
            if (rect.getWidth() + translate.getX() > minWidth)
                addSize.setWidth(translate.getX());
        }
        if (dragSides.indexOf(Side.BOTTOM) >= 0)
            if (rect.getHeight() + translate.getY() > minHieght)
                addSize.setHeight(translate.getY());
        if (dragSides.indexOf(Side.TOP) >= 0) {
            if (rect.getHeight() - translate.getY() > minHieght) {
                addSize.setHeight(-translate.getY());
                this.translate.setLocation(this.translate.getX(), translate
                        .getY());
            }
        }
        if (dragSides.indexOf(Side.LEFT) >= 0) {
            if (rect.getWidth() - translate.getX() > minWidth) {
                addSize.setWidth(-translate.getX());
                this.translate.setLocation(translate.getX(), this.translate
                        .getY());
            }
        }
    }
}
 
Example 14
Project: jmt   File: JMTPoint.java   View Source Code Vote up 4 votes
/**
 * Builds a new JMTPoint from a given point
 * @param point point for coordinates
 * @param rotate true if station is rotated
 */
public JMTPoint(Point2D point, boolean rotate) {
	this.x = point.getX();
	this.y = point.getY();
	this.rotate = rotate;
}
 
Example 15
Project: OpenJSharp   File: CCursorManager.java   View Source Code Vote up 4 votes
@Override
protected Point getCursorPosition() {
    final Point2D nativePosition = nativeGetCursorPosition();
    return new Point((int)nativePosition.getX(), (int)nativePosition.getY());
}
 
Example 16
Project: openjdk-jdk10   File: LinearGradientPaint.java   View Source Code Vote up 4 votes
/**
 * 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
Project: litiengine   File: MapUtilities.java   View Source Code Vote up 4 votes
public static Point getTile(final IMap map, final Point2D mapLocation) {
  return new Point((int) (mapLocation.getX() / map.getTileSize().getWidth()), (int) (mapLocation.getY() / map.getTileSize().getHeight()));
}
 
Example 18
Project: JBotSim   File: ToroidalLinkPainter.java   View Source Code Vote up 4 votes
protected void drawLine(Graphics2D g2d, Point2D p1, Point2D p2) {
    int srcX=(int)p1.getX(), srcY=(int)p1.getY();
    int destX=(int)p2.getX(), destY=(int)p2.getY();
    g2d.drawLine(srcX, srcY, (srcX+(destX-srcX)), (srcY+(destY-srcY)));
}
 
Example 19
Project: JBotSim   File: LinesObstacle.java   View Source Code Vote up 4 votes
private boolean hasCollisionAABB(Point2D a, Point2D b,Point2D o,Point2D p) {
    Point2D opMinX;
    Point2D opMaxX;
    Point2D opMinY;
    Point2D opMaxY;
    Point2D abMinX;
    Point2D abMaxX;
    Point2D abMinY;
    Point2D abMaxY;

    if(o.getX() < p.getX()){
        opMinX=o;
        opMaxX=p;
    }
    else{
        opMinX=p;
        opMaxX=o;
    }
    if(a.getX()<b.getX()){
        abMinX=a;
        abMaxX=b;
    }
    else{
        abMinX=b;
        abMaxX=a;
    }    
    if(a.getY()<b.getY()){
        abMinY=a;
        abMaxY=b;
    }    
    else{
        abMinY=b;
        abMaxY=a;
    }
    if(o.getY() < p.getY()){
        opMinY=o;
        opMaxY=p;
    }
    else{
        opMinY=p;
        opMaxY=o;
    }

    return !(opMinX.getX() >= abMaxX.getX() || opMaxX.getX() <= abMinX.getX() 
            || opMinY.getY() >= abMaxY.getY() || opMaxY.getY() <= abMinY.getY());
}
 
Example 20
Project: litiengine   File: CombatEntityVision.java   View Source Code Vote up 2 votes
/**
 * Gets the render vision circle.
 *
 * @param entity
 *          the mob
 * @return the render vision circle
 */
private Ellipse2D getRenderVisionArc(final IEntity entity) {
  final Point2D renderDimensionCenter = Game.getCamera().getViewPortDimensionCenter(entity);
  return new Ellipse2D.Double(renderDimensionCenter.getX() - this.visionRadius, renderDimensionCenter.getY() - this.visionRadius, this.visionDiameter, this.visionDiameter);
}