@Override public void setBounds(int x, int y, int width, int height) { super.setBounds(x, y, width, height); int w = getWidth() - (SHADOW_SIZE - 2) * 2; int h = getHeight() - (SHADOW_SIZE - 2) * 2; int arc = 15; int shadowSize = SHADOW_SIZE; shadow = GraphicsUtilities.createCompatibleTranslucentImage(w, h); Graphics2D g2 = shadow.createGraphics(); if (active) { g2.setColor(new Color(243, 238, 39, 150)); } else { g2.setColor(Color.WHITE); } g2.setColor(Color.WHITE); g2.fillOval(0, 0, w, h); g2.dispose(); ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f, Color.BLACK); shadow = renderer.createShadow(shadow); g2 = shadow.createGraphics(); g2.setColor(Color.GRAY); g2.setComposite(AlphaComposite.Clear); g2.fillOval(shadowSize, shadowSize, w, h); g2.dispose(); }
private void paintToImage( final BufferedImage img, final int x, final int y, final int width, final int height) { // clear the prior image Graphics2D imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.Clear); imgG.setColor(Color.black); imgG.fillRect(0, 0, width + blur * 2, height + blur * 2); final int adjX = (int) (x + blur + offsetX + (insets.left * distance)); final int adjY = (int) (y + blur + offsetY + (insets.top * distance)); final int adjW = (int) (width - (insets.left + insets.right) * distance); final int adjH = (int) (height - (insets.top + insets.bottom) * distance); // let the delegate paint whatever they want to be blurred imgG.setComposite(AlphaComposite.DstAtop); if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); // blur the prior image back into the same pixels imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.DstAtop); imgG.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); imgG.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); imgG.drawImage(img, blurOp, 0, 0); if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); }
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; } }
private static Icon getThemeIcon(ColorScheme colorScheme, boolean square) { int iSize = SubstanceSizeUtils.getTitlePaneIconSize(); BufferedImage result = SubstanceCoreUtilities.getBlankImage(iSize, iSize); Graphics2D graphics = (Graphics2D) result.getGraphics().create(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color color1 = (colorScheme == null) ? Color.red : colorScheme.getUltraDarkColor(); Color color2 = (colorScheme == null) ? Color.green : colorScheme.getMidColor(); Color color3 = (colorScheme == null) ? Color.blue : colorScheme.getExtraLightColor(); graphics.setColor(color1); if (square) graphics.fillRect(5, 2, 6, 6); else graphics.fillOval(5, 2, 6, 6); graphics.setColor(color1.darker()); if (square) graphics.drawRect(5, 2, 6, 6); else graphics.drawOval(5, 2, 6, 6); graphics.setColor(color2); if (square) graphics.fillRect(1, 9, 6, 6); else graphics.fillOval(1, 9, 6, 6); graphics.setColor(color2.darker()); if (square) graphics.drawRect(1, 9, 6, 6); else graphics.drawOval(1, 9, 6, 6); graphics.setColor(color3); if (square) graphics.fillRect(9, 9, 6, 6); else graphics.fillOval(9, 9, 6, 6); graphics.setColor(color3.darker()); if (square) graphics.drawRect(9, 9, 6, 6); else graphics.drawOval(9, 9, 6, 6); graphics.dispose(); return new ImageIcon(result); }
/** * Draws a double headed arrow with arrow heads of a given width and height. * * @param aG the canvas to draw on; * @param aX1 the starting X position of the arrow; * @param aY1 the starting Y position of the arrow; * @param aX2 the ending X position of the arrow; * @param aY2 the ending Y position of the arrow; * @param aArrowWidth the total width of the arrow head; * @param aArrowHeight the total height of the arrow head. */ public static final void drawDoubleHeadedArrow( final Graphics aG, final int aX1, final int aY1, final int aX2, final int aY2, final int aArrowWidth, final int aArrowHeight) { final Graphics2D g2d = (Graphics2D) aG.create(); final int lineWidth = Math.abs(aX2 - aX1); final int threshold = (2 * aArrowWidth) + 2; try { int x1 = aX1; int x2 = aX2; if (lineWidth > threshold) { drawArrowHead(g2d, aX1, aY1, LEFT_FACING, aArrowWidth, aArrowHeight); // why x2 needs to be shifted by one pixel is beyond me... drawArrowHead(g2d, aX2 + 1, aY2, RIGHT_FACING, aArrowWidth, aArrowHeight); x1 += aArrowWidth - 1; x2 -= aArrowWidth + 1; } g2d.drawLine(x1, aY1, x2, aY2); } finally { g2d.dispose(); } }
/** * Gets (creates if necessary) disabled icon based on the passed one. * * @return <code>ImageIcon</code> constructed from disabled image of passed icon. */ @Nullable public static Icon getDisabledIcon(Icon icon) { if (icon instanceof LazyIcon) icon = ((LazyIcon) icon).getOrComputeIcon(); if (icon == null) return null; Icon disabledIcon = ourIcon2DisabledIcon.get(icon); if (disabledIcon == null) { if (!isGoodSize(icon)) { LOG.error(icon); // # 22481 return EMPTY_ICON; } final int scale = UIUtil.isRetina() ? 2 : 1; @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage( scale * icon.getIconWidth(), scale * icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics = image.createGraphics(); graphics.setColor(UIUtil.TRANSPARENT_COLOR); graphics.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight()); graphics.scale(scale, scale); icon.paintIcon(LabelHolder.ourFakeComponent, graphics, 0, 0); graphics.dispose(); Image img = ImageUtil.filter(image, UIUtil.getGrayFilter()); if (UIUtil.isRetina()) img = RetinaImage.createFrom(img, 2, ImageLoader.ourComponent); disabledIcon = new JBImageIcon(img); ourIcon2DisabledIcon.put(icon, disabledIcon); } return disabledIcon; }
@Override protected void paintBackground(Graphics g, JComponent component) { getGlassParameters(); Graphics2D g2d = (Graphics2D) g.create(); if (getOrientation().isHorizontal()) { paintBackground( g2d, 0, 0, component.getWidth(), component.getHeight(), getOrientation().isHorizontal(), component); } else { paintBackground( g2d, 0, 0, component.getHeight(), component.getWidth(), getOrientation().isHorizontal(), component); } g2d.dispose(); }
private static BufferedImage makeBufferedImage(Icon icon, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconWidth()) / 2); g.dispose(); return image; }
@NotNull public static Icon cropIcon(@NotNull Icon icon, int maxWidth, int maxHeight) { if (icon.getIconHeight() <= maxHeight && icon.getIconWidth() <= maxWidth) { return icon; } final int w = Math.min(icon.getIconWidth(), maxWidth); final int h = Math.min(icon.getIconHeight(), maxHeight); final BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration() .createCompatibleImage( icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT); final Graphics2D g = image.createGraphics(); icon.paintIcon(new JPanel(), g, 0, 0); g.dispose(); final BufferedImage img = UIUtil.createImage(w, h, Transparency.TRANSLUCENT); final int offX = icon.getIconWidth() > maxWidth ? (icon.getIconWidth() - maxWidth) / 2 : 0; final int offY = icon.getIconHeight() > maxHeight ? (icon.getIconHeight() - maxHeight) / 2 : 0; for (int col = 0; col < w; col++) { for (int row = 0; row < h; row++) { img.setRGB(col, row, image.getRGB(col + offX, row + offY)); } } return new ImageIcon(img); }
@NotNull public static Icon colorize(@NotNull final Icon source, @NotNull Color color, boolean keepGray) { float[] base = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); final BufferedImage image = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT); final Graphics2D g = image.createGraphics(); source.paintIcon(null, g, 0, 0); g.dispose(); final BufferedImage img = UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT); int[] rgba = new int[4]; float[] hsb = new float[3]; for (int y = 0; y < image.getRaster().getHeight(); y++) { for (int x = 0; x < image.getRaster().getWidth(); x++) { image.getRaster().getPixel(x, y, rgba); if (rgba[3] != 0) { Color.RGBtoHSB(rgba[0], rgba[1], rgba[2], hsb); int rgb = Color.HSBtoRGB(base[0], base[1] * (keepGray ? hsb[1] : 1f), base[2] * hsb[2]); img.getRaster() .setPixel(x, y, new int[] {rgb >> 16 & 0xff, rgb >> 8 & 0xff, rgb & 0xff, rgba[3]}); } } } return createImageIcon(img); }
/** * Adds the componentType buttons to the Panel of Main Window. * * @param pkg_name whose componentType buttons will be added * @param a needed for the addition of the ActionListener of respective buttons and calling method * of Pad_Draw */ public void add_componentType_buttons(package_cls pkg_name, final counts a) { int i; JLabel pkg_hdng = new JLabel(pkg_name.getName()); panel.add(pkg_hdng); for (i = 0; i < pkg_name.getComponentType_list().size(); i++) { final componentType cmp_Types = pkg_name.getComponentType_list().get(i); int btnHeight, btnWidth; double scale = 0.5; btnWidth = (int) (scale * (double) cmp_Types.getWidth()); btnHeight = (int) (scale * (double) cmp_Types.getHeight()); ImageIcon myIcon = new ImageIcon(cmp_Types.getType_Img()); BufferedImage bi = new BufferedImage(btnWidth, btnHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.scale(scale, scale); myIcon.paintIcon(null, g, 0, 0); g.dispose(); JButton strctButton = new JButton(new ImageIcon(bi)); strctButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { drawPad.add_componentType(cmp_Types, a); taskbar.setText("Click to add a component"); } }); panel.add(strctButton); } panel.validate(); // Updates the Panel }
public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setStroke(new BasicStroke(1.0f)); if (isOpaque()) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); } g2d.setColor(Color.black); g2d.drawLine(0, frameHeight / 2, frameWidth, frameHeight / 2); g2d.drawLine(frameWidth / 2, 0, frameWidth / 2, frameHeight); for (int i = unityX; i < frameWidth / 2; i += unityX) { g2d.drawLine( frameWidth / 2 + i, frameHeight / 2 - 3, frameWidth / 2 + i, frameHeight / 2 + 3); g2d.drawLine( frameWidth / 2 - i, frameHeight / 2 - 3, frameWidth / 2 - i, frameHeight / 2 + 3); } for (int i = unityY; i < frameHeight / 2; i += unityY) { g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 + i, frameWidth / 2 + 3, frameHeight / 2 + i); g2d.drawLine( frameWidth / 2 - 3, frameHeight / 2 - i, frameWidth / 2 + 3, frameHeight / 2 - i); } g2d.setColor(Color.blue); function.drawFunctionToGraphic(g2d, frameWidth, frameHeight, unityX, unityY); paintCurrentMethodState(g2d); g2d.dispose(); }
private static Image getImage(ResizableIcon icon, int size) { icon.setDimension(new Dimension(size, size)); if (icon instanceof AsynchronousLoading) { AsynchronousLoading async = (AsynchronousLoading) icon; if (async.isLoading()) { final CountDownLatch latch = new CountDownLatch(1); final boolean[] status = new boolean[1]; AsynchronousLoadListener all = new AsynchronousLoadListener() { @Override public void completed(boolean success) { status[0] = success; latch.countDown(); } }; async.addAsynchronousLoadListener(all); try { latch.await(); } catch (InterruptedException ignored) { } async.removeAsynchronousLoadListener(all); if (!status[0]) { return null; } if (async.isLoading()) { return null; } } } Image result = FlamingoUtilities.getBlankImage(size, size); Graphics2D g2d = (Graphics2D) result.getGraphics().create(); icon.paintIcon(null, g2d, 0, 0); g2d.dispose(); return result; }
@Override public void paintComponent(final Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); Dimension srcSize = image.getSizeForPaint(g2d); int wSrc = srcSize.width; int hSrc = srcSize.height; int wImg = getPreferredSize().width; int hImg = getPreferredSize().height; int xOffset = (getSize().width - wImg) / 2; RenderingHints hints = new RenderingHints( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setRenderingHints(hints); FSkin.drawImage( g2d, image, xOffset, 0, wImg + xOffset, hImg, // Destination 0, 0, wSrc, hSrc); // Source g2d.dispose(); }
public void drawScreen() { Graphics2D g = (Graphics2D) this.getGraphics(); g.drawImage(buffer, 0, 0, this); Toolkit.getDefaultToolkit().sync(); g.dispose(); }
/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
public void paintComponent(Graphics g) { super.paintComponent(g); int centerX = getWidth() / 2; int centerY = getHeight() / 2; Graphics2D g2d = (Graphics2D) g.create(); g2d.translate(centerX, centerY); // Set Graphics2D transform origin to center of panel g2d.setColor(fgColor); bar.setFrame(-barWidth / 2, -barHeight / 2 + barHeight * barPosition, barWidth, barHeight); g2d.fill(bar); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (Spike spike : spikes) { if (spike != null) { double opacity = 255; if (spike.getDirection() == 0) { opacity = getWidth() * 0.5 - 70 - spike.getPosition().getX(); } else { opacity = spike.getPosition().getX() + getWidth() * 0.5 - 70; } g2d.setColor(new Color(0, 0, 0, (int) clamp(opacity * 10, 0, 255))); g2d.fill(spike); } } g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setColor(Color.BLACK); g2d.draw(barCross); g2d.setStroke(new BasicStroke(2)); g2d.draw(barFrame); g2d.dispose(); }
private static Pair<Image, Point> createDragImage( final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) { if (c instanceof JComponent) { ((JComponent) c).setOpaque(true); } c.setForeground(tree.getForeground()); c.setBackground(tree.getBackground()); c.setFont(tree.getFont()); c.setSize(c.getPreferredSize()); final BufferedImage image = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) image.getGraphics(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); c.paint(g2); g2.dispose(); Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2); if (adjustToPathUnderDragOrigin) { TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y); if (path != null) { Rectangle bounds = tree.getPathBounds(path); point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y); } } return new Pair<Image, Point>(image, point); }
public BufferedImage makeTranslucent(BufferedImage source, float alpha) { Graphics2D g2d = source.createGraphics(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.drawImage(source, 0, 0, null); g2d.dispose(); return source; }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); int width = getWidth(); int height = getHeight(); // rendering hints g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // formatter DecimalFormat format = new DecimalFormat("##.#%"); // text to display String percentage = (value == null || Double.parseDouble(value.toString()) == -1) ? "" : format.format(Double.parseDouble(value.toString())); // paint text g2.setColor(Color.black); g2.setFont(g2.getFont().deriveFont(Font.BOLD)); FontMetrics fontMetrics = g2.getFontMetrics(); int textWidth = fontMetrics.stringWidth(percentage); int xPos = (width - textWidth) / 2; int yPos = height / 2 + fontMetrics.getDescent() + 2; g2.drawString(percentage, xPos, yPos); g2.dispose(); }
/* * (non-Javadoc) * * @seeorg.jvnet.flamingo.common.ui.BasicCommandButtonUI# * paintButtonVerticalSeparator(java.awt.Graphics, int) */ @Override protected void paintButtonVerticalSeparator(Graphics graphics, Rectangle separatorArea) { Graphics2D g2d = (Graphics2D) graphics.create(); g2d.translate(separatorArea.x, 0); SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities.getColorScheme( this.commandButton, ColorSchemeAssociationKind.SEPARATOR, ComponentState.getState(this.commandButton.getActionModel(), this.commandButton)); float fadeAlpha = this.getSeparatorAlpha(); g2d.setComposite(AlphaComposite.SrcOver.derive(fadeAlpha)); SeparatorPainterUtils.paintSeparator( this.commandButton, g2d, colorScheme, 1, this.commandButton.getHeight(), JSlider.VERTICAL, true, 4, 4, true); g2d.dispose(); }
private BufferedImage createGrid() { if (transformCells.getScaleY() < SHOW_GRID_MIN_SCALE) { return null; } Point2D cellSize = getCellSizeAfterScale(); cellWidth = round(cellSize.getX()); cellHeight = round(cellSize.getY()); BufferedImage image = new BufferedImage( getWidth() + 2 * (cellWidth), getHeight() + 2 * (cellHeight), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = image.createGraphics(); graphics2D.setColor(new Color(0, true)); graphics2D.fillRect(0, 0, image.getWidth(), image.getHeight()); graphics2D.setPaint(Color.YELLOW); graphics2D.setStroke(new BasicStroke(1)); for (int x = 0; x < image.getWidth(); x += cellWidth) { graphics2D.drawLine(x, 0, x, image.getHeight()); } for (int y = 0; y < image.getHeight(); y += cellHeight) { graphics2D.drawLine(0, y, image.getWidth(), y); } transformGrid.setToIdentity(); calculateGridTranslation(); graphics2D.dispose(); return image; }
public static BufferedImage convertToARGB(BufferedImage image) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = newImage.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return newImage; }
/* * (non-Javadoc) * * @see * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paintButtonBackground * (java.awt.Graphics, java.awt.Rectangle) */ @Override protected void paintButtonBackground(Graphics graphics, Rectangle toFill) { if (SubstanceCoreUtilities.isButtonNeverPainted(this.commandButton)) return; ButtonModel actionModel = this.commandButton.getActionModel(); PopupButtonModel popupModel = ((JCommandButton) this.commandButton).getPopupModel(); Rectangle actionArea = this.getLayoutInfo().actionClickArea; Rectangle popupArea = this.getLayoutInfo().popupClickArea; BufferedImage fullAlphaBackground = CommandButtonBackgroundDelegate.getCombinedCommandButtonBackground( this.commandButton, actionModel, actionArea, popupModel, popupArea); // Two special cases here: // 1. Button has flat appearance and doesn't show the popup // 2. Button is disabled. // For both cases, we need to set custom translucency. boolean isFlat = this.commandButton.isFlat() && !((JCommandButton) this.commandButton).getPopupModel().isPopupShowing(); boolean isSpecial = isFlat || !this.commandButton.isEnabled(); float extraAlpha = 1.0f; if (isSpecial) { if (isFlat) { float extraActionAlpha = 0.0f; for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : getActionTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) { ComponentState activeState = activeEntry.getKey(); if (activeState.isDisabled()) continue; if (activeState == ComponentState.ENABLED) continue; extraActionAlpha += activeEntry.getValue().getContribution(); } float extraPopupAlpha = 0.0f; for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : getPopupTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) { ComponentState activeState = activeEntry.getKey(); if (activeState.isDisabled()) continue; if (activeState == ComponentState.ENABLED) continue; extraPopupAlpha += activeEntry.getValue().getContribution(); } extraAlpha = Math.max(extraActionAlpha, extraPopupAlpha); } else { ComponentState actionAreaState = ComponentState.getState(actionModel, this.commandButton); if (actionAreaState.isDisabled()) { extraAlpha = SubstanceColorSchemeUtilities.getAlpha(this.commandButton, actionAreaState); } } } // System.out.println(extraAlpha); extraAlpha = Math.min(1.0f, extraAlpha); if (extraAlpha > 0.0f) { Graphics2D g2d = (Graphics2D) graphics.create(); g2d.setComposite( LafWidgetUtilities.getAlphaComposite(this.commandButton, extraAlpha, graphics)); g2d.drawImage(fullAlphaBackground, 0, 0, null); g2d.dispose(); } }
public static BufferedImage resize(BufferedImage image, int width, int height) { BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); Graphics2D g2d = (Graphics2D) bi.createGraphics(); g2d.addRenderingHints( new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)); g2d.drawImage(image, 0, 0, width, height, null); g2d.dispose(); return bi; }
@Override protected void paintComponent(Graphics g) { BufferedImage image = theImage.getImage(); if (image != null) { Graphics2D gg = (Graphics2D) g.create(); overlay.paint(gg, image, theImage.getImageTransform()); gg.dispose(); } }
/** * Resizes an image using a Graphics2D object backed by a BufferedImage. * * @param srcImg - source image to scale * @param w - desired width * @param h - desired height * @return - the new resized image */ private Image getScaledImage(Image srcImg, int w, int h) { BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = resizedImg.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(srcImg, 0, 0, w, h, null); g2.dispose(); return resizedImg; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.translate(x, y); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.ORANGE); g2.fill(star); g2.dispose(); }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Graphics2D g2 = (Graphics2D) g.create(); g2.translate(x, y); g2.setPaint(borderSelectionColor); g2.drawRect(0, 0, w - 1, h - 1); g2.setPaint(getLineColor()); BasicGraphicsUtils.drawDashedRect(g2, 0, 0, w, h); g2.dispose(); }
// Takes resource name and returns button public JButton createButton(String name, String toolTip) { // load the image String imagePath = "./resources/" + name + ".png"; ImageIcon iconRollover = new ImageIcon(imagePath); int w = iconRollover.getIconWidth(); int h = iconRollover.getIconHeight(); // get the cursor for this button Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); // make translucent default image Image image = createCompatibleImage(w, h, Transparency.TRANSLUCENT); Graphics2D g = (Graphics2D) image.getGraphics(); Composite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f); g.setComposite(alpha); g.drawImage(iconRollover.getImage(), 0, 0, null); g.dispose(); ImageIcon iconDefault = new ImageIcon(image); // make a pressed image image = createCompatibleImage(w, h, Transparency.TRANSLUCENT); g = (Graphics2D) image.getGraphics(); g.drawImage(iconRollover.getImage(), 2, 2, null); g.dispose(); ImageIcon iconPressed = new ImageIcon(image); // create the button JButton button = new JButton(); button.addActionListener(this); button.setIgnoreRepaint(true); button.setFocusable(false); button.setToolTipText(toolTip); button.setBorder(null); button.setContentAreaFilled(false); button.setCursor(cursor); button.setIcon(iconDefault); button.setRolloverIcon(iconRollover); button.setPressedIcon(iconPressed); return button; }