use of jmri.IdTag in project JMRI by JMRI.
the class RollingStock method setRfid.
/**
* Sets the RFID for this rolling stock.
*
* @param id 12 character RFID string.
*/
public void setRfid(String id) {
String old = _rfid;
if (id != null && !id.equals(old)) {
log.debug("Changing IdTag for {} to {}", toString(), id);
try {
IdTag tag = InstanceManager.getDefault(IdTagManager.class).getIdTag(id.toUpperCase());
if (tag != null) {
log.debug("Tag {} Found", tag.toString());
} else {
log.error("Tag {} Not Found", id);
}
setIdTag(tag);
} catch (NullPointerException e) {
log.error("Tag {} Not Found", id);
} finally {
// always set the _rfid if it changed.
_rfid = id;
// NOI18N
setDirtyAndFirePropertyChange("rolling stock rfid", old, id);
}
}
}
use of jmri.IdTag in project JMRI by JMRI.
the class EngineEditFrame method saveEngine.
private void saveEngine() {
if (roadComboBox.getSelectedItem() != null && !roadComboBox.getSelectedItem().equals("")) {
if (_engine == null || !_engine.getRoadName().equals(roadComboBox.getSelectedItem()) || !_engine.getNumber().equals(roadNumberTextField.getText())) {
_engine = manager.newEngine((String) roadComboBox.getSelectedItem(), roadNumberTextField.getText());
}
if (modelComboBox.getSelectedItem() != null) {
_engine.setModel((String) modelComboBox.getSelectedItem());
}
if (typeComboBox.getSelectedItem() != null) {
_engine.setTypeName((String) typeComboBox.getSelectedItem());
}
_engine.setBunit(bUnitCheckBox.isSelected());
if (lengthComboBox.getSelectedItem() != null) {
_engine.setLength((String) lengthComboBox.getSelectedItem());
}
_engine.setBuilt(builtTextField.getText());
if (ownerComboBox.getSelectedItem() != null) {
_engine.setOwner((String) ownerComboBox.getSelectedItem());
}
if (consistComboBox.getSelectedItem() != null) {
if (consistComboBox.getSelectedItem().equals(EngineManager.NONE)) {
_engine.setConsist(null);
if (_engine.isBunit())
_engine.setBlocking(Engine.B_UNIT_BLOCKING);
else
_engine.setBlocking(Engine.DEFAULT_BLOCKING_ORDER);
} else {
_engine.setConsist(manager.getConsistByName((String) consistComboBox.getSelectedItem()));
if (_engine.getConsist() != null) {
_engine.setBlocking(_engine.getConsist().getSize());
}
}
}
// confirm that weight is a number
if (!weightTextField.getText().equals("")) {
try {
Integer.parseInt(weightTextField.getText());
_engine.setWeightTons(weightTextField.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("engineWeight"), Bundle.getMessage("engineCanNotWeight"), JOptionPane.ERROR_MESSAGE);
}
}
// confirm that horsepower is a number
if (!hpTextField.getText().equals("")) {
try {
Integer.parseInt(hpTextField.getText());
_engine.setHp(hpTextField.getText());
} catch (Exception e) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("engineHorsepower"), Bundle.getMessage("engineCanNotHp"), JOptionPane.ERROR_MESSAGE);
}
}
if (locationBox.getSelectedItem() == null) {
_engine.setLocation(null, null);
} else {
if (trackLocationBox.getSelectedItem() == null) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("rsFullySelect"), Bundle.getMessage("rsCanNotLoc"), JOptionPane.ERROR_MESSAGE);
} else {
String status = _engine.setLocation((Location) locationBox.getSelectedItem(), (Track) trackLocationBox.getSelectedItem());
if (!status.equals(Track.OKAY)) {
log.debug("Can't set engine's location because of {}", status);
JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("rsCanNotLocMsg"), new Object[] { _engine.toString(), status }), Bundle.getMessage("rsCanNotLoc"), JOptionPane.ERROR_MESSAGE);
// does the user want to force the rolling stock to this track?
int results = JOptionPane.showOptionDialog(this, MessageFormat.format(Bundle.getMessage("rsForce"), new Object[] { _engine.toString(), (Track) trackLocationBox.getSelectedItem() }), MessageFormat.format(Bundle.getMessage("rsOverride"), new Object[] { status }), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
if (results == JOptionPane.YES_OPTION) {
log.debug("Force rolling stock to track");
_engine.setLocation((Location) locationBox.getSelectedItem(), (Track) trackLocationBox.getSelectedItem(), RollingStock.FORCE);
}
}
}
}
_engine.setComment(commentTextField.getText());
_engine.setValue(valueTextField.getText());
// save the IdTag for this engine
IdTag idTag = (IdTag) rfidComboBox.getSelectedItem();
if (idTag != null) {
_engine.setRfid(idTag.toString());
}
}
}
use of jmri.IdTag in project JMRI by JMRI.
the class StandaloneReporterManager method processReply.
private void processReply(StandaloneReply r) {
if (!tc.getAdapterMemo().getProtocol().isValid(r)) {
log.warn("Invalid message - skipping " + r);
return;
}
IdTag idTag = InstanceManager.getDefault(IdTagManager.class).provideIdTag(tc.getAdapterMemo().getProtocol().getTag(r));
TimeoutRfidReporter report = (TimeoutRfidReporter) provideReporter(prefix + typeLetter() + "1");
report.notify(idTag);
}
use of jmri.IdTag in project JMRI by JMRI.
the class StandaloneSensorManager method processReply.
private void processReply(StandaloneReply r) {
if (!tc.getAdapterMemo().getProtocol().isValid(r)) {
log.warn("Invalid message - skipping " + r);
return;
}
IdTag idTag = InstanceManager.getDefault(IdTagManager.class).provideIdTag(tc.getAdapterMemo().getProtocol().getTag(r));
TimeoutRfidSensor sensor = (TimeoutRfidSensor) provideSensor(prefix + typeLetter() + "1");
sensor.notify(idTag);
}
use of jmri.IdTag in project JMRI by JMRI.
the class CarEditFrame method saveCar.
private void saveCar(boolean isSave) {
if (roadComboBox.getSelectedItem() == null) {
return;
}
if (_car == null || !_car.getRoadName().equals(roadComboBox.getSelectedItem()) || !_car.getNumber().equals(roadNumberTextField.getText())) {
_car = carManager.newCar((String) roadComboBox.getSelectedItem(), roadNumberTextField.getText());
_car.addPropertyChangeListener(this);
}
if (typeComboBox.getSelectedItem() != null) {
_car.setTypeName((String) typeComboBox.getSelectedItem());
}
if (lengthComboBox.getSelectedItem() != null) {
_car.setLength((String) lengthComboBox.getSelectedItem());
}
if (colorComboBox.getSelectedItem() != null) {
_car.setColor((String) colorComboBox.getSelectedItem());
}
try {
_car.setWeight(NumberFormat.getNumberInstance().parse(weightTextField.getText()).toString());
} catch (ParseException e1) {
}
_car.setWeightTons(weightTonsTextField.getText());
// ask if all cars of this type should be passenger
if (isSave && _car.isPassenger() ^ passengerCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(passengerCheckBox.isSelected() ? Bundle.getMessage("carModifyTypePassenger") : Bundle.getMessage("carRemoveTypePassenger"), new Object[] { _car.getTypeName() }), MessageFormat.format(Bundle.getMessage("carModifyAllType"), new Object[] { _car.getTypeName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// for all cars of this type
for (RollingStock rs : carManager.getList()) {
Car c = (Car) rs;
if (c.getTypeName().equals(_car.getTypeName())) {
c.setPassenger(passengerCheckBox.isSelected());
}
}
}
}
_car.setPassenger(passengerCheckBox.isSelected());
int blocking = 0;
try {
blocking = Integer.parseInt(blockingTextField.getText());
// only allow numbers between 0 and 100
if (blocking < 0 || blocking > 100) {
blocking = 0;
}
} catch (Exception e) {
log.warn("Blocking must be a number between 0 and 100");
}
// ask if blocking order should be the same
if (isSave && _car.getKernel() == null && passengerCheckBox.isSelected() && _car.getBlocking() != blocking) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("carChangeBlocking"), new Object[] { blocking, _car.getTypeName() }), MessageFormat.format(Bundle.getMessage("carModifyAllType"), new Object[] { _car.getTypeName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// for all cars of this type
for (RollingStock rs : carManager.getList()) {
Car c = (Car) rs;
if (c.isPassenger() && c.getTypeName().equals(_car.getTypeName())) {
c.setBlocking(blocking);
}
}
}
}
_car.setBlocking(blocking);
// ask if all cars of this type should be caboose
if (isSave && _car.isCaboose() ^ cabooseCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(cabooseCheckBox.isSelected() ? Bundle.getMessage("carModifyTypeCaboose") : Bundle.getMessage("carRemoveTypeCaboose"), new Object[] { _car.getTypeName() }), MessageFormat.format(Bundle.getMessage("carModifyAllType"), new Object[] { _car.getTypeName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the caboose setting for all cars of this type
for (RollingStock rs : carManager.getList()) {
Car c = (Car) rs;
if (c.getTypeName().equals(_car.getTypeName())) {
c.setCaboose(cabooseCheckBox.isSelected());
}
}
}
}
_car.setCaboose(cabooseCheckBox.isSelected());
// ask if all cars of this type should be utility
if (isSave && _car.isUtility() ^ utilityCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(utilityCheckBox.isSelected() ? Bundle.getMessage("carModifyTypeUtility") : Bundle.getMessage("carRemoveTypeUtility"), new Object[] { _car.getTypeName() }), MessageFormat.format(Bundle.getMessage("carModifyAllType"), new Object[] { _car.getTypeName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the utility for all cars of this type
for (RollingStock rs : carManager.getList()) {
Car c = (Car) rs;
if (c.getTypeName().equals(_car.getTypeName())) {
c.setUtility(utilityCheckBox.isSelected());
}
}
}
}
_car.setUtility(utilityCheckBox.isSelected());
// ask if all cars of this type should be hazardous
if (isSave && _car.isHazardous() ^ hazardousCheckBox.isSelected()) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(hazardousCheckBox.isSelected() ? Bundle.getMessage("carModifyTypeHazardous") : Bundle.getMessage("carRemoveTypeHazardous"), new Object[] { _car.getTypeName() }), MessageFormat.format(Bundle.getMessage("carModifyAllType"), new Object[] { _car.getTypeName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the hazardous setting for all cars of this type
for (RollingStock rs : carManager.getList()) {
Car c = (Car) rs;
if (c.getTypeName().equals(_car.getTypeName())) {
c.setHazardous(hazardousCheckBox.isSelected());
}
}
}
}
_car.setHazardous(hazardousCheckBox.isSelected());
_car.setFred(fredCheckBox.isSelected());
_car.setBuilt(builtTextField.getText());
if (ownerComboBox.getSelectedItem() != null) {
_car.setOwner((String) ownerComboBox.getSelectedItem());
}
if (kernelComboBox.getSelectedItem() != null) {
if (kernelComboBox.getSelectedItem().equals(CarManager.NONE)) {
_car.setKernel(null);
} else if (!_car.getKernelName().equals(kernelComboBox.getSelectedItem())) {
_car.setKernel(carManager.getKernelByName((String) kernelComboBox.getSelectedItem()));
// if car has FRED or caboose make lead
if (_car.hasFred() || _car.isCaboose()) {
_car.getKernel().setLead(_car);
}
_car.setBlocking(_car.getKernel().getSize());
}
}
if (loadComboBox.getSelectedItem() != null && !_car.getLoadName().equals(loadComboBox.getSelectedItem())) {
_car.setLoadName((String) loadComboBox.getSelectedItem());
// check to see if car is part of kernel, and ask if all the other cars in the kernel should be changed
if (_car.getKernel() != null) {
List<Car> cars = _car.getKernel().getCars();
if (cars.size() > 1) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("carInKernel"), new Object[] { _car.toString() }), MessageFormat.format(Bundle.getMessage("carPartKernel"), new Object[] { _car.getKernelName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the loads for all cars
for (Car car : cars) {
if (CarLoads.instance().containsName(car.getTypeName(), _car.getLoadName())) {
car.setLoadName(_car.getLoadName());
}
}
}
}
}
}
_car.setComment(commentTextField.getText());
_car.setValue(valueTextField.getText());
// save the IdTag for this car
IdTag idTag = (IdTag) rfidComboBox.getSelectedItem();
if (idTag != null) {
_car.setRfid(idTag.toString());
}
autoTrackCheckBox.setEnabled(true);
// update blocking
pBlocking.setVisible(passengerCheckBox.isSelected() || _car.getKernel() != null);
blockingTextField.setText(Integer.toString(_car.getBlocking()));
if (locationBox.getSelectedItem() != null && trackLocationBox.getSelectedItem() == null) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("rsFullySelect"), Bundle.getMessage("rsCanNotLoc"), JOptionPane.ERROR_MESSAGE);
} else {
// update location only if it has changed
if (_car.getLocation() == null || !_car.getLocation().equals(locationBox.getSelectedItem()) || _car.getTrack() == null || !_car.getTrack().equals(trackLocationBox.getSelectedItem())) {
setLocation(_car);
// is this car part of a kernel?
if (_car.getKernel() != null) {
List<Car> cars = _car.getKernel().getCars();
if (cars.size() > 1) {
if (JOptionPane.showConfirmDialog(this, MessageFormat.format(Bundle.getMessage("carInKernel"), new Object[] { _car.toString() }), MessageFormat.format(Bundle.getMessage("carPartKernel"), new Object[] { _car.getKernelName() }), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// go through the entire list and change the location for all cars
for (Car car : cars) {
if (car != _car) {
setLocation(car);
}
}
}
}
}
}
}
}
Aggregations