use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testStringArrayParsing.
@Test
public void testStringArrayParsing() throws Exception {
final VType value = ValueFactory.newVStringArray(Arrays.asList("Flintstone, \"Al\" Fred", "Jane"), ValueFactory.alarmNone(), ValueFactory.timeNow());
final String text = FormatOptionHandler.format(value, FormatOption.DEFAULT, 0, true);
System.out.println(text);
Object parsed = FormatOptionHandler.parse(value, text, FormatOption.DEFAULT);
System.out.println(Arrays.toString((String[]) parsed));
assertThat(parsed, equalTo(new String[] { "Flintstone, \"Al\" Fred", "Jane" }));
parsed = FormatOptionHandler.parse(value, "[ \"Freddy\", \"Janet\" ] ", FormatOption.DEFAULT);
assertThat(parsed, instanceOf(String[].class));
assertThat(parsed, equalTo(new String[] { "Freddy", "Janet" }));
parsed = FormatOptionHandler.parse(value, "[ Freddy, Janet ] ", FormatOption.DEFAULT);
assertThat(parsed, equalTo(new String[] { "Freddy", "Janet" }));
parsed = FormatOptionHandler.parse(value, "Freddy, Janet", FormatOption.DEFAULT);
assertThat(parsed, equalTo(new String[] { "Freddy", "Janet" }));
parsed = FormatOptionHandler.parse(value, " [ \"Flintstone, Fred\", Janet", FormatOption.DEFAULT);
assertThat(parsed, equalTo(new String[] { "Flintstone, Fred", "Janet" }));
parsed = FormatOptionHandler.parse(value, " \"Al \\\"Ed\\\" Stone\", Jane", FormatOption.DEFAULT);
System.out.println(Arrays.toString((String[]) parsed));
assertThat(parsed, equalTo(new String[] { "Al \"Ed\" Stone", "Jane" }));
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testString.
@Test
public void testString() throws Exception {
// Actual String
VType value = ValueFactory.newVString("Test1", ValueFactory.alarmNone(), ValueFactory.timeNow());
String text = FormatOptionHandler.format(value, FormatOption.DEFAULT, -1, true);
System.out.println(text);
assertThat(text, equalTo("Test1"));
text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
System.out.println(text);
assertThat(text, equalTo("Test1"));
text = FormatOptionHandler.format(value, FormatOption.EXPONENTIAL, -1, true);
System.out.println(text);
assertThat(text, equalTo("Test1"));
// Number interpreted as char
value = ValueFactory.newVDouble(65.0, display);
text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
System.out.println(text);
assertThat(text, equalTo("A V"));
// Number array interpreted as long string
// UTF-8 for 'Hello'
ListNumber data = new ArrayInt(72, 101, 108, 108, 111);
value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
System.out.println(value);
text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
System.out.println(text);
assertThat(text, equalTo("Hello"));
data = new ArrayInt(/* Dollar */
0x24, /* Euro */
0xE2, 0x82, 0xAC);
value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
System.out.println(value);
text = FormatOptionHandler.format(value, FormatOption.STRING, -1, true);
System.out.println(text);
// For this to work, Eclipse IDE Preferences -> General -> Workspace -> Text file encoding
// must be set to UTF-8, which is the default on Linux but not necessarily Windows
assertThat(text, equalTo("$€"));
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class FormatOptionHandlerTest method testDecimal.
@Test
public void testDecimal() throws Exception {
VType number = ValueFactory.newVDouble(3.16, display);
assertThat(fmt.format(3.16), equalTo("3.16"));
String text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, true);
System.out.println(text);
assertThat(text, equalTo("3.160 V"));
text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, false);
System.out.println(text);
assertThat(text, equalTo("3.160"));
text = FormatOptionHandler.format(number, FormatOption.DECIMAL, 4, true);
System.out.println(text);
assertThat(text, equalTo("3.1600 V"));
text = FormatOptionHandler.format(number, FormatOption.DECIMAL, 1, true);
System.out.println(text);
assertThat(text, equalTo("3.2 V"));
// For running in debugger: Repeated use of precision 4 should use cached format
text = FormatOptionHandler.format(number, FormatOption.DECIMAL, 4, true);
System.out.println(text);
assertThat(text, equalTo("3.1600 V"));
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class WaveformView method showSelectedSample.
/**
* Show the current sample of the current model item.
*/
private void showSelectedSample() {
// Get selected sample (= one waveform)
final PlotSamples samples = model_item.getSamples();
final int idx = sample_index.getSelection();
final PlotSample sample;
samples.getLock().lock();
try {
sample_index.setMaximum(samples.size());
sample = samples.get(idx);
} finally {
samples.getLock().unlock();
}
// Setting the value can be delayed while the plot is being updated
final VType value = sample.getVType();
Activator.getThreadPool().execute(() -> waveform.setValue(value));
if (value == null)
clearInfo();
else {
updateAnnotation(sample.getPosition(), sample.getValue());
int size = value instanceof VNumberArray ? ((VNumberArray) value).getData().size() : 1;
plot.getXAxis().setValueRange(0.0, (double) size);
timestamp.setText(TimestampHelper.format(VTypeHelper.getTimestamp(value)));
status.setText(NLS.bind(Messages.SeverityStatusFmt, VTypeHelper.getSeverity(value).toString(), VTypeHelper.getMessage(value)));
}
plot.requestUpdate();
}
use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.
the class WidgetInfoDialog method createPVs.
private Tab createPVs(final Collection<NameStateValue> pvs) {
// Use text field to allow users to copy the name, value to clipboard
final TableColumn<NameStateValue, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
name.setCellFactory(TextFieldTableCell.forTableColumn());
name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().name));
final TableColumn<NameStateValue, String> state = new TableColumn<>(Messages.WidgetInfoDialog_State);
state.setCellFactory(TextFieldTableCell.forTableColumn());
state.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().state));
final TableColumn<NameStateValue, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
value.setCellFactory(TextFieldTableCell.forTableColumn());
value.setCellValueFactory(param -> {
String text;
final VType vtype = param.getValue().value;
if (vtype == null)
text = Messages.WidgetInfoDialog_Disconnected;
else {
// so only show the basic type info
if (vtype instanceof VNumberArray)
text = vtype.toString();
else
text = VTypeUtil.getValueString(vtype, true);
if (vtype instanceof Alarm) {
final Alarm alarm = (Alarm) vtype;
if (alarm.getAlarmSeverity() != AlarmSeverity.NONE)
text = text + " [" + alarm.getAlarmSeverity().toString() + ", " + alarm.getAlarmName() + "]";
}
}
return new ReadOnlyStringWrapper(text);
});
final ObservableList<NameStateValue> pv_data = FXCollections.observableArrayList(pvs);
pv_data.sort((a, b) -> a.name.compareTo(b.name));
final TableView<NameStateValue> table = new TableView<>(pv_data);
table.getColumns().add(name);
table.getColumns().add(state);
table.getColumns().add(value);
table.setEditable(true);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
return new Tab(Messages.WidgetInfoDialog_TabPVs, table);
}
Aggregations