本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
}