Skip to content
Permalink
Browse files

linting; use constants for throttle properites

  • Loading branch information...
pabender committed Sep 14, 2019
1 parent 9e1332f commit ddea987acea44c1e62ee9177f59c6468325f93a5
Showing with 556 additions and 551 deletions.
  1. +9 −0 java/src/jmri/Throttle.java
  2. +3 −2 java/src/jmri/jmris/AbstractThrottleServer.java
  3. +5 −5 java/src/jmri/jmris/srcp/JmriSRCPThrottleServer.java
  4. +3 −3 java/src/jmri/jmrit/dispatcher/AutoTrainsFrame.java
  5. +2 −2 java/src/jmri/jmrit/display/MemoryIcon.java
  6. +4 −3 java/src/jmri/jmrit/logix/ControlPanel.java
  7. +5 −7 java/src/jmri/jmrit/throttle/ControlPanel.java
  8. +3 −2 java/src/jmri/jmrit/throttle/SpeedPanel.java
  9. +4 −1 java/src/jmri/jmrit/throttle/ThrottlesTableModel.java
  10. +4 −2 java/src/jmri/jmrit/vsdecoder/EngineSoundEvent.java
  11. +7 −6 java/src/jmri/jmrit/vsdecoder/VSDecoder.java
  12. +5 −7 java/src/jmri/jmrit/withrottle/MultiThrottleController.java
  13. +3 −3 java/src/jmri/jmrix/AbstractThrottle.java
  14. +2 −2 java/src/jmri/jmrix/AbstractThrottleManager.java
  15. +4 −4 java/src/jmri/jmrix/can/cbus/CbusThrottle.java
  16. +2 −2 java/src/jmri/jmrix/debugthrottle/DebugThrottle.java
  17. +2 −2 java/src/jmri/jmrix/direct/Throttle.java
  18. +2 −2 java/src/jmri/jmrix/easydcc/EasyDccThrottle.java
  19. +140 −136 java/src/jmri/jmrix/lenz/XNetConstants.java
  20. +206 −225 java/src/jmri/jmrix/lenz/XNetThrottle.java
  21. +5 −5 java/src/jmri/jmrix/loconet/LocoNetThrottle.java
  22. +2 −2 java/src/jmri/jmrix/loconet/Pr2Throttle.java
  23. +5 −5 java/src/jmri/jmrix/marklin/MarklinThrottle.java
  24. +6 −6 java/src/jmri/jmrix/mrc/MrcThrottle.java
  25. +2 −2 java/src/jmri/jmrix/nce/NceThrottle.java
  26. +2 −2 java/src/jmri/jmrix/openlcb/OlcbThrottle.java
  27. +3 −3 java/src/jmri/jmrix/sprog/SprogCSThrottle.java
  28. +4 −4 java/src/jmri/jmrix/sprog/SprogThrottle.java
  29. +3 −2 java/src/jmri/jmrix/srcp/SRCPThrottle.java
  30. +6 −6 java/src/jmri/jmrix/tams/TamsThrottle.java
  31. +2 −2 java/src/jmri/jmrix/tmcc/SerialThrottle.java
  32. +2 −2 java/src/jmri/jmrix/zimo/Mx1Throttle.java
  33. +2 −2 java/src/jmri/server/json/throttle/JsonThrottle.java
  34. +9 −9 java/test/jmri/jmrit/dispatcher/LoadAtStartUpTest.java
  35. +1 −1 java/test/jmri/jmrit/roster/swing/RosterFrameTest.java
  36. +7 −7 java/test/jmri/jmrit/withrottle/MultiThrottleControllerTest.java
  37. +66 −66 java/test/jmri/jmrix/can/cbus/CbusThrottleManagerTest.java
  38. +9 −4 java/test/jmri/jmrix/easydcc/easydccmon/EasyDccMonFrameTest.java
  39. +5 −5 java/test/jmri/managers/AbstractThrottleManagerTestBase.java
@@ -29,6 +29,15 @@
*/
public interface Throttle {

/**
* Properties strings sent to property change listeners
*/
public static final String SPEEDSTEPS = "SpeedSteps"; // speed steps NOI18N
public static final String SPEEDSTEPMODE = "SpeedStepsMode"; // speed steps NOI18N
public static final String SPEEDSETTING = "SpeedSetting"; // speed setting NOI18N
public static final String ISFORWARD = "IsForward"; // direction setting NOI18N
public static final String SPEEDINCREMENT= "SpeedIncrement"; // direction setting NOI18N

/**
* Constants to represent the functions F0 through F28.
*/
@@ -198,8 +198,9 @@ public void notifyDecisionRequired(LocoAddress address, DecisionType question) {
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
switch (e.getPropertyName()) {
case "SpeedSetting":
case "SpeedSteps":
case Throttle.SPEEDSETTING:
case Throttle.SPEEDSTEPS:
case Throttle.ISFORWARD:
try {
clientserver.sendStatus(throttle.getLocoAddress());
} catch (IOException ioe) {
@@ -72,8 +72,8 @@ public void sendStatus(int bus, int address) throws IOException {
// address, so we need to convert the address to a DccLocoAddress
// object first.
DccLocoAddress addr = new DccLocoAddress(address, !(t.canBeShortAddress(address)));
Boolean isForward = (Boolean) t.getThrottleInfo(addr, "IsForward");
Float speedSetting = (Float) t.getThrottleInfo(addr, "SpeedSetting");
Boolean isForward = (Boolean) t.getThrottleInfo(addr, Throttle.ISFORWARD);
Float speedSetting = (Float) t.getThrottleInfo(addr, Throttle.SPEEDSETTING);
SpeedStepMode speedStepMode = (SpeedStepMode) t.getThrottleInfo(addr, "SpeedStepMode");
Boolean f0 = (Boolean) t.getThrottleInfo(addr, "F0");
Boolean f1 = (Boolean) t.getThrottleInfo(addr, "F1");
@@ -390,9 +390,9 @@ public void propertyChange(java.beans.PropertyChangeEvent e) {
log.debug("Property change event received " + e.getPropertyName() + " / " + e.getNewValue());
}
switch (e.getPropertyName()) {
case "SpeedSetting":
case "SpeedSteps":
case "IsForward":
case Throttle.SPEEDSETTING:
case Throttle.SPEEDSTEPS:
case Throttle.ISFORWARD:
try {
clientServer.sendStatus(bus, address);
} catch (IOException ioe) {
@@ -147,7 +147,7 @@ private void setupThrottle(AutoActiveTrain aat) {
}

private void handleThrottleChange(java.beans.PropertyChangeEvent e) {
if (!e.getPropertyName().equals("SpeedSetting") && !e.getPropertyName().equals("IsForward")) {
if (!e.getPropertyName().equals(Throttle.SPEEDSETTING) && !e.getPropertyName().equals(Throttle.ISFORWARD)) {
return; //ignore if not speed or direction
}
int index = _throttles.indexOf(e.getSource());
@@ -176,7 +176,7 @@ private void handleThrottleChange(java.beans.PropertyChangeEvent e) {
return;
}
jmri.DccLocoAddress addy = (jmri.DccLocoAddress) _throttles.get(index).getLocoAddress();
updateStatusLabel(status, jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, "SpeedSetting"), jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, "IsForward"));
updateStatusLabel(status, jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, Throttle.SPEEDSETTING), jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, Throttle.ISFORWARD));
}

private void updateStatusLabel(JLabel status, Object speed, Object forward) {
@@ -202,7 +202,7 @@ private void addThrottleListener(AutoActiveTrain aat) {
jmri.DccLocoAddress addy = (jmri.DccLocoAddress) _throttles.get(index).getLocoAddress();
jmri.InstanceManager.throttleManagerInstance().attachListener(addy, _throttleListeners.get(index));
JLabel status = _throttleStatus.get(index);
updateStatusLabel(status, jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, "SpeedSetting"), jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, "IsForward"));
updateStatusLabel(status, jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, Throttle.SPEEDSETTING), jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(addy, Throttle.ISFORWARD));
}
}

@@ -175,7 +175,7 @@ public void propertyChange(java.beans.PropertyChangeEvent e) {
displayState();
}
if (e.getSource() instanceof jmri.Throttle) {
if (e.getPropertyName().equals("IsForward")) {
if (e.getPropertyName().equals(jmri.Throttle.ISFORWARD)) {
Boolean boo = (Boolean) e.getNewValue();
if (boo) {
flipIcon(NamedIcon.NOFLIP);
@@ -440,7 +440,7 @@ protected Object updateIconFromRosterVal(RosterEntry roster) {
flipIcon(NamedIcon.HORIZONTALFLIP);
}
jmri.InstanceManager.throttleManagerInstance().attachListener(re.getDccLocoAddress(), this);
Object isForward = jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(re.getDccLocoAddress(), "IsForward");
Object isForward = jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(re.getDccLocoAddress(), jmri.Throttle.ISFORWARD);
if (isForward != null) {
if (!(Boolean) isForward) {
flipIcon(NamedIcon.HORIZONTALFLIP);
@@ -25,6 +25,7 @@
import jmri.DccThrottle;
import jmri.SpeedStepMode;

import jmri.Throttle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -140,7 +141,7 @@ public void propertyChange(java.beans.PropertyChangeEvent e) {
log.debug("propertyChange: " + e.getPropertyName() + ", newValue= "
+ e.getNewValue().toString());
}
if (e.getPropertyName().equals("SpeedSetting")) {
if (e.getPropertyName().equals(Throttle.SPEEDSETTING)) {
internalAdjust = true;
float speed = ((Float) e.getNewValue()).floatValue();
// speedSetting(speed);
@@ -151,11 +152,11 @@ public void propertyChange(java.beans.PropertyChangeEvent e) {
if (speed != 0.0F) {
_emergencyStop = (speed < 0.0F);
}
} else if (e.getPropertyName().equals("SpeedSteps")) {
} else if (e.getPropertyName().equals(Throttle.SPEEDSTEPS)) {
SpeedStepMode steps = (SpeedStepMode)e.getNewValue();
setSpeedSteps(steps);
_throttleFrame.setSpeedStepMode(steps);
} else if (e.getPropertyName().equals("IsForward")) {
} else if (e.getPropertyName().equals(Throttle.ISFORWARD)) {
boolean Forward = ((Boolean) e.getNewValue()).booleanValue();
_throttleFrame.setButtonForward(Forward);
} else {
@@ -34,10 +34,8 @@
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.MouseInputAdapter;
import jmri.DccThrottle;
import jmri.InstanceManager;
import jmri.LocoAddress;
import jmri.SpeedStepMode;

import jmri.*;
import jmri.jmrit.roster.Roster;
import jmri.jmrit.roster.RosterEntry;
import jmri.util.FileUtil;
@@ -1174,7 +1172,7 @@ public JSlider getSpeedSlider() {
// update the state of this panel if any of the properties change
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
if (e.getPropertyName().equals("SpeedSetting")) {
if (e.getPropertyName().equals(Throttle.SPEEDSETTING)) {
internalAdjust = true;
float speed = ((Float) e.getNewValue()).floatValue();
// multiply by MAX_SPEED, and round to find the new
@@ -1195,10 +1193,10 @@ public void propertyChange(java.beans.PropertyChangeEvent e) {
}
}
internalAdjust = false;
} else if (e.getPropertyName().equals("SpeedSteps")) {
} else if (e.getPropertyName().equals(Throttle.SPEEDSTEPS)) {
SpeedStepMode steps = (SpeedStepMode)e.getNewValue();
setSpeedStepsMode(steps);
} else if (e.getPropertyName().equals("IsForward")) {
} else if (e.getPropertyName().equals(Throttle.ISFORWARD)) {
boolean Forward = ((Boolean) e.getNewValue()).booleanValue();
setIsForward(Forward);
} else if (e.getPropertyName().equals(switchSliderFunction)) {
@@ -9,6 +9,7 @@
import javax.swing.WindowConstants;
import jmri.DccThrottle;
import jmri.LocoAddress;
import jmri.Throttle;
import jmri.jmrit.roster.RosterEntry;
import org.jdom2.Element;
import org.slf4j.Logger;
@@ -98,10 +99,10 @@ private void initGUI() {
*/
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
if (e.getPropertyName().equals("SpeedSetting")) {
if (e.getPropertyName().equals(Throttle.SPEEDSETTING)) {
currentThrottleVol = ((Float) e.getNewValue()).floatValue();
scaleSpeedLabel.setText(updateSpeedLabel(useSpeedProfile, currentThrottleVol, currentIsForward));
} else if (e.getPropertyName().equals("IsForward")) {
} else if (e.getPropertyName().equals(Throttle.ISFORWARD)) {
currentIsForward = (boolean) e.getNewValue();
scaleSpeedLabel.setText(updateSpeedLabel(useSpeedProfile, currentThrottleVol, currentIsForward));
}
@@ -6,6 +6,7 @@
import jmri.DccLocoAddress;
import jmri.DccThrottle;
import jmri.LocoAddress;
import jmri.Throttle;

public class ThrottlesTableModel extends AbstractTableModel implements AddressListener, java.beans.PropertyChangeListener {

@@ -76,7 +77,9 @@ public void notifyConsistAddressThrottleFound(DccThrottle throttle) {

@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
if ((e.getPropertyName().equals("SpeedSetting")) || (e.getPropertyName().equals("SpeedSteps")) || (e.getPropertyName().equals("IsForward"))) {
if ((e.getPropertyName().equals(Throttle.SPEEDSETTING)) ||
(e.getPropertyName().equals(Throttle.SPEEDSTEPS)) ||
(e.getPropertyName().equals(Throttle.ISFORWARD))) {
fireTableDataChanged();
}
}
@@ -3,6 +3,8 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;

import jmri.Throttle;
import org.jdom2.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -132,9 +134,9 @@ public void guiAction(PropertyChangeEvent evt) {
@Override
public void propertyChange(PropertyChangeEvent event) {
super.propertyChange(event);
if (event.getPropertyName().equals("SpeedSetting")) {
if (event.getPropertyName().equals(Throttle.SPEEDSETTING)) {
((EngineSound) parent.getSound("ENGINE")).handleSpeedChange((Float) event.getNewValue(), engine_pane);
} else if (event.getPropertyName().equals("IsForward")) {
} else if (event.getPropertyName().equals(Throttle.ISFORWARD)) {
((EngineSound) parent.getSound("ENGINE")).changeLocoDirection((Boolean) event.getNewValue() ? 1 : -1);
log.debug("is forward: {}", event.getNewValue());
} else if (event.getPropertyName().startsWith("F")) {
@@ -9,6 +9,7 @@
import jmri.Audio;
import jmri.DccLocoAddress;
import jmri.LocoAddress;
import jmri.Throttle;
import jmri.jmrit.operations.locations.Location;
import jmri.jmrit.operations.routes.RouteLocation;
import jmri.jmrit.operations.routes.Route;
@@ -299,21 +300,21 @@ protected void throttlePropertyChange(PropertyChangeEvent event) {
log.debug("VSDecoderPane throttle property change: {}", eventName);

if (eventName.equals("throttleAssigned")) {
Float s = (Float) jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(config.getDccAddress(), "SpeedSetting");
Float s = (Float) jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(config.getDccAddress(), Throttle.SPEEDSETTING);
if (s != null) {
((EngineSound) this.getSound("ENGINE")).setFirstSpeed(true); // Auto-start needs this
// Mimic a throttlePropertyChange to propagate the current (init) speed setting of the throttle.
log.debug("Existing DCC Throttle found. Speed: {}", s);
this.throttlePropertyChange(new PropertyChangeEvent(this, "SpeedSetting", null, s));
this.throttlePropertyChange(new PropertyChangeEvent(this, Throttle.SPEEDSETTING, null, s));
}

// Check for an existing throttle and get loco direction if it exists.
Boolean b = (Boolean) jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(config.getDccAddress(), "IsForward");
Boolean b = (Boolean) jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(config.getDccAddress(), Throttle.ISFORWARD);
if (b != null) {
dirfn = b ? 1 : -1;
log.debug("Existing DCC Throttle found. IsForward is {}", b);
log.debug("Initial dirfn: {} for {}", dirfn, config.getDccAddress());
this.throttlePropertyChange(new PropertyChangeEvent(this, "IsForward", null, b));
this.throttlePropertyChange(new PropertyChangeEvent(this, Throttle.ISFORWARD, null, b));
} else {
log.warn("No existing DCC throttle found.");
}
@@ -342,11 +343,11 @@ protected void throttlePropertyChange(PropertyChangeEvent event) {
t.propertyChange(event);
}

if (eventName.equals("SpeedSetting")) {
if (eventName.equals(Throttle.SPEEDSETTING)) {
currentspeed = (float) this.getSound("ENGINE").speedCurve((float) event.getNewValue());
}

if (eventName.equals("IsForward")) {
if (eventName.equals(Throttle.ISFORWARD)) {
dirfn = (Boolean) event.getNewValue() ? 1 : -1;
}
}
@@ -3,10 +3,8 @@
import java.beans.PropertyChangeEvent;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import jmri.LocoAddress;
import jmri.SpeedStepMode;
import jmri.DccThrottle;
import jmri.InstanceManager;

import jmri.*;
import jmri.jmrit.roster.RosterEntry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,23 +71,23 @@ public void propertyChange(PropertyChangeEvent event) {
listener.sendPacketToDevice(message.toString());
}
}
if (eventName.matches("SpeedSteps")) {
if (eventName.matches(Throttle.SPEEDSTEPS)) {
StringBuilder message = new StringBuilder(buildPacketWithChar('A'));
message.append("s");
message.append(encodeSpeedStepMode((SpeedStepMode)event.getNewValue()));
for (ControllerInterface listener : controllerListeners) {
listener.sendPacketToDevice(message.toString());
}
}
if (eventName.matches("IsForward")) {
if (eventName.matches(Throttle.ISFORWARD)) {
StringBuilder message = new StringBuilder(buildPacketWithChar('A'));
message.append("R");
message.append((Boolean) event.getNewValue() ? "1" : "0");
for (ControllerInterface listener : controllerListeners) {
listener.sendPacketToDevice(message.toString());
}
}
if (eventName.matches("SpeedSetting")) {
if (eventName.matches(Throttle.SPEEDSETTING)) {
float currentSpeed = ((Float) event.getNewValue()).floatValue();
log.debug("Speed Setting: {} head of queue {}",currentSpeed, lastSentSpeed.peek());
if(lastSentSpeed.isEmpty()) {
@@ -120,7 +120,7 @@ public void setSpeedSetting(float speed) {
@Override
public void setSpeedSetting(float speed, boolean allowDuplicates, boolean allowDuplicatesOnStop) {
if (Math.abs(this.speedSetting - speed) > 0.0001) {
notifyPropertyChangeListener("SpeedSetting", this.speedSetting, this.speedSetting = speed);
notifyPropertyChangeListener(SPEEDSETTING, this.speedSetting, this.speedSetting = speed);
}
record(speed);
}
@@ -154,7 +154,7 @@ public boolean getIsForward() {
@Override
public void setIsForward(boolean forward) {
if (forward != this.isForward) {
notifyPropertyChangeListener("IsForward", this.isForward, this.isForward = forward);
notifyPropertyChangeListener(ISFORWARD, this.isForward, this.isForward = forward);
}
}

@@ -1748,7 +1748,7 @@ protected void sendMomentaryFunctionGroup5() {
public void setSpeedStepMode(SpeedStepMode Mode) {
log.debug("Speed Step Mode Change from:{} to Mode:{}",this.speedStepMode,Mode);
if (speedStepMode != Mode) {
notifyPropertyChangeListener("SpeedSteps", this.speedStepMode,
notifyPropertyChangeListener(SPEEDSTEPS, this.speedStepMode,
this.speedStepMode = Mode);
}
}
@@ -966,10 +966,10 @@ public Object getThrottleInfo(LocoAddress la, String item) {
} else {
return null;
}
if (item.equals("IsForward")) {
if (item.equals(Throttle.ISFORWARD)) {
return t.getIsForward();
} else if (item.startsWith("Speed")) {
if (item.equals("SpeedSetting")) {
if (item.equals(Throttle.SPEEDSETTING)) {
return t.getSpeedSetting();
} else if (item.equals("SpeedIncrement")) {
return t.getSpeedIncrement();
@@ -506,7 +506,7 @@ public void setSpeedSetting(float speed) {

if (Math.abs(oldSpeed - this.speedSetting) > 0.0001) {
sendToLayout();
notifyPropertyChangeListener("SpeedSetting", oldSpeed, this.speedSetting);
notifyPropertyChangeListener(SPEEDSETTING, oldSpeed, this.speedSetting);
record(this.speedSetting); // float
}
}
@@ -553,7 +553,7 @@ protected void updateSpeedSetting(int speed) {
}

if (Math.abs(oldSpeed - this.speedSetting) > 0.0001) {
notifyPropertyChangeListener("SpeedSetting", oldSpeed, this.speedSetting);
notifyPropertyChangeListener(SPEEDSETTING, oldSpeed, this.speedSetting);
record(this.speedSetting); // float
}
}
@@ -568,7 +568,7 @@ public void setIsForward(boolean forward) {
this.isForward = forward;
if (old != this.isForward) {
sendToLayout();
notifyPropertyChangeListener("IsForward", old, isForward);
notifyPropertyChangeListener(ISFORWARD, old, isForward);
}
}

@@ -583,7 +583,7 @@ protected void updateIsForward(boolean forward) {
isForward = forward;
// updateSpeedSetting(intSpeed(speedSetting));
if (old != isForward) {
notifyPropertyChangeListener("IsForward", old, isForward);
notifyPropertyChangeListener(ISFORWARD, old, isForward);
}
}

0 comments on commit ddea987

Please sign in to comment.
You can’t perform that action at this time.