javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt/InstallerUiEswt.java
--- a/javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt/InstallerUiEswt.java Fri Jul 09 16:35:45 2010 +0300
+++ b/javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt/InstallerUiEswt.java Fri Jul 23 12:27:20 2010 +0300
@@ -35,6 +35,7 @@
import java.io.InputStream;
import java.io.IOException;
+import java.util.Enumeration;
import java.util.Hashtable;
import org.eclipse.ercp.swt.midp.UIThreadSupport;
@@ -48,6 +49,8 @@
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.internal.extension.DisplayExtension;
+import org.eclipse.swt.internal.extension.ImageUtil;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Composite;
@@ -201,10 +204,7 @@
display.sleep();
}
}
- if (iBoldFont != null && !iBoldFont.isDisposed())
- {
- iBoldFont.dispose();
- }
+ disposeResources();
display.dispose();
log("uiMain: display disposed");
synchronized (iExitWaitObject)
@@ -1047,17 +1047,21 @@
{
return iSecurityIcon;
}
- String iconFilename = ResourceUtil.UNTRUSTED_ICON_NAME;
+ int id = ImageUtil.THEME_IMAGE_SECURITY_UNTRUSTED;
if (aIdentified)
{
- iconFilename = ResourceUtil.TRUSTED_ICON_NAME;
+ id = ImageUtil.THEME_IMAGE_SECURITY_TRUSTED;
}
- String resourceDir = ResourceUtil.getResourceDir(0);
- for (int i = 1; iSecurityIcon == null && resourceDir != null; i++)
+
+ try
{
- iSecurityIcon = loadImage(aDisplay, resourceDir + iconFilename, false);
- resourceDir = ResourceUtil.getResourceDir(i);
+ iSecurityIcon = ImageUtil.createImageFromTheme(aDisplay, id);
}
+ catch (Throwable t)
+ {
+ log("Can not load security icon: " + t);
+ }
+
return iSecurityIcon;
}
@@ -1147,22 +1151,26 @@
try
{
long startTime = System.currentTimeMillis();
- ImageData[] imageDatas = new ImageLoader().load(aInputStream);
- ImageData imageData = imageDatas[0];
+
+ Image image = new Image(aDisplay, aInputStream);
if (aScaleImage)
{
- Point bestSize = getBestImageSize(
- imageData.width, imageData.height);
- if (bestSize.x != imageData.width ||
- bestSize.y != imageData.height)
+ int maxWidth = DisplayExtension.getBestImageWidth(DisplayExtension.LIST_ELEMENT);
+ int maxHeight = DisplayExtension.getBestImageHeight(DisplayExtension.LIST_ELEMENT);
+ Rectangle rect = image.getBounds();
+ if (maxWidth != rect.width || maxHeight != rect.height)
{
- imageData = imageData.scaledTo(bestSize.x, bestSize.y);
- log("Image " + aImageName + " scaled from " +
- imageDatas[0].width + "x" + imageDatas[0].height +
- " to " + bestSize.x + "x" + bestSize.y);
+ // Copy and scale natively preserving the aspect ratio
+ result = ImageUtil.scaleImage(aDisplay, image, new Point(maxWidth, maxHeight), true);
+ image.dispose();
+ image = null;
}
}
- result = new Image(aDisplay, imageData);
+ if (result == null)
+ {
+ result = image;
+ }
+
long endTime = System.currentTimeMillis();
log("Loaded image " + aImageName + " (load time " +
(endTime - startTime) + " ms)");
@@ -1176,33 +1184,6 @@
return result;
}
- /**
- * Determines the best image size for the image of given size.
- */
- private static Point getBestImageSize(int aWidth, int aHeight)
- {
- // Actually maximum image width and height should be obtained with
- // org.eclipse.swt.internal.extension.DisplayExtension
- // getBestImageWidth() and getBestImageHeight().
- final int MAX_WIDTH = 50; // max width in pixels
- final int MAX_HEIGHT = 50; // max height in pixels
- Point result = new Point(aWidth, aHeight);
- if (result.x > MAX_WIDTH || result.y > MAX_HEIGHT)
- {
- if (result.x >= MAX_WIDTH)
- {
- result.x = MAX_WIDTH;
- result.y = MAX_WIDTH * aHeight / aWidth;
- }
- if (result.y >= MAX_HEIGHT)
- {
- result.x = MAX_HEIGHT * aWidth / aHeight;
- result.y = MAX_HEIGHT;
- }
- }
- return result;
- }
-
/** Returns true if UI has been created and can be used. */
protected boolean isUiReady()
{
@@ -1298,6 +1279,13 @@
}
return iBoldFont;
}
+
+ int iconLabelTopMargin()
+ {
+ // Aproximating the space at the top of a Label.
+ // eSWT's Label adds extra space around texts but not around images.
+ return getBoldFont().getFontData()[0].getHeight();
+ }
void setActiveView(ViewBase aView)
{
@@ -1313,4 +1301,24 @@
{
return iActiveView;
}
+
+ private void disposeResources() {
+ if (iBoldFont != null && !iBoldFont.isDisposed())
+ {
+ iBoldFont.dispose();
+ }
+ if (iSecurityIcon != null && !iSecurityIcon.isDisposed())
+ {
+ iSecurityIcon.dispose();
+ }
+ Enumeration e = iImageTable.elements();
+ while (e.hasMoreElements())
+ {
+ Image img = (Image)e.nextElement();
+ if (img != null && !img.isDisposed())
+ {
+ img.dispose();
+ }
+ }
+ }
}