Commit cb01e7db authored by Cristina Cocho's avatar Cristina Cocho
Browse files

Solved problem related to properties with zero value decimals (ie. 2.0 vs 2)

parent cb8ebadd
......@@ -30,9 +30,9 @@ public class Float32Property extends FloatProperty {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.format(new Float(AtomicCommandBoxAccessorProxy.getInstance(serverId).getFloat32Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Float(AtomicCommandBoxAccessorProxy.getInstance(serverId).getFloat32Value(containerId, id)).toString());
} else {
return this.propertyFormat.format(new Float(DataAccessor.getInstance(serverId).getFloat32Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Float(DataAccessor.getInstance(serverId).getFloat32Value(containerId, id)).toString());
}
}
......
......@@ -30,9 +30,9 @@ public class Float64Property extends FloatProperty {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.format(new Double(AtomicCommandBoxAccessorProxy.getInstance(serverId).getFloat64Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Double(AtomicCommandBoxAccessorProxy.getInstance(serverId).getFloat64Value(containerId, id)).toString());
} else {
return this.propertyFormat.format(new Double(DataAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Double(DataAccessor.getInstance(serverId).getFloat64Value(containerId, id)).toString());
}
}
......
......@@ -30,9 +30,9 @@ public class Int16Property extends IntegerProperty {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.format(new Short(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt16Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Short(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt16Value(containerId, id)).toString());
} else {
return this.propertyFormat.format(new Short(DataAccessor.getInstance(serverId).getInt16Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Short(DataAccessor.getInstance(serverId).getInt16Value(containerId, id)).toString());
}
}
......
......@@ -30,9 +30,9 @@ public class Int32Property extends IntegerProperty {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.format(new Integer(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt32Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Integer(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt32Value(containerId, id)).toString());
} else {
return this.propertyFormat.format(new Integer(DataAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Integer(DataAccessor.getInstance(serverId).getInt32Value(containerId, id)).toString());
}
}
......
......@@ -30,9 +30,9 @@ public class Int64Property extends IntegerProperty {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.format(new Long(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt64Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Long(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt64Value(containerId, id)).toString());
} else {
return this.propertyFormat.format(new Long(DataAccessor.getInstance(serverId).getInt64Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Long(DataAccessor.getInstance(serverId).getInt64Value(containerId, id)).toString());
}
}
......
......@@ -29,9 +29,9 @@ public class Int8Property extends IntegerProperty {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.format(new Long(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt8Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Long(AtomicCommandBoxAccessorProxy.getInstance(serverId).getInt8Value(containerId, id)).toString());
} else {
return this.propertyFormat.format(new Long(DataAccessor.getInstance(serverId).getInt8Value(containerId, id)).toString());
return this.propertyFormat.formatForDisplay(new Long(DataAccessor.getInstance(serverId).getInt8Value(containerId, id)).toString());
}
}
......
......@@ -29,9 +29,9 @@ public class StringProperty extends Property {
public String getServerValue() {
if (isCommandBox) {
return this.propertyFormat.format(AtomicCommandBoxAccessorProxy.getInstance(serverId).getStringValue(containerId, id));
return this.propertyFormat.formatForDisplay(AtomicCommandBoxAccessorProxy.getInstance(serverId).getStringValue(containerId, id));
} else {
return this.propertyFormat.format(DataAccessor.getInstance(serverId).getStringValue(containerId, id));
return this.propertyFormat.formatForDisplay(DataAccessor.getInstance(serverId).getStringValue(containerId, id));
}
}
......
......@@ -40,7 +40,7 @@ public class DecimalFormat extends PropertyFormat {
private static java.text.DecimalFormat scientificFormat = new java.text.DecimalFormat("0.000E00");
private java.text.DecimalFormat df;
private static String[] decimalFormats = new String[] {
private static String[] decimalDisplayFormats = new String[] {
"0",
"0.0",
"0.00",
......@@ -52,18 +52,6 @@ public class DecimalFormat extends PropertyFormat {
"0.00000000",
"0.000000000"};
/*
"0.#",
"0.##",
"0.###",
"0.####",
"0.#####",
"0.######",
"0.#######",
"0.########",
"0.#########"};
*/
public DecimalFormat(int numberOfDecimalPlaces, boolean isScientific) {
this.nbOfDecimalPlaces = numberOfDecimalPlaces;
......@@ -77,8 +65,18 @@ public class DecimalFormat extends PropertyFormat {
this.isScientific = isScientific;
}
public DecimalFormat() {
}
public String format(String value) {
// Remove unnecessary zeros
df = new java.text.DecimalFormat("0.###########################");
return df.format(Double.valueOf(value));
}
public String formatForDisplay(String value) {
if (nbOfDecimalPlaces == -1) {
// First format, get number of decimals from dedicated property
......@@ -120,7 +118,7 @@ public class DecimalFormat extends PropertyFormat {
// absolute value is less than MINIMUM (0.01) or more than MAXIMUM (999) values
df = scientificFormat;
} else {
df = new java.text.DecimalFormat(decimalFormats[nbOfDecimalPlaces]);
df = new java.text.DecimalFormat(decimalDisplayFormats[nbOfDecimalPlaces]);
}
......
......@@ -22,7 +22,7 @@ import java.math.BigInteger;
public class HexadecimalFormat extends PropertyFormat {
public String format(String value) {
public String formatForDisplay(String value) {
return Integer.toHexString(new Integer(value).intValue());
}
......
......@@ -20,7 +20,7 @@ package fr.ill.ics.core.property.format;
public class NoFormat extends PropertyFormat {
public String format(String value) {
public String formatForDisplay(String value) {
return value;
}
......
......@@ -27,7 +27,7 @@ public abstract class PropertyFormat {
protected static final Logger LOGGER = Logger.getLogger(PropertyFormat.class.getName());
public abstract String format(String value);
public abstract String formatForDisplay(String value);
public abstract String unformat(String value);
......
......@@ -46,7 +46,7 @@ public class UnitFormat extends PropertyFormat {
}
public String format(String value) {
public String formatForDisplay(String value) {
if (formattedUnits == null) {
init();
}
......
......@@ -46,7 +46,7 @@ public class UndoableState extends UndoState {
// forcing to add last value
undoableValues.addLast(property.getServerValue());
}
return property.getPropertyFormat().format((String)undoableValues.getLast());
return property.getPropertyFormat().formatForDisplay((String)undoableValues.getLast());
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment