Skip to content

Commit

Permalink
Hopefully reverted to proper state.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory-J-Bedlek committed Aug 6, 2020
1 parent dcdd3e5 commit a313525
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 100 deletions.
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/ctc/CodeButtonHandler.java
Expand Up @@ -344,7 +344,7 @@ private boolean allowSignalDirectionChangePart2(int presentSignalDirectionLever)
private boolean trafficLockingValid(int presentSignalDirectionLever) {
// If asking for a route and it indicates an error (a conflict), DO NOTHING!
if (_mTrafficLocking != null) {
TrafficLockingInfo trafficLockingInfo = _mTrafficLocking.valid(presentSignalDirectionLever);
TrafficLockingInfo trafficLockingInfo = _mTrafficLocking.valid(presentSignalDirectionLever, _mFleeting.isFleetingEnabled());
_mLockedRoute = trafficLockingInfo._mLockedRoute; // Can be null! This is the bread crumb trail when running time expires.
return trafficLockingInfo._mReturnStatus;
}
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/ctc/Fleeting.java
Expand Up @@ -16,7 +16,7 @@ public Fleeting (String fleetingToggleInternalSensor, boolean defaultFleetingEna

public void removeAllListeners() {} // None done.

public boolean isFleetingEnabled () {
public boolean isFleetingEnabled() {
if (_mFleetingToggleInternalSensor.valid()) return _mFleetingToggleInternalSensor.getKnownState() == Sensor.ACTIVE;
return _mDefaultFleetingEnabled;
}
Expand Down
47 changes: 5 additions & 42 deletions java/src/jmri/jmrit/ctc/ctcserialdata/ProjectsCommonSubs.java
Expand Up @@ -6,10 +6,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.ListIterator;

import javax.swing.ButtonGroup;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVPrinter;
Expand All @@ -21,18 +18,8 @@

public class ProjectsCommonSubs {
static final public char SSV_SEPARATOR = ';';
static final public char CSV_SEPARATOR = ','; // What "CSVFormat.DEFAULT.getDelimiter()" would return.

static public ArrayList<String> getArrayListFromCSV(String csvString, boolean convert) {
ArrayList<String> result = helper1(csvString, CSV_SEPARATOR);
if (convert) {
for (final ListIterator<String> iterator = result.listIterator(); iterator.hasNext();) {
final String element = iterator.next();
iterator.set(convertNonEscapeToEscape(element));
}
}
return result;
}
static public ArrayList<String> getArrayListFromCSV(String csvString) { return helper1(csvString, CSVFormat.DEFAULT.getDelimiter());}
static public ArrayList<String> getArrayListFromSSV(String ssvString) { return helper1(ssvString, SSV_SEPARATOR); }
static private ArrayList<String> helper1(String ssvString, char separator) {
ArrayList<String> list = new ArrayList<>();
Expand All @@ -43,28 +30,11 @@ static private ArrayList<String> helper1(String ssvString, char separator) {
}
return list;
}

static final public String ESCAPE_CHARACTER = "~";
static final public String ESCAPED_ESCAPE_STRING = "~~";
static final public String CSV_SEPARATOR_STRING = ",";
static final public String ESCAPED_CSV_STRING = "~0";
static final public String SSV_SEPARATOR_STRING = ";";
static final public String ESCAPED_SSV_STRING = "~1";
static public String convertNonEscapeToEscape(String nonEscapeString) {
String tempString = nonEscapeString.replace(ESCAPE_CHARACTER, ESCAPED_ESCAPE_STRING);
tempString = tempString.replace(CSV_SEPARATOR_STRING, ESCAPED_CSV_STRING);
return tempString.replace(SSV_SEPARATOR_STRING, ESCAPED_SSV_STRING);
}
static public String convertEscapeToNonEscape(String escapedString) {
String tempString = escapedString.replace(ESCAPED_ESCAPE_STRING, ESCAPE_CHARACTER);
tempString = tempString.replace(ESCAPED_CSV_STRING, CSV_SEPARATOR_STRING);
return tempString.replace(ESCAPED_SSV_STRING, SSV_SEPARATOR_STRING);
}

// Returns an ArrayList guaranteed to have A MINIMUM of "returnArrayListSize" entries (too many is OK!),
// Returns an ArrayList guaranteed to have exactly "returnArrayListSize" entries,
// and if the passed "csvString" has too few entries, then those missing end values are set to "":
static public ArrayList<String> getFixedArrayListSizeFromCSV(String csvString, int returnArrayListSize, boolean convert) {
ArrayList<String> returnArray = getArrayListFromCSV(csvString, convert);
static public ArrayList<String> getFixedArrayListSizeFromCSV(String csvString, int returnArrayListSize) {
ArrayList<String> returnArray = getArrayListFromCSV(csvString);
while (returnArray.size() < returnArrayListSize) returnArray.add("");
return returnArray;
}
Expand All @@ -75,14 +45,7 @@ static public int getIntFromStringNoThrow(String aString, int defaultValueIfProb
return returnValue;
}

static public String constructCSVStringFromArrayList(ArrayList<String> stringArrayList, boolean convert) {
if (convert) {
String result = constructSeparatorStringFromArray(stringArrayList, ProjectsCommonSubs.CSV_SEPARATOR);
return convertEscapeToNonEscape(result);
} else {
return constructSeparatorStringFromArray(stringArrayList, ProjectsCommonSubs.CSV_SEPARATOR);
}
}
static public String constructCSVStringFromArrayList(ArrayList<String> stringArrayList) { return constructSeparatorStringFromArray(stringArrayList, CSVFormat.DEFAULT.getDelimiter()); }
static public String constructSSVStringFromArrayList(ArrayList<String> stringArrayList) { return constructSeparatorStringFromArray(stringArrayList, ProjectsCommonSubs.SSV_SEPARATOR); }
static private String constructSeparatorStringFromArray(ArrayList<String> list, char separator) {
try (CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT.withQuote(null).withDelimiter(separator).withRecordSeparator(null))) {
Expand Down
Expand Up @@ -103,11 +103,16 @@ public static CodeButtonHandlerData uECBHDWSD_TUL(ProgramProperties programPrope
return returnValue;
}

/* This is the "heart" of the pattern match system: It substitutes the passed
value whereever it see a single "#" in the passed template. It does not
support escapes, it will fix ALL "#" with that number in the passed template.
It is indescriminate.
*/
/**
* This is the "heart" of the pattern match system: It substitutes the passed
* value where ever it see a single "#" in the passed template. It does not
* support escapes, it will fix ALL "#" with that number in the passed template.
* It is indiscriminate.
*
* @param value The "number" that will be substituted where the template parameter is
* @param template The pattern used to generate the result.
* @return Modified string. ALL locations modified indiscriminately.
*/
private static String substituteValueForPoundSigns(int value, String template) {
int indexOf;
while (-1 != (indexOf = template.indexOf('#'))) { template = template.substring(0, indexOf) + Integer.toString(value) + template.substring(indexOf+1); }
Expand Down
8 changes: 2 additions & 6 deletions java/src/jmri/jmrit/ctc/editor/code/CommonSubs.java
Expand Up @@ -9,7 +9,6 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
Expand All @@ -19,7 +18,6 @@
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.NumberFormatter;

import jmri.InstanceManager;
import jmri.BlockManager;
import jmri.SensorManager;
Expand All @@ -29,8 +27,6 @@
import jmri.jmrit.ctc.ctcserialdata.CTCSerialData;
import jmri.jmrit.ctc.ctcserialdata.CodeButtonHandlerData;
import jmri.jmrit.ctc.ctcserialdata.ProjectsCommonSubs;
import static jmri.jmrit.ctc.ctcserialdata.ProjectsCommonSubs.convertNonEscapeToEscape;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;

Expand Down Expand Up @@ -91,9 +87,9 @@ public static String getCSVStringFromDefaultTableModel(DefaultTableModel default
}
}
}
try (CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT.withQuote(null).withDelimiter(ProjectsCommonSubs.CSV_SEPARATOR).withRecordSeparator(null))) {
try (CSVPrinter printer = new CSVPrinter(new StringBuilder(), CSVFormat.DEFAULT.withQuote(null).withRecordSeparator(null))) {
printer.printRecord(entries);
return ProjectsCommonSubs.convertEscapeToNonEscape(printer.getOut().toString());
return printer.getOut().toString();
} catch (IOException ex) {
log.error("Unable to create CSV", ex);
return "";
Expand Down
9 changes: 5 additions & 4 deletions java/src/jmri/jmrit/ctc/editor/gui/FrmMainForm.form
Expand Up @@ -287,11 +287,12 @@
<Component id="_mButtonWriteXMLFiles" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="103" alignment="0" groupAlignment="1" max="-2" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="deleteButton" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="addButton" alignment="0" min="-2" pref="63" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="4" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="addButton" max="32767" attributes="0"/>
<Component id="deleteButton" max="32767" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="_mCheckEverythingWithJMRI" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="changeNumbersButton" alignment="0" max="32767" attributes="0"/>
Expand Down

0 comments on commit a313525

Please sign in to comment.