Example usage for java.awt Graphics2D fill

List of usage examples for java.awt Graphics2D fill

Introduction

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

Prototype

public abstract void fill(Shape s);

Source Link

Document

Fills the interior of a Shape using the settings of the Graphics2D context.

Usage

From source file:at.tuwien.ifs.somtoolbox.apps.viewer.GeneralUnitPNode.java

/** @see edu.umd.cs.piccolo.PNode#paint(edu.umd.cs.piccolo.util.PPaintContext) */
@Override//from  ww  w  .  jav a 2 s .  co m
protected void paint(PPaintContext paintContext) {
    Graphics2D g2d = paintContext.getGraphics();

    if (state.exactUnitPlacement && getMapPNode().getCurrentVisualization() == null) { // black background for sky
        // vis
        border.setRect(X, Y, width, height);
        g2d.setColor(Color.BLACK);
        g2d.fill(border);
    }

    if (drawBorder) {
        GridGeometry helper = state.growingSOM.getLayer().getGridGeometry();
        Vector3D[] v = helper.shapeLinePoints(X, Y, width, height);

        g2d.setStroke(borderStroke);
        g2d.setPaint(Color.CYAN);
        g2d.setColor(borderColor);
        g2d.drawLine((int) v[0].getX(), (int) v[0].getY(), (int) v[1].getX(), (int) v[1].getY());

        for (int i = 1; i < v.length; i++) {
            int i_1 = (i + 1) % v.length;
            g2d.drawLine((int) v[i].getX(), (int) v[i].getY(), (int) v[i_1].getX(), (int) v[i_1].getY());
        }

        border.setRect(helper.getBorder(X, Y, width, height));
    }

    PCamera pCam = paintContext.getCamera();
    if (!((PCanvas) pCam.getComponent()).getClass().equals(MapOverviewPane.MapOverviewCanvas.class)) { // only for
        // main
        // display
        currentScale = paintContext.getScale();
        if (currentScale != oldScale) {
            // System.out.println("SCALE: "+currentScale);
            // double os = t10.getScale();
            // t10.setScale(1/currentScale);
            // if (t10.getGlobalFullBounds().width>this.width) {
            // t10.setScale(os);
            // }

            if (currentScale < state.scaleLimits[1]) { // no information
                if (currentDetailLevel != DETAIL_LEVEL_NO) {
                    currentDetailLevel = DETAIL_LEVEL_NO;
                    detailChanged();
                }
            } else if (currentScale >= state.scaleLimits[1] && currentScale < state.scaleLimits[2]) { // little
                // information
                if (currentDetailLevel != DETAIL_LEVEL_LOW) {
                    currentDetailLevel = DETAIL_LEVEL_LOW;
                    detailChanged();
                }
            } else if (currentScale >= state.scaleLimits[2] && currentScale < state.scaleLimits[3]) { // more labels
                if (currentDetailLevel != DETAIL_LEVEL_MEDIUM) {
                    currentDetailLevel = DETAIL_LEVEL_MEDIUM;
                    detailChanged();
                }
            } else if (currentScale >= state.scaleLimits[3]) { // detailed information
                if (currentDetailLevel != DETAIL_LEVEL_HIGH) {
                    currentDetailLevel = DETAIL_LEVEL_HIGH;
                    detailChanged();
                }
            }

            oldScale = currentScale;
        }
    }
}

From source file:com.bdb.weather.display.current.WindDirPointer.java

/**
 * Draws the pointer./*from  w ww.ja v  a 2s.  com*/
 * 
 * @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(Color.blue);
    g2.setStroke(new BasicStroke(1.0f));
    DialScale scale = plot.getScaleForDataset(getDatasetIndex());
    double value = plot.getValue(getDatasetIndex());
    double angle = scale.valueToAngle(value % 360.0);

    Rectangle2D outerRect = DialPlot.rectangleByRadius(frame, outerRadius, outerRadius);
    Rectangle2D innerRect = DialPlot.rectangleByRadius(frame, outerRadius - innerOffset,
            outerRadius - innerOffset);

    g2.setPaint(getOutlinePaint());
    Arc2D arc1 = new Arc2D.Double(outerRect, angle - (ARC_LENGTH / 2), ARC_LENGTH, Arc2D.OPEN);
    g2.draw(arc1);
    Arc2D arc2 = new Arc2D.Double(innerRect, angle, 0.0, Arc2D.OPEN);
    GeneralPath gp = new GeneralPath();
    gp.moveTo(arc1.getStartPoint().getX(), arc1.getStartPoint().getY());
    gp.lineTo(arc2.getStartPoint().getX(), arc2.getStartPoint().getY());
    gp.lineTo(arc1.getEndPoint().getX(), arc1.getEndPoint().getY());
    g2.draw(gp);
    if (fill) {
        g2.setPaint(getFillPaint());
        g2.fill(gp);
    }
}

From source file:GifDecoder.java

/**
 * Creates new frame image from current data (and previous
 * frames as specified by their disposition codes).
 *//*w  w w .ja  v a2 s  . com*/
protected void setPixels() {
    // expose destination image's pixels as int array
    int[] dest = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();

    // fill in starting image contents based on last image's dispose code
    if (lastDispose > 0) {
        if (lastDispose == 3) {
            // use image before last
            int n = frameCount - 2;
            if (n > 0) {
                lastImage = getFrame(n - 1);
            } else {
                lastImage = null;
            }
        }

        if (lastImage != null) {
            int[] prev = ((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();
            System.arraycopy(prev, 0, dest, 0, width * height);
            // copy pixels

            if (lastDispose == 2) {
                // fill last image rect area with background color
                Graphics2D g = image.createGraphics();
                Color c = null;
                if (transparency) {
                    c = new Color(0, 0, 0, 0); // assume background is transparent
                } else {
                    c = new Color(lastBgColor); // use given background color
                }
                g.setColor(c);
                g.setComposite(AlphaComposite.Src); // replace area
                g.fill(lastRect);
                g.dispose();
            }
        }
    }

    // copy each source line to the appropriate place in the destination
    int pass = 1;
    int inc = 8;
    int iline = 0;
    for (int i = 0; i < ih; i++) {
        int line = i;
        if (interlace) {
            if (iline >= ih) {
                pass++;
                switch (pass) {
                case 2:
                    iline = 4;
                    break;
                case 3:
                    iline = 2;
                    inc = 4;
                    break;
                case 4:
                    iline = 1;
                    inc = 2;
                }
            }
            line = iline;
            iline += inc;
        }
        line += iy;
        if (line < height) {
            int k = line * width;
            int dx = k + ix; // start of line in dest
            int dlim = dx + iw; // end of dest line
            if ((k + width) < dlim) {
                dlim = k + width; // past dest edge
            }
            int sx = i * iw; // start of line in source
            while (dx < dlim) {
                // map color and insert in destination
                int index = ((int) pixels[sx++]) & 0xff;
                int c = act[index];
                if (c != 0) {
                    dest[dx] = c;
                }
                dx++;
            }
        }
    }
}

From source file:com.rapidminer.gui.plotter.charts.WeightBasedSymbolAxis.java

/**
 * Draws the grid bands for the axis when it is at the top or bottom of the plot.
 * //from  www  .  j  ava 2  s.  c  o m
 * @param g2
 *            the graphics device.
 * @param plotArea
 *            the area within which the chart should be drawn.
 * @param dataArea
 *            the area within which the plot should be drawn (a subset of the drawArea).
 * @param firstGridBandIsDark
 *            True: the first grid band takes the color of <CODE>gridBandPaint<CODE>.
 *                             False: the second grid band takes the
 *                             color of <CODE>gridBandPaint<CODE>.
 * @param ticks
 *            the ticks.
 */
@Override
protected void drawGridBandsHorizontal(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea,
        boolean firstGridBandIsDark, List ticks) {
    double yy = dataArea.getY();
    double xx1, xx2;

    // gets the outline stroke width of the plot
    double outlineStrokeWidth;
    if (getPlot().getOutlineStroke() != null) {
        outlineStrokeWidth = ((BasicStroke) getPlot().getOutlineStroke()).getLineWidth();
    } else {
        outlineStrokeWidth = 1d;
    }

    Iterator iterator = ticks.iterator();
    ValueTick tick;
    Rectangle2D band;
    while (iterator.hasNext()) {
        tick = (ValueTick) iterator.next();
        int weightIndex = (int) tick.getValue();
        xx1 = valueToJava2D(tick.getValue() - 0.5d, dataArea, RectangleEdge.BOTTOM);
        xx2 = valueToJava2D(tick.getValue() + 0.5d, dataArea, RectangleEdge.BOTTOM);

        g2.setColor(PlotterAdapter.getWeightColor(this.weights[weightIndex], this.maxWeight));

        band = new Rectangle2D.Double(xx1, yy + outlineStrokeWidth, xx2 - xx1,
                dataArea.getMaxY() - yy - outlineStrokeWidth);
        g2.fill(band);
    }
    g2.setPaintMode();
}

From source file:BookTest.java

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    PageFormat pageFormat = book.getPageFormat(currentPage);

    double xoff; // x offset of page start in window
    double yoff; // y offset of page start in window
    double scale; // scale factor to fit page in window
    double px = pageFormat.getWidth();
    double py = pageFormat.getHeight();
    double sx = getWidth() - 1;
    double sy = getHeight() - 1;
    if (px / py < sx / sy) // center horizontally
    {//from w  w w.  j a v  a2 s. c om
        scale = sy / py;
        xoff = 0.5 * (sx - scale * px);
        yoff = 0;
    } else
    // center vertically
    {
        scale = sx / px;
        xoff = 0;
        yoff = 0.5 * (sy - scale * py);
    }
    g2.translate((float) xoff, (float) yoff);
    g2.scale((float) scale, (float) scale);

    // draw page outline (ignoring margins)
    Rectangle2D page = new Rectangle2D.Double(0, 0, px, py);
    g2.setPaint(Color.white);
    g2.fill(page);
    g2.setPaint(Color.black);
    g2.draw(page);

    Printable printable = book.getPrintable(currentPage);
    try {
        printable.print(g2, pageFormat, currentPage);
    } catch (PrinterException e) {
        g2.draw(new Line2D.Double(0, 0, px, py));
        g2.draw(new Line2D.Double(px, 0, 0, py));
    }
}

From source file:org.geotools.renderer.chart.GeometryRenderer.java

void drawGeometry(Geometry g, Graphics2D g2, int series, int item, Rectangle2D dataArea, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis) {

    if (g instanceof GeometryCollection) {
        GeometryCollection gc = (GeometryCollection) g;
        for (int i = 0; i < gc.getNumGeometries(); i++) {
            drawGeometry(gc.getGeometryN(i), g2, series, item, dataArea, plot, domainAxis, rangeAxis);
        }//w  w w. ja v  a  2s.  co m
    } else if (g instanceof Point) {
        drawCoordinate(((Point) g).getCoordinate(), g2, series, item, dataArea, plot, domainAxis, rangeAxis);
    } else if (g instanceof LineString) {
        g2.draw(new TranslatedLiteShape(g, dataArea, plot, domainAxis, rangeAxis));
    } else {

        if (fillPolygons) {
            Paint p = getSeriesPaint(series);
            if (p instanceof Color) {
                Color c = (Color) p;
                p = new Color(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, polygonFillOpacity);
            }
            g2.setPaint(p);
            g2.fill(new TranslatedLiteShape(g, dataArea, plot, domainAxis, rangeAxis));

        }
        g2.setPaint(getSeriesPaint(series));
        g2.draw(new TranslatedLiteShape(g, dataArea, plot, domainAxis, rangeAxis));
    }
}

From source file:no.met.jtimeseries.chart.XYCloudSymbolRenderer.java

/**
 * Draws the visual representation of a single symbol.
 */// w  w w .j  a va 2 s . c  o m
@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:com.rapidminer.gui.plotter.charts.WeightBasedSymbolAxis.java

/**
 * Draws the grid bands for the axis when it is at the top or bottom of the plot.
 * /*from  w  w  w .j  a v  a 2 s  .c  om*/
 * @param g2
 *            the graphics device.
 * @param drawArea
 *            the area within which the chart should be drawn.
 * @param plotArea
 *            the area within which the plot should be drawn (a subset of the drawArea).
 * @param firstGridBandIsDark
 *            True: the first grid band takes the color of <CODE>gridBandPaint<CODE>.
 *                             False: the second grid band takes the
 *                             color of <CODE>gridBandPaint<CODE>.
 * @param ticks
 *            a list of ticks.
 */
@Override
protected void drawGridBandsVertical(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea,
        boolean firstGridBandIsDark, List ticks) {
    double xx = plotArea.getX();
    double yy1, yy2;

    // gets the outline stroke width of the plot
    double outlineStrokeWidth;
    Stroke outlineStroke = getPlot().getOutlineStroke();
    if (outlineStroke != null && outlineStroke instanceof BasicStroke) {
        outlineStrokeWidth = ((BasicStroke) outlineStroke).getLineWidth();
    } else {
        outlineStrokeWidth = 1d;
    }

    Iterator iterator = ticks.iterator();
    ValueTick tick;
    Rectangle2D band;
    while (iterator.hasNext()) {
        tick = (ValueTick) iterator.next();
        int weightIndex = (int) tick.getValue();
        yy1 = valueToJava2D(tick.getValue() + 0.5d, plotArea, RectangleEdge.LEFT);
        yy2 = valueToJava2D(tick.getValue() - 0.5d, plotArea, RectangleEdge.LEFT);

        g2.setColor(PlotterAdapter.getWeightColor(this.weights[weightIndex], this.maxWeight));

        band = new Rectangle2D.Double(xx + outlineStrokeWidth, yy1,
                plotArea.getMaxX() - xx - outlineStrokeWidth, yy2 - yy1);
        g2.fill(band);
    }
    g2.setPaintMode();
}

From source file:com.lfx.web.WebChartXYPlot.java

/**
 * Draws the gridlines for the plot's primary range axis, if they are
 * visible./*from w w  w .  j  av a2 s  .  c o m*/
 *
 * @param g2  the graphics device.
 * @param area  the data area.
 * @param ticks  the ticks.
 *
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {
    Composite oldcomp = g2.getComposite();
    Paint bandPaint = getBackgroundPaint();
    if (bandPaint != null && bandPaint instanceof java.awt.Color) {
        g2.setComposite(AlphaComposite.SrcIn);
        java.awt.Color bandcolor = (java.awt.Color) (bandPaint);
        boolean fillBand = true;
        ValueAxis axis = getDomainAxis();
        double previous = axis.getLowerBound();
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            if (!tick.getTickType().equals(TickType.MAJOR))
                continue;
            double current = tick.getValue();
            double y1 = axis.valueToJava2D(previous, dataArea, getDomainAxisEdge());
            double y2 = axis.valueToJava2D(current, dataArea, getDomainAxisEdge());
            Rectangle2D band = new Rectangle2D.Double(y1, dataArea.getMinY(), y2 - y1, dataArea.getWidth());
            if (fillBand)
                g2.setPaint(bandcolor);
            else
                g2.setPaint(bandcolor.darker());
            g2.fill(band);
            previous = current;
            fillBand = !fillBand;
        }
        double end = axis.getUpperBound();
        double y1 = axis.valueToJava2D(previous, dataArea, getDomainAxisEdge());
        double y2 = axis.valueToJava2D(end, dataArea, getDomainAxisEdge());
        Rectangle2D band = new Rectangle2D.Double(y1, dataArea.getMinY(), y2 - y1, dataArea.getWidth());
        if (fillBand)
            g2.setPaint(bandcolor);
        else
            g2.setPaint(bandcolor.darker());
        g2.fill(band);
    } else {
        super.drawDomainGridlines(g2, dataArea, ticks);
    }
    g2.setComposite(oldcomp);
}

From source file:com.lfx.web.WebChartXYPlot.java

/**
  * Draws the gridlines for the plot, if they are visible.
  *//from w  w  w  .  ja  v a 2  s  .  com
  * @param g2  the graphics device.
  * @param dataArea  the data area.
  * @param ticks  the ticks.
  *
  * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
  */

protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {
    Composite oldcomp = g2.getComposite();
    Paint bandPaint = getBackgroundPaint();
    if (bandPaint != null && bandPaint instanceof java.awt.Color) {
        // g2.setComposite(AlphaComposite.SrcO);
        java.awt.Color bandcolor = (java.awt.Color) (bandPaint);
        boolean fillBand = false;
        ValueAxis axis = getRangeAxis();
        double previous = axis.getLowerBound();
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            if (!tick.getTickType().equals(TickType.MAJOR))
                continue;
            double current = tick.getValue();
            double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge());
            double y2 = axis.valueToJava2D(current, dataArea, getRangeAxisEdge());
            Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2);
            if (fillBand)
                g2.setPaint(bandcolor);
            else
                g2.setPaint(bandcolor.darker());
            g2.fill(band);
            previous = current;
            fillBand = !fillBand;
        }
        double end = axis.getUpperBound();
        double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge());
        double y2 = axis.valueToJava2D(end, dataArea, getRangeAxisEdge());
        Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2);
        if (fillBand)
            g2.setPaint(bandcolor);
        else
            g2.setPaint(bandcolor.darker());
        g2.fill(band);
    } else {
        super.drawRangeGridlines(g2, dataArea, ticks);
    }
    g2.setComposite(oldcomp);
}