From d41e7cb937214327cbcde769a2f0a4a4abbc53e2 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Mon, 16 Mar 2015 11:27:29 -0500 Subject: [PATCH] Genericized the VS* suite of classes, reducing redundancy. Added a element for variables in TV files. Added a Trick 13 to Trick 15 TV file converter. Updated .gitignore files. fixes #21 --- .gitignore | 1 + bin/convert_tv_file | 42 +++ docs/.gitignore | 2 + doxygen/.gitignore | 1 + .../src/trick/common/utils/vs/VSBoolean.java | 31 +- .../src/trick/common/utils/vs/VSByte.java | 31 +- .../src/trick/common/utils/vs/VSDouble.java | 28 +- .../src/trick/common/utils/vs/VSFloat.java | 31 +- .../src/trick/common/utils/vs/VSInteger.java | 31 +- .../src/trick/common/utils/vs/VSLong.java | 31 +- .../src/trick/common/utils/vs/VSShort.java | 31 +- .../src/trick/common/utils/vs/VSString.java | 26 +- .../src/trick/common/utils/vs/VSValue.java | 33 +- .../src/trick/common/utils/vs/Variable.java | 150 ++++----- .../common/utils/vs/VariableTracker.java | 4 +- .../java/src/trick/stripchart/StripChart.java | 2 +- .../trick/stripchart/StripChartManager.java | 2 +- .../java/src/trick/tv/TVApplication.java | 126 +------- trick_source/java/src/trick/tv/TVBean.java | 4 +- trick_source/java/src/trick/tv/TVBoolean.java | 4 +- trick_source/java/src/trick/tv/TVByte.java | 11 +- trick_source/java/src/trick/tv/TVDouble.java | 2 +- .../java/src/trick/tv/TVEnumeration.java | 22 +- trick_source/java/src/trick/tv/TVFloat.java | 2 +- trick_source/java/src/trick/tv/TVInteger.java | 11 +- trick_source/java/src/trick/tv/TVLong.java | 11 +- trick_source/java/src/trick/tv/TVShort.java | 11 +- trick_source/java/src/trick/tv/TVString.java | 2 +- .../java/src/trick/tv/VariableTable.java | 2 +- .../java/src/trick/tv/resources/tv.xsd | 289 ++++++++---------- 30 files changed, 373 insertions(+), 601 deletions(-) create mode 100755 bin/convert_tv_file create mode 100644 docs/.gitignore create mode 100644 doxygen/.gitignore diff --git a/.gitignore b/.gitignore index 6cb2271d..7ebd4036 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ lib_Darwin_* *.tab.c *.tab.h *.swp +*.dox Makefile_jsc_dirs diff --git a/bin/convert_tv_file b/bin/convert_tv_file new file mode 100755 index 00000000..1f8f0a84 --- /dev/null +++ b/bin/convert_tv_file @@ -0,0 +1,42 @@ +#!/usr/bin/python + +import sys +import xml.etree.ElementTree as ET + +arguments = sys.argv[1:] +if len(arguments) == 0: + print 'A utility script for converting TV files from Trick 13 to Trick 15.' + print 'usage: convert_tv_file ' +else: + types = ( + ('Boolean', 'boolean'), + ('Byte', 'byte'), + ('Double', 'double'), + ('Enumeration', 'string'), + ('Float', 'float'), + ('Integer', 'int'), + ('Long', 'long'), + ('Short', 'short'), + ('String', 'string') + ) + + for file in arguments: + print 'Converting ' + file + tree = ET.parse(file) + root = tree.getroot() + + for variable in root.findall('variable'): + for type in types: + value = variable.find('tv' + type[0]) + if value is not None: + value = value.find('value') + value.set('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') + value.set('xmlns:xs', 'http://www.w3.org/2001/XMLSchema') + value.set('xsi:type', 'xs:' + type[1]) + break + + if file.endswith('.tv'): + file = file[:-3] + newFile = file + '_15.tv' + tree.write(newFile) + print 'Converted to ' + newFile diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 00000000..4fc1b6bb --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,2 @@ +html +trick.tag diff --git a/doxygen/.gitignore b/doxygen/.gitignore new file mode 100644 index 00000000..bc7f09ee --- /dev/null +++ b/doxygen/.gitignore @@ -0,0 +1 @@ +warning_msgs diff --git a/trick_source/java/src/trick/common/utils/vs/VSBoolean.java b/trick_source/java/src/trick/common/utils/vs/VSBoolean.java index f89c1ff5..41efc99e 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSBoolean.java +++ b/trick_source/java/src/trick/common/utils/vs/VSBoolean.java @@ -1,37 +1,18 @@ package trick.common.utils.vs; -import javax.xml.bind.annotation.XmlRootElement; +public class VSBoolean extends VSValue { -@XmlRootElement -public class VSBoolean extends VSValue { - - private static final long serialVersionUID = 3720173025885361193L; - - public boolean value; - - public VSBoolean() {} - - public VSBoolean(boolean value) { - this.value = value; + protected VSBoolean() { + this(false); } - public boolean getValue() { - return value; + public VSBoolean(boolean value) { + super(value); } @Override public void fromVariableServer(String string) { - value = Integer.parseInt(string.trim()) != 0; - } - - @Override - public String toVariableServer() { - return value ? "1" : "0"; - } - - @Override - public String toString() { - return Boolean.toString(value); + setValue(Integer.parseInt(string.trim()) != 0); } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSByte.java b/trick_source/java/src/trick/common/utils/vs/VSByte.java index 8824b204..1b49fbb4 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSByte.java +++ b/trick_source/java/src/trick/common/utils/vs/VSByte.java @@ -2,38 +2,19 @@ package trick.common.utils.vs; import java.math.BigInteger; -import javax.xml.bind.annotation.XmlRootElement; +public class VSByte extends VSValue { -@XmlRootElement -public class VSByte extends VSValue { - - private static final long serialVersionUID = 8405472938103497097L; - - public byte value; - - public VSByte() {} - - public VSByte(byte value) { - this.value = value; + protected VSByte() { + this((byte)0); } - public byte getValue() { - return value; + public VSByte(byte value) { + super(value); } @Override public void fromVariableServer(String string) { - value = new BigInteger(string.trim(), 10).byteValue(); - } - - @Override - public String toVariableServer() { - return Byte.toString(value); - } - - @Override - public String toString() { - return Byte.toString(value); + setValue(new BigInteger(string.trim(), 10).byteValue()); } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSDouble.java b/trick_source/java/src/trick/common/utils/vs/VSDouble.java index f8628107..fdf4728c 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSDouble.java +++ b/trick_source/java/src/trick/common/utils/vs/VSDouble.java @@ -1,37 +1,23 @@ package trick.common.utils.vs; -import javax.xml.bind.annotation.XmlRootElement; +public class VSDouble extends VSValue { -@XmlRootElement -public class VSDouble extends VSValue { - - private static final long serialVersionUID = -2895628958106970334L; - - public double value; - - public VSDouble() {} - - public VSDouble(double value) { - this.value = value; + protected VSDouble() { + this(0); } - public double getValue() { - return value; + public VSDouble(double value) { + super(value); } @Override public void fromVariableServer(String string) { - value = Double.parseDouble(string.trim()); + setValue(Double.parseDouble(string.trim())); } @Override public String toVariableServer() { - return Double.toString(value); - } - - @Override - public String toString() { - return Double.toString(value); + return toString(); } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSFloat.java b/trick_source/java/src/trick/common/utils/vs/VSFloat.java index 45f5a35a..cc0f3743 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSFloat.java +++ b/trick_source/java/src/trick/common/utils/vs/VSFloat.java @@ -1,37 +1,18 @@ package trick.common.utils.vs; -import javax.xml.bind.annotation.XmlRootElement; +public class VSFloat extends VSValue { -@XmlRootElement -public class VSFloat extends VSValue { - - private static final long serialVersionUID = -4629816234119061148L; - - public float value; - - public VSFloat() {} - - public VSFloat(float value) { - this.value = value; + protected VSFloat() { + this(0); } - public float getValue() { - return value; + public VSFloat(float value) { + super(value); } @Override public void fromVariableServer(String string) { - value = Float.parseFloat(string.trim()); - } - - @Override - public String toVariableServer() { - return Float.toString(value); - } - - @Override - public String toString() { - return Float.toString(value); + setValue(Float.parseFloat(string.trim())); } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSInteger.java b/trick_source/java/src/trick/common/utils/vs/VSInteger.java index 01520483..92531e83 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSInteger.java +++ b/trick_source/java/src/trick/common/utils/vs/VSInteger.java @@ -2,38 +2,19 @@ package trick.common.utils.vs; import java.math.BigInteger; -import javax.xml.bind.annotation.XmlRootElement; +public class VSInteger extends VSValue { -@XmlRootElement -public class VSInteger extends VSValue { - - private static final long serialVersionUID = 1314788741378939173L; - - public int value; - - public VSInteger() {} - - public VSInteger(int value) { - this.value = value; + protected VSInteger() { + this(0); } - public int getValue() { - return value; + public VSInteger(int value) { + super(value); } @Override public void fromVariableServer(String string) { - value = new BigInteger(string.trim(), 10).intValue(); - } - - @Override - public String toVariableServer() { - return Integer.toString(value); - } - - @Override - public String toString() { - return Integer.toString(value); + setValue(new BigInteger(string.trim(), 10).intValue()); } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSLong.java b/trick_source/java/src/trick/common/utils/vs/VSLong.java index 35a7ea7d..88c0f895 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSLong.java +++ b/trick_source/java/src/trick/common/utils/vs/VSLong.java @@ -2,38 +2,19 @@ package trick.common.utils.vs; import java.math.BigInteger; -import javax.xml.bind.annotation.XmlRootElement; +public class VSLong extends VSValue { -@XmlRootElement -public class VSLong extends VSValue { - - private static final long serialVersionUID = -7792501925528852232L; - - public long value; - - public VSLong() {} - - public VSLong(long value) { - this.value = value; + protected VSLong() { + this(0); } - public long getValue() { - return value; + public VSLong(long value) { + super(value); } @Override public void fromVariableServer(String string) { - value = new BigInteger(string.trim(), 10).longValue(); - } - - @Override - public String toVariableServer() { - return Long.toString(value); - } - - @Override - public String toString() { - return Long.toString(value); + setValue(new BigInteger(string.trim(), 10).longValue()); } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSShort.java b/trick_source/java/src/trick/common/utils/vs/VSShort.java index 91904c85..65d857ed 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSShort.java +++ b/trick_source/java/src/trick/common/utils/vs/VSShort.java @@ -2,38 +2,19 @@ package trick.common.utils.vs; import java.math.BigInteger; -import javax.xml.bind.annotation.XmlRootElement; +public class VSShort extends VSValue { -@XmlRootElement -public class VSShort extends VSValue { - - private static final long serialVersionUID = 5431648313760456676L; - - public short value; - - public VSShort() {} - - public VSShort(short value) { - this.value = value; + protected VSShort() { + this((short)0); } - public short getValue() { - return value; + public VSShort(short value) { + super(value); } @Override public void fromVariableServer(String string) { - value = new BigInteger(string.trim(), 10).shortValue(); - } - - @Override - public String toVariableServer() { - return Short.toString(value); - } - - @Override - public String toString() { - return Short.toString(value); + setValue(new BigInteger(string.trim(), 10).shortValue()); } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSString.java b/trick_source/java/src/trick/common/utils/vs/VSString.java index 398583b3..3ab4d9a8 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSString.java +++ b/trick_source/java/src/trick/common/utils/vs/VSString.java @@ -1,37 +1,21 @@ package trick.common.utils.vs; -import javax.xml.bind.annotation.XmlRootElement; +public class VSString extends VSValue { -@XmlRootElement -public class VSString extends VSValue { - - private static final long serialVersionUID = 2238385297450301960L; - - public String value; - - public VSString() {} + protected VSString() {} public VSString(String value) { - this.value = value; - } - - public String getValue() { - return value; + super(value); } @Override public void fromVariableServer(String string) { - value = string; + setValue(string); } @Override public String toVariableServer() { - return "\"" + value + "\""; - } - - @Override - public String toString() { - return value; + return "\"" + super.toVariableServer() + "\""; } } diff --git a/trick_source/java/src/trick/common/utils/vs/VSValue.java b/trick_source/java/src/trick/common/utils/vs/VSValue.java index 59f1669f..09b4eeee 100644 --- a/trick_source/java/src/trick/common/utils/vs/VSValue.java +++ b/trick_source/java/src/trick/common/utils/vs/VSValue.java @@ -1,6 +1,37 @@ package trick.common.utils.vs; -public abstract class VSValue implements VariableServerFluent, Cloneable { +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public abstract class VSValue implements VariableServerFluent, Cloneable { + + @XmlElement + private T value; + + protected VSValue() {} + + protected VSValue(T value) { + setValue(value); + } + + public T getValue() { + return value; + } + + protected void setValue(T value) { + this.value = value; + } + + @Override + public String toVariableServer() { + return toString(); + } + + @Override + public String toString() { + return value.toString(); + } @Override public VSValue clone() { diff --git a/trick_source/java/src/trick/common/utils/vs/Variable.java b/trick_source/java/src/trick/common/utils/vs/Variable.java index 974c1cd3..fa6ce98b 100644 --- a/trick_source/java/src/trick/common/utils/vs/Variable.java +++ b/trick_source/java/src/trick/common/utils/vs/Variable.java @@ -9,7 +9,6 @@ import java.io.Serializable; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementRef; -import javax.xml.bind.annotation.XmlElementRefs; import trick.common.utils.VariableServerConnection; @@ -20,34 +19,22 @@ import trick.common.utils.VariableServerConnection; */ public class Variable implements Serializable, Cloneable { - private static final long serialVersionUID = 4529167759720494026L; - /** possible states */ public enum State {Unknown, Invalid, Valid}; /** name */ - @XmlElement(required = true) public final String name; /** value */ - @XmlElementRefs({ - @XmlElementRef(type=VSValue.class), - @XmlElementRef(type=VSBoolean.class), - @XmlElementRef(type=VSByte.class), - @XmlElementRef(type=VSDouble.class), - @XmlElementRef(type=VSFloat.class), - @XmlElementRef(type=VSInteger.class), - @XmlElementRef(type=VSLong.class), - @XmlElementRef(type=VSShort.class), - @XmlElementRef(type=VSString.class) - }) + @XmlElementRef(type=VSValue.class) public final T value; /** units */ - String units; + private String units; /** state */ - State state = State.Unknown; + @XmlElement + private State state = State.Unknown; /** * constructor @@ -80,30 +67,6 @@ public class Variable implements Serializable, C value = null; } - /** - * sets this Variable's value to value - * - * @param value the value to be set, expressed in Variable Server format - */ - public void setValue(String value) { - if (value.equals("BAD_REF")) { - state = State.Invalid; - } - else { - this.value.fromVariableServer(value); - state = State.Valid; - } - } - - /** - * sets this Variable's units to units - * - * @param units the units to be set - */ - public void setUnits(String units) { - this.units = units; - } - /** * commands the Variable Server to set the variable's value to value * @@ -145,6 +108,69 @@ public class Variable implements Serializable, C sendUnitsToVariableServer(units, variableServerConnection); } + /** + * sets this Variable's value to value + * + * @param value the value to be set, expressed in Variable Server format + */ + public void setValue(String value) { + if (value.equals("BAD_REF")) { + state = State.Invalid; + } + else { + this.value.fromVariableServer(value); + state = State.Valid; + } + } + + /** + * returns the value + * + * @return the value + */ + public T getValue() { + return value; + } + + /** + * sets this Variable's units to units + * + * @param units the units to be set + */ + public void setUnits(String units) { + this.units = units; + } + + /** + * returns the units + * + * @return the units + */ + public String getUnits() { + return units; + } + + /** + * provided for JAXB compatibility + */ + private void setState(State state) { + this.state = state; + } + + /** + * returns the state + * + * @return the state + */ + public State getState() { + return state; + } + + @Override + public String toString() { + return name; + } + /** * Equality among Variables requires only that their names * be equal as implemented by String.equals. @@ -169,43 +195,6 @@ public class Variable implements Serializable, C return name.hashCode(); } - /** - * returns the value - * - * @return the value - */ - public T getValue() { - return value; - } - - /** - * returns the state - * - * @return the state - */ - public State getState() { - return state; - } - - /** - * returns the name - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * returns the units - * - * @return the units - */ - @XmlElement(required = true) - public String getUnits() { - return units; - } - @Override @SuppressWarnings("unchecked") public Variable clone() { @@ -220,9 +209,4 @@ public class Variable implements Serializable, C } } - @Override - public String toString() { - return name; - } - } diff --git a/trick_source/java/src/trick/common/utils/vs/VariableTracker.java b/trick_source/java/src/trick/common/utils/vs/VariableTracker.java index bc379b32..19c7c572 100644 --- a/trick_source/java/src/trick/common/utils/vs/VariableTracker.java +++ b/trick_source/java/src/trick/common/utils/vs/VariableTracker.java @@ -46,7 +46,7 @@ public class VariableTracker extends SwingWorker { */ public void add(Variable variable) throws IOException { if (variables.add(variable)) { - variableServerConnection.add(variable.name, variable.units); + variableServerConnection.add(variable.name, variable.getUnits()); } } @@ -56,7 +56,7 @@ public class VariableTracker extends SwingWorker { * @param variable the variable to stop tracking */ public void remove(Variable variable) throws IOException { - variableServerConnection.remove(variable.getName()); + variableServerConnection.remove(variable.name); variables.remove(variable); } diff --git a/trick_source/java/src/trick/stripchart/StripChart.java b/trick_source/java/src/trick/stripchart/StripChart.java index d9c56ff4..cfb7f7e7 100644 --- a/trick_source/java/src/trick/stripchart/StripChart.java +++ b/trick_source/java/src/trick/stripchart/StripChart.java @@ -138,7 +138,7 @@ public class StripChart extends JXPanel { settingsPanel = new JXPanel(new GridBagLayout()) {{ final ValueAxis domainAxis = plot.getDomainAxis(); - domainAxis.setLabel(domainVariable.getName()); + domainAxis.setLabel(domainVariable.name); final JRadioButton allRadioButton = new JRadioButton(new AbstractAction() { { diff --git a/trick_source/java/src/trick/stripchart/StripChartManager.java b/trick_source/java/src/trick/stripchart/StripChartManager.java index c86b77a2..6c47cda0 100644 --- a/trick_source/java/src/trick/stripchart/StripChartManager.java +++ b/trick_source/java/src/trick/stripchart/StripChartManager.java @@ -70,7 +70,7 @@ public class StripChartManager { Double.parseDouble(variable.getValue().toVariableServer()); } catch (NumberFormatException numberFormatException) { - throw new IllegalArgumentException(variable.getName() + " cannot be parsed as a double.\n" + + throw new IllegalArgumentException(variable.name + " cannot be parsed as a double.\n" + numberFormatException, numberFormatException); } diff --git a/trick_source/java/src/trick/tv/TVApplication.java b/trick_source/java/src/trick/tv/TVApplication.java index 1b451b19..c8f4e2d2 100644 --- a/trick_source/java/src/trick/tv/TVApplication.java +++ b/trick_source/java/src/trick/tv/TVApplication.java @@ -121,42 +121,11 @@ import trick.tv.VariableTable.Position; */ public class TVApplication extends RunTimeTrickApplication implements VariableListener { - @Deprecated - private enum Mode {ALL, STRIP, FIXED}; - - @Deprecated - private enum VariableType {FIXED, FLOATING, CHARACTER, STRING, BOOLEAN, ENUMERATION, UNKNOWN}; - - @Deprecated - private enum Format { - - DECIMAL("Decimal"), - OCTAL("Octal"), - HEXIDECIMAL("Hexidecimal"), - BOOLEAN("Boolean"), - ENUMERATION("Enumeration"), - STRING("String"), - CHARACTER("Character"), - UNKNOWN("Unknown"); - - private String name; - - private Format(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - - } - /** simulation time tic value */ double timeTicValue; /** simulation time tic count */ - VSLong timeTicCount = new VSLong(); + VSLong timeTicCount = new VSLong(0); /** simulation time */ protected Variable simulationTime = @@ -1262,7 +1231,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi @SuppressWarnings("unchecked") // I know what I'm doing. protected void addVariable(Variable variable, boolean applyDefaults) { // TV relies on time_tics being the first tracked variable, so don't let users manipulate it. - if (!variable.getName().equals("trick_sys.sched.time_tics")) { + if (!variable.name.equals("trick_sys.sched.time_tics")) { try { if (applyDefaults || variable.getValue().getFormat() == null) { variable.getValue().setFormat(Enum.valueOf(variable.getValue().getFormatClass(), @@ -1769,83 +1738,12 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi */ protected void openFile(File file, boolean display, boolean set) { try { - openFileAsBinary(file, display, set); + restoreState((TVBean)unmarshaller.unmarshal(new StreamSource(file), TVBean.class).getValue(), display, set); } - catch (Exception binaryException) { - try { - restoreState((TVBean)unmarshaller.unmarshal(new StreamSource(file), TVBean.class).getValue(), display, set); - } - catch (Exception exception) { - JOptionPane.showMessageDialog(getMainFrame(), exception, - "Failed to Restore State", JOptionPane.ERROR_MESSAGE); - exception.printStackTrace(System.err); - } - } - } - - /** - * gets the value of the first descendent of the specified element with the specified tag name - * - * @return the value of the first descendent of the specified element with the specified tag name, or null - */ - @Deprecated - String getElementValue(Element element, String tag) { - NodeList nodeList = element.getElementsByTagName(tag); - if (nodeList.getLength() > 0) { - Node node = nodeList.item(0).getFirstChild(); - if (node != null) { - return node.getNodeValue(); - } - } - return null; - } - - /** - * attempts to open the file a binary serialization, displaying and setting the variable as specified - * - * @param file the file to be opened - * @param display whether or not to replace the current variable table contents with those in the file - * @param set whether or not to send the values in the file to the Variable Server - */ - @SuppressWarnings("unchecked") // readObject returns an Object which must be cast - @Deprecated - protected void openFileAsBinary(File file, boolean display, boolean set) - throws IOException, ClassNotFoundException { - ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(file)); - - ArrayList> variables = - (ArrayList>)objectInputStream.readObject(); - - if (display) { - removeAllStripCharts(); - removeAllVariables(); - for (Variable variable : variables) { - addVariable(variable); - } - setCyclePeriod(((Double)objectInputStream.readObject()).doubleValue()); - } - - if (set && getConnectionState()) { - try { - for (Variable variable : variables) { - variable.sendValueToVariableServer(variableServerConnection); - } - } - catch (IOException ioException) { - disconnect(ioException); - } - } - - if (display) { - try { - for (StripChart stripChart : stripChartManager.loadStripCharts(objectInputStream)) { - launchStripChart(stripChart, (Rectangle)objectInputStream.readObject()); - } - } - catch (IllegalArgumentException illegalArgumentException) { - JOptionPane.showMessageDialog(getMainFrame(), illegalArgumentException, - "Strip Chart Error", JOptionPane.ERROR_MESSAGE); - } + catch (Exception exception) { + JOptionPane.showMessageDialog(getMainFrame(), exception, + "Failed to Restore State", JOptionPane.ERROR_MESSAGE); + exception.printStackTrace(System.err); } } @@ -1883,7 +1781,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi Variable domainVariable = simulationTime; for (Variable variable : tvBean.variables) { - if (variable.getName().equals(stripChartBean.domainVariable)) { + if (variable.name.equals(stripChartBean.domainVariable)) { domainVariable = variable; break; } @@ -1892,7 +1790,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi ArrayList plottedVariables = new ArrayList(); for (String plottedVariable : stripChartBean.plottedVariables) { for (Variable variable : tvBean.variables) { - if (variable.getName().equals(plottedVariable)) { + if (variable.name.equals(plottedVariable)) { plottedVariables.add(variable); break; } @@ -2126,7 +2024,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi for (Variable variable : pendingVariables) { // If any variables are indexable, launch the dialog. - if (pattern.matcher(variable.getName()).find()) { + if (pattern.matcher(variable.name).find()) { northPanel.removeAll(); for (Variable var : pendingVariables) { northPanel.add(new VariablePanel(var)); @@ -2186,7 +2084,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi public VariablePanel(Variable variable) { super(new GridBagLayout()); this.variable = variable; - matcher = pattern.matcher(variable.getName()); + matcher = pattern.matcher(variable.name); add(new JXButton(new AbstractAction() { { putValue(NAME, "Remove"); @@ -2204,7 +2102,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi })); add(Box.createHorizontalStrut(5)); - segments = pattern.split(variable.getName()); + segments = pattern.split(variable.name); while (matcher.find()) { int arraySize = Integer.parseInt(matcher.group()); indices.add(arraySize == 0 ? new IndexTextField() : new DoubleComboBox(arraySize)); diff --git a/trick_source/java/src/trick/tv/TVBean.java b/trick_source/java/src/trick/tv/TVBean.java index fe2f62ac..16605db7 100644 --- a/trick_source/java/src/trick/tv/TVBean.java +++ b/trick_source/java/src/trick/tv/TVBean.java @@ -85,9 +85,9 @@ public class TVBean { public StripChartBean() {} public StripChartBean(StripChart stripChart) { - domainVariable = stripChart.getDomainVariable().getName(); + domainVariable = stripChart.getDomainVariable().name; for (Variable variable : stripChart.getPlottedVariables()) { - plottedVariables.add(variable.getName()); + plottedVariables.add(variable.name); } mode = stripChart.getMode(); fixedAutoRange = stripChart.getFixedAutoRange(); diff --git a/trick_source/java/src/trick/tv/TVBoolean.java b/trick_source/java/src/trick/tv/TVBoolean.java index f13415a0..381d8cbf 100644 --- a/trick_source/java/src/trick/tv/TVBoolean.java +++ b/trick_source/java/src/trick/tv/TVBoolean.java @@ -23,7 +23,7 @@ public class TVBoolean extends VSBoolean implements TrickViewFluent { } }; - public boolean unsigned = false; + public final boolean unsigned; Format format = Format.Decimal; - public TVByte() {} + public TVByte() { + this(false); + } public TVByte(boolean unsigned) { this.unsigned = unsigned; @@ -130,6 +132,7 @@ public class TVByte extends VSByte implements TrickViewFluent { public TVByte(byte value) { super(value); + unsigned = false; } public Class getFormatClass() { @@ -154,12 +157,12 @@ public class TVByte extends VSByte implements TrickViewFluent { @Override public String toVariableServer() { - return Format.Decimal.format(value, unsigned); + return Format.Decimal.format(getValue(), unsigned); } @Override public String toString() { - return format.format(value, unsigned); + return format.format(getValue(), unsigned); } } diff --git a/trick_source/java/src/trick/tv/TVDouble.java b/trick_source/java/src/trick/tv/TVDouble.java index 4067448d..0ae59655 100644 --- a/trick_source/java/src/trick/tv/TVDouble.java +++ b/trick_source/java/src/trick/tv/TVDouble.java @@ -96,7 +96,7 @@ public class TVDouble extends VSDouble implements TrickViewFluent { - - private static final long serialVersionUID = 4708597538833537404L; +public class TVEnumeration extends VSValue implements TrickViewFluent { @XmlType(name = "") public enum Format { Enumeration { public String format(String value, SieEnumeration enumeration) { - if (enumeration == null) { - return ""; - } for (String key : enumeration.pairs.keySet()) { if (enumeration.pairs.get(key).equals(value)) { return key; @@ -43,9 +38,6 @@ public class TVEnumeration extends VSValue implements TrickViewFluent getFormatClass() { @@ -128,13 +120,9 @@ public class TVEnumeration extends VSValue implements TrickViewFluent @Override public String toString() { - return format.format(value); + return format.format(getValue()); } } diff --git a/trick_source/java/src/trick/tv/TVInteger.java b/trick_source/java/src/trick/tv/TVInteger.java index df8f6e8e..534e78de 100644 --- a/trick_source/java/src/trick/tv/TVInteger.java +++ b/trick_source/java/src/trick/tv/TVInteger.java @@ -99,11 +99,13 @@ public class TVInteger extends VSInteger implements TrickViewFluent getFormatClass() { @@ -135,12 +138,12 @@ public class TVInteger extends VSInteger implements TrickViewFluent { } }; - public boolean unsigned = false; + public final boolean unsigned; Format format = Format.Decimal; - public TVLong() {} + public TVLong() { + this(false); + } public TVLong(boolean unsigned) { this.unsigned = unsigned; @@ -112,6 +114,7 @@ public class TVLong extends VSLong implements TrickViewFluent { public TVLong(long value) { super(value); + unsigned = false; } public Class getFormatClass() { @@ -136,12 +139,12 @@ public class TVLong extends VSLong implements TrickViewFluent { @Override public String toVariableServer() { - return Format.Decimal.format(value, unsigned); + return Format.Decimal.format(getValue(), unsigned); } @Override public String toString() { - return format.format(value, unsigned); + return format.format(getValue(), unsigned); } } diff --git a/trick_source/java/src/trick/tv/TVShort.java b/trick_source/java/src/trick/tv/TVShort.java index 62878836..493f337c 100644 --- a/trick_source/java/src/trick/tv/TVShort.java +++ b/trick_source/java/src/trick/tv/TVShort.java @@ -99,11 +99,13 @@ public class TVShort extends VSShort implements TrickViewFluent } }; - public boolean unsigned = false; + public final boolean unsigned; Format format = Format.Decimal; - public TVShort() {} + public TVShort() { + this(false); + } public TVShort(boolean unsigned) { this.unsigned = unsigned; @@ -111,6 +113,7 @@ public class TVShort extends VSShort implements TrickViewFluent public TVShort(short value) { super(value); + unsigned = false; } public Class getFormatClass() { @@ -135,12 +138,12 @@ public class TVShort extends VSShort implements TrickViewFluent @Override public String toVariableServer() { - return Format.Decimal.format(value, unsigned); + return Format.Decimal.format(getValue(), unsigned); } @Override public String toString() { - return format.format(value, unsigned); + return format.format(getValue(), unsigned); } } diff --git a/trick_source/java/src/trick/tv/TVString.java b/trick_source/java/src/trick/tv/TVString.java index 900f7c6c..4a4ac4b2 100644 --- a/trick_source/java/src/trick/tv/TVString.java +++ b/trick_source/java/src/trick/tv/TVString.java @@ -82,7 +82,7 @@ public class TVString extends VSString implements TrickViewFluent variable = variables.get(rowIndex); switch (columnIndex) { case 0: - return variable.getName(); + return variable.name; case 1: switch (variable.getState()) { case Invalid: diff --git a/trick_source/java/src/trick/tv/resources/tv.xsd b/trick_source/java/src/trick/tv/resources/tv.xsd index d0842b35..5830111e 100644 --- a/trick_source/java/src/trick/tv/resources/tv.xsd +++ b/trick_source/java/src/trick/tv/resources/tv.xsd @@ -1,177 +1,134 @@ + - + - - + + + + + + + - - - - - + + + + + + + - - - - - + + + + + + - - + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - + + + + + + + + + + + + + + + + + + +