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

The following examples show how to use java.awt.Graphics2D#setClip() . 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: Plot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the background image (if there is one) aligned within the
 * specified area.
 *
 * @param g2  the graphics device.
 * @param area  the area.
 *
 * @see #getBackgroundImage()
 * @see #getBackgroundImageAlignment()
 * @see #getBackgroundImageAlpha()
 */
public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) {
    if (this.backgroundImage == null) {
        return;  // nothing to do
    }
    Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            this.backgroundImageAlpha));
    Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0,
            this.backgroundImage.getWidth(null),
            this.backgroundImage.getHeight(null));
    Align.align(dest, area, this.backgroundImageAlignment);
    Shape savedClip = g2.getClip();
    g2.clip(area);
    g2.drawImage(this.backgroundImage, (int) dest.getX(),
            (int) dest.getY(), (int) dest.getWidth() + 1,
            (int) dest.getHeight() + 1, null);
    g2.setClip(savedClip);
    g2.setComposite(savedComposite);
}
 
Example 2
Source File: Plot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the background image (if there is one) aligned within the
 * specified area.
 *
 * @param g2  the graphics device.
 * @param area  the area.
 *
 * @see #getBackgroundImage()
 * @see #getBackgroundImageAlignment()
 * @see #getBackgroundImageAlpha()
 */
public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) {
    if (this.backgroundImage == null) {
        return;  // nothing to do
    }
    Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            this.backgroundImageAlpha));
    Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0,
            this.backgroundImage.getWidth(null),
            this.backgroundImage.getHeight(null));
    Align.align(dest, area, this.backgroundImageAlignment);
    Shape savedClip = g2.getClip();
    g2.clip(area);
    g2.drawImage(this.backgroundImage, (int) dest.getX(),
            (int) dest.getY(), (int) dest.getWidth() + 1,
            (int) dest.getHeight() + 1, null);
    g2.setClip(savedClip);
    g2.setComposite(savedComposite);
}
 
Example 3
Source File: Plot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a message to state that there is no data to plot.
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 */
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
    Shape savedClip = g2.getClip();
    g2.clip(area);
    String message = this.noDataMessage;
    if (message != null) {
        g2.setFont(this.noDataMessageFont);
        g2.setPaint(this.noDataMessagePaint);
        TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont,
                this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
                new G2TextMeasurer(g2));
        block.draw(g2, (float) area.getCenterX(),
                (float) area.getCenterY(), TextBlockAnchor.CENTER);
    }
    g2.setClip(savedClip);
}
 
Example 4
Source File: SymbolAxis.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the grid bands.  Alternate bands are colored using 
 * <CODE>gridBandPaint<CODE> (<CODE>DEFAULT_GRID_BAND_PAINT</CODE> by 
 * default).
 *
 * @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 edge  the axis location.
 * @param ticks  the ticks.
 */
protected void drawGridBands(Graphics2D g2,
                             Rectangle2D plotArea, 
                             Rectangle2D dataArea,
                             RectangleEdge edge, 
                             List ticks) {

    Shape savedClip = g2.getClip();
    g2.clip(dataArea);
    if (RectangleEdge.isTopOrBottom(edge)) {
        drawGridBandsHorizontal(g2, plotArea, dataArea, true, ticks);
    }
    else if (RectangleEdge.isLeftOrRight(edge)) {
        drawGridBandsVertical(g2, plotArea, dataArea, true, ticks);
    }
    g2.setClip(savedClip);

}
 
Example 5
Source File: IncorrectClipSurface2SW.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void draw(Shape clip, Shape to, Image vi, BufferedImage bi,
                         int scale) {
    Graphics2D big = bi.createGraphics();
    big.setComposite(AlphaComposite.Src);
    big.setClip(clip);
    Rectangle toBounds = to.getBounds();
    int x1 = toBounds.x;

    int y1 = toBounds.y;
    int x2 = x1 + toBounds.width;
    int y2 = y1 + toBounds.height;
    big.drawImage(vi, x1, y1, x2, y2, 0, 0, toBounds.width / scale,
                  toBounds.height / scale, null);
    big.dispose();
    vi.flush();
}
 
Example 6
Source File: PrintableLayers.java    From cncgcodecontroller with MIT License 5 votes vote down vote up
public boolean paintlegend(Graphics2D g2, int index, int jpw, int jph){
    if (index < 0 || index >= keys.length || !Double.isNaN(keys[index])) 
    {
        return false;
    }
    
    jpw=jpw-100;
    Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 16);
    g2.setFont(font);
    int zh      = (int)(font.getStringBounds(Tools.dtostr(100.0), g2.getFontRenderContext()).getHeight()) + 10;                    
    int elements= jph / zh;
    int dy      = (jph-elements * zh) / 2;
    for(int i = 0;i < elements && elements >= 2;i++)
    {
        double z = zmax - i * ((zmax-zmin) / (elements - 1));
        double relative = (z - zmin) / (zmax-zmin);
        relative = Tools.adjustDouble(relative, 0, 1);

        Color c = ColorHelper.numberToColorPercentage(relative);
        g2.setColor(c);
        g2.fillRect(jpw + 5,
                    dy + zh * i,
                    90,
                    zh - 4);
        g2.setColor(((299 * c.getRed() + 587 * c.getGreen() + 114 * c.getBlue())> 128000) ? Color.black:Color.white);
        g2.drawString(Tools.dtostr(z), jpw + 10, dy + zh * i + zh - 10);
        g2.setColor(Color.black);
        g2.drawRect(jpw + 5,
                    dy + zh * i,
                    90,
                    zh - 4);
    }    
    g2.setClip(0,0,jpw,jph);
    
    return true;
}
 
Example 7
Source File: EmptyClipRenderingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Run the test: cycle through all the rectangles, use one as clip and
 * another as the area to render to.
 * Set the clip in the same way Swing does it when repainting:
 * first constrain the graphics to the damaged area, and repaint everything
 */
void runTest(Graphics2D destGraphics) {
    destGraphics.setColor(Color.black);
    destGraphics.fillRect(0, 0, IMG_W, IMG_H);

    destGraphics.setColor(Color.red);
    for (Rectangle clip : rects) {
        Graphics2D g2d = (Graphics2D)destGraphics.create();
        g2d.setColor(Color.red);
        // mimic what swing does in BufferStrategyPaintManager
        if (g2d instanceof ConstrainableGraphics) {
            ((ConstrainableGraphics)g2d).constrain(clip.x, clip.y,
                                                   clip.width, clip.height);
        }
        g2d.setClip(clip);

        for (Rectangle renderRegion : rects) {
            if (renderRegion != clip) {
                // from CellRendererPane's paintComponent
                Graphics2D rG = (Graphics2D)
                    g2d.create(renderRegion.x, renderRegion.y,
                               renderRegion.width, renderRegion.height);
                rG.fillRect(0,0, renderRegion.width, renderRegion.height);
            }
        }
    }
}
 
Example 8
Source File: BrowserPane.java    From SwingBox with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Renders current content to graphic context, which is returned. May return
 * null;
 * 
 * @return the Graphics2D context
 * @see Graphics2D
 */
public Graphics2D renderContent()
{
    View view = null;
    ViewFactory factory = getEditorKit().getViewFactory();
    if (factory instanceof SwingBoxViewFactory)
    {
        view = ((SwingBoxViewFactory) factory).getViewport();
    }

    if (view != null)
    {
        int w = (int) view.getPreferredSpan(View.X_AXIS);
        int h = (int) view.getPreferredSpan(View.Y_AXIS);

        Rectangle rec = new Rectangle(w, h);

        BufferedImage img = new BufferedImage(w, h,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g = img.createGraphics();
        g.setClip(rec);
        view.paint(g, rec);

        return g;
    }

    return null;
}
 
Example 9
Source File: IncorrectClipXorModeSurface2Surface.java    From dragonwell8_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 10
Source File: RenderToCustomBufferTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void renderTo(BufferedImage dst) {
    System.out.println("The buffer: " + dst);
    Graphics2D g = dst.createGraphics();

    final int w = dst.getWidth();
    final int h = dst.getHeight();

    g.setColor(Color.blue);
    g.fillRect(0, 0, w, h);

    g.setColor(Color.red);
    Font f = g.getFont();
    g.setFont(f.deriveFont(48f));

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    // NB: this clip ctriggers the problem
    g.setClip(50, 50, 200, 100);

    g.drawString("AA Text", 52, 90);

    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
           RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

    // NB: this clip ctriggers the problem
    g.setClip(50, 100, 100, 100);
    g.drawString("Text", 52, 148);

    g.dispose();
}
 
Example 11
Source File: IncorrectClipXorModeSW2Surface.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 12
Source File: DirectScrollPanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @return A {@link Img} containing the currently visible header and contents (no scroll bars).
 *         If something goes wrong (unable to allocate an offscreen buffer, for instance), then
 *         {@code null} may be returned.
 */
public Img createImage() {
    int        width     = mHeaderBounds.width;
    int        height    = mHeaderBounds.height + mContentBounds.height;
    Img        offscreen = null;
    Graphics2D g2d       = null;
    synchronized (getTreeLock()) {
        try {
            offscreen = Img.create(getGraphicsConfiguration(), width, height, Transparency.TRANSLUCENT);
            g2d = offscreen.getGraphics();
            Color saved = g2d.getBackground();
            g2d.setBackground(new Color(0, true));
            g2d.clearRect(0, 0, width, height);
            g2d.setBackground(saved);
            Insets insets = getInsets();
            g2d.translate(-insets.left, -insets.top);
            Rectangle clip = new Rectangle(0, 0, width, height);
            g2d.setClip(clip);
            paint(g2d);
        } catch (Exception exception) {
            Log.error(exception);
        } finally {
            if (g2d != null) {
                g2d.dispose();
            }
        }
    }
    return offscreen;
}
 
Example 13
Source File: CSSBorder.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void paintBorder(Component c, Graphics g,
                                    int x, int y, int width, int height) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D) g.create();

    int[] widths = getWidths();

    // Position and size of the border interior.
    int intX = x + widths[LEFT];
    int intY = y + widths[TOP];
    int intWidth = width - (widths[RIGHT] + widths[LEFT]);
    int intHeight = height - (widths[TOP] + widths[BOTTOM]);

    // Coordinates of the interior corners, from NW clockwise.
    int[][] intCorners = {
        { intX, intY },
        { intX + intWidth, intY },
        { intX + intWidth, intY + intHeight },
        { intX, intY + intHeight, },
    };

    // Draw the borders for all sides.
    for (int i = 0; i < 4; i++) {
        Value style = getBorderStyle(i);
        Polygon shape = getBorderShape(i);
        if ((style != Value.NONE) && (shape != null)) {
            int sideLength = (i % 2 == 0 ? intWidth : intHeight);

            // "stretch" the border shape by the interior area dimension
            shape.xpoints[2] += sideLength;
            shape.xpoints[3] += sideLength;
            Color color = getBorderColor(i);
            BorderPainter painter = getBorderPainter(i);

            double angle = i * Math.PI / 2;
            g2.setClip(g.getClip()); // Restore initial clip
            g2.translate(intCorners[i][0], intCorners[i][1]);
            g2.rotate(angle);
            g2.clip(shape);
            painter.paint(shape, g2, color, i);
            g2.rotate(-angle);
            g2.translate(-intCorners[i][0], -intCorners[i][1]);
        }
    }
    g2.dispose();
}
 
Example 14
Source File: TrafficLight.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public BufferedImage createHousingImage(final int WIDTH, final int HEIGHT) {
    final GraphicsConfiguration GFX_CONF = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    if (WIDTH <= 0 || HEIGHT <= 0) {
        return GFX_CONF.createCompatibleImage(1, 1, java.awt.Transparency.TRANSLUCENT);
    }
    final BufferedImage IMAGE = GFX_CONF.createCompatibleImage(WIDTH, HEIGHT, Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();
    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    final int IMAGE_WIDTH = IMAGE.getWidth();
    final int IMAGE_HEIGHT = IMAGE.getHeight();
    final RoundRectangle2D HOUSING_BACK = new RoundRectangle2D.Double(0.0 * IMAGE_WIDTH, 0.0 * IMAGE_HEIGHT, 1.0 * IMAGE_WIDTH, 1.0 * IMAGE_HEIGHT, 0.21428571428571427 * IMAGE_WIDTH, 0.07553956834532374 * IMAGE_HEIGHT);
    G2.setPaint(new LinearGradientPaint(new Point2D.Double(0.04081632653061224 * IMAGE_WIDTH, 0.007194244604316547 * IMAGE_HEIGHT), new Point2D.Double(0.9521011364730593 * IMAGE_WIDTH, 0.9958824935586308 * IMAGE_HEIGHT), new float[]{0.0f, 0.01f, 0.09f, 0.24f, 0.55f, 0.78f, 0.98f, 1.0f}, new Color[]{new Color(0.5960784314f, 0.5960784314f, 0.6039215686f, 1f), new Color(0.5960784314f, 0.5960784314f, 0.6039215686f, 1f), new Color(0.2f, 0.2f, 0.2f, 1f), new Color(0.5960784314f, 0.5960784314f, 0.6039215686f, 1f), new Color(0.1215686275f, 0.1215686275f, 0.1215686275f, 1f), new Color(0.2117647059f, 0.2117647059f, 0.2117647059f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f)}));
    G2.fill(HOUSING_BACK);

    final RoundRectangle2D HOUSING_FRONT = new RoundRectangle2D.Double(0.030612244897959183 * IMAGE_WIDTH, 0.01079136690647482 * IMAGE_HEIGHT, 0.9387755102040817 * IMAGE_WIDTH, 0.9784172661870504 * IMAGE_HEIGHT, 0.1683673469387755 * IMAGE_WIDTH, 0.05935251798561151 * IMAGE_HEIGHT);
    G2.setPaint(new LinearGradientPaint(new Point2D.Double(-0.1326530612244898 * IMAGE_WIDTH, -0.0539568345323741 * IMAGE_HEIGHT), new Point2D.Double(2.0614080436330213 * IMAGE_WIDTH, 0.6672932297063833 * IMAGE_HEIGHT), new float[]{0.0f, 0.01f, 0.16f, 0.31f, 0.44f, 0.65f, 0.87f, 0.98f, 1.0f}, new Color[]{new Color(0f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0.2156862745f, 0.2156862745f, 0.2078431373f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0.1882352941f, 0.1882352941f, 0.1882352941f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0.2117647059f, 0.2117647059f, 0.2117647059f, 1f), new Color(0f, 0f, 0f, 1f), new Color(0f, 0f, 0f, 1f)}));
    G2.fill(HOUSING_FRONT);

    final Random BW_RND = new Random();
    final Random ALPHA_RND = new Random();
    G2.setClip(HOUSING_FRONT);
    final Color DARK_NOISE = new Color(0.2f, 0.2f, 0.2f);
    final Color BRIGHT_NOISE = new Color(0.8f, 0.8f, 0.8f);
    Color noiseColor;
    int noiseAlpha;
    for (int y = 0 ; y < HOUSING_FRONT.getHeight() ; y ++) {
        for (int x = 0 ; x < HOUSING_FRONT.getWidth() ; x ++) {
            if (BW_RND.nextBoolean()) {
                noiseColor = BRIGHT_NOISE;
            } else {
                noiseColor = DARK_NOISE;
            }
            noiseAlpha = 10 + ALPHA_RND.nextInt(10) - 5;
            G2.setColor(new Color(noiseColor.getRed(), noiseColor.getGreen(), noiseColor.getBlue(), noiseAlpha));
            G2.drawLine((int) (x + HOUSING_FRONT.getMinX()), (int) (y + HOUSING_FRONT.getMinY()), (int) (x + HOUSING_FRONT.getMinX()), (int) (y + HOUSING_FRONT.getMinY()));
        }
    }


    G2.dispose();
    return IMAGE;
}
 
Example 15
Source File: BiomeWidget.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
@CalledOnlyBy(AmidstThread.EDT)
private void clearClip(Graphics2D g2d) {
	g2d.setClip(null);
}
 
Example 16
Source File: WaferMapPlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Calculates and draws the chip locations on the wafer.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 */
protected void drawChipGrid(Graphics2D g2, Rectangle2D plotArea) {

    Shape savedClip = g2.getClip();
    g2.setClip(getWaferEdge(plotArea));
    Rectangle2D chip = new Rectangle2D.Double();
    int xchips = 35;
    int ychips = 20;
    double space = 1d;
    if (this.dataset != null) {
        xchips = this.dataset.getMaxChipX() + 2;
        ychips = this.dataset.getMaxChipY() + 2;
        space = this.dataset.getChipSpace();
    }
    double startX = plotArea.getX();
    double startY = plotArea.getY();
    double chipWidth = 1d;
    double chipHeight = 1d;
    if (plotArea.getWidth() != plotArea.getHeight()) {
        double major, minor;
        if (plotArea.getWidth() > plotArea.getHeight()) {
            major = plotArea.getWidth();
            minor = plotArea.getHeight();
        }
        else {
            major = plotArea.getHeight();
            minor = plotArea.getWidth();
        }
        //set upperLeft point
        if (plotArea.getWidth() == minor) { // x is minor
            startY += (major - minor) / 2;
            chipWidth = (plotArea.getWidth() - (space * xchips - 1))
                / xchips;
            chipHeight = (plotArea.getWidth() - (space * ychips - 1))
                / ychips;
        }
        else { // y is minor
            startX += (major - minor) / 2;
            chipWidth = (plotArea.getHeight() - (space * xchips - 1))
                / xchips;
            chipHeight = (plotArea.getHeight() - (space * ychips - 1))
                / ychips;
        }
    }

    for (int x = 1; x <= xchips; x++) {
        double upperLeftX = (startX - chipWidth) + (chipWidth * x)
            + (space * (x - 1));
        for (int y = 1; y <= ychips; y++) {
            double upperLeftY = (startY - chipHeight) + (chipHeight * y)
                + (space * (y - 1));
            chip.setFrame(upperLeftX, upperLeftY, chipWidth, chipHeight);
            g2.setColor(Color.white);
            if (this.dataset.getChipValue(x - 1, ychips - y - 1) != null) {
                g2.setPaint(
                    this.renderer.getChipColor(
                        this.dataset.getChipValue(x - 1, ychips - y - 1)
                    )
                );
            }
            g2.fill(chip);
            g2.setColor(Color.lightGray);
            g2.draw(chip);
        }
    }
    g2.setClip(savedClip);
}
 
Example 17
Source File: IncorrectFractionalClip.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void drawToImage(int testId, boolean horiz, double scale,
                                BufferedImage image, boolean shape) {
    Graphics2D g = image.createGraphics();
    g.setComposite(AlphaComposite.Src);
    g.setColor(WHITE);
    g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    g.setComposite(AlphaComposite.SrcOver);
    g.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE);

    // set the scale in one direction
    if (horiz) {
        g.scale(scale, 1);
    } else {
        g.scale(1, scale);
    }
    // cover all units in the user space to touch all pixels in the
    // image after transform
    final int destSize = (int) Math.ceil(SIZE / scale);
    final int destW;
    final int destH;
    if (horiz) {
        destW = destSize;
        destH = SIZE;
    } else {
        destW = SIZE;
        destH = destSize;
    }
    for (int step = 0; step < destSize; ++step) {
        if (horiz) {
            if (!shape) {
                g.setClip(step, 0, 1, SIZE);
            } else{
                g.setClip(new Area(new Rectangle(step, 0, 1, SIZE)));
            }
        } else {
            if (!shape) {
                g.setClip(0, step, SIZE, 1);
            }else{
                g.setClip(new Area(new Rectangle(0, step, SIZE, 1)));
            }
        }
        switch (testId) {
            case 0:
                g.setColor(step % 2 == 0 ? RED : GREEN);
                g.fillRect(0, 0, destW, destH);
                break;
            case 1:
                g.drawImage(step % 2 == 0 ? redI : greenI, 0, 0,
                            destW, destH, null);
                break;
            case 2:
                g.setColor(step % 2 == 0 ? RED : GREEN);
                g.setStroke(STROKE);
                if (horiz) {
                    g.drawLine(step, 0, step, SIZE);
                } else {
                    g.drawLine(0, step, SIZE, step);
                }
                break;
            default:
                throw new RuntimeException();
        }
    }
    g.dispose();
}
 
Example 18
Source File: SymbolAxis.java    From SIMVA-SoS with Apache License 2.0 3 votes vote down vote up
/**
 * Draws the grid bands.  Alternate bands are colored using
 * <CODE>gridBandPaint</CODE> (<CODE>DEFAULT_GRID_BAND_PAINT</CODE> by
 * default).
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plotArea  the area within which the plot is drawn 
 *     (<code>null</code> not permitted).
 * @param dataArea  the data area to which the axes are aligned 
 *     (<code>null</code> not permitted).
 * @param edge  the edge to which the axis is aligned (<code>null</code> not
 *     permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 */
protected void drawGridBands(Graphics2D g2, Rectangle2D plotArea,
        Rectangle2D dataArea, RectangleEdge edge, List ticks) {
    Shape savedClip = g2.getClip();
    g2.clip(dataArea);
    if (RectangleEdge.isTopOrBottom(edge)) {
        drawGridBandsHorizontal(g2, plotArea, dataArea, true, ticks);
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        drawGridBandsVertical(g2, plotArea, dataArea, true, ticks);
    }
    g2.setClip(savedClip);
}
 
Example 19
Source File: RasterPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
     * Configure the passed in Graphics2D so that
     * is contains the defined initial settings
     * for a print job. These settings are:
     *      color:  black.
     *      clip:   <as passed in>
     */
// MacOSX - made protected so subclasses can reference it.
    protected void initPrinterGraphics(Graphics2D g, Rectangle2D clip) {

        g.setClip(clip);
        g.setPaint(Color.black);
    }
 
Example 20
Source File: RasterPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
     * Configure the passed in Graphics2D so that
     * is contains the defined initial settings
     * for a print job. These settings are:
     *      color:  black.
     *      clip:   <as passed in>
     */
// MacOSX - made protected so subclasses can reference it.
    protected void initPrinterGraphics(Graphics2D g, Rectangle2D clip) {

        g.setClip(clip);
        g.setPaint(Color.black);
    }