Search in sources :

Example 1 with RosterGroup

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TrainCommon.splitString(jmri.jmrit.operations.trains.TrainCommon.splitString) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) RosterGroup(jmri.jmrit.roster.rostergroup.RosterGroup)

Example 2 with RosterGroup

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()
}
Also used : RosterGroup(jmri.jmrit.roster.rostergroup.RosterGroup)

Example 3 with RosterGroup

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());
        });
    }
}
Also used : FileUtilSupport(jmri.util.FileUtilSupport) RosterGroup(jmri.jmrit.roster.rostergroup.RosterGroup) ProcessingInstruction(org.jdom2.ProcessingInstruction) LoggerFactory(org.slf4j.LoggerFactory) RosterGroupSelector(jmri.jmrit.roster.rostergroup.RosterGroupSelector) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SymbolicProgBundle(jmri.jmrit.symbolicprog.SymbolicProgBundle) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException) Locale(java.util.Locale) HeadlessException(java.awt.HeadlessException) Nonnull(javax.annotation.Nonnull) PropertyChangeEvent(java.beans.PropertyChangeEvent) InstanceManager(jmri.InstanceManager) UserPreferencesManager(jmri.UserPreferencesManager) Logger(org.slf4j.Logger) PropertyChangeProvider(jmri.beans.PropertyChangeProvider) Set(java.util.Set) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) File(java.io.File) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) FileUtil(jmri.util.FileUtil) PropertyChangeSupport(java.beans.PropertyChangeSupport) Collections(java.util.Collections) XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) Element(org.jdom2.Element) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 4 with RosterGroup

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);
}
Also used : RosterGroup(jmri.jmrit.roster.rostergroup.RosterGroup)

Aggregations

RosterGroup (jmri.jmrit.roster.rostergroup.RosterGroup)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HeadlessException (java.awt.HeadlessException)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 PropertyChangeSupport (java.beans.PropertyChangeSupport)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Nonnull (javax.annotation.Nonnull)1 JOptionPane (javax.swing.JOptionPane)1 InstanceManager (jmri.InstanceManager)1 UserPreferencesManager (jmri.UserPreferencesManager)1