Example usage for java.awt Graphics2D setStroke

List of usage examples for java.awt Graphics2D setStroke

Introduction

In this page you can find the example usage for java.awt Graphics2D setStroke.

Prototype

public abstract void setStroke(Stroke s);

Source Link

Document

Sets the Stroke for the Graphics2D context.

Usage

From source file:ucar.unidata.idv.control.chart.WayPoint.java

/**
 * Draws the annotation./* www . j ava 2  s .c  o m*/
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  an optional info object that will be populated with
 *              entity information.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis,
        int rendererIndex, PlotRenderingInfo info) {
    super.setGraphicsState(g2);
    if (!getPlotWrapper().okToDraw(this)) {
        return;
    }

    g2.setStroke(new BasicStroke());
    if (false && getSelected()) {
        g2.setColor(COLOR_SELECTED);
    } else {
        g2.setColor(getColor());
    }
    x = getXFromValue(dataArea, domainAxis);

    int width2 = (int) (ANNOTATION_WIDTH / 2);
    int bottom = (int) (dataArea.getY() + dataArea.getHeight());
    y = bottom;
    int[] xs = { x - width2, x + width2, x, x - width2 };
    int[] ys = { bottom - ANNOTATION_WIDTH, bottom - ANNOTATION_WIDTH, bottom, bottom - ANNOTATION_WIDTH };
    g2.fillPolygon(xs, ys, xs.length);

    if ((getName() != null) && !isForAnimation) {
        FontMetrics fm = g2.getFontMetrics();
        int width = fm.stringWidth(getName());
        int textLeft = x - width / 2;
        g2.drawString(getName(), textLeft, bottom - ANNOTATION_WIDTH - 2);
    }

    if (getSelected()) {
        g2.setColor(COLOR_SELECTED);
        g2.drawPolygon(xs, ys, xs.length);
    }

    if (getPropertyListeners().hasListeners(PROP_WAYPOINTVALUE) || isForAnimation) {
        g2.setColor(Color.gray);
        g2.drawLine(x, y - ANNOTATION_WIDTH, x, (int) dataArea.getY());
    }

    boolean playSound = canPlaySound();

    if (isForAnimation) {
        if (clockImage == null) {
            clockImage = GuiUtils.getImage("/auxdata/ui/icons/clock.gif");
        }
        if (playSound) {
            g2.drawImage(clockImage, x - 8, (int) dataArea.getY() + 1, null);
        } else {
            g2.drawImage(clockImage, x - 8, (int) dataArea.getY() + 1, null);
        }
    }

    if (canPlaySound()) {
        if (noteImage == null) {
            noteImage = GuiUtils.getImage("/auxdata/ui/icons/note.gif");
        }
        if (isForAnimation) {
            g2.drawImage(noteImage, x + 8, (int) dataArea.getY() + 1, null);
        } else {
            g2.drawImage(noteImage, x, (int) dataArea.getY() + 1, null);
        }
    }

    if (minutesSpan > 0.0) {
        int left = (int) domainAxis.valueToJava2D(domainValue - (minutesSpan * 60000) / 2, dataArea,
                RectangleEdge.BOTTOM);
        int right = (int) domainAxis.valueToJava2D(domainValue + (minutesSpan * 60000) / 2, dataArea,
                RectangleEdge.BOTTOM);
        g2.setPaint(Color.black);
        g2.setStroke(new BasicStroke(2.0f));
        g2.drawLine(left, y, right, y);
    }

}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void paintRect(Graphics2D g2d, int x, int y, int width, int height, Color linecoler, int thickness,
        Color fillColor) throws Exception {

    //int x, int y, int width, int height
    //g2d.fill(new Rectangle(x,y,width,height));

    g2d.setStroke(new BasicStroke(thickness));

    if (linecoler != null) {
        g2d.setPaint(linecoler);//from   w  ww  .  j  a  v a  2  s . c o m
        g2d.drawRect(x, y, width, height);
    }

    if (fillColor != null) {
        g2d.setPaint(fillColor);
        g2d.fillRect(x, y, width, height);
    }

}

From source file:rod_design_compute.ShowPanel.java

private void drawChooseRod(Point a, Point b, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    g.setColor(Color.blue);//from ww  w  . ja  v  a 2 s. com
    g.drawLine(toScreenX(a.X), toScreenY(a.Y), toScreenX(b.X), toScreenY(b.Y));
}

From source file:rod_design_compute.ShowPanel.java

private void drawChoosePoint(Point point, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    int x = toScreenX(point.X);
    int y = toScreenY(point.Y);

    g.setColor(Color.blue);/*from ww  w.  j a  va 2 s. c  o m*/
    g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
}

From source file:rod_design_compute.ShowPanel.java

private void paintRRP(RRP rodRRP, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    drawSlider(rodRRP.getrodslider(), rodRRP.getPointC(), g);

    drawBlock(rodRRP.getrodslider(), rodRRP.getPointC(), g);

    g.drawLine(toScreenX(rodRRP.getPointB().X), toScreenY(rodRRP.getPointB().Y),
            toScreenX(rodRRP.getPointC().X), toScreenY(rodRRP.getPointC().Y));

    drawJunctionPoint(rodRRP.getPointB(), g);
    drawJunctionPoint(rodRRP.getPointC(), g);
}

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private void drawSeriesLines(Graphics2D g2, Collection<Line2D> lines, int series, int item) {
    g2.setPaint(getItemPaint(series, item));
    g2.setStroke(getItemStroke(series, item));

    for (Line2D line : lines) {
        g2.draw(line);/*  ww w  .ja v a  2  s.c o m*/
    }
}

From source file:rod_design_compute.ShowPanel.java

private void paintSR(SR rodSR, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    if (rodSR.flag == true) {
        g2d.setColor(Color.red);/*from w w w  . j a  v  a 2 s.co  m*/
        g.drawLine(toScreenX(rodSR.getPointA().X), toScreenY(rodSR.getPointA().Y),
                toScreenX(rodSR.getPointE().X), toScreenY(rodSR.getPointE().Y));
        g.drawLine(toScreenX(rodSR.getPointB().X), toScreenY(rodSR.getPointB().Y),
                toScreenX(rodSR.getPointE().X), toScreenY(rodSR.getPointE().Y));
        drawOtherPoint(rodSR.getPointE(), g);
        g2d.setColor(Color.black);
    }

    g2d.setColor(Color.green);
    g.drawLine(toScreenX(rodSR.getPointA().X), toScreenY(rodSR.getPointA().Y), toScreenX(rodSR.getPointB().X),
            toScreenY(rodSR.getPointB().Y));
    g2d.setColor(Color.black);

    drawBasePoint(rodSR.getPointA(), g);
    drawJunctionPoint(rodSR.getPointB(), g);
}

From source file:rod_design_compute.ShowPanel.java

private void paintRRR(RRR rodRRR, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    if (rodRRR.flag2 == true || rodRRR.flag3 == true) {
        g2d.setColor(Color.red);//  w  w  w . ja v a2 s.  c o m
        if (rodRRR.flag2 == true) {
            g.drawLine(toScreenX(rodRRR.getPointB().X), toScreenY(rodRRR.getPointB().Y),
                    toScreenX(rodRRR.getPointE().X), toScreenY(rodRRR.getPointE().Y));
        } else if (rodRRR.flag3 == true) {
            g.drawLine(toScreenX(rodRRR.getPointD().X), toScreenY(rodRRR.getPointD().Y),
                    toScreenX(rodRRR.getPointE().X), toScreenY(rodRRR.getPointE().Y));
        }
        g.drawLine(toScreenX(rodRRR.getPointC().X), toScreenY(rodRRR.getPointC().Y),
                toScreenX(rodRRR.getPointE().X), toScreenY(rodRRR.getPointE().Y));
        drawOtherPoint(rodRRR.getPointE(), g);
        g2d.setColor(Color.black);
    }

    g.drawLine(toScreenX(rodRRR.getPointB().X), toScreenY(rodRRR.getPointB().Y),
            toScreenX(rodRRR.getPointC().X), toScreenY(rodRRR.getPointC().Y));

    g.drawLine(toScreenX(rodRRR.getPointC().X), toScreenY(rodRRR.getPointC().Y),
            toScreenX(rodRRR.getPointD().X), toScreenY(rodRRR.getPointD().Y));

    drawJunctionPoint(rodRRR.getPointB(), g);
    drawJunctionPoint(rodRRR.getPointC(), g);
    drawBasePoint(rodRRR.getPointD(), g);
}

From source file:CustomStrokes.java

/** Draw the example */
public void paint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    // Get a shape to work with. Here we'll use the letter B
    Font f = new Font("Serif", Font.BOLD, 200);
    GlyphVector gv = f.createGlyphVector(g.getFontRenderContext(), "B");
    Shape shape = gv.getOutline();

    // Set drawing attributes and starting position
    g.setColor(Color.black);//from w  w  w .j  ava 2s .c o m
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.translate(10, 175);

    // Draw the shape once with each stroke
    for (int i = 0; i < strokes.length; i++) {
        g.setStroke(strokes[i]); // set the stroke
        g.draw(shape); // draw the shape
        g.translate(140, 0); // move to the right
    }
}

From source file:nl.b3p.viewer.image.ImageTool.java

public static BufferedImage drawGeometries(BufferedImage bi, CombineImageSettings settings, int srid, Bbox bbox,
        int width, int height) throws Exception {
    List wktGeoms = settings.getWktGeoms();
    if (wktGeoms == null || wktGeoms.size() <= 0) {
        return bi;
    }/*  w ww .  j  a v a  2 s  .  c  om*/
    BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    //        BufferedImage newBufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D gbi = newBufIm.createGraphics();
    gbi.drawImage(bi, 0, 0, null);
    for (int i = 0; i < wktGeoms.size(); i++) {
        gbi.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        CombineImageWkt ciw = (CombineImageWkt) wktGeoms.get(i);
        Color color = settings.getDefaultWktGeomColor();
        if (ciw.getColor() != null) {
            color = ciw.getColor();
        }
        gbi.setColor(color);
        String wktGeom = ciw.getWktGeom();
        Geometry geom = geometrieFromText(wktGeom, srid);
        Shape shape = createImage(geom, srid, bbox, width, height);
        Point centerPoint = null;
        if (geom instanceof Polygon) {
            gbi.fill(shape);
        } else if (geom instanceof com.vividsolutions.jts.geom.Point) {
            centerPoint = calculateCenter(shape, srid, bbox, width, height);
            gbi.fill(new Ellipse2D.Double(centerPoint.getX(), centerPoint.getY(), 8, 8));
        } else {
            float strokeWidth = ciw.getStrokeWidth() != null ? ciw.getStrokeWidth() : 3f;
            gbi.setStroke(new BasicStroke(strokeWidth));
            gbi.draw(shape);
        }
        if (ciw.getLabel() != null) {
            if (centerPoint == null) {
                centerPoint = calculateCenter(shape, srid, bbox, width, height);
            }
            gbi.setColor(Color.black);
            gbi.drawString(ciw.getLabel(), (float) centerPoint.getX(), (float) centerPoint.getY());
        }
    }
    gbi.dispose();
    return newBufIm;
}