Search in sources :

Example 1 with GTViewZoomDialog

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

Aggregations

MouseEvent (java.awt.event.MouseEvent)1 JMenuItem (javax.swing.JMenuItem)1 GTViewZoomDialog (net.parostroj.timetable.gui.dialogs.GTViewZoomDialog)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 RegionCollector (net.parostroj.timetable.output2.gt.RegionCollector)1