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:no.met.jtimeseries.chart.XYCloudSymbolRenderer.java

/**
 * Draws the visual representation of a single symbol.
 *//*from  ww  w  . jav a 2  s.  com*/
@Override
public void drawItem(Graphics2D g2d, XYItemRendererState state, Rectangle2D plotArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {
    // Needs a new graphics object to use translate() and rotate()
    Graphics2D g2 = (Graphics2D) g2d.create();
    g2.setRenderingHints(renderHints);

    double middleY = plotArea.getCenterY();
    CloudDataset cloudData = (CloudDataset) dataset;
    Number x = cloudData.getX(series, item);
    double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, plot.getDomainAxisEdge());
    g2.translate((int) middleX, (int) middleY); // make x=0, y=0 the middle of the symbol
    g2.setStroke(new BasicStroke());
    double height = plotArea.getHeight() - 2;

    // we set the width to be 20 which is the same as the weather symbols 
    double width = calculateWidth(plotArea.getWidth());
    double startX = -(width / 2);
    double startY[] = { -(height / 2), -(height / 4), 0, (height / 4) };
    double values[] = { (cloudData.getHighClouds(series, item).doubleValue() / 100.0),
            (cloudData.getMediumClouds(series, item).doubleValue() / 100.0),
            (cloudData.getLowClouds(series, item).doubleValue() / 100.0),
            (cloudData.getFog(series, item).doubleValue() / 100.0) };

    for (int i = 0; i < values.length; i++) { // for each cloud type
        g2.setColor(new Color(96, 96, 96));
        g2.fill(new Rectangle2D.Double(startX, startY[i], (width * values[i]), (height / 4 - 1))); // plot could
        g2.setColor(new Color(97, 204, 247));
        g2.fill(new Rectangle2D.Double(startX + (width * values[i]), startY[i], (width * (1 - values[i])),
                (height / 4 - 1))); // plot sky
    }
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java

/**
 * Draws zoom rectangle (if present)./*from   w w w.  j ava  2 s  .  co m*/
 * The drawing is performed in XOR mode, therefore
 * when this method is called twice in a row,
 * the second call will completely restore the state
 * of the canvas.
 *
 * @param selectedRegion
 * @param stroke
 * @param fillColor
 */
protected void drawSelectedRegion(Rectangle2D selectedRegion, Stroke stroke, Color fillColor, boolean xorMode,
        Graphics2D g2) {
    // Set XOR mode to draw the zoom rectangle
    if (g2 == null)
        return;
    Paint origColor = g2.getPaint();

    if (selectedRegion != null) {
        if (xorMode) {
            g2.setXORMode(fillColor);
        } else
            g2.setPaint(fillColor);
        g2.fill(selectedRegion);
        g2.setPaint(Color.black);
        g2.setStroke(stroke);
        if (xorMode)
            g2.setPaint(Color.white);
        else
            g2.setPaint(Color.black);

        g2.draw(selectedRegion);
        g2.setPaintMode();
        g2.setPaint(origColor);
    }
}

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

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

    for (Line2D line : lines) {
        g2.draw(line);//from w  w  w  .  ja  va  2 s .com
    }
}

From source file:ImageDuplicity.java

private void createOffscreenImage() {
    Dimension d = getSize();//from w  w w .j a va 2  s  . c  om
    int width = d.width;
    int height = d.height;
    image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2 = image.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    try {
        String filename = "largeJava2sLogo.jpg";
        InputStream in = getClass().getResourceAsStream(filename);
        JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
        BufferedImage image = decoder.decodeAsBufferedImage();
        in.close();
        g2.drawImage(image, 0, 0, width, height, null);
    } catch (Exception e) {
        System.out.print(e);
    }

    g2.setStroke(new BasicStroke(2));
    Color[] colors = { Color.red, Color.blue, Color.green };
    for (int i = -32; i < 40; i += 8) {
        g2.setPaint(colors[Math.abs(i) % 3]);
        g2.drawOval(i, i, width - i * 2, height - i * 2);
    }
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

protected void drawBarShadow(double x, double y, boolean alternate) {
    if (x == -1)//from  w w  w .  java  2  s.  c o m
        return;
    Graphics2D g = initGraphics();

    Shape bounds = getBarShadowBounds(x, y);
    if (bounds == null)
        return;
    g.setStroke(new BasicStroke(3));
    g.draw(bounds);
    if (alternate) {
        lastShadowX = (lastShadowX == -1) ? x : -1;
        lastShadowY = (lastShadowY == -1) ? y : -1;
    }
}

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

public void drawThickLine(Graphics2D g2d, int x1, int y1, int x2, int y2, int width, Color c) throws Exception {
    g2d.setPaint(c);//ww  w  .  j a  va 2 s .  com
    g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    g2d.drawLine(x1, y1, x2, y2);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.CustomLegendGraphic.java

@Override
public void draw(Graphics2D g2, Rectangle2D area) {

    area = trimMargin(area);//from   ww  w .ja v  a 2  s  . co  m
    drawBorder(g2, area);
    area = trimBorder(area);
    area = trimPadding(area);

    if (isLineVisible()) {
        Point2D location = RectangleAnchor.coordinates(area, getShapeLocation());
        Shape aLine = ShapeUtilities.createTranslatedShape(getLine(), getShapeAnchor(), location.getX(),
                location.getY());
        g2.setPaint(getLinePaint());
        g2.setStroke(getLineStroke());
        g2.draw(aLine);
    }

    if (isShapeVisible()) {
        Point2D location = RectangleAnchor.coordinates(area, getShapeLocation());

        Shape s = ShapeUtilities.createTranslatedShape(getShape(), getShapeAnchor(), location.getX(),
                location.getY());
        if (isShapeFilled()) {
            Paint p = getFillPaint();
            if (p instanceof GradientPaint) {
                GradientPaint gp = (GradientPaint) getFillPaint();
                p = getFillPaintTransformer().transform(gp, s);
            } else if (p instanceof LinearGradientPaint) {
                LinearGradientPaint gradient = (LinearGradientPaint) p;
                Rectangle2D bounds = s.getBounds2D();
                p = getTranslatedLinearGradientPaint(gradient,
                        new Point2D.Double(bounds.getMinX(), bounds.getMinY()),
                        new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), false);
            }
            g2.setPaint(p);
            g2.fill(s);
        }
        if (isShapeOutlineVisible()) {
            g2.setPaint(getOutlinePaint());
            g2.setStroke(getOutlineStroke());
            g2.draw(s);
        }
    }

}

From source file:com.simiacryptus.mindseye.applications.ArtistryUtil.java

/**
 * Paint circles.//from w  ww .j  a v a2s  . c o  m
 *
 * @param canvas the canvas
 * @param scale  the scale
 */
public static void paint_Circles(final Tensor canvas, final int scale) {
    BufferedImage originalImage = canvas.toImage();
    BufferedImage newImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = (Graphics2D) newImage.getGraphics();
    IntStream.range(0, 10000).forEach(i -> {
        Random random = new Random();
        int positionX = random.nextInt(originalImage.getWidth());
        int positionY = random.nextInt(originalImage.getHeight());
        int width = 1 + random.nextInt(2 * scale);
        int height = 1 + random.nextInt(2 * scale);
        DoubleStatistics[] stats = { new DoubleStatistics(), new DoubleStatistics(), new DoubleStatistics() };
        canvas.coordStream(false).filter(c -> {
            int[] coords = c.getCoords();
            int x = coords[0];
            int y = coords[1];
            double relX = Math.pow(1 - 2 * ((double) (x - positionX) / width), 2);
            double relY = Math.pow(1 - 2 * ((double) (y - positionY) / height), 2);
            return relX + relY < 1.0;
        }).forEach(c -> stats[c.getCoords()[2]].accept(canvas.get(c)));
        graphics.setStroke(new Stroke() {
            @Override
            public Shape createStrokedShape(final Shape p) {
                return null;
            }
        });
        graphics.setColor(new Color((int) stats[0].getAverage(), (int) stats[1].getAverage(),
                (int) stats[2].getAverage()));
        graphics.fillOval(positionX, positionY, width, height);
    });
    canvas.set(Tensor.fromRGB(newImage));
}

From source file:com.od.jtimeseries.ui.visualizer.chart.creator.EfficientXYLineAndShapeRenderer.java

private void drawLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double transX0, double transY0,
        double transX1, double transY1, Stroke s, Paint p) {
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        state.workingLine.setLine(transY0, transX0, transY1, transX1);
    } else if (orientation == PlotOrientation.VERTICAL) {
        state.workingLine.setLine(transX0, transY0, transX1, transY1);
    }/*from   w  w  w .j a v a 2 s. co m*/

    g2.setStroke(s);
    g2.setPaint(p);
    g2.draw(state.workingLine);
}

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

protected void drawLinkSelectionBarShadow(GraphicNode node) {
    if (node == null)
        return;/* w w  w .j ava  2 s .c o m*/
    Graphics2D g = initGraphics();
    Rectangle2D selectionRectangle = getLinkSelectionShadowBounds(node);
    if (selectionRectangle == null)
        return;
    g.setStroke(new BasicStroke(3));
    g.draw(selectionRectangle);
}