List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:org.squidy.designer.model.PipeShape.java
private PBounds computeBounds() { // TODO: [RR] Hack!!! Do not compute bounds if ports are invisible. // if (source.getOutputPort().getScale() < 1.0 || // target.getOutputPort().getScale() < 1.0) { // return getBoundsReference(); // }/*from w w w. j a va 2 s . c om*/ PortShape sourcePortShape; PortShape targetPortShape; if (!source.getParent().equals(target.getParent())) { if (source instanceof PipelineShape && !(target instanceof PipelineShape)) { // ConnectorShape<?, ?> tmp = source; // source = target; // target = tmp; sourcePortShape = source.getInputPort(); targetPortShape = target.getInputPort(); } else if (!(source instanceof PipelineShape) && target instanceof PipelineShape) { sourcePortShape = source.getOutputPort(); targetPortShape = target.getOutputPort(); } else { // TODO [RR]: This may cause unexpected painting of shapes -> The visual shape drawing does not match the processing hierarchy. sourcePortShape = source.getInputPort(); targetPortShape = target.getInputPort(); } } else { sourcePortShape = source.getOutputPort(); targetPortShape = target.getInputPort(); } // System.out.println("GFB: " + source.getGlobalFullBounds()); // System.out.println("FBR: " + source.getFullBoundsReference()); // System.out.println("BR : " + source.getBoundsReference()); // System.out.println("Off: " + source.getOffset()); Point2D p1 = globalToLocal( sourcePortShape.getParent().localToGlobal(sourcePortShape.getFullBoundsReference().getCenter2D())); Point2D p2 = globalToLocal( targetPortShape.getParent().localToGlobal(targetPortShape.getFullBoundsReference().getCenter2D())); double x1 = p1.getX(); double x2 = p2.getX(); double y1 = p1.getY(); double y2 = p2.getY(); // Rectangle2D bounds1 = // globalToLocal(sourcePortShape.getGlobalFullBounds()); // Rectangle2D bounds2 = // globalToLocal(targetPortShape.getGlobalFullBounds()); // // double x1 = bounds1.getMinX(); // double x2 = bounds2.getMinX(); // double y1 = bounds1.getMinY(); // double y2 = bounds2.getMinY(); double x = Math.min(x1, x2); double y = Math.min(y1, y2); double width = Math.max(Math.abs(x1 - x2), 1); double height = Math.max(Math.abs(y1 - y2), 1); // Rectangle2D b = localToParent(new PBounds(x, y, width, height)); // shape.setCurve(x1, y1, x1 + (width / 2), y1, x2 - (width / 2), y2, // x2, y2); shape.setLine(x1, y1 - LINE_WIDTH / 2.0 - 10, x2, y2 - LINE_WIDTH / 2.0 - 10); return new PBounds(shape.getBounds()); }
From source file:org.jfree.experimental.chart.plot.dial.DialValueIndicator.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *///ww w. ja v a2s . co m public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.font); String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); }
From source file:org.apache.fop.svg.AbstractFOPTextPainter.java
private void updateLocationFromACI(AttributedCharacterIterator aci, Point2D loc) { //Adjust position of span Float xpos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.X); Float ypos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.Y); Float dxpos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.DX); Float dypos = (Float) aci.getAttribute(GVTAttributedCharacterIterator.TextAttribute.DY); if (xpos != null) { loc.setLocation(xpos.doubleValue(), loc.getY()); }/* w w w. ja v a2 s .co m*/ if (ypos != null) { loc.setLocation(loc.getX(), ypos.doubleValue()); } if (dxpos != null) { loc.setLocation(loc.getX() + dxpos.doubleValue(), loc.getY()); } if (dypos != null) { loc.setLocation(loc.getX(), loc.getY() + dypos.doubleValue()); } }
From source file:Hexagon.java
public void align(Rectangle2D bounds, Direction direction) { // these are defined here INSTEAD of in the switch, or it won't compile Point2D newTopRight, newTopLeft, newBottomRight, newBottomLeft; Point2D oldTopRight, oldTopLeft, oldBottomRight, oldBottomLeft; switch (direction) { case NorthEast: newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY()); oldTopRight = boundingCorners.get(BoundingCorner.TopRight); translate(newTopRight.getX() - oldTopRight.getX(), // deltaX newTopRight.getY() - oldTopRight.getY() // deltaY );// ww w. j a v a 2s. c om break; case East: newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY()); oldTopRight = boundingCorners.get(BoundingCorner.TopRight); translate(newTopRight.getX() - oldTopRight.getX(), // deltaX 0 // deltaY ); break; case SouthEast: newBottomRight = new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()); oldBottomRight = boundingCorners.get(BoundingCorner.BottomRight); translate(newBottomRight.getX() - oldBottomRight.getX(), // deltaX newBottomRight.getY() - oldBottomRight.getY() // deltaY ); break; case SouthWest: newBottomLeft = new Point2D.Double(bounds.getMinX(), bounds.getMaxY()); oldBottomLeft = boundingCorners.get(BoundingCorner.BottomLeft); translate(newBottomLeft.getX() - oldBottomLeft.getX(), // deltaX newBottomLeft.getY() - oldBottomLeft.getY() // deltaY ); break; case West: newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY()); oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft); translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX 0 // deltaY ); break; case NorthWest: newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY()); oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft); translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX newTopLeft.getY() - oldTopLeft.getY() // deltaY ); break; } }
From source file:edu.snu.leader.discrete.simulator.Agent.java
/** * Initializes Agent//w ww . ja va 2 s. c o m * * @param simState The simulation state */ public void initialize(SimulationState simState, Point2D initialLocation) { _simState = simState; _initialLocation = new Vector2D(initialLocation.getX(), initialLocation.getY()); String nearestNeighborCount = _simState.getProperties().getProperty("nearest-neighbor-count"); Validate.notEmpty(nearestNeighborCount, "Nearest neighbor count may not be empty"); _nearestNeighborCount = Integer.parseInt(nearestNeighborCount); String maxLocationRadius = _simState.getProperties().getProperty("max-location-radius"); Validate.notEmpty(maxLocationRadius, "Max location raidus may not be empty"); _maxLocationRadius = Double.parseDouble(maxLocationRadius); String canMultipleInitiate = _simState.getProperties().getProperty("can-multiple-initiate"); Validate.notEmpty(canMultipleInitiate, "Can multiple initiate may not be empty"); _canMultipleInitiate = Boolean.parseBoolean(canMultipleInitiate); String cancellationThreshold = _simState.getProperties().getProperty("cancellation-threshold"); Validate.notEmpty(cancellationThreshold, "Use cancellation threshold may not be empty"); _cancellationThreshold = Double.parseDouble(cancellationThreshold); String lambda = _simState.getProperties().getProperty("lambda"); Validate.notEmpty(lambda, "Lambda may not be empty"); _lambda = Float.parseFloat(lambda); String preCalcProbs = _simState.getProperties().getProperty("pre-calculate-probabilities"); Validate.notEmpty(preCalcProbs, "pre-calculate-probabilities may not be empty"); _preCalcProbs = Boolean.parseBoolean(preCalcProbs); _communicationType = _simState.getCommunicationType(); _positionHistory = new Reporter(_id.toString() + ".dat", "", false); reset(); _personalityTrait.initialize(this); }
From source file:net.sf.mzmine.modules.visualization.metamsecorrelate.visual.pseudospectra.PseudoSpectraRenderer.java
@Override protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { //super.drawItemLabel(g2, dataset, series, item, plot, generator, bar, negative); if (generator != null) { String label = generator.generateLabel(dataset, series, item); if (label != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont);//from w ww . j av a 2 s . co m g2.setPaint(paint); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); // split by \n String symbol = "\n"; String[] splitted = label.split(symbol); if (splitted.length > 1) { FontRenderContext frc = g2.getFontRenderContext(); GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,"); int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight(); // draw more than one row for (int i = 0; i < splitted.length; i++) { int offset = -height * (splitted.length - i - 1); TextUtilities.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(), (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } else { // one row TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } } }
From source file:lu.lippmann.cdb.graph.GraphViewImpl.java
public void rescaleSatelliteView() { //MutableTransformer masterViewTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW); //MutableTransformer masterLayoutTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT); MutableTransformer slaveViewTransformer = vv2.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW); MutableTransformer slaveLayoutTransformer = vv2.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT); final Layout<CNode, CEdge> layout = vv.getGraphLayout(); double minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE; final Graph<CNode, CEdge> graph = layout.getGraph(); double w = 0, h = 0; for (final CNode n : graph.getVertices()) { final Point2D point = layout.transform(n); //center of the node if (point.getX() < minX) { minX = point.getX();//w w w.j a va 2 s . c o m w = ShapeFactory.createShape(n.getShape()).getBounds().getWidth() / 2; } if (point.getX() > maxX) { maxX = point.getX(); } if (point.getY() < minY) { minY = point.getY(); h = ShapeFactory.createShape(n.getShape()).getBounds().getHeight() / 2; } if (point.getY() > maxY) { maxY = point.getY(); } } final double graphWidth = (maxX - minX) + 2 * w;///slaveViewTransformer.getScale(); final double graphHeight = (maxY - minY) + 2 * h;///slaveViewTransformer.getScale(); final double slaveWidth = vv2.getBounds().getWidth() / slaveViewTransformer.getScale(); final double slaveHeight = vv2.getBounds().getHeight() / slaveViewTransformer.getScale(); final double scale1 = (slaveWidth / graphWidth); final double scale2 = (slaveHeight / graphHeight); final float scale = (float) (Math.min(scale1, scale2)); //to avoid round error if (scale < slaveLayoutTransformer.getScale()) { slaveLayoutTransformer.setToIdentity(); final Point2D graphCenter = GraphUtil.getCenter( new HashSet<CNode>(vv.getGraphLayout().getGraph().getVertices()), vv.getModel().getGraphLayout()); //System.out.println("Scaling from center : " + graphCenter +"->" + slaveViewTransformer.transform(graphCenter)); slaveLayoutTransformer.scale(scale, scale, slaveViewTransformer.transform(graphCenter)); //System.out.println("Graph center : " + graphCenter); //slaveLayoutTransformer.setTranslate(slaveWidth/2-graphCenter.getX()/2,slaveHeight/2-graphCenter.getY()/2); } else { final double tx = slaveLayoutTransformer.getTranslateX(); final double ty = slaveLayoutTransformer.getTranslateY(); if (minX < tx) { slaveLayoutTransformer.translate(-minX - tx + w, 0); } else if (slaveWidth < maxX) { slaveLayoutTransformer.translate(slaveWidth - maxX - tx - w, 0); } if (minY < ty) { slaveLayoutTransformer.translate(0, -minY - ty + h); } else if (slaveHeight < maxY) { slaveLayoutTransformer.translate(0, slaveHeight - maxY - ty - h); } } }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
@Override public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) { // to ensure that the path is created in the right direction, we have to create // it by combining single lines instead of creating a simple rectangle linePath.moveTo((float) p0.getX(), (float) p0.getY()); linePath.lineTo((float) p1.getX(), (float) p1.getY()); linePath.lineTo((float) p2.getX(), (float) p2.getY()); linePath.lineTo((float) p3.getX(), (float) p3.getY()); // close the subpath instead of adding the last line so that a possible set line // cap style isn't taken into account at the "beginning" of the rectangle linePath.closePath();/*from w w w .j av a 2 s . co m*/ }
From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java
@Override protected void paintLayer(Graphics2D g2, JXLayer<? extends V> layer) { super.paintLayer(g2, layer); if (this.mainTraceInfo.getPoint() == null) { return;//from ww w. ja v a 2 s . co m } final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(COLOR_BLUE); final int BALL_RADIUS = 8; g2.fillOval((int) (this.mainTraceInfo.getPoint().getX() - (BALL_RADIUS >> 1) + 0.5), (int) (this.mainTraceInfo.getPoint().getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS); for (TraceInfo indicatorTraceInfo : this.indicatorTraceInfos) { final Point2D point = indicatorTraceInfo.getPoint(); if (null == point) { continue; } g2.fillOval((int) (point.getX() - (BALL_RADIUS >> 1) + 0.5), (int) (point.getY() - (BALL_RADIUS >> 1) + 0.5), BALL_RADIUS, BALL_RADIUS); } g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); this.drawInformationBox(g2, layer); }
From source file:org.jcurl.core.swing.RockEditDisplay.java
protected void paintSpeed(final Graphics2D g2, final int idx) { if (idx < 0) return;// ww w . j a va 2 s. co m final Point2D cwc = getPos().getRock(idx); final Point2D cdc = wc2dc(cwc, null); // prepare a direction beam (line) 5 Meters long from cwc final Point2D dir_dc; final Point2D normwc; final double vwc_abs; { Point2D norm = speed.getRock(idx); vwc_abs = MathVec.abs2D(norm); if (vwc_abs == 0.0) normwc = new Point2D.Double(0, -1); else normwc = MathVec.mult(1.0 / vwc_abs, norm, null); norm = MathVec.mult(5, normwc, null); MathVec.add(cwc, norm, norm); wc2dc(norm, norm); dir_dc = norm; } // prepare a perpendicular line for the "strength" final Point2D abs1_dc; final Point2D abs2_dc; final Point2D spotWc; { final double len = 0.5; spotWc = getSpeedSpotWC(idx, null); // get a perpendicular abs2_dc = new Point2D.Double(-normwc.getY(), normwc.getX()); MathVec.mult(len, abs2_dc, abs2_dc); abs1_dc = MathVec.add(spotWc, abs2_dc, null); MathVec.mult(-1, abs2_dc, abs2_dc); MathVec.add(spotWc, abs2_dc, abs2_dc); wc2dc(abs1_dc, abs1_dc); wc2dc(abs2_dc, abs2_dc); } lineDC(g2, cdc, dir_dc); lineDC(g2, abs1_dc, abs2_dc); // circle at the hot "spot" for changing speed circleDC(g2, wc2dc(spotWc, null), hotRadiusDC); }