25 import com.nokia.mj.impl.installer.ui.InstallerUiListener; |
25 import com.nokia.mj.impl.installer.ui.InstallerUiListener; |
26 import com.nokia.mj.impl.installer.ui.InstallInfo; |
26 import com.nokia.mj.impl.installer.ui.InstallInfo; |
27 import com.nokia.mj.impl.installer.ui.LaunchAppInfo; |
27 import com.nokia.mj.impl.installer.ui.LaunchAppInfo; |
28 import com.nokia.mj.impl.installer.ui.PermissionInfo; |
28 import com.nokia.mj.impl.installer.ui.PermissionInfo; |
29 import com.nokia.mj.impl.installer.ui.UninstallInfo; |
29 import com.nokia.mj.impl.installer.ui.UninstallInfo; |
30 import com.nokia.mj.impl.installer.ui.eswt.MinimalUi; |
|
31 import com.nokia.mj.impl.rt.ui.ConfirmData; |
30 import com.nokia.mj.impl.rt.ui.ConfirmData; |
32 import com.nokia.mj.impl.rt.ui.RuntimeUi; |
31 import com.nokia.mj.impl.rt.ui.RuntimeUi; |
33 import com.nokia.mj.impl.rt.ui.RuntimeUiFactory; |
32 import com.nokia.mj.impl.rt.ui.RuntimeUiFactory; |
34 import com.nokia.mj.impl.utils.ResourceUtil; |
33 import com.nokia.mj.impl.utils.ResourceUtil; |
35 import com.nokia.mj.impl.utils.StartUpTrace; |
34 import com.nokia.mj.impl.utils.StartUpTrace; |
45 import org.eclipse.swt.events.ControlListener; |
44 import org.eclipse.swt.events.ControlListener; |
46 import org.eclipse.swt.graphics.Font; |
45 import org.eclipse.swt.graphics.Font; |
47 import org.eclipse.swt.graphics.FontData; |
46 import org.eclipse.swt.graphics.FontData; |
48 import org.eclipse.swt.graphics.Image; |
47 import org.eclipse.swt.graphics.Image; |
49 import org.eclipse.swt.graphics.ImageData; |
48 import org.eclipse.swt.graphics.ImageData; |
50 import org.eclipse.swt.graphics.ImageLoader; |
|
51 import org.eclipse.swt.graphics.Point; |
49 import org.eclipse.swt.graphics.Point; |
52 import org.eclipse.swt.graphics.Rectangle; |
50 import org.eclipse.swt.graphics.Rectangle; |
53 import org.eclipse.swt.internal.extension.DisplayExtension; |
51 import org.eclipse.swt.internal.extension.DisplayExtension; |
|
52 import org.eclipse.swt.internal.qt.BaseCSSEngine; |
54 import org.eclipse.swt.widgets.Display; |
53 import org.eclipse.swt.widgets.Display; |
55 import org.eclipse.swt.widgets.Event; |
54 import org.eclipse.swt.widgets.Event; |
56 import org.eclipse.swt.widgets.Composite; |
55 import org.eclipse.swt.widgets.Composite; |
57 import org.eclipse.swt.widgets.Listener; |
56 import org.eclipse.swt.widgets.Listener; |
58 import org.eclipse.swt.widgets.Shell; |
57 import org.eclipse.swt.widgets.Shell; |
61 * JavaInstaller eSWT UI. |
60 * JavaInstaller eSWT UI. |
62 */ |
61 */ |
63 public class InstallerUiEswt extends InstallerUi |
62 public class InstallerUiEswt extends InstallerUi |
64 { |
63 { |
65 /** Disable UI temporarily. */ |
64 /** Disable UI temporarily. */ |
66 private static final boolean DISABLE_UI = true; |
65 private static final boolean DISABLE_UI = |
|
66 (System.getProperty("com.nokia.mj.impl.installer.ui.disableui") |
|
67 == null? false: true); |
67 /** Default shell style. */ |
68 /** Default shell style. */ |
68 private static final int SHELL_STYLE = |
69 private static final int SHELL_STYLE = |
69 SWT.BORDER | SWT.APPLICATION_MODAL | SWT.ON_TOP; |
70 SWT.BORDER | SWT.APPLICATION_MODAL | SWT.ON_TOP; |
70 |
71 |
|
72 private BaseCSSEngine iCssEngine = null; |
71 private Shell iParent = null; |
73 private Shell iParent = null; |
72 private Shell iDialog = null; |
74 private Shell iDialog = null; |
73 private ProgressView iProgressView = null; |
75 private ProgressView iProgressView = null; |
74 private ProgressView iDlProgressView = null; |
76 private ProgressView iDlProgressView = null; |
75 private ProgressView iOcspProgressView = null; |
77 private ProgressView iOcspProgressView = null; |
98 private Image iSecurityIcon = null; |
100 private Image iSecurityIcon = null; |
99 /** Flag telling if progress bar should be displayed. */ |
101 /** Flag telling if progress bar should be displayed. */ |
100 private boolean iDisplayProgress = false; |
102 private boolean iDisplayProgress = false; |
101 /** Flag telling if the first progress bar update has been traced. */ |
103 /** Flag telling if the first progress bar update has been traced. */ |
102 private boolean iProgressBarUpdateTraced = false; |
104 private boolean iProgressBarUpdateTraced = false; |
103 /** Flag telling if MinimalUi should be used if UI creation fails. */ |
|
104 private boolean iMinimalUiEnabled = true; |
|
105 |
105 |
106 /** Hashtable for storing the loaded icons. */ |
106 /** Hashtable for storing the loaded icons. */ |
107 private static Hashtable iImageTable = null; |
107 private static Hashtable iImageTable = null; |
108 /** Best size for application icon. */ |
108 /** Best size for application icon. */ |
109 private static Point iBestIconSize = null; |
109 private static Point iBestIconSize = null; |
160 { |
160 { |
161 // Create the necessary views. |
161 // Create the necessary views. |
162 DisplayExtension display = new DisplayExtension(); |
162 DisplayExtension display = new DisplayExtension(); |
163 StartUpTrace.doTrace("InstallerUiEswt display created"); |
163 StartUpTrace.doTrace("InstallerUiEswt display created"); |
164 display.setAppName(""); // Remove display title. |
164 display.setAppName(""); // Remove display title. |
|
165 iCssEngine = new BaseCSSEngine(display); |
165 iParent = new Shell(display); |
166 iParent = new Shell(display); |
166 iDialog = new Shell(iParent, SHELL_STYLE); |
167 iDialog = new Shell(iParent, SHELL_STYLE); |
167 iDefaultShellBounds = iDialog.internal_getDefaultBounds(); |
168 iDefaultShellBounds = iDialog.internal_getDefaultBounds(); |
168 iDefaultShellClientBounds = iDialog.getClientArea(); |
169 iDefaultShellClientBounds = iDialog.getClientArea(); |
169 iBoldFont = getBoldFont(); |
170 iBoldFont = getBoldFont(); |
182 //aEvent.doit = false; |
183 //aEvent.doit = false; |
183 } |
184 } |
184 }); |
185 }); |
185 |
186 |
186 // Initialize best icon size. |
187 // Initialize best icon size. |
187 iBestIconSize = new Point( |
188 //iBestIconSize = new Point( |
188 display.getBestImageWidth(DisplayExtension.ALERT), |
189 // display.getBestImageWidth(DisplayExtension.ALERT), |
189 display.getBestImageHeight(DisplayExtension.ALERT)); |
190 // display.getBestImageHeight(DisplayExtension.ALERT)); |
190 log("Best icon size: " + iBestIconSize); |
191 //log("Best icon size: " + iBestIconSize); |
191 |
192 |
192 synchronized (iInitWaitObject) |
193 synchronized (iInitWaitObject) |
193 { |
194 { |
194 // Notify that UI is now ready. |
195 // Notify that UI is now ready. |
195 iInitWaitObject.notify(); |
196 iInitWaitObject.notify(); |
302 public boolean confirm(InstallInfo aInstallInfo) |
303 public boolean confirm(InstallInfo aInstallInfo) |
303 { |
304 { |
304 super.confirm(aInstallInfo); |
305 super.confirm(aInstallInfo); |
305 |
306 |
306 waitForUi(); |
307 waitForUi(); |
|
308 if (!isUiReady()) |
|
309 { |
|
310 // If UI is not ready by the time confirmation is requested, |
|
311 // throw an exception. |
|
312 throw new RuntimeException("JavaInstallerUi not ready"); |
|
313 } |
|
314 |
307 boolean result = true; |
315 boolean result = true; |
308 if (!isUiReady()) |
|
309 { |
|
310 result = false; |
|
311 if (iMinimalUiEnabled) |
|
312 { |
|
313 result = MinimalUi.confirmStatic(aInstallInfo); |
|
314 log("MinimalUi installation confirmation returns " + result); |
|
315 return result; |
|
316 } |
|
317 else |
|
318 { |
|
319 // If UI is not ready by the time confirmation is requested, |
|
320 // throw an exception. |
|
321 throw new RuntimeException("JavaInstallerUi not ready"); |
|
322 } |
|
323 } |
|
324 |
|
325 if (result) |
316 if (result) |
326 { |
317 { |
327 StartUpTrace.doTrace("InstallerUiEswt confirm"); |
318 StartUpTrace.doTrace("InstallerUiEswt confirm"); |
328 if (iInstallConfirmationView == null) |
319 if (iInstallConfirmationView == null) |
329 { |
320 { |
474 // UI was not yet ready when started() was called. |
465 // UI was not yet ready when started() was called. |
475 // Ensure that iProgressView has been opened before |
466 // Ensure that iProgressView has been opened before |
476 // updating it. |
467 // updating it. |
477 synchronized (iProgressSyncObject) |
468 synchronized (iProgressSyncObject) |
478 { |
469 { |
|
470 if (iDlProgressView != null && iDlProgressView.isVisible()) |
|
471 { |
|
472 // If download progress is being displayed, |
|
473 // do not display installation progress. |
|
474 return; |
|
475 } |
479 if (iDisplayProgress && !iProgressView.isVisible()) |
476 if (iDisplayProgress && !iProgressView.isVisible()) |
480 { |
477 { |
481 // Re-create iProgressView here so that it gets |
478 // Re-create iProgressView here so that it gets |
482 // application info that was set when confirm() |
479 // application info that was set when confirm() |
483 // was called. |
480 // was called. |
1066 { |
1063 { |
1067 if (iSecurityIcon != null) |
1064 if (iSecurityIcon != null) |
1068 { |
1065 { |
1069 return iSecurityIcon; |
1066 return iSecurityIcon; |
1070 } |
1067 } |
1071 String iconFilename = ResourceUtil.UNTRUSTED_ICON_NAME; |
1068 String iconFilename = "java_3_untrusted.png"; |
1072 if (aIdentified) |
1069 if (aIdentified) |
1073 { |
1070 { |
1074 iconFilename = ResourceUtil.TRUSTED_ICON_NAME; |
1071 iconFilename = "java_3_trusted.png"; |
1075 } |
1072 } |
1076 String resourceDir = ResourceUtil.getResourceDir(0); |
1073 String resourceDir = ResourceUtil.getResourceDir(0); |
1077 for (int i = 1; iSecurityIcon == null && resourceDir != null; i++) |
1074 for (int i = 1; iSecurityIcon == null && resourceDir != null; i++) |
1078 { |
1075 { |
1079 iSecurityIcon = loadImage(aDisplay, resourceDir + iconFilename, false); |
1076 iSecurityIcon = loadImage(aDisplay, resourceDir + iconFilename, false); |
1166 return result; |
1163 return result; |
1167 } |
1164 } |
1168 try |
1165 try |
1169 { |
1166 { |
1170 long startTime = System.currentTimeMillis(); |
1167 long startTime = System.currentTimeMillis(); |
1171 ImageData[] imageDatas = new ImageLoader().load(aInputStream); |
1168 Image image = new Image(aDisplay, aInputStream); |
1172 ImageData imageData = imageDatas[0]; |
1169 ImageData imageData = image.getImageData(); |
1173 if (aScaleImage) |
1170 if (aScaleImage) |
1174 { |
1171 { |
1175 Point bestSize = getBestImageSize( |
1172 Point bestSize = getBestImageSize( |
1176 imageData.width, imageData.height); |
1173 imageData.width, imageData.height); |
1177 if (bestSize.x != imageData.width || |
1174 if (bestSize.x != imageData.width || |
1178 bestSize.y != imageData.height) |
1175 bestSize.y != imageData.height) |
1179 { |
1176 { |
|
1177 Point oldSize = |
|
1178 new Point(imageData.width, imageData.height); |
1180 imageData = imageData.scaledTo(bestSize.x, bestSize.y); |
1179 imageData = imageData.scaledTo(bestSize.x, bestSize.y); |
1181 log("Image " + aImageName + " scaled from " + |
1180 log("Image " + aImageName + " scaled from " + |
1182 imageDatas[0].width + "x" + imageDatas[0].height + |
1181 oldSize.x + "x" + oldSize.y + " to " + |
1183 " to " + bestSize.x + "x" + bestSize.y); |
1182 bestSize.x + "x" + bestSize.y); |
1184 } |
1183 } |
1185 } |
1184 } |
1186 result = new Image(aDisplay, imageData); |
1185 result = new Image(aDisplay, imageData); |
1187 long endTime = System.currentTimeMillis(); |
1186 long endTime = System.currentTimeMillis(); |
1188 log("Loaded image " + aImageName + " (load time " + |
1187 log("Loaded image " + aImageName + " (load time " + |
1200 /** |
1199 /** |
1201 * Determines the best image size for the image of given size. |
1200 * Determines the best image size for the image of given size. |
1202 */ |
1201 */ |
1203 private static Point getBestImageSize(int aWidth, int aHeight) |
1202 private static Point getBestImageSize(int aWidth, int aHeight) |
1204 { |
1203 { |
1205 final int MAX_WIDTH = iBestIconSize.x; |
1204 final int MAX_WIDTH = (iBestIconSize == null? 50: iBestIconSize.x); |
1206 final int MAX_HEIGHT = iBestIconSize.y; |
1205 final int MAX_HEIGHT = (iBestIconSize == null? 50: iBestIconSize.y); |
1207 Point result = new Point(aWidth, aHeight); |
1206 Point result = new Point(aWidth, aHeight); |
1208 if (result.x > MAX_WIDTH || result.y > MAX_HEIGHT) |
1207 if (result.x > MAX_WIDTH || result.y > MAX_HEIGHT) |
1209 { |
1208 { |
1210 if (result.x >= MAX_WIDTH) |
1209 if (result.x >= MAX_WIDTH) |
1211 { |
1210 { |
1329 |
1328 |
1330 ViewBase getActiveView() |
1329 ViewBase getActiveView() |
1331 { |
1330 { |
1332 return iActiveView; |
1331 return iActiveView; |
1333 } |
1332 } |
|
1333 |
|
1334 /** |
|
1335 * Loads JavaInstaller UI stylesheet. |
|
1336 */ |
|
1337 void loadCss() |
|
1338 { |
|
1339 String cssFilename = "javaapplicationinstaller.css"; |
|
1340 String cssPath = null; |
|
1341 try |
|
1342 { |
|
1343 if (iCssEngine != null) |
|
1344 { |
|
1345 boolean loaded = false; |
|
1346 String resourceDir = ResourceUtil.getResourceDir(0); |
|
1347 for (int i = 1; !loaded && resourceDir != null; i++) |
|
1348 { |
|
1349 cssPath = resourceDir + cssFilename; |
|
1350 FileUtility cssFile = new FileUtility(cssPath); |
|
1351 if (cssFile.exists()) |
|
1352 { |
|
1353 iCssEngine.loadCSS(cssPath); |
|
1354 log("CSS loaded from " + cssPath); |
|
1355 break; |
|
1356 } |
|
1357 resourceDir = ResourceUtil.getResourceDir(i); |
|
1358 } |
|
1359 } |
|
1360 } |
|
1361 catch (Throwable t) |
|
1362 { |
|
1363 logError("Loading CSS from " + cssPath + " failed", t); |
|
1364 } |
|
1365 } |
1334 } |
1366 } |