33 import com.nokia.mj.impl.utils.StartUpTrace; |
33 import com.nokia.mj.impl.utils.StartUpTrace; |
34 import com.nokia.mj.impl.utils.exception.InstallerExceptionBase; |
34 import com.nokia.mj.impl.utils.exception.InstallerExceptionBase; |
35 |
35 |
36 import java.io.InputStream; |
36 import java.io.InputStream; |
37 import java.io.IOException; |
37 import java.io.IOException; |
|
38 import java.util.Enumeration; |
38 import java.util.Hashtable; |
39 import java.util.Hashtable; |
39 |
40 |
40 import org.eclipse.ercp.swt.midp.UIThreadSupport; |
41 import org.eclipse.ercp.swt.midp.UIThreadSupport; |
41 import org.eclipse.swt.SWT; |
42 import org.eclipse.swt.SWT; |
42 import org.eclipse.swt.events.ControlEvent; |
43 import org.eclipse.swt.events.ControlEvent; |
46 import org.eclipse.swt.graphics.Image; |
47 import org.eclipse.swt.graphics.Image; |
47 import org.eclipse.swt.graphics.ImageData; |
48 import org.eclipse.swt.graphics.ImageData; |
48 import org.eclipse.swt.graphics.ImageLoader; |
49 import org.eclipse.swt.graphics.ImageLoader; |
49 import org.eclipse.swt.graphics.Point; |
50 import org.eclipse.swt.graphics.Point; |
50 import org.eclipse.swt.graphics.Rectangle; |
51 import org.eclipse.swt.graphics.Rectangle; |
|
52 import org.eclipse.swt.internal.extension.DisplayExtension; |
|
53 import org.eclipse.swt.internal.extension.ImageUtil; |
51 import org.eclipse.swt.widgets.Display; |
54 import org.eclipse.swt.widgets.Display; |
52 import org.eclipse.swt.widgets.Event; |
55 import org.eclipse.swt.widgets.Event; |
53 import org.eclipse.swt.widgets.Composite; |
56 import org.eclipse.swt.widgets.Composite; |
54 import org.eclipse.swt.widgets.Listener; |
57 import org.eclipse.swt.widgets.Listener; |
55 import org.eclipse.swt.widgets.Shell; |
58 import org.eclipse.swt.widgets.Shell; |
124 super.init(aMode, aListener); |
127 super.init(aMode, aListener); |
125 StartUpTrace.doTrace("InstallerUiEswt init"); |
128 StartUpTrace.doTrace("InstallerUiEswt init"); |
126 // Create a hashtable for icons. |
129 // Create a hashtable for icons. |
127 iImageTable = new Hashtable(); |
130 iImageTable = new Hashtable(); |
128 // Create a new thread to be the UI main thread. |
131 // Create a new thread to be the UI main thread. |
129 iUiThreadExists = true; |
|
130 UIThreadSupport.startInUIThread(new Runnable() |
132 UIThreadSupport.startInUIThread(new Runnable() |
131 { |
133 { |
132 public void run() |
134 public void run() |
133 { |
135 { |
134 uiMain(); |
136 uiMain(); |
143 * This method is executed in UI main thread. |
145 * This method is executed in UI main thread. |
144 */ |
146 */ |
145 private void uiMain() |
147 private void uiMain() |
146 { |
148 { |
147 log("uiMain: thread started"); |
149 log("uiMain: thread started"); |
|
150 iUiThreadExists = true; |
148 try |
151 try |
149 { |
152 { |
150 // Create the necessary views. |
153 // Create the necessary views. |
151 Display display = new Display(); |
154 Display display = new Display(); |
152 StartUpTrace.doTrace("InstallerUiEswt display created"); |
155 StartUpTrace.doTrace("InstallerUiEswt display created"); |
510 // UI was not yet ready when started() was called. |
510 // UI was not yet ready when started() was called. |
511 // Ensure that iProgressView has been opened before |
511 // Ensure that iProgressView has been opened before |
512 // updating it. |
512 // updating it. |
513 synchronized (iProgressSyncObject) |
513 synchronized (iProgressSyncObject) |
514 { |
514 { |
|
515 if (iDlProgressView != null && iDlProgressView.isVisible()) |
|
516 { |
|
517 // If download progress is being displayed, |
|
518 // do not display installation progress. |
|
519 return; |
|
520 } |
515 if (iDisplayProgress && !iProgressView.isVisible()) |
521 if (iDisplayProgress && !iProgressView.isVisible()) |
516 { |
522 { |
517 iProgressView.setVisible(true); |
523 iProgressView.setVisible(true); |
518 } |
524 } |
519 if (iDisplayProgress && !iProgressBarUpdateTraced) |
525 if (iDisplayProgress && !iProgressBarUpdateTraced) |
992 log("LaunchAppQuery returns " + result + " for " + aLaunchAppInfo); |
998 log("LaunchAppQuery returns " + result + " for " + aLaunchAppInfo); |
993 return result; |
999 return result; |
994 } |
1000 } |
995 |
1001 |
996 /** |
1002 /** |
|
1003 * Executes given Runnable synchronously in the UI thread. |
|
1004 */ |
|
1005 public void syncExec(Runnable aRunnable) |
|
1006 { |
|
1007 iParent.getDisplay().syncExec(aRunnable); |
|
1008 } |
|
1009 |
|
1010 /** |
997 * Returns string title basing on mode of this InstallerUi. |
1011 * Returns string title basing on mode of this InstallerUi. |
998 */ |
1012 */ |
999 protected String getTitle() |
1013 protected String getTitle() |
1000 { |
1014 { |
1001 String result = null; |
1015 String result = null; |
1031 { |
1045 { |
1032 if (iSecurityIcon != null) |
1046 if (iSecurityIcon != null) |
1033 { |
1047 { |
1034 return iSecurityIcon; |
1048 return iSecurityIcon; |
1035 } |
1049 } |
1036 String iconFilename = ResourceUtil.UNTRUSTED_ICON_NAME; |
1050 int id = ImageUtil.THEME_IMAGE_SECURITY_UNTRUSTED; |
1037 if (aIdentified) |
1051 if (aIdentified) |
1038 { |
1052 { |
1039 iconFilename = ResourceUtil.TRUSTED_ICON_NAME; |
1053 id = ImageUtil.THEME_IMAGE_SECURITY_TRUSTED; |
1040 } |
1054 } |
1041 String resourceDir = ResourceUtil.getResourceDir(0); |
1055 |
1042 for (int i = 1; iSecurityIcon == null && resourceDir != null; i++) |
1056 try |
1043 { |
1057 { |
1044 iSecurityIcon = loadImage(aDisplay, resourceDir + iconFilename, false); |
1058 iSecurityIcon = ImageUtil.createImageFromTheme(aDisplay, id); |
1045 resourceDir = ResourceUtil.getResourceDir(i); |
1059 } |
1046 } |
1060 catch (Throwable t) |
|
1061 { |
|
1062 log("Can not load security icon: " + t); |
|
1063 } |
|
1064 |
1047 return iSecurityIcon; |
1065 return iSecurityIcon; |
1048 } |
1066 } |
1049 |
1067 |
1050 /** |
1068 /** |
1051 * Loads image from specified InputStream. This method scales the image |
1069 * Loads image from specified InputStream. This method scales the image |
1131 return result; |
1149 return result; |
1132 } |
1150 } |
1133 try |
1151 try |
1134 { |
1152 { |
1135 long startTime = System.currentTimeMillis(); |
1153 long startTime = System.currentTimeMillis(); |
1136 ImageData[] imageDatas = new ImageLoader().load(aInputStream); |
1154 |
1137 ImageData imageData = imageDatas[0]; |
1155 Image image = new Image(aDisplay, aInputStream); |
1138 if (aScaleImage) |
1156 if (aScaleImage) |
1139 { |
1157 { |
1140 Point bestSize = getBestImageSize( |
1158 int maxWidth = DisplayExtension.getBestImageWidth(DisplayExtension.LIST_ELEMENT); |
1141 imageData.width, imageData.height); |
1159 int maxHeight = DisplayExtension.getBestImageHeight(DisplayExtension.LIST_ELEMENT); |
1142 if (bestSize.x != imageData.width || |
1160 Rectangle rect = image.getBounds(); |
1143 bestSize.y != imageData.height) |
1161 if (maxWidth != rect.width || maxHeight != rect.height) |
1144 { |
1162 { |
1145 imageData = imageData.scaledTo(bestSize.x, bestSize.y); |
1163 // Copy and scale natively preserving the aspect ratio |
1146 log("Image " + aImageName + " scaled from " + |
1164 result = ImageUtil.scaleImage(aDisplay, image, new Point(maxWidth, maxHeight), true); |
1147 imageDatas[0].width + "x" + imageDatas[0].height + |
1165 image.dispose(); |
1148 " to " + bestSize.x + "x" + bestSize.y); |
1166 image = null; |
1149 } |
1167 } |
1150 } |
1168 } |
1151 result = new Image(aDisplay, imageData); |
1169 if (result == null) |
|
1170 { |
|
1171 result = image; |
|
1172 } |
|
1173 |
1152 long endTime = System.currentTimeMillis(); |
1174 long endTime = System.currentTimeMillis(); |
1153 log("Loaded image " + aImageName + " (load time " + |
1175 log("Loaded image " + aImageName + " (load time " + |
1154 (endTime - startTime) + " ms)"); |
1176 (endTime - startTime) + " ms)"); |
1155 iImageTable.put(aImageName, result); |
1177 iImageTable.put(aImageName, result); |
1156 } |
1178 } |
1160 //logError("Exception while loading image " + aImageName, t); |
1182 //logError("Exception while loading image " + aImageName, t); |
1161 } |
1183 } |
1162 return result; |
1184 return result; |
1163 } |
1185 } |
1164 |
1186 |
1165 /** |
|
1166 * Determines the best image size for the image of given size. |
|
1167 */ |
|
1168 private static Point getBestImageSize(int aWidth, int aHeight) |
|
1169 { |
|
1170 // Actually maximum image width and height should be obtained with |
|
1171 // org.eclipse.swt.internal.extension.DisplayExtension |
|
1172 // getBestImageWidth() and getBestImageHeight(). |
|
1173 final int MAX_WIDTH = 50; // max width in pixels |
|
1174 final int MAX_HEIGHT = 50; // max height in pixels |
|
1175 Point result = new Point(aWidth, aHeight); |
|
1176 if (result.x > MAX_WIDTH || result.y > MAX_HEIGHT) |
|
1177 { |
|
1178 if (result.x >= MAX_WIDTH) |
|
1179 { |
|
1180 result.x = MAX_WIDTH; |
|
1181 result.y = MAX_WIDTH * aHeight / aWidth; |
|
1182 } |
|
1183 if (result.y >= MAX_HEIGHT) |
|
1184 { |
|
1185 result.x = MAX_HEIGHT * aWidth / aHeight; |
|
1186 result.y = MAX_HEIGHT; |
|
1187 } |
|
1188 } |
|
1189 return result; |
|
1190 } |
|
1191 |
|
1192 /** Returns true if UI has been created and can be used. */ |
1187 /** Returns true if UI has been created and can be used. */ |
1193 protected boolean isUiReady() |
1188 protected boolean isUiReady() |
1194 { |
1189 { |
1195 if (iProgressView == null) |
1190 if (iProgressView == null) |
1196 { |
1191 { |
1282 } |
1277 } |
1283 iBoldFont = new Font(iParent.getDisplay(), boldFontDatas); |
1278 iBoldFont = new Font(iParent.getDisplay(), boldFontDatas); |
1284 } |
1279 } |
1285 return iBoldFont; |
1280 return iBoldFont; |
1286 } |
1281 } |
|
1282 |
|
1283 int iconLabelTopMargin() |
|
1284 { |
|
1285 // Aproximating the space at the top of a Label. |
|
1286 // eSWT's Label adds extra space around texts but not around images. |
|
1287 return getBoldFont().getFontData()[0].getHeight(); |
|
1288 } |
1287 |
1289 |
1288 void setActiveView(ViewBase aView) |
1290 void setActiveView(ViewBase aView) |
1289 { |
1291 { |
1290 if (iActiveView != null && iActiveView != aView && |
1292 if (iActiveView != null && iActiveView != aView && |
1291 !iActiveView.isDisposed()) |
1293 !iActiveView.isDisposed()) |
1297 |
1299 |
1298 ViewBase getActiveView() |
1300 ViewBase getActiveView() |
1299 { |
1301 { |
1300 return iActiveView; |
1302 return iActiveView; |
1301 } |
1303 } |
|
1304 |
|
1305 private void disposeResources() { |
|
1306 if (iBoldFont != null && !iBoldFont.isDisposed()) |
|
1307 { |
|
1308 iBoldFont.dispose(); |
|
1309 } |
|
1310 if (iSecurityIcon != null && !iSecurityIcon.isDisposed()) |
|
1311 { |
|
1312 iSecurityIcon.dispose(); |
|
1313 } |
|
1314 Enumeration e = iImageTable.elements(); |
|
1315 while (e.hasMoreElements()) |
|
1316 { |
|
1317 Image img = (Image)e.nextElement(); |
|
1318 if (img != null && !img.isDisposed()) |
|
1319 { |
|
1320 img.dispose(); |
|
1321 } |
|
1322 } |
|
1323 } |
1302 } |
1324 } |