Java Code Examples for java.awt.Graphics2D.drawPolyline()

The following are Jave code examples for showing how to use drawPolyline() of the java.awt.Graphics2D 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: VISNode   File: JNodeConnection.java   View Source Code Vote up 7 votes
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.translate(-getX(), -getY());
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(Color.BLUE);
    int[] xs = new int[points.length];
    int[] ys = new int[points.length];
    for (int i = 0; i < points.length; i++) {
        xs[i] = points[i].x;
        ys[i] = points[i].y;
    }
    g2d.setColor(UIHelper.getColor("NodeConnection.border"));
    g2d.setStroke(new BasicStroke(3));
    g2d.drawPolyline(xs, ys, points.length);
    g2d.setPaint(new GradientPaint(points[0], UIHelper.getColor("NodeConnection.color1"), points[points.length - 1], UIHelper.getColor("NodeConnection.color2")));
    g2d.setStroke(new BasicStroke(1.5f));
    g2d.drawPolyline(xs, ys, points.length);
    g2d.dispose();
}
 
Example 2
Project: brModelo   File: Linha.java   View Source Code Vote up 6 votes
@Override
public void DoPaint(Graphics2D g) {
    super.DoPaint(g);
    Stroke bkp = g.getStroke();

    g.setPaint(getForeColor());
    if (getPontosParaDesenho() != null) {
        if (isDashed()) {
            g.setStroke(new BasicStroke(getLargura(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1, 2}, 0));
        } else {
            g.setStroke(new BasicStroke(
                    getLargura(),
                    BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND));
        }

        g.drawPolyline(pontosParaDesenhoX, pontosParaDesenhoY, pontosParaDesenhoX.length);
    }
    g.setStroke(bkp);
}
 
Example 3
Project: incubator-netbeans   File: ContinuousXYPainter.java   View Source Code Vote up 5 votes
protected void paint(XYItem item, List<ItemSelection> highlighted,
                     List<ItemSelection> selected, Graphics2D g,
                     Rectangle dirtyArea, SynchronousXYChartContext context) {

    int valuesCount = item.getValuesCount();
    int extraTrailing = fillColor != null ? 2 : 0;

    Rectangle dirtyExtended = new Rectangle(dirtyArea);
    dirtyExtended.x -= lineWidth;
    dirtyExtended.width += lineWidth * 2;
    int[][] idxs = computer.getVisible(dirtyExtended, valuesCount, context, 1,
                                       extraTrailing);
    if (idxs == null) return;
    int[] visibleIndexes = idxs[0];
    int npoints = idxs[1][0];
    int[][] points = computer.createPoints(visibleIndexes, npoints, item,
                                           dataFactor, context);

    if (fillColor != null) {
        points[0][npoints - 2] = points[0][npoints - 3];
        points[1][npoints - 2] = computer.getZeroY(context);
        points[0][npoints - 1] = points[0][0];
        points[1][npoints - 1] = points[1][npoints - 2];

        POLYGON.xpoints = points[0];
        POLYGON.ypoints = points[1];
        POLYGON.npoints = npoints;

        g.setPaint(fillColor);
        g.fill(POLYGON);
    }

    if (lineColor != null) {
        g.setPaint(lineColor);
        g.setStroke(lineStroke);
        g.drawPolyline(points[0], points[1], npoints - extraTrailing);
    }
}
 
Example 4
Project: jdk8u-jdk   File: Test8004821.java   View Source Code Vote up 5 votes
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 5
Project: openjdk-jdk10   File: Test8004821.java   View Source Code Vote up 5 votes
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 6
Project: incubator-netbeans   File: SynchronousXYItemPainter.java   View Source Code Vote up 4 votes
protected void paint(XYItem item, List<ItemSelection> highlighted,
                       List<ItemSelection> selected, Graphics2D g,
                       Rectangle dirtyArea, SynchronousXYChartContext context) {

        if (item.getValuesCount() < 2) return;
        if (context.getViewWidth() == 0 || context.getViewHeight() == 0) return;

        int[][] points = createPoints(item, dirtyArea, context, type, maxValueOffset);
        if (points == null) return;

        int[] xPoints  = points[0];
        int[] yPoints  = points[1];
        int npoints = xPoints.length;

//long start = System.nanoTime();
        if (fillColor != null) {
            int zeroY = Utils.checkedInt(context.getViewY(context.getDataOffsetY()));
            zeroY = Math.max(Utils.checkedInt(context.getViewportOffsetY()), zeroY);
            zeroY = Math.min(Utils.checkedInt(context.getViewportOffsetY() +
                                                      context.getViewportHeight()), zeroY);

            Polygon polygon = new Polygon();
            polygon.xpoints = xPoints;
            polygon.ypoints = yPoints;
            polygon.npoints = npoints;
            polygon.xpoints[npoints - 2] = xPoints[npoints - 3];
            polygon.ypoints[npoints - 2] = zeroY;
            polygon.xpoints[npoints - 1] = xPoints[0];
            polygon.ypoints[npoints - 1] = zeroY;
            g.setPaint(fillColor);
            g.fill(polygon);
        }

        if (lineColor != null) {
            g.setPaint(lineColor);
            g.setStroke(lineStroke);
            g.drawPolyline(xPoints, yPoints, npoints - 2);
        }
//System.err.println(">>> Paint: " + (System.nanoTime() - start) / 1000 + " [ms], dirtyArea: " + dirtyArea);
//        if (type == TYPE_RELATIVE) {
//        g.setColor(Color.RED);
//        Rectangle bbox = new Rectangle(dirtyArea);
////        bbox.width -= 1;
////        bbox.height -= 1;
//            g.draw(bbox);
////            System.err.println(">>> Here");
//        }

//        if (type == TYPE_RELATIVE_BOUNDED) {
//            System.err.println(">>> paintItem, dirtyArea: " + dirtyArea);
//        }
        
    }
 
Example 7
Project: jaer   File: JAERDataViewer.java   View Source Code Vote up 4 votes
private synchronized void drawData(Graphics2D g2) {
    int n;
    int [] x;
    int [] y;
    int length = 0;
    g2.setStroke(new BasicStroke());
      for(Iterator<GraphData> it = currentGraphs.values().iterator(); it.hasNext(); ) {
         GraphData dt = it.next();
         g2.setColor(dt.Color);
         synchronized (dt.Y) {
         
             switch(dt.DataType) {
                 case YScrolling:
                     length = Math.min(this.getWidth(), dt.Y.size());
                     x = new int[length];
                     y = new int[length];
                     int l = dt.Y.size() - length;
                     for(n = 0; n < length;n++ ) {
                         x[n] = n;
                         y[n] = (int)(this.getHeight()- (dt.Y.get(l + n) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
                     }
                     break;

                 case YScaling:
                     length = this.getWidth();
                     x = new int[length];
                     y = new int[length];
                     double scale = ((double) dt.Y.size() ) / (double)length;
                     for(n = 0; n < length ;n++ ) {
                         x[n] = n;
                         y[n] = (int)(this.getHeight()- (dt.Y.get((int)(n*scale)) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
                     }
                     break;

                 case XY:
                     assert(dt.X.size() == dt.Y.size());
                     length = dt.X.size();
                     x = new int[length];
                     y = new int[length];

                     for(n = 0; n < length;n++ ) {
                         x[n] = (int)((dt.X.get(n) - (double)getMinX())/(double)(max_x - getMinX())*this.getWidth());
                         y[n] = (int)(this.getHeight()- (dt.Y.get(n) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
                     }
                     break;
                 default:
                     length = 0;
                     x = new int[length];
                     y = new int[length];
             }
             if(dt.Style == LineStyle.Point || dt.Style == LineStyle.PointLine) {
                 for(n = 0; n < length ;n++ ) {
                     g2.setStroke(new BasicStroke(3.0f));
                     g2.drawOval(x[n] - 2, y[n] -2, 4 , 4);
                     g2.setStroke(new BasicStroke(1.0f));
                 }
             }

             if(dt.Style == LineStyle.Line || dt.Style == LineStyle.PointLine) {
                g2.drawPolyline(x, y, length);    
             }
         }
      }
}
 
Example 8
Project: openjdk-jdk10   File: PolylinePrintingTest.java   View Source Code Vote up 4 votes
private void drawPolylineBAD(Graphics2D g, int[] xp, int[] yp) {
    int offset = 200;
    g.translate(0, offset);
    g.drawPolyline(xp, yp, xp.length);
}
 
Example 9
Project: JGraphix   File: JGraphix_Example_1.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
	DrawFrame df = DrawFrame.create("MyDrawing", 200, 300);
	Graphics2D g = df.getGraphics2D();
	
	float linewidth = 5.0f;	// line width = 5 pixels
	g.setStroke(new BasicStroke(linewidth));
	
	g.setColor(Color.BLUE);
	g.drawLine(40, 10, 10, 40);
	g.draw(new Line2D.Double(70.2, 10.3, 100.4, 40.5));

	g.fillOval(10, 60, 30, 30);
	g.drawOval(60, 60, 30, 30);
	g.fillRoundRect(110, 60, 30, 30, 10, 10);
	g.drawRoundRect(160, 60, 30, 30, 10, 10);

	g.setColor(Color.GREEN.darker());
	g.fillArc(10, 110, 30, 30, 45, 240);
	g.fillArc(60, 110, 30, 30, 45 + 240, 360 - 240);
	g.fillArc(110, 110, 30, 30, 90, 270);
	g.fillArc(160, 110, 30, 30, 270, 270);

	g.setColor(Color.MAGENTA);
	g.drawArc(10, 160, 30, 30, 45, 240);
	g.drawArc(60, 160, 30, 30, 45 + 240, 360 - 240);
	g.drawArc(110, 160, 30, 30, 90, 270);
	g.drawArc(160, 160, 30, 30, 270, 270);

	g.setColor(Color.ORANGE);
	g.fillPolygon(new int[] { 10, 40, 10, 40 }, new int[] { 210, 210, 240, 240 }, 4);
	g.drawPolygon(new int[] { 60, 90, 60, 90 }, new int[] { 210, 210, 240, 240 }, 4);
	g.drawPolyline(new int[] { 110, 140, 110, 140 }, new int[] { 210, 210, 240, 240 }, 4);
	g.drawPolyline(new int[] { 160, 160, 190, 190 }, new int[] {240, 210, 240, 210 }, 4);

	// Printing texts
	g.setColor(Color.BLACK);
	g.setFont(new Font("Monospaced", Font.PLAIN, 14));
	g.drawString("Drawn with JGraphix", 10, 275);

	df.refresh();

	System.out.println("done.");
}