use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class XmlStationTimetablesOutput method writeTo.
@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
try {
// show circulations in adjacent sessions
boolean adjacentSessions = params.getParamValue("adjacent.sessions", Boolean.class, false);
// technological times
boolean techTime = false;
if (params.paramExistWithValue("tech.time")) {
techTime = params.getParam("tech.time").getValue(Boolean.class);
}
// extract positions
StationTimetablesExtractor se = new StationTimetablesExtractor(diagram, SelectionHelper.selectNodes(params, diagram), techTime, adjacentSessions, this.getLocale());
StationTimetables st = new StationTimetables(se.getStationTimetables());
JAXBContext context = JAXBContext.newInstance(StationTimetables.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer writer = new OutputStreamWriter(stream, this.getCharset());
m.marshal(st, writer);
} catch (Exception e) {
throw new OutputException(e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class XmlTrainUnitCyclesOutput method writeTo.
@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
try {
TrainUnitCyclesExtractor tuce = new TrainUnitCyclesExtractor(SelectionHelper.selectCycles(params, diagram, diagram.getTrainUnitCycleType()));
TrainUnitCycles cards = new TrainUnitCycles(tuce.getTrainUnitCycles());
JAXBContext context = JAXBContext.newInstance(TrainUnitCycles.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer writer = new OutputStreamWriter(stream, this.getCharset());
m.marshal(cards, writer);
} catch (Exception e) {
throw new OutputException(e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class XmlStartPositionsOutput method writeTo.
@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
try {
// extract positions
PositionsExtractor pe = new PositionsExtractor(diagram);
List<Position> engines = pe.getStartPositions(diagram.getEngineCycleType().getCycles(), null);
List<Position> trainUnits = pe.getStartPositions(diagram.getTrainUnitCycleType().getCycles(), null);
List<Cycles> customCycles = pe.getStartPositionsCustom(null);
StartPositions sp = new StartPositions();
sp.setEnginesPositions(engines);
sp.setTrainUnitsPositions(trainUnits);
sp.setCustomCycles(customCycles);
JAXBContext context = JAXBContext.newInstance(StartPositions.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer writer = new OutputStreamWriter(stream, this.getCharset());
m.marshal(sp, writer);
} catch (Exception e) {
throw new OutputException(e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class GPdfOutputFactory method createOutput.
@Override
public Output createOutput(String type) throws OutputException {
try {
if (!OUTPUT_TYPES.contains(type)) {
throw new OutputException("Unknown type: " + type);
}
TemplateWriterFactory templateFactory = () -> factory.getTemplate(type, this.getCharset());
TemplateTransformerFactory transformerFactory = () -> (is, os, params) -> transformer.write(os, is, getResolver(params));
return new TemplateOutput(getLocale(), templateFactory, transformerFactory);
} catch (Exception e) {
throw new OutputException(e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class GraphicalTimetableViewWithSave method saveMenuItemActionPerformed.
private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
if (this.getRoute() == null) {
return;
}
if (dialog == null) {
dialog = new SaveImageDialog((Frame) this.getTopLevelAncestor(), true);
}
dialog.setLocationRelativeTo(this.getParent());
dialog.setSaveSize(this.getSize());
dialog.setVisible(true);
if (!dialog.isSave()) {
return;
}
// save action
ActionContext actionContext = new ActionContext(GuiComponentUtils.getTopLevelComponent(this));
ModelAction action = new EventDispatchAfterModelAction(actionContext) {
private boolean error;
@Override
protected void backgroundAction() {
setWaitMessage(ResourceLoader.getString("wait.message.image.save"));
setWaitDialogVisible(true);
long time = System.currentTimeMillis();
try {
Dimension saveSize = dialog.getSaveSize();
// get values and provide save
GTViewSettings config = getSettings();
config.setOption(Key.DISABLE_STATION_NAMES, Boolean.FALSE);
GTDraw draw = createDraw(config, saveSize);
try {
OutputFactory factory = OutputFactory.newInstance("draw");
Output output = factory.createOutput("diagram");
output.write(output.getAvailableParams().setParam(Output.PARAM_OUTPUT_FILE, dialog.getSaveFile()).setParam(Output.PARAM_TRAIN_DIAGRAM, diagram).setParam(DrawParams.GT_DRAWS, Arrays.asList(draw)).setParam(DrawParams.OUTPUT_TYPE, dialog.getImageType() == SaveImageDialog.Type.PNG ? FileOutputType.PNG : FileOutputType.SVG));
} catch (OutputException e) {
log.warn("Error saving file: " + dialog.getSaveFile(), e);
error = true;
}
} finally {
log.debug("Image save finished in {}ms", System.currentTimeMillis() - time);
setWaitDialogVisible(false);
}
}
@Override
protected void eventDispatchActionAfter() {
if (error) {
JOptionPane.showMessageDialog(context.getLocationComponent(), ResourceLoader.getString("save.image.error"), ResourceLoader.getString("save.image.error.text"), JOptionPane.ERROR_MESSAGE);
}
}
};
ActionHandler.getInstance().execute(action);
}
Aggregations