use of java.awt.image.RGBImageFilter 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;
}
use of java.awt.image.RGBImageFilter in project intellij-community by JetBrains.
the class ColorBlindnessTest method compareFilters.
private static void compareFilters(ImageFilter one, ImageFilter two) {
RGBImageFilter rgb1 = (RGBImageFilter) one;
RGBImageFilter rgb2 = (RGBImageFilter) two;
for (int i = 0; i < 0x01000000; i++) {
assertEquals(rgb1.filterRGB(0, 0, i), rgb2.filterRGB(0, 0, i));
}
}
Aggregations