Search in sources :

Example 1 with Settings

use of net.parostroj.timetable.output2.OutputWriter.Settings in project grafikon by jub77.

the class MainFrame method ouputTemplatesMenuItemActionPerformed.

private void ouputTemplatesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
    // output templates list dialog
    OutputTemplateListDialog dialog = new OutputTemplateListDialog(this, true);
    dialog.setLocationRelativeTo(this);
    dialog.registerContext(model.getGuiContext());
    OutputSettings settings = model.getOutputSettings();
    FileChooserFactory chooserFactory = FileChooserFactory.getInstance();
    File outputDirectory = chooserFactory.getLocation(FileChooserFactory.Type.OUTPUT_DIRECTORY);
    try (CloseableFileChooser allChooser = chooserFactory.getFileChooser(FileChooserFactory.Type.ALL_FILES)) {
        dialog.showDialog(model.getDiagram(), outputDirectory, allChooser, new Settings(settings.getLocale()));
        dialog.dispose();
    }
}
Also used : FileChooserFactory(net.parostroj.timetable.gui.actions.impl.FileChooserFactory) OutputSettings(net.parostroj.timetable.gui.data.OutputSettings) CloseableFileChooser(net.parostroj.timetable.gui.actions.impl.CloseableFileChooser) File(java.io.File) LSFile(net.parostroj.timetable.model.ls.LSFile) Settings(net.parostroj.timetable.output2.OutputWriter.Settings) OutputSettings(net.parostroj.timetable.gui.data.OutputSettings)

Example 2 with Settings

use of net.parostroj.timetable.output2.OutputWriter.Settings in project grafikon by jub77.

the class MainFrame method ouputMenuItemActionPerformed.

private void ouputMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
    // dialog with outputs
    EditOutputsDialog dialog = EditOutputsDialog.newInstance(this, true);
    dialog.setSettings(new Settings(model.getOutputSettings().getLocale()));
    GenerateOutputPM pm = new GenerateOutputPM(model.getLanguageLoader().getAvailableLocales(), model.getDiagram().getLocales());
    try (CloseableFileChooser chooser = FileChooserFactory.getInstance().getFileChooser(FileChooserFactory.Type.OUTPUT_DIRECTORY)) {
        pm.init(model.get(), chooser);
        dialog.setPresentationModel(pm);
        dialog.setLocationRelativeTo(this);
        dialog.registerContext(model.getGuiContext());
        dialog.showDialog(model.getDiagram());
        dialog.dispose();
        pm.writeBack();
    }
}
Also used : GenerateOutputPM(net.parostroj.timetable.gui.pm.GenerateOutputPM) CloseableFileChooser(net.parostroj.timetable.gui.actions.impl.CloseableFileChooser) Settings(net.parostroj.timetable.output2.OutputWriter.Settings) OutputSettings(net.parostroj.timetable.gui.data.OutputSettings)

Example 3 with Settings

use of net.parostroj.timetable.output2.OutputWriter.Settings in project grafikon by jub77.

the class GraphicalTimetableView method initComponents.

private void initComponents() {
    popupMenu = new javax.swing.JPopupMenu();
    routesMenu = new SelectionMenu<>();
    javax.swing.JMenuItem routesEditMenuItem = new javax.swing.JMenuItem();
    javax.swing.JSeparator jSeparator1 = new javax.swing.JSeparator();
    typesMenu = new SelectionMenu<>();
    sizesMenu = new SelectionMenu<>();
    orientationMenu = new SelectionMenu<>();
    preferencesMenu = new ChoicesMenu<>();
    // NOI18N
    routesMenu.setText(ResourceLoader.getString("gt.routes"));
    popupMenu.add(routesMenu);
    // NOI18N
    routesEditMenuItem.setText(ResourceLoader.getString("gt.routes.edit"));
    routesEditMenuItem.addActionListener(evt -> {
        if (diagram == null) {
            return;
        }
        getRouteDialog().setLocationRelativeTo(GraphicalTimetableView.this.getParent());
        getRouteDialog().showDialog(diagram);
    });
    popupMenu.add(routesEditMenuItem);
    popupMenu.add(jSeparator1);
    // NOI18N
    typesMenu.setText(ResourceLoader.getString("gt.type"));
    // NOI18N
    typesMenu.addItem(ResourceLoader.getString("gt.classic"), GTDraw.Type.CLASSIC);
    // NOI18N
    typesMenu.addItem(ResourceLoader.getString("gt.classic.station.stops"), GTDraw.Type.CLASSIC_STATION_STOPS);
    // NOI18N
    typesMenu.addItem(ResourceLoader.getString("gt.withtracks"), GTDraw.Type.WITH_TRACKS);
    typesMenu.setSelectedItem(GTDraw.Type.CLASSIC);
    typesMenu.addListener(value -> {
        settings.set(Key.TYPE, value);
        recreateDraw();
    });
    popupMenu.add(typesMenu);
    // NOI18N
    sizesMenu.setText(ResourceLoader.getString("gt.sizes"));
    popupMenu.add(sizesMenu);
    // NOI18N
    orientationMenu.setText(ResourceLoader.getString("gt.orientation"));
    // NOI18N
    orientationMenu.addItem(ResourceLoader.getString("gt.orientation.left.right"), GTOrientation.LEFT_RIGHT);
    // NOI18N
    orientationMenu.addItem(ResourceLoader.getString("gt.orientation.top.down"), GTOrientation.TOP_DOWN);
    orientationMenu.setSelectedItem(GTOrientation.LEFT_RIGHT);
    orientationMenu.addListener(value -> {
        settings.set(Key.ORIENTATION, value);
        setSettings(settings);
    });
    popupMenu.add(orientationMenu);
    orientationMenu.setVisible(false);
    // NOI18N
    preferencesMenu.setText(ResourceLoader.getString("gt.preferences"));
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.addigits"), Key.ARRIVAL_DEPARTURE_DIGITS);
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.extendedlines"), Key.EXTENDED_LINES);
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.trainnames"), Key.TRAIN_NAMES);
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.technological.time"), Key.TECHNOLOGICAL_TIME);
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.train.ends"), Key.TRAIN_ENDS);
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.ignore.time.limits"), Key.IGNORE_TIME_LIMITS);
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.to.train.scroll"), Key.TO_TRAIN_SCROLL);
    // NOI18N
    preferencesMenu.addItem(ResourceLoader.getString("gt.to.train.change.route"), Key.TO_TRAIN_CHANGE_ROUTE);
    preferencesMenu.addListener((value, selected) -> {
        settings.setOption(value, selected);
        // recreate draw
        recreateDraw();
    });
    popupMenu.add(preferencesMenu);
    routesMenu.addListener(route -> setRoute(route));
    javax.swing.JMenuItem zoomMenuItem = new javax.swing.JMenuItem(ResourceLoader.getString("gt.zoom"));
    zoomMenuItem.addActionListener(e -> {
        // select zoom
        GTViewZoomDialog dialog = new GTViewZoomDialog((Window) getTopLevelAncestor(), true);
        dialog.setLocationRelativeTo(getParent());
        Float oldZoom = settings.get(Key.ZOOM, Float.class);
        Float newZoom = dialog.showDialog(oldZoom);
        if (newZoom != null && newZoom.floatValue() != oldZoom.floatValue()) {
            settings.set(Key.ZOOM, newZoom);
            recreateDraw();
        }
    });
    popupMenu.add(zoomMenuItem);
    setDoubleBuffered(false);
    addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (!SwingUtilities.isLeftMouseButton(evt)) {
                return;
            }
            // collector/selector
            boolean selected = false;
            for (RegionCollector<?> collector : gtStorage.collectors()) {
                if (evt.getClickCount() % 2 == 0) {
                    // indicates double click
                    if (collector.editSelected()) {
                        break;
                    }
                } else {
                    if (!selected) {
                        selected = collector.selectItemsRadiuses(evt.getX(), evt.getY(), 2, SELECTION_RADIUS);
                    } else {
                        collector.deselectItems();
                    }
                }
            }
            repaint();
        }
    });
    java.awt.event.MouseAdapter motionListener = new java.awt.event.MouseAdapter() {

        @Override
        public void mouseExited(MouseEvent e) {
            handle(e, MouseAction.EXIT);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            handle(e, MouseAction.ENTER);
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            handle(e, MouseAction.MOVE);
        }

        private void handle(MouseEvent e, MouseAction action) {
            MouseOverHandler moh = gtStorage.getParameter(MOUSE_OVER_HANDLER_KEY, MouseOverHandler.class);
            if (moh != null) {
                RegionCollector<TimeInterval> collector = getRegionCollector(TimeInterval.class);
                if (collector != null) {
                    List<TimeInterval> items = collector.getItemsForPointRadiuses(e.getX(), e.getY(), 2, SELECTION_RADIUS);
                    moh.mouseOverIntervals(items);
                }
            }
        }
    };
    addMouseListener(motionListener);
    addMouseMotionListener(motionListener);
    setLayout(null);
}
Also used : RegionCollector(net.parostroj.timetable.output2.gt.RegionCollector) JMenuItem(javax.swing.JMenuItem) JMenuItem(javax.swing.JMenuItem) MouseEvent(java.awt.event.MouseEvent) TimeInterval(net.parostroj.timetable.model.TimeInterval) MouseEvent(java.awt.event.MouseEvent) GTViewZoomDialog(net.parostroj.timetable.gui.dialogs.GTViewZoomDialog)

Example 4 with Settings

use of net.parostroj.timetable.output2.OutputWriter.Settings in project grafikon by jub77.

the class OutputWriter method createOutputs.

private List<OutputSettings> createOutputs(net.parostroj.timetable.model.Output modelOutput) throws OutputException {
    OutputTemplate template = modelOutput.getTemplate();
    List<OutputSettings> result = null;
    if (template.getScript() != null) {
        final List<OutputSettings> out = new ArrayList<>();
        Map<String, Object> binding = new HashMap<>();
        binding.put("diagram", diagram);
        binding.put("output", modelOutput);
        binding.put("log", scriptLog);
        binding.put("settings", new WrapperLogMap<>(modelOutput.getSettings().getAttributesMap(net.parostroj.timetable.model.Output.CATEGORY_SETTINGS), scriptLog, "settings"));
        binding.put("localization", new WrapperLogMap<>(template.getAttributes().getAttributesMap(OutputTemplate.CATEGORY_I18N), scriptLog, "localization"));
        binding.put("locale", modelOutput.getLocale() != null ? modelOutput.getLocale() : settings.getLocale());
        binding.put("key", getOutputKey(modelOutput));
        binding.put("selection", modelOutput.getSelection());
        binding.put("util", new OutputUtil());
        binding.put("outputs", new OutputCollector() {

            @Override
            public void add(String name, Map<String, Object> context) {
                out.add(new OutputSettings().setName(name).setContext(context));
            }

            @Override
            public void add(String name, Map<String, Object> context, String encoding) {
                out.add(new OutputSettings().setName(name).setContext(context).setEncoding(encoding));
            }

            @Override
            public OutputSettings create() {
                OutputSettings lSettings = new OutputSettings();
                out.add(lSettings);
                return lSettings;
            }
        });
        try {
            template.getScript().evaluateWithException(binding);
        } catch (GrafikonException e) {
            throw new OutputException("Error in script: " + e.getMessage(), e);
        }
        result = out;
    }
    return result;
}
Also used : OutputUtil(net.parostroj.timetable.output2.util.OutputUtil)

Example 5 with Settings

use of net.parostroj.timetable.output2.OutputWriter.Settings in project grafikon by jub77.

the class OutputWriter method updateContext.

private Map<String, Object> updateContext(net.parostroj.timetable.model.Output modelOutput, OutputTemplate outputTemplate, Map<String, Object> context) {
    Map<String, Object> usedContext = context;
    if (usedContext == null)
        usedContext = new HashMap<>();
    usedContext.put("settings", new WrapperLogMap<>(modelOutput.getSettings().getAttributesMap(net.parostroj.timetable.model.Output.CATEGORY_SETTINGS), templateLog, "settings"));
    usedContext.put("localization", new WrapperLogMap<>(outputTemplate.getAttributes().getAttributesMap(OutputTemplate.CATEGORY_I18N), templateLog, "localization"));
    usedContext.put("selection", modelOutput.getSelection());
    usedContext.put("util", new OutputUtil());
    return usedContext;
}
Also used : OutputUtil(net.parostroj.timetable.output2.util.OutputUtil)

Aggregations

CloseableFileChooser (net.parostroj.timetable.gui.actions.impl.CloseableFileChooser)2 OutputSettings (net.parostroj.timetable.gui.data.OutputSettings)2 Settings (net.parostroj.timetable.output2.OutputWriter.Settings)2 OutputUtil (net.parostroj.timetable.output2.util.OutputUtil)2 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 JMenuItem (javax.swing.JMenuItem)1 FileChooserFactory (net.parostroj.timetable.gui.actions.impl.FileChooserFactory)1 GTViewZoomDialog (net.parostroj.timetable.gui.dialogs.GTViewZoomDialog)1 GenerateOutputPM (net.parostroj.timetable.gui.pm.GenerateOutputPM)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 LSFile (net.parostroj.timetable.model.ls.LSFile)1 RegionCollector (net.parostroj.timetable.output2.gt.RegionCollector)1