ImageLoaderpublic class ImageLoader extends Object
Fields Summary |
---|
private org.eclipse.swt.widgets.Display | display | public static org.eclipse.swt.graphics.Image | noImage | private final Map | mapImages | private final ArrayList | notFound | private com.aelitis.azureus.ui.skin.SkinProperties | skinProperties | private final ClassLoader | classLoader |
Methods Summary |
---|
private org.eclipse.swt.graphics.Image[] | findResources(java.lang.String sKey)
if (Collections.binarySearch(notFound, sKey) >= 0) {
return null;
}
String[] sSuffixChecks = {
"-over",
"-down",
"-disabled",
};
for (int i = 0; i < sSuffixChecks.length; i++) {
String sSuffix = sSuffixChecks[i];
if (sKey.endsWith(sSuffix)) {
//System.out.println("YAY " + sSuffix + " for " + sKey);
String sParentName = sKey.substring(0, sKey.length() - sSuffix.length());
String[] sParentFiles = skinProperties.getStringArray(sParentName);
if (sParentFiles != null) {
boolean bFoundOne = false;
Image[] images = new Image[sParentFiles.length];
for (int j = 0; j < sParentFiles.length; j++) {
int index = sParentFiles[j].lastIndexOf('.");
if (index > 0) {
String sTryFile = sParentFiles[j].substring(0, index) + sSuffix
+ sParentFiles[j].substring(index);
images[j] = loadImage(display, sTryFile, sKey);
if (images[j] == null) {
sTryFile = sParentFiles[j].substring(0, index)
+ sSuffix.replace('-", '_")
+ sParentFiles[j].substring(index);
images[j] = loadImage(display, sTryFile, sKey);
}
if (!bFoundOne && images[j] != null) {
bFoundOne = true;
}
}
}
if (bFoundOne) {
return images;
}
}
}
}
int i = Collections.binarySearch(notFound, sKey) * -1 - 1;
notFound.add(i, sKey);
return null;
| public org.eclipse.swt.graphics.Image | getImage(java.lang.String sKey)
Image[] images = getImages(sKey);
if (images == null || images.length == 0) {
return null;
}
return images[0];
| public org.eclipse.swt.graphics.Image[] | getImages(java.lang.String sKey)
if (sKey == null) {
return new Image[] {
getNoImage()
};
}
Image[] images = (Image[]) mapImages.get(sKey);
if (images != null) {
return images;
}
String[] locations = skinProperties.getStringArray(sKey);
// System.out.println(sKey + "=" + properties.getStringValue(sKey)
// + ";" + ((locations == null) ? "null" : "" + locations.length));
if (locations == null || locations.length == 0) {
images = findResources(sKey);
if (images == null) {
return new Image[] {
getNoImage()
};
}
for (int i = 0; i < images.length; i++) {
if (images[i] == null) {
images[i] = getNoImage();
}
}
} else {
images = new Image[locations.length];
for (int i = 0; i < locations.length; i++) {
images[i] = loadImage(display, locations[i], sKey);
if (images[i] == null) {
images[i] = getNoImage();
}
}
}
mapImages.put(sKey, images);
return images;
| private static org.eclipse.swt.graphics.Image | getNoImage()
if (noImage == null) {
Display display = Display.getDefault();
final int SIZE = 10;
noImage = new Image(display, SIZE, SIZE);
GC gc = new GC(noImage);
gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
gc.fillRectangle(0, 0, SIZE, SIZE);
gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
gc.drawRectangle(0, 0, SIZE - 1, SIZE - 1);
gc.dispose();
}
return noImage;
| public boolean | imageExists(java.lang.String name)
return isRealImage(getImage(name));
| public static boolean | isRealImage(org.eclipse.swt.graphics.Image image)
return image != null && image != getNoImage() && !image.isDisposed();
| private org.eclipse.swt.graphics.Image | loadImage(org.eclipse.swt.widgets.Display display, java.lang.String key)
return loadImage(display, skinProperties.getStringValue(key), key);
| private org.eclipse.swt.graphics.Image | loadImage(org.eclipse.swt.widgets.Display display, java.lang.String res, java.lang.String sKey)
Image img = null;
//System.out.println("LoadImage " + sKey + " - " + res);
if (res == null) {
String[] sSuffixChecks = {
"-over",
"-down",
"-disabled",
};
for (int i = 0; i < sSuffixChecks.length; i++) {
String sSuffix = sSuffixChecks[i];
if (sKey.endsWith(sSuffix)) {
//System.out.println("Yay " + sSuffix + " for " + sKey);
String sParentName = sKey.substring(0, sKey.length()
- sSuffix.length());
String sParentFile = skinProperties.getStringValue(sParentName);
if (sParentFile != null) {
int index = sParentFile.lastIndexOf('.");
if (index > 0) {
String sTryFile = sParentFile.substring(0, index) + sSuffix
+ sParentFile.substring(index);
img = loadImage(display, sTryFile, sKey);
if (img != null) {
break;
}
sTryFile = sParentFile.substring(0, index)
+ sSuffix.replace('-", '_") + sParentFile.substring(index);
img = loadImage(display, sTryFile, sKey);
if (img != null) {
break;
}
}
}
}
}
}
if (img == null) {
try {
InputStream is = classLoader.getResourceAsStream(res);
if (is != null) {
img = new Image(display, is);
}
if (img == null) {
//IMP.log("ImageRepository:loadImage:: Resource not found: " + res);
}
} catch (Throwable e) {
System.err.println("ImageRepository:loadImage:: Resource not found: "
+ res + "\n" + e);
}
}
return img;
| public void | unLoadImages()
Iterator iter;
iter = mapImages.values().iterator();
while (iter.hasNext()) {
Image[] images = (Image[]) iter.next();
if (images != null) {
for (int i = 0; i < images.length; i++) {
Image image = images[i];
if (image != null && !image.isDisposed()) {
image.dispose();
}
}
}
}
|
|