List of usage examples for java.awt Graphics2D setXORMode
public abstract void setXORMode(Color c1);
From source file:gda.plots.SimplePlot.java
/** * Part of the implementation of MouseListener - overrides the super class (ChartPanel) implementation so that the * mouse can be used to select a rectangle as well as for zooming. * //ww w. ja va2 s .c o m * @param e * the mouse event which caused the call */ @Override public void mousePressed(MouseEvent e) { // Unless a rectangle is being dragged we just // want to call the super class method (which // deals with zooming) if (rd == null) { super.mousePressed(e); if (magnifyingImage || magnifyingData) { if (e.getButton() == MouseEvent.BUTTON1) { magnifyRectangle = null; magnifyXPoint = e.getX(); magnifyYPoint = e.getY(); } if (!e.isPopupTrigger()) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(dragColour); if (magnifyRectangle != null) { g2.fill(magnifyRectangle); } g2.dispose(); } } } else { rd.mousePressed(e); } }
From source file:gda.plots.SimplePlot.java
/** * Part of the implementation of MouseMotionListener - overrides the super class (ChartPanel) implementation so that * the mouse can be used to select a rectangle as well as for zooming. * //from w w w .ja v a 2s. c o m * @param e * the mouse event which caused the call */ @Override public void mouseDragged(MouseEvent e) { // If the rectangle dragger is not in operation then call the // super class method (to deal with any possible zooming) then // deal with magnifyingImage or magnifyingData. if (rd == null) { super.mouseDragged(e); if ((magnifyingImage || magnifyingData) && (e.getModifiers() & InputEvent.BUTTON3_MASK) == 0) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(dragColour); if (magnifyRectangle != null) { if (magnifyRectangleIsNew) { magnifyRectangleIsNew = false; } else { g2.fill(magnifyRectangle); } } if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) { magnifyWidth = e.getX() - magnifyXPoint; magnifyHeight = e.getY() - magnifyYPoint; } recalculateMagnifyRectangle(e); if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0) { magnifier.update(magnifyRectangle); } if (magnifyRectangle != null) { g2.fill(magnifyRectangle); } g2.dispose(); } } else { rd.mouseDragged(e); } }
From source file:gda.plots.SimplePlot.java
/** * Part of the implementation of MouseListener. Overrides the super class (ChartPanel) implementation so that the * mouse can be used to select a rectangle as well as for zooming. * //w w w. ja v a 2 s . c o m * @see #mousePressed(java.awt.event.MouseEvent) * @see #mouseDragged(java.awt.event.MouseEvent) * @param e * the mouse event which caused the call */ @Override public void mouseReleased(MouseEvent e) { // Unless a rectangle is being dragged we just // want to call the super class method (which // deals with zooming) if (rd == null) { super.mouseReleased(e); if (magnifyingImage || magnifyingData) { // If the button released is BUTTON1 then the rectangle for // magnification will have been resized. if (e.getButton() == MouseEvent.BUTTON1) { magnifyWidth = e.getX() - magnifyXPoint; magnifyHeight = e.getY() - magnifyYPoint; magnifyRectangleIsNew = true; } // If the button released is BUTTON2 then the rectangle will // have been being dragged around. Need to redraw in XOR mode // one // last time to remove rectangle from plot. else if (e.getButton() == MouseEvent.BUTTON2) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(dragColour); if (magnifyRectangle != null) { g2.fill(magnifyRectangle); } g2.dispose(); } recalculateMagnifyRectangle(e); magnifier.update(magnifyRectangle); } } else { rd.mouseReleased(e); } }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
/** * Renders this image/* www .jav a 2 s . c o m*/ * * @return The image data */ private final byte[] render() throws IOException { Graphics2D gfx = (Graphics2D) this.image.getGraphics(); if (config.isFontAntialiasing()) gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int curWidth = config.getTextMarginLeft(); FontRenderContext ctx = new FontRenderContext(null, config.isFontAntialiasing(), false); for (int i = 0; i < charAttsList.size(); i++) { CharAttributes cf = (CharAttributes) charAttsList.get(i); TextLayout text = new TextLayout(cf.getChar() + "", getFont(cf.getName()), ctx); //gfx.getFontRenderContext()); AffineTransform textAt = new AffineTransform(); textAt.translate(curWidth, this.height - cf.getRise()); if (cf.getRotation() != 0) { textAt.rotate(cf.getRotation()); } if (cf.getShearX() > 0.0) textAt.shear(cf.getShearX(), cf.getShearY()); Shape shape = text.getOutline(textAt); curWidth += shape.getBounds().getWidth() + config.getTextSpacing(); if (config.isUseImageBackground()) gfx.setColor(Color.BLACK); else gfx.setXORMode(Color.BLACK); gfx.fill(shape); } if (config.isEffectsNoise()) { noiseEffects(gfx, image); } if (config.isUseTimestamp()) { if (config.isEffectsNoise()) gfx.setColor(Color.WHITE); else gfx.setColor(Color.BLACK); TimeZone tz = TimeZone.getTimeZone(config.getTimestampTZ()); Calendar cal = new GregorianCalendar(tz); SimpleDateFormat formatter; if (config.isUseTimestamp24hr()) formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z"); else formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a, z"); formatter.setTimeZone(tz); Font font = gfx.getFont(); Font newFont = new Font(font.getName(), font.getStyle(), config.getTimestampFontSize()); gfx.setFont(newFont); gfx.drawString(formatter.format(cal.getTime()), config.getTextMarginLeft() * 4, this.height - 1); } return toImageData(image); }
From source file:org.apache.jetspeed.security.mfa.impl.CaptchaImageResource.java
protected void noiseEffects(Graphics2D gfx, BufferedImage image) { // XOR circle int dx = randomInt(width, 2 * width); int dy = randomInt(width, 2 * height); int x = randomInt(0, width / 2); int y = randomInt(0, height / 2); gfx.setXORMode(Color.GRAY); if (config.isFontSizeRandom()) gfx.setStroke(new BasicStroke(randomInt(config.getFontSize() / 8, config.getFontSize() / 2))); else/*from w ww. j a v a2s.c om*/ gfx.setStroke(new BasicStroke(config.getFontSize())); gfx.drawOval(x, y, dx, dy); WritableRaster rstr = image.getRaster(); int[] vColor = new int[3]; int[] oldColor = new int[3]; Random vRandom = new Random(System.currentTimeMillis()); // noise for (x = 0; x < width; x++) { for (y = 0; y < height; y++) { rstr.getPixel(x, y, oldColor); // hard noise vColor[0] = 0 + (int) (Math.floor(vRandom.nextFloat() * 1.03) * 255); // soft noise vColor[0] = vColor[0] ^ (170 + (int) (vRandom.nextFloat() * 80)); // xor to image vColor[0] = vColor[0] ^ oldColor[0]; vColor[1] = vColor[0]; vColor[2] = vColor[0]; rstr.setPixel(x, y, vColor); } } }