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


Java Graphics.getClipBounds方法代码示例

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


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

示例1: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 
 */
public void paintComponent(Graphics g)
{
	if (gradientColor == null)
	{
		super.paintComponent(g);
	}
	else
	{
		Rectangle rect = getVisibleRect();

		if (g.getClipBounds() != null)
		{
			rect = rect.intersection(g.getClipBounds());
		}

		Graphics2D g2 = (Graphics2D) g;

		g2.setPaint(new GradientPaint(0, 0, getBackground(), getWidth(), 0,
				gradientColor));
		g2.fill(rect);
	}
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:26,代码来源:EditorPalette.java

示例2: paint

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * Paints this JLayeredPane within the specified graphics context.
 *
 * @param g  the Graphics context within which to paint
 */
public void paint(Graphics g) {
    if(isOpaque()) {
        Rectangle r = g.getClipBounds();
        Color c = getBackground();
        if(c == null)
            c = Color.lightGray;
        g.setColor(c);
        if (r != null) {
            g.fillRect(r.x, r.y, r.width, r.height);
        }
        else {
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    }
    super.paint(g);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:JLayeredPane.java

示例3: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, JComponent c) {
	recalculateIfInsetsChanged();
	recalculateIfOrientationChanged();
	Rectangle clip = g.getClipBounds();

	if (!clip.intersects(trackRect) && slider.getPaintTrack()) {
		calculateGeometry();
	}

	if (slider.getPaintTrack() && clip.intersects(trackRect)) {
		paintTrack(g);
	}
	if (slider.hasFocus() && clip.intersects(focusRect)) {
		paintFocus(g);
	}

	// the ticks are now inside the track so they have to be painted each thumb movement
	paintTicks(g);
	// thumb is always painted due to value below thumb
	paintThumb(g);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:23,代码来源:SliderUI.java

示例4: paintHorizontalSeparators

import java.awt.Graphics; //导入方法依赖的package包/类
protected void paintHorizontalSeparators(Graphics g, JComponent c) {
	Rectangle clipBounds = g.getClipBounds();

	int beginRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y));
	int endRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y + clipBounds.height - 1));

	if ((beginRow <= -1) || (endRow <= -1)) {
		return;
	}

	for (int i = beginRow; i <= endRow; ++i) {
		TreePath path = getPathForRow(this.tree, i);

		if ((path != null) && (path.getPathCount() == 2)) {
			Rectangle rowBounds = getPathBounds(this.tree, getPathForRow(this.tree, i));

			// Draw a line at the top
			if (rowBounds != null) {
				g.drawLine(clipBounds.x, rowBounds.y, clipBounds.x + clipBounds.width, rowBounds.y);
			}
		}
	}

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:25,代码来源:TreeUI.java

示例5: fillClippedRect

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * 
 */
public static void fillClippedRect(Graphics g, int x, int y, int width,
		int height)
{
	Rectangle bg = new Rectangle(x, y, width, height);

	try
	{
		if (g.getClipBounds() != null)
		{
			bg = bg.intersection(g.getClipBounds());
		}
	}
	catch (Exception e)
	{
		// FIXME: Getting clipbounds sometimes throws an NPE
	}

	g.fillRect(bg.x, bg.y, bg.width, bg.height);
}
 
开发者ID:GDSRS,项目名称:TrabalhoFinalEDA2,代码行数:23,代码来源:mxUtils.java

示例6: paint

import java.awt.Graphics; //导入方法依赖的package包/类
/** It divides painting into three areas:
* INSETS_TOP, MAIN_AREA, INSETS_BOTTOM. It paints them sequentially
* using <CODE>paintArea()</CODE> method until it returns false.
* This implementation also supposes that <CODE>allocation</CODE> is
* instance of <CODE>Rectangle</CODE> to save object creations. The root
* view in TextUI implementation will take care to ensure child views will
* get rectangle instances.
*/
public void paint(Graphics g, Shape allocation) {
    Rectangle clip = g.getClipBounds();
    if (clip.height < 0 || clip.width < 0) {
        return;
    }
    int paintAreas = getPaintAreas(g, clip.y, clip.height);
    if (paintAreas != 0) {
        paintAreas(g, clip.y, clip.height, paintAreas);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:BaseView.java

示例7: paint

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

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

示例9: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g) {
    Rectangle cp = g.getClipBounds();
    g.setColor(getBackground());
    g.fillRect(cp.x, cp.y, cp.width, cp.height);
    if (lines == null) {
        return;
    }
    g.setColor(getForeground());
    FontMetrics fontMetrics = textView.getFontMetrics(textView.getFont());
    int lineHeight = fontMetrics.getHeight();
    int descent = fontMetrics.getDescent();
    int offset = 0;
    try {
        Rectangle modelToView = textView.modelToView(0);
        offset = modelToView == null ? 0 : modelToView.y;
    } catch (BadLocationException ex) {
        LOG.log(Level.INFO, null, ex);
    }
    offset += lineHeight - fontMetrics.getAscent();

    int size = lines.getLineCount();
    int logLine = 0; // logical line (including wrapped lines)
    int nextLogLine;
    int firstVisibleLine = Math.max(0, getLineAtPosition(cp.y) - 1);
    int lastVisibleLine = getLastVisibleLine(cp, size);
    for (int i = firstVisibleLine; i < lastVisibleLine; i++) {
        if (!lines.isVisible(i)) {
            continue;
        }
        nextLogLine = findLogicalLineIndex(findNextVisibleLine(i), size);
        drawLineGraphics(g, i, logLine, nextLogLine, offset, lineHeight,
                descent);
        logLine = nextLogLine;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:FoldingSideBar.java

示例10: paintEmptyRows

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * Paints the backgrounds of the implied empty rows when the
 * table model is insufficient to fill all the visible area
 * available to us. We don't involve cell renderers, because
 * we have no data.
 */
protected void paintEmptyRows(Graphics g) {
    final int rowCount = getRowCount();
    final Rectangle clip = g.getClipBounds();
    final int height = clip.y + clip.height;
    if (rowCount * rowHeight < height) {
        for (int i = rowCount; i <= height / rowHeight; ++i) {
            g.setColor(backgroundColorForRow(i));
            g.fillRect(clip.x, i * rowHeight, clip.width, rowHeight);
            drawHorizontalLine(g, clip, i);
        }
        drawVerticalLines(g, rowCount, height);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:JXTableDecorator.java

示例11: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g)
{
	// Draw the background:
	if( getBackground() != null )
	{
		Rectangle clip = g.getClipBounds();
		g.setColor(getBackground());
		g.fillRect(clip.x, clip.y, clip.width, clip.height);
	}

	// Draw the backing to the text:
	int transX = (int) g.getFontMetrics().getStringBounds(getText(), g).getWidth() + getInsets().left;

	if( TEXT_BACK != null && TEXT_BACK.getWidth(null) > 0 )
	{
		for( int i = 0; i < transX; i += TEXT_BACK.getWidth(null) )
			g.drawImage(TEXT_BACK, i, 0, null);
	}

	// Draw transition:
	if( transition != null )
	{
		g.drawImage(transition, transX, 0, null);
	}

	// Draw the text:
	super.paint(g);
}
 
开发者ID:equella,项目名称:Equella,代码行数:30,代码来源:JFlatDialog.java

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

示例13: print

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public int print(Graphics base, PageFormat format, int pageIndex) {
	if (pageIndex >= circuits.size())
		return Printable.NO_SUCH_PAGE;

	Circuit circ = circuits.get(pageIndex);
	CircuitState circState = proj.getCircuitState(circ);
	Graphics g = base.create();
	Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
	FontMetrics fm = g.getFontMetrics();
	String head = (header != null && !header.equals(""))
			? format(header, pageIndex + 1, circuits.size(), circ.getName())
			: null;
	int headHeight = (head == null ? 0 : fm.getHeight());

	// Compute image size
	double imWidth = format.getImageableWidth();
	double imHeight = format.getImageableHeight();

	// Correct coordinate system for page, including
	// translation and possible rotation.
	Bounds bds = circ.getBounds(g).expand(4);
	double scale = Math.min(imWidth / bds.getWidth(), (imHeight - headHeight) / bds.getHeight());
	if (g2 != null) {
		g2.translate(format.getImageableX(), format.getImageableY());
		if (rotateToFit && scale < 1.0 / 1.1) {
			double scale2 = Math.min(imHeight / bds.getWidth(), (imWidth - headHeight) / bds.getHeight());
			if (scale2 >= scale * 1.1) { // will rotate
				scale = scale2;
				if (imHeight > imWidth) { // portrait -> landscape
					g2.translate(0, imHeight);
					g2.rotate(-Math.PI / 2);
				} else { // landscape -> portrait
					g2.translate(imWidth, 0);
					g2.rotate(Math.PI / 2);
				}
				double t = imHeight;
				imHeight = imWidth;
				imWidth = t;
			}
		}
	}

	// Draw the header line if appropriate
	if (head != null) {
		g.drawString(head, (int) Math.round((imWidth - fm.stringWidth(head)) / 2), fm.getAscent());
		if (g2 != null) {
			imHeight -= headHeight;
			g2.translate(0, headHeight);
		}
	}

	// Now change coordinate system for circuit, including
	// translation and possible scaling
	if (g2 != null) {
		if (scale < 1.0) {
			g2.scale(scale, scale);
			imWidth /= scale;
			imHeight /= scale;
		}
		double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
		g2.translate(-bds.getX() + dx, -bds.getY());
	}

	// Ensure that the circuit is eligible to be drawn
	Rectangle clip = g.getClipBounds();
	clip.add(bds.getX(), bds.getY());
	clip.add(bds.getX() + bds.getWidth(), bds.getY() + bds.getHeight());
	g.setClip(clip);

	// And finally draw the circuit onto the page
	ComponentDrawContext context = new ComponentDrawContext(proj.getFrame().getCanvas(), circ, circState, base,
			g, printerView);
	Collection<Component> noComps = Collections.emptySet();
	circ.draw(context, noComps);
	g.dispose();
	return Printable.PAGE_EXISTS;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:79,代码来源:Print.java

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

示例15: paintChildren

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * Paint the children that intersect the clip area.
 *
 * @param g graphics to render into.
 * @param alloc allocation for the parent view including the insets.
 *  The rectangle can be mutated.
 */
protected void paintChildren(Graphics g, Rectangle alloc) {
    int viewAllocX = alloc.x;
    int viewAllocY = alloc.y;
    // int viewAllocWidth = alloc.width;
    // int viewAllocHeight = alloc.height;
    
    alloc = g.getClipBounds(alloc); // get the clip - reuse alloc variable
    if (alloc == null) { // no clip => return
        return;
    }
    int clipX = alloc.x;
    int clipY = alloc.y;
    boolean isXMajorAxis = view.isXMajorAxis();
    int clipEnd = isXMajorAxis
        ? (clipX + alloc.width)
        : (clipY + alloc.height);
    

    int childIndex = getChildIndexAtCorePoint(clipX, clipY);
    int childCount = getChildCount();

    for (int i = Math.max(childIndex, 0); i < childCount; i++) {
        ViewLayoutState child = getChild(i);
        // Reuse alloc for child's allocation
        alloc = getChildCoreAllocation(i, alloc);
        alloc.x += viewAllocX;
        alloc.y += viewAllocY;
        /*
         * Paint the child if it lies before the end of the clip.
         * We should also check whether the child
         * fits into the allocation given to this view by checking whether
         *     parentViewAllocation.intersects(childAllocation))
         * but for the orthogonal use this should not be necessary.
         */
        int allocStart = isXMajorAxis ? alloc.x : alloc.y;
                
        if (allocStart < clipEnd) { // child at least partly inside clip
            
            View v = child.getView();
            v.paint(g, alloc);
        } else {
            break; // stop painting of children
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:GapBoxViewChildren.java


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