javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java
changeset 61 bf7ee68962da
parent 35 85266cc22c7f
child 76 4ad59aaee882
--- a/javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java	Tue Jul 06 14:10:26 2010 +0300
+++ b/javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java	Wed Aug 18 09:43:15 2010 +0300
@@ -20,6 +20,7 @@
 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Internal_PackageSupport;
+import org.eclipse.swt.graphics.Point;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -72,44 +73,6 @@
  * @see ImageLoader
  */
 public final class Image implements Drawable {
-
-    static int getNullIconHandle() {
-        if( Device.nullIconHandle == 0 ){
-            Device.nullIconHandle = OS.QIcon_new();
-        }
-        return Device.nullIconHandle;
-    }
-
-    /*
-     * Creates new Image instance.
-     * <p>
-     * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
-     * API for <code>Image</code>. It is marked public only so that it
-     * can be shared within the packages provided by SWT. It is not
-     * available on all platforms, and should never be called from
-     * application code.
-     * </p>
-     * @param device the device on which to create the image
-     * @param cgImage the internal image instance
-     *
-     * @exception IllegalArgumentException <ul>
-     *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
-     *    <li>ERROR_NULL_ARGUMENT - if the iternal image is null</li>
-     * </ul>
-     * @exception SWTException <ul>
-     *    <li>ERROR_INVALID_IMAGE - if the given internal image is not valid</li>
-     * </ul>
-     * @exception SWTError <ul>
-     *    <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
-     * </ul>
-     */
-    static Image new_Image(
-        Device device, org.eclipse.swt.internal.qt.graphics.Image cgImage) {
-        Image image = new Image(device);
-        image.init(cgImage);
-        return image;
-    }
-
     /**
      * specifies whether the receiver is a bitmap or an icon
      * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
@@ -367,7 +330,7 @@
      */
     public Image(Device device, String filename) {
         this(device, filename, true);
-     }
+    }
     
     private Image(Device device, String filename, boolean securityCheck) {
         this(device);
@@ -432,6 +395,43 @@
     static Image createImageWithoutSecurityCheck(Device device, String filename) {
         return new Image(device, filename, false);
     }
+    
+    /*
+     * Returns the bounds of an image without creating an Image instance.
+     */
+    static Point getImageSize(Device device, String filename) {
+        
+        if (filename == null) {
+            SWT.error(SWT.ERROR_NULL_ARGUMENT);
+        }
+        
+        InputStream is = device.getClass().getResourceAsStream(filename);
+        
+        if (is == null) {
+            SWT.error(SWT.ERROR_IO);
+        }
+        
+        return getImageSize(is);
+    }
+    
+    /*
+     * Returns the bounds of an image without creating an Image instance.
+     */
+    static Point getImageSize(InputStream stream) {
+        Point point = null;
+        
+        try {
+            point = org.eclipse.swt.internal.qt.graphics.ImageLoader.getImageSize(stream);
+        } catch (IOException e) {
+            SWT.error(SWT.ERROR_IO);
+        } catch (NullPointerException e) {
+            SWT.error(SWT.ERROR_NULL_ARGUMENT);
+        } catch (IllegalArgumentException e) {
+            SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+        }
+        
+        return point;
+    }
 
     /**
      * Disposes of the operating system resources associated with the image.
@@ -821,4 +821,41 @@
     private void track() {
         if (Device.tracking) device.new_Object(this);
     }
+
+    static int getNullIconHandle() {
+        if( Device.nullIconHandle == 0 ){
+            Device.nullIconHandle = OS.QIcon_new();
+        }
+        return Device.nullIconHandle;
+    }
+    
+    /**
+     * Creates new Image instance.
+     * <p>
+     * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
+     * API for <code>Image</code>. It is marked public only so that it
+     * can be shared within the packages provided by SWT. It is not
+     * available on all platforms, and should never be called from
+     * application code.
+     * </p>
+     * @param device the device on which to create the image
+     * @param cgImage the internal image instance
+     *
+     * @exception IllegalArgumentException <ul>
+     *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
+     *    <li>ERROR_NULL_ARGUMENT - if the iternal image is null</li>
+     * </ul>
+     * @exception SWTException <ul>
+     *    <li>ERROR_INVALID_IMAGE - if the given internal image is not valid</li>
+     * </ul>
+     * @exception SWTError <ul>
+     *    <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
+     * </ul>
+     */
+    static Image qt_new(
+        Device device, org.eclipse.swt.internal.qt.graphics.Image cgImage) {
+        Image image = new Image(device);
+        image.init(cgImage);
+        return image;
+    }
 }