graphics.setPaint(fillPaint); Rectangle2D cellAnc = tc.getAnchor(); graphics.fill(cellAnc); continue; graphics.setStroke(getStroke(stroke)); Paint linePaint = drawPaint.getPaint(graphics, stroke.getPaint()); graphics.setPaint(linePaint); double x=cellAnc.getX(), y=cellAnc.getY(), w=cellAnc.getWidth(), h=cellAnc.getHeight(); Line2D line; switch (edge) { default: case bottom: line = new Line2D.Double(x-borderSize, y+h, x+w+borderSize, y+h); break; case left: line = new Line2D.Double(x, y, x, y+h+borderSize); break; case right: line = new Line2D.Double(x+w, y, x+w, y+h+borderSize); break; case top: line = new Line2D.Double(x-borderSize, y, x+w+borderSize, y); break;
double[] coords = new double[6]; double[] pos = new double[2]; Line2D.Double l = new Line2D.Double(); while (!it.isDone()) { int type = it.currentSegment(coords); break; case PathIterator.SEG_LINETO: l = new Line2D.Double(pos[0], pos[1], coords[0], coords[1]); if (line.intersectsLine(l)) { return getLinesIntersection(line, l);
pieBounds.getX() + pieBounds.getWidth() / 2 - annotationRectangle.getWidth() / 2; double yCenter = pieBounds.getY() + pieBounds.getHeight() / 2 + annotationRectangle.getHeight() / 2; g.setColor(pieStyler.getChartFontColor()); g.setFont(pieStyler.getAnnotationsFont()); AffineTransform orig = g.getTransform(); AffineTransform at = new AffineTransform(); g.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); Shape line = new Line2D.Double(xOffsetStart, yOffsetStart, xOffsetEnd, yOffsetEnd); g.draw(line);
gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gr.setColor(Color.WHITE); gr.fillRect(0, 0, image.getWidth(), image.getHeight()); gr.setColor(Color.LIGHT_GRAY); gr.setStroke(new BasicStroke(1, 0, 0, 1, new float[] {5, 5}, 0)); gr.draw(new Line2D.Double(0, 300, 600, 300)); gr.draw(new Line2D.Double(300, 0, 300, 600)); gr.dispose(); JFrame frame = new JFrame(title); frame.setContentPane(new JLabel(new ImageIcon(image))); frame.pack(); frame.setVisible(true);
Floor2 mainPanel = new Floor2(w, h, gridDiv); JFrame frame = new JFrame("Floor2"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationRelativeTo(null); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(LINE_COLOR); for (List<Ellipse2D> ellipses : ellipseList) { Point2D p2d1 = new Point2D.Double(ellipses.get(0).getCenterX(), ellipses.get(0).getCenterY()); Point2D p2d2 = new Point2D.Double(ellipses.get(1).getCenterX(), ellipses.get(1).getCenterY()); Line2D line = new Line2D.Double(p2d1, p2d2); g2.draw(line); g.drawImage(bufImage, 0, 0, this); g2.setStroke(initStroke); return; drawingLine = new Line2D.Double(p1, e.getPoint()); repaint();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g2d.setBackground(Color.BLACK); g2d.setColor(color[currShape]); case 1: g2d.fill(new Rectangle2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE)); break; case 2: g2d.setStroke(lineStroke); g2d.draw(new Line2D.Double(currX,currY,currX+SHAPE_SIZE,currY+SHAPE_SIZE)); break; default: break; case 1: g2d.fill(new Rectangle2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE)); break; case 2: case 3: g2d.setStroke(lineStroke); g2d.draw(new Line2D.Double(distractorX,distractorY,distractorX+SHAPE_SIZE,distractorY+SHAPE_SIZE)); break; default:
int y2 = getHeight(); Line2D line = new Line2D.Double(x1, y1, x2, y2); Rectangle2D rect = new Rectangle2D.Double(x, y, width, height); Graphics2D g2d = (Graphics2D) g.create(); g2d.draw(rect); g2d.draw(line); g2d.dispose(); new Line2D.Double( rectangle.getX(), rectangle.getY(), new Line2D.Double( rectangle.getX(), rectangle.getY() + rectangle.getHeight(), new Line2D.Double( rectangle.getX(), rectangle.getY(), new Line2D.Double( rectangle.getX() + rectangle.getWidth(), rectangle.getY(),
Graphics2D g = (Graphics2D) image.getGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.WHITE); g.fillRect(0, 0, 400, 400); g.setColor(Color.BLACK); g.setStroke(new BasicStroke(2)); for (int i=0; i<400; i+=5) g.setColor(Color.BLACK); g.draw(new Line2D.Double(-100, dy+i, 90, i)); g.draw(new Line2D.Double(200+-100, dy+i, 200+90, i));
Rectangle clipBounds = g.getClipBounds(); double annotationWidth = annotationBounds.getWidth(); double annotationHeight = annotationBounds.getHeight(); double xOffset = xCenter + cos * xDiameter; double yOffset = yCenter - sin * yDiameter; Line2D.Double line = new Line2D.Double(xCenter, yCenter, xOffset, yOffset); g.setColor(styler.getPlotGridLinesColor()); g.setStroke(styler.getPlotGridLinesStroke()); g.draw(line);
import javax.swing.*; import java.awt.*; import java.awt.geom.*; public class X { public static void main( String [] args ) { JFrame frame = new JFrame(); frame.add( new JPanel() { public void paintComponent( Graphics g ) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; Line2D line = new Line2D.Double(10, 10, 40, 40); g2.setColor(Color.blue); g2.setStroke(new BasicStroke(10)); g2.draw(line); } }); frame.setVisible( true ); } }
final JFrame frame = new JFrame("Test"); frame.add(new JComponent() { @Override protected void paintComponent(Graphics g) { System.out.println(g2d.getTransform()); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g2d.draw(new Line2D.Double( (dia / 2) + Math.cos(angle) * dia / 2.1d, (dia / 2) + Math.sin(angle) * dia / 2.1d, frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setVisible(true);
lastY = y + coord[1]; } else if (type == USegmentType.SEG_LINETO) { final Shape line = new Line2D.Double(lastX, lastY, x + coord[0], y + coord[1]); drawShadow(g2d, line, shape.getDeltaShadow(), dpiFactor); lastX = x + coord[0]; (float) minMax.getMaxX(), (float) minMax.getMaxY(), mapper.getMappedColor(gr.getColor2())); g2d.setPaint(paint); g2d.fill(p); } else if (back != null) { g2d.setColor(mapper.getMappedColor(back)); g2d.fill(p);
/** * 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); }
double starty = yOffset + chart.getStyler().getLegendPadding(); Object oldHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(series.getLineColor()); g.setStroke(series.getLineStyle()); Shape line = new Line2D.Double( startx, starty + legendEntryHeight / 2.0, Shape rectSmall = new Rectangle2D.Double(startx, starty, BOX_SIZE, BOX_SIZE); g.setColor(series.getFillColor()); g.fill(rectSmall);
Color curColor = g2.getColor(); g2.setColor(paintColor); g2.drawString(nodeStr, (float) (nodeTab + start.getX()), (float) (start.getY() + nodeAscent)); g2.setColor(curColor); double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip); double layerHeight = nodeHeight * layerMultiplier; if (t.isLeaf()) { yieldOffsets[leafCtr++] = (float) (nodeTab + start.getX()); return nodeWidth; g2.draw(new Line2D.Double(lineStartX, lineStartY, lineEndX, lineEndY)); childStartX += cWidth; if (i < t.children().length - 1) {
/** * 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 drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double xx = getDomainAxis().valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); }
Rectangle2D r1 = getBounds(); int margin = 50; Rectangle2D r2 = new Rectangle2D.Double( r1.getMinX()+margin, r1.getMinY()+margin, r1.getHeight()-2*margin); g2d.setColor(Color.YELLOW); g2d.fill(r1); g2d.clip(p); g2d.setColor(Color.BLACK); for (double d = 0; d < r1.getWidth() + r1.getHeight(); d += spacing) Line2D line = new Line2D.Double(0, d, d, 0); g2d.draw(line); clipper.setPreferredSize(new Dimension(300, 200)); JFrame frame = new JFrame("HoleClipper"); frame.setContentPane(clipper); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
/** * Draws the pointer. * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame. * @param view the dial's view. */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setPaint(this.paint); g2.setStroke(this.stroke); Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.radius, this.radius); double value = plot.getValue(this.datasetIndex); DialScale scale = plot.getScaleForDataset(this.datasetIndex); double angle = scale.valueToAngle(value); Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN); Point2D pt = arc.getEndPoint(); Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt.getX(), pt.getY()); g2.draw(line); }
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray); for (int y = 0; y <= 300; y += 30) { g2.draw(new Line2D.Double(0, y, 300, y)); JFrame f = new JFrame("Line"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { f.getContentPane().add("Center", applet); applet.init(); f.pack();
/** * 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} not permitted). * @param paint the line paint ({@code null} 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); }