Exemplo n.º 1
0
 @Override
 public void propertyChange(PropertyChangeEvent e) {
   if (e.getPropertyName().equals(Roster.ADD)) {
     fireTableDataChanged();
   } else if (e.getPropertyName().equals(Roster.REMOVE)) {
     fireTableDataChanged();
   } else if (e.getPropertyName().equals(Roster.SAVED)) {
     // TODO This really needs to do something like find the index of the roster entry here
     if (e.getSource() instanceof RosterEntry) {
       int row = Roster.getDefault().getGroupIndex(rosterGroup, (RosterEntry) e.getSource());
       fireTableRowsUpdated(row, row);
     } else {
       fireTableDataChanged();
     }
   } else if (e.getPropertyName().equals(RosterGroupSelector.SELECTED_ROSTER_GROUP)) {
     setRosterGroup((e.getNewValue() != null) ? e.getNewValue().toString() : null);
   } else if (e.getPropertyName().startsWith("attribute")
       && e.getSource() instanceof RosterEntry) { // NOI18N
     int row = Roster.getDefault().getGroupIndex(rosterGroup, (RosterEntry) e.getSource());
     fireTableRowsUpdated(row, row);
   } else if (e.getPropertyName().equals(Roster.ROSTER_GROUP_ADDED)
       && e.getNewValue().equals(rosterGroup)) {
     fireTableDataChanged();
   }
 }
Exemplo n.º 2
0
 /** Test of onClose method, of class JsonRosterSocketService. */
 @Test
 public void testOnClose() {
   JsonRosterSocketService instance =
       new JsonRosterSocketService(new JsonMockConnection((DataOutputStream) null));
   // listen to the roster, since onClose stops listening to the roster
   instance.listen();
   // assert we are listening
   Assert.assertEquals(1, Roster.getDefault().getPropertyChangeListeners().length);
   Roster.getDefault()
       .getEntriesInGroup(Roster.ALLENTRIES)
       .stream()
       .forEach(
           (entry) -> {
             Assert.assertEquals(2, entry.getPropertyChangeListeners().length);
           });
   // the connection is closing, stop listening
   instance.onClose();
   // assert we are not listening
   Assert.assertEquals(0, Roster.getDefault().getPropertyChangeListeners().length);
   Roster.getDefault()
       .getEntriesInGroup(Roster.ALLENTRIES)
       .stream()
       .forEach(
           (entry) -> {
             Assert.assertEquals(1, entry.getPropertyChangeListeners().length);
           });
 }
Exemplo n.º 3
0
 /**
  * Test of onList method, of class JsonRosterSocketService.
  *
  * @throws java.io.IOException this is an error, not a failure, in the test
  * @throws jmri.JmriException this is an error, not a failure, in the test
  * @throws jmri.server.json.JsonException this is an error, not a failure, in the test
  */
 @Test
 public void testOnList() throws IOException, JmriException, JsonException {
   JsonNode data = null;
   Locale locale = Locale.ENGLISH;
   JsonRosterSocketService instance = new JsonRosterSocketService(this.connection);
   // assert we have not been listening
   Assert.assertEquals(0, Roster.getDefault().getPropertyChangeListeners().length);
   Roster.getDefault()
       .getEntriesInGroup(Roster.ALLENTRIES)
       .stream()
       .forEach(
           (entry) -> {
             Assert.assertEquals(1, entry.getPropertyChangeListeners().length);
           });
   // onList should cause listening to start if it hasn't already
   instance.onList(JsonRoster.ROSTER, data, locale);
   Assert.assertNotNull(this.connection.getMessage());
   Assert.assertEquals(Roster.getDefault().numEntries(), this.connection.getMessage().size());
   // assert we are listening
   Assert.assertEquals(1, Roster.getDefault().getPropertyChangeListeners().length);
   Roster.getDefault()
       .getEntriesInGroup(Roster.ALLENTRIES)
       .stream()
       .forEach(
           (entry) -> {
             Assert.assertEquals(2, entry.getPropertyChangeListeners().length);
           });
 }
Exemplo n.º 4
0
 public final void setRosterGroup(String rosterGroup) {
   for (RosterEntry re : Roster.getDefault().getEntriesInGroup(rosterGroup)) {
     re.removePropertyChangeListener(this);
   }
   this.rosterGroup = rosterGroup;
   for (RosterEntry re : Roster.getDefault().getEntriesInGroup(rosterGroup)) {
     re.addPropertyChangeListener(this);
   }
   fireTableDataChanged();
 }
Exemplo n.º 5
0
 /** Editable state must be set in ctor. */
 @Override
 public boolean isCellEditable(int row, int col) {
   if (col == ADDRESSCOL) {
     return false;
   }
   if (col == PROTOCOL) {
     return false;
   }
   if (col == DECODERCOL) {
     return false;
   }
   if (col == ICONCOL) {
     return false;
   }
   if (col == DATEUPDATECOL) {
     return false;
   }
   if (editable) {
     RosterEntry re = Roster.getDefault().getGroupEntry(rosterGroup, row);
     if (re != null) {
       return (!re.isOpen());
     }
   }
   return editable;
 }
Exemplo n.º 6
0
 /**
  * Test of onMessage method INVALID on a ROSTER
  *
  * @throws java.io.IOException this is an error, not a failure, in the test
  * @throws jmri.JmriException this is an error, not a failure, in the test
  * @throws jmri.server.json.JsonException this is an error, not a failure, in the test
  */
 @Test
 public void testOnMessageInvalidRoster() throws IOException, JmriException, JsonException {
   JsonNode data =
       this.connection.getObjectMapper().createObjectNode().put(JSON.METHOD, "Invalid");
   Locale locale = Locale.ENGLISH;
   JsonRosterSocketService instance = new JsonRosterSocketService(this.connection);
   instance.onMessage(JsonRoster.ROSTER, data, locale);
   Assert.assertNotNull(this.connection.getMessage());
   Assert.assertEquals(Roster.getDefault().numEntries(), this.connection.getMessage().size());
 }
Exemplo n.º 7
0
  /**
   * Create the panel used to select an existing entry
   *
   * @return a JPanel for handling the entry-selection GUI
   */
  protected JPanel layoutRosterSelection() {
    JPanel pane2a = new JPanel();
    pane2a.setLayout(new BoxLayout(pane2a, BoxLayout.X_AXIS));
    pane2a.add(new JLabel(Bundle.getMessage("USE LOCOMOTIVE SETTINGS FOR: ")));
    locoBox.setNonSelectedItem(Bundle.getMessage("<NONE - NEW LOCO>"));
    Roster.getDefault().addPropertyChangeListener(this);
    pane2a.add(locoBox);
    locoBox.addPropertyChangeListener(
        RosterEntrySelector.SELECTED_ROSTER_ENTRIES,
        new PropertyChangeListener() {

          @Override
          public void propertyChange(PropertyChangeEvent pce) {
            if (locoBox.getSelectedRosterEntries().length != 0) {
              // reset and disable decoder selection
              setDecoderSelectionFromLoco(locoBox.getSelectedRosterEntries()[0].titleString());
              go2.setEnabled(true);
              go2.setRequestFocusEnabled(true);
              go2.requestFocus();
              go2.setToolTipText(Bundle.getMessage("CLICK TO OPEN THE PROGRAMMER"));
            } else {
              go2.setEnabled(false);
              go2.setToolTipText(Bundle.getMessage("SELECT A LOCOMOTIVE OR DECODER TO ENABLE"));
            }
          }
        });
    idloco = new JToggleButton(Bundle.getMessage("IDENT"));
    idloco.setToolTipText(
        Bundle.getMessage(
            "READ THE LOCOMOTIVE'S ADDRESS AND ATTEMPT TO SELECT THE RIGHT SETTINGS"));
    if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null
        && jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer()
            != null
        && !jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class)
            .getGlobalProgrammer()
            .getCanRead()) {
      // can't read, disable the button
      idloco.setEnabled(false);
      idloco.setToolTipText(
          Bundle.getMessage("BUTTON DISABLED BECAUSE CONFIGURED COMMAND STATION CAN'T READ CVS"));
    }
    idloco.addActionListener(
        new ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent e) {
            if (log.isDebugEnabled()) {
              log.debug("Identify locomotive pressed");
            }
            startIdentifyLoco();
          }
        });
    pane2a.add(idloco);
    pane2a.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
    return pane2a;
  }
Exemplo n.º 8
0
 /** Test of listen method, of class JsonRosterSocketService. */
 @Test
 public void testListen() {
   JsonRosterSocketService instance = new JsonRosterSocketService(this.connection);
   Assert.assertEquals(0, Roster.getDefault().getPropertyChangeListeners().length);
   Roster.getDefault()
       .getEntriesInGroup(Roster.ALLENTRIES)
       .stream()
       .forEach(
           (entry) -> {
             Assert.assertEquals(1, entry.getPropertyChangeListeners().length);
           });
   // add the first time
   instance.listen();
   Assert.assertEquals(1, Roster.getDefault().getPropertyChangeListeners().length);
   Roster.getDefault()
       .getEntriesInGroup(Roster.ALLENTRIES)
       .stream()
       .forEach(
           (entry) -> {
             Assert.assertEquals(2, entry.getPropertyChangeListeners().length);
           });
   // don't add the second time
   instance.listen();
   Assert.assertEquals(1, Roster.getDefault().getPropertyChangeListeners().length);
   Roster.getDefault()
       .getEntriesInGroup(Roster.ALLENTRIES)
       .stream()
       .forEach(
           (entry) -> {
             Assert.assertEquals(2, entry.getPropertyChangeListeners().length);
           });
 }
Exemplo n.º 9
0
  /** 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());
  }
Exemplo n.º 10
0
 /** Provides the empty String if attribute doesn't exist. */
 @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:
       return re.getDateUpdated();
     case PROTOCOL:
       return re.getProtocolAsString();
     default:
       break;
   }
   String value = re.getAttribute(getColumnName(col).replaceAll("\\s", "")); // NOI18N
   if (value != null) {
     return value;
   }
   return "";
 }
Exemplo n.º 11
0
 /**
  * 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"));
   }
 }
Exemplo n.º 12
0
 @Override
 public int getRowCount() {
   return Roster.getDefault().numGroupEntries(rosterGroup);
 }
Exemplo n.º 13
0
 public RosterTableModel(boolean editable) {
   this.editable = editable;
   Roster.getDefault().addPropertyChangeListener(this);
 }
Exemplo n.º 14
0
 @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();
 }
Exemplo n.º 15
0
 /**
  * Store the roster in the default place, including making a backup if needed.
  *
  * <p>Uses writeFile(String), a protected method that can write to a specific location.
  *
  * @deprecated Since 4.0 Use Roster.getDefault().writeRoster() instead
  * @see #writeRoster()
  */
 @Deprecated
 public static void writeRosterFile() {
   Roster.getDefault().writeRoster();
 }
Exemplo n.º 16
0
 /**
  * Locate the single instance of Roster, loading it if need be.
  *
  * <p>Calls {@link #getDefault() } to provide the single instance.
  *
  * @deprecated 4.5.1
  * @return The valid Roster object
  */
 @Deprecated
 public static synchronized Roster instance() {
   return Roster.getDefault();
 }