Search in sources :

Example 1 with SaveImageDialog

use of net.parostroj.timetable.gui.dialogs.SaveImageDialog 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)

Example 2 with SaveImageDialog

use of net.parostroj.timetable.gui.dialogs.SaveImageDialog in project grafikon by jub77.

the class CirculationViewPanel method saveButtonActionPerformed.

private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (dialog == null)
        dialog = new SaveImageDialog((Dialog) this.getTopLevelAncestor(), true);
    dialog.setLocationRelativeTo(this.getParent());
    dialog.setSaveSize(circulationView.getPreferredSize());
    dialog.setSizeChangeEnabled(false);
    dialog.setVisible(true);
    if (!dialog.isSave()) {
        return;
    }
    ActionContext actionContext = new ActionContext(GuiComponentUtils.getTopLevelComponent(this));
    SaveImageAction action = new SaveImageAction(actionContext, dialog, circulationView);
    ActionHandler.getInstance().execute(action);
}
Also used : SaveImageAction(net.parostroj.timetable.gui.actions.execution.SaveImageAction) SaveImageDialog(net.parostroj.timetable.gui.dialogs.SaveImageDialog) ActionContext(net.parostroj.timetable.gui.actions.execution.ActionContext)

Aggregations

SaveImageDialog (net.parostroj.timetable.gui.dialogs.SaveImageDialog)2 Dimension (java.awt.Dimension)1 Frame (java.awt.Frame)1 ActionContext (net.parostroj.timetable.gui.actions.execution.ActionContext)1 SaveImageAction (net.parostroj.timetable.gui.actions.execution.SaveImageAction)1 GTDraw (net.parostroj.timetable.output2.gt.GTDraw)1