Search in sources :

Example 1 with LengthUnit

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

the class NetItemConversionUtil method getLineLengthString.

public String getLineLengthString(Line line, LengthUnit defaultLengthUnit) {
    LengthUnit lengthUnit = line.getDiagram().getAttributes().get(TrainDiagram.ATTR_EDIT_LENGTH_UNIT, LengthUnit.class, defaultLengthUnit);
    BigDecimal cValue = lengthUnit.convertFrom(new BigDecimal(line.getLength()), LengthUnit.MM);
    return UnitUtil.convertToString("#0.###", cValue) + lengthUnit.getUnitsOfString();
}
Also used : LengthUnit(net.parostroj.timetable.model.units.LengthUnit) BigDecimal(java.math.BigDecimal)

Example 2 with LengthUnit

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

the class ApplicationModel method loadFromPreferences.

@Override
public IniConfigSection loadFromPreferences(IniConfig prefs) {
    guiContext.loadFromPreferences(prefs);
    IniConfigSection section = prefs.getSection("model");
    deserializeOutputTemplates(section.get("output.templates", ""));
    programSettings.setUserName(section.get("user.name"));
    LengthUnit lengthUnit = LengthUnit.getByKey(section.get("unit", "mm"));
    SpeedUnit speedUnit = SpeedUnit.getByKey(section.get("unit.speed", "kmph"));
    programSettings.setLengthUnit(lengthUnit != null ? lengthUnit : LengthUnit.MM);
    programSettings.setSpeedUnit(speedUnit != null ? speedUnit : SpeedUnit.KMPH);
    List<String> filenames = section.getAll("last.opened");
    if (filenames != null) {
        Collections.reverse(filenames);
        for (String filename : filenames) {
            if (filename != null) {
                this.addLastOpenedFile(new File(filename));
            }
        }
    }
    return section;
}
Also used : SpeedUnit(net.parostroj.timetable.model.units.SpeedUnit) IniConfigSection(net.parostroj.timetable.gui.ini.IniConfigSection) File(java.io.File) LengthUnit(net.parostroj.timetable.model.units.LengthUnit)

Example 3 with LengthUnit

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

the class TrainTimetablesExtractor method extractLengthData.

private void extractLengthData(Train train, TrainTimetable timetable) {
    if (train.getAttributes().getBool(Train.ATTR_SHOW_STATION_LENGTH)) {
        // compute maximal length
        Pair<Node, Integer> length = TrainsHelper.getNextLength(train.getStartNode(), train, TrainsHelper.NextType.LAST_STATION);
        if (length != null && length.second != null) {
            // get length unit
            LengthUnit lengthUnitObj = diagram.getAttribute(TrainDiagram.ATTR_LENGTH_UNIT, LengthUnit.class);
            LengthData data = new LengthData();
            data.setLength(length.second);
            data.setLengthInAxles(LengthUnit.AXLE == lengthUnitObj);
            data.setLengthUnit(lengthUnitObj);
            timetable.setLengthData(data);
        }
    }
}
Also used : Node(net.parostroj.timetable.model.Node) LengthUnit(net.parostroj.timetable.model.units.LengthUnit)

Example 4 with LengthUnit

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

the class LSAttributesItem method extractSimpleValue.

private LSAttributesValue extractSimpleValue(String key, Object value) {
    LSAttributesValue cValue = null;
    if (value instanceof String) {
        cValue = new LSAttributesValue((String) value, "string");
    } else if (value instanceof Boolean) {
        cValue = new LSAttributesValue(value.toString(), "boolean");
    } else if (value instanceof Integer) {
        cValue = new LSAttributesValue(value.toString(), "integer");
    } else if (value instanceof Long) {
        cValue = new LSAttributesValue(value.toString(), "long");
    } else if (value instanceof Float) {
        cValue = new LSAttributesValue(value.toString(), "float");
    } else if (value instanceof Double) {
        cValue = new LSAttributesValue(value.toString(), "double");
    } else if (value instanceof Scale) {
        cValue = new LSAttributesValue(value.toString(), "scale");
    } else if (value instanceof FreightColor) {
        cValue = new LSAttributesValue(((FreightColor) value).getKey(), "freight.color");
    } else if (value instanceof LengthUnit) {
        cValue = new LSAttributesValue(((LengthUnit) value).getKey(), "length.unit");
    } else if (value instanceof WeightUnit) {
        cValue = new LSAttributesValue(((WeightUnit) value).getKey(), "weight.unit");
    } else if (value instanceof Locale) {
        cValue = new LSAttributesValue(((Locale) value).toLanguageTag(), "locale");
    } else if (value instanceof TextTemplate) {
        TextTemplate tt = (TextTemplate) value;
        cValue = new LSAttributesValue(tt.getTemplate(), TEXT_TEMPLATE_KEY_PREFIX + tt.getLanguage().name());
    } else if (value instanceof Script) {
        Script script = (Script) value;
        cValue = new LSAttributesValue(script.getSourceCode(), SCRIPT_KEY_PREFIX + script.getLanguage().name());
    } else if (value instanceof ObjectWithId) {
        Pair<String, String> pair = this.convertToId((ObjectWithId) value);
        cValue = new LSAttributesValue(pair.second, pair.first);
    } else if (value instanceof StringWithLocale) {
        StringWithLocale stringWithLocale = (StringWithLocale) value;
        cValue = new LSAttributesValue(stringWithLocale.getString(), "string." + stringWithLocale.getLocale().toLanguageTag());
    } else {
        log.warn("Cannot convert value to string: {}", key);
    }
    return cValue;
}
Also used : StringWithLocale(net.parostroj.timetable.model.LocalizedString.StringWithLocale) WeightUnit(net.parostroj.timetable.model.units.WeightUnit) LengthUnit(net.parostroj.timetable.model.units.LengthUnit) StringWithLocale(net.parostroj.timetable.model.LocalizedString.StringWithLocale) Pair(net.parostroj.timetable.utils.Pair)

Example 5 with LengthUnit

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

the class EditLineDialog method showDialog.

public void showDialog(Line line, LengthUnit lengthUnit) {
    this.line = line;
    TrainDiagram diagram = line.getDiagram();
    lengthEditBox.setUnit(diagram.getAttributes().get(TrainDiagram.ATTR_EDIT_LENGTH_UNIT, LengthUnit.class, lengthUnit));
    // update track for from and to (direct)
    Node from = line.getFrom();
    Node to = line.getTo();
    fromToLabel.setText(from.getName() + " - " + to.getName());
    fromDirectTrackComboBox.removeAllItems();
    toDirectTrackComboBox.removeAllItems();
    fromDirectTrackComboBox.addItem(noneTrack);
    toDirectTrackComboBox.addItem(noneTrack);
    for (NodeTrack track : from.getTracks()) {
        fromDirectTrackComboBox.addItem(track);
    }
    for (NodeTrack track : to.getTracks()) {
        toDirectTrackComboBox.addItem(track);
    }
    if (line.getTopSpeed() == null) {
        speedTextField.setText("");
    } else {
        speedTextField.setText(Integer.toString(line.getTopSpeed()));
    }
    lengthEditBox.setValueInUnit(new BigDecimal(line.getLength()), LengthUnit.MM);
    controlledCheckBox.setSelected(Boolean.TRUE.equals(line.getAttribute(Line.ATTR_CONTROLLED, Boolean.class)));
    // update line class combo box
    List<LineClass> classes = line.getDiagram().getNet().getLineClasses();
    lineClassComboBox.removeAllItems();
    lineClassComboBox.addItem(noneLineClass);
    for (LineClass clazz : classes) {
        lineClassComboBox.addItem(clazz);
    }
    if (line.getAttribute(Line.ATTR_CLASS, LineClass.class) == null)
        lineClassComboBox.setSelectedItem(noneLineClass);
    else
        lineClassComboBox.setSelectedItem(line.getAttribute(Line.ATTR_CLASS, LineClass.class));
    // update line class back combo box
    lineClassBackComboBox.removeAllItems();
    lineClassBackComboBox.addItem(noneLineClass);
    for (LineClass clazz : classes) lineClassBackComboBox.addItem(clazz);
    if (line.getAttribute(Line.ATTR_CLASS_BACK, LineClass.class) == null)
        lineClassBackComboBox.setSelectedItem(lineClassComboBox.getSelectedItem());
    else
        lineClassBackComboBox.setSelectedItem(line.getAttribute(Line.ATTR_CLASS_BACK, LineClass.class));
    this.updateTracks();
    this.pack();
    this.setVisible(true);
}
Also used : LengthUnit(net.parostroj.timetable.model.units.LengthUnit) BigDecimal(java.math.BigDecimal)

Aggregations

LengthUnit (net.parostroj.timetable.model.units.LengthUnit)10 BigDecimal (java.math.BigDecimal)4 Node (net.parostroj.timetable.model.Node)2 Train (net.parostroj.timetable.model.Train)2 TrainType (net.parostroj.timetable.model.TrainType)2 File (java.io.File)1 LinkedList (java.util.LinkedList)1 IniConfigSection (net.parostroj.timetable.gui.ini.IniConfigSection)1 Attributes (net.parostroj.timetable.model.Attributes)1 StringWithLocale (net.parostroj.timetable.model.LocalizedString.StringWithLocale)1 TextItem (net.parostroj.timetable.model.TextItem)1 TranslatedString (net.parostroj.timetable.model.TranslatedString)1 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)1 SpeedUnit (net.parostroj.timetable.model.units.SpeedUnit)1 WeightUnit (net.parostroj.timetable.model.units.WeightUnit)1 Pair (net.parostroj.timetable.utils.Pair)1