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

The following are Jave code examples for showing how to use setPaintMode() 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: rapidminer   File: AbstractChartPanel.java   View Source Code Vote up 6 votes
/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 * 
 * @param g2
 *            the graphics device.
 * @param x
 *            the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {

	Rectangle2D dataArea = getScreenDataArea();

	g2.setXORMode(Color.orange);
	if ((int) dataArea.getMinX() < x && x < (int) dataArea.getMaxX()) {

		if (this.verticalTraceLine != null) {
			g2.draw(this.verticalTraceLine);
			this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
		} else {
			this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
		}
		g2.draw(this.verticalTraceLine);
	}

	// Reset to the default 'overwrite' mode
	g2.setPaintMode();
}
 
Example 2
Project: rapidminer   File: AbstractChartPanel.java   View Source Code Vote up 6 votes
/**
 * Draws a horizontal line used to trace the mouse position to the vertical axis.
 * 
 * @param g2
 *            the graphics device.
 * @param y
 *            the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {

	Rectangle2D dataArea = getScreenDataArea();

	g2.setXORMode(Color.orange);
	if ((int) dataArea.getMinY() < y && y < (int) dataArea.getMaxY()) {

		if (this.horizontalTraceLine != null) {
			g2.draw(this.horizontalTraceLine);
			this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
		} else {
			this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
		}
		g2.draw(this.horizontalTraceLine);
	}

	// Reset to the default 'overwrite' mode
	g2.setPaintMode();
}
 
Example 3
Project: rapidminer   File: LinkAndBrushChartPanel.java   View Source Code Vote up 6 votes
/**
 * Draws zoom rectangle (if present). 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 g2
 *            the graphics device.
 * @param xor
 *            use XOR for drawing?
 */
private void drawZoomRectangle(Graphics2D g2, boolean xor) {
	Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle");
	if (zoomRectangle != null) {
		// fix rectangle parameters when chart is transformed
		zoomRectangle = coordinateTransformation.transformRectangle(zoomRectangle, this);
		if (!(coordinateTransformation instanceof NullCoordinateTransformation)) {
			g2 = coordinateTransformation.getTransformedGraphics(this);
		}
		if (xor) {
			// Set XOR mode to draw the zoom rectangle
			g2.setXORMode(Color.gray);
		}
		if ((Boolean) getChartFieldValueByName("fillZoomRectangle")) {
			g2.setPaint((Paint) getChartFieldValueByName("zoomFillPaint"));
			g2.fill(zoomRectangle);
		} else {
			g2.setPaint((Paint) getChartFieldValueByName("zoomOutlinePaint"));
			g2.draw(zoomRectangle);
		}
		if (xor) {
			// Reset to the default 'overwrite' mode
			g2.setPaintMode();
		}
	}
}
 
Example 4
Project: OpenJSharp   File: WTrayIconPeer.java   View Source Code Vote up 6 votes
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
Example 5
Project: parabuild-ci   File: ChartPanel.java   View Source Code Vote up 6 votes
/**
 * Draws a vertical line used to trace the mouse position to the horizontal 
 * axis.
 *
 * @param g2 the graphics device.
 * @param x  the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {

        if (this.verticalTraceLine != null) {
            g2.draw(this.verticalTraceLine);
            this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, 
                    (int) dataArea.getMaxY());
        }
        else {
            this.verticalTraceLine = new Line2D.Float(x, 
                    (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        }
        g2.draw(this.verticalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}
 
Example 6
Project: parabuild-ci   File: ChartPanel.java   View Source Code Vote up 6 votes
/**
 * Draws a horizontal line used to trace the mouse position to the vertical
 * axis.
 *
 * @param g2 the graphics device.
 * @param y  the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {

        if (this.horizontalTraceLine != null) {
            g2.draw(this.horizontalTraceLine);
            this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, 
                    (int) dataArea.getMaxX(), y);
        }
        else {
            this.horizontalTraceLine = new Line2D.Float(
                    (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), 
                    y);
        }
        g2.draw(this.horizontalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}
 
Example 7
Project: jdk8u-jdk   File: WTrayIconPeer.java   View Source Code Vote up 6 votes
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();

    BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT,
                                               BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)),
                         (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
Example 8
Project: parabuild-ci   File: ChartPanel.java   View Source Code Vote up 5 votes
/**
 * Draws zoom rectangle (if present).
 * 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 g2 the graphics device. 
 */
private void drawZoomRectangle(Graphics2D g2) {
    // Set XOR mode to draw the zoom rectangle
    g2.setXORMode(Color.gray);
    if (this.zoomRectangle != null) {
        if (this.fillZoomRectangle) {
            g2.fill(this.zoomRectangle);
        }
        else {
            g2.draw(this.zoomRectangle);
        }
    }
    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}
 
Example 9
Project: jdk8u-jdk   File: ITXtTest.java   View Source Code Vote up 5 votes
private static BufferedImage createBufferedImage() {
    BufferedImage image = new BufferedImage(128, 128,
                  BufferedImage.TYPE_4BYTE_ABGR_PRE);
    Graphics2D graph = image.createGraphics();
    graph.setPaintMode();
    graph.setColor(Color.orange);
    graph.fillRect(32, 32, 64, 64);
    graph.dispose();
    return image;
}
 
Example 10
Project: openjdk-jdk10   File: WTrayIconPeer.java   View Source Code Vote up 5 votes
synchronized void updateNativeImage(Image image) {
    if (isDisposed())
        return;

    boolean autosize = ((TrayIcon)target).isImageAutoSize();
    AffineTransform tx = GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().
            getDefaultTransform();
    int w = Region.clipScale(TRAY_ICON_WIDTH, tx.getScaleX());
    int h = Region.clipScale(TRAY_ICON_HEIGHT, tx.getScaleY());
    int imgWidth = Region.clipScale(image.getWidth(observer), tx.getScaleX());
    int imgHeight = Region.clipScale(image.getHeight(observer), tx.getScaleY());
    BufferedImage bufImage = new BufferedImage(w,
            h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gr = bufImage.createGraphics();
    if (gr != null) {
        try {
            gr.setPaintMode();

            gr.drawImage(image, 0, 0, (autosize ? w : imgWidth),
                         (autosize ? h : imgHeight), observer);

            createNativeImage(bufImage);

            updateNativeIcon(!firstUpdate);
            if (firstUpdate) firstUpdate = false;

        } finally {
            gr.dispose();
        }
    }
}
 
Example 11
Project: openjdk-jdk10   File: ITXtTest.java   View Source Code Vote up 5 votes
private static BufferedImage createBufferedImage() {
    BufferedImage image = new BufferedImage(128, 128,
                  BufferedImage.TYPE_4BYTE_ABGR_PRE);
    Graphics2D graph = image.createGraphics();
    graph.setPaintMode();
    graph.setColor(Color.orange);
    graph.fillRect(32, 32, 64, 64);
    graph.dispose();
    return image;
}
 
Example 12
Project: sbc-qsystem   File: Uses.java   View Source Code Vote up 5 votes
static void renderSplashFrame(Graphics2D g, int frame) {
    final String[] comps = {"foo", "bar", "baz"};
    g.setComposite(AlphaComposite.Clear);
    g.fillRect(120, 140, 200, 40);
    g.setPaintMode();
    g.setColor(Color.BLACK);
    g.drawString("Loading " + comps[(frame / 5) % 3] + "...", 120, 150);
}
 
Example 13
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 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 firstGridLineIsDark  True: the first symbolic grid line take the
 *                             color of <CODE>symbolicGridPaint<CODE>.
 *                             False: the first symbolic grid line is white.
 * @param ticks  the ticks.
 */
public void drawSymbolicGridLinesHorizontal(Graphics2D g2,
                                            Rectangle2D plotArea, 
                                            Rectangle2D dataArea,
                                            boolean firstGridLineIsDark, 
                                            List ticks) {

    this.symbolicGridLineList = new Vector(ticks.size());
    boolean currentGridLineIsDark = firstGridLineIsDark;
    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 symbolicGridLine;
    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 (currentGridLineIsDark) {
            g2.setPaint(this.symbolicGridPaint);
            //g2.setXORMode((Color) this.symbolicGridPaint);
        }
        else {
            g2.setPaint(Color.white);
            //g2.setXORMode(Color.white);
        }
        symbolicGridLine =
            new Rectangle2D.Double(xx1,
                                   yy + outlineStrokeWidth, xx2 - xx1,
                                   dataArea.getMaxY() - yy - outlineStrokeWidth);
        g2.fill(symbolicGridLine);
        this.symbolicGridLineList.add(symbolicGridLine);
        currentGridLineIsDark = !currentGridLineIsDark;
    }
    g2.setPaintMode();
}
 
Example 14
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 15
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 16
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 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.
 */
protected void drawGridBandsVertical(Graphics2D g2, 
                                     Rectangle2D drawArea,
                                     Rectangle2D plotArea, 
                                     boolean firstGridBandIsDark,
                                     List ticks) {

    boolean currentGridBandIsDark = firstGridBandIsDark;
    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();
        yy1 = valueToJava2D(tick.getValue() + 0.5d, plotArea, 
                RectangleEdge.LEFT);
        yy2 = valueToJava2D(tick.getValue() - 0.5d, plotArea, 
                RectangleEdge.LEFT);
        if (currentGridBandIsDark) {
            g2.setPaint(this.gridBandPaint);
        }
        else {
            g2.setPaint(Color.white);
        }
        band = new Rectangle2D.Double(xx + outlineStrokeWidth, yy1, 
                plotArea.getMaxX() - xx - outlineStrokeWidth, yy2 - yy1);
        g2.fill(band);
        currentGridBandIsDark = !currentGridBandIsDark;
    }
    g2.setPaintMode();
}