String oldImageID = (String) canvas.getData("ImageID");
if (sImageID != null && sImageID.equals(oldImageID)) {
return null;
}
ImageLoader imageLoader = skin.getImageLoader(properties);
if (oldImageID != null && canvas.getData("image") != null) {
imageLoader.releaseImage(oldImageID);
}
int hpadding = properties.getIntValue(sConfigID + ".h-padding", 0);
canvas.setData("hpadding", new Long(hpadding));
Image[] images = sImageID == null || sImageID.length() == 0 ? null
: imageLoader.getImages(sImageID);
String sDrawMode = properties.getStringValue(sConfigID + ".drawmode");
if (sDrawMode == null) {
sDrawMode = properties.getStringValue(
SWTSkinObjectImage.this.sConfigID + ".drawmode", "");
}
Long drawMode;
if (sDrawMode.equals("scale")) {
drawMode = DRAW_SCALE;
} else if (sDrawMode.equals("stretch")) {
drawMode = DRAW_STRETCH;
} else if (sDrawMode.equals("center")) {
drawMode = DRAW_CENTER;
} else if (sDrawMode.equals("h-center")) {
drawMode = DRAW_HCENTER;
} else if (sDrawMode.equalsIgnoreCase("tile")) {
drawMode = DRAW_TILE;
} else if (sDrawMode.equalsIgnoreCase("animate")
|| (sDrawMode.length() == 0 && images != null && images.length > 3)) {
drawMode = DRAW_ANIMATE;
} else if (sDrawMode.equalsIgnoreCase("left")) {
drawMode = DRAW_LEFT;
} else {
drawMode = DRAW_NORMAL;
}
canvas.setData("drawmode", drawMode);
Image image = null;
boolean hasExistingDelay = canvas.getData("delay") != null;
canvas.setData("delay", null);
if (images == null) {
canvas.setData("images", null);
image = null;
} else if (drawMode == DRAW_ANIMATE) {
int animationDelay = ImageLoader.getInstance().getAnimationDelay(sImageID);
canvas.setData("images", images);
canvas.setData("ImageIndex", Long.valueOf(0));
canvas.setData("delay", new Long(animationDelay));
image = images[0];
if (!hasExistingDelay) {
setupAnimationTrigger(animationDelay);
}
} else if (images.length == 3) {
Image imageLeft = images[0];
if (ImageLoader.isRealImage(imageLeft)) {
canvas.setData("image-left", imageLeft);
}
image = images[1];
Image imageRight = images[2];
if (ImageLoader.isRealImage(imageRight)) {
canvas.setData("image-right", imageRight);
}
} else if (images.length > 0) {
image = images[0];
}
if (image == null) {
image = ImageLoader.noImage;
}
//allowImageDimming = sDrawMode.equalsIgnoreCase("dim");
Rectangle imgBounds = image.getBounds();
if (drawMode != DRAW_CENTER && drawMode != DRAW_HCENTER
&& drawMode != DRAW_STRETCH) {
canvas.setSize(imgBounds.width + hpadding, imgBounds.height);
canvas.setData("oldSize", canvas.getSize());
}
//canvas.setData("image", image);
if (drawMode == DRAW_TILE || drawMode == DRAW_NORMAL || drawMode == DRAW_LEFT
|| drawMode == DRAW_ANIMATE) {
// XXX Huh? A tile of one? :)
FormData fd = (FormData) canvas.getLayoutData();
if (fd == null) {
fd = new FormData(imgBounds.width + hpadding, imgBounds.height);
} else {
fd.width = imgBounds.width + hpadding;
fd.height = imgBounds.height;
}
canvas.setData("oldSize", new Point(fd.width, fd.height));
canvas.setLayoutData(fd);
Utils.relayout(canvas);
}
// remove in case already added
canvas.removePaintListener(paintListener);
canvas.addPaintListener(paintListener);
canvas.setData("ImageID", sImageID);
canvas.redraw();
SWTSkinUtils.addMouseImageChangeListeners(canvas);
if (drawMode != DRAW_ANIMATE) {
imageLoader.releaseImage(sImageID);
}
return null;
}
});
}