use of java.awt.image.ImageObserver in project processing by processing.
the class Toolkit method getIconX.
/**
* Get an icon of the format base-NN.png where NN is the size, but if it's
* a hidpi display, get the NN*2 version automatically, sized at NN
*/
public static ImageIcon getIconX(File dir, String base, int size) {
final int scale = Toolkit.highResImages() ? 2 : 1;
String filename = (size == 0) ? (base + "-" + scale + "x.png") : (base + "-" + (size * scale) + ".png");
File file = new File(dir, filename);
if (!file.exists()) {
return null;
}
ImageIcon outgoing = new ImageIcon(file.getAbsolutePath()) {
@Override
public int getIconWidth() {
return Toolkit.zoom(super.getIconWidth()) / scale;
}
@Override
public int getIconHeight() {
return Toolkit.zoom(super.getIconHeight()) / scale;
}
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
ImageObserver imageObserver = getImageObserver();
if (imageObserver == null) {
imageObserver = c;
}
g.drawImage(getImage(), x, y, getIconWidth(), getIconHeight(), imageObserver);
}
};
return outgoing;
}
use of java.awt.image.ImageObserver in project jdk8u_jdk by JetBrains.
the class MultiResolutionToolkitImage method getResolutionVariantObserver.
public static ImageObserver getResolutionVariantObserver(final Image image, final ImageObserver observer, final int imgWidth, final int imgHeight, final int rvWidth, final int rvHeight, boolean concatenateInfo) {
if (observer == null) {
return null;
}
synchronized (ObserverCache.INSTANCE) {
ImageObserver o = (ImageObserver) ObserverCache.INSTANCE.get(observer);
if (o == null) {
o = (Image resolutionVariant, int flags, int x, int y, int width, int height) -> {
if ((flags & (ImageObserver.WIDTH | BITS_INFO)) != 0) {
width = (width + 1) / 2;
}
if ((flags & (ImageObserver.HEIGHT | BITS_INFO)) != 0) {
height = (height + 1) / 2;
}
if ((flags & BITS_INFO) != 0) {
x /= 2;
y /= 2;
}
if (concatenateInfo) {
flags &= ((ToolkitImage) image).getImageRep().check(null);
}
return observer.imageUpdate(image, flags, x, y, width, height);
};
ObserverCache.INSTANCE.put(observer, o);
}
return o;
}
}
use of java.awt.image.ImageObserver in project jdk8u_jdk by JetBrains.
the class MultiResolutionImageTest method testToolkitImageObserver.
static void testToolkitImageObserver(final Image image) {
ImageObserver observer = new ImageObserver() {
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if (img != image) {
throw new RuntimeException("Wrong image in observer");
}
if ((infoflags & (ImageObserver.ERROR | ImageObserver.ABORT)) != 0) {
throw new RuntimeException("Error during image loading");
}
return (infoflags & ImageObserver.ALLBITS) == 0;
}
};
final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics();
setImageScalingHint(g2x, true);
g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, observer);
}
use of java.awt.image.ImageObserver in project java-swing-tips by aterai.
the class MainPanel method makeImageIcon.
private static Icon makeImageIcon(URL url, final JComboBox combo, final int row) {
ImageIcon icon = new ImageIcon(url);
// Wastefulness: icon.setImageObserver(combo);
icon.setImageObserver(new ImageObserver() {
// @see http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
@Override
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
if (combo.isShowing() && (infoflags & (FRAMEBITS | ALLBITS)) != 0) {
if (combo.getSelectedIndex() == row) {
combo.repaint();
}
BasicComboPopup p = (BasicComboPopup) combo.getAccessibleContext().getAccessibleChild(0);
JList list = p.getList();
if (list.isShowing()) {
list.repaint(list.getCellBounds(row, row));
}
}
return (infoflags & (ALLBITS | ABORT)) == 0;
}
});
return icon;
}
Aggregations