// Export plugins.
if (e.getSource().equals(buttOK)) {
FileDialog dia = new FileDialog(this.myStarter, "Choose JAR file to store plugins", FileDialog.SAVE);
frame.dispose();
dia.setFilenameFilter(new FileNamePostfixFilter(".jar"));
dia.setVisible(true);
if (dia.getDirectory() == null || dia.getFile() == null) {
return;
}
File storeFile = new File(dia.getDirectory() + File.separator + dia.getFile());
@SuppressWarnings("deprecation")
Object[] selected = list.getSelectedValues();
String dirPrefixPlugin = dirPrefix;
StaticMethods.delDir(new File(dirPrefix));
for (Object o : selected) {
Class<Plugin<?>> c = (Class<Plugin<?>>) o;
try {
dirPrefixPlugin = dirPrefix + c.newInstance().id() + "/";
} catch (Exception e2) {
throw new RuntimeException("Plugin instance not created.");
}
File dir = new File(dirPrefixPlugin + "/" + c.getPackage().getName().replace('.', '/'));
File dirOwn = new File("./" + c.getPackage().getName().replace('.', '/'));
FileCopy copy = new FileCopy();
dir.mkdirs();
try {
copy.copyFolder(dirOwn, dir, true, false);
} catch (IOException e1) {
GlobalVariables.getPrematureParameters().logError("Could not copy directory '" + dirOwn + "':" + e1.getMessage() + "\n" + Arrays.deepToString(e1.getStackTrace()).replace(',', '\n'));
GlobalVariables.getPrematureParameters().logInfo("Plugin export aborted due to errors.");
return;
}
}
try {
ZipIt.createJARfromDirectory(dirPrefix, storeFile, null);
} catch (IOException e1) {
GlobalVariables.getPrematureParameters().logError("Could not create JAR file '" + storeFile + "'.");
}
StaticMethods.delDir(new File(dirPrefix));
GlobalVariables.getPrematureParameters().logInfo("Plugin JAR file '" + storeFile + "' exported.");
GeneralDialog dia2 = new GeneralDialog(
myStarter,
null,
"Export successful (" + selected.length + " plugins)",
GeneralDialog.OK_BUTT,
"Plugin JAR file '" + storeFile + "' exported:\n\n- " + Arrays.deepToString(selected).replace("[", "").replace("]", "").replace(", ", "\n- "));
dia2.setVisible(true);
return;
} else if (e.getSource().equals(buttCancel)) {
frame.dispose();
return;
}
myStarter.actionPerformed(e);
if (e.getActionCommand().equals(Starter.EXIT_STRING)) {
myStarter.dispose();
System.exit(0);
} else if (e.getActionCommand().equals(Starter.LOAD_STORED_SIMULATION)) {
if (loadSimState()) {
this.myStarter.dispose();
}
} else if (e.getActionCommand().equals(Starter.EXPORT_PLUGINS_STRING)) {
frame = new JDialog(myStarter, Starter.EXPORT_PLUGINS_STRING + " NOTE: all necessary classes have to be located in the package of the main plugin class.");
JPanel panel = new JPanel(new GridLayout(2, 1));
Object[] items = convertListToArray(getSharablePlugins());
list = new JList(items);
JScrollPane jScrollPane1 = new JScrollPane(list);
panel.add(jScrollPane1);
JPanel mainPanel = new JPanel();
JPanel panel1 = new JPanel(new GridLayout(1, 4));
panel1.add(buttOK);
panel1.add(buttCancel);
buttOK.addActionListener(this);
buttCancel.addActionListener(this);
panel.add(mainPanel);
mainPanel.add(panel1);
frame.getContentPane().add(panel);
frame.setSize(750, 400);
frame.setVisible(true);
} else if (e.getActionCommand().equals(Starter.IMPORT_PLUGINS_STRING)) {
// User selects file to import.
FileDialog dia = new FileDialog(this.myStarter, "Choose JAR file to store plugins", FileDialog.LOAD);
dia.setFilenameFilter(new FileNamePostfixFilter(".jar"));
dia.setVisible(true);
if (dia.getDirectory() == null || dia.getFile() == null) {
return;
}