Support for future JavaFX GUI

This is a minor patch that adds detection (which will fail currently)
for a JavaFX GUI, when one is written.  It doesn't presently exist, but
when the ui/fx directory is created and populated with a JavaFX-based
GUI, it will start working and be used as the default choice.  Left
fallbacks for SWT and Swing, though of course the Swing fallback doesn't
have enough there to actually be useful yet.

I'm still teaching myself SWT and JavaFX, so this is all I've done with
it so far.  If anyone would like to contribute, please feel free.  :)
This commit is contained in:
T. Joseph Carter 2017-11-15 19:11:27 -08:00
parent 4b213c8f09
commit 830b4966d2
2 changed files with 54 additions and 2 deletions

View File

@ -47,7 +47,9 @@ public class AppleCommander {
*/
public static void main(String[] args) {
if (args.length == 0) {
if (isSwtAvailable()) {
if (isFXAvailable()) {
launchFXAppleCommander(args);
} else if (isSwtAvailable()) {
launchSwtAppleCommander(args);
} else if (isSwingAvailable()) {
launchSwingAppleCommander(args);
@ -57,7 +59,13 @@ public class AppleCommander {
} else {
String[] extraArgs = new String[args.length - 1];
System.arraycopy(args, 1, extraArgs, 0, extraArgs.length);
if ("-swt".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
if ("-fx".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
if (isFXAvailable()) {
launchFXAppleCommander(args);
} else {
System.err.println(textBundle.get("FXVersionNotAvailable")); //$NON-NLS-1$
}
} else if ("-swt".equalsIgnoreCase(args[0])) { //$NON-NLS-1$
if (isSwtAvailable()) {
launchSwtAppleCommander(args);
} else {
@ -79,6 +87,49 @@ public class AppleCommander {
}
}
}
/**
* Test to see if JavaFX is available.
*/
protected static boolean isFXAvailable() {
try {
Class.forName("javafx.application.Application"); //$NON-NLS-1$
Class.forName("com.webcodepro.applecommander.ui.fx.FXAppleCommander"); //$NON-NLS-1$
return true;
} catch (ClassNotFoundException ex) {
return false;
}
}
/**
* Launch the JavaFX version of AppleCommander. This method
* uses reflection to load FXAppleCommander to minimize which
* classes get loaded. This is particularly important for the
* command-line version.
*/
protected static void launchFXAppleCommander(String[] args) {
Class<?> fxAppleCommander;
try {
fxAppleCommander = Class.forName(
"com.webcodepro.applecommander.ui.fx.FXAppleCommander"); //$NON-NLS-1$
Object object = fxAppleCommander.newInstance();
Method launchMethod = fxAppleCommander.
getMethod("launch", (Class[]) null); //$NON-NLS-1$
launchMethod.invoke(object, (Object[]) null);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
}
/**
* Launch the SWT version of AppleCommander. This method
* uses reflection to load SwtAppleCommander to minimize which

View File

@ -110,6 +110,7 @@ CommandLineDC42Bad = Unable to interpret this DiskCopy 42 image.
UserPreferencesComment = AppleCommander user preferences
# AppleCommander
FXVersionNotAvailable = Sorry, the JavaFX GUI is not available.
SwtVersionNotAvailable = Sorry, the SWT GUI is not available.
SwingVersionNotAvailable = Sorry, the Swing GUI is not available.
CommandLineNotAvailable = Sorry, the command line user interface is not available.