Java Code Examples for java.awt.Graphics#setClip()

The following examples show how to use java.awt.Graphics#setClip() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoundedRectanglePopup.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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();
	}
}
 
Example 2
Source File: FadingButtonTF.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void paint(Graphics g) {
       // Create an image for the button graphics if necessary
       if (buttonImage == null || buttonImage.getWidth() != getWidth() ||
               buttonImage.getHeight() != getHeight()) {
           buttonImage = getGraphicsConfiguration().
                   createCompatibleImage(getWidth(), getHeight());
       }
       Graphics gButton = buttonImage.getGraphics();
       gButton.setClip(g.getClip());
       
       //  Have the superclass render the button for us
       super.paint(gButton);
       
       // Make the graphics object sent to this paint() method translucent
Graphics2D g2d  = (Graphics2D)g;
AlphaComposite newComposite = 
    AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
g2d.setComposite(newComposite);
       
       // Copy the button's image to the destination graphics, translucently
       g2d.drawImage(buttonImage, 0, 0, null);
   }
 
Example 3
Source File: ProfilerXYTooltipOverlay.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: Test6978482.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: Test6978482.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 6
Source File: ComponentPaintCache.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Paint the cached component.
 *
 * @param g graphics
 */
public void paintComponent(Graphics g) {
	/*
	 * A Component listener would be cleaner way to detect resizes.
	 * Unfortunately the component gets drawn before the listener gets
	 * notified.
	 */
	int width = component.getWidth();
	int height = component.getHeight();
	if (cachedImage == null || (oldWidth != width) || (oldHeight != height)) {
		oldWidth = width;
		oldHeight = height;

		// Create a new image, and draw the components onto it
		cachedImage = component.getGraphicsConfiguration().createCompatibleImage(width, height, Transparency.OPAQUE);
		Graphics imageGraphics = cachedImage.getGraphics();
		imageGraphics.setClip(0, 0, width, height);
		component.paintComponent(imageGraphics);
		component.paintBorder(imageGraphics);
		if (paintChildren) {
			/*
			 * JComponent.paint produces garbage, and paintComponent &
			 * paintBorder need to be exposed for those that can't include
			 * the children anyway. Otherwise it would be easiest to use
			 * SwingUtilities.paintComponent and accept JComponent in the
			 * constructor, but now we need the interface anyway.
			 */
			component.paintChildren(imageGraphics);
		}
		imageGraphics.dispose();
	}
	g.drawImage(cachedImage, 0, 0, null);
}
 
Example 7
Source File: Test6978482.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 8
Source File: Test6978482.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: Test6978482.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: Test6978482.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 11
Source File: GuiBoard.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
private void drawImage()
{
    if (m_image == null || m_dirty == null)
        return;
    if (DEBUG_REPAINT)
        System.err.println("BoardPanel.drawImage " + m_dirty.x + " "
                           + m_dirty.y + " " + m_dirty.width + " "
                           + m_dirty.height);
    Graphics graphics = m_image.getGraphics();
    graphics.setClip(m_dirty);
    m_painter.draw(graphics, m_field, m_imageWidth, m_showGrid);
    m_dirty = null;
}
 
Example 12
Source File: MultiColumnListUI.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
/**
  * Paint the rows that intersect the Graphics objects clipRect.  This
  * method calls paintCell as necessary.  Subclasses
  * may want to override these methods.
  *
  * @see #paintCell
  */
 public void paint(Graphics g, JComponent c)
 {
   maybeUpdateLayoutState();
   
   ListCellRenderer   renderer  = list.getCellRenderer();
   ListModel          dataModel = list.getModel();
   ListSelectionModel selModel  = list.getSelectionModel();
   
   if ((renderer == null) || (dataModel.getSize() == 0)) {
     return;
   }
   
   /* Compute the area we're going to paint in terms of the affected
    * rows (firstPaintRow, lastPaintRow), and the clip bounds.
    */
   
   Rectangle paintBounds   = g.getClipBounds();
   int       firstPaintRow = locationToIndex(paintBounds.x, paintBounds.y);
   int       lastPaintRow  = locationToIndex((paintBounds.x + paintBounds.width) - 1, (paintBounds.y + paintBounds.height) - 1);
   
   if (firstPaintRow == -1) {
     firstPaintRow = 0;
   }
   if (lastPaintRow == -1) {
     lastPaintRow = dataModel.getSize() - 1;
   }
   
   Rectangle rowBounds = getCellBounds(list, firstPaintRow, lastPaintRow);
   if (rowBounds == null) {
     return;
   }
   
   int leadIndex = list.getLeadSelectionIndex();
   
   for(int row = firstPaintRow; row <= lastPaintRow; row++) {
     /* Set the clip rect to be the intersection of rowBounds
      * and paintBounds and then paint the cell.
      */
     
     g.setClip(rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
     g.clipRect(paintBounds.x, paintBounds.y, paintBounds.width, paintBounds.height);
     
     Rectangle bounds = getCellBounds(row);
     if(bounds != null)
paintCell(g, row, bounds, renderer, dataModel, selModel, leadIndex);
   }
 }
 
Example 13
Source File: RepaintArea.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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();
                }
            }
        }
    }
}
 
Example 14
Source File: MemoryStatus.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
@Override
    public void paintComponent(Graphics g) {
        Insets insets = new Insets(0, 0, 0, 0);
//        MemoryStatus.this.getBorder().getBorderInsets(this);

        Runtime runtime = Runtime.getRuntime();
        int freeMemory = (int) (runtime.freeMemory() / 1024);
        int totalMemory = (int) (runtime.totalMemory() / 1024);
        int usedMemory = (totalMemory - freeMemory);

        int width = MemoryStatus.this.getWidth() - insets.left - insets.right;
//        int height = MemoryStatus.this.getHeight() - insets.top - insets.bottom - 1;
        int height = MemoryStatus.this.getHeight() - insets.top - insets.bottom;

        float fraction = ((float) usedMemory) / totalMemory;

        g.setColor(PROGRESS_BACKGROUND);
        g.fillRect(insets.left, insets.top, (int) (width * fraction), height);

        String str = (usedMemory / 1024) + "/" + (totalMemory / 1024) + "M";

        FontRenderContext fontRendererContext = new FontRenderContext(null, false, false);

        Rectangle2D bounds = g.getFont().getStringBounds(str, fontRendererContext);

        Graphics g2 = g.create();
        g2.setClip(insets.left, insets.top, (int) (width * fraction), height);
        g2.setColor(PROGRESS_FOREGROUND);
        g2.drawString(str, insets.left + (int) (width - bounds.getWidth()) / 2,
                (int) (insets.top + lineMetrics.getAscent()));

        g2.dispose();
        g2 = g.create();

        g2.setClip(insets.left + (int) (width * fraction), insets.top,
                MemoryStatus.this.getWidth() - insets.left
                        - (int) (width * fraction), height);

        g2.setColor(MemoryStatus.this.getForeground());

        g2.drawString(str, insets.left + (int) (width - bounds.getWidth()) / 2,
                (int) (insets.top + lineMetrics.getAscent()));

        g2.dispose();
    }
 
Example 15
Source File: Print.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 16
Source File: RepaintArea.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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();
                }
            }
        }
    }
}
 
Example 17
Source File: RepaintArea.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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();
                }
            }
        }
    }
}
 
Example 18
Source File: FlatJideTabbedPaneUI.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
/**
 * Actually does the nearly the same as super.paintContentBorder() but
 *   - not invoking paintContentBorder*Edge() methods
 *   - repaint selection
 */
@Override
protected void paintContentBorder( Graphics g, int tabPlacement, int selectedIndex ) {
	if( _tabPane.getTabCount() <= 0 )
		return;

	Insets insets = _tabPane.getInsets();
	Insets tabAreaInsets = getTabAreaInsets( tabPlacement );

	int x = insets.left;
	int y = insets.top;
	int w = _tabPane.getWidth() - insets.right - insets.left;
	int h = _tabPane.getHeight() - insets.top - insets.bottom;

	Dimension lsize = isTabLeadingComponentVisible() ? _tabLeadingComponent.getPreferredSize() : new Dimension();
	Dimension tsize = isTabTrailingComponentVisible() ? _tabTrailingComponent.getPreferredSize() : new Dimension();

	// remove tabs from bounds
	switch( tabPlacement ) {
		case LEFT:
			x += Math.max( calculateTabAreaWidth( tabPlacement, _runCount, _maxTabWidth ),
				Math.max( lsize.width, tsize.width ) );
			if( tabsOverlapBorder )
				x -= tabAreaInsets.right;
			w -= (x - insets.left);
			break;
		case RIGHT:
			w -= calculateTabAreaWidth( tabPlacement, _runCount, _maxTabWidth );
			if( tabsOverlapBorder )
				w += tabAreaInsets.left;
			break;
		case BOTTOM:
			h -= calculateTabAreaHeight( tabPlacement, _runCount, _maxTabHeight );
			if( tabsOverlapBorder )
				h += tabAreaInsets.top;
			break;
		case TOP:
		default:
			y += Math.max( calculateTabAreaHeight( tabPlacement, _runCount, _maxTabHeight ),
				Math.max( lsize.height, tsize.height ) );
			if( tabsOverlapBorder )
				y -= tabAreaInsets.bottom;
			h -= (y - insets.top);
	}

	// compute insets for separator or full border
	boolean hasFullBorder = clientPropertyBoolean( _tabPane, TABBED_PANE_HAS_FULL_BORDER, this.hasFullBorder );
	int sh = scale( contentSeparatorHeight * 100 ); // multiply by 100 because rotateInsets() does not use floats
	Insets ci = new Insets( 0, 0, 0, 0 );
	rotateInsets( hasFullBorder ? new Insets( sh, sh, sh, sh ) : new Insets( sh, 0, 0, 0 ), ci, tabPlacement );

	// paint content area
	g.setColor( contentAreaColor );
	Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
	path.append( new Rectangle2D.Float( x, y, w, h ), false );
	path.append( new Rectangle2D.Float( x + (ci.left / 100f), y + (ci.top / 100f),
		w - (ci.left / 100f) - (ci.right / 100f), h - (ci.top / 100f) - (ci.bottom / 100f) ), false );
	((Graphics2D)g).fill( path );

	// repaint selection in scroll-tab-layout because it may be painted before
	// the content border was painted (from BasicTabbedPaneUI$ScrollableTabPanel)
	if( scrollableTabLayoutEnabled() && selectedIndex >= 0 && _tabScroller != null && _tabScroller.viewport != null ) {
		Rectangle tabRect = getTabBounds( _tabPane, selectedIndex );

		Shape oldClip = g.getClip();
		g.setClip( _tabScroller.viewport.getBounds() );
		paintTabSelection( g, tabPlacement, tabRect.x, tabRect.y, tabRect.width, tabRect.height );
		g.setClip( oldClip );
	}
}
 
Example 19
Source File: GlyphVectorPainter.java    From PolyGlot with MIT License 4 votes vote down vote up
/**
 * Paints the glyphs representing the given range.
 */
@Override
public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
    try {
        sync(v);

        if (a != null ) {
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            String localText;
            TabExpander expander = v.getTabExpander();
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();

            // determine the x coordinate to render the glyphs
            int x = alloc.x;
            int p = v.getStartOffset();
            if (p != p0) {
                localText = v.getDocument().getText(p, p0-p);
                float width = getTabbedTextWidth(v, localText, x, expander, p, null);
                x += width;
            }

            // determine the y coordinate to render the glyphs
            int y = alloc.y + Math.round(lm.getHeight() - lm.getDescent());

            // render the glyphs
            localText = v.getDocument().getText(p0, p1-p0);
            g.setFont(font);

            if( p0 > v.getStartOffset() || p1 < v.getEndOffset() ) {
                Shape s = v.modelToView(p0, Position.Bias.Forward,
                                        p1, Position.Bias.Backward, a);
                Shape savedClip = g.getClip();
                ((Graphics2D)g).clip(s);
                x=v.modelToView(v.getStartOffset(), a, Position.Bias.Forward).getBounds().x;
                drawTabbedText(v, localText, x, y, g, expander,p0, null);
                g.setClip(savedClip);
            }
            else {
                drawTabbedText(v, localText, x, y, g, expander,p0, null);                
            }
        }

    } catch (BadLocationException e) {
        //e.printStackTrace();
        IOHandler.writeErrorLog(e, "EXTERNAL CODE");
    }
}
 
Example 20
Source File: RepaintArea.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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();
                }
            }
        }
    }
}