Search in sources :

Example 1 with NodeFreightConnection

use of net.parostroj.timetable.model.freight.NodeFreightConnection 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)

Example 2 with NodeFreightConnection

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

the class FreightComboBoxHelper method updateView.

public void updateView(Node from, Node to) {
    // 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_conn", 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());
            NodeFreightConnection ncf = connectionAnalyser.analyse(from, to).stream().min(Comparator.comparingInt(NodeFreightConnection::getLength)).get();
            stateIconLabel.setIcon(ncf.isComplete() ? okIcon : errorIcon);
            ncf.getSteps().forEach(s -> {
                List<String> list = convertStep(s);
                String node = convertNode(s.getFrom());
                for (String item : list) {
                    model.addLine(node, item);
                    node = null;
                }
            });
            if (ncf.isComplete()) {
                model.addLine(convertNode(to), "");
            } else {
                List<DirectNodeConnection> steps = ncf.getSteps();
                if (steps != null && !steps.isEmpty()) {
                    model.addLine(convertNode(steps.get(steps.size() - 1).getTo()), "");
                }
            }
        }).onEdt().addConsumer((c, diagram) -> {
            tableModel.addLines(model);
            adjustColumnWidth.run();
        }).execute();
    }
}
Also used : DirectNodeConnection(net.parostroj.timetable.model.freight.DirectNodeConnection) 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) WrapperListModel(net.parostroj.timetable.gui.wrappers.WrapperListModel) Iterator(java.util.Iterator) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) TrainConnection(net.parostroj.timetable.model.freight.TrainConnection) BorderFactory(javax.swing.BorderFactory) FreightConnectionAnalyser(net.parostroj.timetable.model.freight.FreightConnectionAnalyser) JScrollPane(javax.swing.JScrollPane) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) DataModel(net.parostroj.timetable.gui.components.FreightDestinationPanel.DataModel) Type(net.parostroj.timetable.model.events.Event.Type) 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) Comparator(java.util.Comparator) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) JPanel(javax.swing.JPanel) NodeFreightConnection(net.parostroj.timetable.model.freight.NodeFreightConnection) TimeUtil(net.parostroj.timetable.utils.TimeUtil) NodeFreightConnection(net.parostroj.timetable.model.freight.NodeFreightConnection) DataModel(net.parostroj.timetable.gui.components.FreightDestinationPanel.DataModel) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) FreightConnectionAnalyser(net.parostroj.timetable.model.freight.FreightConnectionAnalyser)

Aggregations

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