javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/InstallerUiEswt.java
branchRCL_3
changeset 60 6c158198356e
parent 25 9ac0a0a7da70
child 77 7cee158cb8cd
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
    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;
    36 import com.nokia.mj.impl.utils.exception.InstallerExceptionBase;
    35 import com.nokia.mj.impl.utils.exception.InstallerExceptionBase;
    37 
    36 
    38 import java.io.InputStream;
    37 import java.io.InputStream;
    39 import java.io.IOException;
    38 import java.io.IOException;
       
    39 import java.util.Enumeration;
    40 import java.util.Hashtable;
    40 import java.util.Hashtable;
    41 
    41 
    42 import org.eclipse.ercp.swt.midp.UIThreadSupport;
    42 import org.eclipse.ercp.swt.midp.UIThreadSupport;
    43 import org.eclipse.swt.SWT;
    43 import org.eclipse.swt.SWT;
    44 import org.eclipse.swt.events.ControlEvent;
    44 import org.eclipse.swt.events.ControlEvent;
    45 import org.eclipse.swt.events.ControlListener;
    45 import org.eclipse.swt.events.ControlListener;
    46 import org.eclipse.swt.graphics.Font;
    46 import org.eclipse.swt.graphics.Font;
    47 import org.eclipse.swt.graphics.FontData;
    47 import org.eclipse.swt.graphics.FontData;
    48 import org.eclipse.swt.graphics.Image;
    48 import org.eclipse.swt.graphics.Image;
    49 import org.eclipse.swt.graphics.ImageData;
    49 import org.eclipse.swt.graphics.ImageData;
    50 import org.eclipse.swt.graphics.ImageLoader;
       
    51 import org.eclipse.swt.graphics.Point;
    50 import org.eclipse.swt.graphics.Point;
    52 import org.eclipse.swt.graphics.Rectangle;
    51 import org.eclipse.swt.graphics.Rectangle;
    53 import org.eclipse.swt.internal.extension.DisplayExtension;
    52 import org.eclipse.swt.internal.extension.DisplayExtension;
       
    53 import org.eclipse.swt.internal.qt.BaseCSSEngine;
    54 import org.eclipse.swt.widgets.Display;
    54 import org.eclipse.swt.widgets.Display;
    55 import org.eclipse.swt.widgets.Event;
    55 import org.eclipse.swt.widgets.Event;
    56 import org.eclipse.swt.widgets.Composite;
    56 import org.eclipse.swt.widgets.Composite;
    57 import org.eclipse.swt.widgets.Listener;
    57 import org.eclipse.swt.widgets.Listener;
    58 import org.eclipse.swt.widgets.Shell;
    58 import org.eclipse.swt.widgets.Shell;
    60 /**
    60 /**
    61  * JavaInstaller eSWT UI.
    61  * JavaInstaller eSWT UI.
    62  */
    62  */
    63 public class InstallerUiEswt extends InstallerUi
    63 public class InstallerUiEswt extends InstallerUi
    64 {
    64 {
       
    65     /** Disable UI temporarily. */
       
    66     private static final boolean DISABLE_UI =
       
    67         (System.getProperty("com.nokia.mj.impl.installer.ui.disableui")
       
    68          == null? false: true);
    65     /** Default shell style. */
    69     /** Default shell style. */
    66     private static final int SHELL_STYLE =
    70     private static final int SHELL_STYLE =
    67         SWT.BORDER | SWT.APPLICATION_MODAL | SWT.ON_TOP;
    71         SWT.BORDER | SWT.APPLICATION_MODAL | SWT.ON_TOP;
    68 
    72 
       
    73     private BaseCSSEngine iCssEngine = null;
    69     private Shell iParent = null;
    74     private Shell iParent = null;
    70     private Shell iDialog = null;
    75     private Shell iDialog = null;
    71     private ProgressView iProgressView = null;
    76     private ProgressView iProgressView = null;
    72     private ProgressView iDlProgressView = null;
    77     private ProgressView iDlProgressView = null;
    73     private ProgressView iOcspProgressView = null;
    78     private ProgressView iOcspProgressView = null;
    96     private Image iSecurityIcon = null;
   101     private Image iSecurityIcon = null;
    97     /** Flag telling if progress bar should be displayed. */
   102     /** Flag telling if progress bar should be displayed. */
    98     private boolean iDisplayProgress = false;
   103     private boolean iDisplayProgress = false;
    99     /** Flag telling if the first progress bar update has been traced. */
   104     /** Flag telling if the first progress bar update has been traced. */
   100     private boolean iProgressBarUpdateTraced = false;
   105     private boolean iProgressBarUpdateTraced = false;
   101     /** Flag telling if MinimalUi should be used if UI creation fails. */
       
   102     private boolean iMinimalUiEnabled = true;
       
   103 
   106 
   104     /** Hashtable for storing the loaded icons. */
   107     /** Hashtable for storing the loaded icons. */
   105     private static Hashtable iImageTable = null;
   108     private static Hashtable iImageTable = null;
   106     /** Best size for application icon. */
   109     /** Best size for application icon. */
   107     private static Point iBestIconSize = null;
   110     private static Point iBestIconSize = null;
   133         StartUpTrace.doTrace("InstallerUiEswt init");
   136         StartUpTrace.doTrace("InstallerUiEswt init");
   134         InstallerRuntimeUi.init(this);
   137         InstallerRuntimeUi.init(this);
   135         // Create a hashtable for icons.
   138         // Create a hashtable for icons.
   136         iImageTable = new Hashtable();
   139         iImageTable = new Hashtable();
   137         // Create a new thread to be the UI main thread.
   140         // Create a new thread to be the UI main thread.
   138         iUiThreadExists = true;
       
   139         UIThreadSupport.startInUIThread(new Runnable()
   141         UIThreadSupport.startInUIThread(new Runnable()
   140         {
   142         {
   141             public void run()
   143             public void run()
   142             {
   144             {
   143                 uiMain();
   145                 uiMain();
   152      * This method is executed in UI main thread.
   154      * This method is executed in UI main thread.
   153      */
   155      */
   154     private void uiMain()
   156     private void uiMain()
   155     {
   157     {
   156         log("uiMain: thread started");
   158         log("uiMain: thread started");
       
   159         iUiThreadExists = true;
   157         try
   160         try
   158         {
   161         {
   159             // Create the necessary views.
   162             // Create the necessary views.
   160             DisplayExtension display = new DisplayExtension();
   163             DisplayExtension display = new DisplayExtension();
   161             StartUpTrace.doTrace("InstallerUiEswt display created");
   164             StartUpTrace.doTrace("InstallerUiEswt display created");
   162             display.setAppName(""); // Remove display title.
   165             display.setAppName(""); // Remove display title.
       
   166             iCssEngine = new BaseCSSEngine(display);
   163             iParent = new Shell(display);
   167             iParent = new Shell(display);
   164             iDialog = new Shell(iParent, SHELL_STYLE);
   168             iDialog = new Shell(iParent, SHELL_STYLE);
   165             iDefaultShellBounds = iDialog.internal_getDefaultBounds();
   169             iDefaultShellBounds = iDialog.internal_getDefaultBounds();
   166             iDefaultShellClientBounds = iDialog.getClientArea();
   170             iDefaultShellClientBounds = iDialog.getClientArea();
   167             iBoldFont = getBoldFont();
   171             iBoldFont = getBoldFont();
   180                     //aEvent.doit = false;
   184                     //aEvent.doit = false;
   181                 }
   185                 }
   182             });
   186             });
   183 
   187 
   184             // Initialize best icon size.
   188             // Initialize best icon size.
   185             iBestIconSize = new Point(
   189             //iBestIconSize = new Point(
   186                 display.getBestImageWidth(DisplayExtension.ALERT),
   190             //    display.getBestImageWidth(DisplayExtension.ALERT),
   187                 display.getBestImageHeight(DisplayExtension.ALERT));
   191             //    display.getBestImageHeight(DisplayExtension.ALERT));
   188             log("Best icon size: " + iBestIconSize);
   192             //log("Best icon size: " + iBestIconSize);
   189 
   193 
   190             synchronized (iInitWaitObject)
   194             synchronized (iInitWaitObject)
   191             {
   195             {
   192                 // Notify that UI is now ready.
   196                 // Notify that UI is now ready.
   193                 iInitWaitObject.notify();
   197                 iInitWaitObject.notify();
   214                 if (!display.readAndDispatch())
   218                 if (!display.readAndDispatch())
   215                 {
   219                 {
   216                     display.sleep();
   220                     display.sleep();
   217                 }
   221                 }
   218             }
   222             }
   219             if (iBoldFont != null && !iBoldFont.isDisposed())
   223             disposeResources();
   220             {
       
   221                 iBoldFont.dispose();
       
   222             }
       
   223             display.dispose();
   224             display.dispose();
   224             log("uiMain: display disposed");
   225             log("uiMain: display disposed");
   225             synchronized (iExitWaitObject)
   226             synchronized (iExitWaitObject)
   226             {
   227             {
   227                 // Notify that UI main thread has been terminated.
   228                 // Notify that UI main thread has been terminated.
   300     public boolean confirm(InstallInfo aInstallInfo)
   301     public boolean confirm(InstallInfo aInstallInfo)
   301     {
   302     {
   302         super.confirm(aInstallInfo);
   303         super.confirm(aInstallInfo);
   303 
   304 
   304         waitForUi();
   305         waitForUi();
       
   306         if (!isUiReady())
       
   307         {
       
   308             // If UI is not ready by the time confirmation is requested,
       
   309             // throw an exception.
       
   310             throw new RuntimeException("JavaInstallerUi not ready");
       
   311         }
       
   312 
   305         boolean result = true;
   313         boolean result = true;
   306         if (!isUiReady())
       
   307         {
       
   308             result = false;
       
   309             if (iMinimalUiEnabled)
       
   310             {
       
   311                 result = MinimalUi.confirmStatic(aInstallInfo);
       
   312                 log("MinimalUi installation confirmation returns " + result);
       
   313                 return result;
       
   314             }
       
   315             else
       
   316             {
       
   317                 // If UI is not ready by the time confirmation is requested,
       
   318                 // throw an exception.
       
   319                 throw new RuntimeException("JavaInstallerUi not ready");
       
   320             }
       
   321         }
       
   322 
       
   323         if (result)
   314         if (result)
   324         {
   315         {
   325             StartUpTrace.doTrace("InstallerUiEswt confirm");
   316             StartUpTrace.doTrace("InstallerUiEswt confirm");
   326             if (iInstallConfirmationView == null)
   317             if (iInstallConfirmationView == null)
   327             {
   318             {
   461      * @param aProgress progress value between 0 and 100
   452      * @param aProgress progress value between 0 and 100
   462      */
   453      */
   463     public void updateProgress(int aProgress)
   454     public void updateProgress(int aProgress)
   464     {
   455     {
   465         super.updateProgress(aProgress);
   456         super.updateProgress(aProgress);
       
   457         if (DISABLE_UI) return; // Disable UI temporarily.
   466         if (!isUiReady())
   458         if (!isUiReady())
   467         {
   459         {
   468             return;
   460             return;
   469         }
   461         }
   470         // UI is created asynchronously, so it might be that
   462         // UI is created asynchronously, so it might be that
   471         // UI was not yet ready when started() was called.
   463         // UI was not yet ready when started() was called.
   472         // Ensure that iProgressView has been opened before
   464         // Ensure that iProgressView has been opened before
   473         // updating it.
   465         // updating it.
   474         synchronized (iProgressSyncObject)
   466         synchronized (iProgressSyncObject)
   475         {
   467         {
       
   468             if (iDlProgressView != null && iDlProgressView.isVisible())
       
   469             {
       
   470                 // If download progress is being displayed,
       
   471                 // do not display installation progress.
       
   472                 return;
       
   473             }
   476             if (iDisplayProgress && !iProgressView.isVisible())
   474             if (iDisplayProgress && !iProgressView.isVisible())
   477             {
   475             {
   478                 // Re-create iProgressView here so that it gets
   476                 // Re-create iProgressView here so that it gets
   479                 // application info that was set when confirm()
   477                 // application info that was set when confirm()
   480                 // was called.
   478                 // was called.
   507      * This method must return quickly.
   505      * This method must return quickly.
   508      */
   506      */
   509     public void ended()
   507     public void ended()
   510     {
   508     {
   511         super.ended();
   509         super.ended();
       
   510         if (DISABLE_UI) return; // Disable UI temporarily.
   512         if (!isUiReady())
   511         if (!isUiReady())
   513         {
   512         {
   514             return;
   513             return;
   515         }
   514         }
   516         Display display = iParent.getDisplay();
   515         Display display = iParent.getDisplay();
   551      * @param aDownloadInfo information about download
   550      * @param aDownloadInfo information about download
   552      */
   551      */
   553     public void started(DownloadInfo aDownloadInfo)
   552     public void started(DownloadInfo aDownloadInfo)
   554     {
   553     {
   555         super.started(aDownloadInfo);
   554         super.started(aDownloadInfo);
       
   555         if (DISABLE_UI) return; // Disable UI temporarily.
   556         if (!isUiReady())
   556         if (!isUiReady())
   557         {
   557         {
   558             return;
   558             return;
   559         }
   559         }
   560         // Ensure that download progress bar is displayed and
   560         // Ensure that download progress bar is displayed and
   577      * @param aDownloadInfo information about download
   577      * @param aDownloadInfo information about download
   578      */
   578      */
   579     public void updateProgress(DownloadInfo aDownloadInfo)
   579     public void updateProgress(DownloadInfo aDownloadInfo)
   580     {
   580     {
   581         super.updateProgress(aDownloadInfo);
   581         super.updateProgress(aDownloadInfo);
       
   582         if (DISABLE_UI) return; // Disable UI temporarily.
   582         if (!isUiReady())
   583         if (!isUiReady())
   583         {
   584         {
   584             return;
   585             return;
   585         }
   586         }
   586 
   587 
   626      * @param aDownloadInfo information about download
   627      * @param aDownloadInfo information about download
   627      */
   628      */
   628     public void ended(DownloadInfo aDownloadInfo)
   629     public void ended(DownloadInfo aDownloadInfo)
   629     {
   630     {
   630         super.ended(aDownloadInfo);
   631         super.ended(aDownloadInfo);
       
   632         if (DISABLE_UI) return; // Disable UI temporarily.
   631         if (!isUiReady())
   633         if (!isUiReady())
   632         {
   634         {
   633             return;
   635             return;
   634         }
   636         }
   635         if (iDlProgressView != null && !iDlProgressView.isDisposed())
   637         if (iDlProgressView != null && !iDlProgressView.isDisposed())
   652      * @param aOn true when OCSP is started, false when OCSP is stopped
   654      * @param aOn true when OCSP is started, false when OCSP is stopped
   653      */
   655      */
   654     public void setOcspIndicator(boolean aOn)
   656     public void setOcspIndicator(boolean aOn)
   655     {
   657     {
   656         super.setOcspIndicator(aOn);
   658         super.setOcspIndicator(aOn);
       
   659         if (DISABLE_UI) return; // Disable UI temporarily.
   657         waitForUi();
   660         waitForUi();
   658         if (!isUiReady())
   661         if (!isUiReady())
   659         {
   662         {
   660             log("UI not ready, could not set OCSP indicator to " + aOn);
   663             log("UI not ready, could not set OCSP indicator to " + aOn);
   661             return;
   664             return;
   667                 final InstallerUiEswt self = this;
   670                 final InstallerUiEswt self = this;
   668                 iParent.getDisplay().syncExec(new Runnable()
   671                 iParent.getDisplay().syncExec(new Runnable()
   669                 {
   672                 {
   670                     public void run()
   673                     public void run()
   671                     {
   674                     {
   672                         iOcspProgressView = new ProgressView(self, iDialog,
   675                         iOcspProgressView = new ProgressView(
   673                                                              InstallerUiTexts.get(InstallerUiTexts.OCSP_CHECK_PROGRESS),
   676                             self, iDialog,
   674                                                              true);
   677                             InstallerUiTexts.get(InstallerUiTexts.OCSP_CHECK_PROGRESS),
       
   678                             true);
   675                     }
   679                     }
   676                 });
   680                 });
   677                 iOcspProgressView.addCancelCommand();
   681                 iOcspProgressView.addCancelCommand();
   678             }
   682             }
   679             if (iOcspProgressView != null)
   683             if (iOcspProgressView != null)
   752      * @param aInstallerException exception indicating the error reason
   756      * @param aInstallerException exception indicating the error reason
   753      */
   757      */
   754     public void error(InstallerExceptionBase aInstallerException)
   758     public void error(InstallerExceptionBase aInstallerException)
   755     {
   759     {
   756         super.error(aInstallerException);
   760         super.error(aInstallerException);
       
   761         if (DISABLE_UI) return; // Disable UI temporarily.
   757 
   762 
   758         waitForUi();
   763         waitForUi();
   759         if (!isUiReady()) {
   764         if (!isUiReady()) {
   760             return;
   765             return;
   761         }
   766         }
   795             result = iErrorDetailsView.error(aInstallerException);
   800             result = iErrorDetailsView.error(aInstallerException);
   796             iErrorDetailsView.dispose();
   801             iErrorDetailsView.dispose();
   797             iErrorDetailsView = null;
   802             iErrorDetailsView = null;
   798         }
   803         }
   799     }
   804     }
   800 
       
   801     /**
       
   802      * Notify user that an error has occurred using RuntimeUI.
       
   803      *
       
   804      * @param aInstallerException exception indicating the error reason
       
   805      */
       
   806     /*
       
   807     private void showRuntimeUiError(InstallerExceptionBase aInstallerException)
       
   808     {
       
   809         boolean identified = false;
       
   810         if (iInstallInfo != null)
       
   811         {
       
   812             if (iInstallInfo.getCertificates() != null)
       
   813             {
       
   814                 identified = true;
       
   815             }
       
   816         }
       
   817         else if (iUninstallInfo != null)
       
   818         {
       
   819             if (iUninstallInfo.getCertificates() != null)
       
   820             {
       
   821                 identified = true;
       
   822             }
       
   823         }
       
   824         String tmpTitle = InstallerUiTexts.get(InstallerUiTexts.INSTALL_FAILED);
       
   825 
       
   826         // Ensure that no confirmations are being displayed.
       
   827         cancelConfirmations();
       
   828         // Hide progress view before displaying error message.
       
   829         if (iProgressView != null)
       
   830         {
       
   831             iProgressView.setVisible(false);
       
   832         }
       
   833         // Use RuntimeUi to display uninstallation error message.
       
   834         RuntimeUi runtimeUi = RuntimeUiFactory.getRuntimeUi(identified);
       
   835         runtimeUi.error(tmpTitle, aInstallerException);
       
   836         runtimeUi.destroy();
       
   837     }
       
   838     */
       
   839 
   805 
   840     /**
   806     /**
   841      * Seeks confirmation from the user.
   807      * Seeks confirmation from the user.
   842      *
   808      *
   843      * @param aAppName     the name of the application on behalf of which the
   809      * @param aAppName     the name of the application on behalf of which the
   848      * @return             true if the user has answered, false if the user has
   814      * @return             true if the user has answered, false if the user has
   849      *                     canceled the confirmation
   815      *                     canceled the confirmation
   850      */
   816      */
   851     public boolean confirm(String aAppName, ConfirmData aConfirmData)
   817     public boolean confirm(String aAppName, ConfirmData aConfirmData)
   852     {
   818     {
       
   819         if (DISABLE_UI) return true; // Disable UI temporarily.
   853         waitForUi();
   820         waitForUi();
   854         if (!isUiReady()) {
   821         if (!isUiReady()) {
   855             return true;
   822             return true;
   856         }
   823         }
   857 
   824 
   886      * and second being password. If username and password
   853      * and second being password. If username and password
   887      * cannot be obtained, this method returns null.
   854      * cannot be obtained, this method returns null.
   888      */
   855      */
   889     public String[] getUsernamePassword(String aUrl)
   856     public String[] getUsernamePassword(String aUrl)
   890     {
   857     {
       
   858         if (DISABLE_UI) return new String[] { "", "" }; // Disable UI temporarily.
   891         waitForUi();
   859         waitForUi();
   892         if (!isUiReady())
   860         if (!isUiReady())
   893         {
   861         {
   894             return null;
   862             return null;
   895         }
   863         }
   941      * @return true if the user has chosen to launch the application,
   909      * @return true if the user has chosen to launch the application,
   942      * false if the user has canceled the query
   910      * false if the user has canceled the query
   943      */
   911      */
   944     public boolean launchAppQuery(LaunchAppInfo aLaunchAppInfo)
   912     public boolean launchAppQuery(LaunchAppInfo aLaunchAppInfo)
   945     {
   913     {
       
   914         if (DISABLE_UI) return false; // Disable UI temporarily.
   946         waitForUi();
   915         waitForUi();
   947         if (!isUiReady() || iConfirmationsCanceled || getInstallInfo() == null)
   916         if (!isUiReady() || iConfirmationsCanceled || getInstallInfo() == null)
   948         {
   917         {
   949             // Either UI is not yet ready, or user has cancelled
   918             // Either UI is not yet ready, or user has cancelled
   950             // installation, in both cases do nothing.
   919             // installation, in both cases do nothing.
   962                     iLaunchAppQueryView = new LaunchAppQueryView(self, iDialog);
   931                     iLaunchAppQueryView = new LaunchAppQueryView(self, iDialog);
   963                 }
   932                 }
   964             });
   933             });
   965         }
   934         }
   966         boolean result = iLaunchAppQueryView.launchAppQuery(aLaunchAppInfo);
   935         boolean result = iLaunchAppQueryView.launchAppQuery(aLaunchAppInfo);
   967         iParent.getDisplay().syncExec(new Runnable()
   936         iLaunchAppQueryView.dispose();
   968         {
       
   969             public void run()
       
   970             {
       
   971                 iParent.dispose();
       
   972             }
       
   973         });
       
   974         iLaunchAppQueryView = null;
   937         iLaunchAppQueryView = null;
       
   938         if (!result)
       
   939         {
       
   940             iParent.getDisplay().syncExec(new Runnable()
       
   941             {
       
   942                 public void run()
       
   943                 {
       
   944                     iParent.dispose();
       
   945                 }
       
   946             });
       
   947         }
   975         log("LaunchAppQuery returns " + result + " for " + aLaunchAppInfo);
   948         log("LaunchAppQuery returns " + result + " for " + aLaunchAppInfo);
   976         return result;
   949         return result;
   977     }
   950     }
   978 
   951 
   979     /**
   952     /**
       
   953      * Executes given Runnable synchronously in the UI thread.
       
   954      */
       
   955     public void syncExec(Runnable aRunnable)
       
   956     {
       
   957         iParent.getDisplay().syncExec(aRunnable);
       
   958     }
       
   959 
       
   960     /**
   980      * Hides or unhides InstallerUi.
   961      * Hides or unhides InstallerUi.
   981      */
   962      */
   982     public void hide(boolean aHide)
   963     public void hide(boolean aHide)
   983     {
   964     {
   984         final boolean hide = aHide;
   965         final boolean hide = aHide;
  1009     /**
   990     /**
  1010      * Returns string title basing on mode of this InstallerUi.
   991      * Returns string title basing on mode of this InstallerUi.
  1011      */
   992      */
  1012     protected String getTitle()
   993     protected String getTitle()
  1013     {
   994     {
  1014         String result = null;
   995         String result = super.getTitle();
  1015         if (iMode == MODE_INSTALL)
   996         if (isUiReady())
  1016         {
   997         {
  1017             result = InstallerUiTexts.get(InstallerUiTexts.INSTALLING);
   998             if (iMode == MODE_INSTALL)
  1018         }
   999             {
  1019         else if (iMode == MODE_UNINSTALL)
  1000                 result = InstallerUiTexts.get(InstallerUiTexts.INSTALLING);
  1020         {
  1001             }
  1021             result = InstallerUiTexts.get("Uninstalling");
  1002             else if (iMode == MODE_UNINSTALL)
  1022         }
  1003             {
  1023         else if (iMode == MODE_APP_CONVERSION)
  1004                 result = InstallerUiTexts.get("Uninstalling");
  1024         {
  1005             }
  1025             result = InstallerUiTexts.get(
  1006             else if (iMode == MODE_APP_CONVERSION)
  1026                 "Converting data for application " +
  1007             {
  1027                 iAppConversionCurrent + "/" + iAppConversionTotal);
  1008                 result = InstallerUiTexts.get(
       
  1009                     "Converting data for application " +
       
  1010                     iAppConversionCurrent + "/" + iAppConversionTotal);
       
  1011             }
  1028         }
  1012         }
  1029         return result;
  1013         return result;
  1030     }
  1014     }
  1031 
  1015 
  1032     /**
  1016     /**
  1042     {
  1026     {
  1043         if (iSecurityIcon != null)
  1027         if (iSecurityIcon != null)
  1044         {
  1028         {
  1045             return iSecurityIcon;
  1029             return iSecurityIcon;
  1046         }
  1030         }
  1047         String iconFilename = ResourceUtil.UNTRUSTED_ICON_NAME;
  1031         String iconFilename = "java_3_untrusted.png";
  1048         if (aIdentified)
  1032         if (aIdentified)
  1049         {
  1033         {
  1050             iconFilename = ResourceUtil.TRUSTED_ICON_NAME;
  1034             iconFilename = "java_3_trusted.png";
  1051         }
  1035         }
  1052         String resourceDir = ResourceUtil.getResourceDir(0);
  1036         try
  1053         for (int i = 1; iSecurityIcon == null && resourceDir != null; i++)
  1037         {
  1054         {
  1038             String resourceDir = ResourceUtil.getResourceDir(0);
  1055             iSecurityIcon = loadImage(aDisplay, resourceDir + iconFilename, false);
  1039             for (int i = 1; iSecurityIcon == null && resourceDir != null; i++)
  1056             resourceDir = ResourceUtil.getResourceDir(i);
  1040             {
       
  1041                 iSecurityIcon = loadImage(
       
  1042                     aDisplay, resourceDir + iconFilename, false);
       
  1043                 resourceDir = ResourceUtil.getResourceDir(i);
       
  1044             }
       
  1045         }
       
  1046         catch (Throwable t)
       
  1047         {
       
  1048             log("Can not load security icon: " + t);
  1057         }
  1049         }
  1058         return iSecurityIcon;
  1050         return iSecurityIcon;
  1059     }
  1051     }
  1060 
  1052 
  1061     /**
  1053     /**
  1142             return result;
  1134             return result;
  1143         }
  1135         }
  1144         try
  1136         try
  1145         {
  1137         {
  1146             long startTime = System.currentTimeMillis();
  1138             long startTime = System.currentTimeMillis();
  1147             ImageData[] imageDatas = new ImageLoader().load(aInputStream);
  1139             Image image = new Image(aDisplay, aInputStream);
  1148             ImageData imageData = imageDatas[0];
  1140             ImageData imageData = image.getImageData();
  1149             if (aScaleImage)
  1141             if (aScaleImage)
  1150             {
  1142             {
  1151                 Point bestSize = getBestImageSize(
  1143                 Point bestSize = getBestImageSize(
  1152                                      imageData.width, imageData.height);
  1144                     imageData.width, imageData.height);
  1153                 if (bestSize.x != imageData.width ||
  1145                 if (bestSize.x != imageData.width ||
  1154                         bestSize.y != imageData.height)
  1146                         bestSize.y != imageData.height)
  1155                 {
  1147                 {
       
  1148                     Point oldSize =
       
  1149                         new Point(imageData.width, imageData.height);
  1156                     imageData = imageData.scaledTo(bestSize.x, bestSize.y);
  1150                     imageData = imageData.scaledTo(bestSize.x, bestSize.y);
  1157                     log("Image " + aImageName + " scaled from " +
  1151                     log("Image " + aImageName + " scaled from " +
  1158                         imageDatas[0].width + "x" + imageDatas[0].height +
  1152                         oldSize.x + "x" + oldSize.y + " to " +
  1159                         " to " + bestSize.x + "x" + bestSize.y);
  1153                         bestSize.x + "x" + bestSize.y);
  1160                 }
  1154                 }
  1161             }
  1155             }
  1162             result = new Image(aDisplay, imageData);
  1156             result = new Image(aDisplay, imageData);
  1163             long endTime = System.currentTimeMillis();
  1157             long endTime = System.currentTimeMillis();
  1164             log("Loaded image " + aImageName + " (load time " +
  1158             log("Loaded image " + aImageName + " (load time " +
  1176     /**
  1170     /**
  1177      * Determines the best image size for the image of given size.
  1171      * Determines the best image size for the image of given size.
  1178      */
  1172      */
  1179     private static Point getBestImageSize(int aWidth, int aHeight)
  1173     private static Point getBestImageSize(int aWidth, int aHeight)
  1180     {
  1174     {
  1181         final int MAX_WIDTH = iBestIconSize.x;
  1175         final int MAX_WIDTH = (iBestIconSize == null? 50: iBestIconSize.x);
  1182         final int MAX_HEIGHT = iBestIconSize.y;
  1176         final int MAX_HEIGHT = (iBestIconSize == null? 50: iBestIconSize.y);
  1183         Point result = new Point(aWidth, aHeight);
  1177         Point result = new Point(aWidth, aHeight);
  1184         if (result.x > MAX_WIDTH || result.y > MAX_HEIGHT)
  1178         if (result.x > MAX_WIDTH || result.y > MAX_HEIGHT)
  1185         {
  1179         {
  1186             if (result.x >= MAX_WIDTH)
  1180             if (result.x >= MAX_WIDTH)
  1187             {
  1181             {
  1305 
  1299 
  1306     ViewBase getActiveView()
  1300     ViewBase getActiveView()
  1307     {
  1301     {
  1308         return iActiveView;
  1302         return iActiveView;
  1309     }
  1303     }
       
  1304 
       
  1305     /**
       
  1306      * Loads JavaInstaller UI stylesheet.
       
  1307      */
       
  1308     void loadCss()
       
  1309     {
       
  1310         String cssFilename = "javaapplicationinstaller.css";
       
  1311         String cssPath = null;
       
  1312         try
       
  1313         {
       
  1314             if (iCssEngine != null)
       
  1315             {
       
  1316                 boolean loaded = false;
       
  1317                 String resourceDir = ResourceUtil.getResourceDir(0);
       
  1318                 for (int i = 1; !loaded && resourceDir != null; i++)
       
  1319                 {
       
  1320                     cssPath = resourceDir + cssFilename;
       
  1321                     FileUtility cssFile = new FileUtility(cssPath);
       
  1322                     if (cssFile.exists())
       
  1323                     {
       
  1324                         iCssEngine.loadCSS(cssPath);
       
  1325                         log("CSS loaded from " + cssPath);
       
  1326                         break;
       
  1327                     }
       
  1328                     resourceDir = ResourceUtil.getResourceDir(i);
       
  1329                 }
       
  1330             }
       
  1331         }
       
  1332         catch (Throwable t)
       
  1333         {
       
  1334             logError("Loading CSS from " + cssPath + " failed", t);
       
  1335         }
       
  1336     }
       
  1337 
       
  1338     private void disposeResources() {
       
  1339         if (iBoldFont != null && !iBoldFont.isDisposed())
       
  1340         {
       
  1341             iBoldFont.dispose();
       
  1342         }
       
  1343         if (iSecurityIcon != null && !iSecurityIcon.isDisposed())
       
  1344         {
       
  1345             iSecurityIcon.dispose();
       
  1346         }
       
  1347         Enumeration e = iImageTable.elements();
       
  1348         while (e.hasMoreElements())
       
  1349         {
       
  1350             Image img = (Image)e.nextElement();
       
  1351             if (img != null && !img.isDisposed())
       
  1352             {
       
  1353                 img.dispose();
       
  1354             }
       
  1355         }
       
  1356     }
  1310 }
  1357 }