Search in sources :

Example 56 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class ScaleImageLabel method setUIID.

/**
 * {@inheritDoc}
 * Overriden to prevent the setUIID from replacing the code
 */
@Override
public void setUIID(String id) {
    byte type = getBackgroundType();
    Image icon = getIcon();
    super.setUIID(id);
    setIcon(icon);
    getAllStyles().setBackgroundType(type);
}
Also used : Image(com.codename1.ui.Image)

Example 57 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class RSSReader method setIconPlaceholder.

/**
 * @param iconPlaceholder the iconPlaceholder to set
 */
public void setIconPlaceholder(Image iconPlaceholder) {
    this.iconPlaceholder = iconPlaceholder;
    if (service != null) {
        service.setIconPlaceholder(iconPlaceholder);
    }
    setRenderer(new GenericListCellRenderer(createRendererContainer(), createRendererContainer()));
}
Also used : GenericListCellRenderer(com.codename1.ui.list.GenericListCellRenderer)

Example 58 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class ScaleImageButton method calcPreferredSize.

/**
 * {@inheritDoc}
 */
@Override
protected Dimension calcPreferredSize() {
    Image i = getIcon();
    if (i == null) {
        return new Dimension();
    }
    int dw = Display.getInstance().getDisplayWidth();
    int iw = i.getWidth();
    int ih = i.getHeight();
    // a scrollable container the vertical height might be granted providing so much space as to make this unrealistic...
    if (iw > dw) {
        float ratio = ((float) iw) / ((float) dw);
        iw = (int) (((float) iw) / ((float) ratio));
        ih = (int) (((float) ih) / ((float) ratio));
    }
    Style s = getStyle();
    return new Dimension(iw + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), ih + s.getPaddingTop() + s.getPaddingBottom());
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Image(com.codename1.ui.Image)

Example 59 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class CloudImageProperty method propertyValue.

/**
 * {@inheritDoc}
 */
public Object propertyValue(CloudObject obj, String propertyName) {
    final String key = (String) obj.getObject(idProperty);
    if (key == null) {
        return placeholderImage;
    }
    Image image = (Image) getCache().get(key);
    if (image == null) {
        ReplaceableImage r = inProgress.get(key);
        if (r != null) {
            return r;
        }
        final ReplaceableImage rp = ReplaceableImage.create(placeholderImage);
        inProgress.put(key, rp);
        ConnectionRequest cr = new ConnectionRequest() {

            private EncodedImage e;

            protected void readResponse(InputStream input) throws IOException {
                e = EncodedImage.create(input);
                ;
                if (e.getWidth() != placeholderImage.getWidth() || e.getHeight() != placeholderImage.getHeight()) {
                    ImageIO io = ImageIO.getImageIO();
                    if (io != null) {
                        ByteArrayOutputStream bo = new ByteArrayOutputStream();
                        io.save(new ByteArrayInputStream(e.getImageData()), bo, ImageIO.FORMAT_JPEG, placeholderImage.getWidth(), placeholderImage.getHeight(), 0.9f);
                        e = EncodedImage.create(bo.toByteArray());
                    }
                }
            }

            protected void postResponse() {
                rp.replace(e);
                getCache().put(key, e);
                inProgress.remove(key);
            }
        };
        cr.setPost(false);
        cr.setUrl(CloudStorage.getInstance().getUrlForCloudFileId(key));
        NetworkManager.getInstance().addToQueue(cr);
        return rp;
    }
    return image;
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ReplaceableImage(com.codename1.components.ReplaceableImage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Image(com.codename1.ui.Image) ReplaceableImage(com.codename1.components.ReplaceableImage) EncodedImage(com.codename1.ui.EncodedImage) EncodedImage(com.codename1.ui.EncodedImage) ImageIO(com.codename1.ui.util.ImageIO)

Example 60 with Image

use of com.codename1.ui.Image in project CodenameOne by codenameone.

the class SignatureComponent method setSignatureImage.

/**
 * Sets the signature image for this field.  This will also scale the image and
 * show it as the icon for the button.
 * @param img The image to set as the signature image.
 */
public void setSignatureImage(Image img) {
    if (img != signatureImage) {
        signatureImage = img;
        lead.setText("");
        if (img != null) {
            int maxW = lead.getWidth() - lead.getStyle().getPaddingLeftNoRTL() - lead.getStyle().getPaddingRightNoRTL();
            int maxH = lead.getHeight() - lead.getStyle().getPaddingTop() - lead.getStyle().getPaddingBottom();
            Image icon = img;
            if (icon.getWidth() > maxW || icon.getHeight() > maxH) {
                icon = icon.scaledSmallerRatio(maxW, maxH);
            }
            lead.setIcon(icon);
        } else {
            lead.setText(localize("SignatureComponent.LeadText", "Press to sign"));
            lead.setIcon(null);
        }
    }
}
Also used : Image(com.codename1.ui.Image)

Aggregations

Image (com.codename1.ui.Image)82 EncodedImage (com.codename1.ui.EncodedImage)46 IOException (java.io.IOException)29 Hashtable (java.util.Hashtable)19 AnimationObject (com.codename1.ui.animations.AnimationObject)18 BufferedImage (java.awt.image.BufferedImage)18 Style (com.codename1.ui.plaf.Style)16 Form (com.codename1.ui.Form)15 ActionEvent (com.codename1.ui.events.ActionEvent)14 Dimension (com.codename1.ui.geom.Dimension)14 FontImage (com.codename1.ui.FontImage)13 BorderLayout (com.codename1.ui.layouts.BorderLayout)13 Timeline (com.codename1.ui.animations.Timeline)12 ActionListener (com.codename1.ui.events.ActionListener)12 Border (com.codename1.ui.plaf.Border)12 Container (com.codename1.ui.Container)11 InputStream (java.io.InputStream)11 Graphics (com.codename1.ui.Graphics)10 Label (com.codename1.ui.Label)10 Button (com.codename1.ui.Button)9