use of net.parostroj.timetable.model.LocalizedString in project grafikon by jub77.
the class TCItemChangeDialog method updateValues.
private void updateValues(TrainsCycleItem item) {
this.updateFromTo(item.getTrain().getTimeIntervalList(), item.getFromInterval(), item.getToInterval());
LocalizedString lComment = item.getComment();
commentTextField.getPresentationModel().init(lComment == null ? LocalizedString.fromString("") : lComment, item.getCycle().getDiagram().getLocales());
Integer setupTime = item.getSetupTime();
if (setupTimeTextField != null) {
setupTimeTextField.setText(setupTime == null ? null : Integer.toString(setupTime / TimeInterval.MINUTE));
}
}
use of net.parostroj.timetable.model.LocalizedString in project grafikon by jub77.
the class TrainsCycleItemWrapperDelegate method toStringItem.
public String toStringItem(TrainsCycleItem item) {
TimeConverter c = item.getTrain().getDiagram().getTimeConverter();
String str = String.format("%s (%s[%s],%s[%s])", item.getTrain().getDefaultName(), item.getFromInterval().getOwnerAsNode().getName(), this.getStartTime(c, item), item.getToInterval().getOwnerAsNode().getName(), c.convertIntToText(item.getEndTime()));
LocalizedString lComment = item.getComment();
String comment = ObjectsUtil.checkAndTrim(lComment == null ? null : lComment.getDefaultString());
if (showComment && comment != null) {
str = String.format("%s - %s", str, comment);
}
return str;
}
use of net.parostroj.timetable.model.LocalizedString in project grafikon by jub77.
the class TrainTypeDialog method updateButtonActionPerformed.
private void updateButtonActionPerformed() {
// update values of a type
TrainType type = trainType;
if (type != null) {
LocalizedString abbr = abbrTextField.getPresentationModel().getCurrentEdit().get();
LocalizedString desc = descTextField.getPresentationModel().getCurrentEdit().get();
// check values ....
if (abbr == null || desc == null) {
GuiComponentUtils.showError("dialog.error.missingvalues", this);
return;
}
type.setAbbr(abbr);
type.setDesc(desc);
type.setPlatform(platformNeededCheckBox.isSelected());
type.getAttributes().setBool(TrainType.ATTR_SHOW_WEIGHT_INFO, showWeightInfoCheckBox.isSelected());
Color c = Conversions.convertTextToColor(colorLabel.getText());
type.setColor(c);
Wrapper<?> categoryWrapper = (Wrapper<?>) brakeComboBox.getSelectedItem();
type.setCategory(categoryWrapper != NONE_CATEGORY ? (TrainTypeCategory) categoryWrapper.getElement() : null);
if (nameTemplateCheckBox.isSelected()) {
try {
type.setTrainNameTemplate(nameTemplateEditBox.getTemplate());
} catch (GrafikonException e) {
GuiComponentUtils.showWarning(e.getMessage(), this);
log.warn(e.getMessage(), e);
return;
}
} else {
type.setTrainNameTemplate(null);
}
if (completeNameTemplateCheckBox.isSelected()) {
try {
type.setTrainCompleteNameTemplate(cNameTemplateEditBox.getTemplate());
} catch (GrafikonException e) {
GuiComponentUtils.showWarning(e.getMessage(), this);
log.warn(e.getMessage(), e);
return;
}
} else {
type.setTrainCompleteNameTemplate(null);
}
type.getAttributes().setRemove(TrainType.ATTR_LINE_TYPE, extractLineType());
type.getAttributes().setRemove(TrainType.ATTR_LINE_WIDTH, extractRatioFromPercentage(lineWidthTextField));
type.getAttributes().setRemove(TrainType.ATTR_LINE_LENGTH, extractRatioFromPercentage(lineLengthTextField));
}
setVisible(false);
}
use of net.parostroj.timetable.model.LocalizedString in project grafikon by jub77.
the class LocalizationTypeFactory method getCirculationItemDesc.
private static String getCirculationItemDesc(Reference<LocalizedString> ref) {
TrainsCycleItem circulationItem = (TrainsCycleItem) ((AttributeReference<?>) ref).getHolder();
String circDesc = circulationItem.getCycle().getDisplayDescription();
String trainDesc = circulationItem.getTrain().getDefaultName();
return String.format("%s (%s: %s)", trainDesc, circulationItem.getCycle().getName(), circDesc);
}
use of net.parostroj.timetable.model.LocalizedString in project grafikon by jub77.
the class TrainTableModel method setValueAt.
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
int time = 0;
editBlock = true;
TimeInterval interval = train.getTimeIntervalList().get(rowIndex);
TrainTableColumn column = TrainTableColumn.getColumn(columnIndex);
switch(column) {
case START:
time = converter.convertTextToInt((String) aValue);
if (time != -1) {
int oldTime = TimeUtil.normalizeTime(interval.getStart());
int newTime = TimeUtil.normalizeTime(time);
int newStartTime = TimeUtil.normalizeTime(train.getStartTime() + (newTime - oldTime));
train.move(newStartTime);
this.fireTableRowsUpdated(0, lastRow);
}
break;
case END:
// departure
time = converter.convertTextToInt((String) aValue);
if (time != -1) {
if (rowIndex == 0) {
train.move(time);
this.fireTableDataChanged();
} else {
int start = TimeUtil.normalizeTime(interval.getStart());
time = TimeUtil.normalizeTime(time);
if (time < start) {
time += TimeInterval.DAY;
}
int newStop = time - start;
if (newStop >= 0) {
train.changeStopTime(interval, newStop);
this.fireTableRowsUpdated(rowIndex - 1, lastRow);
}
}
}
break;
case STOP:
// stop time
try {
time = converter.convertMinutesTextToInt((String) aValue);
} catch (ParseException e) {
// wrong conversion doesn't change anything
time = -1;
}
if (time >= 0) {
boolean originalIsFreight = interval.isFreight();
train.changeStopTime(interval, time);
int firstRow = rowIndex - 1;
if (interval.isFreight() != originalIsFreight) {
firstRow = 0;
}
this.fireTableRowsUpdated(firstRow, lastRow);
}
break;
case SPEED_LIMIT:
// velocity limit
Integer velocity = (Integer) aValue;
if (velocity == null || velocity > 0) {
train.changeSpeedAndAddedTime(interval, velocity, interval.getAddedTime());
this.fireTableRowsUpdated(rowIndex - 2 >= 0 ? rowIndex - 2 : 0, lastRow);
}
break;
case ADDED_TIME:
// added time
if (aValue != null) {
int addedTime;
try {
addedTime = ObjectsUtil.isEmpty((String) aValue) ? 0 : converter.convertMinutesTextToInt((String) aValue);
} catch (ParseException e) {
// wrong conversion doesn't change anything
addedTime = -1;
}
if (addedTime >= 0) {
train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), addedTime);
}
} else {
train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), 0);
}
this.fireTableRowsUpdated(rowIndex, lastRow);
break;
case PLATFORM:
// platform
Track track = (Track) aValue;
if (interval.isNodeOwner()) {
NodeTrack newTrack = (NodeTrack) track;
if (newTrack != null) {
train.changeNodeTrack(interval, newTrack);
this.fireTableRowsUpdated(rowIndex, rowIndex);
}
} else if (interval.isLineOwner()) {
LineTrack newTrack = (LineTrack) track;
if (newTrack != null) {
train.changeLineTrack(interval, newTrack);
this.fireTableRowsUpdated(rowIndex, rowIndex);
}
}
break;
case COMMENT:
// comment
String commentStr = ObjectsUtil.checkAndTrim((String) aValue);
LocalizedString lComment = null;
if (commentStr != null) {
lComment = LocalizedString.newBuilder(interval.getComment()).setDefaultString(commentStr).build();
}
interval.getAttributes().setRemove(TimeInterval.ATTR_COMMENT, lComment);
break;
case OCCUPIED_ENTRY:
// entry of the occupied track
interval.getAttributes().setBool(TimeInterval.ATTR_OCCUPIED, (Boolean) aValue);
break;
case SHUNT:
// entry shunting on the far side
interval.getAttributes().setBool(TimeInterval.ATTR_SHUNT, (Boolean) aValue);
break;
case COMMENT_SHOWN:
// entry shunting on the far side
interval.getAttributes().setBool(TimeInterval.ATTR_COMMENT_SHOWN, (Boolean) aValue);
break;
case SET_SPEED:
// train speed
Integer trainSpeed = (Integer) aValue;
if (trainSpeed != null && trainSpeed <= 0) {
trainSpeed = null;
}
interval.getAttributes().setRemove(TimeInterval.ATTR_SET_SPEED, trainSpeed);
break;
case IGNORE_LENGTH:
// ignore length of the station in computation
interval.getAttributes().setBool(TimeInterval.ATTR_IGNORE_LENGTH, (Boolean) aValue);
this.fireTableRowsUpdated(rowIndex, rowIndex);
break;
case MANAGED_FREIGHT:
interval.getAttributes().setBool(TimeInterval.ATTR_NOT_MANAGED_FREIGHT, !((Boolean) aValue));
this.fireTableRowsUpdated(0, lastRow);
break;
case REGION_CENTER_TRANSFER:
interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, !((Boolean) aValue));
this.fireTableRowsUpdated(0, lastRow);
break;
default:
break;
}
editBlock = false;
}
Aggregations