package ie.dcu.apps.ist; import ie.dcu.plugin.*; import ie.dcu.segment.Segmenter; import java.util.logging.Logger; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.*; /** * Application launcher. * * @author Kevin McGuinness */ public class Main { public static final Logger log = Logger.getLogger("Main"); /** * Message to show when GDI+ is not installed. */ private static final String NO_GDIPLUS = "Unable to load required library: GDI+ (gdiplus.dll)\n\n" + "The GDI+ library needs to be installed before this program " + "can be used on this platform. See the note at the end of " + "the download page for further details."; public static void main(String[] args) { System.out.print(Application.DEFAULT_PLUGIN_SEARCH_PATH); for (String s: Application.DEFAULT_PLUGIN_SEARCH_PATH) { System.out.println(s); } Display.setAppName(Application.APP_NAME); check(); loadPlugins(); AppWindow window = new AppWindow(); window.setBlockOnOpen(true); window.open(); System.exit(0); } private static void loadPlugins() { PluginManager manager = new PluginManager(); for (String path : Application.DEFAULT_PLUGIN_SEARCH_PATH) { manager.searchPath().add(path); } manager.loadPlugins(); for (Plugin plugin : manager.plugins()) { String classname = plugin.getMetadata("segmenter"); if (classname != null) { loadSegmenterPlugin(plugin, classname); } } } private static void loadSegmenterPlugin(Plugin plugin, String classname) { try { Segmenter segmenter = (Segmenter) plugin.loadObject(classname); SegmenterRegistry.getInstance().add(segmenter); } catch (PluginException e) { log.severe("Unable to load plugin: " + e); } } public static boolean contains(String[] args, String argument) { for (String arg : args) { while (arg.startsWith("-")) { arg = arg.substring(1); } if (arg.equals(argument)) { return true; } } return false; } private static void check() { // Check for potential missing GDI+ on Win2K, NT, ME 98 String os = System.getProperty("os.name"); if (os.equals("Windows 2000") || os.equals("Windows NT") || os.equals("Windows ME") || os.equals("Windows 98")) { try { System.loadLibrary("gdiplus"); } catch (RuntimeException e) { exit(NO_GDIPLUS); } } } static void exit(String message) { Display display = Display.getDefault(); Rectangle rect = display.getBounds(); Shell shell = display.getActiveShell(); if (shell == null) { shell = new Shell(display, SWT.NO_TRIM); shell.setBounds(rect.width/2, rect.height/2, 0, 0); shell.open(); shell.setText("Error"); } MessageBox box = new MessageBox(shell, SWT.ICON_ERROR); box.setText("Error"); box.setMessage(message); box.open(); display.dispose(); System.exit(1); } }