javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/org/eclipse/swt/internal/qt/graphics/ImageLoader.java
--- a/javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/org/eclipse/swt/internal/qt/graphics/ImageLoader.java Mon Oct 04 11:29:25 2010 +0300
+++ b/javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/org/eclipse/swt/internal/qt/graphics/ImageLoader.java Fri Oct 15 12:29:39 2010 +0300
@@ -46,14 +46,20 @@
* Status of native peer
*/
private boolean disposed;
+
+ /**
+ * Default native type of loaded images
+ */
+ private int nativeImageType = Config.IMAGE_DEFAULT_TYPE;
/**
* Creates an instance of this class and initializes native
- * image loader.
+ * image loader. Type of native image created is set to
+ * the default type defined Config.IMAGE_DEFAULT_TYPE;
*/
public ImageLoader() {
- Utils.validateUiThread();
- handle = OS.imageLoader_init();
+ Utils.validateUiThread();
+ handle = OS.imageLoader_init(nativeImageType);
if (handle == 0) {
throw new OutOfMemoryError();
}
@@ -61,10 +67,30 @@
}
/**
+ * Creates an instance of this class and initializes native
+ * image loader with specified target image type.
+ * @param resultImageType The native type of image for loaded images,
+ * either Image.IMAGE_TYPE_QIMAGE or Image.IMAGE_TYPE_QPIXMAP.
+ */
+ public ImageLoader(int resultImageType) {
+ Utils.validateUiThread();
+ if((resultImageType != Image.IMAGE_TYPE_QIMAGE) &&
+ (resultImageType != Image.IMAGE_TYPE_QPIXMAP)) {
+ throw new IllegalArgumentException("Illegal resultImageType");
+ }
+ nativeImageType = resultImageType;
+ handle = OS.imageLoader_init(nativeImageType);
+ if (handle == 0) {
+ throw new OutOfMemoryError();
+ }
+ disposed = false;
+ }
+
+ /**
* Disposes native image, i.e. frees resources.
*/
public void dispose() {
- Utils.validateUiThread();
+ Utils.validateUiThread();
if (disposed) {
return;
} else {
@@ -75,6 +101,14 @@
}
/**
+ * Returns current result native image type.
+ * @return Native image type, either Image.IMAGE_TYPE_QIMAGE or Image.IMAGE_TYPE_QPIXMAP
+ */
+ public int getResultImageType() {
+ return nativeImageType;
+ }
+
+ /**
* Gets the status of this image loader.
*
* @return True if this instance has been already disposed otherwise false
@@ -114,14 +148,14 @@
* Loads image from given byte array.
*
* @param data The array containing image data
- * @param offset The offset from beginnig of data where image data starts
+ * @param offset The offset from beginning of data where image data starts
* @param length The length of data beginning form offset
* @return Instance of loaded image
* @throws NullPointerException if data is null
* @throws IllegalArgumentException if offset is less than 0
* @throws IllegalArgumentException if length is equal or less than 0
* @throws ArrayIndexOutOfBoundsException if offset and length define an invalid range
- * @throws IOException if image cannot be loaded or it is unsupported format
+ * @throws IllegalArgumentException if image cannot be loaded or it is unsupported format
* @throws OutOfMemoryError if native buffer allocation fails
*/
public Image loadImage(byte[] data, int offset, int length) throws IOException {
@@ -147,14 +181,14 @@
return new Image(OS.imageLoader_endStream(handle));
}
- /**
- * Loads image from file directly using the native APIs. Note that Java
- * security checks are not done.
- *
- * @param filename The filename to pass to the native APIs.
- * @return Image The loaded image.
- * @throws IOException
- */
+ /**
+ * Loads image from file directly using the native APIs. Note that Java
+ * security checks are not done.
+ *
+ * @param filename The filename to pass to the native APIs.
+ * @return Image The loaded image.
+ * @throws IOException
+ */
public Image nativelyLoadImageFromFileNoSecurity(String filename) throws IOException {
checkState();
if (filename == null) {
@@ -164,12 +198,12 @@
}
/**
- * Contructs an instance of Image by reading image data from given InputStream.
+ * Constructs an instance of Image by reading image data from given InputStream.
*
* @param is The InputStream from where to read the image data from
* @return Instance of loaded image
* @throws NullPointerException if InputStream is is null
- * @throws IOException if image cannot be loaded
+ * @throws IllegalArgumentException if image cannot be loaded
* @throws OutOfMemoryError if allocation of native buffer of image creation fails
* @throws IllegalStateException if image data is invalid
* @throws IllegalArgumentException if image format is not supported
@@ -227,10 +261,28 @@
* @param height The height to scale to
*/
public void setLoadSize(int width, int height) {
- OS.imageLoader_setLoadSize(handle, width, height);
+ OS.imageLoader_setLoadSize(handle, width, height);
}
/**
+ * Sets the result image type, i.e. the native type for the images
+ * loaded.
+ *
+ * @param resultImageType The type of loaded image, either Image.IMAGE_TYPE_QIMAGE or
+ * Image.IMAGE_TYPE_QPIXMAP
+ * @throws IllegalArgumentException if imageType is not one of Image.
+ * IMAGE_TYPE_QIMAGE or Image.IMAGE_TYPE QPIXMAP
+ */
+ public void setResultImageType(int resultImageType) {
+ if((resultImageType != Image.IMAGE_TYPE_QIMAGE) &&
+ (resultImageType != Image.IMAGE_TYPE_QPIXMAP)) {
+ throw new IllegalArgumentException("Illegal resultImageType");
+ }
+ nativeImageType = resultImageType;
+ OS.imageloader_setResultImageType(handle, nativeImageType);
+ }
+
+ /**
* Returns the bounds of an Image without creating an actual Image instance.
*
* @param is The InputStream from where to read the image data from
@@ -261,7 +313,7 @@
* Private helper to check the state of the current instance.
*/
private void checkState() {
- Utils.validateUiThread();
+ Utils.validateUiThread();
if (disposed) {
throw new IllegalStateException("Image loader already disposed");
}