use of jmri.jmrit.roster.rostergroup.RosterGroup in project JMRI by JMRI.
the class JsonUtil method getRosterEntry.
/**
* Returns the JSON representation of a roster entry.
*
* Note that this returns, for images and icons, a URL relative to the root
* folder of the JMRI server. It is expected that clients will fill in the
* server IP address and port as they know it to be.
*
* @param locale The client Locale
* @param re A RosterEntry that may or may not be in the roster.
* @return a roster entry in JSON notation
* @deprecated since 4.3.5
*/
@Deprecated
public static JsonNode getRosterEntry(Locale locale, RosterEntry re) {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, ROSTER_ENTRY);
ObjectNode entry = root.putObject(DATA);
entry.put(NAME, re.getId());
entry.put(ADDRESS, re.getDccAddress());
entry.put(IS_LONG_ADDRESS, re.isLongAddress());
entry.put(ROAD, re.getRoadName());
entry.put(NUMBER, re.getRoadNumber());
entry.put(MFG, re.getMfg());
entry.put(DECODER_MODEL, re.getDecoderModel());
entry.put(DECODER_FAMILY, re.getDecoderFamily());
entry.put(MODEL, re.getModel());
entry.put(COMMENT, re.getComment());
entry.put(MAX_SPD_PCT, Integer.toString(re.getMaxSpeedPCT()));
entry.put(IMAGE, (re.getImagePath() != null) ? "/" + ROSTER + "/" + re.getId() + "/" + IMAGE : (String) null);
entry.put(ICON, (re.getIconPath() != null) ? "/" + ROSTER + "/" + re.getId() + "/" + ICON : (String) null);
entry.put(SHUNTING_FUNCTION, re.getShuntingFunction());
ArrayNode labels = entry.putArray(FUNCTION_KEYS);
for (int i = 0; i <= re.getMAXFNNUM(); i++) {
ObjectNode label = mapper.createObjectNode();
label.put(NAME, F + i);
label.put(LABEL, re.getFunctionLabel(i));
label.put(LOCKABLE, re.getFunctionLockable(i));
label.put(ICON, (re.getFunctionImage(i) != null) ? "/" + ROSTER + "/" + re.getId() + "/" + F + i + "/" + ICON : (String) null);
label.put(SELECTED_ICON, (re.getFunctionSelectedImage(i) != null) ? "/" + ROSTER + "/" + re.getId() + "/" + F + i + "/" + SELECTED_ICON : (String) null);
labels.add(label);
}
ArrayNode rga = entry.putArray(ROSTER_GROUPS);
for (RosterGroup group : re.getGroups()) {
rga.add(group.getName());
}
return root;
}
use of jmri.jmrit.roster.rostergroup.RosterGroup in project JMRI by JMRI.
the class Roster method copyRosterGroupList.
/**
* Copy a roster group, adding every entry in the roster group to the new
* group.
* <p>
* If a roster group with the target name already exists, this method
* silently fails to rename the roster group. The GUI method
* CopyRosterGroupAction.performAction() catches this error and informs the
* user. This method fires the property change
* "{@value #ROSTER_GROUP_ADDED}".
*
* @param oldName Name of the roster group to be copied
* @param newName Name of the new roster group
* @see jmri.jmrit.roster.swing.RenameRosterGroupAction
*/
public void copyRosterGroupList(String oldName, String newName) {
if (this.rosterGroups.containsKey(newName)) {
return;
}
this.rosterGroups.put(newName, new RosterGroup(newName));
String newGroup = Roster.getRosterGroupProperty(newName);
this.rosterGroups.get(oldName).getEntries().stream().forEach((re) -> {
// NOI18N
re.putAttribute(newGroup, "yes");
});
this.addRosterGroup(new RosterGroup(newName));
// the firePropertyChange event will be called by addRosterGroup()
}
use of jmri.jmrit.roster.rostergroup.RosterGroup in project JMRI by JMRI.
the class Roster method readFile.
/**
* Read the contents of a roster XML file into this object.
* <P>
* Note that this does not clear any existing entries.
*
* @param name filename of roster file
*/
void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
// roster exists?
if (!(new File(name)).exists()) {
log.debug("no roster file found; this is normal if you haven't put decoders in your roster yet");
return;
}
// find root
Element root = rootFromName(name);
if (root == null) {
log.error("Roster file exists, but could not be read; roster not available");
return;
}
// decode type, invoke proper processing routine if a decoder file
if (root.getChild("roster") != null) {
// NOI18N
// NOI18N
List<Element> l = root.getChild("roster").getChildren("locomotive");
if (log.isDebugEnabled()) {
log.debug("readFile sees " + l.size() + " children");
}
l.stream().forEach((e) -> {
addEntry(new RosterEntry(e));
});
//any <?p?> processor directives and change them to back \n characters
synchronized (_list) {
_list.stream().map((entry) -> {
//Extract the Comment field and create a new string for output
String tempComment = entry.getComment();
String xmlComment = "";
//characters in tempComment.
for (int k = 0; k < tempComment.length(); k++) {
if (tempComment.startsWith("<?p?>", k)) {
// NOI18N
// NOI18N
xmlComment = xmlComment + "\n";
k = k + 4;
} else {
xmlComment = xmlComment + tempComment.substring(k, k + 1);
}
}
entry.setComment(xmlComment);
return entry;
}).forEachOrdered((r) -> {
//Now do the same thing for the decoderComment field
String tempDecoderComment = r.getDecoderComment();
String xmlDecoderComment = "";
for (int k = 0; k < tempDecoderComment.length(); k++) {
if (tempDecoderComment.startsWith("<?p?>", k)) {
// NOI18N
// NOI18N
xmlDecoderComment = xmlDecoderComment + "\n";
k = k + 4;
} else {
xmlDecoderComment = xmlDecoderComment + tempDecoderComment.substring(k, k + 1);
}
}
r.setDecoderComment(xmlDecoderComment);
});
}
} else {
log.error("Unrecognized roster file contents in file: " + name);
}
if (root.getChild("rosterGroup") != null) {
// NOI18N
// NOI18N
List<Element> groups = root.getChild("rosterGroup").getChildren("group");
groups.stream().forEach((group) -> {
addRosterGroup(group.getText());
});
}
}
use of jmri.jmrit.roster.rostergroup.RosterGroup in project JMRI by JMRI.
the class Roster method delRosterGroupList.
/**
* Delete a roster group, notifying all listeners of the change.
* <p>
* This method fires the property change notification
* "{@value #ROSTER_GROUP_REMOVED}".
*
* @param rg The group to be deleted
*/
public void delRosterGroupList(String rg) {
RosterGroup group = this.rosterGroups.remove(rg);
String str = Roster.getRosterGroupProperty(rg);
group.getEntries().stream().forEach((re) -> {
re.deleteAttribute(str);
});
firePropertyChange(ROSTER_GROUP_REMOVED, rg, null);
}
Aggregations