javamanager/javainstaller/installerui/javasrc/com/nokia/mj/impl/installer/ui/eswt2/InstallerUiEswt.java
changeset 80 d6dafc5d983f
parent 78 71ad690e91f5
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
    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;
       
    50 import org.eclipse.swt.graphics.Point;
    49 import org.eclipse.swt.graphics.Point;
    51 import org.eclipse.swt.graphics.Rectangle;
    50 import org.eclipse.swt.graphics.Rectangle;
    52 import org.eclipse.swt.internal.extension.DisplayExtension;
    51 import org.eclipse.swt.internal.extension.DisplayExtension;
    53 import org.eclipse.swt.internal.qt.BaseCSSEngine;
    52 import org.eclipse.swt.internal.qt.BaseCSSEngine;
    54 import org.eclipse.swt.widgets.Display;
    53 import org.eclipse.swt.widgets.Display;
   108     /** Certificate details view, owned by the view where it was opened. */
   107     /** Certificate details view, owned by the view where it was opened. */
   109     private CertificateDetailsView iCertificateDetailsView = null;
   108     private CertificateDetailsView iCertificateDetailsView = null;
   110 
   109 
   111     /** Hashtable for storing the loaded icons. */
   110     /** Hashtable for storing the loaded icons. */
   112     private static Hashtable iImageTable = null;
   111     private static Hashtable iImageTable = null;
   113     /** Best size for application icon. */
       
   114     private static Point iBestImageSize = null;
       
   115 
   112 
   116     /** Default shell bounds. */
   113     /** Default shell bounds. */
   117     private Rectangle iDefaultShellBounds = null;
   114     private Rectangle iDefaultShellBounds = null;
   118     private Rectangle iDefaultShellClientBounds = null;
   115     private Rectangle iDefaultShellClientBounds = null;
   119 
   116 
   189                     // Prevent UI from being automatically disposed.
   186                     // Prevent UI from being automatically disposed.
   190                     //aEvent.doit = false;
   187                     //aEvent.doit = false;
   191                 }
   188                 }
   192             });
   189             });
   193 
   190 
   194             // Initialize best image size.
       
   195             iBestImageSize = new Point(
       
   196                 DisplayExtension.getBestImageWidth(DisplayExtension.LIST_ELEMENT),
       
   197                 DisplayExtension.getBestImageHeight(DisplayExtension.LIST_ELEMENT));
       
   198             log("Best image size: " + iBestImageSize);
       
   199 
       
   200             synchronized (iInitWaitObject)
   191             synchronized (iInitWaitObject)
   201             {
   192             {
   202                 // Notify that UI is now ready.
   193                 // Notify that UI is now ready.
   203                 iInitWaitObject.notify();
   194                 iInitWaitObject.notify();
   204             }
   195             }
  1124         {
  1115         {
  1125             String resourceDir = ResourceUtil.getResourceDir(0);
  1116             String resourceDir = ResourceUtil.getResourceDir(0);
  1126             for (int i = 1; iSecurityIcon == null && resourceDir != null; i++)
  1117             for (int i = 1; iSecurityIcon == null && resourceDir != null; i++)
  1127             {
  1118             {
  1128                 iSecurityIcon = loadImage(
  1119                 iSecurityIcon = loadImage(
  1129                     aDisplay, resourceDir + iconFilename, false);
  1120                     aDisplay, resourceDir + iconFilename, null);
  1130                 resourceDir = ResourceUtil.getResourceDir(i);
  1121                 resourceDir = ResourceUtil.getResourceDir(i);
  1131             }
  1122             }
  1132         }
  1123         }
  1133         catch (Throwable t)
  1124         catch (Throwable t)
  1134         {
  1125         {
  1136         }
  1127         }
  1137         return iSecurityIcon;
  1128         return iSecurityIcon;
  1138     }
  1129     }
  1139 
  1130 
  1140     /**
  1131     /**
  1141      * Loads image from specified InputStream. This method scales the image
  1132      * Loads image from specified file.
  1142      * to optimum size.
  1133      *
       
  1134      * @param aDisplay display to which the icon will be added
       
  1135      * @param aImageFilename name of the image file to be loaded
       
  1136      * @param aImageSize size to which the image should be scaled, can be null
       
  1137      * @return image from file or null if image cannot be loaded
       
  1138      */
       
  1139     protected static Image loadImage(
       
  1140         Display aDisplay, String aImageFilename, Point aImageSize)
       
  1141     {
       
  1142         Image result = null;
       
  1143         InputStream imageInputStream = null;
       
  1144         try
       
  1145         {
       
  1146             FileUtility imageFile = new FileUtility(aImageFilename);
       
  1147             if (imageFile.exists())
       
  1148             {
       
  1149                 imageInputStream = imageFile.openInputStream();
       
  1150                 result = loadImage(aDisplay, imageInputStream,
       
  1151                                    aImageFilename, aImageSize);
       
  1152             }
       
  1153         }
       
  1154         catch (IOException ioe)
       
  1155         {
       
  1156             log("Can not get InputStream for " + aImageFilename + ": " + ioe);
       
  1157         }
       
  1158         finally
       
  1159         {
       
  1160             if (imageInputStream != null)
       
  1161             {
       
  1162                 try
       
  1163                 {
       
  1164                     imageInputStream.close();
       
  1165                     imageInputStream = null;
       
  1166                 }
       
  1167                 catch (IOException ioe)
       
  1168                 {
       
  1169                     logError("Closing image InputStream failed", ioe);
       
  1170                 }
       
  1171             }
       
  1172         }
       
  1173         return result;
       
  1174     }
       
  1175 
       
  1176     /**
       
  1177      * Loads image from specified InputStream.
  1143      *
  1178      *
  1144      * @param aDisplay display to which the icon will be added
  1179      * @param aDisplay display to which the icon will be added
  1145      * @param aInputStream InputStream where the image is loaded
  1180      * @param aInputStream InputStream where the image is loaded
  1146      * @param aImageName name of the image to be loaded
  1181      * @param aImageName name of the image to be loaded
       
  1182      * @param aImageSize size to which the image should be scaled, can be null
  1147      * @return image from InputStream or null if image cannot be loaded
  1183      * @return image from InputStream or null if image cannot be loaded
  1148      */
  1184      */
  1149     protected static Image loadImage(
  1185     protected static Image loadImage(
  1150         Display aDisplay, InputStream aInputStream, String aImageName)
       
  1151     {
       
  1152         return loadImage(aDisplay, aInputStream, aImageName, true);
       
  1153     }
       
  1154 
       
  1155     /**
       
  1156      * Loads image from specified file.
       
  1157      *
       
  1158      * @param aDisplay display to which the icon will be added
       
  1159      * @param aImageFilename name of the image file to be loaded
       
  1160      * @param aScaleImage flag telling if the loaded image should be scaled
       
  1161      * @return image from file or null if image cannot be loaded
       
  1162      */
       
  1163     private static Image loadImage(
       
  1164         Display aDisplay, String aImageFilename, boolean aScaleImage)
       
  1165     {
       
  1166         Image result = null;
       
  1167         InputStream imageInputStream = null;
       
  1168         try
       
  1169         {
       
  1170             FileUtility imageFile = new FileUtility(aImageFilename);
       
  1171             if (imageFile.exists())
       
  1172             {
       
  1173                 imageInputStream = imageFile.openInputStream();
       
  1174                 result = loadImage(aDisplay, imageInputStream,
       
  1175                                    aImageFilename, aScaleImage);
       
  1176             }
       
  1177         }
       
  1178         catch (IOException ioe)
       
  1179         {
       
  1180             log("Can not get InputStream for " + aImageFilename + ": " + ioe);
       
  1181         }
       
  1182         finally
       
  1183         {
       
  1184             if (imageInputStream != null)
       
  1185             {
       
  1186                 try
       
  1187                 {
       
  1188                     imageInputStream.close();
       
  1189                     imageInputStream = null;
       
  1190                 }
       
  1191                 catch (IOException ioe)
       
  1192                 {
       
  1193                     logError("Closing image InputStream failed", ioe);
       
  1194                 }
       
  1195             }
       
  1196         }
       
  1197         return result;
       
  1198     }
       
  1199 
       
  1200     /**
       
  1201      * Loads image from specified InputStream.
       
  1202      *
       
  1203      * @param aDisplay display to which the icon will be added
       
  1204      * @param aInputStream InputStream where the image is loaded
       
  1205      * @param aImageName name of the image to be loaded
       
  1206      * @param aScaleImage flag telling if the loaded image should be scaled
       
  1207      * @return image from InputStream or null if image cannot be loaded
       
  1208      */
       
  1209     private static Image loadImage(
       
  1210         Display aDisplay, InputStream aInputStream,
  1186         Display aDisplay, InputStream aInputStream,
  1211         String aImageName, boolean aScaleImage)
  1187         String aImageName, Point aImageSize)
  1212     {
  1188     {
       
  1189         String imageTableKey = aImageName + "," + aImageSize;
  1213         Image result = null;
  1190         Image result = null;
  1214         if (aImageName != null)
  1191         if (aImageName != null)
  1215         {
  1192         {
  1216             result = (Image)iImageTable.get(aImageName);
  1193             result = (Image)iImageTable.get(imageTableKey);
  1217         }
  1194         }
  1218         if (result != null)
  1195         if (result != null)
  1219         {
  1196         {
  1220             log("Using already loaded image " + aImageName);
  1197             log("Using already loaded image " + aImageName);
  1221             return result;
  1198             return result;
  1222         }
  1199         }
  1223         try
  1200         try
  1224         {
  1201         {
  1225             long startTime = System.currentTimeMillis();
  1202             long startTime = System.currentTimeMillis();
  1226             aDisplay.setData("org.eclipse.swt.internal.image.loadSize",
  1203             if (aImageSize != null)
  1227                              iBestImageSize);
  1204             {
  1228             Image image = new Image(aDisplay, aInputStream);
  1205                 aDisplay.setData("org.eclipse.swt.internal.image.loadSize",
  1229             if (aScaleImage)
  1206                                  aImageSize);
  1230             {
  1207             }
  1231                 ImageData imageData = image.getImageData();
  1208             result = new Image(aDisplay, aInputStream);
  1232                 if (iBestImageSize.x != imageData.width ||
       
  1233                         iBestImageSize.y != imageData.height)
       
  1234                 {
       
  1235                     Point oldSize =
       
  1236                         new Point(imageData.width, imageData.height);
       
  1237                     imageData = imageData.scaledTo(iBestImageSize.x, iBestImageSize.y);
       
  1238                     log("Image " + aImageName + " scaled from " +
       
  1239                         oldSize.x + "x" + oldSize.y + " to " +
       
  1240                         iBestImageSize.x + "x" + iBestImageSize.y);
       
  1241                     image = new Image(aDisplay, imageData);
       
  1242                 }
       
  1243             }
       
  1244             result = image;
       
  1245             long endTime = System.currentTimeMillis();
  1209             long endTime = System.currentTimeMillis();
  1246             log("Loaded image " + aImageName + " (load time " +
  1210             log("Loaded image " + aImageName + " (load time " +
  1247                 (endTime - startTime) + " ms)");
  1211                 (endTime - startTime) + " ms)");
  1248             iImageTable.put(aImageName, result);
  1212             iImageTable.put(imageTableKey, result);
  1249         }
  1213         }
  1250         catch (Throwable t)
  1214         catch (Throwable t)
  1251         {
  1215         {
  1252             log("Can not load image " + aImageName + ": " + t);
  1216             log("Can not load image " + aImageName + ": " + t);
  1253             //logError("Exception while loading image " + aImageName, t);
  1217             //logError("Exception while loading image " + aImageName, t);