use of org.diirt.vtype.VImage in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandler method format.
/**
* Format value as string
*
* @param value Value to format
* @param option How to format the value
* @param precision Precision to use. -1 will try to fetch precision from VType
* @param show_units Include units?
* @return Formatted value
*/
public static String format(final VType value, final FormatOption option, int precision, final boolean show_units) {
precision = actualPrecision(value, precision);
if (value == null)
return "<null>";
if (value instanceof VNumber) {
final VNumber number = (VNumber) value;
final String text = formatNumber(number.getValue(), number, option, precision);
if (show_units && !number.getUnits().isEmpty())
return text + " " + number.getUnits();
return text;
} else if (value instanceof VString)
return ((VString) value).getValue();
else if (value instanceof VEnum)
return formatEnum((VEnum) value, option);
else if (value instanceof VNumberArray) {
final VNumberArray array = (VNumberArray) value;
if (option == FormatOption.STRING)
return getLongString(array);
final ListNumber data = array.getData();
if (data.size() <= 0)
return "[]";
final StringBuilder buf = new StringBuilder("[");
buf.append(formatNumber(data.getDouble(0), array, option, precision));
for (int i = 1; i < data.size(); ++i) {
buf.append(", ");
buf.append(formatNumber(data.getDouble(i), array, option, precision));
}
buf.append("]");
if (show_units && !array.getUnits().isEmpty())
buf.append(" ").append(array.getUnits());
return buf.toString();
} else if (value instanceof VEnumArray) {
final List<String> labels = ((VEnumArray) value).getLabels();
final StringBuilder buf = new StringBuilder("[");
for (int i = 0; i < labels.size(); ++i) {
if (i > 0)
buf.append(", ");
buf.append(labels.get(i));
}
buf.append("]");
return buf.toString();
} else if (value instanceof VStringArray)
return StringList.join(((VStringArray) value).getData());
else if (value instanceof VImage) {
final VImage image = (VImage) value;
return "VImage(" + image.getWidth() + " x " + image.getHeight() + ")";
} else if (value instanceof VTable)
return formatTable((VTable) value);
return "<" + value.getClass().getName() + ">";
}
Aggregations