Search in sources :

Example 11 with MyImageIcon

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) JpegEncoder(com.servoy.j2db.util.gui.JpegEncoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Image(java.awt.Image) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Example 12 with MyImageIcon

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);
        }
    }
}
Also used : MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Example 13 with MyImageIcon

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++;
    }
}
Also used : MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) ImageIcon(javax.swing.ImageIcon) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Example 14 with MyImageIcon

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();
                            }
                        }
                    }
                });
            }
        }
    }
}
Also used : MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) ImageIcon(javax.swing.ImageIcon) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Aggregations

MyImageIcon (com.servoy.j2db.util.gui.MyImageIcon)14 ImageIcon (javax.swing.ImageIcon)11 Icon (javax.swing.Icon)5 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)3 IconUIResource (javax.swing.plaf.IconUIResource)2 DataAdapterList (com.servoy.j2db.dataprocessing.DataAdapterList)1 Style (com.servoy.j2db.persistence.Style)1 IStyleSheet (com.servoy.j2db.util.IStyleSheet)1 JpegEncoder (com.servoy.j2db.util.gui.JpegEncoder)1 Image (java.awt.Image)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1