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

The following are Jave code examples for showing how to use setXORMode() 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: geomapapp   File: LineSegmentsObject.java   View Source Code Vote up 6 votes
public void drawEdit() {
	if( editShape==null ) return;
	synchronized( map.getTreeLock() ) {
		Graphics2D g = map.getGraphics2D();
		g.setStroke( new BasicStroke( 1f/(float)map.getZoom() ));
		g.setXORMode( Color.white);
		Rectangle2D bounds = editShape.getBounds2D();
		double min = bounds.getX();
		double max = min + bounds.getWidth();
		if( wrap>0. ) {
			Rectangle2D rect = map.getClipRect2D();
			double offset = 0.;
			while( min+offset>rect.getX() ) offset -= wrap;
			while( max+offset< rect.getX() ) offset += wrap;
			g.translate( offset, 0.);
			while( min+offset < rect.getX()+rect.getWidth() ) {
				g.draw( editShape );
				offset += wrap;
				g.translate( wrap, 0.);
			}
		} else {
			g.draw( editShape );
		}
	}
}
 
Example 3
Project: geomapapp   File: CoreColorDisplay.java   View Source Code Vote up 6 votes
public void drawLineAtAge( int currentAge )	{
	if ( exists ) {
		synchronized (getTreeLock()) {
			Graphics2D g = (Graphics2D)getGraphics();
			Rectangle r = getVisibleRect();
			int x1 = r.x;
			int x2 = r.x+r.width;
			g.setXORMode( Color.cyan );
			if ( prevAge != -1)	{
				g.drawLine(x1, prevAge, x2, prevAge);
			}
			g.drawLine(x1, currentAge, x2, currentAge);
			prevAge = currentAge;
		}
	}
}
 
Example 4
Project: openjdk-jdk10   File: CustomCompositeTest.java   View Source Code Vote up 6 votes
public static void renderTest(Graphics2D g2d, int w, int h) {
    g2d.setColor(Color.yellow);
    g2d.fillRect(0, 0, w, h);

    BufferedImage image = getTestImage();
    // draw original image
    g2d.drawRenderedImage(image, null);

    // draw image with custom composite
    g2d.translate(175, 25);
    Composite currentComposite = g2d.getComposite();
    g2d.setComposite(new TestComposite());
    g2d.drawRenderedImage(image, null);
    g2d.setComposite(currentComposite);

    // draw image with XOR
    g2d.translate(175, 25);
    g2d.setXORMode(Color.red);
    g2d.drawRenderedImage(image, null);


    System.out.println("Painting is done...");
}
 
Example 5
Project: geomapapp   File: DataSetGraph.java   View Source Code Vote up 5 votes
/**
	undraws the polygon represented by poly
*/
void unDrawLasso(XYGraph xyg){
	synchronized (xyg.getTreeLock()) {
		Graphics2D g = (Graphics2D) xyg.getGraphics(); 
		g.setXORMode(Color.GRAY);
		for(int i=1;i<poly.npoints;i++) {
			g.drawLine(poly.xpoints[i-1], poly.ypoints[i-1], poly.xpoints[i], poly.ypoints[i]);
		}
	}
}
 
Example 6
Project: QN-ACTR-Release   File: ConnectState.java   View Source Code Vote up 5 votes
@Override
public void handleDrag(MouseEvent e) {

	if (firstPort != null) {
		if (!e.isConsumed()) {
			Graphics2D g = mediator.getGraphGraphics();
			Color bg = mediator.getGraphBackground();
			Color fg = Color.black;
			g.setColor(fg);
			g.setXORMode(bg);
			overlay(g);

			current = mediator.snap(e.getPoint());

			port = getInPortViewAt(e.getX(), e.getY());
			if (port != null) {
				current = mediator.toScreen(port.getLocation(null));
			}

			g.setColor(bg);
			g.setXORMode(fg);
			overlay(g);
			e.consume();
		}
	}

}
 
Example 7
Project: geomapapp   File: LocationInset.java   View Source Code Vote up 5 votes
public void drawBox() {
	synchronized (map.getTreeLock()) {
		Graphics2D g = (Graphics2D) map.getGraphics();
		g.setXORMode(Color.GRAY);
		g.translate(map.getVisibleRect().x, map.getVisibleRect().y);
		g.translate(x, y);
		g.drawRect(0, 0, this.w, this.h);
	}
}
 
Example 8
Project: geomapapp   File: GMAProfile.java   View Source Code Vote up 5 votes
void drawLine() {
	if( currentPath==null )return;
	double wrap = map.getWrap();
	synchronized(map.getTreeLock()) {
		Graphics2D g = map.getGraphics2D();
		g.setStroke( new BasicStroke(2f/(float)map.getZoom()) );
		//g.setColor( Color.red );
		g.setXORMode(Color.white);
		g.draw( currentPath );
		if( wrap>0.) {
			g.translate(wrap,0.);
			g.draw( currentPath );
		}
	}
}
 
Example 9
Project: geomapapp   File: DataSetGraph.java   View Source Code Vote up 5 votes
void drawLine(XYGraph xyg) {
	if( Float.isNaN(lastV) || side==0) return;
	synchronized (xyg.getTreeLock()) {
		Graphics2D g = (Graphics2D)xyg.getGraphics();
		g.transform(dat);
		g.setXORMode( Color.white );
		g.setColor(Color.blue);
		if (side<0) g.drawLine((int)((lastV-x0)*xScale), y1, (int)((lastV-x0)*xScale), y2);
		else g.drawLine(x1, (int)((lastV-y0)*-yScale), x2, (int)((lastV-y0)*-yScale));
	}
}
 
Example 10
Project: geomapapp   File: PDBDataSetGraph.java   View Source Code Vote up 5 votes
/**
	undraws the polygon represented by poly
*/
void unDrawLasso(XYGraph xyg){
	synchronized (xyg.getTreeLock()) {
		Graphics2D g = (Graphics2D) xyg.getGraphics(); 
		g.setXORMode(Color.GRAY);
		for(int i=1;i<poly.npoints;i++) {
			g.drawLine(poly.xpoints[i-1], poly.ypoints[i-1], poly.xpoints[i], poly.ypoints[i]);
		}
	}
}
 
Example 11
Project: geomapapp   File: PDBDataSetGraph.java   View Source Code Vote up 5 votes
/**
	Draws the last line in polygon poly to XYGraph xyg
	Uses XOR mode
*/
void drawLasso(XYGraph xyg) {
	synchronized (xyg.getTreeLock()) {
		Graphics2D g = (Graphics2D) xyg.getGraphics(); 
		g.setXORMode(Color.GRAY);
		int x1 = poly.xpoints[poly.npoints-2];
		int y1 = poly.ypoints[poly.npoints-2];
		int x2 = poly.xpoints[poly.npoints-1];
		int y2 = poly.ypoints[poly.npoints-1];
		g.drawLine(x1, y1, x2, y2);
	}
}
 
Example 12
Project: geomapapp   File: PDB.java   View Source Code Vote up 5 votes
public void drawSelectionBox(){
	synchronized (map.getTreeLock()) {
		Graphics2D g = (Graphics2D) map.getGraphics();
		g.setXORMode(Color.GRAY);
		int x = Math.min(p1.x, p2.x);
		int y = Math.min(p1.y, p2.y);
		int w = Math.max(p1.x, p2.x) - x;
		int h = Math.max(p1.y, p2.y) - y;
		r = new Rectangle(x,y,w,h);
		g.draw(r);
	}
}
 
Example 13
Project: jdk8u-jdk   File: IncorrectClipXorModeSurface2Surface.java   View Source Code Vote up 5 votes
private static void draw(Shape clip, Shape shape, Image from, Image to) {
    Graphics2D g2d = (Graphics2D) to.getGraphics();
    g2d.setXORMode(Color.BLACK);
    g2d.setClip(clip);
    Rectangle toBounds = shape.getBounds();
    g2d.drawImage(from, toBounds.x, toBounds.y, toBounds.width,
                  toBounds.height, null);
    g2d.dispose();
}
 
Example 14
Project: geomapapp   File: AgeDepthModel.java   View Source Code Vote up 5 votes
void drawCursorLine( int xPos, int yPos ) {
	synchronized (graph.getTreeLock()) {
		Graphics2D g = graph.getGraphics2D();
		g.setXORMode( Color.cyan );
		g.drawLine(0, yPos, xPos, yPos);
	}
}
 
Example 15
Project: geomapapp   File: LocationInset.java   View Source Code Vote up 5 votes
public void drawRect(){
	synchronized (map.getTreeLock()) {
		Graphics2D g = (Graphics2D) map.getGraphics();
		g.setXORMode(Color.GRAY);
		g.translate(map.getVisibleRect().x, map.getVisibleRect().y);
		g.translate(x, y);
		g.drawRect((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
	}
}
 
Example 16
Project: Caritemere   File: GuiUtil.java   View Source Code Vote up 5 votes
public BufferedImage tint(BufferedImage src, Color col) {
	BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TRANSLUCENT);
	Graphics2D graphics = img.createGraphics();
	graphics.setXORMode(new Color(col.getRed(), col.getGreen(), col.getBlue(), 0));
	graphics.drawImage(src, null, 0, 0);
	graphics.dispose();
	return img;
}
 
Example 17
Project: geomapapp   File: PhotoDisplay.java   View Source Code Vote up 5 votes
public void drawLineAtAge( int currentAge )	{
	synchronized (getTreeLock()) {
		Graphics2D g = (Graphics2D)getGraphics();
		Rectangle r = getVisibleRect();
		int x1 = r.x;
		int x2 = r.x+r.width;
		g.setXORMode( Color.cyan );
		if ( prevAge != -1)	{
			g.drawLine(x1, prevAge, x2, prevAge);
		}
		g.drawLine(x1, currentAge, x2, currentAge);
		prevAge = currentAge;
	}
}
 
Example 18
Project: openjdk-jdk10   File: IncorrectClipXorModeSurface2Surface.java   View Source Code Vote up 5 votes
private static void draw(Shape clip, Shape shape, Image from, Image to) {
    Graphics2D g2d = (Graphics2D) to.getGraphics();
    g2d.setXORMode(Color.BLACK);
    g2d.setClip(clip);
    Rectangle toBounds = shape.getBounds();
    g2d.drawImage(from, toBounds.x, toBounds.y, toBounds.width,
                  toBounds.height, null);
    g2d.dispose();
}
 
Example 19
Project: geomapapp   File: MGGData.java   View Source Code Vote up 4 votes
protected void drawCurrentPoint() {
	if( map==null || currentPoint==null || !map.isVisible() ) return;
	synchronized (map.getTreeLock() ) {
		Graphics2D g = map.getGraphics2D();
		Graphics2D g2 = map.getGraphics2D();
		float zoom = (float)map.getZoom();

		g.setStroke( new BasicStroke( 5f/ zoom ) );

		Rectangle2D rect = map.getClipRect2D();
		double wrap = map.getWrap();
		if( wrap>0. ) while( currentPoint.x-wrap > rect.getX() ) currentPoint.x-=wrap;
		double size = 10./map.getZoom();

		Arc2D.Double arc = new Arc2D.Double( 0., currentPoint.y, 
						size/6, size/6, 0., 360., Arc2D.CHORD);
		Arc2D.Double arc2 = new Arc2D.Double( 0., currentPoint.y-.5*size, 
				size, size, 0., 360., Arc2D.CHORD);
		if( wrap>0. ) {
			while( currentPoint.x < rect.getX()+rect.getWidth() ) {
				g.setColor(Color.red);
				g.setStroke( new BasicStroke( 5f/ zoom ) );
				g.draw(currentSeg);
				g.setColor(Color.white);
				g.setStroke( new BasicStroke( 2.f/ zoom ) );
				arc.x = currentPoint.x;
				g.draw(arc);
				arc2.x = currentPoint.x-.5*size;
				g2.setXORMode( Color.white );
				g2.setStroke( new BasicStroke( 4f/ zoom ) );
				g2.draw(arc2);
				currentPoint.x += wrap;
			}
		} else {
			g.setColor(Color.red);
			g.setStroke( new BasicStroke( 5f/ zoom ) );
			g.draw(currentSeg);
			g.setColor(Color.white);
			g.setStroke( new BasicStroke( 2.f/ zoom ) );
			arc.x = currentPoint.x;
			g.draw(arc);
			arc2.x = currentPoint.x-.5*size;
			g2.setXORMode( Color.white );
			g2.setStroke( new BasicStroke( 4f/ zoom ) );
			g2.draw(arc2);
		}
	}
}
 
Example 20
Project: jdk8u-jdk   File: GraphicsTests.java   View Source Code Vote up 4 votes
public void initContext(TestEnvironment env, Context ctx) {
    ctx.graphics = env.getGraphics();
    int w = env.getWidth();
    int h = env.getHeight();
    ctx.size = env.getIntValue(sizeList);
    ctx.outdim = getOutputSize(ctx.size, ctx.size);
    ctx.pixscale = 1.0;
    if (hasGraphics2D) {
        Graphics2D g2d = (Graphics2D) ctx.graphics;
        AlphaComposite ac = (AlphaComposite) env.getModifier(compRules);
        if (env.isEnabled(doExtraAlpha)) {
            ac = AlphaComposite.getInstance(ac.getRule(), 0.125f);
        }
        g2d.setComposite(ac);
        if (env.isEnabled(doXor)) {
            g2d.setXORMode(Color.white);
        }
        if (env.isEnabled(doClipping)) {
            Polygon p = new Polygon();
            p.addPoint(0, 0);
            p.addPoint(w, 0);
            p.addPoint(0, h);
            p.addPoint(w, h);
            p.addPoint(0, 0);
            g2d.clip(p);
        }
        Transform tx = (Transform) env.getModifier(transforms);
        Dimension envdim = new Dimension(w, h);
        tx.init(g2d, ctx, envdim);
        w = envdim.width;
        h = envdim.height;
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                             env.getModifier(renderHint));
    }
    switch (env.getIntValue(animList)) {
    case 0:
        ctx.animate = false;
        ctx.maxX = 3;
        ctx.maxY = 1;
        ctx.orgX = (w - ctx.outdim.width) / 2;
        ctx.orgY = (h - ctx.outdim.height) / 2;
        break;
    case 1:
        ctx.animate = true;
        ctx.maxX = Math.max(Math.min(32, w - ctx.outdim.width), 3);
        ctx.maxY = 1;
        ctx.orgX = (w - ctx.outdim.width - ctx.maxX) / 2;
        ctx.orgY = (h - ctx.outdim.height) / 2;
        break;
    case 2:
        ctx.animate = true;
        ctx.maxX = (w - ctx.outdim.width) + 1;
        ctx.maxY = (h - ctx.outdim.height) + 1;
        ctx.maxX = adjustWidth(ctx.maxX, ctx.maxY);
        ctx.maxX = Math.max(ctx.maxX, 3);
        ctx.maxY = Math.max(ctx.maxY, 1);
        // ctx.orgX = ctx.orgY = 0;
        break;
    }
    ctx.initX = ctx.maxX / 2;
    ctx.initY = ctx.maxY / 2;
}