Search in sources :

Example 6 with OutputException

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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) OutputException(net.parostroj.timetable.output2.OutputException) StationTimetables(net.parostroj.timetable.output2.impl.StationTimetables) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) StationTimetablesExtractor(net.parostroj.timetable.output2.impl.StationTimetablesExtractor) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) OutputException(net.parostroj.timetable.output2.OutputException)

Example 7 with OutputException

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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) TrainUnitCyclesExtractor(net.parostroj.timetable.output2.impl.TrainUnitCyclesExtractor) TrainUnitCycles(net.parostroj.timetable.output2.impl.TrainUnitCycles) OutputException(net.parostroj.timetable.output2.OutputException) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) OutputException(net.parostroj.timetable.output2.OutputException)

Example 8 with OutputException

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);
    }
}
Also used : StartPositions(net.parostroj.timetable.output2.impl.StartPositions) Cycles(net.parostroj.timetable.output2.impl.Cycles) Marshaller(javax.xml.bind.Marshaller) PositionsExtractor(net.parostroj.timetable.output2.impl.PositionsExtractor) Position(net.parostroj.timetable.output2.impl.Position) OutputException(net.parostroj.timetable.output2.OutputException) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) OutputException(net.parostroj.timetable.output2.OutputException)

Example 9 with OutputException

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);
    }
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) GroovyTemplateFactory(net.parostroj.timetable.output2.groovy.GroovyTemplateFactory) TemplateTransformerFactory(net.parostroj.timetable.output2.template.TemplateTransformerFactory) StreamSource(javax.xml.transform.stream.StreamSource) URIResolver(javax.xml.transform.URIResolver) LoggerFactory(org.slf4j.LoggerFactory) PdfTransformer(net.parostroj.timetable.output2.pdf.PdfTransformer) Source(javax.xml.transform.Source) StandardCharsets(java.nio.charset.StandardCharsets) net.parostroj.timetable.output2(net.parostroj.timetable.output2) Charset(java.nio.charset.Charset) TransformerFactory(javax.xml.transform.TransformerFactory) TemplateWriterFactory(net.parostroj.timetable.output2.template.TemplateWriterFactory) TemplateOutput(net.parostroj.timetable.output2.template.TemplateOutput) InputStream(java.io.InputStream) TemplateTransformerFactory(net.parostroj.timetable.output2.template.TemplateTransformerFactory) TemplateWriterFactory(net.parostroj.timetable.output2.template.TemplateWriterFactory) TemplateOutput(net.parostroj.timetable.output2.template.TemplateOutput)

Example 10 with OutputException

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);
}
Also used : Frame(java.awt.Frame) SaveImageDialog(net.parostroj.timetable.gui.dialogs.SaveImageDialog) GTDraw(net.parostroj.timetable.output2.gt.GTDraw) Dimension(java.awt.Dimension)

Aggregations

OutputException (net.parostroj.timetable.output2.OutputException)13 OutputStreamWriter (java.io.OutputStreamWriter)9 Writer (java.io.Writer)9 JAXBContext (javax.xml.bind.JAXBContext)8 Marshaller (javax.xml.bind.Marshaller)8 Dimension (java.awt.Dimension)4 IOException (java.io.IOException)4 Font (java.awt.Font)2 InputStream (java.io.InputStream)2 StreamSource (javax.xml.transform.stream.StreamSource)2 Position (net.parostroj.timetable.output2.impl.Position)2 PositionsExtractor (net.parostroj.timetable.output2.impl.PositionsExtractor)2 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)2 PDFDocumentGraphics2D (org.apache.fop.svg.PDFDocumentGraphics2D)2 Frame (java.awt.Frame)1 Graphics2D (java.awt.Graphics2D)1 RenderingHints (java.awt.RenderingHints)1 Key (java.awt.RenderingHints.Key)1 BufferedImage (java.awt.image.BufferedImage)1 URI (java.net.URI)1