javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/InstallerUiEswt.java
changeset 79 2f468c1958d0
parent 76 4ad59aaee882
equal deleted inserted replaced
76:4ad59aaee882 79:2f468c1958d0
    72 
    72 
    73     private BaseCSSEngine iCssEngine = null;
    73     private BaseCSSEngine iCssEngine = null;
    74     private Shell iParent = null;
    74     private Shell iParent = null;
    75     private Shell iDialog = null;
    75     private Shell iDialog = null;
    76     private ProgressView iProgressView = null;
    76     private ProgressView iProgressView = null;
       
    77     private ProgressView iPreparingInstallationView = null;
    77     private ProgressView iDlProgressView = null;
    78     private ProgressView iDlProgressView = null;
    78     private ProgressView iOcspProgressView = null;
    79     private ProgressView iOcspProgressView = null;
    79     private InstallConfirmationView iInstallConfirmationView = null;
    80     private InstallConfirmationView iInstallConfirmationView = null;
    80     private PermissionConfirmationView iPermissionConfirmationView = null;
    81     private PermissionConfirmationView iPermissionConfirmationView = null;
    81     private UsernamePasswordView iUsernamePasswordView = null;
    82     private UsernamePasswordView iUsernamePasswordView = null;
   108     private CertificateDetailsView iCertificateDetailsView = null;
   109     private CertificateDetailsView iCertificateDetailsView = null;
   109 
   110 
   110     /** Hashtable for storing the loaded icons. */
   111     /** Hashtable for storing the loaded icons. */
   111     private static Hashtable iImageTable = null;
   112     private static Hashtable iImageTable = null;
   112     /** Best size for application icon. */
   113     /** Best size for application icon. */
   113     private static Point iBestIconSize = null;
   114     private static Point iBestImageSize = null;
   114 
   115 
   115     /** Default shell bounds. */
   116     /** Default shell bounds. */
   116     private Rectangle iDefaultShellBounds = null;
   117     private Rectangle iDefaultShellBounds = null;
   117     private Rectangle iDefaultShellClientBounds = null;
   118     private Rectangle iDefaultShellClientBounds = null;
   118 
   119 
   171             iDialog = new Shell(iParent, SHELL_STYLE);
   172             iDialog = new Shell(iParent, SHELL_STYLE);
   172             iDefaultShellBounds = iDialog.internal_getDefaultBounds();
   173             iDefaultShellBounds = iDialog.internal_getDefaultBounds();
   173             iDefaultShellClientBounds = iDialog.getClientArea();
   174             iDefaultShellClientBounds = iDialog.getClientArea();
   174             iBoldFont = getBoldFont();
   175             iBoldFont = getBoldFont();
   175             StartUpTrace.doTrace("InstallerUiEswt shell created");
   176             StartUpTrace.doTrace("InstallerUiEswt shell created");
   176             iProgressView = new ProgressView(this, iDialog, getTitle());
   177             iProgressView = new ProgressView(this, iDialog, getTitle(), false, true);
       
   178             //createPreparingInstallationView();
   177 
   179 
   178             iParent.addControlListener(new CListener(this));
   180             iParent.addControlListener(new CListener(this));
   179             log("InstallerUiEswt CListener added");
   181             log("InstallerUiEswt CListener added");
   180 
   182 
   181             display.addListener(SWT.Dispose, new Listener()
   183             display.addListener(SWT.Dispose, new Listener()
   186                     // Prevent UI from being automatically disposed.
   188                     // Prevent UI from being automatically disposed.
   187                     //aEvent.doit = false;
   189                     //aEvent.doit = false;
   188                 }
   190                 }
   189             });
   191             });
   190 
   192 
   191             // Initialize best icon size.
   193             // Initialize best image size.
   192             //iBestIconSize = new Point(
   194             iBestImageSize = new Point(
   193             //    display.getBestImageWidth(DisplayExtension.ALERT),
   195                 DisplayExtension.getBestImageWidth(DisplayExtension.LIST_ELEMENT),
   194             //    display.getBestImageHeight(DisplayExtension.ALERT));
   196                 DisplayExtension.getBestImageHeight(DisplayExtension.LIST_ELEMENT));
   195             //log("Best icon size: " + iBestIconSize);
   197             log("Best image size: " + iBestImageSize);
   196 
   198 
   197             synchronized (iInitWaitObject)
   199             synchronized (iInitWaitObject)
   198             {
   200             {
   199                 // Notify that UI is now ready.
   201                 // Notify that UI is now ready.
   200                 iInitWaitObject.notify();
   202                 iInitWaitObject.notify();
   254      * Cancels all confirmation views that are currently displayed.
   256      * Cancels all confirmation views that are currently displayed.
   255      */
   257      */
   256     public void cancelConfirmations()
   258     public void cancelConfirmations()
   257     {
   259     {
   258         super.cancelConfirmations();
   260         super.cancelConfirmations();
       
   261         if (iPreparingInstallationView != null &&
       
   262             !iPreparingInstallationView.isDisposed())
       
   263         {
       
   264             iPreparingInstallationView.dispose();
       
   265             iPreparingInstallationView = null;
       
   266         }
   259         if (iCertificateDetailsView != null)
   267         if (iCertificateDetailsView != null)
   260         {
   268         {
   261             iCertificateDetailsView.confirmCancel();
   269             iCertificateDetailsView.confirmCancel();
   262         }
   270         }
   263         if (iInstallConfirmationView != null)
   271         if (iInstallConfirmationView != null)
   313         if (!isUiReady())
   321         if (!isUiReady())
   314         {
   322         {
   315             // If UI is not ready by the time confirmation is requested,
   323             // If UI is not ready by the time confirmation is requested,
   316             // throw an exception.
   324             // throw an exception.
   317             throw new RuntimeException("JavaInstallerUi not ready");
   325             throw new RuntimeException("JavaInstallerUi not ready");
       
   326         }
       
   327 
       
   328         if (iPreparingInstallationView != null &&
       
   329             !iPreparingInstallationView.isDisposed())
       
   330         {
       
   331             iPreparingInstallationView.setVisible(false);
       
   332             iPreparingInstallationView.dispose();
       
   333             iPreparingInstallationView = null;
   318         }
   334         }
   319 
   335 
   320         boolean result = true;
   336         boolean result = true;
   321         if (result)
   337         if (result)
   322         {
   338         {
   491                 iParent.getDisplay().syncExec(new Runnable()
   507                 iParent.getDisplay().syncExec(new Runnable()
   492                 {
   508                 {
   493                     public void run()
   509                     public void run()
   494                     {
   510                     {
   495                         iProgressView = new ProgressView(
   511                         iProgressView = new ProgressView(
   496                             self, iDialog, getTitle());
   512                             self, iDialog, getTitle(), false, true);
   497                     }
   513                     }
   498                 });
   514                 });
   499                 iProgressView.setVisible(true);
   515                 iProgressView.setVisible(true);
   500             }
   516             }
   501             if (iDisplayProgress && !iProgressBarUpdateTraced)
   517             if (iDisplayProgress && !iProgressBarUpdateTraced)
   606                 public void run()
   622                 public void run()
   607                 {
   623                 {
   608                     iDlProgressView = new ProgressView(
   624                     iDlProgressView = new ProgressView(
   609                         self, iDialog,
   625                         self, iDialog,
   610                         InstallerUiTexts.get(InstallerUiTexts.DOWNLOADING),
   626                         InstallerUiTexts.get(InstallerUiTexts.DOWNLOADING),
   611                         indeterminate);
   627                         indeterminate, true);
   612                 }
   628                 }
   613             });
   629             });
   614             iDlProgressView.addCancelCommand();
       
   615         }
   630         }
   616 
   631 
   617         synchronized (iProgressSyncObject)
   632         synchronized (iProgressSyncObject)
   618         {
   633         {
   619             if (iDisplayProgress && !iDlProgressView.isVisible() &&
   634             if (iDisplayProgress && !iDlProgressView.isVisible() &&
   686                     public void run()
   701                     public void run()
   687                     {
   702                     {
   688                         iOcspProgressView = new ProgressView(
   703                         iOcspProgressView = new ProgressView(
   689                             self, iDialog,
   704                             self, iDialog,
   690                             InstallerUiTexts.get(InstallerUiTexts.OCSP_CHECK_PROGRESS),
   705                             InstallerUiTexts.get(InstallerUiTexts.OCSP_CHECK_PROGRESS),
   691                             true);
   706                             true, true);
   692                     }
   707                     }
   693                 });
   708                 });
   694                 iOcspProgressView.addCancelCommand();
       
   695             }
   709             }
   696             if (iOcspProgressView != null)
   710             if (iOcspProgressView != null)
   697             {
   711             {
   698                 if (!iOcspProgressView.isVisible() &&
   712                 if (!iOcspProgressView.isVisible() &&
   699                     iCertificateDetailsView == null)
   713                     iCertificateDetailsView == null)
  1206             return result;
  1220             return result;
  1207         }
  1221         }
  1208         try
  1222         try
  1209         {
  1223         {
  1210             long startTime = System.currentTimeMillis();
  1224             long startTime = System.currentTimeMillis();
       
  1225             aDisplay.setData("org.eclipse.swt.internal.image.loadSize",
       
  1226                              iBestImageSize);
  1211             Image image = new Image(aDisplay, aInputStream);
  1227             Image image = new Image(aDisplay, aInputStream);
  1212             ImageData imageData = image.getImageData();
       
  1213             if (aScaleImage)
  1228             if (aScaleImage)
  1214             {
  1229             {
  1215                 Point bestSize = getBestImageSize(
  1230                 ImageData imageData = image.getImageData();
  1216                     imageData.width, imageData.height);
  1231                 if (iBestImageSize.x != imageData.width ||
  1217                 if (bestSize.x != imageData.width ||
  1232                         iBestImageSize.y != imageData.height)
  1218                         bestSize.y != imageData.height)
       
  1219                 {
  1233                 {
  1220                     Point oldSize =
  1234                     Point oldSize =
  1221                         new Point(imageData.width, imageData.height);
  1235                         new Point(imageData.width, imageData.height);
  1222                     imageData = imageData.scaledTo(bestSize.x, bestSize.y);
  1236                     imageData = imageData.scaledTo(iBestImageSize.x, iBestImageSize.y);
  1223                     log("Image " + aImageName + " scaled from " +
  1237                     log("Image " + aImageName + " scaled from " +
  1224                         oldSize.x + "x" + oldSize.y + " to " +
  1238                         oldSize.x + "x" + oldSize.y + " to " +
  1225                         bestSize.x + "x" + bestSize.y);
  1239                         iBestImageSize.x + "x" + iBestImageSize.y);
  1226                 }
  1240                     image = new Image(aDisplay, imageData);
  1227             }
  1241                 }
  1228             result = new Image(aDisplay, imageData);
  1242             }
       
  1243             result = image;
  1229             long endTime = System.currentTimeMillis();
  1244             long endTime = System.currentTimeMillis();
  1230             log("Loaded image " + aImageName + " (load time " +
  1245             log("Loaded image " + aImageName + " (load time " +
  1231                 (endTime - startTime) + " ms)");
  1246                 (endTime - startTime) + " ms)");
  1232             iImageTable.put(aImageName, result);
  1247             iImageTable.put(aImageName, result);
  1233         }
  1248         }
  1237             //logError("Exception while loading image " + aImageName, t);
  1252             //logError("Exception while loading image " + aImageName, t);
  1238         }
  1253         }
  1239         return result;
  1254         return result;
  1240     }
  1255     }
  1241 
  1256 
  1242     /**
       
  1243      * Determines the best image size for the image of given size.
       
  1244      */
       
  1245     private static Point getBestImageSize(int aWidth, int aHeight)
       
  1246     {
       
  1247         final int MAX_WIDTH = (iBestIconSize == null? 50: iBestIconSize.x);
       
  1248         final int MAX_HEIGHT = (iBestIconSize == null? 50: iBestIconSize.y);
       
  1249         Point result = new Point(aWidth, aHeight);
       
  1250         if (result.x > MAX_WIDTH || result.y > MAX_HEIGHT)
       
  1251         {
       
  1252             if (result.x >= MAX_WIDTH)
       
  1253             {
       
  1254                 result.x = MAX_WIDTH;
       
  1255                 result.y = MAX_WIDTH * aHeight / aWidth;
       
  1256             }
       
  1257             if (result.y >= MAX_HEIGHT)
       
  1258             {
       
  1259                 result.x = MAX_HEIGHT * aWidth / aHeight;
       
  1260                 result.y = MAX_HEIGHT;
       
  1261             }
       
  1262         }
       
  1263         return result;
       
  1264     }
       
  1265 
       
  1266     /** Returns true if UI has been created and can be used. */
  1257     /** Returns true if UI has been created and can be used. */
  1267     protected boolean isUiReady()
  1258     protected boolean isUiReady()
  1268     {
  1259     {
  1269         if (iProgressView == null)
  1260         if (iProgressView == null)
  1270         {
  1261         {
  1327         }
  1318         }
  1328 
  1319 
  1329         public void controlResized(ControlEvent aEvent)
  1320         public void controlResized(ControlEvent aEvent)
  1330         {
  1321         {
  1331             iInstallerUi.screenOrientationChanged();
  1322             iInstallerUi.screenOrientationChanged();
       
  1323         }
       
  1324     }
       
  1325 
       
  1326     /**
       
  1327      * Creates preparing installation view.
       
  1328      */
       
  1329     private void createPreparingInstallationView()
       
  1330     {
       
  1331         if (iPreparingInstallationView == null)
       
  1332         {
       
  1333             final InstallerUiEswt self = this;
       
  1334             iParent.getDisplay().syncExec(new Runnable()
       
  1335             {
       
  1336                 public void run()
       
  1337                 {
       
  1338                     iPreparingInstallationView = new ProgressView(
       
  1339                         self, iDialog, "Preparing installation", true, false);
       
  1340                     iPreparingInstallationView.setVisible(true);
       
  1341                 }
       
  1342             });
  1332         }
  1343         }
  1333     }
  1344     }
  1334 
  1345 
  1335     Rectangle getDefaultShellBounds()
  1346     Rectangle getDefaultShellBounds()
  1336     {
  1347     {