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

The following examples show how to use java.awt.Graphics2D#setXORMode() . 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
Source File: ChartPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a vertical line used to trace the mouse position to the horizontal 
 * axis.
 *
 * @param x  the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(int x) {

    Graphics2D g2 = (Graphics2D) getGraphics();
    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(java.awt.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);
    }

}
 
Example 2
Source File: CustomCompositeTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: ChartPanel.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Source File: ImageCursorOverlay.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private void drawCursor(Graphics2D graphics, Viewport viewport, PixelPos pixelPos) {
    AffineTransform i2mTransform = sceneView.getBaseImageLayer().getImageToModelTransform();
    AffineTransform m2vTransform = viewport.getModelToViewTransform();
    AffineTransform i2vTransform = new AffineTransform(m2vTransform);
    i2vTransform.concatenate(i2mTransform);

    Point centerPixel = new Point((int) Math.floor(pixelPos.x), (int) Math.floor(pixelPos.y));
    Rectangle pixelImageRect = new Rectangle(centerPixel, new Dimension(1, 1));

    Rectangle2D pixelViewRect = i2vTransform.createTransformedShape(pixelImageRect).getBounds2D();
    graphics.setStroke(cursorStroke);
    graphics.setColor(cursorColor);
    graphics.setXORMode(Color.BLACK);
    graphics.draw(pixelViewRect);

    if (pixelViewRect.getBounds2D().getWidth() < MAX_CROSSHAIR_SIZE) {
        drawCrosshair(graphics, i2vTransform, centerPixel, pixelViewRect);
    }
}
 
Example 5
Source File: ChartPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a horizontal line used to trace the mouse position to the vertical
 * axis.
 *
 * @param y  the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(int y) {

    Graphics2D g2 = (Graphics2D) getGraphics();
    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(java.awt.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);
    }

}
 
Example 6
Source File: cfImageData.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the Graphics2D object, applying all the standard propeties to it
 * @return
 */
public Graphics2D createGraphics() {
	Graphics2D g2 = image.createGraphics();
	
	if ( bAntiAlias )
		g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
	
	g2.setBackground( getBackgroundColor() );
	g2.setColor( getActiveColor() );
	
	if ( xorMode != null )
		g2.setXORMode(xorMode);
	else
		g2.setPaintMode();
	
	return g2;
}
 
Example 7
Source File: IncorrectClipXorModeSurface2Surface.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: ChartPanel.java    From astor with 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 9
Source File: IncorrectClipXorModeSurface2Surface.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: IncorrectClipXorModeSurface2Surface.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: AcceleratedXORModeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
void draw(Graphics2D g) {
    g.setColor(backColor);
    g.fillRect(0, 0, width, height);
    g.setXORMode(xorColor1);
    drawPattern(g, 100);
    g.setXORMode(xorColor2);
    drawPattern(g, 400);
    g.dispose();
}
 
Example 12
Source File: IncorrectClipXorModeSurface2Surface.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 13
Source File: GlyphBrowser.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void renderItems (Graphics2D g)
{
    // Mark the current glyph
    int index = navigator.getIndex();

    if (index >= 0) {
        String gName = names.get(index);
        Glyph glyph = navigator.getGlyph(gName);
        g.setColor(Color.black);
        g.setXORMode(Color.darkGray);
        renderGlyphArea(glyph, g);
    }
}
 
Example 14
Source File: AcceleratedXORModeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
void draw(Graphics2D g) {
    g.setColor(backColor);
    g.fillRect(0, 0, width, height);
    g.setXORMode(xorColor1);
    drawPattern(g, 100);
    g.setXORMode(xorColor2);
    drawPattern(g, 400);
    g.dispose();
}
 
Example 15
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
private void doBoxSelect(MouseEvent e) {
   // if no initial boxSelect point was set, ignore dragging...
   if (this.boxSelectPoint == null)
      return;

   Graphics2D g2 = (Graphics2D) getGraphics();

   // Use XOR to erase the old rectangle, if any.
   g2.setXORMode(boxSelectColor);
   if (this.boxSelectRectangle != null)
      g2.draw(this.boxSelectRectangle);
   // Save the current paint color. You need to restore it
   // after highlighting the control points in order for
   // the XOR drawing of the box to work properly.
   Paint savedPaint = g2.getPaint();
   g2.setPaintMode();

   Rectangle2D scaledDataArea = getScreenDataArea(
      (int) this.boxSelectPoint.getX(), (int) this.boxSelectPoint.getY());
   // Box can be dragged in any direction, so compute proper min and max
   // given direction of drag and bounds of data area.
   double xmin=0, xmax=0, ymin=0, ymax=0;
   if (e.getX() < this.boxSelectPoint.getX()) {
      xmin = Math.max(e.getX(), scaledDataArea.getMinX());
      xmax = this.boxSelectPoint.getX();
   } else {
      xmin = this.boxSelectPoint.getX();
      xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
   }
   if (e.getY() < this.boxSelectPoint.getY()) {
      ymin = Math.max(e.getY(), scaledDataArea.getMinY());
      ymax = this.boxSelectPoint.getY();
   } else {
      ymin = this.boxSelectPoint.getY();
      ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
   }
   this.boxSelectRectangle = new Rectangle2D.Double(xmin, ymin, xmax - xmin, ymax - ymin);

   XYPlot xyPlot = getChart().getXYPlot();
   ArrayList<FunctionNode> newBoxSelectNodes = getBoxSelectNodes(this.boxSelectRectangle);
   // For the nodes that were picked up with the latest box resizing, toggle their select state
   for (int i=0; i<newBoxSelectNodes.size(); i++) {
      if (oldBoxSelectNodes == null || listContainsNode(newBoxSelectNodes.get(i), oldBoxSelectNodes) == false) {
         toggleSelectedNode(newBoxSelectNodes.get(i).series, newBoxSelectNodes.get(i).node);
         // Draw the control point with the new color
         xyPlot.getRenderer().drawItem(g2, null, getScreenDataArea(), null, xyPlot,
            xyPlot.getDomainAxis(), xyPlot.getRangeAxis(), xyPlot.getDataset(), newBoxSelectNodes.get(i).series,
            newBoxSelectNodes.get(i).node, null, 1);
      }
   }
   // For the nodes that dropped out with the latest box resizing, toggle their select state
   if (oldBoxSelectNodes != null) {
      for (int i=0; i<oldBoxSelectNodes.size(); i++) {
         if (listContainsNode(oldBoxSelectNodes.get(i), newBoxSelectNodes) == false) {
            toggleSelectedNode(oldBoxSelectNodes.get(i).series, oldBoxSelectNodes.get(i).node);
            // Draw the control point with the new color
            xyPlot.getRenderer().drawItem(g2, null, getScreenDataArea(), null, xyPlot,
               xyPlot.getDomainAxis(), xyPlot.getRangeAxis(), xyPlot.getDataset(), oldBoxSelectNodes.get(i).series,
               oldBoxSelectNodes.get(i).node, null, 1);
         }
      }
   }
   oldBoxSelectNodes = newBoxSelectNodes;

   // Use XOR to draw the new rectangle.
   g2.setPaint(savedPaint);
   g2.setXORMode(boxSelectColor);
   if (this.boxSelectRectangle != null)
      g2.draw(this.boxSelectRectangle);

   g2.dispose();
}
 
Example 16
Source File: GraphicsTests.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 17
Source File: GraphicsTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 18
Source File: GraphicsTests.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 19
Source File: ChartPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Handles a 'mouse released' event.  On Windows, we need to check if this 
 * is a popup trigger, but only if we haven't already been tracking a zoom
 * rectangle.
 *
 * @param e  information about the event.
 */
public void mouseReleased(MouseEvent e) {

    if (this.zoomRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        }
        else {
            hZoom = this.domainZoomable;              
            vZoom = this.rangeZoomable;
        }
        
        boolean zoomTrigger1 = hZoom && Math.abs(e.getX() 
            - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY() 
            - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < this.zoomPoint.getX())) 
                || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
                restoreAutoBounds();
            }
            else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea(
                        (int) this.zoomPoint.getX(), 
                        (int) this.zoomPoint.getY());
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() 
                            - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                }
                else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() 
                            - this.zoomPoint.getY());
                }
                else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() 
                            - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() 
                            - this.zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                zoom(zoomArea);
            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }
        else {
            Graphics2D g2 = (Graphics2D) getGraphics();
            g2.setXORMode(java.awt.Color.gray);
            if (this.fillZoomRectangle) {
                g2.fill(this.zoomRectangle);
            }
            else {
                g2.draw(this.zoomRectangle);
            }
            g2.dispose();
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }

}
 
Example 20
Source File: GraphicsTests.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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;
}