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

The following are Jave code examples for showing how to use setClip() 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: jdk8u-jdk   File: IncorrectClipSurface2SW.java   View Source Code Vote up 6 votes
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 2
Project: openjdk-jdk10   File: IncorrectClipSurface2SW.java   View Source Code Vote up 6 votes
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 3
Project: parabuild-ci   File: Plot.java   View Source Code Vote up 6 votes
/**
     * 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);
//            FontMetrics fm = g2.getFontMetrics(this.noDataMessageFont);
//            Rectangle2D bounds = TextUtilities.getTextBounds(message, g2, fm);
//            float x = (float) (area.getX() + area.getWidth() / 2 - bounds.getWidth() / 2);
//            float y = (float) (area.getMinY() + (area.getHeight() / 2) - (bounds.getHeight() / 2));
//            g2.drawString(message, x, y);
            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
Project: brModelo   File: InspectorItemSeparador.java   View Source Code Vote up 5 votes
@Override
protected void paintBase(Graphics2D g) {
    if (endOFF) {
        return;
    }
    setArea(null);
    Rectangle r = this.getBounds();
    g.setColor(Color.GRAY);
    g.drawRoundRect(0, 0, r.width - 1, r.height - 1, 10, 10);

    g.setColor(Color.lightGray);
    g.drawRoundRect(5, 5, r.height - 10, r.height - 10, 4,4);

    int met = (r.height - 11) / 2;
    g.setColor(Color.black);
    g.drawLine(7, 6 + met, r.height - 7, 6 + met);
    if ('+' == getEstado()) {
        g.drawLine(6 + met, 7, 6 + met, r.height - 7);
    }

    g.setColor(Color.BLACK);
    Rectangle bkp = g.getClipBounds();
    g.clipRect(0, 0, r.width - 1, r.height);
    if (isSelecionado()) {
        g.setFont(new Font(this.getFont().getFontName(), Font.BOLD, getFont().getSize()));
        g.drawRoundRect(0, 0, r.width - 1, r.height - 1, 10, 10);
    }
    int tmp = (r.width - g.getFontMetrics().stringWidth(getTexto())) / 2;

    g.drawString(getTexto(), tmp, (int) (r.height * 0.72));
    g.setClip(bkp);
}
 
Example 5
Project: openjdk-jdk10   File: RenderToCustomBufferTest.java   View Source Code Vote up 5 votes
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 6
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 7
Project: ramus   File: DFDFunctionEllipse.java   View Source Code Vote up 5 votes
@Override
public void paintTringle(Graphics2D g) {
    if (paintTriangle >= 0) {

        final Rectangle2D rect = movingArea.getBounds(getBounds());
        Ellipse2D ellipse = new Ellipse2D.Double(rect.getX(), rect.getY(),
                rect.getWidth(), rect.getHeight());
        g.setClip(ellipse);

        g.fill(getTrianglePath(paintTriangle).createTransformedShape(
                AffineTransform.getScaleInstance(movingArea.zoom,
                        movingArea.zoom)));
        g.setClip(null);
    }
}
 
Example 8
Project: ramus   File: DFDFunction.java   View Source Code Vote up 5 votes
@Override
public void paintTringle(Graphics2D g) {
    if (paintTriangle >= 0) {
        final Rectangle2D rect = movingArea.getBounds(getBounds());
        RoundRectangle2D rectangle2d = new RoundRectangle2D.Double(rect.getX(),
                rect.getY(), rect.getWidth(), rect.getHeight(),
                movingArea.getIDoubleOrdinate(20),
                movingArea.getIDoubleOrdinate(20));
        g.setClip(rectangle2d);
        g.fill(getTrianglePath(paintTriangle).createTransformedShape(
                AffineTransform.getScaleInstance(movingArea.zoom,
                        movingArea.zoom)));
        g.setClip(null);
    }
}
 
Example 9
Project: openjdk-jdk10   File: Test8004859.java   View Source Code Vote up 5 votes
private static void test(final Graphics2D g) {
    for (final Shape clip : clips) {
        g.setClip(clip);
        if (!g.getClip().equals(clip)) {
            System.err.println("Expected clip: " + clip);
            System.err.println("Actual clip: " + g.getClip());
            System.err.println("bounds="+g.getClip().getBounds2D());
            System.err.println("bounds="+g.getClip().getBounds());
            status = false;
        }
        final Rectangle bounds = g.getClipBounds();
        if (!clip.equals(bounds)) {
            System.err.println("Expected getClipBounds(): " + clip);
            System.err.println("Actual getClipBounds(): " + bounds);
            status = false;
        }
        g.getClipBounds(bounds);
        if (!clip.equals(bounds)) {
            System.err.println("Expected getClipBounds(r): " + clip);
            System.err.println("Actual getClipBounds(r): " + bounds);
            status = false;
        }
        if (!clip.getBounds2D().isEmpty() && ((SunGraphics2D) g).clipRegion
                .isEmpty()) {
            System.err.println("clipRegion should not be empty");
            status = false;
        }
    }
}
 
Example 10
Project: What-Happened-to-Station-7   File: TStack.java   View Source Code Vote up 5 votes
public void apply(Graphics2D g)
{
	g.setTransform(transform);
	g.setPaint(paint);
	g.setStroke(stroke);
	g.setFont(font);
	g.setComposite(composite);
	g.setBackground(bgrnd);
	g.setClip(shape);
	g.setRenderingHints(hints);
}
 
Example 11
Project: brModelo   File: Legenda.java   View Source Code Vote up 4 votes
@Override
    public void DoPaint(Graphics2D g) {
        super.DoPaint(g);
        Rectangle rec = getArea();
        Color bkpc = g.getColor();

        g.setColor(getBorderColor());

        g.drawRect(rec.x, rec.y, rec.width, rec.height);

        Rectangle bkp = g.getClipBounds();
        g.clipRect(rec.x, rec.y, rec.width, rec.height);

        Font fn = getFont();
        Font font = new Font(fn.getFontName(), fn.getStyle(), fn.getSize() - 2);

        fn = g.getFont();
        g.setFont(font);

        altura = g.getFontMetrics().getHeight() + g.getFontMetrics().getDescent();
        alturaTitulo = altura + altura / 2;

        Composite originalComposite = g.getComposite();
        float alfa = 0.8f;
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));

        if (getTipo() == TipoLegenda.tpObjetos) {
            altura = Math.max(32, altura);
        }

        int posi = altura + alturaTitulo + rec.y;
        final int lft = rec.x + 2;

        for (ItemDeLegenda it : getItens()) {

            if (it.isSelecionada()) {
                g.setColor(isDisablePainted()? disabledColor : new Color(204, 204, 255, 50));
                g.fillRect(lft, posi - altura - 2, getWidth(), altura + 4);
            }
            g.setColor(isDisablePainted()? disabledColor : it.cor);
            int moveleft;
            switch (getTipo()) {
                case tpLinhas:
                    moveleft = 3 * altura;
                    g.fillRoundRect(lft, posi - (altura / 2) - 2, moveleft - 2, 4, 2, 2);
                    g.setColor(bkpc);
                    g.drawString(it.texto, lft + moveleft, posi - 6);
                    break;
                case tpObjetos:
                    ImageIcon img = Editor.fromControler().getImagemNormal(getMaster().getCassesDoDiagrama()[it.getTag()].getSimpleName());
                    g.drawImage(util.TratadorDeImagens.ReColorBlackImg(img, it.getCor()), lft, posi - altura, null);
                    moveleft = altura + 2;
                    g.drawString(it.texto, lft + moveleft, posi - altura / 2 + 6);
                    break;
                default:
                    moveleft = altura;
                    g.fillRect(lft, posi - altura, altura - 4, altura - 4);
                    g.setColor(bkpc);
                    g.drawRect(lft, posi - altura, altura - 4, altura - 4);
                    g.drawString(it.texto, lft + moveleft, posi - 6);
            }
            it.Area = new Point(posi - altura - 2, altura + 4);
            posi += altura + 4;
        }

        g.setComposite(originalComposite);

//        g.setColor(Color.LIGHT_GRAY);
//        g.drawLine(lft - 1, posi - altura - 2, getLeft() + getWidth() - 1, posi - altura - 2);
        g.setClip(bkp);
        g.setFont(fn);
    }
 
Example 12
Project: geomapapp   File: MapServerB.java   View Source Code Vote up 4 votes
public static boolean getHighRes(double[] wesn, int width, int height, BufferedImage image) {
	getImage(wesn, width, height, image);
	Graphics2D g = image.createGraphics();
	Rectangle rect = new Rectangle(0, 0, width, height);
	double scale = (wesn[1] - wesn[0]) / (double)width;
	double r = 1/scale;
	if(r < (double)res[0]) return false;
	int ires = 0;
	while( r < (double)highRes[ires] && ires<highRes.length-1) ires++;
	if(ires == highRes.length-1) ires--;
	double gridScale = 600 / (double) highRes[ires];
	
	int x1 = (int) Math.floor( wesn[0] / gridScale);
	int x2 = (int) Math.ceil( wesn[1] / gridScale);
	int xmax = (int) Math.ceil( 360 / gridScale);

	int y1 = (int) Math.ceil( wesn[3] / gridScale);
	int y2 = (int) Math.floor( wesn[2] / gridScale);
	Rectangle clipRect = new Rectangle(8, 8, 600, 600);

	int xgrid, ygrid;
	String name;
	File file;
	double x0, y0;
	double west;
	double north;
	double offset;
	double pad = 8 / (double) highRes[ires];
	BufferedImage im = null;
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
		RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	AffineTransform at = new AffineTransform();
	boolean returnVal = false;
	for( int x=x1 ; x<x2 ; x++ ) {
		xgrid = x;
		offset = -pad;
		while(xgrid < 0) {
			xgrid += xmax;
			offset -= 360;
		}
		while(xgrid >= xmax) {
			xgrid -= xmax;
			offset += 360;
		}
		west = (double) xgrid * gridScale + offset;
		x0 = (west - wesn[0]) / scale;
		for( int y=y1 ; y>y2 ; y--) {
			
			north = (double)y *gridScale + pad;
			if( y>0 ) {
				name = "g" + highRes[ires] + "_" + xgrid + "_N" + y +".jpg";
			} else {
				ygrid = -y;
				name = "g" + highRes[ires] + "_" + xgrid + "_S" + ygrid +".jpg";
			}
			String url = "file:/usr/local/seabeam/kn166-14/copy/science/tiles/g"+highRes[ires]+"/" + name;
			im = null;
			try { 
				BufferedInputStream in = new BufferedInputStream(
					(URLFactory.url(url)).openStream());
				//JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
				//im = decoder.decodeAsBufferedImage();
				im = ImageIO.read(in);
				in.close();
			} catch ( Exception ioe) {
				continue;
			}
			g.setTransform(at);
			g.setClip(rect);
			y0 = (wesn[3] - north) / scale ;
			g.translate(x0, y0);
			double scl = 1 / ((double) highRes[ires] * scale);
			g.scale(scl, scl);
			g.clip(clipRect);
			returnVal = true;
			g.drawRenderedImage(im, at);
		}
	}
	return returnVal;
}
 
Example 13
Project: incubator-netbeans   File: FoldView.java   View Source Code Vote up 4 votes
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
    Rectangle2D.Double allocBounds = ViewUtils.shape2Bounds(alloc);
    if (allocBounds.intersects(clipBounds)) {
        Font origFont = g.getFont();
        Color origColor = g.getColor();
        Color origBkColor = g.getBackground();
        Shape origClip = g.getClip();
        try {
            // Leave component font
            
            g.setBackground(getBackgroundColor());

            int xInt = (int) allocBounds.getX();
            int yInt = (int) allocBounds.getY();
            int endXInt = (int) (allocBounds.getX() + allocBounds.getWidth() - 1);
            int endYInt = (int) (allocBounds.getY() + allocBounds.getHeight() - 1);
            g.setColor(getBorderColor());
            g.drawRect(xInt, yInt, endXInt - xInt, endYInt - yInt);
            
            g.setColor(getForegroundColor());
            g.clearRect(xInt + 1, yInt + 1, endXInt - xInt - 1, endYInt - yInt - 1);
            g.clip(alloc);
            TextLayout textLayout = getTextLayout();
            if (textLayout != null) {
                EditorView.Parent parent = (EditorView.Parent) getParent();
                float ascent = parent.getViewRenderContext().getDefaultAscent();
                String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
                float x = (float) (allocBounds.getX() + EXTRA_MARGIN_WIDTH);
                float y = (float) allocBounds.getY();
                if (desc.length() > 0) {
                    
                    textLayout.draw(g, x, y + ascent);
                }
            }
        } finally {
            g.setClip(origClip);
            g.setBackground(origBkColor);
            g.setColor(origColor);
            g.setFont(origFont);
        }
    }
}
 
Example 14
Project: rapidminer   File: ProgressBarUI.java   View Source Code Vote up 4 votes
@Override
protected void paintIndeterminate(Graphics g, JComponent c) {
	boolean compressed = Boolean.parseBoolean(String.valueOf(progressBar
			.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));

	int y = 0;
	int x = 0;
	int w;
	int h;
	if (compressed) {
		x = (int) (c.getWidth() * 0.67);
		w = (int) (c.getWidth() * 0.33);
		y = 3;
		h = c.getHeight() - 6;
	} else {
		w = c.getWidth();
		h = c.getHeight() / 2;
	}

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (c.isOpaque()) {
		if (c.getParent() != null) {
			g2.setColor(c.getParent().getBackground());
		} else {
			g2.setColor(c.getBackground());
		}
		g2.fillRect(x, y, c.getWidth(), c.getHeight());
	}

	g2.setColor(Colors.PROGRESSBAR_BACKGROUND);
	g2.fillRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	g2.setColor(Colors.PROGRESSBAR_BORDER);
	g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	// make sure we don't draw over the boundaries
	RoundRectangle2D clipRect = new RoundRectangle2D.Double(x + 3, y + 3, w - 5, h - 5,
			RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
	g2.setClip(clipRect);

	for (double xCoord = x + -4 * ANIMATION_BAR_LENGTH + System.currentTimeMillis() * ANIMATION_SPEED
			% (2 * ANIMATION_BAR_LENGTH); xCoord < x + w + 2 * ANIMATION_BAR_LENGTH;) {
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_1);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
		g2.setColor(Colors.PROGRESSBAR_INDETERMINATE_FOREGROUND_2);
		g2.fill(createIntermediateShape(xCoord, ANIMATION_BAR_LENGTH, h));
		xCoord += ANIMATION_BAR_LENGTH;
	}
	g2.setClip(null);

	drawString(g2, w, h, compressed);
}
 
Example 15
Project: parabuild-ci   File: PolarPlot.java   View Source Code Vote up 4 votes
/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a printer).
 * <P>
 * This plot relies on an {@link org.jfree.chart.renderer.DefaultPolarItemRenderer} to draw 
 * each item in the plot.  This allows the visual representation of the data to be changed 
 * easily.
 * <P>
 * The optional info argument collects information about the rendering of
 * the plot (dimensions, tooltip information etc).  Just pass in <code>null</code> if
 * you do not need this information.
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the plot (including axes and labels) should be drawn.
 * @param parentState  ignored.
 * @param info  collects chart drawing information (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, 
                 Rectangle2D plotArea, 
                 PlotState parentState,
                 PlotRenderingInfo info) {
   
    // if the plot area is too small, just return...
    boolean b1 = (plotArea.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (plotArea.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
   
    // record the plot area...
    if (info != null) {
        info.setPlotArea(plotArea);
    }
   
    // adjust the drawing area for the plot insets (if any)...
    Insets insets = getInsets();
    if (insets != null) {
        plotArea.setRect(plotArea.getX() + insets.left,
                         plotArea.getY() + insets.top,
                         plotArea.getWidth() - insets.left - insets.right,
                         plotArea.getHeight() - insets.top - insets.bottom);
    }
  
    Rectangle2D dataArea = plotArea;
    if (info != null) {
        info.setDataArea(dataArea);
    }
   
    // draw the plot background and axes...
    drawBackground(g2, dataArea);
    double h = Math.min(dataArea.getWidth() / 2.0, dataArea.getHeight() / 2.0) - MARGIN;
    Rectangle2D quadrant = new Rectangle2D.Double(
        dataArea.getCenterX(), dataArea.getCenterY(), h, h
    );
    AxisState state = drawAxis(g2, plotArea, quadrant);
    if (this.renderer != null) {
        Shape originalClip = g2.getClip();
        Composite originalComposite = g2.getComposite();
      
        g2.clip(dataArea);
        g2.setComposite(
            AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())
        );
      
        drawGridlines(g2, dataArea, this.angleTicks, state.getTicks());
      
        // draw...
        render(g2, dataArea, info);
      
        g2.setClip(originalClip);
        g2.setComposite(originalComposite);
    }
    drawOutline(g2, dataArea);
    drawCornerTextItems(g2, dataArea);
}
 
Example 16
Project: brModelo   File: InspectorItemCor.java   View Source Code Vote up 4 votes
@Override
    protected void paintBase(Graphics2D g) {
        Rectangle r = this.getBounds();
        int esq = (int) (r.width * Criador.getDivisor());
        setArea(new Rectangle(esq -2, 0, 4, r.height - 1));

        //int dir = r.width - esq;
        if (!isSelecionado()) {
            g.setColor(Color.GRAY);
            g.drawRoundRect(0, 0, r.width - 1, r.height - 1, 10, 10);
            g.drawLine(esq, 0, esq, r.height - 1);

            g.setColor(Color.BLACK);
            
            getCorParaTexto(g);
            
            Rectangle bkp = g.getClipBounds();
            g.clipRect(0, 0, esq - 1, r.height);
            g.drawString(getTexto(), (Criador.espaco * 2) + 1, (int) (r.height * 0.72));

            g.setClip(bkp);
            int re = esq + r.height -5;
            g.setColor(CanEdit() ? Color.BLACK : Color.LIGHT_GRAY);
            g.fillRect(esq + 4, 4, r.height - 9, r.height - 9);
            try {
                Color c = util.Utilidades.StringToColor(getTransValor());//new Color(Integer.parseInt(getTransValor()));
                g.setColor(c);
            } catch (Exception e) {
            }
            Color tmpc = g.getColor();
            String bonito = Integer.toString(tmpc.getRed()) + ", " + Integer.toString(tmpc.getGreen()) + ", " +Integer.toString(tmpc.getBlue())+ ", " +Integer.toString(tmpc.getAlpha());
            
            if (CanEdit()) {
                g.fillRect(esq + 5, 5, r.height - 10, r.height -10);
            }
            
//            g.setColor(CanEdit() ? Color.BLACK : Color.LIGHT_GRAY);
//            g.drawRect(tmp + 4, 4, r.height - 9, r.height -9);
            
            g.clipRect(re, 0, esq - 1, r.height);
            
            getCorParaTexto(g);

            g.drawString(bonito, re + (Criador.espaco * 2) + 1, (int) (r.height * 0.72));

            g.setClip(bkp);

        } else {
            super.paintBase(g);
        }
    }
 
Example 17
Project: parabuild-ci   File: WaferMapPlot.java   View Source Code Vote up 4 votes
/**
 * Calculates and draws the chip locations on the wafer.
 * 
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 */
private 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 = 0d;
        double minor = 0d;
        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 18
Project: parabuild-ci   File: FastScatterPlot.java   View Source Code Vote up 4 votes
/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the screen or
 * a printer).
 *
 * @param g2  the graphics device.
 * @param plotArea   the area within which the plot (including axis labels) should be drawn.
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects chart drawing information (<code>null</code> permitted).
 */
public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, 
                 PlotRenderingInfo info) {

    // set up info collection...
    if (info != null) {
        info.setPlotArea(plotArea);

    }

    // adjust the drawing area for plot insets (if any)...
    Insets insets = getInsets();
    if (insets != null) {
        plotArea.setRect(plotArea.getX() + insets.left,
                         plotArea.getY() + insets.top,
                         plotArea.getWidth() - insets.left - insets.right,
                         plotArea.getHeight() - insets.top - insets.bottom);
    }

    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, plotArea, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, plotArea, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(plotArea, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    AxisState domainAxisState = null;
    AxisState rangeAxisState = null;
    if (this.domainAxis != null) {
        domainAxisState = this.domainAxis.draw(
            g2, dataArea.getMaxY(), plotArea, dataArea, RectangleEdge.BOTTOM, info
        );
    }
    if (this.rangeAxis != null) {
        rangeAxisState = this.rangeAxis.draw(
            g2, dataArea.getMinX(), plotArea, dataArea, RectangleEdge.LEFT, info
        );
    }
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());
    
    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(
        AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())
    );

    render(g2, dataArea, info, null);

    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);

}
 
Example 19
Project: nativehtml   File: AbstractSwingComponentElement.java   View Source Code Vote up 4 votes
private void drawBackground(Graphics2D g2d, int x, int y, int w, int h) {
  CssStyleDeclaration style = getComputedStyle();
  if (style.isSet(CssProperty.BACKGROUND_COLOR)) {
    g2d.setColor(createColor(style.getColor(CssProperty.BACKGROUND_COLOR)));
    g2d.fillRect(x, y, w, h);
  }

  if (!style.isSet(CssProperty.BACKGROUND_IMAGE)) {
    return;
  }

  String bgImage = style.getString(CssProperty.BACKGROUND_IMAGE);
  Image image = ((SwingPlatform) getOwnerDocument().getPlatform()).getImage(this, getOwnerDocument().getUrl().resolve(bgImage));
  
  if (image == null) {
    return;
  }

  Shape savedClip = g2d.getClip(); 
  g2d.clipRect(x, y, w, h);
  CssEnum repeat = style.getEnum(CssProperty.BACKGROUND_REPEAT);
     int bgY = 0;
     int bgX = 0;
     if (repeat == CssEnum.REPEAT_Y || repeat == CssEnum.REPEAT) {
       do {
         if (repeat == CssEnum.REPEAT) {
           int currentBgX = bgX;
           do {
             g2d.drawImage(image, x + currentBgX, y + bgY, null);
             currentBgX += image.getWidth(null);
           } while (currentBgX < w);
         } else {
           g2d.drawImage(image, x + bgX, y + bgY, null);
         }
         bgY += image.getHeight(null);
       } while (bgY < h);
     } else if (repeat == CssEnum.REPEAT_X) {
       do {
         g2d.drawImage(image, x + bgX, y + bgY, null);
         bgX += image.getWidth(null);
       } while (bgX < w);
     } else {
       g2d.drawImage(image, x + bgX, y + bgY, null);
     }
     
     g2d.setClip(savedClip);
}
 
Example 20
Project: jdk8u-jdk   File: RasterPrinterJob.java   View Source Code Vote up 3 votes
/**
     * 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);
    }