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

The following are Jave code examples for showing how to use getClip() 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: NimbusEditorTabCellRenderer.java   View Source Code Vote up 5 votes
private static void paintTabBackground (Graphics g, int index, Component c,
int x, int y, int w, int h) {

    Shape clip = g.getClip();
    NimbusEditorTabCellRenderer ren = (NimbusEditorTabCellRenderer) c;

    w +=1;
    boolean isPreviousTabSelected = ren.isPreviousTabSelected();
    if (isPreviousTabSelected) {
        g.setClip(x+1, y, w-1, h);
    }

    Object o = null;
    if (ren.isSelected()) {
        if (ren.isActive()) {
            o = UIManager.get("TabbedPane:TabbedPaneTab[MouseOver+Selected].backgroundPainter");
        } else {
            o = UIManager.get("TabbedPane:TabbedPaneTab[Selected].backgroundPainter");
        }
    } else {
        o = UIManager.get("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter");
    }
    if ((o != null) && (o instanceof javax.swing.Painter)) {
        javax.swing.Painter painter = (javax.swing.Painter) o;
        BufferedImage bufIm = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bufIm.createGraphics();
        g2d.setBackground(UIManager.getColor("Panel.background"));
        g2d.clearRect(0, 0, w, h);
        painter.paint(g2d, null, w, h);
        g.drawImage(bufIm, x, y, null);
    }

    if (isPreviousTabSelected) {
        g.setClip(clip);
    }
}
 
Example 2
Project: incubator-netbeans   File: NimbusViewTabDisplayerUI.java   View Source Code Vote up 4 votes
@Override
protected void paintTabBackground(Graphics g, int index, int x, int y,
                                  int width, int height) {
    boolean isLast = index == getDataModel().size()-1;
    if (!isLast) {
        width++;
    }

    Shape clip = g.getClip();
    boolean isPreviousTabSelected = index-1 == displayer.getSelectionModel().getSelectedIndex();
    if (isPreviousTabSelected) {
        g.setClip(x+1, y, width-1, height);
    }

    final boolean attention = isAttention(index);
    Object o = null;
    if (isSelected(index)) {
        String mouseOver = "TabbedPane:TabbedPaneTab[MouseOver+Selected].backgroundPainter";
        String selected = "TabbedPane:TabbedPaneTab[Selected].backgroundPainter";
        if (isActive()) {
            o = UIManager.get( attention ? selected : mouseOver);
        } else {
            o = UIManager.get( attention ? mouseOver: selected);
        }
    } else {
        if( attention ) {
            o = UIManager.get("TabbedPane:TabbedPaneTab[Disabled].backgroundPainter");
        } else {
            o = UIManager.get("TabbedPane:TabbedPaneTab[Enabled].backgroundPainter");
        }
    }

    if ((o != null) && (o instanceof javax.swing.Painter)) {
        javax.swing.Painter painter = (javax.swing.Painter) o;
        BufferedImage bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bufIm.createGraphics();
        g2d.setBackground(UIManager.getColor("Panel.background"));
        g2d.clearRect(0, 0, width, height);
        painter.paint(g2d, null, width, height);
        g.drawImage(bufIm, x, y, null);
    }

    if (isPreviousTabSelected) {
        g.setClip(clip);
    }
}
 
Example 3
Project: VASSAL-src   File: Region.java   View Source Code Vote up 4 votes
public void draw(Graphics g, Rectangle bounds, Rectangle visibleRect, double scale, boolean reversed, int xOffset, int yOffset) {
  if (!bounds.intersects(visibleRect)) {
    return;
  }

  final int labelOffset = 7;

  int size = (int) (scale * myGrid.getFontSize() + 0.5);
  Font f = new Font("Dialog", Font.PLAIN, size); //$NON-NLS-1$

  Color fg = selected ? Color.white : Color.black;
  Color bg = selected ? Color.black : Color.white;

  Rectangle region = bounds.intersection(visibleRect);

  Shape oldClip = g.getClip();
  if (oldClip != null) {
    Area clipArea = new Area(oldClip);
    clipArea.intersect(new Area(region));
    g.setClip(clipArea);
  }

  int posX = (int) (scale * origin.x + 0.5) + bounds.x - 1 + xOffset;
  int posY = (int) (scale * origin.y + 0.5) + bounds.y - 1 + yOffset;

  Color saveColor = g.getColor();

  g.setColor(bg);
  g.fillRect(posX, posY, 3, 3);
  g.setColor(fg);
  g.drawRect(posX, posY, 3, 3);

  g.setColor(saveColor);

  Labeler.drawLabel(g, getLocalizedConfigureName(), posX, posY + labelOffset, f, Labeler.CENTER,
                    Labeler.TOP, fg, bg, fg);
  g.setClip(oldClip);

  // Calculate and store the selection rectangle
  int width = g.getFontMetrics().stringWidth(getConfigureName() + "  ")+1; //$NON-NLS-1$
  int height = g.getFontMetrics().getHeight()+1;

  selectionRect.setLocation(posX - (width / 2), posY - 1);
  selectionRect.setSize(width, height + labelOffset + 1);

}
 
Example 4
Project: TrabalhoFinalEDA2   File: mxGraph.java   View Source Code Vote up 4 votes
/**
 * Draws the cell state with the given label onto the canvas. No
 * children or descendants are painted here. This method invokes
 * cellDrawn after the cell, but not its descendants have been
 * painted.
 * 
 * @param canvas Canvas onto which the cell should be drawn.
 * @param state State of the cell to be drawn.
 * @param drawLabel Indicates if the label should be drawn.
 */
public void drawState(mxICanvas canvas, mxCellState state, boolean drawLabel)
{
	Object cell = (state != null) ? state.getCell() : null;

	if (cell != null && cell != view.getCurrentRoot()
			&& cell != model.getRoot()
			&& (model.isVertex(cell) || model.isEdge(cell)))
	{
		Object obj = canvas.drawCell(state);
		Object lab = null;

		// Holds the current clipping region in case the label will
		// be clipped
		Shape clip = null;
		Rectangle newClip = state.getRectangle();

		// Indirection for image canvas that contains a graphics canvas
		mxICanvas clippedCanvas = (isLabelClipped(state.getCell())) ? canvas
				: null;

		if (clippedCanvas instanceof mxImageCanvas)
		{
			clippedCanvas = ((mxImageCanvas) clippedCanvas)
					.getGraphicsCanvas();
			// TODO: Shift newClip to match the image offset
			//Point pt = ((mxImageCanvas) canvas).getTranslate();
			//newClip.translate(-pt.x, -pt.y);
		}

		if (clippedCanvas instanceof mxGraphics2DCanvas)
		{
			Graphics g = ((mxGraphics2DCanvas) clippedCanvas).getGraphics();
			clip = g.getClip();

			// Ensure that our new clip resides within our old clip
			if (clip instanceof Rectangle)
			{
				g.setClip(newClip.intersection((Rectangle) clip));
			}
			// Otherwise, default to original implementation
			else
			{
				g.setClip(newClip);
			}
		}

		if (drawLabel)
		{
			String label = state.getLabel();

			if (label != null && state.getLabelBounds() != null)
			{
				lab = canvas.drawLabel(label, state, isHtmlLabel(cell));
			}
		}

		// Restores the previous clipping region
		if (clippedCanvas instanceof mxGraphics2DCanvas)
		{
			((mxGraphics2DCanvas) clippedCanvas).getGraphics()
					.setClip(clip);
		}

		// Invokes the cellDrawn callback with the object which was created
		// by the canvas to represent the cell graphically
		if (obj != null)
		{
			cellDrawn(canvas, state, obj, lab);
		}
	}
}
 
Example 5
Project: Tarski   File: mxGraph.java   View Source Code Vote up 4 votes
/**
 * Draws the cell state with the given label onto the canvas. No children or descendants are
 * painted here. This method invokes cellDrawn after the cell, but not its descendants have been
 * painted.
 *
 * @param canvas Canvas onto which the cell should be drawn.
 * @param state State of the cell to be drawn.
 * @param drawLabel Indicates if the label should be drawn.
 */
public void drawState(final mxICanvas canvas, final mxCellState state, final boolean drawLabel) {
  final Object cell = state != null ? state.getCell() : null;

  if (cell != null && cell != this.view.getCurrentRoot() && cell != this.model.getRoot()
      && (this.model.isVertex(cell) || this.model.isEdge(cell))) {
    final Object obj = canvas.drawCell(state);
    Object lab = null;

    // Holds the current clipping region in case the label will
    // be clipped
    Shape clip = null;
    final Rectangle newClip = state.getRectangle();

    // Indirection for image canvas that contains a graphics canvas
    mxICanvas clippedCanvas = this.isLabelClipped(state.getCell()) ? canvas : null;

    if (clippedCanvas instanceof mxImageCanvas) {
      clippedCanvas = ((mxImageCanvas) clippedCanvas).getGraphicsCanvas();
      // TODO: Shift newClip to match the image offset
      // Point pt = ((mxImageCanvas) canvas).getTranslate();
      // newClip.translate(-pt.x, -pt.y);
    }

    if (clippedCanvas instanceof mxGraphics2DCanvas) {
      final Graphics g = ((mxGraphics2DCanvas) clippedCanvas).getGraphics();
      clip = g.getClip();

      // Ensure that our new clip resides within our old clip
      if (clip instanceof Rectangle) {
        g.setClip(newClip.intersection((Rectangle) clip));
      }
      // Otherwise, default to original implementation
      else {
        g.setClip(newClip);
      }
    }

    if (drawLabel) {
      final String label = state.getLabel();

      if (label != null && state.getLabelBounds() != null) {
        lab = canvas.drawLabel(label, state, this.isHtmlLabel(cell));
      }
    }

    // Restores the previous clipping region
    if (clippedCanvas instanceof mxGraphics2DCanvas) {
      ((mxGraphics2DCanvas) clippedCanvas).getGraphics().setClip(clip);
    }

    // Invokes the cellDrawn callback with the object which was created
    // by the canvas to represent the cell graphically
    if (obj != null) {
      this.cellDrawn(canvas, state, obj, lab);
    }
  }
}