Search in sources :

Example 16 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class FreightDestinationPanel method addFreightTrainUnitsFromNode.

private void addFreightTrainUnitsFromNode(DataModel model, Node node, FreightAnalyser analyser) {
    Locale locale = Locale.getDefault();
    List<TimeInterval> intervals = analyser.getFreightTrainUnitIntervals(node);
    List<Tuple<String>> trains = intervals.stream().map(i -> new Tuple<>(util.intervalToString(diagram, i, locale), util.intervalFreightTrainUnitToString(diagram, i).stream().collect(Collectors.joining(", ")))).collect(Collectors.toList());
    model.addLinesWithEmpty(trains);
}
Also used : Locale(java.util.Locale) TableColumnModel(javax.swing.table.TableColumnModel) OutputFreightUtil(net.parostroj.timetable.output2.util.OutputFreightUtil) TableCellRenderer(javax.swing.table.TableCellRenderer) Node(net.parostroj.timetable.model.Node) ArrayList(java.util.ArrayList) TimeInterval(net.parostroj.timetable.model.TimeInterval) ResourceLoader(net.parostroj.timetable.gui.utils.ResourceLoader) Locale(java.util.Locale) AbstractTableModel(javax.swing.table.AbstractTableModel) NodeFreight(net.parostroj.timetable.model.freight.NodeFreight) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) Collator(java.text.Collator) FlowLayout(java.awt.FlowLayout) ItemEvent(java.awt.event.ItemEvent) JButton(javax.swing.JButton) WrapperListModel(net.parostroj.timetable.gui.wrappers.WrapperListModel) Collection(java.util.Collection) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) JScrollPane(javax.swing.JScrollPane) List(java.util.List) GuiIcon(net.parostroj.timetable.gui.utils.GuiIcon) Tuple(net.parostroj.timetable.utils.Tuple) JTable(javax.swing.JTable) RxActionHandler(net.parostroj.timetable.gui.actions.execution.RxActionHandler) Comparator(java.util.Comparator) FreightAnalyser(net.parostroj.timetable.model.freight.FreightAnalyser) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) JPanel(javax.swing.JPanel) TimeInterval(net.parostroj.timetable.model.TimeInterval) Tuple(net.parostroj.timetable.utils.Tuple)

Example 17 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class TCItemChangeDialog method updateFromTo.

private void updateFromTo(List<TimeInterval> intervals, TimeInterval from, TimeInterval to) {
    fromComboBox.removeAllItems();
    toComboBox.removeAllItems();
    for (TimeInterval interval : intervals) {
        if (interval.isNodeOwner()) {
            Wrapper<TimeInterval> w = new Wrapper<>(interval);
            fromComboBox.addItem(w);
            toComboBox.addItem(w);
        }
    }
    fromComboBox.setSelectedItem(new Wrapper<>(from));
    toComboBox.setSelectedItem(new Wrapper<>(to));
}
Also used : Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) TimeInterval(net.parostroj.timetable.model.TimeInterval)

Example 18 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval 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 19 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class TrackCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    ignoreAction = true;
    editor.removeAllItems();
    TimeInterval interval = ((TrainTableModel) table.getModel()).getTrain().getTimeIntervalList().get(row);
    List<? extends Track> tracks = interval.getOwner().getTracks();
    for (Track track : tracks) {
        editor.addItem(track);
    }
    editor.setSelectedItem(interval.getTrack());
    ignoreAction = false;
    return editor;
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) Track(net.parostroj.timetable.model.Track)

Example 20 with TimeInterval

use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.

the class PreviousNextTrainValidator method checkAndUpdateTrackAndTimeAfter.

private void checkAndUpdateTrackAndTimeAfter(Train currentTrain, Train newNextTrain) {
    if (newNextTrain != null) {
        TimeInterval source = currentTrain.getLastInterval();
        TimeInterval dest = newNextTrain.getFirstInterval();
        checkAndUpdateTrack(source, dest);
        checkAndUpdateTimeAfter(currentTrain);
    } else {
        currentTrain.setTimeAfter(0);
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval)

Aggregations

TimeInterval (net.parostroj.timetable.model.TimeInterval)26 Train (net.parostroj.timetable.model.Train)9 ArrayList (java.util.ArrayList)6 Node (net.parostroj.timetable.model.Node)6 List (java.util.List)5 LinkedList (java.util.LinkedList)4 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)4 Component (java.awt.Component)3 Collection (java.util.Collection)3 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)3 FNConnection (net.parostroj.timetable.model.FNConnection)3 LocalizedString (net.parostroj.timetable.model.LocalizedString)3 TranslatedString (net.parostroj.timetable.model.TranslatedString)3 Pair (net.parostroj.timetable.utils.Pair)3 BorderLayout (java.awt.BorderLayout)2 FlowLayout (java.awt.FlowLayout)2 Rectangle (java.awt.Rectangle)2 Shape (java.awt.Shape)2 ItemEvent (java.awt.event.ItemEvent)2 Collator (java.text.Collator)2