下面列出了java.awt.image.FilteredImageSource#javax.swing.GrayFilter 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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;
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
@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);
}
@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);
}
}
private Image getImage(boolean enabled) {
Image img = getImage();
if (! enabled) {
if (disabledImage == null) {
disabledImage = GrayFilter.createDisabledImage(img);
}
img = disabledImage;
}
return img;
}
@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);
}
}
@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);
}
}
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");
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
private Image getImage(boolean enabled) {
Image img = getImage();
if (! enabled) {
if (disabledImage == null) {
disabledImage = GrayFilter.createDisabledImage(img);
}
img = disabledImage;
}
return img;
}
@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);
}
}
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");
}
}
@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);
}
}
@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);
}
}
@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 );
}
private static Icon disabledIcon(Icon icon) {
return new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)icon).getImage()));
}
private static Icon disabledIcon(Icon icon) {
return new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)icon).getImage()));
}
private static Icon disabledIcon(Icon icon) {
return new ImageIcon(GrayFilter.createDisabledImage(((ImageIcon)icon).getImage()));
}
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);
}