Java Code Examples for java.awt.Graphics.clipRect()

The following are Jave code examples for showing how to use clipRect() of the java.awt.Graphics 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: incubator-netbeans   File: GlassPane.java   View Source Code Vote up 6 votes
/**
 * Paints additional information about component constraints.
 * 
 * @param g graphics to use for painting.
 */
private void paintConstraints(Graphics g) {
    Point shift = fromComponentPane(new Point());
    Graphics gClip = g.create();
    Rectangle paneRect = fromComponentPane(new Rectangle(new Point(), componentPane.getSize()));
    gClip.clipRect(paneRect.x, paneRect.y, paneRect.width, paneRect.height);
    gClip.translate(shift.x, shift.y);
    for (Component comp : componentPane.getComponents()) {
        if (GridUtils.isPaddingComponent(comp)) {
            continue;
        }
        boolean selected = selection.contains(comp);
        gridInfo.paintConstraints(gClip, comp, selected);
    }
    gClip.dispose();
}
 
Example 2
Project: TrabalhoFinalEDA2   File: mxGraphComponent.java   View Source Code Vote up 6 votes
/**
 * 
 */
protected void paintBackground(Graphics g)
{
	Rectangle clip = g.getClipBounds();
	Rectangle rect = paintBackgroundPage(g);

	if (isPageVisible())
	{
		g.clipRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
	}

	// Paints the clipped background image
	paintBackgroundImage(g);

	// Paints the grid directly onto the graphics
	paintGrid(g);
	g.setClip(clip);
}
 
Example 3
Project: Tarski   File: mxGraphComponent.java   View Source Code Vote up 6 votes
/**
 * 
 */
protected void paintBackground(Graphics g) {
  Rectangle clip = g.getClipBounds();
  Rectangle rect = paintBackgroundPage(g);

  if (isPageVisible()) {
    g.clipRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
  }

  // Paints the clipped background image
  paintBackgroundImage(g);

  // Paints the grid directly onto the graphics
  paintGrid(g);
  g.setClip(clip);
}
 
Example 4
Project: openjdk-jdk10   File: SuppCharDrawTest.java   View Source Code Vote up 5 votes
private static BufferedImage renderFirstChar(String s) {
    BufferedImage image = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics g = image.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
    g.setColor(Color.black);
    g.setFont(FONT);
    FontMetrics metrics = g.getFontMetrics();
    g.clipRect(0, 0, metrics.charWidth(s.charAt(0)), IMAGE_HEIGHT);
    g.drawString(s, 0, metrics.getAscent());
    g.dispose();
    return image;
}
 
Example 5
Project: brModelo   File: InspectorExtenderEditor.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g) {
    super.paint(g);
    //Color bkp = g.getColor();
    Rectangle r = this.getBounds();
    g.setColor(Color.BLACK);
    int re = 0;
    String bonito = "?";
    if (getAcaoTipo() == TipoDeAcao.tpAcaoDlgCor || getAcaoTipo() == TipoDeAcao.tpReadOnlyCor) {
        g.setColor(Color.BLACK);
        g.fillRect(3, 3, r.height - 7, r.height - 7);
        try {
            Color c = util.Utilidades.StringToColor(getTexto());
            g.setColor(c);
            bonito = getTexto();
        } catch (Exception e) {
        }
        g.fillRect(4, 4, r.height - 8, r.height - 8);
        //g.setColor(Color.BLACK);
        //g.drawRect(3, 3, r.height - 7, r.height - 7);
        re = r.height - 1;
    } else {
        bonito = getTexto().replaceAll("\n", " | ");
    }
    //g.setColor(bkp);
    
    Rectangle obkp = g.getClipBounds();

    g.setColor(Color.DARK_GRAY);
    g.setFont(new Font(this.getFont().getFontName(), Font.BOLD, getFont().getSize()));
    g.clipRect(re, 0, r.width - r.height -re - (re == 0? 4: 8), r.height);
    g.drawString(bonito, re + 2, (int) (r.height * 0.72) + 1);
    g.drawLine(0, 0, 0, getHeight());
    g.setClip(obkp);
}
 
Example 6
Project: incubator-netbeans   File: HeapView.java   View Source Code Vote up 4 votes
/**
 * Paints the component.
 */
@Override protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D)g;
    int width = getWidth();
    int height = getHeight();
    if (width - BORDER_W > 0 && height - BORDER_H > 0) {
        startTimerIfNecessary();
        updateCacheIfNecessary(width, height);
        paintCachedBackground(g2, width, height);
        g.translate(1, 2);
        if (containsMouse) {
            g.clipRect(1, 0, width - 4, height - 4);
        }
        else {
            g.clipRect(0, 0, width - 2, height - 4);
        }
        int innerW = width - BORDER_W;
        int innerH = height - BORDER_H;
        if (heapGrowTimer != null) {
            // Render the heap growing animation.
            Composite lastComposite = ((Graphics2D)g).getComposite();
            float percent = 1f - heapGrowTimer.getPercent();
            ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, percent));
            g.drawImage(heapGrowTimer.image, 0, 0, null);
            ((Graphics2D)g).setComposite(lastComposite);
        }
        paintTicks(g2, innerW, innerH);
        if (getTickStyle() == STYLE_OVERLAY) {
            g2.drawImage(getGridOverlayImage(), 0, 0, null);
        }
        if (getShowText()) {
            if (getShowDropShadow()) {
                paintDropShadowText(g, innerW, innerH);
            } else {
                g.setColor(textColor);
                paintText(g, innerW, innerH);
            }
        }
        g.translate(-1, -2);
    } else {
        stopTimerIfNecessary();
        // To honor opaque contract, fill in the background
        g.setColor(getBackground());
        g.fillRect(0, 0, width, height);
    }
}