Search in sources :

Example 6 with MyImageIcon

use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.

the class AbstractScriptLabel method setRolloverIcon.

public void setRolloverIcon(byte[] data) {
    ComponentFactory.deregisterIcon(rolloverIcon);
    if (mediaOption != 1 && data != null) {
        rolloverIcon = new MyImageIcon(application, this, data, mediaOption);
    } else {
        rolloverIcon = ImageLoader.getIcon(data, -1, -1, true);
    }
    if (rolloverIcon != null) {
        ComponentFactory.registerIcon(rolloverIcon);
        addRolloverListener();
    }
}
Also used : MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Example 7 with MyImageIcon

use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.

the class AbstractScriptLabel method getDisabledIcon.

@Override
public Icon getDisabledIcon() {
    if (disabledIcon != null)
        return disabledIcon;
    if (getIcon() instanceof MyImageIcon) {
        MyImageIcon icon = (MyImageIcon) getIcon();
        icon.getIconWidth();
        ImageIcon scaledIcon = icon.getScaledIcon(0, 0);
        if (scaledIcon != null) {
            disabledIcon = new IconUIResource(new ImageIcon(GrayFilter.createDisabledImage(scaledIcon.getImage())));
            return disabledIcon;
        }
    }
    return super.getDisabledIcon();
}
Also used : MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) ImageIcon(javax.swing.ImageIcon) IconUIResource(javax.swing.plaf.IconUIResource) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Example 8 with MyImageIcon

use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.

the class DataImgMediaField method copyToClipboard.

protected void copyToClipboard() {
    try {
        // we copy to clipboard as byte array and filename/mimetype array used when pasting into another media field and as image icon for external pastes or if byte array is not available (and for external types)
        final Icon icon = enclosedComponent.getIcon();
        final byte[] bytes = getByteArrayContents(value);
        final String[] fileNameAndMime = new String[2];
        if (resolver instanceof DataAdapterList) {
            DataAdapterList dal = ((DataAdapterList) resolver);
            Object tmp = dal.getValueObject(dal.getState(), dataProviderID + IMediaFieldConstants.FILENAME);
            fileNameAndMime[0] = (tmp instanceof String) ? (String) tmp : null;
            tmp = dal.getValueObject(dal.getState(), dataProviderID + IMediaFieldConstants.MIMETYPE);
            fileNameAndMime[1] = (tmp instanceof String) ? (String) tmp : null;
        }
        if (icon instanceof ImageIcon || icon instanceof MyImageIcon) {
            Transferable tr = new Transferable() {

                public DataFlavor[] getTransferDataFlavors() {
                    List<DataFlavor> list = new ArrayList<DataFlavor>(3);
                    if (bytes != null)
                        list.add(getByteArrayDataFlavor());
                    list.add(DataFlavor.imageFlavor);
                    if (fileNameAndMime[0] != null || fileNameAndMime[1] != null) {
                        list.add(getStringArrayDataFlavor());
                        list.add(DataFlavor.stringFlavor);
                    }
                    return list.toArray(new DataFlavor[list.size()]);
                }

                public boolean isDataFlavorSupported(DataFlavor flavor) {
                    return DataFlavor.imageFlavor.equals(flavor) || (bytes != null && getByteArrayDataFlavor().equals(flavor)) || ((fileNameAndMime[0] != null || fileNameAndMime[1] != null) && (getStringArrayDataFlavor().equals(flavor) || DataFlavor.stringFlavor.equals(flavor)));
                }

                public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
                    if (!isDataFlavorSupported(flavor)) {
                        throw new UnsupportedFlavorException(flavor);
                    }
                    if (DataFlavor.imageFlavor.equals(flavor)) {
                        if (icon instanceof ImageIcon) {
                            return ((ImageIcon) icon).getImage();
                        } else if (icon instanceof MyImageIcon) {
                            return ((MyImageIcon) icon).getOriginal().getImage();
                        }
                    } else if (getByteArrayDataFlavor().equals(flavor)) {
                        return bytes;
                    } else if (getStringArrayDataFlavor().equals(flavor)) {
                        return fileNameAndMime;
                    } else if (DataFlavor.stringFlavor.equals(flavor)) {
                        return (fileNameAndMime[0] != null ? "Filename: '" + fileNameAndMime[0] + "' " : "") + (fileNameAndMime[1] != null ? "Type: '" + fileNameAndMime[1] + "'" : "");
                    }
                    return null;
                }
            };
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(tr, null);
        }
    } catch (Exception e) {
        Debug.error(e);
    }
}
Also used : MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) ImageIcon(javax.swing.ImageIcon) Transferable(java.awt.datatransfer.Transferable) ArrayList(java.util.ArrayList) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) DataFlavor(java.awt.datatransfer.DataFlavor) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Example 9 with MyImageIcon

use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.

the class AbstractScriptButton method setIcon.

public void setIcon(byte[] data) {
    Icon prevIcon = getIcon();
    if (prevIcon instanceof MyImageIcon) {
        Icon rollOver = getRolloverIcon();
        if (rollOver instanceof MyImageIcon) {
            ((MyImageIcon) prevIcon).removeImageIcon((MyImageIcon) rollOver);
        }
    }
    ComponentFactory.deregisterIcon(prevIcon);
    Icon icon = null;
    // media option 1 == crop so no scaling
    if (mediaOption != 1 && data != null) {
        // do scaling cropping if needed
        icon = new MyImageIcon(application, this, data, mediaOption);
        Icon rollOver = getRolloverIcon();
        if (rollOver instanceof MyImageIcon) {
            ((MyImageIcon) icon).addImageIcon((MyImageIcon) rollOver);
        }
    } else {
        icon = ImageLoader.getIcon(data, -1, -1, true);
    }
    ComponentFactory.registerIcon(icon);
    super.setIcon(icon);
}
Also used : ImageIcon(javax.swing.ImageIcon) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) Icon(javax.swing.Icon) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon)

Example 10 with MyImageIcon

use of com.servoy.j2db.util.gui.MyImageIcon in project servoy-client by Servoy.

the class AbstractScriptButton method setRolloverIcon.

public void setRolloverIcon(byte[] data) {
    ComponentFactory.deregisterIcon(getRolloverIcon());
    Icon rolloverIcon = null;
    // media option 1 == crop so no scaling
    if (mediaOption != 1 && data != null) {
        // do scaling cropping if needed
        rolloverIcon = new MyImageIcon(application, this, data, mediaOption);
        Icon icon = getIcon();
        if (icon instanceof MyImageIcon) {
            ((MyImageIcon) icon).addImageIcon((MyImageIcon) rolloverIcon);
        }
    } else {
        rolloverIcon = ImageLoader.getIcon(data, -1, -1, true);
    }
    super.setRolloverIcon(rolloverIcon);
}
Also used : ImageIcon(javax.swing.ImageIcon) MyImageIcon(com.servoy.j2db.util.gui.MyImageIcon) Icon(javax.swing.Icon) 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