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);
}
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()));
}
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());
}
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;
}
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);
}
}
}
Aggregations