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


Java Graphics.setClip方法代码示例

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


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

示例1: updatey

import java.awt.Graphics; //导入方法依赖的package包/类
private void updatey(Graphics g) { //done.
    if (pane.getViewportSize().height - header.getHeight() < 0)
        return;
    if (previousimagex != pane.getViewportSize().width || //makes sure the
            // image buffer is
            // up to date!
            previousimagey != pane.getViewportSize().height
            || false) {
        im = createImage(pane.getViewportSize().width, pane.getViewportSize().height
                - header.getHeight());//new
        // BufferedImage(pane.getViewportSize().width,pane.getViewportSize().height-header.getHeight(),BufferedImage.TYPE_INT_BGR);//
        previousimagex = pane.getViewportSize().width;
        previousimagey = pane.getViewportSize().height;
    }
    paint(im.getGraphics(), pane.getScrollPosition().x, pane.getScrollPosition().x
            + pane.getViewportSize().width, pane.getScrollPosition().y, pane
            .getScrollPosition().y
            + pane.getViewportSize().height);
    g.setClip(pane.getScrollPosition().x, pane.getScrollPosition().y,
            pane.getViewportSize().width, pane.getViewportSize().height);
    g.drawImage(im, pane.getScrollPosition().x,
            pane.getScrollPosition().y + header.getHeight(), this);
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:24,代码来源:AWTMCList.java

示例2: drawRemaining

import java.awt.Graphics; //导入方法依赖的package包/类
private void drawRemaining(Rectangle rectangle, Component lp, BufferedImage pic) {
	if ((rectangle.x + rectangle.width) > lp.getWidth()) {
		rectangle.width = lp.getWidth() - rectangle.x;
	}
	if ((rectangle.y + rectangle.height) > lp.getHeight()) {
		rectangle.height = lp.getHeight() - rectangle.y;
	}
	if (!rectangle.isEmpty()) {
		Graphics g = pic.createGraphics();
		g.translate(-rectangle.x, -rectangle.y);
		g.setClip(rectangle);
		boolean doubleBuffered = lp.isDoubleBuffered();
		if (lp instanceof JComponent) {
			((JComponent) lp).setDoubleBuffered(false);
			lp.paint(g);
			((JComponent) lp).setDoubleBuffered(doubleBuffered);
		} else {
			lp.paint(g);
		}
		g.dispose();
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:RoundedRectanglePopup.java

示例3: paintBackground

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

示例4: paintBackground

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

示例5: paint

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

示例6: paint

import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g) {
    if (getComponentCount() == 0) return;

    Rectangle bounds = new Rectangle(0, 0, getWidth(), getHeight());
    Rectangle clip = g.getClipBounds();
    if (clip == null) g.setClip(bounds);
    else g.setClip(clip.intersection(bounds));

    super.paint(g);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:TimelineTooltipOverlay.java

示例7: main

import java.awt.Graphics; //导入方法依赖的package包/类
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Test6978482.java

示例8: paint

import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g) {
    if (pushed || !button.isEnabled() || container.getComponent(0) == this) {
        Rectangle c = g.getClipBounds();
        g.setClip(getWidth() - POPUP_EXTENT, 0, POPUP_EXTENT, getHeight());
        super.paint(g);
        g.setClip(c);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:DropdownButton.java

示例9: paint

import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g) {
    if (tooltipPainter == null) return;

    Rectangle bounds = new Rectangle(0, 0, getWidth(), getHeight());
    Rectangle clip = g.getClipBounds();
    if (clip == null) g.setClip(bounds);
    else g.setClip(clip.intersection(bounds));

    super.paint(g);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ProfilerXYTooltipOverlay.java

示例10: paint

import java.awt.Graphics; //导入方法依赖的package包/类
public void paint(Graphics g, Shape a) {
    if (!(getDocument() instanceof BaseDocument)) return; //#48134
    // When painting make sure the estimated span is set to false
    setEstimatedSpan(false);
    // No modifications to allocReadOnly variable!
    Rectangle allocReadOnly = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
    int startOffset = getStartOffset();
    int endOffset = getAdjustedEOLOffset();
    try{
        if (isFragment()){
            Rectangle oldClipRect = g.getClipBounds();                
            Rectangle newClip = new Rectangle(oldClipRect);
            Rectangle startOffsetClip = modelToView(startOffset, a, Position.Bias.Forward).getBounds();
            Rectangle endOffsetClip = modelToView(endOffset, a, Position.Bias.Forward).getBounds();
            View parent = getParent();
            if (parent instanceof FoldMultiLineView && !equals(parent.getView(parent.getViewCount() - 1))) {
                newClip.width = Math.min(oldClipRect.width, endOffsetClip.x);
                
                if (newClip.width + newClip.x > endOffsetClip.x) {
                    newClip.width = newClip.width - (newClip.width + newClip.x - endOffsetClip.x);
                }
                
                g.setClip(newClip);
            }

            int shift = startOffsetClip.x - getEditorUI().getTextMargin().left - allocReadOnly.x;
            g.translate(-shift,0);
            
            DrawEngine.getDrawEngine().draw(this, new DrawGraphics.GraphicsDG(g),
            getEditorUI(), startOffset, endOffset,
            getBaseX(allocReadOnly.x), allocReadOnly.y, Integer.MAX_VALUE);
            
            g.translate(shift,0);                
            g.setClip(oldClipRect);

        }else{
            JTextComponent component = getComponent();
            if (component!=null){
                long ts1 = 0, ts2 = 0;
                if (loggable) {
                    ts1 = System.currentTimeMillis();
                }
                
                // Translate the graphics clip region to the document offsets
                // and their view region
                Rectangle clip = g.getClipBounds();
                int fromOffset = viewToModel(clip.x, clip.y, allocReadOnly, null);
                int toOffset = viewToModel(clip.x + clip.width, clip.y, allocReadOnly, null);
                
                fromOffset = Math.max(fromOffset - 1, getStartOffset());
                toOffset = Math.min(toOffset + 1, getAdjustedEOLOffset());
                
                Rectangle rr = modelToView(fromOffset, allocReadOnly, Position.Bias.Forward).getBounds();
                
                DrawEngine.getDrawEngine().draw(this, new DrawGraphics.GraphicsDG(g),
                    getEditorUI(), fromOffset, toOffset,
                    rr.x, rr.y, Integer.MAX_VALUE);
                
                if (loggable) {
                    ts2 = System.currentTimeMillis();
                    if (ts2 - ts1 > PERF_TRESHOLD) {
                        LOG.finest("paint: " + //NOI18N
                            "<" + fromOffset + ", " + toOffset + ">, " + //NOI18N
                            "DrawEngine.startX = " + rr.x + ", DrawEngine.startY = " + rr.y + ", " + //NOI18N
                            "shape = [" + allocReadOnly.x + ", " + allocReadOnly.y + ", " + allocReadOnly.width + ", " + allocReadOnly.height + "], " + //NOI18N
                            "clip = [" + clip.x + ", " + clip.y + ", " + clip.width + ", " + clip.height + "] " + //NOI18N
                            "took " + (ts2 - ts1) + " msec"); //NOI18N
                    }
                }
            }
        }
    } catch (BadLocationException ble) {
        LOG.log(Level.INFO, "Painting the view failed", ble); //NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:DrawEngineLineView.java

示例11: 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

示例12: updateTooltipImage

import java.awt.Graphics; //导入方法依赖的package包/类
private boolean updateTooltipImage(RenderedImage contents, int row, int col) {
            TableCellRenderer renderer = listClasses.getCellRenderer(row, col); 
            Component component = listClasses.prepareRenderer(renderer, row, col);
            
            if (!(component instanceof JComponent)) {
                // sorry.
                return false;
            }
            Rectangle cellRect = listClasses.getCellRect(row, col, false);
            Dimension size = component.getPreferredSize();
            Rectangle visibleRect = listClasses.getVisibleRect();
            
            // The visible region is wide enough, hide the tooltip
            if (cellRect.width >= size.width) {
                hidePopup();
                return false;
            }           
            // Hide if the cell does not vertically fit
            if (cellRect.y + size.height > visibleRect.y + visibleRect.height + 1) {
                hidePopup();
                return false;
            }
            BufferedImage img = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
            Graphics g = img.getGraphics();
            g.setClip(null);
            g.setColor(listClasses.getBackground());
            g.fillRect(0, 0, size.width, size.height);
            g.translate(-cellRect.x, -cellRect.y);
//            g.translate(-visibleRect.x, -visibleRect.y);
            
            cellRect.width = size.width;
            // prevent some repaing issues, see javadoc for CellRendererPane.
            rendererPane.paintComponent(g, component, listClasses, cellRect);
            
            // if table displays lines, frame the cell's display using lines.
            if (listClasses.getShowHorizontalLines()) {
                int rightX = size.width - 1;
                g.translate(cellRect.x, cellRect.y);
                g.setColor(listClasses.getForeground());
                g.drawLine(0, 0, rightX, 0);
                g.drawLine(rightX, 0, rightX, size.height);
                g.drawLine(rightX, size.height - 1, 0, size.height - 1);
            }
            g.dispose();
            rendererPane.remove(component);
            contents.setImage(img);
            return true;
        }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:49,代码来源:InnerPanelSupport.java

示例13: 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

示例14: paint

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * Invokes paint and update on target Component with optimal
 * rectangular clip region.
 * If PAINT bounding rectangle is less than
 * MAX_BENEFIT_RATIO times the benefit, then the vertical and horizontal unions are
 * painted separately.  Otherwise the entire bounding rectangle is painted.
 *
 * @param   target Component to <code>paint</code> or <code>update</code>
 * @since   1.4
 */
public void paint(Object target, boolean shouldClearRectBeforePaint) {
    Component comp = (Component)target;

    if (isEmpty()) {
        return;
    }

    if (!comp.isVisible()) {
        return;
    }

    RepaintArea ra = this.cloneAndReset();

    if (!subtract(ra.paintRects[VERTICAL], ra.paintRects[HORIZONTAL])) {
        subtract(ra.paintRects[HORIZONTAL], ra.paintRects[VERTICAL]);
    }

    if (ra.paintRects[HORIZONTAL] != null && ra.paintRects[VERTICAL] != null) {
        Rectangle paintRect = ra.paintRects[HORIZONTAL].union(ra.paintRects[VERTICAL]);
        int square = paintRect.width * paintRect.height;
        int benefit = square - ra.paintRects[HORIZONTAL].width
            * ra.paintRects[HORIZONTAL].height - ra.paintRects[VERTICAL].width
            * ra.paintRects[VERTICAL].height;
        // if benefit is comparable with bounding box
        if (MAX_BENEFIT_RATIO * benefit < square) {
            ra.paintRects[HORIZONTAL] = paintRect;
            ra.paintRects[VERTICAL] = null;
        }
    }
    for (int i = 0; i < paintRects.length; i++) {
        if (ra.paintRects[i] != null
            && !ra.paintRects[i].isEmpty())
        {
            // Should use separate Graphics for each paint() call,
            // since paint() can change Graphics state for next call.
            Graphics g = comp.getGraphics();
            if (g != null) {
                try {
                    g.setClip(ra.paintRects[i]);
                    if (i == UPDATE) {
                        updateComponent(comp, g);
                    } else {
                        if (shouldClearRectBeforePaint) {
                            g.clearRect( ra.paintRects[i].x,
                                         ra.paintRects[i].y,
                                         ra.paintRects[i].width,
                                         ra.paintRects[i].height);
                        }
                        paintComponent(comp, g);
                    }
                } finally {
                    g.dispose();
                }
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:68,代码来源:RepaintArea.java

示例15: 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


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