Search in sources :

Example 1 with CLISmartHandler

use of de.lmu.ifi.dbs.elki.logging.CLISmartHandler in project elki by elki-project.

the class MiniGUI method main.

/**
 * Main method that just spawns the UI.
 *
 * @param args command line parameters
 */
public static void main(final String[] args) {
    // Detect the common problem of an incomplete class path:
    try {
        Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass("de.lmu.ifi.dbs.elki.database.ids.DBIDUtil");
        clz.getMethod("newHashSet").invoke(null);
    } catch (ReflectiveOperationException e) {
        StringBuilder msg = new StringBuilder(500).append("Your Java class path is incomplete.\n");
        if (e.getCause() != null) {
            for (Throwable t = e.getCause(); t != null; t = t.getCause()) {
                msg.append(t.toString()).append('\n');
            }
        } else {
            msg.append(e.toString()).append('\n');
        }
        msg.append("Make sure you have all the required jars on the classpath.\nOn the home page, you can find a 'elki-bundle' which should include everything.");
        JOptionPane.showMessageDialog(null, msg, "ClassPath incomplete", JOptionPane.ERROR_MESSAGE);
        return;
    }
    // Detect the broken Ubuntu jAyatana hack;
    String toolopt = System.getenv("JAVA_TOOL_OPTION");
    if (toolopt != null && toolopt.indexOf("jayatana") >= 0) {
        String msg = "The Ubuntu JAyatana 'global menu support' hack is known to cause problems with many Java applications.\nPlease unset JAVA_TOOL_OPTION.";
        JOptionPane.showMessageDialog(null, msg, "Incompatible with JAyatana", JOptionPane.ERROR_MESSAGE);
        return;
    }
    GUIUtil.logUncaughtExceptions(LOG);
    GUIUtil.setLookAndFeel();
    OutputStep.setDefaultHandlerVisualizer();
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                final MiniGUI gui = new MiniGUI();
                gui.run();
                List<String> params = Collections.emptyList();
                if (args != null && args.length > 0) {
                    params = new ArrayList<>(Arrays.asList(args));
                    // TODO: it would be nicer to use the Parameterization API for this!
                    if (!params.isEmpty()) {
                        Class<? extends AbstractApplication> c = ELKIServiceRegistry.findImplementation(AbstractApplication.class, params.get(0));
                        if (c != null) {
                            gui.maincls = c;
                            // on success
                            params.remove(0);
                        }
                    }
                    if (params.remove("-minigui.last")) {
                        javax.swing.SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                gui.loadLatest();
                            }
                        });
                    }
                    if (params.remove("-minigui.autorun")) {
                        javax.swing.SwingUtilities.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                gui.startTask();
                            }
                        });
                    }
                }
                gui.doSetParameters(params);
            } catch (Exception | Error e) {
                // Restore error handler, as the GUI is likely broken.
                LoggingConfiguration.replaceDefaultHandler(new CLISmartHandler());
                LOG.exception(e);
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) CLISmartHandler(de.lmu.ifi.dbs.elki.logging.CLISmartHandler) AbstractApplication(de.lmu.ifi.dbs.elki.application.AbstractApplication) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with CLISmartHandler

use of de.lmu.ifi.dbs.elki.logging.CLISmartHandler in project elki by elki-project.

the class MultiStepGUI method main.

/**
 * Main method that just spawns the UI.
 *
 * @param args command line parameters
 */
public static void main(final String[] args) {
    GUIUtil.logUncaughtExceptions(LOG);
    GUIUtil.setLookAndFeel();
    OutputStep.setDefaultHandlerVisualizer();
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                final MultiStepGUI gui = new MultiStepGUI();
                gui.run();
                if (args != null && args.length > 0) {
                    gui.setParameters(new SerializedParameterization(args));
                } else {
                    gui.setParameters(new SerializedParameterization());
                }
            } catch (Exception | Error e) {
                // Restore error handler, as the GUI is likely broken.
                LoggingConfiguration.replaceDefaultHandler(new CLISmartHandler());
                LOG.exception(e);
            }
        }
    });
}
Also used : CLISmartHandler(de.lmu.ifi.dbs.elki.logging.CLISmartHandler) SerializedParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization)

Aggregations

CLISmartHandler (de.lmu.ifi.dbs.elki.logging.CLISmartHandler)2 AbstractApplication (de.lmu.ifi.dbs.elki.application.AbstractApplication)1 SerializedParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1