Search in sources :

Example 6 with TimeInterval

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

the class NormalHTS method regionsSelected.

@Override
public boolean regionsSelected(List<TimeInterval> intervals) {
    selection = true;
    try {
        TimeInterval interval = SelectorUtils.select(intervals, selectedTimeInterval, SelectorUtils.createUniqueTrainIntervalFilter());
        // set selected train
        Train selected = interval != null ? interval.getTrain() : null;
        set = selected == null ? Collections.<Train>emptySet() : Collections.singleton(selected);
        model.setSelectedTrain(selected);
        selectedTimeInterval = interval;
        if (!appEvent) {
            model.getMediator().sendMessage(new IntervalSelectionMessage(interval));
        }
        return interval != null;
    } finally {
        selection = false;
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) Train(net.parostroj.timetable.model.Train)

Example 7 with TimeInterval

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

the class LocalizationTypeFactory method getTimeIntervalDesc.

private static String getTimeIntervalDesc(Reference<LocalizedString> ref) {
    TimeInterval interval = (TimeInterval) ((AttributeReference<?>) ref).getHolder();
    String trainDesc = interval.getTrain().getDefaultName();
    String nodeDesc = interval.getOwnerAsNode().getName();
    return String.format("%s (%s)", trainDesc, nodeDesc);
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) LocalizedString(net.parostroj.timetable.model.LocalizedString)

Example 8 with TimeInterval

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

the class TrainTableModel method getValueAt.

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    TimeInterval interval = train.getTimeIntervalList().get(rowIndex);
    TrainDiagram diagram = train.getDiagram();
    Object retValue = null;
    TrainTableColumn column = TrainTableColumn.getColumn(columnIndex);
    switch(column) {
        // node name
        case NODE:
            if (interval.isNodeOwner()) {
                retValue = interval.getOwnerAsNode().getName();
            } else {
                retValue = "";
            }
            break;
        // arrival
        case START:
            if (!interval.isFirst()) {
                retValue = converter.convertIntToText(interval.getStart(), true);
            }
            break;
        // departure
        case END:
            if (!interval.isLast()) {
                retValue = converter.convertIntToText(interval.getEnd(), true);
            }
            break;
        // stop time
        case STOP:
            if (interval.isNodeOwner() && rowIndex != 0 && rowIndex != lastRow && interval.getOwnerAsNode().getType() != NodeType.SIGNAL) {
                retValue = converter.convertIntToMinutesText(interval.getLength());
            }
            break;
        // speed
        case SPEED_LIMIT:
            if (interval.isLineOwner()) {
                retValue = interval.getSpeedLimit();
            }
            break;
        // used speed
        case SPEED:
            retValue = interval.getSpeed();
            break;
        // added time
        case ADDED_TIME:
            if (interval.isLineOwner() && interval.getAddedTime() != 0) {
                retValue = converter.convertIntToMinutesText(interval.getAddedTime());
            }
            break;
        // platform
        case PLATFORM:
            if (interval.isNodeOwner()) {
                if (interval.getOwnerAsNode().getTracks().size() > 1) {
                    retValue = interval.getTrack();
                }
            } else if (interval.isLineOwner()) {
                // only for more than one track per line
                if (interval.getOwnerAsLine().getTracks().size() > 1) {
                    return interval.getTrack();
                }
            }
            break;
        // problems
        case CONFLICTS:
            StringBuilder builder = new StringBuilder();
            for (TimeInterval overlap : interval.getOverlappingIntervals()) {
                if (builder.length() != 0) {
                    builder.append(", ");
                }
                builder.append(overlap.getTrain().getDefaultName());
            }
            retValue = builder.toString();
            break;
        // comment
        case COMMENT:
            LocalizedString lComment = interval.getComment();
            retValue = lComment == null ? null : lComment.getDefaultString();
            break;
        case OCCUPIED_ENTRY:
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_OCCUPIED);
            break;
        case SHUNT:
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_SHUNT);
            break;
        case COMMENT_SHOWN:
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_COMMENT_SHOWN);
            break;
        case REAL_STOP:
            if (interval.isNodeOwner() && rowIndex != 0 && rowIndex != lastRow && interval.getOwnerAsNode().getType() != NodeType.SIGNAL) {
                int stop = interval.getLength() / 60;
                // celculate with time scale ...
                Double timeScale = diagram.getAttributes().get(TrainDiagram.ATTR_TIME_SCALE, Double.class);
                retValue = stop / timeScale;
            }
            break;
        case WEIGHT:
            // weight info
            if (interval.isLineOwner()) {
                retValue = TrainsHelper.getWeight(interval);
            }
            break;
        case LENGTH:
            // length info
            retValue = TrainsHelper.getLength(interval);
            break;
        case SET_SPEED:
            // train speed
            retValue = interval.getAttribute(TimeInterval.ATTR_SET_SPEED, Object.class);
            break;
        case IGNORE_LENGTH:
            // ignore station length
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_IGNORE_LENGTH);
            break;
        case MANAGED_FREIGHT:
            // managed freight
            retValue = false;
            if (train.isManagedFreight() && interval.isNodeOwner()) {
                retValue = (interval.getLength() > 0 || rowIndex == 0 || rowIndex == lastRow) && !interval.getAttributeAsBool(TimeInterval.ATTR_NOT_MANAGED_FREIGHT);
            }
            break;
        case REGION_CENTER_TRANSFER:
            // transfer in region center
            retValue = false;
            if (interval.isNodeOwner() && train.isManagedFreight()) {
                if (interval.getOwnerAsNode().isCenterOfRegions() && !interval.getAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER) && rowIndex != 0) {
                    retValue = true;
                }
            }
            break;
        case FREIGHT_TO_STATIONS:
            FreightConnectionStrategy strategy = train.getDiagram().getFreightNet().getConnectionStrategy();
            if (rowIndex % 2 == 0 && (interval.isFreight() || interval.isFreightConnection())) {
                StringBuilder result = new StringBuilder();
                Map<Train, List<FreightConnectionPath>> passedCargoDst = strategy.getFreightPassedInNode(interval);
                for (Map.Entry<Train, List<FreightConnectionPath>> entry : passedCargoDst.entrySet()) {
                    List<FreightConnectionPath> mList = entry.getValue();
                    result.append('(').append(freightUtil.freightListToString(mList, Locale.getDefault()));
                    result.append(" > ").append(entry.getKey().getDefaultName()).append(')');
                }
                if (interval.isFreightFrom()) {
                    List<FreightConnectionPath> cargoDst = strategy.getFreightToNodes(interval);
                    List<FreightConnectionPath> mList = cargoDst;
                    if (!cargoDst.isEmpty() && result.length() > 0) {
                        result.append(' ');
                    }
                    result.append(freightUtil.freightListToString(mList, Locale.getDefault()));
                }
                retValue = result.toString();
            }
            break;
        // default (should not be reached)
        default:
            // nothing
            assert false : "Unexpected column";
            break;
    }
    return retValue;
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) FreightConnectionStrategy(net.parostroj.timetable.model.freight.FreightConnectionStrategy) LocalizedString(net.parostroj.timetable.model.LocalizedString) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) FreightConnectionPath(net.parostroj.timetable.model.freight.FreightConnectionPath) List(java.util.List) Train(net.parostroj.timetable.model.Train) Map(java.util.Map)

Example 9 with TimeInterval

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

the class TrainView method setModel.

public void setModel(final ApplicationModel model) {
    this.model = model;
    this.updateView(model.getSelectedTrain());
    this.model.addListener(this);
    ((TrainTableModel) trainTable.getModel()).setModel(model);
    model.getMediator().addColleague(message -> {
        IntervalSelectionMessage ism = (IntervalSelectionMessage) message;
        if (ism.getInterval() != null) {
            TimeInterval interval = ism.getInterval();
            Train trainForInterval = interval.getTrain();
            if (trainForInterval.getTimeIntervalBefore() == interval) {
                interval = trainForInterval.getFirstInterval();
            } else if (trainForInterval.getTimeIntervalAfter() == interval) {
                interval = trainForInterval.getLastInterval();
            }
            if (trainForInterval != TrainView.this.train) {
                updateView(trainForInterval);
            }
            int row = interval.getTrain().getTimeIntervalList().indexOf(interval);
            int column = TrainTableColumn.getIndex(trainTable.getColumnModel(), interval.isNodeOwner() ? TrainTableColumn.STOP : TrainTableColumn.SPEED_LIMIT);
            trainTable.setRowSelectionInterval(row, row);
            if (column != -1) {
                trainTable.setColumnSelectionInterval(column, column);
            }
            Rectangle rect = trainTable.getCellRect(row, 0, true);
            trainTable.scrollRectToVisible(rect);
            Component topLevelComponent = GuiComponentUtils.getTopLevelComponent(TrainView.this);
            if (topLevelComponent.hasFocus()) {
                trainTable.requestFocus();
            }
        }
    }, IntervalSelectionMessage.class);
    model.getMediator().addColleague(new GTEventsReceiverColleague() {

        @Override
        public void processTrainEvent(Event event) {
            Train selectedTrain = model.getSelectedTrain();
            if (event.getSource() == selectedTrain) {
                updateView(selectedTrain);
            }
        }
    }, Event.class);
}
Also used : IntervalSelectionMessage(net.parostroj.timetable.gui.utils.IntervalSelectionMessage) TimeInterval(net.parostroj.timetable.model.TimeInterval) GTEventsReceiverColleague(net.parostroj.timetable.mediator.GTEventsReceiverColleague) Rectangle(java.awt.Rectangle) Component(java.awt.Component) Train(net.parostroj.timetable.model.Train)

Example 10 with TimeInterval

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

the class TrainTimetablesExtractor method getConcurrentTrains.

private Pair<Boolean, List<TranslatedString>> getConcurrentTrains(TimeInterval interval) {
    TrainComparator comparator = diagram.getTrainsData().getTrainComparator();
    Node node = interval.getOwnerAsNode();
    TimeInterval toBeChecked = interval;
    Train train = interval.getTrain();
    if (interval.isFirst() && train.getTimeIntervalBefore() != null)
        toBeChecked = train.getTimeIntervalBefore();
    else if (interval.isLast() && train.getTimeIntervalAfter() != null)
        toBeChecked = train.getTimeIntervalAfter();
    Set<TimeInterval> over = node.getOverlappingTimeIntervals(toBeChecked);
    boolean first = true;
    // check if the train is first in the station (start be marked with trapezoid)
    if (!interval.isFirst())
        for (Iterator<TimeInterval> i = over.iterator(); i.hasNext(); ) {
            TimeInterval checked = i.next();
            if (interval.getStart() > checked.getStart() || (interval.getStart() == checked.getStart() && comparator.compare(interval.getTrain(), checked.getTrain()) >= 0)) {
                first = false;
                break;
            }
        }
    if (over.isEmpty()) {
        return null;
    } else {
        List<Train> tTrains = new ArrayList<>(over.size());
        for (TimeInterval ti : over) {
            if (!tTrains.contains(ti.getTrain()))
                tTrains.add(ti.getTrain());
        }
        ElementSort<Train> s = new ElementSort<>(new TrainComparator(node.getDiagram().getTrainsData().getTrainSortPattern()));
        tTrains = s.sort(tTrains);
        List<TranslatedString> result = new LinkedList<>();
        for (Train t : tTrains) {
            result.add(t.getName());
        }
        return new Pair<>(first, result);
    }
}
Also used : TranslatedString(net.parostroj.timetable.model.TranslatedString) TimeInterval(net.parostroj.timetable.model.TimeInterval) Node(net.parostroj.timetable.model.Node) ArrayList(java.util.ArrayList) ElementSort(net.parostroj.timetable.actions.ElementSort) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) TrainComparator(net.parostroj.timetable.actions.TrainComparator) Train(net.parostroj.timetable.model.Train) Pair(net.parostroj.timetable.utils.Pair)

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