use of net.parostroj.timetable.actions.scripts.ScriptAction in project grafikon by jub77.
the class MainFrame method initializeFrame.
/**
* initializes frame.
*/
private void initializeFrame() {
provider.setPresentationModel(model);
lastOpened = new HashMap<>();
// set local before anything else
String loadedLocale = null;
try {
IniConfigSection section = AppPreferences.getPreferences().getSection("main");
loadedLocale = section.get("locale.program");
String templateLocale = section.get("locale.output");
if (loadedLocale != null) {
Locale locale = ModelUtils.parseLocale(loadedLocale);
model.setLocale(locale);
Locale.setDefault(locale);
} else {
model.setLocale(null);
}
if (templateLocale != null) {
model.getOutputSettings().setLocale(ModelUtils.parseLocale(templateLocale));
}
} catch (IOException e) {
log.warn("Cannot load preferences.", e);
}
log.debug("Locale: {}", Locale.getDefault());
executeScriptAction = new ExecuteScriptAction(model);
initComponents();
this.addWindowListener(new MainFrameWindowListener(model, this));
trainsPane.setModel(model);
engineCyclesPane.setModel(new EngineCycleDelegate(model), interval -> {
TrainsCycleType type = interval.getTrain().getDiagram().getEngineCycleType();
if (!interval.getTrain().isCovered(type, interval)) {
return Color.black;
} else {
return Color.gray;
}
});
trainUnitCyclesPane.setModel(new TrainUnitCycleDelegate(model), interval -> {
TrainsCycleType type = interval.getTrain().getDiagram().getTrainUnitCycleType();
if (!interval.getTrain().isCovered(type, interval)) {
return Color.black;
} else {
return Color.gray;
}
});
driverCyclesPane.setModel(new DriverCycleDelegate(model), interval -> {
TrainsCycleType type = interval.getTrain().getDiagram().getDriverCycleType();
if (!interval.getTrain().isCovered(type, interval)) {
return Color.black;
} else {
return Color.gray;
}
});
circulationPane.setModel(model);
freightNetPane2.setModel(model);
model.addListener(this);
model.addListener(statusBar);
netPane.setModel(model);
this.updateView();
model.setDiagram(null);
// apply preferences
try {
this.loadFromPreferences(AppPreferences.getPreferences());
} catch (IOException e) {
log.error("Error loading preferences.", e);
}
// add predefined scripts
for (ScriptAction sd : model.getScriptsLoader().getScriptActions()) {
addScriptAction(sd, ExecuteScriptAction.MODEL_PREFIX, scriptsMenuModel);
}
// add gui scripts
for (ScriptAction sd : model.getGuiScriptsLoader().getScriptActions()) {
addScriptAction(sd, ExecuteScriptAction.GUI_PREFIX, scriptsMenuGui);
}
statusBar.setModel(model);
}
use of net.parostroj.timetable.actions.scripts.ScriptAction in project grafikon by jub77.
the class ExecuteScriptAction method predefinedExecution.
private void predefinedExecution(ScriptsLoader loader, Component comp, String scriptId) {
Component parent = GuiComponentUtils.getTopLevelComponent(comp);
parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
long time = System.currentTimeMillis();
try {
try {
ScriptAction scriptAction = loader.getScriptAction(scriptId);
scriptAction.execute(model.getDiagram(), Collections.<String, Object>singletonMap("parent", parent));
} finally {
parent.setCursor(Cursor.getDefaultCursor());
log.debug("Script {} finished in {}ms", scriptId, System.currentTimeMillis() - time);
}
} catch (GrafikonException ex) {
log.error("Error executing script.", ex);
String message = ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage();
GuiComponentUtils.showError(message, parent);
}
}
Aggregations