using new constructor mechanism #36

This commit is contained in:
Rob Greene 2020-01-20 14:18:28 -06:00
parent 9151c49983
commit 253ad08520
2 changed files with 21 additions and 7 deletions

View File

@ -19,6 +19,7 @@
*/
package com.webcodepro.applecommander.ui;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@ -95,7 +96,8 @@ public class AppleCommander {
try {
swtAppleCommander = Class.forName(
"com.webcodepro.applecommander.ui.swt.SwtAppleCommander"); //$NON-NLS-1$
Object object = swtAppleCommander.newInstance();
Constructor<?> constructor = swtAppleCommander.getConstructor();
Object object = constructor.newInstance();
Method launchMethod = swtAppleCommander.
getMethod("launch", (Class[]) null); //$NON-NLS-1$
launchMethod.invoke(object, (Object[]) null);
@ -149,7 +151,8 @@ public class AppleCommander {
try {
swingAppleCommander = Class.forName(
"com.webcodepro.applecommander.ui.swing.SwingAppleCommander"); //$NON-NLS-1$
Object object = swingAppleCommander.newInstance();
Constructor<?> constructor = swingAppleCommander.getConstructor();
Object object = constructor.newInstance();
Method launchMethod = swingAppleCommander.
getMethod("launch", (Class[]) null); //$NON-NLS-1$
launchMethod.invoke(object, (Object[]) null);

View File

@ -26,6 +26,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@ -232,9 +234,9 @@ public class DiskExplorerTab {
public void widgetSelected(SelectionEvent event) {
try {
changeCurrentFormat(getCurrentFormat()); // minor hack
} catch (DiskException e) {
DiskExplorerTab.this.diskWindow.handle(e);
}
} catch (DiskException e) {
DiskExplorerTab.this.diskWindow.handle(e);
}
}
/**
* Double-click handler.
@ -1602,14 +1604,23 @@ public class DiskExplorerTab {
FileViewerWindow window = null;
FileFilter fileFilter = null;
try {
fileFilter = fileFilterClass.newInstance();
Constructor<? extends FileFilter> constructor = fileFilterClass.getConstructor();
fileFilter = constructor.newInstance();
} catch (NullPointerException ex) {
// This is expected
} catch (InstantiationException e) {
SwtUtil.showSystemErrorDialog(shell, e);
} catch (IllegalAccessException e) {
SwtUtil.showSystemErrorDialog(shell, e);
}
} catch (NoSuchMethodException e) {
SwtUtil.showSystemErrorDialog(shell, e);
} catch (SecurityException e) {
SwtUtil.showSystemErrorDialog(shell, e);
} catch (IllegalArgumentException e) {
SwtUtil.showSystemErrorDialog(shell, e);
} catch (InvocationTargetException e) {
SwtUtil.showSystemErrorDialog(shell, e);
}
if (fileFilter != null) {
window = new FileViewerWindow(shell, fileEntry, imageManager, fileFilter);
} else {