Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/org/openlcb/cdi/CdiRep.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ public static interface IntegerRep extends Item {

public int getSize();

// Did the CDI content hint that this value should be presented as a slider?
public boolean isSliderHint();
// Does the slider itself immediately write its value on change?
// Should the slider itself immediately write its value on change?
public boolean isSliderImmediate();
public int getSliderDivisions();
// Optionally specifies the 'distance' between tick marks on the slider.
// If 0 (default value), don't show tick marks.
public int getSliderTickSpacing();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a documentation comment that tells what this value is, especially the error case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done!

}

public static interface BitRep extends Item {
Expand Down
14 changes: 7 additions & 7 deletions src/org/openlcb/cdi/jdom/JdomCdiRep.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,16 @@ public boolean isSliderImmediate() {
}

@Override
public int getSliderDivisions() {
public int getSliderTickSpacing() {
Element hints = e.getChild("hints");
if (hints == null) return 1;
if (hints == null) return 0;
Element slider = hints.getChild("slider");
if (slider == null) return 1;
Attribute divisions = slider.getAttribute("divisions");
if (divisions == null) return 1;
if (slider == null) return 0;
Attribute tickSpacing = slider.getAttribute("tickSpacing");
if (tickSpacing == null) return 0;
try {
return divisions.getIntValue();
} catch (org.jdom2.DataConversionException e) { return 1; }
return tickSpacing.getIntValue();
} catch (org.jdom2.DataConversionException e) { return 0; }
}

}
Expand Down
30 changes: 17 additions & 13 deletions src/org/openlcb/cdi/swing/CdiPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2374,7 +2374,8 @@ private class IntPane extends EntryPane {
JSlider slider = null;
CdiRep.Map map = null;
private final ConfigRepresentation.IntegerEntry entry;
boolean first = true; // used to suppress slider output on initial change
boolean suppressExternal = false; // used to suppress slider output when changed from read
boolean suppressInternal = false; // used to suppress slider output when changed internally


IntPane(ConfigRepresentation.IntegerEntry e) {
Expand All @@ -2398,15 +2399,10 @@ public java.awt.Dimension getMaximumSize() {
// display a slider
slider = new JSlider((int)entry.rep.getMin(), (int)entry.rep.getMax());
slider.setOpaque(true); // so you can color it
if (entry.rep.getSliderDivisions() > 1) {
if (entry.rep.getSliderTickSpacing() > 1) {
// display divisions on the slider
int divisionSpacing =
(int)Math.round(
(entry.rep.getMax()-entry.rep.getMin()+0.0) // force float calculation
/entry.rep.getSliderDivisions()
);
slider.setMajorTickSpacing(divisionSpacing);
slider.setLabelTable(slider.createStandardLabels(divisionSpacing));
slider.setMajorTickSpacing(entry.rep.getSliderTickSpacing());
slider.setLabelTable(slider.createStandardLabels(entry.rep.getSliderTickSpacing()));
slider.setPaintTicks(true);
slider.setPaintLabels(true);
}
Expand All @@ -2416,9 +2412,12 @@ public java.awt.Dimension getMaximumSize() {
slider.addChangeListener(new javax.swing.event.ChangeListener(){
public void stateChanged(javax.swing.event.ChangeEvent e) {
if (!slider.getValueIsAdjusting()) {
if (!first) writeDisplayTextToNode();
first = false;
if (!suppressInternal && !suppressExternal) {
writeDisplayTextToNode();
}
}
suppressExternal = false;
suppressInternal = false;
}
});
}
Expand Down Expand Up @@ -2466,13 +2465,15 @@ protected void writeDisplayTextToNode() {
value = Long.parseLong(textField.getText());
} else if (slider != null) {
// get value from current slider position
suppressInternal = true; // will be set false once change works through
value = slider.getValue();
} else {
// have to get key from stored map value
String entry = (String) box.getSelectedItem();
String key = map.getKey(entry);
value = Long.parseLong(key);
}
suppressExternal = true; // will be reset when the change returns
entry.setValue(value);
_changeMade = true;
notifyTabColorRefresh();
Expand All @@ -2481,7 +2482,10 @@ protected void writeDisplayTextToNode() {
@Override
protected void updateDisplayText(@NonNull String value) {
if (textField != null) textField.setText(value);
if (slider != null) slider.setValue(Integer.parseInt(value));
if (slider != null) {
suppressInternal = true;
slider.setValue(Integer.parseInt(value));
}
if (box != null) {
// check to see if item exists
box.setSelectedItem(value);
Expand Down Expand Up @@ -2576,7 +2580,7 @@ void updateWriteButton() {
}

static final int MAX_SINGLE_LINE_ENTRY = 64; // somewhat arbitrary max length of single-line entry
private class StringPane extends EntryPane {
private class StringPane extends EntryPane {
JTextComponent textField;
private final ConfigRepresentation.StringEntry entry;

Expand Down
2 changes: 1 addition & 1 deletion src/org/openlcb/implementations/DatagramService.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public DatagramService(NodeID here, Connection downstream) {
*/
public void sendData(DatagramServiceTransmitMemo memo) {
if (xmtMemo != null) {
logger.log(Level.SEVERE, "Overriding datagram transmit memo. old {0} new {1}", new Object[]{xmtMemo, memo}); //log
logger.log(Level.SEVERE, "Overriding datagram transmit memo. old {0} new {1}", new Object[]{xmtMemo, memo});
}
xmtMemo = memo;
Message m = new DatagramMessage(here, memo.dest, memo.data);
Expand Down