Search in sources :

Example 36 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class CombinedLocoSelPane method selectLoco.

/**
     * Identify locomotive complete, act on it by setting the GUI. This will
     * fire "GUI changed" events which will reset the decoder GUI.
     *
     */
protected void selectLoco(int dccAddress) {
    // raise the button again
    idloco.setSelected(false);
    // locate that loco
    List<RosterEntry> l = Roster.getDefault().matchingList(null, null, Integer.toString(dccAddress), null, null, null, null);
    if (log.isDebugEnabled()) {
        log.debug("selectLoco found " + l.size() + " matches");
    }
    if (l.size() > 0) {
        RosterEntry r = l.get(0);
        if (log.isDebugEnabled()) {
            log.debug("Loco id is " + r.getId());
        }
        locoBox.setSelectedItem(r);
    } else {
        log.warn("Read address " + dccAddress + ", but no such loco in roster");
        _statusLabel.setText(Bundle.getMessage("READ ADDRESS ") + dccAddress + Bundle.getMessage(", BUT NO SUCH LOCO IN ROSTER"));
    }
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 37 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class NewLocoSelPane method matchDecoderToLoco.

private void matchDecoderToLoco() {
    if (((String) locoBox.getSelectedItem()).equals("<none>")) {
        return;
    }
    RosterEntry r = Roster.getDefault().entryFromTitle((String) locoBox.getSelectedItem());
    String decoderModel = r.getDecoderModel();
    String decoderFamily = r.getDecoderFamily();
    if (log.isDebugEnabled()) {
        log.debug("selected loco uses decoder " + decoderFamily + " " + decoderModel);
    }
    // locate a decoder like that.
    List<DecoderFile> l = DecoderIndexFile.instance().matchingDecoderList(null, decoderFamily, null, null, null, decoderModel);
    if (log.isDebugEnabled()) {
        log.debug("found " + l.size() + " matches");
    }
    if (l.size() > 0) {
        DecoderFile d = l.get(0);
        String title = d.titleString();
        if (log.isDebugEnabled()) {
            log.debug("Decoder file title " + title);
        }
        for (int i = 0; i < decoderBox.getItemCount(); i++) {
            if (title.equals(decoderBox.getItemAt(i))) {
                decoderBox.setSelectedIndex(i);
            }
        }
    } else {
        log.warn("Loco uses " + decoderFamily + " " + decoderModel + " decoder, but no such decoder defined");
    }
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 38 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class ThrottleController method requestEntryFromID.

public void requestEntryFromID(String id) {
    RosterEntry re = null;
    List<RosterEntry> l = Roster.getDefault().matchingList(null, null, null, null, null, null, id);
    if (l.size() > 0) {
        if (log.isDebugEnabled()) {
            log.debug("Roster Loco found: " + l.get(0).getDccAddress() + " for ID: " + id);
        }
        re = l.get(0);
        rosterLoco = re;
        setAddress(Integer.parseInt(re.getDccAddress()), re.isLongAddress());
    } else {
        log.debug("No Roster Loco found for: " + id);
    }
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 39 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class AddRosterEntryToEcos method rosterEntryUpdate.

void rosterEntryUpdate() {
    if (rosterEntry != null) {
        rosterEntry.removeAllItems();
    }
    for (RosterEntry r : roster.getAllEntries()) {
        // Add only those locos to the drop-down list that are in the roster but not in the Ecos
        String DccAddress = r.getDccAddress();
        EcosLocoAddress EcosAddress = null;
        if (DccAddress != null) {
            log.debug("DccAddress=" + DccAddress);
            EcosAddress = objEcosLocoManager.getByDccAddress(Integer.parseInt(DccAddress));
        }
        if (EcosAddress == null) {
            // It is not possible to create MFX locomotives in the Ecos. They are auto-discovered.
            if (r.getProtocol() != jmri.LocoAddress.Protocol.MFX) {
                rosterEntry.addItem(r.titleString());
            }
        }
    }
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry) EcosLocoAddress(jmri.jmrix.ecos.EcosLocoAddress)

Example 40 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class RosterServlet method doEntry.

/**
     * Provide the XML representation of a roster entry given its ID.
     *
     * Lists roster entries and return an XML document conforming to the JMRI
     * Roster XML schema. Requests for roster entry images and icons can include
     * width and height specifiers, and always return PNG images.
     *
     * This method responds to the following URL patterns: <ul>
     * <li>{@code/roster/<ID>}</li> <li>{@code/roster/entry/<ID>}</li>
     * <li>{@code/roster/<ID>/image}</li> <li>{@code/roster/<ID>/icon}</li></ul>
     * <b>Note:</b> The use of the term <em>entry</em> in URLs is optional.
     *
     * Images and icons can be rescaled using the following parameters:<ul>
     * <li>height</li> <li>maxHeight</li> <li>minHeight</li> <li>width</li>
     * <li>maxWidth</li> <li>minWidth</li></ul>
     *
     * @param request  servlet request
     * @param response servlet response
     * @throws java.io.IOException if communications is cut with client
     */
protected void doEntry(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String[] pathInfo = request.getPathInfo().substring(1).split("/");
    int idOffset = 0;
    String type = null;
    if (pathInfo[0].equals("entry")) {
        if (pathInfo.length == 1) {
            // path must be /roster/<id> or /roster/entry/<id>
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
        idOffset = 1;
    }
    String id = pathInfo[idOffset];
    if (pathInfo.length > (1 + idOffset)) {
        type = pathInfo[pathInfo.length - 1];
    }
    RosterEntry re = Roster.getDefault().getEntryForId(id);
    try {
        if (re == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Could not find roster entry " + id);
        } else if (type == null || type.equals("entry")) {
            // this should be an entirely different format than the table
            this.doRoster(request, response, this.mapper.createObjectNode().put(ID, id));
        } else if (type.equals(JSON.IMAGE)) {
            if (re.getImagePath() != null) {
                this.doImage(request, response, FileUtil.getFile(re.getImagePath()));
            } else {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
        } else if (type.equals(JSON.ICON)) {
            int function = -1;
            if (pathInfo.length != (2 + idOffset)) {
                function = Integer.parseInt(pathInfo[pathInfo.length - 2].substring(1));
            }
            if (function == -1) {
                if (re.getIconPath() != null) {
                    this.doImage(request, response, FileUtil.getFile(re.getIconPath()));
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }
            } else if (re.getFunctionImage(function) != null) {
                this.doImage(request, response, FileUtil.getFile(re.getFunctionImage(function)));
            } else {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
        } else if (type.equals(JSON.SELECTED_ICON)) {
            if (pathInfo.length != (2 + idOffset)) {
                int function = Integer.parseInt(pathInfo[pathInfo.length - 2].substring(1));
                this.doImage(request, response, FileUtil.getFile(re.getFunctionSelectedImage(function)));
            }
        } else if (type.equals("file")) {
            // NOI18N
            ServletUtil.getInstance().writeFile(response, new File(Roster.getDefault().getRosterLocation(), "roster" + File.separator + re.getFileName()), ServletUtil.UTF8_APPLICATION_XML);
        } else if (type.equals("throttle")) {
            // NOI18N
            ServletUtil.getInstance().writeFile(response, new File(FileUtil.getUserFilesPath(), "throttle" + File.separator + id + ".xml"), ServletUtil.UTF8_APPLICATION_XML);
        } else {
            // don't know what to do
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    } catch (NullPointerException ex) {
        // triggered by instanciating a File with null path
        // this would happen when an image or icon is requested for a
        // rosterEntry that has no such image or icon associated with it
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry) File(java.io.File)

Aggregations

RosterEntry (jmri.jmrit.roster.RosterEntry)77 DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)12 JPanel (javax.swing.JPanel)11 Element (org.jdom2.Element)11 JFrame (javax.swing.JFrame)9 BoxLayout (javax.swing.BoxLayout)8 JLabel (javax.swing.JLabel)8 Test (org.junit.Test)7 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 JMenuBar (javax.swing.JMenuBar)6 CvTableModel (jmri.jmrit.symbolicprog.CvTableModel)6 IndexedCvTableModel (jmri.jmrit.symbolicprog.IndexedCvTableModel)6 VariableTableModel (jmri.jmrit.symbolicprog.VariableTableModel)6 ArrayList (java.util.ArrayList)5 JmriJFrame (jmri.util.JmriJFrame)5 File (java.io.File)4 JButton (javax.swing.JButton)3 JMenu (javax.swing.JMenu)3 NamedIcon (jmri.jmrit.catalog.NamedIcon)3