use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.
the class ImportRosterEngines method run.
// we use a thread so the status frame will work!
@Override
public void run() {
// create a status frame
JPanel ps = new JPanel();
jmri.util.JmriJFrame fstatus = new jmri.util.JmriJFrame(Bundle.getMessage("TitleImportEngines"));
fstatus.setLocationRelativeTo(null);
fstatus.setSize(200, 100);
ps.add(textEngine);
ps.add(textId);
fstatus.getContentPane().add(ps);
textEngine.setText(Bundle.getMessage("AddEngine"));
textEngine.setVisible(true);
textId.setVisible(true);
fstatus.setVisible(true);
// Now get engines from the JMRI roster
int enginesAdded = 0;
List<RosterEntry> engines = Roster.getDefault().matchingList(null, null, null, null, null, null, null);
for (RosterEntry re : engines) {
// add engines that have a road name and number
if (!re.getRoadName().equals("") && !re.getRoadNumber().equals("")) {
String road = re.getRoadName();
if (road.length() > Control.max_len_string_attibute) {
road = road.substring(0, Control.max_len_string_attibute);
}
textId.setText(road + " " + re.getRoadNumber());
Engine engine = manager.getByRoadAndNumber(road, re.getRoadNumber());
if (engine == null) {
engine = manager.newEngine(road, re.getRoadNumber());
String model = re.getModel();
if (model.length() > Control.max_len_string_attibute) {
model = model.substring(0, Control.max_len_string_attibute);
}
engine.setModel(model);
// does this model already have a length?
if (engine.getLength().equals(Engine.NONE)) {
engine.setLength(defaultEngineLength);
}
// does this model already have a type?
if (engine.getTypeName().equals(Engine.NONE)) {
engine.setTypeName(defaultEngineType);
}
// does this model already have a hp?
if (engine.getHp().equals(Engine.NONE)) {
engine.setHp(defaultEngineHp);
}
String owner = re.getOwner();
if (owner.length() > Control.max_len_string_attibute) {
owner = owner.substring(0, Control.max_len_string_attibute);
}
engine.setOwner(owner);
enginesAdded++;
} else {
log.info("Can not add, engine number (" + re.getRoadNumber() + ") road (" + re.getRoadName() + ") already exists");
}
}
}
// kill status panel
fstatus.dispose();
if (enginesAdded > 0) {
JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("ImportEnginesAdded"), new Object[] { enginesAdded }), Bundle.getMessage("SuccessfulImport"), JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, MessageFormat.format(Bundle.getMessage("ImportEnginesAdded"), new Object[] { enginesAdded }), Bundle.getMessage("ImportFailed"), JOptionPane.ERROR_MESSAGE);
}
}
use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.
the class Train method createTrainIcon.
public void createTrainIcon(RouteLocation rl) {
if (_trainIcon != null && _trainIcon.isActive()) {
_trainIcon.remove();
}
// if there's a panel specified, get it and place icon
if (!Setup.getPanelName().equals(Setup.NONE)) {
Editor editor = PanelMenu.instance().getEditorByName(Setup.getPanelName());
if (editor != null) {
_trainIcon = editor.addTrainIcon(getIconName());
_trainIcon.setTrain(this);
if (getIconName().length() > 9) {
_trainIcon.setFont(jmri.util.FontUtil.deriveFont(_trainIcon.getFont(), 8.f));
}
if (rl != null) {
_trainIcon.setLocation(rl.getTrainIconX(), rl.getTrainIconY());
}
// add throttle if there's a throttle manager
if (jmri.InstanceManager.getNullableDefault(jmri.ThrottleManager.class) != null) {
// add throttle if JMRI loco roster entry exist
RosterEntry entry = null;
if (getLeadEngine() != null) {
// first try and find a match based on loco road number
List<RosterEntry> entries = Roster.getDefault().matchingList(null, getLeadEngine().getNumber(), null, null, null, null, null);
if (entries.size() > 0) {
entry = entries.get(0);
}
if (entry == null) {
// now try finding a match based on DCC address
entries = Roster.getDefault().matchingList(null, null, getLeadEngine().getNumber(), null, null, null, null);
if (entries.size() > 0) {
entry = entries.get(0);
}
}
}
if (entry != null) {
_trainIcon.setRosterEntry(entry);
if (getLeadEngine().getConsist() != null) {
_trainIcon.setConsistNumber(getLeadEngine().getConsist().getConsistNumber());
}
} else {
log.debug("Loco roster entry not found for train (" + getName() + ")");
}
}
}
}
}
use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.
the class RosterTable method setSelection.
public void setSelection(RosterEntry... selection) {
//Remove the listener as this change will re-activate it and we end up in a loop!
dataTable.getSelectionModel().removeListSelectionListener(tableSelectionListener);
dataTable.clearSelection();
if (selection != null) {
for (RosterEntry entry : selection) {
re = entry;
int entries = dataTable.getRowCount();
for (int i = 0; i < entries; i++) {
if (dataModel.getValueAt(sorter.convertRowIndexToModel(i), RosterTableModel.IDCOL).equals(re.getId())) {
dataTable.addRowSelectionInterval(i, i);
}
}
}
if (selection.length > 1) {
re = null;
} else {
this.moveTableViewToSelected();
}
} else {
re = null;
}
dataTable.getSelectionModel().addListSelectionListener(tableSelectionListener);
}
use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.
the class RosterTableModel method setValueAt.
@Override
public void setValueAt(Object value, int row, int col) {
// get roster entry for row
RosterEntry re = Roster.getDefault().getGroupEntry(rosterGroup, row);
if (re == null) {
log.warn("roster entry is null!");
return;
}
if (re.isOpen()) {
log.warn("Entry is already open");
return;
}
String valueToSet = (String) value;
switch(col) {
case IDCOL:
if (re.getId().equals(valueToSet)) {
return;
}
re.setId(valueToSet);
break;
case ROADNAMECOL:
if (re.getRoadName().equals(valueToSet)) {
return;
}
re.setRoadName(valueToSet);
break;
case ROADNUMBERCOL:
if (re.getRoadNumber().equals(valueToSet)) {
return;
}
re.setRoadNumber(valueToSet);
break;
case MFGCOL:
if (re.getMfg().equals(valueToSet)) {
return;
}
re.setMfg(valueToSet);
break;
case MODELCOL:
if (re.getModel().equals(valueToSet)) {
return;
}
re.setModel(valueToSet);
break;
case OWNERCOL:
if (re.getOwner().equals(valueToSet)) {
return;
}
re.setOwner(valueToSet);
break;
default:
String attributeName = (getColumnName(col)).replaceAll("\\s", "");
if (re.getAttribute(attributeName) != null && re.getAttribute(attributeName).equals(valueToSet)) {
return;
}
if ((valueToSet == null) || valueToSet.isEmpty()) {
re.deleteAttribute(attributeName);
} else {
re.putAttribute(attributeName, valueToSet);
}
break;
}
// need to mark as updated
re.changeDateUpdated();
re.updateFile();
}
use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.
the class RosterTableModel method getValueAt.
/**
* {@inheritDoc}
*
* Provides an empty string for a column if the model returns null for that
* value.
*/
@Override
public Object getValueAt(int row, int col) {
// get roster entry for row
RosterEntry re = Roster.getDefault().getGroupEntry(rosterGroup, row);
if (re == null) {
log.debug("roster entry is null!");
return null;
}
switch(col) {
case IDCOL:
return re.getId();
case ADDRESSCOL:
return re.getDccLocoAddress().getNumber();
case DECODERCOL:
return re.getDecoderModel();
case MODELCOL:
return re.getModel();
case ROADNAMECOL:
return re.getRoadName();
case ROADNUMBERCOL:
return re.getRoadNumber();
case MFGCOL:
return re.getMfg();
case ICONCOL:
return getIcon(re);
case OWNERCOL:
return re.getOwner();
case DATEUPDATECOL:
// will not display last update if not parsable as date
return re.getDateModified();
case PROTOCOL:
return re.getProtocolAsString();
default:
break;
}
// NOI18N
String value = re.getAttribute(getColumnName(col).replaceAll("\\s", ""));
if (value != null) {
return value;
}
return "";
}
Aggregations