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

The following examples show how to use java.awt.Graphics2D#setPaintMode() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static void updateSplashMessage(SplashScreen splash, String message) {
	// Splash screen may not be present
	if (splash != null) {
		Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 10);
		Graphics2D g = splash.createGraphics();
		g.setFont(font);
		g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

		// Wipe out any previous text
		g.setColor(new Color(238, 238, 238)); // #EEEEEE
		g.setPaintMode();
		g.fillRect(12, 70, 250, 30); // (x,y) is top left corner of area

		// Draw next text
		g.setColor(new Color(96, 96, 96)); // #606060
		g.setPaintMode();
		g.drawString(message, 17, 86); // (x,y) is baseline of text

		splash.update();
	}
}
 
Example 2
/**
 * 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
/**
 * 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 4
/**
 * 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) {
    if (this.zoomRectangle != null) {
        if (xor) {
             // Set XOR mode to draw the zoom rectangle
            g2.setXORMode(Color.gray);
        }
        if (this.fillZoomRectangle) {
            g2.setPaint(this.zoomFillPaint);
            g2.fill(this.zoomRectangle);
        }
        else {
            g2.setPaint(this.zoomOutlinePaint);
            g2.draw(this.zoomRectangle);
        }
        if (xor) {
            // Reset to the default 'overwrite' mode
            g2.setPaintMode();
        }
    }
}
 
Example 5
/**
 * 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) {
    if (this.zoomRectangle != null) {
        if (xor) {
             // Set XOR mode to draw the zoom rectangle
            g2.setXORMode(Color.gray);
        }
        if (this.fillZoomRectangle) {
            g2.setPaint(this.zoomFillPaint);
            g2.fill(this.zoomRectangle);
        }
        else {
            g2.setPaint(this.zoomOutlinePaint);
            g2.draw(this.zoomRectangle);
        }
        if (xor) {
            // Reset to the default 'overwrite' mode
            g2.setPaintMode();
        }
    }
}
 
Example 6
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 7
Source Project: astor   File: ChartPanel.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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) {
    if (this.zoomRectangle != null) {
        if (xor) {
             // Set XOR mode to draw the zoom rectangle
            g2.setXORMode(Color.gray);
        }
        if (this.fillZoomRectangle) {
            g2.setPaint(this.zoomFillPaint);
            g2.fill(this.zoomRectangle);
        }
        else {
            g2.setPaint(this.zoomOutlinePaint);
            g2.draw(this.zoomRectangle);
        }
        if (xor) {
            // Reset to the default 'overwrite' mode
            g2.setPaintMode();
        }
    }
}
 
Example 8
/**
 * 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 9
private static void paintSplashScreen() {
	if (isVisible()) {
		try {
			if (splashScreen != null) {
				Graphics2D g = splashScreen.createGraphics();
				if (g != null) {
					g.setComposite(AlphaComposite.Clear);
					Dimension size = splashScreen.getSize();
					g.fillRect(0, 0, size.width, size.height);
					g.setPaintMode();
					paint(g);
					splashScreen.update();
				}
			}
		} catch (IllegalStateException ex) {
			LOG.info("SplashScreen: Closed before painting ended (NO PROBLEM)");
		}
	}
}
 
Example 10
Source Project: jclic   File: BoxConnector.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void drawLine(Graphics2D g2, Point2D origin, Point2D dest, boolean arrow, Color color, Color xorColor,
    double arrow_l, double arrowAngle, float strokeWidth) {
  Stroke oldStroke = g2.getStroke();
  Object oldStrokeHint = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
  g2.setColor(color);
  if (USE_XOR && xorColor != null)
    g2.setXORMode(xorColor);
  g2.setStroke(strokeWidth == LINE_WIDTH ? BASIC_STROKE : new BasicStroke(strokeWidth));
  g2.drawLine((int) origin.getX(), (int) origin.getY(), (int) dest.getX(), (int) dest.getY());
  if (arrow) {
    double beta = Math.atan2(origin.getY() - dest.getY(), dest.getX() - origin.getX());
    Point2D arp = new Point2D.Double(dest.getX() - arrow_l * Math.cos(beta + arrowAngle),
        dest.getY() + arrow_l * Math.sin(beta + arrowAngle));
    g2.drawLine((int) dest.getX(), (int) dest.getY(), (int) arp.getX(), (int) arp.getY());
    arp.setLocation(dest.getX() - arrow_l * Math.cos(beta - arrowAngle),
        dest.getY() + arrow_l * Math.sin(beta - arrowAngle));
    g2.drawLine((int) dest.getX(), (int) dest.getY(), (int) arp.getX(), (int) arp.getY());
  }
  if (USE_XOR && xorColor != null)
    g2.setPaintMode();
  g2.setStroke(oldStroke);
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, oldStrokeHint);
}
 
Example 11
/**
 * 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 12
Source Project: SIMVA-SoS   File: ChartPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
    if (this.zoomRectangle != null) {
        if (xor) {
             // Set XOR mode to draw the zoom rectangle
            g2.setXORMode(Color.gray);
        }
        if (this.fillZoomRectangle) {
            g2.setPaint(this.zoomFillPaint);
            g2.fill(this.zoomRectangle);
        }
        else {
            g2.setPaint(this.zoomOutlinePaint);
            g2.draw(this.zoomRectangle);
        }
        if (xor) {
            // Reset to the default 'overwrite' mode
            g2.setPaintMode();
        }
    }
}
 
Example 13
Source Project: jdk8u-jdk   File: ITXtTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 14
Source Project: pdfxtk   File: ProjectionProfiles.java    License: Apache License 2.0 5 votes vote down vote up
public void paintObject(Graphics2D g) {
  g.drawLine(x, y+ascent, x+width, y+ascent);
  g.drawLine(x, y+baseline, x+width, y+baseline);

  g.setXORMode(java.awt.Color.white);
  profile.paint(g, ProjectionProfile.VERTICAL, x, y);
  g.setPaintMode();
}
 
Example 15
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 16
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 17
public void drawPreview(Graphics2D g2, Rectangle bounds, int margin) {
  Rectangle r = new Rectangle(bounds.x + margin, bounds.y + margin, bounds.width - 2 * margin,
      bounds.height - 2 * margin);
  g2.setXORMode(Color.white);
  Stroke str = g2.getStroke();
  g2.setStroke(dashedStroke);
  g2.draw(r);
  g2.setPaintMode();
  g2.setStroke(str);
}
 
Example 18
Source Project: astor   File: ChartPanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 19
Source Project: opensim-gui   File: SymbolAxis.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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;
    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();
        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();
}
 
Example 20
Source Project: astor   File: SymbolAxis.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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();
}