Java Code Examples for java.awt.Graphics#getClip()
The following examples show how to use
java.awt.Graphics#getClip() .
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: PicMap.java From megamek with GNU General Public License v2.0 | 6 votes |
private void drawInto(Graphics g) { int w = Math.max(getSize().width, minWidth); int h = Math.max(getSize().height, minHeight); // Background painting Enumeration<BackGroundDrawer> iter = bgDrawers.elements(); while (iter.hasMoreElements()) { BackGroundDrawer bgd = iter.nextElement(); bgd.drawInto(g, w, h); } Shape oldClip = g.getClip(); g.setClip(new Rectangle(leftMargin, topMargin, w - leftMargin - rightMargin, h - topMargin - bottomMargin)); // Hot areas painting hotAreas.drawInto(g); if (activeHotArea != null) activeHotArea.drawInto(g); labels.drawInto(g); g.setClip(oldClip); }
Example 2
Source File: Histogram.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Draws this histogram in the drawing panel. * * @param drawingPanel * @param g */ public synchronized void draw(DrawingPanel drawingPanel, Graphics g) { if(bins.size()==0 || !visible) { return; } Shape oldClip = g.getClip(); g.setColor(binFillColor); g.clipRect(0, 0, drawingPanel.getWidth(), drawingPanel.getHeight()); for(Iterator<Integer> keys = bins.keySet().iterator(); keys.hasNext(); ) { Integer binNumber = keys.next(); Double d = (bins.get(binNumber)); if(d==null) { return; } double occurrences = d.doubleValue(); if(normalizedToOne) { occurrences /= sum; } if(binStyle==DRAW_BIN) { drawBin(drawingPanel, g, binNumber.intValue(), occurrences); } else { drawPoint(drawingPanel, g, binNumber.intValue(), occurrences); } } g.setClip(oldClip); }
Example 3
Source File: NimbusEditorTabCellRenderer.java From netbeans with Apache License 2.0 | 5 votes |
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); } }
Example 4
Source File: GradientOverlay.java From 07kit with GNU General Public License v3.0 | 5 votes |
private void paintGradient(Graphics g, int cornerRadius) { final Graphics2D copy = (Graphics2D) g.create(); copy.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Shape clip = g.getClip(); GradientPaint mask = new GradientPaint(0, 0, fStartColor, 0, clip.getBounds().height, fEndColor); copy.setPaint(mask); if(cornerRadius == 0) { copy.fill(clip); } else { copy.fill(new RoundRectangle2D.Double(0, 0, clip.getBounds().getWidth(), clip.getBounds().getHeight(), cornerRadius, cornerRadius)); } copy.dispose(); }
Example 5
Source File: SeaGlassSplitPaneUI.java From seaglass with Apache License 2.0 | 5 votes |
private void paintDragDivider(Graphics g, int x, int y, int w, int h) { SeaGlassContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER); context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^ MOUSE_OVER) | PRESSED); Shape oldClip = g.getClip(); g.clipRect(x, y, w, h); context.getPainter().paintSplitPaneDragDivider(context, g, x, y, w, h, splitPane.getOrientation()); g.setClip(oldClip); context.dispose(); }
Example 6
Source File: ColorLabel.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void drawChessboardBackground(Graphics g, int x, int y, int w, int h) { int s = 8; int ni = w / s + 1; int nj = h / s + 1; Shape clip = g.getClip(); g.setClip(x, y, w, h); for (int j = 0; j < nj; j++) { for (int i = 0; i < ni; i++) { g.setColor(i % 2 != j % 2 ? Color.WHITE : Color.LIGHT_GRAY); g.fillRect(x + i * s, y + j * s, s, s); } } g.setClip(clip); }
Example 7
Source File: CellLatticeOSX.java From osp with GNU General Public License v3.0 | 5 votes |
/** * Draws the lattice and the grid. * * @param panel * @param g */ public void draw(DrawingPanel panel, Graphics g) { if(!visible) { return; } double ymax = this.ymax; double xmin = this.xmin; if(panel.getXMax()<panel.getXMin()) { // x axis is flipped xmin = (dx<0) ? this.xmin-dx : this.xmin+dx; } if(panel.getYMax()<panel.getYMin()) { // yaxis is flipped ymax = (dy<0) ? this.ymax+dy : this.ymax-dy; } double x = (dx<0) ? xmin+dx : xmin; double y = (dy<0) ? ymax-dy : ymax; int x1pix = panel.xToPix(x); int y1pix = panel.yToPix(y); int x2pix, y2pix; Shape clipShape = g.getClip(); Rectangle r = getBounds(panel); g.clipRect(r.x, r.y, r.width, r.height); for(int ix = 0; ix<nx; ix++) { x += dx; x2pix = panel.xToPix(x); for(int iy = ny-1; iy>=0; iy--) { // start at top y -= dy; y2pix = panel.yToPix(y); int val = data[ix][iy]&0xFF; g.setColor(colors[val]); g.fillRect(x1pix, y1pix, Math.abs(x2pix-x1pix)+1, Math.abs(y1pix-y2pix)+1); y1pix = y2pix; } x1pix = x2pix; y = (dy<0) ? ymax-dy : ymax; y1pix = panel.yToPix(y); } g.setClip(clipShape); super.draw(panel, g); // draw the grid }
Example 8
Source File: FlatJideTabbedPaneUI.java From FlatLaf with Apache License 2.0 | 4 votes |
/** * 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 9
Source File: FlatTabbedPaneUI.java From FlatLaf with Apache License 2.0 | 4 votes |
/** * Actually does nearly the same as super.paintContentBorder() but * - not using UIManager.getColor("TabbedPane.contentAreaColor") to be GUI builder friendly * - 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; // remove tabs from bounds switch( tabPlacement ) { case LEFT: x += calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth ); 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 += calculateTabAreaHeight( tabPlacement, runCount, maxTabHeight ); 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( isScrollTabLayout() && selectedIndex >= 0 ) { Component scrollableTabViewport = findComponentByClassName( tabPane, BasicTabbedPaneUI.class.getName() + "$ScrollableTabViewport" ); if( scrollableTabViewport != null ) { Rectangle tabRect = getTabBounds( tabPane, selectedIndex ); Shape oldClip = g.getClip(); g.setClip( scrollableTabViewport.getBounds() ); paintTabSelection( g, tabPlacement, tabRect.x, tabRect.y, tabRect.width, tabRect.height ); g.setClip( oldClip ); } } }
Example 10
Source File: NimbusViewTabDisplayerUI.java From netbeans with Apache License 2.0 | 4 votes |
@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); } }
Example 11
Source File: Loupe.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void paintComponent(Graphics g) { if (buffer == null) { buffer = createBuffer(); } Graphics2D g2 = buffer.createGraphics(); g2.setComposite(AlphaComposite.Clear); g2.fillRect(0, 0, buffer.getWidth(), buffer.getHeight()); g2.setComposite(AlphaComposite.Src); Point location = getLocation(); location.translate(getWidth() / 2, getHeight() / 2); int myLayer = layeredPane.getLayer(this); for (int i = myLayer - 1; i >= 2; i -= 2) { Component[] components = layeredPane.getComponentsInLayer(i); for (Component c : components) { if (c.getBounds().contains(location)) { g2.translate(c.getX(), c.getY()); c.paint(g2); g2.translate(-c.getX(), -c.getY()); } } } g2.dispose(); if (zoomLevel > 1) { ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); Shape clip = g.getClip(); Area newClip = new Area(clip); newClip.intersect(new Area(new Ellipse2D.Double(6.0, 6.0, 138.0, 138.0))); g.setClip(newClip); g.drawImage(buffer, (int) (-getX() * zoomLevel - getWidth() * 0.5 * (zoomLevel - 1)), (int) (-getY() * zoomLevel - getHeight() * 0.5 * (zoomLevel - 1)), buffer.getWidth() * zoomLevel, buffer.getHeight() * zoomLevel, null); g.setClip(clip); } g.drawImage(loupeImage, 0, 0, null); }
Example 12
Source File: GraphicsContext.java From Freerouting with GNU General Public License v3.0 | 4 votes |
/** * draws the interiour of an item of class geometry.planar.Area */ public void fill_area(Area p_area, Graphics p_g, Color p_color, double p_translucency_factor) { if (p_color == null || p_area.is_empty()) { return; } if (p_area instanceof Circle) { fill_circle((Circle) p_area, p_g, p_color, p_translucency_factor); } else { PolylineShape border = (PolylineShape) p_area.get_border(); if (!border.is_bounded()) { System.out.println("GraphicsContext.fill_area: shape not bounded"); return; } Rectangle clip_shape = (Rectangle)p_g.getClip() ; IntBox clip_box = coordinate_transform.screen_to_board(clip_shape); if (!border.bounding_box().intersects(clip_box)) { return; } Shape [] holes = p_area.get_holes(); FloatPoint[] [] draw_polygons = new FloatPoint [holes.length + 1][]; for (int j = 0; j < draw_polygons.length; ++j) { PolylineShape curr_draw_shape; if (j == 0) { curr_draw_shape = border; } else { curr_draw_shape = (PolylineShape) holes[j - 1]; } draw_polygons[j] = new FloatPoint [curr_draw_shape.border_line_count() + 1]; FloatPoint curr_draw_polygon[] = draw_polygons[j]; for (int i = 0; i < curr_draw_polygon.length - 1; ++i) { curr_draw_polygon[i] = curr_draw_shape.corner_approx(i); } // close the polygon curr_draw_polygon[curr_draw_polygon.length - 1] = curr_draw_polygon[0]; } fill_area(draw_polygons, p_g, p_color, p_translucency_factor) ; } if (show_area_division) { TileShape[] tiles = p_area.split_to_convex(); for (int i = 0; i < tiles.length; ++i) { FloatPoint[] corners = new FloatPoint [tiles[i].border_line_count() + 1]; TileShape curr_tile = tiles[i]; for (int j = 0; j < corners.length - 1; ++j) { corners[j]= curr_tile.corner_approx(j); } corners[corners.length - 1] = corners[0]; draw(corners, 1, java.awt.Color.white, p_g, 0.7); } } }
Example 13
Source File: GlyphVectorPainter.java From PolyGlot with MIT License | 4 votes |
/** * 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 14
Source File: GraphicsUtilities.java From pgptool with GNU General Public License v3.0 | 3 votes |
/** * Sets the clip on a graphics object by merging a supplied clip with the * existing one. The new clip will be an intersection of the old clip and the * supplied clip. The old clip shape will be returned. This is useful for * resetting the old clip after an operation is performed. * * @param g * the graphics object to update * @param clip * a new clipping region to add to the graphics clip. This may return * {@code null} if the current clip is {@code null}. * @return the current clipping region of the supplied graphics object * @throws NullPointerException * if any parameter is {@code null} */ public static Shape mergeClip(Graphics g, Shape clip) { Shape oldClip = g.getClip(); if (oldClip == null) { g.setClip(clip); return null; } Area area = new Area(oldClip); area.intersect(new Area(clip));// new Rectangle(0,0,width,height))); g.setClip(area); return oldClip; }