Search in sources :

Example 1 with LocalizedString

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

the class NodeDelegateTypeImpl method getNodeText.

@Override
public String getNodeText(TrainTreeNode trainTreeNode) {
    TrainType type = (TrainType) trainTreeNode.getUserObject();
    LocalizedString desc = type != null ? type.getDesc() : null;
    return type != null ? (desc != null ? desc.translate() : type.getDefaultAbbr()) : "-";
}
Also used : TrainType(net.parostroj.timetable.model.TrainType) LocalizedString(net.parostroj.timetable.model.LocalizedString)

Example 2 with LocalizedString

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

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

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

the class LocalizedStringPM method initImpl.

private LolizationEditResult initImpl(LocalizedString string, Collection<Locale> availableLocales, boolean editable) {
    if (currentResult != null) {
        currentResult.finishBuild();
        currentResult = null;
    }
    if (string == null) {
        this.strings.clear();
        this.string.setText(null);
        this.string.setEditable(false);
        return null;
    }
    this.string.setEditable(true);
    currentResult = editable ? new EditResultImpl() : null;
    Collection<Locale> stringLocales = string.getLocales();
    Set<Locale> locales = new HashSet<>(availableLocales);
    locales.addAll(stringLocales);
    strings.clear();
    for (Locale locale : locales) {
        String text = string.getLocalizedString(locale);
        strings.add(new StringWithLocalePM(text, locale));
    }
    this.string.setText(string.getDefaultString());
    strings.sortBy(Arrays.asList(new SortKey(true, new Path("locale"))));
    return currentResult;
}
Also used : StringWithLocale(net.parostroj.timetable.model.LocalizedString.StringWithLocale) Locale(java.util.Locale) Path(org.beanfabrics.Path) SortKey(org.beanfabrics.model.SortKey) LocalizedString(net.parostroj.timetable.model.LocalizedString) HashSet(java.util.HashSet)

Example 5 with LocalizedString

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

the class EditOutputsDialog method edit.

@Override
protected void edit(Output item) {
    EditOutputDialog dialog = new EditOutputDialog(this, true);
    dialog.setLocationRelativeTo(this);
    dialog.registerContext(context);
    LocalizedString oldName = item.getName();
    OutputPM pModel = new OutputPM(getPresentationModel().getLocales(), getPresentationModel().getModelLocales());
    dialog.setPresentationModel(pModel);
    pModel.init(element, item);
    dialog.setVisible(true);
    dialog.dispose();
    // refresh item(s)
    if (!oldName.equals(item.getName())) {
        refreshAll();
    }
}
Also used : GenerateOutputPM(net.parostroj.timetable.gui.pm.GenerateOutputPM) OutputPM(net.parostroj.timetable.gui.pm.OutputPM) LocalizedString(net.parostroj.timetable.model.LocalizedString)

Aggregations

LocalizedString (net.parostroj.timetable.model.LocalizedString)10 TimeInterval (net.parostroj.timetable.model.TimeInterval)3 TrainType (net.parostroj.timetable.model.TrainType)2 Color (java.awt.Color)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 GenerateOutputPM (net.parostroj.timetable.gui.pm.GenerateOutputPM)1 OutputPM (net.parostroj.timetable.gui.pm.OutputPM)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 GrafikonException (net.parostroj.timetable.model.GrafikonException)1 LineTrack (net.parostroj.timetable.model.LineTrack)1 StringWithLocale (net.parostroj.timetable.model.LocalizedString.StringWithLocale)1 NodeTrack (net.parostroj.timetable.model.NodeTrack)1 TimeConverter (net.parostroj.timetable.model.TimeConverter)1 Track (net.parostroj.timetable.model.Track)1 Train (net.parostroj.timetable.model.Train)1 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)1