当前位置: 首页>>代码示例>>Java>>正文


Java Graphics.getClip方法代码示例

本文整理汇总了Java中java.awt.Graphics.getClip方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.getClip方法的具体用法?Java Graphics.getClip怎么用?Java Graphics.getClip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics的用法示例。


在下文中一共展示了Graphics.getClip方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paintTabBackground

import java.awt.Graphics; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:NimbusEditorTabCellRenderer.java

示例2: paintTabBackground

import java.awt.Graphics; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:NimbusViewTabDisplayerUI.java

示例3: draw

import java.awt.Graphics; //导入方法依赖的package包/类
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);

}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:47,代码来源:Region.java

示例4: drawState

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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);
		}
	}
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:82,代码来源:mxGraph.java

示例5: drawState

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 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);
    }
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:67,代码来源:mxGraph.java


注:本文中的java.awt.Graphics.getClip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。