Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TV VariableTable max precision column option #1670

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
28 changes: 25 additions & 3 deletions trick_source/java/src/main/java/trick/tv/TVApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public class TVApplication extends RunTimeTrickApplication implements VariableLi
final String validateAddressesKey = "validateAddresses";
final String searchPanelVisibleKey = "searchPanelVisible";
final String variableTreeVisibleKey = "variableTreeVisible";
final String maxPrecisionVisibleKey = "maxPrecisionVisible";

/** new action */
protected AbstractAction newAction = new AbstractAction("New",
Expand Down Expand Up @@ -403,7 +404,7 @@ protected void initialize(final String[] args) {
setFileFilter(new FileNameExtensionFilter("Trick View Files", "tv"));
}};

// Initialze the variable tree.
// Initialize the variable tree.
variableTree = new TVVariableTree() {{
setEnabled(false);

Expand Down Expand Up @@ -1263,9 +1264,10 @@ protected void addVariable(Variable<? extends TrickViewFluent> variable, boolean
// TV relies on time_tics being the first tracked variable, so don't let users manipulate it.
if (!variable.name.equals("trick_sys.sched.time_tics")) {
try {
if (applyDefaults || variable.getValue().getFormat() == null) {
if (applyDefaults || (variable.getValue().getFormat() == null || variable.getValue().getPrecision() == null)) {
variable.getValue().setFormat(Enum.valueOf(variable.getValue().getFormatClass(),
defaultFormats.get(variable.getValue().getClass()).toString()));
defaultFormats.get(variable.getValue().getClass()).toString()));
variable.getValue().setPrecision("--"); // Default precision value
}
variableTable.add(variable, position);
if (getConnectionState()) {
Expand Down Expand Up @@ -1642,6 +1644,26 @@ public void actionPerformed(ActionEvent actionEvent) {
}
});
}});

// Max Precision Toggle
add(new JCheckBoxMenuItem("Max Precision") {{
setToolTipText("Toggle visibility of the Max Precision.");
setMnemonic(KeyEvent.VK_M);
setSelected(Boolean.parseBoolean(trickProperties.getProperty(
maxPrecisionVisibleKey, Boolean.toString(false))));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
// by default it is not selected. On selection, it shows Max Precision Column on Variable Table
if(isSelected()) {
variableTable.setMaxPrecisionVisible(true);
} else {
variableTable.setMaxPrecisionVisible(false);
}
}
});
}});


}}, 1);

return menuBar;
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVBoolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
@XmlRootElement
public class TVBoolean extends VSBoolean implements TrickViewFluent<TVBoolean.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -87,6 +89,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toString() {
return format.format(getValue());
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVByte.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@XmlRootElement
public class TVByte extends VSByte implements TrickViewFluent<TVByte.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -156,6 +158,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toVariableServer() {
return Format.Decimal.format(getValue(), unsigned);
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
@XmlRootElement
public class TVDouble extends VSDouble implements TrickViewFluent<TVDouble.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -94,6 +96,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toString() {
return format.format(getValue());
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVEnumeration.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@XmlRootElement
public class TVEnumeration extends VSValue<String> implements TrickViewFluent<TVEnumeration.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -116,6 +118,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

public SieEnumeration getEnumeration() {
return enumeration;
}
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVFloat.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
@XmlRootElement
public class TVFloat extends VSFloat implements TrickViewFluent<TVFloat.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -94,6 +96,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toString() {
return format.format(getValue());
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@XmlRootElement
public class TVInteger extends VSInteger implements TrickViewFluent<TVInteger.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -183,6 +185,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toVariableServer() {
return Format.Decimal.format(getValue(), unsigned);
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVLong.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@XmlRootElement
public class TVLong extends VSLong implements TrickViewFluent<TVLong.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -186,6 +188,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toVariableServer() {
return Format.Decimal.format(getValue(), unsigned);
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVShort.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@XmlRootElement
public class TVShort extends VSShort implements TrickViewFluent<TVShort.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -183,6 +185,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toVariableServer() {
return Format.Decimal.format(getValue(), unsigned);
Expand Down
12 changes: 12 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TVString.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
@XmlRootElement
public class TVString extends VSString implements TrickViewFluent<TVString.Format> {

private String precision;

@XmlType(name = "")
public enum Format {

Expand Down Expand Up @@ -80,6 +82,16 @@ public TableCellEditor getCellEditor() {
return tableCellEditor;
}

@Override
public void setPrecision(String precision) {
this.precision = precision;
}

@Override
public String getPrecision() {
return precision;
}

@Override
public String toString() {
return format.format(getValue());
Expand Down
14 changes: 14 additions & 0 deletions trick_source/java/src/main/java/trick/tv/TrickViewFluent.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,18 @@ public interface TrickViewFluent<T extends Enum<T>> extends VariableServerFluent
*/
public TableCellEditor getCellEditor();

/**
* sets visible(shown) precision of the <code>Variable</code>'s value
* only on TV Table, does not affect the value in simulation.
*
* @param precision the value after dot(.) to be set
*/
public void setPrecision(String precision);

/**
* returns the precision
*
* @return the precision
*/
public String getPrecision();
}
Loading