Search in sources :

Example 1 with FilteredImageSource

use of java.awt.image.FilteredImageSource in project gephi by gephi.

the class WhiteFilter method createDisabledImage.

//~ Methods --------------------------------------------------------------------------------------------------------------
/**
     * Creates a disabled image
     */
public static Image createDisabledImage(final Image i) {
    final WhiteFilter filter = new WhiteFilter();
    final ImageProducer prod = new FilteredImageSource(i.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(prod);
}
Also used : ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource)

Example 2 with FilteredImageSource

use of java.awt.image.FilteredImageSource in project adempiere by adempiere.

the class PDFViewerBean method createActionButton.

protected JButton createActionButton(Action action, String text, String image, String tooltip) {
    final ImageIcon icon = new ImageIcon(getClass().getResource(image));
    final double colorFactor = 0.9;
    final RGBImageFilter filter = new RGBImageFilter() {

        public int filterRGB(int x, int y, int rgb) {
            final int alpha = (rgb >> 24) & 0xff;
            final int red = (rgb >> 16) & 0xff;
            final int green = (rgb >> 8) & 0xff;
            final int blue = (rgb) & 0xff;
            return ((int) (alpha * colorFactor) << 24) | ((int) (red * colorFactor) << 16) | ((int) (green * colorFactor) << 8) | ((int) (blue * colorFactor));
        }
    };
    final ImageIcon darkerIcon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(icon.getImage().getSource(), filter)));
    final JButton result = new JButton();
    result.setAction(action);
    result.setText(text);
    result.setIcon(darkerIcon);
    result.setBorderPainted(false);
    result.setHorizontalTextPosition(SwingConstants.CENTER);
    result.setVerticalTextPosition(SwingConstants.BOTTOM);
    result.setMnemonic(0);
    result.setToolTipText(tooltip);
    final Dimension dim = result.getPreferredSize();
    result.setMaximumSize(new Dimension(32, dim.height));
    result.addMouseListener(new MouseAdapter() {

        public void mouseEntered(MouseEvent me) {
            result.setBorderPainted(true);
            result.setIcon(icon);
        }

        public void mouseExited(MouseEvent me) {
            result.setBorderPainted(false);
            result.setIcon(darkerIcon);
        }
    });
    result.setBorderPainted(false);
    result.setFocusPainted(false);
    return result;
}
Also used : ImageIcon(javax.swing.ImageIcon) RGBImageFilter(java.awt.image.RGBImageFilter) MouseEvent(java.awt.event.MouseEvent) FilteredImageSource(java.awt.image.FilteredImageSource) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) Dimension(java.awt.Dimension)

Example 3 with FilteredImageSource

use of java.awt.image.FilteredImageSource in project jdk8u_jdk by JetBrains.

the class Image method getScaledInstance.

/**
     * Creates a scaled version of this image.
     * A new <code>Image</code> object is returned which will render
     * the image at the specified <code>width</code> and
     * <code>height</code> by default.  The new <code>Image</code> object
     * may be loaded asynchronously even if the original source image
     * has already been loaded completely.
     *
     * <p>
     *
     * If either <code>width</code>
     * or <code>height</code> is a negative number then a value is
     * substituted to maintain the aspect ratio of the original image
     * dimensions. If both <code>width</code> and <code>height</code>
     * are negative, then the original image dimensions are used.
     *
     * @param width the width to which to scale the image.
     * @param height the height to which to scale the image.
     * @param hints flags to indicate the type of algorithm to use
     * for image resampling.
     * @return     a scaled version of the image.
     * @exception IllegalArgumentException if <code>width</code>
     *             or <code>height</code> is zero.
     * @see        java.awt.Image#SCALE_DEFAULT
     * @see        java.awt.Image#SCALE_FAST
     * @see        java.awt.Image#SCALE_SMOOTH
     * @see        java.awt.Image#SCALE_REPLICATE
     * @see        java.awt.Image#SCALE_AREA_AVERAGING
     * @since      JDK1.1
     */
public Image getScaledInstance(int width, int height, int hints) {
    ImageFilter filter;
    if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) {
        filter = new AreaAveragingScaleFilter(width, height);
    } else {
        filter = new ReplicateScaleFilter(width, height);
    }
    ImageProducer prod;
    prod = new FilteredImageSource(getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(prod);
}
Also used : ImageFilter(java.awt.image.ImageFilter) ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource) AreaAveragingScaleFilter(java.awt.image.AreaAveragingScaleFilter) ReplicateScaleFilter(java.awt.image.ReplicateScaleFilter)

Example 4 with FilteredImageSource

use of java.awt.image.FilteredImageSource in project processdash by dtuma.

the class BufferedIcon method applyFilter.

public void applyFilter(RGBImageFilter filter) {
    ImageProducer prod = new FilteredImageSource(getImage().getSource(), filter);
    setImage(Toolkit.getDefaultToolkit().createImage(prod));
}
Also used : ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource)

Example 5 with FilteredImageSource

use of java.awt.image.FilteredImageSource in project jdk8u_jdk by JetBrains.

the class WindowsLookAndFeel method getDisabledIcon.

/**
     * {@inheritDoc}
     *
     * @since 1.6
     */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // in particular by the WindowsFileChooserUI class)
    if (icon != null && component != null && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY)) && icon.getIconWidth() > 0 && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
Also used : RGBImageFilter(java.awt.image.RGBImageFilter) ImageFilter(java.awt.image.ImageFilter) ImageIconUIResource(sun.swing.ImageIconUIResource) ImageProducer(java.awt.image.ImageProducer) FilteredImageSource(java.awt.image.FilteredImageSource) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Aggregations

FilteredImageSource (java.awt.image.FilteredImageSource)6 ImageProducer (java.awt.image.ImageProducer)5 BufferedImage (java.awt.image.BufferedImage)2 ImageFilter (java.awt.image.ImageFilter)2 RGBImageFilter (java.awt.image.RGBImageFilter)2 ImageIcon (javax.swing.ImageIcon)2 Dimension (java.awt.Dimension)1 Image (java.awt.Image)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 AreaAveragingScaleFilter (java.awt.image.AreaAveragingScaleFilter)1 ReplicateScaleFilter (java.awt.image.ReplicateScaleFilter)1 JButton (javax.swing.JButton)1 ImageIconUIResource (sun.swing.ImageIconUIResource)1