use of de.lmu.ifi.dbs.elki.application.AbstractApplication in project elki by elki-project.
the class MiniGUI method setupAppChooser.
/**
* Setup the application chooser.
*/
private void setupAppChooser() {
// Configurator to choose the main application
appCombo = new JComboBox<>();
for (Class<?> clz : ELKIServiceRegistry.findAllImplementations(AbstractApplication.class)) {
String nam = clz.getCanonicalName();
if (nam == null || clz.getCanonicalName().contains("GUI")) {
continue;
}
if (nam.startsWith(APP_PREFIX)) {
nam = nam.substring(APP_PREFIX.length());
}
appCombo.addItem(nam);
}
appCombo.setEditable(true);
String sel = maincls.getCanonicalName();
if (sel.startsWith(APP_PREFIX)) {
sel = sel.substring(APP_PREFIX.length());
}
appCombo.setSelectedItem(sel);
appCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if ("comboBoxChanged".equals(e.getActionCommand())) {
Class<? extends AbstractApplication> clz = ELKIServiceRegistry.findImplementation(AbstractApplication.class, (String) appCombo.getSelectedItem());
if (clz != null) {
maincls = clz;
updateParameterTable();
} else {
LOG.warning("Main class name not found.");
}
}
}
});
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 1;
constraints.weighty = .01;
panel.add(appCombo, constraints);
}
use of de.lmu.ifi.dbs.elki.application.AbstractApplication 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);
}
}
});
}
use of de.lmu.ifi.dbs.elki.application.AbstractApplication in project elki by elki-project.
the class MiniGUI method startTask.
/**
* Do a full run of the KDDTask with the specified parameters.
*/
protected void startTask() {
parameterTable.editCellAt(-1, -1);
parameterTable.setEnabled(false);
final ArrayList<String> params = new ArrayList<>(parameters.size() * 2);
parameters.serializeParameters(params);
parameterTable.setEnabled(true);
runButton.setEnabled(false);
outputArea.clear();
SwingWorker<Void, Void> r = new SwingWorker<Void, Void>() {
@Override
public Void doInBackground() {
SerializedParameterization config = new SerializedParameterization(params);
config.tryInstantiate(LoggingStep.class);
AbstractApplication task = config.tryInstantiate(maincls);
try {
config.logUnusedParameters();
if (config.getErrors().size() == 0) {
task.run();
} else {
reportErrors(config);
}
LOG.debug("Task completed successfully.");
} catch (Throwable e) {
LOG.exception("Task failed", e);
}
return null;
}
@Override
protected void done() {
super.done();
runButton.setEnabled(true);
}
};
r.execute();
}
Aggregations