/** * Draw every char in separate terminal cell to guaranty equal width for different lines. * Nevertheless to improve kerning we draw word characters as one block for monospaced fonts. */ private void drawChars(int x, int y, CharBuffer buf, TextStyle style, Graphics2D gfx) { final int blockLen = 1; int offset = 0; int drawCharsOffset = 0; // workaround to fix Swing bad rendering of bold special chars on Linux // TODO required for italic? CharBuffer renderingBuffer; if (mySettingsProvider.DECCompatibilityMode() && style.hasOption(TextStyle.Option.BOLD)) { renderingBuffer = CharUtils.heavyDecCompatibleBuffer(buf); } else { renderingBuffer = buf; } while (offset + blockLen <= buf.length()) { if (renderingBuffer.getBuf()[buf.getStart() + offset] == CharUtils.DWC) { offset += blockLen; drawCharsOffset += blockLen; continue; // dont' draw second part(fake one) of double width character } Font font = getFontToDisplay(buf.charAt(offset + blockLen - 1), style); // while (myMonospaced && (offset + blockLen < buf.getLength()) && // isWordCharacter(buf.charAt(offset + blockLen - 1)) // && (font == getFontToDisplay(buf.charAt(offset + blockLen - 1), style))) { // blockLen++; // } gfx.setFont(font); int descent = gfx.getFontMetrics(font).getDescent(); int baseLine = (y + 1) * myCharSize.height - descent; int xCoord = (x + drawCharsOffset) * myCharSize.width; int textLength = CharUtils.getTextLengthDoubleWidthAware( buf.getBuf(), buf.getStart() + offset, blockLen, mySettingsProvider.ambiguousCharsAreDoubleWidth()); int yCoord = y * myCharSize.height; gfx.setClip( xCoord, yCoord, Math.min(textLength * myCharSize.width, getWidth() - xCoord), Math.min(myCharSize.height, getHeight() - yCoord)); gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun()))); gfx.drawChars(renderingBuffer.getBuf(), buf.getStart() + offset, blockLen, xCoord, baseLine); drawCharsOffset += blockLen; offset += blockLen; } gfx.setClip(null); }
private void paintString( Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2D = (Graphics2D) g; String progressString = progressBar.getString(); g2D.setFont(progressBar.getFont()); Point renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Rectangle savedClip = g2D.getClipBounds(); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { g2D.setColor(getSelectionBackground()); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(fillStart, y, amountFull, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } else { // VERTICAL g2D.setColor(getSelectionBackground()); AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2); g2D.setFont(progressBar.getFont().deriveFont(rotate)); renderLocation = getStringPlacement(g2D, progressString, x, y, width, height); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); g2D.setColor(getSelectionForeground()); g2D.clipRect(x, fillStart, width, amountFull); Utilities.drawString(progressBar, g2D, progressString, renderLocation.x, renderLocation.y); } g2D.setClip(savedClip); }
/** * Paints the icon. * * @param c the component on which it is painted * @param _g the graphics context * @param x the x coordinate of the icon * @param y the y coordinate of the icon */ public void paintIcon(Component c, Graphics _g, int x, int y) { Graphics2D g = (Graphics2D) _g; AffineTransform at = AffineTransform.getTranslateInstance(x + offsetX, y + offsetY); // save current graphics paint and clip Paint gPaint = g.getPaint(); Shape gClip = g.getClip(); // render shape(s) g.setPaint(color); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.clipRect(x, y, w, h); // paint shape, if any if (shape != null) { g.fill(at.createTransformedShape(shape)); } // paint decoration, if any if (decoration != null) { g.setPaint(decoColor); g.fill(at.createTransformedShape(decoration)); } // restore graphics paint and clip g.setPaint(gPaint); g.setClip(gClip); }
public void generarFondo(Component componente) { boolean dibujarFondo = false; Rectangle med = this.getBounds(); Rectangle areaDibujo = this.getBounds(); BufferedImage tmp; GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); if (Principal.fondoBlur) { dibujarFondo = true; } if (dibujarFondo) { JRootPane root = SwingUtilities.getRootPane(this); blurBuffer = GraphicsUtilities.createCompatibleImage(Principal.sysAncho, Principal.sysAlto); Graphics2D g2 = blurBuffer.createGraphics(); g2.setClip(med); blurBuffer = blurBuffer.getSubimage(med.x, med.y, med.width, med.height); ((Escritorio) Principal.getEscritorio()).getFrameEscritorio().paint(g2); g2.dispose(); backBuffer = blurBuffer; // blurBuffer = toGrayScale(blurBuffer); blurBuffer = GraphicsUtilities.createThumbnailFast(blurBuffer, getWidth() / 2); blurBuffer = new GaussianBlurFilter(4).filter(blurBuffer, null); g2 = (Graphics2D) blurBuffer.getGraphics(); g2.setColor(new Color(0, 0, 0, 195)); g2.fillRect(0, 0, Principal.sysAncho, Principal.sysAlto); listo = true; } }
protected void paintBackground(Graphics g, AbstractButton b) { if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) { return; } int width = b.getWidth(); int height = b.getHeight(); Graphics2D g2D = (Graphics2D) g; Shape savedClip = g.getClip(); if ((b.getBorder() != null) && b.isBorderPainted() && (b.getBorder() instanceof UIResource)) { Area clipArea = new Area(new Rectangle2D.Double(1, 1, width - 2, height - 2)); if (savedClip != null) { clipArea.intersect(new Area(savedClip)); } g2D.setClip(clipArea); } super.paintBackground(g, b); g2D.setClip(savedClip); }
/** Part of print code coped from Sun */ public void printTablePart(Graphics2D g2, PageFormat pageFormat, int rowIndex, int columnIndex) { String pageNumber = "Page: " + (rowIndex + 1); if (subTableSplitSize > 1) { pageNumber += "-" + (columnIndex + 1); } int pageLeft = subTableSplit[columnIndex]; int pageRight = subTableSplit[columnIndex + 1]; int pageWidth = pageRight - pageLeft; // page number message (in smaller type) g2.setFont(new Font(g2.getFont().getName(), g2.getFont().getStyle(), 8)); g2.drawString(pageNumber, pageWidth / 2 - 35, (int) (pageHeight - fontHeight)); double clipHeight = Math.min(tableHeightOnFullPage, tableHeight - rowIndex * tableHeightOnFullPage); g2.translate(-subTableSplit[columnIndex], 0); g2.setClip(pageLeft, 0, pageWidth, (int) headerHeight); g2.scale(scale, scale); tableHeader.paint(g2); // draw the header on every page g2.scale(1 / scale, 1 / scale); g2.translate(0, headerHeight); g2.translate(0, -tableHeightOnFullPage * rowIndex); // cut table image and draw on the page g2.setClip(pageLeft, (int) tableHeightOnFullPage * rowIndex, pageWidth, (int) clipHeight); g2.scale(scale, scale); _table.paint(g2); g2.scale(1 / scale, 1 / scale); double pageTop = tableHeightOnFullPage * rowIndex - headerHeight; // double pageBottom = pageTop + clipHeight + headerHeight; g2.drawRect(pageLeft, (int) pageTop, pageWidth, (int) (clipHeight + headerHeight)); }
/* * Create a BufferedImage for Swing components. * All or part of the component can be captured to an image. * * @param component Swing component to create image from * @param region The region of the component to be captured to an image * @param fileName name of file to be created or null * @return image the image for the given region * @exception IOException if an error occurs during writing */ public static BufferedImage createImage(JComponent component, Rectangle region, String fileName) throws IOException { boolean opaqueValue = component.isOpaque(); component.setOpaque(true); BufferedImage image = new BufferedImage(region.width, region.height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = image.createGraphics(); g2d.setClip(region); component.paint(g2d); g2d.dispose(); component.setOpaque(opaqueValue); ScreenCapture.writeImage(image, fileName); return image; }
public static BitmapFont createFromFont(Font font) { font = font.deriveFont(FONT_SIZE); int imageWidth = CHAR_WIDTH * NUM_CHARACTERS; //noinspection UndesirableClassUsage BufferedImage image = new BufferedImage(imageWidth, CHAR_HEIGHT, BufferedImage.TYPE_BYTE_BINARY); Graphics2D g = image.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, imageWidth, CHAR_HEIGHT); g.setColor(Color.black); g.setFont(font); char[] c = new char[1]; for (c[0] = 0; c[0] < NUM_CHARACTERS; c[0]++) { if (font.canDisplay(c[0])) { int x = c[0] * CHAR_WIDTH; g.setClip(x, 0, CHAR_WIDTH, CHAR_HEIGHT); g.drawChars(c, 0, 1, x, CHAR_HEIGHT - CHAR_DESCENT); } } g.dispose(); return new BitmapFont(image); }
public void paintComponent(Graphics g1) { animationCount = 1; if (!visible) return; Graphics2D g = (Graphics2D) g1; float width = getWidth(); float height = getHeight(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (45.0 <= rotate && rotate < 135.0) { g.translate(width, 0.0); g.rotate(Math.PI * rotate / 180, 0.0, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else if (135.0 <= rotate && rotate < 225.0) { g.rotate(Math.PI * rotate / 180, width / 2, height / 2); g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); } else if (225.0 <= rotate && rotate < 315.0) { g.translate(-height, 0.0); g.rotate(Math.PI * rotate / 180, height, 0.0); g.transform( AffineTransform.getScaleInstance(height / original_width, width / original_height)); } else g.transform( AffineTransform.getScaleInstance(width / original_width, height / original_height)); if ((dd.dynType & GeDyn.mDynType_Rotate) != 0 && dd.rotate != 0) { g.rotate( Math.PI * dd.rotate / 180, (dd.x0 - getX()) * original_width / width, (dd.y0 - getY()) * original_height / height); } AffineTransform save = g.getTransform(); AffineTransform save_tmp; int rounds = 1; if (fillLevel != 1F) rounds = 2; int oldColor = 0; for (int i = 0; i < rounds; i++) { if (rounds == 2) { switch (i) { case 0: if (levelColorTone != GeColor.COLOR_TONE_NO) { oldColor = colorTone; colorTone = levelColorTone; } else if (levelFillColor != GeColor.COLOR_NO) { oldColor = fillColor; fillColor = levelFillColor; } break; case 1: if (levelColorTone != GeColor.COLOR_TONE_NO) colorTone = oldColor; else if (levelFillColor != GeColor.COLOR_NO) fillColor = oldColor; break; } switch (levelDirection) { case Ge.DIRECTION_UP: if (i == 0) g.setClip( new Rectangle2D.Float( 0F, fillLevel * original_height + Ge.cJBean_Offset, original_width, original_height)); else g.setClip( new Rectangle2D.Float( 0F, 0F, original_width, fillLevel * original_height + Ge.cJBean_Offset)); break; case Ge.DIRECTION_DOWN: if (i == 0) g.setClip( new Rectangle2D.Float( 0F, 0F, original_width, (1 - fillLevel) * original_height + Ge.cJBean_Offset)); else g.setClip( new Rectangle2D.Float( 0F, (1 - fillLevel) * original_height + Ge.cJBean_Offset, original_width, original_height)); break; case Ge.DIRECTION_RIGHT: if (i == 0) g.setClip( new Rectangle2D.Float( fillLevel * original_width + Ge.cJBean_Offset, 0F, original_width, original_height)); else g.setClip( new Rectangle2D.Float(0F, 0F, fillLevel * width + Ge.cJBean_Offset, height)); break; case Ge.DIRECTION_LEFT: if (i == 0) g.setClip( new Rectangle2D.Float( 0F, 0F, (1 - fillLevel) * original_width + Ge.cJBean_Offset, original_height)); else g.setClip( new Rectangle2D.Float( (1 - fillLevel) * original_width + Ge.cJBean_Offset, 0F, original_width, original_height)); break; } } { int fcolor = GeColor.getDrawtype( 293, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, fillColor, dimmed); if (gradient == GeGradient.eGradient_No) { g.setColor(GeColor.getColor(fcolor)); g.fill(shapes[0]); } else { GeGradient.paint( g, gradient, 2, -2, 2F, 2F, 13.6808F, 14.8208F, false, 293, colorTone, colorShift, colorIntensity, colorInverse, fillColor, dimmed); g.fill(shapes[0]); } if (shadow != 0) { g.setColor(GeColor.shiftColor(fcolor, -2, colorInverse)); g.fill(shapes[1]); g.setColor(GeColor.shiftColor(fcolor, 2, colorInverse)); g.fill(shapes[2]); } g.setStroke(new BasicStroke(1F)); g.setColor( GeColor.getColor( 0, colorTone, colorShift, colorIntensity, colorBrightness, colorInverse, borderColor, dimmed)); g.draw(shapes[0]); } } if (rounds == 2) g.setClip(null); g.setTransform(save); }
@Nullable private Point createToolTipImage(@NotNull KeyType key) { UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, true); Pair<Component, Rectangle> rendererAndBounds = getCellRendererAndBounds(key); UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, null); if (rendererAndBounds == null) return null; JComponent renderer = ObjectUtils.tryCast(rendererAndBounds.first, JComponent.class); if (renderer == null) return null; if (renderer.getClientProperty(DISABLE_EXPANDABLE_HANDLER) != null) return null; if (UIUtil.getClientProperty((JComponent) rendererAndBounds.getFirst(), USE_RENDERER_BOUNDS) == Boolean.TRUE) { rendererAndBounds.getSecond().translate(renderer.getX(), renderer.getY()); rendererAndBounds.getSecond().setSize(renderer.getSize()); } myKeyItemBounds = rendererAndBounds.second; Rectangle cellBounds = myKeyItemBounds; Rectangle visibleRect = getVisibleRect(key); if (cellBounds.y < visibleRect.y) return null; int cellMaxY = cellBounds.y + cellBounds.height; int visMaxY = visibleRect.y + visibleRect.height; if (cellMaxY > visMaxY) return null; int cellMaxX = cellBounds.x + cellBounds.width; int visMaxX = visibleRect.x + visibleRect.width; Point location = new Point(visMaxX, cellBounds.y); SwingUtilities.convertPointToScreen(location, myComponent); Rectangle screen = !Registry.is("ide.expansion.hints.on.all.screens") ? ScreenUtil.getScreenRectangle(location) : ScreenUtil.getAllScreensRectangle(); int borderWidth = isPaintBorder() ? 1 : 0; int width = Math.min(screen.width + screen.x - location.x - borderWidth, cellMaxX - visMaxX); int height = cellBounds.height; if (width <= 0 || height <= 0) return null; Dimension size = getImageSize(width, height); myImage = UIUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = myImage.createGraphics(); g.setClip(null); doFillBackground(height, width, g); g.translate(cellBounds.x - visMaxX, 0); doPaintTooltipImage(renderer, cellBounds, g, key); CustomLineBorder border = null; if (borderWidth > 0) { border = new CustomLineBorder(getBorderColor(), borderWidth, 0, borderWidth, borderWidth); location.y -= borderWidth; size.width += borderWidth; size.height += borderWidth + borderWidth; } g.dispose(); myRendererPane.remove(renderer); myTipComponent.setBorder(border); myTipComponent.setPreferredSize(size); return location; }
public void paintIcon(Component c, Graphics g, int x, int y) { if (!JTattooUtilities.isLeftToRight(c)) { x += GAP; } int w = getIconWidth() - GAP; int h = getIconHeight(); Graphics2D g2D = (Graphics2D) g; AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); Color colors[]; if (button.isEnabled()) { if ((button.isRolloverEnabled() && model.isRollover()) || (model.isPressed() && model.isArmed())) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) { colors = AbstractLookAndFeel.getTheme().getFocusColors(); } else { colors = AbstractLookAndFeel.getTheme().getCheckBoxColors(); } } } else { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } Color frameColor = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6); Shape savedClip = g.getClip(); Area clipArea = new Area(new Ellipse2D.Double(x, y, w + 1, h + 1)); if (savedClip != null) { clipArea.intersect(new Area(savedClip)); } g2D.setClip(clipArea); JTattooUtilities.fillHorGradient(g, colors, x, y, w, h); g2D.setClip(savedClip); Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(frameColor); g.drawOval(x, y, w, h); if (model.isSelected()) { if (model.isEnabled()) { Color fc = AbstractLookAndFeel.getForegroundColor(); if (ColorHelper.getGrayValue(colors[0]) < 128) { if (ColorHelper.getGrayValue(fc) < 128) { g2D.setColor(Color.white); } else { g2D.setColor(fc); } } else { if (ColorHelper.getGrayValue(fc) > 128) { g2D.setColor(Color.black); } else { g2D.setColor(fc); } } } else { g.setColor(AbstractLookAndFeel.getDisabledForegroundColor()); } if (AbstractLookAndFeel.getTheme().isSmallFontSize()) { g2D.fillOval(x + 4, y + 4, w - 7, h - 7); } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) { g2D.fillOval(x + 4, y + 4, w - 7, h - 7); } else { g2D.fillOval(x + 5, y + 5, w - 9, h - 9); } } g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
// also clip, transform, composite, // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;} // --------------------------------------------------------- private void doPaint(Graphics2D g, int s, Object o) { // process an operation from the buffer // System.out.println(s); Object o1 = null, o2 = null, o3 = null, o4 = null, o5 = null, o6 = null, o7 = null, o8 = null, o9 = null, o10 = null, o11 = null; if (o instanceof Object[]) { Object[] a = (Object[]) o; if (a.length > 0) o1 = a[0]; if (a.length > 1) o2 = a[1]; if (a.length > 2) o3 = a[2]; if (a.length > 3) o4 = a[3]; if (a.length > 4) o5 = a[4]; if (a.length > 5) o6 = a[5]; if (a.length > 6) o7 = a[6]; if (a.length > 7) o8 = a[7]; if (a.length > 8) o9 = a[8]; if (a.length > 9) o10 = a[9]; if (a.length > 10) o11 = a[10]; } switch (s) { case clear: paintBackground(g, theBackground); break; // public void addRenderingHints(Map<?,?> hints) // {toBuffer("addRenderingHints",hints );} case addRenderingHints: g.addRenderingHints((Map<?, ?>) o); break; case clip1: g.clip((Shape) o); break; case draw1: g.draw((Shape) o); break; case draw3DRect: g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case drawGlyphVector: g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3); break; case drawImage1: g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4); break; case drawImage2: g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3); break; case drawRenderableImage: g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2); break; case drawRenderedImage: g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2); break; case drawString1: g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3); break; case drawString2: g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3); break; case drawString3: g.drawString((String) o1, (Float) o2, (Float) o3); break; case drawString4: g.drawString((String) o1, (Integer) o2, (Integer) o3); break; case fill: g.fill((Shape) o); break; case fill3DRect: g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case rotate1: g.rotate((Double) o); break; case rotate2: g.rotate((Double) o1, (Double) o2, (Double) o3); break; case scale1: g.scale((Double) o1, (Double) o2); break; case setBackground: g.setBackground( (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/ break; case setComposite: g.setComposite((Composite) o); break; case setPaint: g.setPaint((Paint) o); break; case setRenderingHint: g.setRenderingHint((RenderingHints.Key) o1, o2); break; case setRenderingHints: g.setRenderingHints((Map<?, ?>) o); break; case setStroke: g.setStroke((Stroke) o); break; case setTransform: g.setTransform(makeTransform(o)); break; case shear: g.shear((Double) o1, (Double) o2); break; case transform1: g.transform(makeTransform(o)); break; case translate1: g.translate((Double) o1, (Double) o2); break; case translate2: g.translate((Integer) o1, (Integer) o2); break; case clearRect: g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case copyArea: g.copyArea( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawArc: g.drawArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawBytes: g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawChars: g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawImage4: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5); break; case drawImage5: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4); break; case drawImage6: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Color) o6, (ImageObserver) o7); break; case drawImage7: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6); break; case drawImage8: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (Color) o10, (ImageObserver) o11); break; case drawImage9: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (ImageObserver) o10); break; case drawLine: g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawOval: g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawPolygon1: g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case drawPolygon2: g.drawPolygon((Polygon) o); break; case drawPolyline: g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3); break; case drawRect: g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawRoundRect: g.drawRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillArc: g.fillArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillOval: g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; // {toBuffer("fillPolygon",mkArg(xPoints, yPoints, nPoints) );} case fillPolygon1: g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case fillPolygon2: g.fillPolygon((Polygon) o); break; case fillRect: g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case fillRoundRect: g.fillRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case setClip1: g.setClip((Shape) o); break; case setColor: g.setColor((Color) o); break; case setFont: g.setFont((Font) o); break; case setPaintMode: g.setPaintMode(); break; case setXORMode: g.setXORMode((Color) o); break; case opaque: super.setOpaque((Boolean) o); break; case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break; { FontRenderContext frc = g.getFontRenderContext(); TextLayout tl = new TextLayout((String) o1, g.getFont(), frc); Shape s1 = tl.getOutline(null); AffineTransform af = g.getTransform(); g.translate((Integer) o2, (Integer) o3); g.draw(s1); g.setTransform(af); } ; break; default: System.out.println("Unknown image operation " + s); } }
protected void paintComponent(Graphics graphics) { if (justShown) { if (!paintTimer.isRunning()) paintTimer.start(); return; } if (!isWidthInitialized) { // Only paint if the component size has been initialized. Layout // jumps are typical the first time this component is displayed, // because the preferred height depends on the component width. return; } Graphics2D g = (Graphics2D) graphics; Rectangle clip = g.getClipBounds(); // Figure out which ImageDatums fall within the clip bounds. List<ImageDatum> datums = getAllImageData(); int[] indices = getIndices(datums.size(), clip); // Iterate backwards through indices, so repaints get enqueued // in a visually pleasing order. for (int i = indices.length - 1; i >= 0; i--) { int index = indices[i]; if (index < 0) { continue; } ImageDatum datum = datums.get(index); if (datum == null) { // A race; the image disappeared during painting. continue; } RenderedImage image = datum.getImage(this); // This queue prevents GC of recently painted images: recentImages.add(image); Rectangle rect = getBounds(index); g.setClip(clip.intersection(rect)); File file = datum.getFile(); String label = file.getName(); ImageDatumType type = datum.getType(); String tag = type.toString(); ImageMetadata meta = datum.getMetadata(true); int rating = meta.getRating(); boolean selected = selection.isSelected(datum); renderer.paint(g, image, label, tag, rating, rect, selected); ImageGroup group = datum.getGroup(); if (group.isNonTrivial()) { ImageGroupCountRenderer.paint(g, rect, datum); } } g.setClip(clip); // The control is drawn as an overlay. if (controller.isEnabled()) { Rectangle ctrlRect = controller.getRect(); if (ctrlRect != null) { if (ctrlRect.intersects(clip)) { controller.paint(g); } } } }
public void run() { Thread me = Thread.currentThread(); while (getSize().width <= 0) { try { anim.sleep(500); } catch (InterruptedException e) { return; } } Graphics2D g2d = null; Graphics2D BufferG2D = null; Graphics2D ScreenG2D = null; BasicStroke solid = new BasicStroke(9.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 9.0f); GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO); int rule = AlphaComposite.SRC_OVER; AlphaComposite opaque = AlphaComposite.SrcOver; AlphaComposite blend = AlphaComposite.getInstance(rule, 0.9f); AlphaComposite set = AlphaComposite.Src; int frame = 0; int frametmp = 0; Dimension oldSize = getSize(); Shape clippath = null; while (anim == me) { Dimension size = getSize(); if (size.width != oldSize.width || size.height != oldSize.height) { img = null; clippath = null; if (BufferG2D != null) { BufferG2D.dispose(); BufferG2D = null; } if (ScreenG2D != null) { ScreenG2D.dispose(); ScreenG2D = null; } } oldSize = size; if (img == null) { img = (BufferedImage) createImage(size.width, size.height); } if (BufferG2D == null) { BufferG2D = img.createGraphics(); BufferG2D.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); BufferG2D.setClip(clippath); } g2d = BufferG2D; float[] ctrlpts; for (int i = 0; i < animpts.length; i += 2) { animate(animpts, deltas, i + 0, size.width); animate(animpts, deltas, i + 1, size.height); } ctrlpts = animpts; int len = ctrlpts.length; gp.reset(); int dir = 0; float prevx = ctrlpts[len - 2]; float prevy = ctrlpts[len - 1]; float curx = ctrlpts[0]; float cury = ctrlpts[1]; float midx = (curx + prevx) / 2.0f; float midy = (cury + prevy) / 2.0f; gp.moveTo(midx, midy); for (int i = 2; i <= ctrlpts.length; i += 2) { float x1 = (midx + curx) / 2.0f; float y1 = (midy + cury) / 2.0f; prevx = curx; prevy = cury; if (i < ctrlpts.length) { curx = ctrlpts[i + 0]; cury = ctrlpts[i + 1]; } else { curx = ctrlpts[0]; cury = ctrlpts[1]; } midx = (curx + prevx) / 2.0f; midy = (cury + prevy) / 2.0f; float x2 = (prevx + midx) / 2.0f; float y2 = (prevy + midy) / 2.0f; gp.curveTo(x1, y1, x2, y2, midx, midy); } gp.closePath(); g2d.setComposite(set); g2d.setBackground(backgroundColor); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); if (bgChanged || bounds == null) { bounds = new Rectangle(0, 0, getWidth(), getHeight()); bgChanged = false; } // g2d.clearRect(bounds.x-5, bounds.y-5, bounds.x + bounds.width + 5, bounds.y + bounds.height // + 5); g2d.clearRect(0, 0, getWidth(), getHeight()); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(outerColor); g2d.setComposite(opaque); g2d.setStroke(solid); g2d.draw(gp); g2d.setPaint(gradient); if (!bgChanged) { bounds = gp.getBounds(); } else { bounds = new Rectangle(0, 0, getWidth(), getHeight()); bgChanged = false; } gradient = new GradientPaint( bounds.x, bounds.y, gradientColorA, bounds.x + bounds.width, bounds.y + bounds.height, gradientColorB, true); g2d.setComposite(blend); g2d.fill(gp); if (g2d == BufferG2D) { repaint(); } ++frame; Thread.yield(); } if (g2d != null) { g2d.dispose(); } }
protected void paintBackground(Graphics g, AbstractButton b) { if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) { return; } if (!(b.isBorderPainted() && (b.getBorder() instanceof UIResource))) { super.paintBackground(g, b); return; } int width = b.getWidth(); int height = b.getHeight(); ButtonModel model = b.getModel(); Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (((width < 64) || (height < 16)) && ((b.getText() == null) || b.getText().length() == 0)) { if (model.isSelected()) { Color color = ColorHelper.darker(b.getBackground(), 20); g2D.setColor(color); g2D.fillRect(0, 0, width - 1, height - 1); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRect(0, 0, width - 1, height - 1); } else { Color[] colors = null; if (b.getBackground() instanceof ColorUIResource) { if (!model.isEnabled()) { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } else if (b.isRolloverEnabled() && model.isRollover()) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { colors = AbstractLookAndFeel.getTheme().getButtonColors(); } } else { colors = ColorHelper.createColorArr( ColorHelper.brighter(b.getBackground(), 20), ColorHelper.darker(b.getBackground(), 20), 20); } JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRect(0, 0, width - 1, height - 1); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); g2D.setColor(Color.white); g2D.drawRect(1, 1, width - 3, height - 3); } } else if (model.isPressed() && model.isArmed()) { int d = height - 2; Color color = AbstractLookAndFeel.getTheme().getSelectionBackgroundColor(); g2D.setColor(color); g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d); g2D.setColor(ColorHelper.darker(color, 40)); g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); } else if (model.isSelected()) { int d = height - 2; Color color = ColorHelper.darker(b.getBackground(), 20); g2D.setColor(color); g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); } else { int d = height - 2; Color[] colors = null; if (b.getBackground() instanceof ColorUIResource) { if (!model.isEnabled()) { colors = AbstractLookAndFeel.getTheme().getDisabledColors(); } else if (b.isRolloverEnabled() && model.isRollover()) { colors = AbstractLookAndFeel.getTheme().getRolloverColors(); } else { colors = AbstractLookAndFeel.getTheme().getButtonColors(); } } else { colors = ColorHelper.createColorArr( ColorHelper.brighter(b.getBackground(), 20), ColorHelper.darker(b.getBackground(), 20), 20); } Shape savedClip = g.getClip(); Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, d, d)); clipArea.intersect(new Area(savedClip)); g2D.setClip(clipArea); JTattooUtilities.fillHorGradient(g, colors, 0, 0, width, height); g2D.setClip(savedClip); if (model.isEnabled()) { g2D.setColor(AbstractLookAndFeel.getFrameColor()); } else { g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20)); } g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); g2D.setColor(Color.white); g2D.drawRoundRect(1, 1, width - 3, height - 3, d - 2, d - 2); } g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); g2D.setComposite(composite); }