Revamping AppleImage creation a bit. #36.
This commit is contained in:
parent
f1202a1c66
commit
8fa9f64b6c
|
@ -47,22 +47,20 @@ public abstract class AppleImage {
|
||||||
* using Reflection to ease native compilation for the most part.
|
* using Reflection to ease native compilation for the most part.
|
||||||
*/
|
*/
|
||||||
public static AppleImage create(int width, int height) {
|
public static AppleImage create(int width, int height) {
|
||||||
String[] classes = {
|
String[] classNames = {
|
||||||
"ImageIoImage", "SunJpegImage", "SwtImage" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
"ImageIoImage", "SunJpegImage", "SwtImage" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
Class[] constructorArgClasses = new Class[] { int.class, int.class };
|
Class<?>[] constructorArgClasses = new Class<?>[] { int.class, int.class };
|
||||||
Object[] constructorArgs = new Object[] {
|
Object[] constructorArgs = { new Integer(width), new Integer(height) };
|
||||||
new Integer(width), new Integer(height) };
|
for (String className : classNames) {
|
||||||
for (int i=0; i<classes.length; i++) {
|
|
||||||
try {
|
try {
|
||||||
Class<?> appleImageClass = Class.forName(
|
Class<?> appleImageClass = Class.forName(
|
||||||
"com.webcodepro.applecommander.storage.filters.imagehandlers." //$NON-NLS-1$
|
"com.webcodepro.applecommander.storage.filters.imagehandlers." //$NON-NLS-1$
|
||||||
+ classes[i]);
|
+ className);
|
||||||
Constructor<?> constructor =
|
Constructor<?> constructor =
|
||||||
appleImageClass.getConstructor(constructorArgClasses);
|
appleImageClass.getConstructor(constructorArgClasses);
|
||||||
|
Object instance =
|
||||||
AppleImage appleImage = (AppleImage)
|
|
||||||
constructor.newInstance(constructorArgs);
|
constructor.newInstance(constructorArgs);
|
||||||
return appleImage;
|
return AppleImage.class.cast(instance);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
// There are multiple exceptions that can be thrown here.
|
// There are multiple exceptions that can be thrown here.
|
||||||
// For the most part, this is expected and simply means that
|
// For the most part, this is expected and simply means that
|
||||||
|
|
Loading…
Reference in New Issue