Skip to content

Commit

Permalink
Allow NodeSelector user to specify length of ID string (#213)
Browse files Browse the repository at this point in the history
NodeSelector constructs an ID string from the various information available in SNIP.  Right now, it uses just two terms from that.  This provides another ctor that lets the using code lengthen or shorten that.

Intended for use in the JMRI firmware download frame so that the software version ID can be included in the selector.

===

* allow user to specify length of ID string

* properly handle empty base info

* better Javadoc

* even better javadoc
  • Loading branch information
bobjacobsen authored Feb 22, 2023
1 parent c33ab5d commit 52dbd04
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions src/org/openlcb/swing/NodeSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,37 @@
* from a MimicNodeStore
*
* @author Bob Jacobsen Copyright (C) 2012
* @version $Revision$
*/
public class NodeSelector extends JPanel {
/** Comment for <code>serialVersionUID</code>. */
private static final long serialVersionUID = 1714640844679691939L;


private final PropertyChangeListener propertyChangeListener;
MimicNodeStore store;
JComboBox<ModelEntry> box;
private DefaultComboBoxModel<ModelEntry> model = new DefaultComboBoxModel<ModelEntry>();
private boolean seenLight = false;
private int termCount = 2; // how many terms to keep in ID string


/**
* Constructor that allows you to set the number of properties displayed
* after the NodeID.
*
* The properties will be shown in the order of User Name, User Description,
* Manufacturer+Model, Software version. Only non-empty values are shown.
*
* @param store Node store containing the existing network
* @param termCount Number of ID terms to include in the displayed ID
*/
public NodeSelector(MimicNodeStore store, int termCount) {
this(store);
this.termCount = termCount;
}

/**
* Constructor with default displayed ID consisting of NodeID,
* User Name and User Description.
* @param store Node store containing the existing network
*/
public NodeSelector(MimicNodeStore store) {
this.store = store;

Expand Down Expand Up @@ -98,7 +117,7 @@ protected class ModelEntry implements Comparable<ModelEntry>, PropertyChangeList

/**
* Constructor for prototype display value
*
*
* @param description prototype display value
*/
private ModelEntry(String description) {
Expand All @@ -115,17 +134,19 @@ private void updateDescription() {
StringBuilder sb = new StringBuilder();
sb.append(nodeMemo.getNodeID().toString());
int count = 0;
if (count < 2) {
if (count < termCount) {
count += addToDescription(ident.getUserName(), sb);
}
if (count < 2) {
if (count < termCount) {
count += addToDescription(ident.getUserDesc(), sb);
}
if (count < 2) {
count += addToDescription(ident.getMfgName() + ident.getModelName(),
if (count < termCount) {
if (!ident.getMfgName().isEmpty() || !ident.getModelName().isEmpty()) {
count += addToDescription(ident.getMfgName() + " " +ident.getModelName(),
sb);
}
}
if (count < 2) {
if (count < termCount) {
count += addToDescription(ident.getSoftwareVersion(), sb);
}
String newDescription = sb.toString();
Expand Down Expand Up @@ -174,7 +195,7 @@ public boolean equals(Object o) {
}
return false;
}

@Override
public int hashCode() {
return getNodeID().hashCode();
Expand Down

0 comments on commit 52dbd04

Please sign in to comment.