add checks on ImageUtils instances
[nikiroo-utils.git] / src / be / nikiroo / utils / ImageUtils.java
index 37d73191a52307641ef67f48bcd3f839786607f2..e95f73e4216d1cb8cc66db89227aca94fdd9c3f7 100644 (file)
@@ -190,15 +190,27 @@ public abstract class ImageUtils {
                return set_flag;
        }
 
+       /**
+        * Check that the class can operate (for instance, that all the required
+        * libraries or frameworks are present).
+        * 
+        * @return TRUE if it works
+        */
+       abstract protected boolean check();
+
        /**
         * Create a new {@link ImageUtils}.
         * 
         * @return the {@link ImageUtils}
         */
        private static ImageUtils newObject() {
-               for (String clazz : new String[] { "be.nikiroo.utils.ui.ImageUtilsAwt" }) {
+               for (String clazz : new String[] { "be.nikiroo.utils.ui.ImageUtilsAwt",
+                               "be.nikiroo.utils.android.ImageUtilsAndroid" }) {
                        try {
-                               return (ImageUtils) SerialUtils.createObject(clazz);
+                               ImageUtils obj = (ImageUtils) SerialUtils.createObject(clazz);
+                               if (obj.check()) {
+                                       return obj;
+                               }
                        } catch (Exception e) {
                        }
                }