Java Code Examples for javax.swing.GrayFilter

The following examples show how to use javax.swing.GrayFilter. These examples are extracted from open source projects. 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 Project: netbeans   Source File: BiFeatureNode.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public java.awt.Image getIcon( int type ){        
    if( biFeature instanceof BiFeature.Descriptor  && biAnalyser.isNullDescriptor() ) {
        //setIconBase( biFeature.getIconBase(true));
        return GrayFilter.createDisabledImage(super.getIcon(type));
    }
    if( ( biFeature instanceof BiFeature.Property || biFeature instanceof BiFeature.IdxProperty ) && biAnalyser.isNullProperties() ) {
        //setIconBase( biFeature.getIconBase(true));
        return GrayFilter.createDisabledImage(super.getIcon(type));
    }
    if( biFeature instanceof BiFeature.EventSet && biAnalyser.isNullEventSets() ) {
        //setIconBase( biFeature.getIconBase(true));
        return GrayFilter.createDisabledImage(super.getIcon(type));
    }
    if( biFeature instanceof BiFeature.Method && biAnalyser.isNullMethods() ) {
        //setIconBase( biFeature.getIconBase(true));
        return GrayFilter.createDisabledImage(super.getIcon(type));
    }
    //setIconBase( biFeature.getIconBase(false));
    return super.getIcon(type);
}
 
Example 2
Source Project: scelight   Source File: LRIcon.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Image getGrayedImage( final boolean cache ) {
	Image grayedImage = this.grayedImage;
	if ( grayedImage == null ) {
		grayedImage = GrayFilter.createDisabledImage( get( cache ).getImage() );
		if ( cache )
			this.grayedImage = grayedImage;
		
		// The Java image API uses asynchronous image processing, wait for the grayed image to complete
		// in order to avoid empty images being displayed!
		final int id = ID_GENERATOR.getAndIncrement();
		MEDIA_TRACKER.addImage( grayedImage, id );
		try {
			MEDIA_TRACKER.waitForID( id );
		} catch ( final InterruptedException ie ) {
			LEnv.LOGGER.warning( "Image conversion (graying) interrupted!", ie );
		} finally {
			MEDIA_TRACKER.removeImage( grayedImage, id );
		}
	}
	
	return grayedImage;
}
 
Example 3
Source Project: jdk1.8-source-analysis   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 4
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 5
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 6
Source Project: jdk8u60   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 7
Source Project: JDKSourceCode1.8   Source File: NimbusLookAndFeel.java    License: MIT License 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 8
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 9
Source Project: netbeans   Source File: BiNode.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public java.awt.Image getIcon( int type ){
    if( key == BiFeature.Descriptor.class && biAnalyser.isNullDescriptor() )
        return GrayFilter.createDisabledImage(super.getIcon(type));
    if( key == BiFeature.Property.class && biAnalyser.isNullProperties() )
        return GrayFilter.createDisabledImage(super.getIcon(type));
    if( key == BiFeature.EventSet.class && biAnalyser.isNullEventSets() )
        return GrayFilter.createDisabledImage(super.getIcon(type));
    if( key == BiFeature.Method.class && biAnalyser.isNullMethods() )
        return GrayFilter.createDisabledImage(super.getIcon(type));

    return super.getIcon(type);
}
 
Example 10
Source Project: netbeans   Source File: BiNode.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public java.awt.Image getOpenedIcon( int type ){
    if( key == BiFeature.Descriptor.class && biAnalyser.isNullDescriptor() )
        return GrayFilter.createDisabledImage(super.getIcon(type));
    if( key == BiFeature.Property.class && biAnalyser.isNullProperties() )
        return GrayFilter.createDisabledImage(super.getIcon(type));
    if( key == BiFeature.EventSet.class && biAnalyser.isNullEventSets() )
        return GrayFilter.createDisabledImage(super.getIcon(type));
    if( key == BiFeature.Method.class && biAnalyser.isNullMethods() )
        return GrayFilter.createDisabledImage(super.getIcon(type));

    return super.getOpenedIcon(type);
}
 
Example 11
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 12
Source Project: Bytecoder   Source File: ImageView.java    License: Apache License 2.0 5 votes vote down vote up
private Image getImage(boolean enabled) {
    Image img = getImage();
    if (! enabled) {
        if (disabledImage == null) {
            disabledImage = GrayFilter.createDisabledImage(img);
        }
        img = disabledImage;
    }
    return img;
}
 
Example 13
Source Project: Bytecoder   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 14
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 15
private static void testMRDisabledImage(Image image) throws Exception {

        Image disabledImage = GrayFilter.createDisabledImage(image);
        MediaTracker mediaTracker = new MediaTracker(new JLabel());
        mediaTracker.addImage(disabledImage, 0);
        mediaTracker.waitForID(0);

        BufferedImage buffImage = new BufferedImage(IMAGE_SIZE,
                                                    IMAGE_SIZE,
                                                    BufferedImage.TYPE_INT_RGB);

        int x = IMAGE_SIZE / 2;
        int y = IMAGE_SIZE / 2;

        Graphics2D g = buffImage.createGraphics();

        g.scale(1, 1);
        g.drawImage(disabledImage, 0, 0, null);
        int rgb1x = buffImage.getRGB(x, y);

        g.scale(2, 2);
        g.drawImage(disabledImage, 0, 0, null);
        int rgb2x = buffImage.getRGB(x, y);

        g.dispose();

        if (rgb1x == rgb2x) {
            throw new RuntimeException("Disabled image is the same for the base"
                    + "image and the resolution variant");
        }

    }
 
Example 16
Source Project: jdk8u-jdk   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 17
Source Project: Java8CN   Source File: NimbusLookAndFeel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 18
Source Project: hottub   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 19
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 20
Source Project: openjdk-8   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 21
Source Project: jdk8u_jdk   Source File: ImageView.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Image getImage(boolean enabled) {
    Image img = getImage();
    if (! enabled) {
        if (disabledImage == null) {
            disabledImage = GrayFilter.createDisabledImage(img);
        }
        img = disabledImage;
    }
    return img;
}
 
Example 22
Source Project: jdk8u_jdk   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 23
private static void testMRDisabledImage(Image image) throws Exception {

        Image disabledImage = GrayFilter.createDisabledImage(image);
        MediaTracker mediaTracker = new MediaTracker(new JLabel());
        mediaTracker.addImage(disabledImage, 0);
        mediaTracker.waitForID(0);

        BufferedImage buffImage = new BufferedImage(IMAGE_SIZE,
                                                    IMAGE_SIZE,
                                                    BufferedImage.TYPE_INT_RGB);

        int x = IMAGE_SIZE / 2;
        int y = IMAGE_SIZE / 2;

        Graphics2D g = buffImage.createGraphics();

        g.scale(1, 1);
        g.drawImage(disabledImage, 0, 0, null);
        int rgb1x = buffImage.getRGB(x, y);

        g.scale(2, 2);
        g.drawImage(disabledImage, 0, 0, null);
        int rgb2x = buffImage.getRGB(x, y);

        g.dispose();

        if (rgb1x == rgb2x) {
            throw new RuntimeException("Disabled image is the same for the base"
                    + "image and the resolution variant");
        }

    }
 
Example 24
Source Project: jdk8u-jdk   Source File: NimbusLookAndFeel.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 25
@Override
public Icon getDisabledIcon(JComponent component, Icon icon) {
    if (icon instanceof SynthIcon) {
        SynthIcon si = (SynthIcon)icon;
        BufferedImage img = EffectUtils.createCompatibleTranslucentImage(
                si.getIconWidth(), si.getIconHeight());
        Graphics2D gfx = img.createGraphics();
        si.paintIcon(component, gfx, 0, 0);
        gfx.dispose();
        return new ImageIconUIResource(GrayFilter.createDisabledImage(img));
    } else {
        return super.getDisabledIcon(component, icon);
    }
}
 
Example 26
@Override
public ImageDifference compare( BufferedImage img1, BufferedImage img2 ) {
	if ( img1 == null ) {
		if ( img2 == null ) {
			return new ImageDifference( 1.0, null, FuzzyImageDifferenceCalculator.class );
		}
		return new ImageDifference( 0.0, img2, FuzzyImageDifferenceCalculator.class );
	}
	if ( img2 == null ) {
		return new ImageDifference( 0.0, img1, FuzzyImageDifferenceCalculator.class );
	}
	img1 = toBufferedImage( scaleProportionallyToMaxWidthHeight( img1, 800, 600 ) );
	img1 = toBufferedImage( scaleToSameSize( img1, img2 ) );
	img2 = toBufferedImage( scaleToSameSize( img2, img1 ) );
	final BufferedImage differenceImage = toBufferedImage( img2 );
	final Graphics2D gc = differenceImage.createGraphics();
	gc.setColor( Color.RED );
	// convert to gray images.
	img1 = toBufferedImage( GrayFilter.createDisabledImage( img1 ) );
	img2 = toBufferedImage( GrayFilter.createDisabledImage( img2 ) );
	// set to a match by default, if a change is found then flag non-match
	int numdiffs = 0;
	final int numRows = (int) Math.ceil( img1.getHeight() / (float) blockSize );
	final int numCols = (int) Math.ceil( img1.getWidth() / (float) blockSize );
	// loop through whole image and compare individual blocks of images
	StringBuilder textual = new StringBuilder();
	for ( int row = 0; row < numRows; row++ ) {
		textual.append( "|" );
		for ( int col = 0; col < numCols; col++ ) {
			final int b1 = getAverageBrightness( getSubImage( img1, col, row ) );
			final int b2 = getAverageBrightness( getSubImage( img2, col, row ) );
			final int diff = Math.abs( b1 - b2 );
			if ( diff > sensitivity ) {
				// the difference in a certain region has passed the threshold value
				// draw an indicator on the change image to show where change was detected.
				// TODO Merge borders of neighboring blocks
				gc.drawRect( col * blockSize, row * blockSize, blockSize - 1, blockSize - 1 );
				numdiffs++;
			}
			textual.append( diff > sensitivity ? "X" : " " );
		}
		textual.append( "|" );
		logger.warn( textual.toString() );
		textual = new StringBuilder();
	}
	if ( numdiffs == 0 ) {
		// ensure no rounding errors...
		return new ImageDifference( 1.0, differenceImage, FuzzyImageDifferenceCalculator.class );
	}
	final int total = numRows * numCols;
	final double match = (total - numdiffs) / (double) total;
	return new ImageDifference( match, differenceImage, FuzzyImageDifferenceCalculator.class );
}
 
Example 27
Source Project: netbeans   Source File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
private static Icon disabledIcon(Icon icon) {
    return new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)icon).getImage()));
}
 
Example 28
Source Project: netbeans   Source File: ProjectsSelector.java    License: Apache License 2.0 4 votes vote down vote up
private static Icon disabledIcon(Icon icon) {
    return new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)icon).getImage()));
}
 
Example 29
Source Project: visualvm   Source File: ProjectsSelector.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static Icon disabledIcon(Icon icon) {
    return new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)icon).getImage()));
}
 
Example 30
Source Project: WorldGrower   Source File: ImageInfoReader.java    License: GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage createGhostImage(Image image) {
	ImageFilter filter = new GrayFilter(true, 50);  
	ImageProducer producer = new FilteredImageSource(image.getSource(), filter);  
	Image toolkitImage = Toolkit.getDefaultToolkit().createImage(producer);  
	return ImageUtils.toBufferedImage(toolkitImage);
}