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

The following are Jave code examples for showing how to use setPaint() 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: jdk8u-jdk   File: WritingInterruptionTest.java   View Source Code Vote up 9 votes
private static BufferedImage createTestImage() {
    int w = 1024;
    int h = 768;

    BufferedImage img = new
        BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = {0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);

    RadialGradientPaint p =
        new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();

    return img;
}
 
Example 2
Project: jdk8u-jdk   File: MlibOpsTest.java   View Source Code Vote up 8 votes
private static BufferedImage createSrcImage() {
    BufferedImage img = createImage();

    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = {0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);

    RadialGradientPaint p =
            new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();

    return img;
}
 
Example 3
Project: brModelo   File: InspectorItemBase.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g) {
    super.paint(g);
    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    Graphics2D Canvas = (Graphics2D) g;

    Canvas.addRenderingHints(renderHints);

    Canvas.setStroke(new BasicStroke(
            1f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND));

    Canvas.setPaint(Color.BLACK);

    paint2D(Canvas);
}
 
Example 4
Project: parabuild-ci   File: StandardDialFrame.java   View Source Code Vote up 6 votes
/**
 * Draws the frame.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view rectangle.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Shape window = getWindow(frame);
    Shape outerWindow = getOuterWindow(frame);

    Area area1 = new Area(outerWindow);
    Area area2 = new Area(window);
    area1.subtract(area2);
    g2.setPaint(Color.lightGray);
    g2.fill(area1);
    
    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(outerWindow);
    
    
}
 
Example 5
Project: parabuild-ci   File: CategoryPlot.java   View Source Code Vote up 6 votes
/**
 * Draws a range crosshair.
 * 
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 * 
 * @since 1.0.5
 */
protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, 
        PlotOrientation orientation, double value, ValueAxis axis, 
        Stroke stroke, Paint paint) {
    
    if (!axis.getRange().contains(value)) {
        return;
    }
    Line2D line = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        double xx = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.BOTTOM);
        line = new Line2D.Double(xx, dataArea.getMinY(), xx, 
                dataArea.getMaxY());
    }
    else {
        double yy = axis.valueToJava2D(value, dataArea, 
                RectangleEdge.LEFT);
        line = new Line2D.Double(dataArea.getMinX(), yy, 
                dataArea.getMaxX(), yy);
    }
    g2.setStroke(stroke);
    g2.setPaint(paint);
    g2.draw(line);
   
}
 
Example 6
Project: parabuild-ci   File: FastScatterPlot.java   View Source Code Vote up 6 votes
/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible()) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            Iterator iterator = ticks.iterator();
            while (iterator.hasNext()) {
                ValueTick tick = (ValueTick) iterator.next();
                double v = this.rangeAxis.valueToJava2D(
                    tick.getValue(), dataArea, RectangleEdge.LEFT
                );
                Line2D line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v);
                g2.setPaint(gridPaint);
                g2.setStroke(gridStroke);
                g2.draw(line);                
            }
        }
    }

}
 
Example 7
Project: brModelo   File: Editor.java   View Source Code Vote up 6 votes
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background

    if (diagramaAtual == null) {
        return;
    }

    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    Graphics2D Canvas = (Graphics2D) g;
    Canvas.addRenderingHints(renderHints);

    Canvas.setPaint(Color.BLACK);
    Stroke stroke = new BasicStroke(2.f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
    Canvas.setStroke(stroke);

    Canvas.drawRect(box.getLocation().x, box.getLocation().y, box.getWidth(), box.getHeight());
    Canvas.setPaint(Color.GRAY);
    Canvas.drawRect(box.getLocation().x + 1, box.getLocation().y + 1, box.getWidth(), box.getHeight());
    //Canvas.setPaint(Color.BLACK);
}
 
Example 8
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 9
Project: jmt   File: QueueDrawer.java   View Source Code Vote up 5 votes
private void drawProcessor2(Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {
	double x = getProcessorXY().x, y = getProcessorXY().y;
	processor.setFrame(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, PROC_RAD, PROC_RAD);
	if (gradientFill) {
		GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + PROC_RAD * 2), startC.darker(),
				false);
		g2d.setPaint(gp);
	} else {
		g2d.setPaint(startC);
	}
	g2d.fill(processor);
	g2d.setPaint(border);
	g2d.draw(processor);
}
 
Example 10
Project: QN-ACTR-Release   File: QueueDrawer.java   View Source Code Vote up 5 votes
private void drawProcessorMulti(Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {
	double x = getProcessorXY().x, y = getProcessorXY().y;
	processor.setFrame(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3 - ELEMS_GAP / 2, PROC_RAD
			- ELEMS_GAP, PROC_RAD - ELEMS_GAP);
	if (gradientFill) {
		GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + PROC_RAD * 2), startC.darker(),
				false);
		g2d.setPaint(gp);
	} else {
		g2d.setPaint(startC);
	}
	g2d.fill(processor);
	g2d.setPaint(border);
	g2d.draw(processor);
}
 
Example 11
Project: parabuild-ci   File: AbstractCategoryItemRenderer.java   View Source Code Vote up 5 votes
/**
 * Draws a grid line against the domain axis.
 * <P>
 * Note that this default implementation assumes that the horizontal axis
 * is the domain axis. If this is not the case, you will need to override
 * this method.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the area for plotting data (not yet adjusted for any
 *                  3D effect).
 * @param value  the Java2D value at which the grid line should be drawn.
 *
 * @see #drawRangeGridline(Graphics2D, CategoryPlot, ValueAxis,
 *     Rectangle2D, double)
 */
public void drawDomainGridline(Graphics2D g2,
                               CategoryPlot plot,
                               Rectangle2D dataArea,
                               double value) {

    Line2D line = null;
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value,
                dataArea.getMaxX(), value);
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value,
                dataArea.getMaxY());
    }

    Paint paint = plot.getDomainGridlinePaint();
    if (paint == null) {
        paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT;
    }
    g2.setPaint(paint);

    Stroke stroke = plot.getDomainGridlineStroke();
    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }
    g2.setStroke(stroke);

    g2.draw(line);

}
 
Example 12
Project: parabuild-ci   File: XYBlockRenderer.java   View Source Code Vote up 5 votes
/**
 * Draws the block representing the specified item.
 * 
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, 
        Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, 
        ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, 
        int series, int item, CrosshairState crosshairState, int pass) {
    
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    if (dataset instanceof XYZDataset) {
        z = ((XYZDataset) dataset).getZValue(series, item);
    }
    Paint p = this.paintScale.getPaint(z);
    double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, 
            plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, 
            plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth 
            + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight 
            + this.yOffset, dataArea, plot.getRangeAxisEdge());
    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        block = new Rectangle2D.Double(Math.min(yy0, yy1), 
                Math.min(xx0, xx1), Math.abs(yy1 - yy0), 
                Math.abs(xx0 - xx1));
    }
    else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1), 
                Math.min(yy0, yy1), Math.abs(xx1 - xx0), 
                Math.abs(yy1 - yy0));            
    }
    g2.setPaint(p);
    g2.fill(block);
    g2.setStroke(new BasicStroke(1.0f));
    g2.draw(block);
}
 
Example 13
Project: DicomViewer   File: SliderComponentForTimeSlider.java   View Source Code Vote up 5 votes
@Override
protected void drawSlider(final Graphics2D g2) {
    GradientPaint gradient = new GradientPaint(0, 0, colorLimitMin, sliderWidth(), 0, colorLimitMax, true);
    g2.setPaint(gradient);
    fillSlider(g2);
    g2.setColor(Color.black);
    super.drawSlider(g2);
}
 
Example 14
Project: jdk8u-jdk   File: TransformedPaintTest.java   View Source Code Vote up 5 votes
private Paint createPaint(PaintType type, int startx, int starty,
                          int w, int h)
{
    // make sure that the blue color doesn't show up when filling a
    // w by h rect
    w++; h++;

    int endx = startx + w;
    int endy = starty + h;
    Rectangle2D.Float r = new Rectangle2D.Float(startx, starty, w, h);
    switch (type) {
        case COLOR: return Color.red;
        case GRADIENT: return
            new GradientPaint(startx, starty, Color.red,
                              endx, endy, Color.green);
        case LINEAR_GRADIENT: return
            new LinearGradientPaint(startx, starty, endx, endy,
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue });
        case RADIAL_GRADIENT: return
            new RadialGradientPaint(startx, starty,
                (float)Math.sqrt(w * w + h * h),
                new float[] { 0.0f, 0.999f, 1.0f },
                new Color[] { Color.red, Color.green, Color.blue },
                CycleMethod.NO_CYCLE);
        case TEXTURE: {
            BufferedImage bi =
                new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = (Graphics2D) bi.getGraphics();
            g.setPaint(createPaint(PaintType.LINEAR_GRADIENT, 0, 0, w, h));
            g.fillRect(0, 0, w, h);
            return new TexturePaint(bi, r);
        }
    }
    return Color.green;
}
 
Example 15
Project: JuggleMasterPro   File: AnimationJFrame.java   View Source Code Vote up 5 votes
/**
 * Method description
 * 
 * @see
 * @param objPgraphics2D
 */
final private void doDrawColoredBorder(Graphics2D objPgraphics2D) {

	final Insets objLinsets = this.getInsets();

	final byte bytLthickness = 4;
	final int intLx0 = objLinsets.left;
	final int intLy0 = objLinsets.top;
	final int intLx1 = objLinsets.left + this.intGbackgroundWidth;
	final int intLy1 = objLinsets.top + this.intGbackgroundHeight;

	// North border :
	objPgraphics2D.setStroke(new BasicStroke(0.5F, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
	objPgraphics2D.setPaint(new GradientPaint(intLx0, intLy0, Color.WHITE, intLx1, intLy0, Color.ORANGE, false));
	objPgraphics2D.fillRect(intLx0, intLy0, intLx1 - intLx0, bytLthickness);

	// West border :
	objPgraphics2D.setPaint(new GradientPaint(intLx0, intLy0, Color.WHITE, intLx0, intLy1, Color.ORANGE, false));
	objPgraphics2D.fillRect(intLx0, intLy0, bytLthickness, intLy1 - intLy0);

	// East border :
	objPgraphics2D.setPaint(new GradientPaint(intLx1, intLy0, Color.ORANGE, intLx1, intLy1, Color.RED, false));
	objPgraphics2D.fillRect(intLx1 - bytLthickness, intLy0, bytLthickness, intLy1 - intLy0);

	// South border :
	objPgraphics2D.setPaint(new GradientPaint(intLx0, intLy1, Color.ORANGE, intLx1, intLy1, Color.RED, false));
	objPgraphics2D.fillRect(intLx0, intLy1 - bytLthickness, intLx1 - intLx0, bytLthickness);
}
 
Example 16
Project: brModelo   File: ForkJoinAtividade.java   View Source Code Vote up 5 votes
@Override
public void DoPaint(Graphics2D g) {
    super.DoPaint(g); //To change body of generated methods, choose Tools | Templates.
    Paint bkp = g.getPaint();
    g.setPaint(this.getForeColor());
    g.fillRect(getLeft(), getTop(), getWidth() - 1, getHeight() - 1);
    g.setPaint(bkp);
}
 
Example 17
Project: openjdk-jdk10   File: Decoration.java   View Source Code Vote up 4 votes
public void drawTextAndDecorations(Label label,
                            Graphics2D g2d,
                            float x,
                            float y) {

    if (fgPaint == null && bgPaint == null && swapColors == false) {
        drawTextAndEmbellishments(label, g2d, x, y);
    }
    else {
        Paint savedPaint = g2d.getPaint();
        Paint foreground, background;

        if (swapColors) {
            background = fgPaint==null? savedPaint : fgPaint;
            if (bgPaint == null) {
                if (background instanceof Color) {
                    Color bg = (Color)background;
                    // 30/59/11 is standard weights, tweaked a bit
                    int brightness = 33 * bg.getRed()
                        + 53 * bg.getGreen()
                        + 14 * bg.getBlue();
                    foreground = brightness > 18500 ? Color.BLACK : Color.WHITE;
                } else {
                    foreground = Color.WHITE;
                }
            } else {
                foreground = bgPaint;
            }
        }
        else {
            foreground = fgPaint==null? savedPaint : fgPaint;
            background = bgPaint;
        }

        if (background != null) {

            Rectangle2D bgArea = label.getLogicalBounds();
            bgArea = new Rectangle2D.Float(x + (float)bgArea.getX(),
                                        y + (float)bgArea.getY(),
                                        (float)bgArea.getWidth(),
                                        (float)bgArea.getHeight());

            g2d.setPaint(background);
            g2d.fill(bgArea);
        }

        g2d.setPaint(foreground);
        drawTextAndEmbellishments(label, g2d, x, y);
        g2d.setPaint(savedPaint);
    }
}
 
Example 18
Project: parabuild-ci   File: SymbolAxis.java   View Source Code Vote up 4 votes
/**
 * Draws the grid bands for the axis when it is at the top or bottom of 
 * the plot.
 *
 * @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.
 */
protected void drawGridBandsHorizontal(Graphics2D g2,
                                       Rectangle2D plotArea, 
                                       Rectangle2D dataArea,
                                       boolean firstGridBandIsDark, 
                                       List ticks) {

    boolean currentGridBandIsDark = firstGridBandIsDark;
    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();
        xx1 = valueToJava2D(tick.getValue() - 0.5d, dataArea, 
                RectangleEdge.BOTTOM);
        xx2 = valueToJava2D(tick.getValue() + 0.5d, dataArea, 
                RectangleEdge.BOTTOM);
        if (currentGridBandIsDark) {
            g2.setPaint(this.gridBandPaint);
        }
        else {
            g2.setPaint(Color.white);
        }
        band = new Rectangle2D.Double(xx1, yy + outlineStrokeWidth, 
            xx2 - xx1, dataArea.getMaxY() - yy - outlineStrokeWidth);
        g2.fill(band);
        currentGridBandIsDark = !currentGridBandIsDark;
    }
    g2.setPaintMode();
}
 
Example 19
Project: parabuild-ci   File: SymbolicAxis.java   View Source Code Vote up 4 votes
/**
 * Draws the symbolic grid lines.
 * <P>
 * The colors are consecutively the color specified by
 * <CODE>symbolicGridPaint<CODE>
 * (<CODE>DEFAULT_SYMBOLIC_GRID_LINE_PAINT</CODE> by default) and white.
 * or if <CODE>firstGridLineIsDark</CODE> is <CODE>true</CODE> white and
 * the color specified by <CODE>symbolicGridPaint<CODE>.
 *
 * @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 firstGridLineIsDark   True: the first symbolic grid line take the
 *      color of <CODE>symbolicGridPaint<CODE>.
 *      False: the first symbolic grid line is white.
 * @param ticks  a list of ticks.
 */
public void drawSymbolicGridLinesVertical(Graphics2D g2, Rectangle2D drawArea,
                                          Rectangle2D plotArea, boolean firstGridLineIsDark,
                                          List ticks) {

    this.symbolicGridLineList = new Vector(ticks.size());
    boolean currentGridLineIsDark = firstGridLineIsDark;
    double xx = plotArea.getX();
    double yy1, yy2;

    //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 symbolicGridLine;
    while (iterator.hasNext()) {
        tick = (ValueTick) iterator.next();
        yy1 = valueToJava2D(tick.getValue() + 0.5d, plotArea, RectangleEdge.LEFT);
        yy2 = valueToJava2D(tick.getValue() - 0.5d, plotArea, RectangleEdge.LEFT);
        if (currentGridLineIsDark) {
            g2.setPaint(this.symbolicGridPaint);
            //g2.setXORMode((Color) getSymbolicGridPaint());
        }
        else {
            g2.setPaint(Color.white);
            //g2.setXORMode(Color.white);
        }
        symbolicGridLine = new Rectangle2D.Double(xx + outlineStrokeWidth,
            yy1, plotArea.getMaxX() - xx - outlineStrokeWidth, yy2 - yy1);
        g2.fill(symbolicGridLine);
        this.symbolicGridLineList.add(symbolicGridLine);
        currentGridLineIsDark = !currentGridLineIsDark;
    }
    g2.setPaintMode();
}
 
Example 20
Project: FreeCol   File: ImageLibrary.java   View Source Code Vote up 3 votes
/**
 * Fills a certain rectangle with the image texture.
 * 
 * @param g2 The {@code Graphics} used for painting the border.
 * @param img The {@code BufferedImage} to fill the texture.
 * @param x The x-component of the offset.
 * @param y The y-component of the offset.
 * @param width The width of the rectangle.
 * @param height The height of the rectangle.
 */
public static void fillTexture(Graphics2D g2, BufferedImage img,
                               int x, int y, int width, int height) {
    Rectangle anchor = new Rectangle(
        x, y, img.getWidth(), img.getHeight());
    TexturePaint paint = new TexturePaint(img, anchor);
    g2.setPaint(paint);
    g2.fillRect(x, y, width, height);
}