javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java
changeset 61 bf7ee68962da
parent 35 85266cc22c7f
child 76 4ad59aaee882
equal deleted inserted replaced
48:e0d6e9bd3ca7 61:bf7ee68962da
    18 import org.eclipse.swt.internal.qt.GCData;
    18 import org.eclipse.swt.internal.qt.GCData;
    19 import org.eclipse.swt.internal.qt.OS;
    19 import org.eclipse.swt.internal.qt.OS;
    20 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
    20 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
    21 import org.eclipse.swt.widgets.Display;
    21 import org.eclipse.swt.widgets.Display;
    22 import org.eclipse.swt.widgets.Internal_PackageSupport;
    22 import org.eclipse.swt.widgets.Internal_PackageSupport;
       
    23 import org.eclipse.swt.graphics.Point;
    23 
    24 
    24 import java.io.IOException;
    25 import java.io.IOException;
    25 import java.io.InputStream;
    26 import java.io.InputStream;
    26 
    27 
    27 /**
    28 /**
    70  * @see Color
    71  * @see Color
    71  * @see ImageData
    72  * @see ImageData
    72  * @see ImageLoader
    73  * @see ImageLoader
    73  */
    74  */
    74 public final class Image implements Drawable {
    75 public final class Image implements Drawable {
    75 
       
    76     static int getNullIconHandle() {
       
    77         if( Device.nullIconHandle == 0 ){
       
    78             Device.nullIconHandle = OS.QIcon_new();
       
    79         }
       
    80         return Device.nullIconHandle;
       
    81     }
       
    82 
       
    83     /*
       
    84      * Creates new Image instance.
       
    85      * <p>
       
    86      * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
       
    87      * API for <code>Image</code>. It is marked public only so that it
       
    88      * can be shared within the packages provided by SWT. It is not
       
    89      * available on all platforms, and should never be called from
       
    90      * application code.
       
    91      * </p>
       
    92      * @param device the device on which to create the image
       
    93      * @param cgImage the internal image instance
       
    94      *
       
    95      * @exception IllegalArgumentException <ul>
       
    96      *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
       
    97      *    <li>ERROR_NULL_ARGUMENT - if the iternal image is null</li>
       
    98      * </ul>
       
    99      * @exception SWTException <ul>
       
   100      *    <li>ERROR_INVALID_IMAGE - if the given internal image is not valid</li>
       
   101      * </ul>
       
   102      * @exception SWTError <ul>
       
   103      *    <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
       
   104      * </ul>
       
   105      */
       
   106     static Image new_Image(
       
   107         Device device, org.eclipse.swt.internal.qt.graphics.Image cgImage) {
       
   108         Image image = new Image(device);
       
   109         image.init(cgImage);
       
   110         return image;
       
   111     }
       
   112 
       
   113     /**
    76     /**
   114      * specifies whether the receiver is a bitmap or an icon
    77      * specifies whether the receiver is a bitmap or an icon
   115      * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
    78      * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
   116      * <p>
    79      * <p>
   117      * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
    80      * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
   365      *    <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
   328      *    <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
   366      * </ul>
   329      * </ul>
   367      */
   330      */
   368     public Image(Device device, String filename) {
   331     public Image(Device device, String filename) {
   369         this(device, filename, true);
   332         this(device, filename, true);
   370      }
   333     }
   371     
   334     
   372     private Image(Device device, String filename, boolean securityCheck) {
   335     private Image(Device device, String filename, boolean securityCheck) {
   373         this(device);
   336         this(device);
   374         if (filename == null) {
   337         if (filename == null) {
   375             SWT.error(SWT.ERROR_NULL_ARGUMENT);
   338             SWT.error(SWT.ERROR_NULL_ARGUMENT);
   429         }
   392         }
   430     }
   393     }
   431     
   394     
   432     static Image createImageWithoutSecurityCheck(Device device, String filename) {
   395     static Image createImageWithoutSecurityCheck(Device device, String filename) {
   433         return new Image(device, filename, false);
   396         return new Image(device, filename, false);
       
   397     }
       
   398     
       
   399     /*
       
   400      * Returns the bounds of an image without creating an Image instance.
       
   401      */
       
   402     static Point getImageSize(Device device, String filename) {
       
   403         
       
   404         if (filename == null) {
       
   405             SWT.error(SWT.ERROR_NULL_ARGUMENT);
       
   406         }
       
   407         
       
   408         InputStream is = device.getClass().getResourceAsStream(filename);
       
   409         
       
   410         if (is == null) {
       
   411             SWT.error(SWT.ERROR_IO);
       
   412         }
       
   413         
       
   414         return getImageSize(is);
       
   415     }
       
   416     
       
   417     /*
       
   418      * Returns the bounds of an image without creating an Image instance.
       
   419      */
       
   420     static Point getImageSize(InputStream stream) {
       
   421         Point point = null;
       
   422         
       
   423         try {
       
   424             point = org.eclipse.swt.internal.qt.graphics.ImageLoader.getImageSize(stream);
       
   425         } catch (IOException e) {
       
   426             SWT.error(SWT.ERROR_IO);
       
   427         } catch (NullPointerException e) {
       
   428             SWT.error(SWT.ERROR_NULL_ARGUMENT);
       
   429         } catch (IllegalArgumentException e) {
       
   430             SWT.error(SWT.ERROR_INVALID_ARGUMENT);
       
   431         }
       
   432         
       
   433         return point;
   434     }
   434     }
   435 
   435 
   436     /**
   436     /**
   437      * Disposes of the operating system resources associated with the image.
   437      * Disposes of the operating system resources associated with the image.
   438      */
   438      */
   819      * Call this only after dealing with all exceptions!
   819      * Call this only after dealing with all exceptions!
   820      */
   820      */
   821     private void track() {
   821     private void track() {
   822         if (Device.tracking) device.new_Object(this);
   822         if (Device.tracking) device.new_Object(this);
   823     }
   823     }
       
   824 
       
   825     static int getNullIconHandle() {
       
   826         if( Device.nullIconHandle == 0 ){
       
   827             Device.nullIconHandle = OS.QIcon_new();
       
   828         }
       
   829         return Device.nullIconHandle;
       
   830     }
       
   831     
       
   832     /**
       
   833      * Creates new Image instance.
       
   834      * <p>
       
   835      * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
       
   836      * API for <code>Image</code>. It is marked public only so that it
       
   837      * can be shared within the packages provided by SWT. It is not
       
   838      * available on all platforms, and should never be called from
       
   839      * application code.
       
   840      * </p>
       
   841      * @param device the device on which to create the image
       
   842      * @param cgImage the internal image instance
       
   843      *
       
   844      * @exception IllegalArgumentException <ul>
       
   845      *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
       
   846      *    <li>ERROR_NULL_ARGUMENT - if the iternal image is null</li>
       
   847      * </ul>
       
   848      * @exception SWTException <ul>
       
   849      *    <li>ERROR_INVALID_IMAGE - if the given internal image is not valid</li>
       
   850      * </ul>
       
   851      * @exception SWTError <ul>
       
   852      *    <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
       
   853      * </ul>
       
   854      */
       
   855     static Image qt_new(
       
   856         Device device, org.eclipse.swt.internal.qt.graphics.Image cgImage) {
       
   857         Image image = new Image(device);
       
   858         image.init(cgImage);
       
   859         return image;
       
   860     }
   824 }
   861 }