/** * Draws the needle. * * @param g2 the graphics device. * @param plotArea the plot area. * @param rotate the rotation point. * @param angle the angle. */ protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) { Line2D shape = new Line2D.Double(); double x = plotArea.getMinX() + (plotArea.getWidth() / 2); shape.setLine(x, plotArea.getMinY(), x, plotArea.getMaxY()); Shape s = shape; if ((rotate != null) && (angle != 0)) { /// we have rotation getTransform().setToRotation(angle, rotate.getX(), rotate.getY()); s = getTransform().createTransformedShape(s); } defaultDisplay(g2, s); }
/** * Utility method for drawing a horizontal line across the data area of the plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getRangeAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getDomainAxis(); } if (axis.getRange().contains(value)) { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
/** * Draws a vertical line used to trace the mouse position to the horizontal axis. * * @param x the x-coordinate of the trace line. */ private void drawHorizontalAxisTrace(int x) { Graphics2D g2 = (Graphics2D) getGraphics(); Rectangle2D dataArea = getScaledDataArea(); g2.setXORMode(java.awt.Color.orange); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { if (this.verticalTraceLine != null) { g2.draw(this.verticalTraceLine); this.verticalTraceLine.setLine( x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY() ); } else { this.verticalTraceLine = new Line2D.Float( x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY() ); } g2.draw(this.verticalTraceLine); } }
/** * Adds or removes a control point on a specified location * @param widget the connection widget * @param localLocation the local location */ private void addRemoveControlPoint (ConnectionWidget widget, Point localLocation) { ArrayList<Point> list = new ArrayList<Point> (widget.getControlPoints ()); if (!removeControlPoint (localLocation, list, deleteSensitivity)) { Point exPoint = null; int index = 0; for (Point elem : list) { if (exPoint != null) { Line2D l2d = new Line2D.Double (exPoint, elem); if (l2d.ptSegDist (localLocation) < createSensitivity) { list.add (index, localLocation); break; } } exPoint = elem; index++; } } if (routingPolicy != null) widget.setRoutingPolicy (routingPolicy); widget.setControlPoints (list, false); }
/** * * @param line1 * @param line2 * @return */ public static boolean isParallel(Line2D line1, Line2D line2) { float x1 = (float) line1.getX1(); float y1 = (float) line1.getY1(); float x2 = (float) line1.getX2(); float y2 = (float) line1.getY2(); float dx = x2 - x1; float dy = y1 - y2; float d = (float) Math.sqrt((double) (dx * dx + dy * dy)); float slope1 = Math.abs(dx / d); x1 = (float) line2.getX1(); y1 = (float) line2.getY1(); x2 = (float) line2.getX2(); y2 = (float) line2.getY2(); dx = x2 - x1; dy = y1 - y2; d = (float) Math.sqrt((double) (dx * dx + dy * dy)); float slope2 = Math.abs(dx / d); return (slope1 == slope2); }
/** * Returns whether a specified local location is a part of the connection widget. It checks whether the location is * close to the control-points-based path (up to 4px from the line), * close to the anchors (defined by AnchorShape) or * close to the control points (PointShape). * @param localLocation the local locaytion * @return true, if the location is a part of the connection widget */ public boolean isHitAt (Point localLocation) { if (! super.isHitAt (localLocation)) return false; List<Point> controlPoints = getControlPoints (); for (int i = 0; i < controlPoints.size () - 1; i++) { Point point1 = controlPoints.get (i); Point point2 = controlPoints.get (i + 1); double dist = Line2D.ptSegDistSq (point1.x, point1.y, point2.x, point2.y, localLocation.x, localLocation.y); if (dist < HIT_DISTANCE_SQUARE) return true; } return getControlPointHitAt (localLocation) >= 0; }
/** * Draws a horizontal line used to trace the mouse position to the vertical axis. * * @param g2 * the graphics device. * @param y * the y-coordinate of the trace line. */ private void drawVerticalAxisTrace(Graphics2D g2, int y) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if ((int) dataArea.getMinY() < y && y < (int) dataArea.getMaxY()) { if (this.horizontalTraceLine != null) { g2.draw(this.horizontalTraceLine); this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } else { this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } g2.draw(this.horizontalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
/** * Utility method for drawing a line perpendicular to the range axis (used * for crosshairs). * * @param g2 the graphics device. * @param dataArea the area defined by the axes. * @param value the data value. * @param stroke the line stroke (<code>null</code> not permitted). * @param paint the line paint (<code>null</code> not permitted). */ protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double java2D = getRangeAxis().valueToJava2D(value, dataArea, getRangeAxisEdge()); Line2D line = null; if (this.orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, dataArea.getMaxY()); } else if (this.orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), java2D, dataArea.getMaxX(), java2D); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
/** * Draws an axis line at the current cursor position and edge. * * @param g2 the graphics device. * @param cursor the cursor position. * @param dataArea the data area. * @param edge the edge. */ protected void drawAxisLine(Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge) { Line2D axisLine = null; if (edge == RectangleEdge.TOP) { axisLine = new Line2D.Double(dataArea.getX(), cursor, dataArea.getMaxX(), cursor); } else if (edge == RectangleEdge.BOTTOM) { axisLine = new Line2D.Double(dataArea.getX(), cursor, dataArea.getMaxX(), cursor); } else if (edge == RectangleEdge.LEFT) { axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getMaxY()); } else if (edge == RectangleEdge.RIGHT) { axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getMaxY()); } g2.setPaint(this.axisLinePaint); g2.setStroke(this.axisLineStroke); g2.draw(axisLine); }
/** * Draws a section label on the left side of the pie chart. * * @param g2 the graphics device. * @param state the state. * @param record the label record. */ protected void drawLeftLabel(Graphics2D g2, PiePlotState state, PieLabelRecord record) { double theta = record.getAngle(); double linkX = state.getPieCenterX() + Math.cos(theta) * state.getPieWRadius() * record.getLinkPercent(); double linkY = state.getPieCenterY() - Math.sin(theta) * state.getPieHRadius() * record.getLinkPercent(); double elbowX = state.getPieCenterX() + Math.cos(theta) * state.getLinkArea().getWidth() / 2.0; double elbowY = state.getPieCenterY() - Math.sin(theta) * state.getLinkArea().getHeight() / 2.0; double anchorX = state.getLinkArea().getMinX(); double anchorY = elbowY; double targetX = anchorX - record.getGap(); double targetY = record.getAllocatedY(); g2.setPaint(this.labelLinkPaint); g2.setStroke(this.labelLinkStroke); g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY)); g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY)); g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY)); TextBox tb = record.getLabel(); tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT); }
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) { // draw the domain grid lines, if the flag says they're visible... if (isDomainGridlinesVisible()) { Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); double v = this.domainAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); g2.setPaint(getDomainGridlinePaint()); g2.setStroke(getDomainGridlineStroke()); g2.draw(line); } } }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { LegendItemCollection c1 = new LegendItemCollection(); LegendItemCollection c2 = new LegendItemCollection(); assertTrue(c1.equals(c2)); assertTrue(c2.equals(c1)); LegendItem item1 = new LegendItem("Label", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red, true, Color.blue, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); LegendItem item2 = new LegendItem("Label", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red, true, Color.blue, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); c1.add(item1); c2.add(item2); assertTrue(c1.equals(c2)); }
/** * Utility method for drawing a line perpendicular to the range axis (used for crosshairs). * * @param g2 the graphics device. * @param dataArea the area defined by the axes. * @param value the data value. * @param stroke the line stroke. * @param paint the line paint. */ protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double java2D = getRangeAxis().valueToJava2D(value, dataArea, getRangeAxisEdge()); Line2D line = null; if (this.orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, dataArea.getMaxY()); } else if (this.orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), java2D, dataArea.getMaxX(), java2D); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
public void paint(Graphics g) { Dimension d = this.getSize(); super.paint(g); // fixes the immediate problem. Graphics2D g2 = (Graphics2D) g; horizontalLine1 = new Line2D.Float(45, d.height-290, d.width - 45, d.height-290); verticalLine1 = new Line2D.Float(d.width/3+10, 100 , d.width/3+10, d.height - 325); verticalLine2 = new Line2D.Float((2*d.width)/3-10, 100 , (2*d.width)/3-10, d.height - 325); verticalLine3 = new Line2D.Float(d.width/3+10, 350 , d.width/3+10, d.height - 50); verticalLine4 = new Line2D.Float((2*d.width)/3-10, 350 , (2*d.width)/3-10, d.height - 50); //System.out.println("Height: "+d.height+"\tWidth: "+d.width); // (45, 267, 129, 20) //g2.setColor(Color.DARK_GRAY); g2.draw(horizontalLine1); g2.draw(verticalLine1); g2.draw(verticalLine2); g2.draw(verticalLine3); g2.draw(verticalLine4); }
/** * Draws a sequence of connected lines defined by * arrays of <i>x</i> and <i>y</i> coordinates. * Each pair of (<i>x</i>, <i>y</i>) coordinates defines a point. * The figure is not closed if the first point * differs from the last point. * @param xPoints an array of <i>x</i> points * @param yPoints an array of <i>y</i> points * @param nPoints the total number of points * @see java.awt.Graphics#drawPolygon(int[], int[], int) * @since JDK1.1 */ public void drawPolyline(int xPoints[], int yPoints[], int nPoints) { float fromX; float fromY; float toX; float toY; if (nPoints > 0) { fromX = xPoints[0]; fromY = yPoints[0]; for(int i = 1; i < nPoints; i++) { toX = xPoints[i]; toY = yPoints[i]; draw(new Line2D.Float(fromX, fromY, toX, toY)); fromX = toX; fromY = toY; } } }
Shape getUnderlineShape(float thickness, float x1, float x2, float y) { GeneralPath gp = new GeneralPath(); Line2D.Float line = new Line2D.Float(x1, y, x2, y); gp.append(stroke.createStrokedShape(line), false); line.y1 += DEFAULT_THICKNESS; line.y2 += DEFAULT_THICKNESS; line.x1 += DEFAULT_THICKNESS; gp.append(stroke.createStrokedShape(line), false); return gp; }
/** * Utility method for drawing a horizontal line across the data area of the * plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getRangeAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getDomainAxis(); } if (axis.getRange().contains(value)) { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } }
@Override public void paint(Graphics2D g, Bounds aBounds, Diagram diagram) { QBounds bounds = (QBounds) aBounds; label.setLocation(0, 0); Dimension size = new Dimension((int) bounds.getSize().getWidth() - 4, (int) bounds.getSize().getHeight()); label.setPreferredSize(size); label.setSize(label.getPreferredSize()); g.setColor(Color.black); Line2D line = new Line2D.Double(8, getMinHeight(), getMinWidth() - 16, getMinHeight()); Stroke stroke = g.getStroke(); g.setStroke(this.stroke); g.draw(line); g.setStroke(stroke); paintText(g); }
void drawUnderline(Graphics2D g2d, float thickness, float x1, float x2, float y) { Stroke saveStroke = g2d.getStroke(); g2d.setStroke(stroke); Line2D.Float drawLine = new Line2D.Float(x1, y, x2, y); g2d.draw(drawLine); drawLine.y1 += DEFAULT_THICKNESS; drawLine.y2 += DEFAULT_THICKNESS; drawLine.x1 += DEFAULT_THICKNESS; g2d.draw(drawLine); g2d.setStroke(saveStroke); }
private static void paintTilda(final Graphics2D g, final double x1, final double y1, final double x2, final double y2, MovingArea movingArea) { final int tWidth = movingArea.getIntOrdinate(TILDA_WIDTH); final double bx = (x1 + x2) / 2; final double by = (y1 + y2) / 2; double dy = y2 - y1; double dx = x2 - x1; final double len = Math.sqrt(dx * dx + dy * dy); if (len <= 0.2) return; dx = dx / len * tWidth; dy = dy / len * tWidth; final double nx1 = bx + dy; final double ny1 = by - dx; final double nx2 = bx - dy; final double ny2 = by + dx; g.draw(new Line2D.Double(x1, y1, nx1, ny1)); g.draw(new Line2D.Double(nx1, ny1, nx2, ny2)); g.draw(new Line2D.Double(nx2, ny2, x2, y2)); }
void dragEdge(MouseEvent e) { if( e.isControlDown() )return; if( !(xy instanceof ScalableXYPoints) )return; if( cursor==0 )return; drawLine(); int[] wesn = getWESN(); Rectangle r = getVisibleRect(); Point p = e.getPoint(); if( cursor>=10 ) { if( cursor==10 ) { if(p.x>wesn[1]-2) p.x=wesn[1]-2; } else { if(p.x<wesn[0]+2) p.x=wesn[0]+2; } line = new Line2D.Double(p.x, r.y, p.x, r.y+r.height); } else { line = new Line2D.Double(r.x, p.y, r.x+r.width, p.y); } drawLine(); }
@Override public Point2D collides(final Line2D rayCast) { final Point2D rayCastSource = new Point2D.Double(rayCast.getX1(), rayCast.getY1()); final List<Rectangle2D> collBoxes = this.getAllCollisionBoxes(); collBoxes.sort((rect1, rect2) -> { final Point2D rect1Center = new Point2D.Double(rect1.getCenterX(), rect1.getCenterY()); final Point2D rect2Center = new Point2D.Double(rect2.getCenterX(), rect2.getCenterY()); final double dist1 = rect1Center.distance(rayCastSource); final double dist2 = rect2Center.distance(rayCastSource); if (dist1 < dist2) { return -1; } if (dist1 > dist2) { return 1; } return 0; }); for (final Rectangle2D collisionBox : collBoxes) { if (collisionBox.intersectsLine(rayCast)) { double closestDist = -1; Point2D closestPoint = null; for (final Point2D intersection : GeometricUtilities.getIntersectionPoints(rayCast, collisionBox)) { final double dist = intersection.distance(rayCastSource); if (closestPoint == null || dist < closestDist) { closestPoint = intersection; closestDist = dist; } } return closestPoint; } } return null; }
public void draw(SunGraphics2D sg2d, Shape s) { if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) { BasicStroke bs = ((BasicStroke) sg2d.stroke); if (s instanceof Rectangle2D) { if (bs.getLineJoin() == BasicStroke.JOIN_MITER && bs.getDashArray() == null) { Rectangle2D r2d = (Rectangle2D) s; double w = r2d.getWidth(); double h = r2d.getHeight(); double x = r2d.getX(); double y = r2d.getY(); if (w >= 0 && h >= 0) { double lw = bs.getLineWidth(); drawRectangle(sg2d, x, y, w, h, lw); } return; } } else if (s instanceof Line2D) { Line2D l2d = (Line2D) s; if (drawGeneralLine(sg2d, l2d.getX1(), l2d.getY1(), l2d.getX2(), l2d.getY2())) { return; } } } outpipe.draw(sg2d, s); }
/** * Utility method for drawing a crosshair on the chart (if required). * * @param g2 The graphics device. * @param dataArea The data area. * @param value The coordinate, where to draw the line. * @param stroke The stroke to use. * @param paint The paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double yy = getRangeAxis().valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
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); }
public Snakelet(int index, int point1, int point2, int ts){ idx = index; i1 = point1; i2 = point2; line = new Line2D.Float(); on = false; type = -1; timestamp = ts; }
Shape getUnderlineShape(float thickness, float x1, float x2, float y) { Stroke ulStroke = getStroke(thickness); Line2D line = new Line2D.Float(x1, y + shift, x2, y + shift); return ulStroke.createStrokedShape(line); }
/** * Draws a line perpendicular to the range axis. * * @param g2 the graphics device. * @param plot the plot. * @param axis the value axis. * @param dataArea the area for plotting data (not yet adjusted for any 3D * effect). * @param value the value at which the grid line should be drawn. * @param paint the paint. * @param stroke the stroke. */ public void drawRangeLine(Graphics2D g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double value, Paint paint, Stroke stroke) { Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); Line2D line = null; double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } g2.setPaint(paint); g2.setStroke(stroke); g2.draw(line); }
/** * */ public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Stroke stroke = g2.getStroke(); g2.setStroke(getSelectionStroke()); g.setColor(getSelectionColor()); Point last = state.getAbsolutePoint(0).getPoint(); for (int i = 1; i < state.getAbsolutePointCount(); i++) { Point current = state.getAbsolutePoint(i).getPoint(); Line2D line = new Line2D.Float(last.x, last.y, current.x, current.y); Rectangle bounds = g2.getStroke().createStrokedShape(line) .getBounds(); if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) { g2.draw(line); } last = current; } g2.setStroke(stroke); super.paint(g); }
private void setupDropLine( DropTargetDragEvent dtde, CategoryList list, int dropIndex ) { boolean verticalDropBar = list.getColumnCount() > 1; Rectangle rect = list.getCellBounds( dropIndex, dropIndex ); if( verticalDropBar ) dropBefore = dtde.getLocation().x < (rect.x + rect.width/2); else dropBefore = dtde.getLocation().y < (rect.y + rect.height/2); Point p1 = rect.getLocation(); Point p2 = rect.getLocation(); if( verticalDropBar ) { p2.y += rect.height; if( !dropBefore ) { p1.x += rect.width; p2.x += rect.width; } } else { p2.x += rect.width; if( !dropBefore ) { p1.y += rect.height; p2.y += rect.height; } } p1 = SwingUtilities.convertPoint( list, p1, palette.getRootPane() ); p2 = SwingUtilities.convertPoint( list, p2, palette.getRootPane() ); Line2D line = new Line2D.Double( p1.x, p1.y, p2.x, p2.y ); dropPane.setDropLine( line ); targetItem = (Item)list.getModel().getElementAt( dropIndex ); }
/** * Draws the border by filling in the reserved space (in black). * * @param g2 the graphics device. * @param area the area. */ public void draw(Graphics2D g2, Rectangle2D area) { double w = area.getWidth(); double h = area.getHeight(); double t = this.insets.calculateTopInset(h); double b = this.insets.calculateBottomInset(h); double l = this.insets.calculateLeftInset(w); double r = this.insets.calculateRightInset(w); double x = area.getX(); double y = area.getY(); double x0 = x + l / 2.0; double x1 = x + w - r / 2.0; double y0 = y + h - b / 2.0; double y1 = y + t / 2.0; g2.setPaint(getPaint()); g2.setStroke(getStroke()); Line2D line = new Line2D.Double(); if (t > 0.0) { line.setLine(x0, y1, x1, y1); g2.draw(line); } if (b > 0.0) { line.setLine(x0, y0, x1, y0); g2.draw(line); } if (l > 0.0) { line.setLine(x0, y0, x0, y1); g2.draw(line); } if (r > 0.0) { line.setLine(x1, y0, x1, y1); g2.draw(line); } }
private void drawSlowPans(Graphics2D g2d, double downsampleFactor, Rectangle clippingRectangle) { g2d.setStroke(new BasicStroke((float)boundsThicknessScalar.get() * ((downsampleFactor > 1) ? (float) downsampleFactor : 1))); g2d.setColor(Color.BLUE); TrackerFeatureList slowPans = trackerFeatures.getBoundsFeatures().getSlowPans(); for (TrackerFeature slowPan : slowPans) { Rectangle startRect = slowPan.getFrameAtFeatureIndex(0).getImageBounds(); Rectangle endRect = slowPan.getFrameAtFeatureIndex(slowPan.size() - 1).getImageBounds(); g2d.setColor(TrackerUtils.colorFXtoAWT( (javafx.scene.paint.Color)zoomPeakStartColorProperty.get())); if (startRect.intersects(clippingRectangle)) g2d.draw(startRect); g2d.setColor(TrackerUtils.colorFXtoAWT( (javafx.scene.paint.Color)zoomPeakEndColorProperty.get())); if (endRect.intersects(clippingRectangle)) g2d.draw(endRect); g2d.setStroke(new BasicStroke((float)boundsThicknessScalar.get() * ((downsampleFactor > 1) ? (float) downsampleFactor : 1))); g2d.setColor(TrackerUtils.colorFXtoAWT( (javafx.scene.paint.Color)zoomPeakPathColorProperty.get())); for (Line2D line : makeSlowPanLines(startRect, endRect)) { if (line.intersects(clippingRectangle)) { g2d.draw(line); } } } }
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2d = (Graphics2D)g; Shape s; if(topColor != null) { s = new Line2D.Double(x,y,x+width, y); g2d.setColor(topColor); g2d.fill(s); } if(leftColor != null) { s = new Line2D.Double(x,y,x, y+height); g2d.setColor(leftColor); g2d.fill(s); } if(bottomColor != null) { s = new Line2D.Double(x,y+height-1,x+width, y+height-1); g2d.setColor(bottomColor); g2d.fill(s); } if(rightColor != null) { s = new Line2D.Double(x+width-1,y,x+width-1, y+height); g2d.setColor(rightColor); g2d.fill(s); } }
void drag(MouseEvent e) { if (p0==null) { begin(e); return; } drawLine(); Point2D p = map.getScaledPoint(e.getPoint()); currentLine = new Line2D.Double(map.getScaledPoint(p0), p); Point2D[] pts = getPath(currentLine, 5); currentPath = getGeneralPath(pts); drawLine(); java.text.NumberFormat fmt = java.text.NumberFormat.getInstance(); fmt.setMaximumFractionDigits(2); map.setXY(e.getPoint()); map.getMapTools().setInfoText( map.getMapTools().getInfoText() + ", distance = " + fmt.format(distance(pts)) +" km"); }
public void paint(Graphics gr) { super.paint(gr); if (stroke == null) return; final Graphics2D g = (Graphics2D) gr; g.setColor(getForeground()); g.setStroke(stroke); g.draw(new Line2D.Double(0, (double) getHeight() / 2, getWidth(), (double) getHeight() / 2)); }
public mxPoint paintMarker(mxGraphics2DCanvas canvas, mxCellState state, String type, mxPoint pe, double nx, double ny, double size, boolean source) { canvas.getGraphics() .draw(new Line2D.Float((int) Math.round(pe.getX() - nx - ny / 2), (int) Math.round(pe.getY() - ny + nx / 2), (int) Math.round(pe.getX() - nx / 6), (int) Math.round(pe.getY() - ny / 6))); canvas.getGraphics() .draw(new Line2D.Float((int) Math.round(pe.getX() - nx / 6), (int) Math.round(pe.getY() - ny / 6), (int) Math.round(pe.getX() + ny / 2 - nx), (int) Math.round(pe.getY() - ny - nx / 2))); return new mxPoint(-nx / 2, -ny / 2); }
private void drawHorizontalTic(Graphics2D g, int ticNumber, double yTicSize, double ticDifference, int pixWidth, int pixHeight, DecimalFormat format) { g.setColor(GRID_COLOR); double yValue = this.globalMax - ticNumber * yTicSize; double yPos = ticNumber * ticDifference; g.draw(new Line2D.Double(0, yPos, pixWidth, yPos)); g.setColor(Color.black); String label = format.format(yValue) + " "; Rectangle2D stringBounds = LABEL_FONT.getStringBounds(label, g.getFontRenderContext()); g.drawString(label, (float) -stringBounds.getWidth(), (float) (yPos - stringBounds.getHeight() / 2 - stringBounds.getY())); }
/** * Draws a grid line against the range axis. * * @param g2 the graphics device. * @param plot the plot. * @param axis the value axis. * @param dataArea the area for plotting data (not yet adjusted for any 3D effect). * @param value the value at which the grid line should be drawn. * */ public void drawRangeGridLine(Graphics2D g2, XYPlot plot, ValueAxis axis, Rectangle2D dataArea, double value) { Range range = axis.getRange(); if (!range.contains(value)) { return; } PlotOrientation orientation = plot.getOrientation(); Line2D line = null; double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); } Paint paint = plot.getRangeGridlinePaint(); Stroke stroke = plot.getRangeGridlineStroke(); g2.setPaint(paint != null ? paint : Plot.DEFAULT_OUTLINE_PAINT); g2.setStroke(stroke != null ? stroke : Plot.DEFAULT_OUTLINE_STROKE); g2.draw(line); }
private void drawVerticalTic(Graphics2D g, int ticNumber, DecimalFormat format, double dx, double dy, double sx, double sy) { double x = ticNumber * xTicSize + minX; g.setColor(GRID_COLOR); g.draw(new Line2D.Double((x + dx) * sx, (minY + dy) * sy, (x + dx) * sx, (maxY + dy) * sy)); g.setColor(Color.black); }
private void drawOccupiedPercentage2(Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) { //processor.setFrame(x+PROC_RAD/2 , y + cpu*PROC_RAD, 2 * PROC_RAD /2, 2 * PROC_RAD /2); // if (remainingTime[cpu] != 0) { double x = getProcessorXY().x, y = getProcessorXY().y; occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, 2 * PROC_RAD / 2, 2 * PROC_RAD * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2); occupiedEll = new Ellipse2D.Double(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, 2 * PROC_RAD / 2, 2 * PROC_RAD / 2); if (gradientFill) { GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + 2 * PROC_RAD), startC.darker(), false); g2d.setPaint(gp); } else { g2d.setPaint(startC); } occupiedArea = new Area(occupiedEll); occupiedArea.subtract(new Area(occupiedRect)); g2d.fill(occupiedArea); g2d.setPaint(Color.BLACK); g2d.draw(occupiedArea); // draw orizontal line parallel to occupation Line2D.Double l = new Line2D.Double(x + PROC_RAD * 2 + ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2,//y + PROC_RAD * 2 * (1 - (double) remainingTime / (double) totTime) /2 + ELEMS_GAP * cpu - ELEMS_GAP /2 , x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2);//y + PROC_RAD * 2 * (1 - (double) remainingTime / (double) totTime) /2 + ELEMS_GAP * cpu - ELEMS_GAP /2 ); g2d.draw(l); // draw vertical line l = new Line2D.Double(x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2, x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + PROC_RAD * 2 / 2 + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2); g2d.draw(l); // } }