}
this.liveWindow.metaInfVis.repaint();
} else if (arg0.getActionCommand().equals("Generate PDF...")) {
boolean pause = liveWindow.vidParent.getPause();
liveWindow.vidParent.pause();
FileDialog dia = new FileDialog(
this,
"Save environment view as pdf (works with AbstractEnvironment2D<?> only)...",
FileDialog.SAVE);
dia.setFilenameFilter(new FileNamePostfixFilter("pdf"));
dia.setVisible(true);
if (dia.getDirectory() != null && dia.getFile() != null) {
StaticMethods.saveEnvironmentViewAsPDF(
new File(dia.getDirectory() + "/" + dia.getFile()),
// dia.getFiles()[0],
(AbstractEnvironment2D<?>) this.liveWindow.vidParent
.getEnvironment(), new DefaultFontMapper());
}
if (!pause) {
liveWindow.vidParent.depause();
}
} else if (arg0.getActionCommand().equals(this.saveString)) {
AllroundVideoPlugin vid = this.videoPlugin;
if (vid != null) {
vid.pause();
// Ask for executable simState.
String butt1 = "SimState only";
String butt2 = "Executable SimState";
String text = "Saving the simState allows to continue the simulation at another time and on another computer.\n"
+ "However, problems may occur if the EAS version to run the simulation on is different from the current.\n \n"
+ "Choose \"" + butt1 + "\" to keep track of the EAS version yourself or \"" + butt2 + "\" to create a package\n"
+ "containing EAS and everything else required to load the simState including an executable batch file\n"
+ "(only available when not already running an exectuable simState).";
String[] buttons = {butt1, GeneralDialog.CANCEL};
File testFile = new File("./" + GlobalVariables.ROOT_PACKAGE_NAME);
if (testFile.exists() && testFile.isDirectory()) {
buttons = new String[] {butt1, butt2, GeneralDialog.CANCEL};
}
GeneralDialog dia2 = new GeneralDialog(
null,
text,
"Save simState on its own or create executable simState (may take a bit)?",
buttons,
null);
dia2.setVisible(true);
if (dia2.getResult().equals(GeneralDialog.CANCEL)) {
return;
}
// Ask for location.
FileDialog dia = new FileDialog(this, "Select a place to store simulation state", FileDialog.SAVE);
dia.setFilenameFilter(new FileNamePostfixFilter(".eas"));
dia.setVisible(true);
if (dia.getDirectory() != null && dia.getFile() != null) {
File easFile;
if (dia.getFile().endsWith(".eas")) {
easFile = new File(dia.getDirectory() + File.separator + dia.getFile());
} else {
easFile = new File(dia.getDirectory() + File.separator + dia.getFile() + ".eas");
}
SerializableSimulationState simState = new SerializableSimulationState(
this.liveWindow.environment.getSimTime(), easFile);
try {
if (dia2.getResult().equals(butt1)) {
simState.save();
} else if (dia2.getResult().equals(butt2)) {
GlobalVariables.getPrematureParameters().logInfo("Creating executable simState (this may take a while).");
simState.createExecutableSimState();
}
} catch (SimStateUnserializableException e) {
String info =
"The simulation state could not be saved. This probably means that one or more objects\n"
+ "stored as field variables are not implementing the Serializable interface.\n"
+ "Most EAS classes are serializable, so you should check field types from the\n"
+ "Java internal or possibly external libraries. A good starting point often appears\n"
+ "to be objects of type BufferedImage (or Graphics, Graphics2D etc). Another known problem\n"
+ "is given by the unseriablizable Stroke classes - when using " + new AllroundChartPlugin().id() + ",\n"
+ "try avoiding to specifically set the Stroke. Note that all 3D simulation currently cannot\n"
+ "be serialized. Concerning AVI and GIF recording, both should be turned off for now\n"
+ "as errors will occur on reloading the simState (this is work in progress).\n\n"
+ "A list of unserializable fields in the currently used plugins and environments follows.\n"
+ "You should first look into them as the trouble-causing field(s) is/are probably among them:\n\n";
LinkedList<Class<?>> classes = new LinkedList<>();
for (Plugin<?> p : this.videoPlugin.getCurrentEnv().getSimTime().getPlugins()) {
classes.add(p.getClass());
}
classes.add(this.videoPlugin.getCurrentEnv().getClass());
for (AbstractAgent<?> a : this.videoPlugin.getCurrentEnv().getAgents()) {
classes.add(a.getClass());
}
HashMap<Field, HashSet<String>> result = Crawler.initiateCrawling(classes);
String resString = "";
for (Field field : result.keySet()) {
resString += "<UnSer> "
+ field.getType().getSimpleName() + " "
+ field.getName() + " ("
+ field.getDeclaringClass().getName() + ") => " + result.get(field) + "\n";
}
info += resString + "\n\n";
GeneralDialog dia3 = new GeneralDialog(
null,
null,
"Simulation state not serialized",
new String[] {GeneralDialog.OK, "Throw exception"},
info
+ "Exception caught: " + e.toString() + "\n" + Arrays.toString(e.getStackTrace()).replace(", ", "\n"));
dia3.setVisible(true);
if (dia3.getResult().equals("Throw exception")) {
GlobalVariables.getPrematureParameters().logDebug("Full stack trace of exception: ");
e.printStackTrace();
GlobalVariables.getPrematureParameters().logError("Throwing exception: ");
throw new RuntimeException(e);
}
}
}
vid.depause();
}
} else if (arg0.getActionCommand().equals(this.pluginManagerString)) {
liveWindow.vidParent
.getEnvironment()
.getSimTime()
.registerPlugin(PluginFactory.getKonstPlug(
new AllroundPluginManager().id(),
GlobalVariables.getPrematureParameters()));
} else if (arg0.getActionCommand().equals("Exit!")) {
liveWindow.vidParent.pause();
GeneralDialog dia = new GeneralDialog(
null,
"Do you really want to exit?\n\nUnsaved changes will be lost!",
"Exit request", GeneralDialog.YES_NO, null);
dia.setLocationRelativeTo(null);
dia.setVisible(true);
if (dia.getResult().equals(GeneralDialog.YES)) {
System.exit(0);
}
liveWindow.vidParent.depause();
}