Search in sources :

Example 1 with TrainPath

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

the class FreightTrainPathPanel method updateView.

public void updateView(Node from, Node to, int shuntDuration, int startTime) {
    // update selection
    if (fromNode.getSelectedObject() != from) {
        fromNode.setSelectedObject(from);
    }
    if (toNode.getSelectedObject() != to) {
        toNode.setSelectedObject(to);
    }
    tableModel.clear();
    stateIconLabel.setIcon(null);
    if (from != null && to != null && from != to) {
        DataModel model = new DataModel();
        RxActionHandler.getInstance().newExecution("freight_path", GuiComponentUtils.getTopLevelComponent(this), diagram).addConsumer((c, diagram) -> {
            c.setWaitMessage(ResourceLoader.getString("wait.message.processing"));
            c.setWaitDialogVisible(true);
        }).onBackground().addConsumer((c, diagram) -> {
            FreightConnectionAnalyser connectionAnalyser = new FreightConnectionAnalyser(diagram.getFreightNet().getConnectionStrategy());
            Set<NodeFreightConnection> conns = connectionAnalyser.analyse(from, to);
            TrainPath trainPath = connectionAnalyser.getTrainPath(conns, startTime, shuntDuration);
            stateIconLabel.setIcon(!trainPath.isEmpty() ? okIcon : errorIcon);
            Integer time = null;
            for (TrainConnection tc : trainPath) {
                String right = convertConnectionTrain(tc);
                String left = convertNode(tc.getFrom().getOwnerAsNode(), time == null ? null : TimeUtil.difference(time, tc.getStartTime()));
                time = tc.getEndTime();
                model.addLine(left, right);
            }
            if (!trainPath.isEmpty()) {
                model.addLine(convertNode(to, null), "");
            }
        }).onEdt().addConsumer((c, diagram) -> {
            tableModel.addLines(model);
            adjustColumnWidth.run();
        }).execute();
    }
}
Also used : JTextField(javax.swing.JTextField) LoggerFactory(org.slf4j.LoggerFactory) ItemListener(java.awt.event.ItemListener) Node(net.parostroj.timetable.model.Node) DestinationTableModel(net.parostroj.timetable.gui.components.FreightDestinationPanel.DestinationTableModel) ResourceLoader(net.parostroj.timetable.gui.utils.ResourceLoader) ImageIcon(javax.swing.ImageIcon) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) FlowLayout(java.awt.FlowLayout) ItemEvent(java.awt.event.ItemEvent) JButton(javax.swing.JButton) Logger(org.slf4j.Logger) WrapperListModel(net.parostroj.timetable.gui.wrappers.WrapperListModel) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) TrainConnection(net.parostroj.timetable.model.freight.TrainConnection) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) FreightConnectionAnalyser(net.parostroj.timetable.model.freight.FreightConnectionAnalyser) JScrollPane(javax.swing.JScrollPane) DataModel(net.parostroj.timetable.gui.components.FreightDestinationPanel.DataModel) TrainPath(net.parostroj.timetable.model.freight.TrainPath) GuiIcon(net.parostroj.timetable.gui.utils.GuiIcon) JLabel(javax.swing.JLabel) JTable(javax.swing.JTable) RxActionHandler(net.parostroj.timetable.gui.actions.execution.RxActionHandler) ColumnAdjuster(net.parostroj.timetable.gui.components.FreightDestinationPanel.ColumnAdjuster) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) JPanel(javax.swing.JPanel) NodeFreightConnection(net.parostroj.timetable.model.freight.NodeFreightConnection) TimeUtil(net.parostroj.timetable.utils.TimeUtil) Set(java.util.Set) DataModel(net.parostroj.timetable.gui.components.FreightDestinationPanel.DataModel) TrainConnection(net.parostroj.timetable.model.freight.TrainConnection) TrainPath(net.parostroj.timetable.model.freight.TrainPath) FreightConnectionAnalyser(net.parostroj.timetable.model.freight.FreightConnectionAnalyser)

Aggregations

BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 Set (java.util.Set)1 BorderFactory (javax.swing.BorderFactory)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 RxActionHandler (net.parostroj.timetable.gui.actions.execution.RxActionHandler)1 ColumnAdjuster (net.parostroj.timetable.gui.components.FreightDestinationPanel.ColumnAdjuster)1 DataModel (net.parostroj.timetable.gui.components.FreightDestinationPanel.DataModel)1 DestinationTableModel (net.parostroj.timetable.gui.components.FreightDestinationPanel.DestinationTableModel)1 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)1 GuiIcon (net.parostroj.timetable.gui.utils.GuiIcon)1