Search in sources :

Example 1 with RosterEntry

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

the class WarrantRoute method getRoster.

private void getRoster() {
    List<RosterEntry> list = Roster.getDefault().matchingList(null, null, null, null, null, null, null);
    _rosterBox.setRenderer(new jmri.jmrit.roster.swing.RosterEntryListCellRenderer());
    _rosterBox.addItem(" ");
    _rosterBox.addItem(Bundle.getMessage("noSuchAddress"));
    for (int i = 0; i < list.size(); i++) {
        RosterEntry r = list.get(i);
        _rosterBox.addItem(r.titleString());
    }
    //_rosterBox = Roster.getDefault().fullRosterComboBox();
    _rosterBox.setMaximumSize(_rosterBox.getPreferredSize());
    _rosterBox.addActionListener((ActionEvent e) -> {
        String selection = (String) _rosterBox.getSelectedItem();
        if (Bundle.getMessage("noSuchAddress").equals(selection)) {
            _dccNumBox.setText(null);
        } else {
            setTrainInfo(selection);
        }
    });
    _viewProfile.addActionListener((ActionEvent e) -> {
        showProfile();
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 2 with RosterEntry

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

the class RemoveRosterEntryToGroupAction method okPressed.

public void okPressed() {
    String group = rosterBox.getSelectedRosterGroup();
    log.info("Selected " + group);
    if (group != null && !group.equals(Roster.ALLENTRIES)) {
        if (rosterBox.getSelectedRosterEntries().length != 0) {
            RosterEntry re = rosterBox.getSelectedRosterEntries()[0];
            log.info("Preparing to remove " + re.getId() + " from " + group);
            if (userOK(re.getId(), group)) {
                re.deleteAttribute(Roster.getRosterGroupProperty(group));
                re.updateFile();
                Roster.getDefault().writeRoster();
                rosterBox.getRosterEntryComboBox().update();
            }
        }
    }
    frame.pack();
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 3 with RosterEntry

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

the class RosterEntryComboBox method update.

/**
     * Update the combo box with an arbitrary roster group, using new roster
     * entry attributes.
     *
     */
public final void update(String rosterGroup, String roadName, String roadNumber, String dccAddress, String mfg, String decoderMfgID, String decoderVersionID, String id) {
    Object selection = this.getSelectedItem();
    if (log.isDebugEnabled()) {
        log.debug("Old selection: " + selection);
        log.debug("Old group: " + _group);
    }
    ActionListener[] ALs = this.getActionListeners();
    for (ActionListener al : ALs) {
        this.removeActionListener(al);
    }
    this.setSelectedItem(null);
    List<RosterEntry> l = _roster.matchingList(roadName, roadNumber, dccAddress, mfg, decoderMfgID, decoderVersionID, id);
    _group = rosterGroup;
    _roadName = roadName;
    _roadNumber = roadNumber;
    _dccAddress = dccAddress;
    _mfg = mfg;
    _decoderMfgID = decoderMfgID;
    _decoderVersionID = decoderVersionID;
    _id = id;
    removeAllItems();
    if (_nonSelectedItem != null) {
        insertItemAt(_nonSelectedItem, 0);
        setSelectedItem(_nonSelectedItem);
    }
    for (RosterEntry r : l) {
        if (rosterGroup != null && !rosterGroup.equals(Roster.ALLENTRIES)) {
            if (r.getAttribute(Roster.getRosterGroupProperty(rosterGroup)) != null && r.getAttribute(Roster.getRosterGroupProperty(rosterGroup)).equals("yes")) {
                addItem(r);
            }
        } else {
            addItem(r);
        }
        if (r.equals(selection)) {
            this.setSelectedItem(r);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("New selection: " + this.getSelectedItem());
        log.debug("New group: " + _group);
    }
    for (ActionListener al : ALs) {
        this.addActionListener(al);
    }
    // don't use equals() since selection or getSelectedItem could be null
    if (this.getSelectedItem() != selection) {
        this.fireActionEvent();
        // this is part of the RosterEntrySelector contract
        this.fireSelectedRosterEntriesPropertyChange();
    }
}
Also used : ActionListener(java.awt.event.ActionListener) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 4 with RosterEntry

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

the class CombinedLocoSelPane method openNewLoco.

/**
     * Start with a decoder selected, so we're going to create a new
     * RosterEntry.
     */
protected void openNewLoco() {
    // find the decoderFile object
    DecoderFile decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
    if (log.isDebugEnabled()) {
        log.debug("decoder file: " + decoderFile.getFilename());
    }
    // create a dummy RosterEntry with the decoder info
    RosterEntry re = new RosterEntry();
    re.setDecoderFamily(decoderFile.getFamily());
    re.setDecoderModel(decoderFile.getModel());
    re.setId(Bundle.getMessage("LabelNewDecoder"));
    // note that we're leaving the filename null
    // add the new roster entry to the in-memory roster
    Roster.getDefault().addEntry(re);
    startProgrammer(decoderFile, re, (String) programmerBox.getSelectedItem());
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 5 with RosterEntry

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

the class CombinedLocoSelTreePane method setDecoderSelectionFromLoco.

/**
     * Set the decoder selection to a specific decoder from a selected Loco.
     * <P>
     * This must not trigger an update event from the Tree selection, so we
     * remove and replace the listener.
     */
@Override
void setDecoderSelectionFromLoco(String loco) {
    // if there's a valid loco entry...
    RosterEntry locoEntry = Roster.getDefault().entryFromTitle(loco);
    if (locoEntry == null) {
        return;
    }
    dTree.removeTreeSelectionListener(dListener);
    dTree.clearSelection();
    // get the decoder type, it has to be there (assumption!),
    String modelString = locoEntry.getDecoderModel();
    String familyString = locoEntry.getDecoderFamily();
    // close the entire GUI (not currently done, users want left open)
    //collapseAll();
    // find this one to select it
    Enumeration<DecoderTreeNode> e = dRoot.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        DecoderTreeNode node = e.nextElement();
        DecoderTreeNode parentNode = (DecoderTreeNode) node.getParent();
        if (node.toString().equals(modelString) && parentNode.toString().equals(familyString)) {
            TreePath path = new TreePath(node.getPath());
            node.setIdentified(true);
            parentNode.setIdentified(true);
            dModel.reload();
            dTree.addSelectionPath(path);
            dTree.scrollPathToVisible(path);
            break;
        }
    }
    // and restore the listener
    dTree.addTreeSelectionListener(dListener);
}
Also used : TreePath(javax.swing.tree.TreePath) RosterEntry(jmri.jmrit.roster.RosterEntry)

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