use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.
the class AbstractScriptButton method getThumbnailJPGImage.
static byte[] getThumbnailJPGImage(Component component, int width, int height, Icon icon) {
Image image = null;
if (icon instanceof MyImageIcon) {
ImageIcon myIcon = ((MyImageIcon) icon).getScaledIcon(width, height);
image = myIcon.getImage();
} else if (icon instanceof ImageIcon) {
image = ((ImageIcon) icon).getImage();
}
if (image != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JpegEncoder encoder = new JpegEncoder(component, image, 100, baos);
encoder.compress();
return baos.toByteArray();
}
return null;
}
use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.
the class AbstractScriptLabel method setIconDirect.
public void setIconDirect(byte[] data, int seq) {
if (imageSeq == seq) {
ComponentFactory.deregisterIcon(normalIcon);
if (data != null) {
disabledIcon = null;
// media option 1 == crop so no scaling
if (mediaOption != 1) {
normalIcon = new MyImageIcon(application, this, data, mediaOption);
} else {
normalIcon = ImageLoader.getIcon(data, -1, -1, true);
}
ComponentFactory.registerIcon(normalIcon);
} else {
normalIcon = null;
}
if (// $NON-NLS-1$
application.getI18NMessage("servoy.imageMedia.loadingImage").equals(getText())) {
setText(null);
}
try {
application.invokeAndWait(new Runnable() {
public void run() {
AbstractScriptLabel.super.setIcon(normalIcon);
}
});
} catch (Exception e) {
Debug.error(e);
}
}
}
use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.
the class ComponentFactory method registerIcon.
public static void registerIcon(Icon icon) {
if (icon == null)
return;
Object image;
if (icon instanceof ImageIcon) {
image = ((ImageIcon) icon).getImage();
} else if (icon instanceof MyImageIcon) {
ImageIcon myIcon = ((MyImageIcon) icon).getOriginal();
if (myIcon != null) {
image = myIcon.getImage();
} else {
image = icon;
}
} else
image = null;
IconHolder ih = lstIcons.get(image);
if (ih == null) {
lstIcons.put(image, new IconHolder(icon));
} else {
ih.counter++;
}
}
use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.
the class ComponentFactory method deregisterIcon.
public static void deregisterIcon(final Icon icon) {
if (icon == null)
return;
Object image;
if (icon instanceof ImageIcon) {
image = ((ImageIcon) icon).getImage();
} else if (icon instanceof MyImageIcon) {
ImageIcon myIcon = ((MyImageIcon) icon).getOriginal();
if (myIcon != null) {
image = myIcon.getImage();
} else {
image = icon;
}
} else
image = null;
if (image != null) {
IconHolder ih = lstIcons.get(image);
if (ih != null) {
ih.counter--;
if (ih.counter == 0) {
lstIcons.remove(image);
final Object img = image;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (icon instanceof ImageIcon) {
ImageIcon imageIcon = (ImageIcon) icon;
if (!lstIcons.containsKey(img)) {
imageIcon.setImageObserver(null);
}
} else if (icon instanceof MyImageIcon) {
if (img == null || !lstIcons.containsKey(img)) {
((MyImageIcon) icon).flush();
}
}
}
});
}
}
}
}
Aggregations