use of org.csstudio.javafx.rtplot.PointType in project org.csstudio.display.builder by kasemir.
the class TraceTableHandler method createColumns.
/**
* Create table columns: Auto-sizable, with label provider and editor
* @param table_layout
* @param operations_manager
* @param table_viewer
*/
public void createColumns(final TableColumnLayout table_layout, final UndoableActionManager operations_manager, final TableViewer table_viewer) {
color_registry = new LocalResourceManager(JFaceResources.getResources(), table_viewer.getTable());
final Shell shell = table_viewer.getTable().getShell();
// Visible Column ----------
TableViewerColumn view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceVisibility, 45, 1);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setImage(item.isVisible() ? Activator.getDefault().getImage(Activator.ICON_CHECKED) : Activator.getDefault().getImage(Activator.ICON_UNCHECKED));
}
@Override
public String getToolTipText(Object element) {
return Messages.TraceVisibilityTT;
}
});
new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {
@Override
public int compare(final ModelItem item1, final ModelItem item2) {
final int v1 = item1.isVisible() ? 1 : 0;
final int v2 = item2.isVisible() ? 1 : 0;
final int cmp = v1 - v2;
if (cmp != 0)
return cmp;
return item1.getName().compareTo(item2.getName());
}
};
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected CellEditor getCellEditor(final Object element) {
editing = true;
return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
}
@Override
protected Object getValue(final Object element) {
return ((ModelItem) element).isVisible();
}
@Override
protected void setValue(final Object element, final Object value) {
final ModelItem item = (ModelItem) element;
final boolean visible = ((Boolean) value).booleanValue();
if (!visible && prompt_for_not_visible) {
if (!MessageDialog.openQuestion(shell, Messages.HideTraceWarning, Messages.HideTraceWarningDetail))
return;
prompt_for_not_visible = false;
}
new ChangeVisibilityCommand(operations_manager, item, visible);
editing = false;
}
});
// Trace PV/Formula Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.ItemName, 70, 70);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(item.getName());
}
@Override
public String getToolTipText(Object element) {
return Messages.ItemNameTT;
}
});
new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {
@Override
public int compare(final ModelItem item1, final ModelItem item2) {
return item1.getName().compareTo(item2.getName());
}
};
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected Object getValue(final Object element) {
return ((ModelItem) element).getName();
}
@Override
protected CellEditor getCellEditor(Object element) {
editing = true;
return super.getCellEditor(element);
}
@Override
protected void setValue(final Object element, final Object value) {
final String new_name = value.toString().trim();
final ModelItem item = (ModelItem) element;
if (new_name.equals(item.getName()))
return;
new ChangeNameCommand(shell, operations_manager, item, new_name);
editing = false;
}
});
// Display Name Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceDisplayName, 70, 70);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(item.getDisplayName());
}
@Override
public String getToolTipText(Object element) {
return Messages.TraceDisplayNameTT;
}
});
new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {
@Override
public int compare(final ModelItem item1, final ModelItem item2) {
return item1.getDisplayName().compareTo(item2.getDisplayName());
}
};
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected Object getValue(final Object element) {
return ((ModelItem) element).getDisplayName();
}
@Override
protected CellEditor getCellEditor(Object element) {
editing = true;
return super.getCellEditor(element);
}
@Override
protected void setValue(final Object element, final Object value) {
final String new_name = value.toString().trim();
final ModelItem item = (ModelItem) element;
if (new_name.equals(item.getDisplayName()))
return;
new ChangeDisplayNameCommand(operations_manager, item, new_name);
editing = false;
}
});
// Color Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.Color, 40, 10);
view_col.setLabelProvider(new ColorCellLabelProvider<ModelItem>() {
@Override
protected Color getColor(ModelItem item) {
return color_registry.createColor(SWTMediaPool.getRGB(item.getPaintColor()));
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected CellEditor getCellEditor(final Object element) {
editing = true;
return new RGBCellEditor(table_viewer.getTable());
}
@Override
protected Object getValue(final Object element) {
return ((ModelItem) element).getRGBColor();
}
@Override
protected void setValue(final Object element, final Object value) {
new ChangeColorCommand(operations_manager, (ModelItem) element, SWTMediaPool.getJFX((RGB) value));
editing = false;
}
});
// Selected sample time stamp and value
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.CursorTimestamp, 150, 30);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
final Optional<PlotDataItem<Instant>> sample = item.getSelectedSample();
if (sample.isPresent())
cell.setText(TimeHelper.format(sample.get().getPosition()));
else
cell.setText(Messages.NotApplicable);
}
@Override
public String getToolTipText(Object element) {
return Messages.CursorTimestampTT;
}
});
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.CursorValue, 40, 30);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
final Optional<PlotDataItem<Instant>> sample = item.getSelectedSample();
if (sample.isPresent()) {
final PlotSample plot_sample = (PlotSample) sample.get();
String text = DefaultVTypeFormat.get().format(plot_sample.getVType());
final String units = item.getUnits();
if (units != null)
// $NON-NLS-1$
text += " " + units;
cell.setText(text);
} else
cell.setText(Messages.NotApplicable);
}
@Override
public String getToolTipText(Object element) {
return Messages.CursorValueTT;
}
});
// Scan Period Column (only applies to PVItems) ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.ScanPeriod, 70, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
if (item instanceof PVItem)
cell.setText(Double.toString(((PVItem) item).getScanPeriod()));
else
cell.setText(Messages.NotApplicable);
}
@Override
public String getToolTipText(final Object element) {
if (!(element instanceof PVItem))
return null;
return Messages.ScanPeriodTT;
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected boolean canEdit(Object element) {
return element instanceof PVItem;
}
@Override
protected CellEditor getCellEditor(Object element) {
editing = true;
return super.getCellEditor(element);
}
@Override
protected Object getValue(final Object element) {
if (element instanceof PVItem)
return Double.toString(((PVItem) element).getScanPeriod());
else
return Messages.NotApplicable;
}
@Override
protected void setValue(final Object element, final Object value) {
if (!(element instanceof PVItem))
return;
final PVItem pv = (PVItem) element;
try {
final double period = Double.parseDouble(value.toString().trim());
if (period != pv.getScanPeriod())
new ChangeSamplePeriodCommand(shell, operations_manager, pv, period);
editing = false;
} catch (NumberFormatException ex) {
// Display will revert to original value
return;
}
}
});
// Buffer size Column (only applies to PVItems) ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.LiveSampleBufferSize, 70, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
if (item instanceof PVItem)
cell.setText(Integer.toString(((PVItem) item).getLiveCapacity()));
else
cell.setText(Messages.NotApplicable);
}
@Override
public String getToolTipText(final Object element) {
if (!(element instanceof PVItem))
return null;
final PVItem pv = (PVItem) element;
return NLS.bind(Messages.LiveBufferSizeInfoFmt, pv.getLiveCapacity(), new RelativeTime(pv.getLiveCapacity()).toString());
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected boolean canEdit(Object element) {
return element instanceof PVItem;
}
@Override
protected Object getValue(final Object element) {
if (element instanceof PVItem)
return Integer.toString(((PVItem) element).getLiveCapacity());
else
return Messages.NotApplicable;
}
@Override
protected CellEditor getCellEditor(Object element) {
editing = true;
return super.getCellEditor(element);
}
@Override
protected void setValue(final Object element, final Object value) {
if (!(element instanceof PVItem))
return;
final PVItem pv = (PVItem) element;
try {
final int size = Integer.parseInt(value.toString().trim());
if (size != pv.getLiveCapacity())
new ChangeLiveCapacityCommand(shell, operations_manager, pv, size);
editing = false;
} catch (NumberFormatException ex) {
// Display will revert to original value
return;
}
}
});
// Axis Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.Axis, 60, 30);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(item.getAxis().getName());
}
@Override
public String getToolTipText(Object element) {
return Messages.AxisTT;
}
});
new TableColumnSortHelper<ModelItem>(table_viewer, view_col) {
@Override
public int compare(final ModelItem item1, final ModelItem item2) {
final int cmp = item1.getAxis().getName().compareTo(item2.getAxis().getName());
if (cmp != 0)
return cmp;
return item1.getDisplayName().compareTo(item2.getDisplayName());
}
};
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
// Thread-safe copy of model axes as this editor is invoked
final List<AxisConfig> axes = new ArrayList<>();
@Override
protected CellEditor getCellEditor(final Object element) {
editing = true;
final List<String> axis_names = new ArrayList<>();
axes.clear();
for (AxisConfig axis : model.getAxes()) {
axes.add(axis);
axis_names.add(axis.getName());
}
final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), axis_names.toArray(new String[axis_names.size()]), SWT.READ_ONLY);
combo.setValue(getValue(element));
return combo;
}
@Override
protected Object getValue(final Object element) {
return model.getAxisIndex(((ModelItem) element).getAxis());
}
@Override
protected void setValue(final Object element, final Object value) {
final int axis_index = ((Integer) value).intValue();
final AxisConfig axis = axes.get(axis_index);
final ModelItem item = (ModelItem) element;
if (axis != item.getAxis())
new ChangeAxisCommand(operations_manager, item, axis);
editing = false;
}
});
// Trace Type Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceType, 75, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(item.getTraceType().toString());
}
@Override
public String getToolTipText(Object element) {
return Messages.TraceTypeTT;
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected CellEditor getCellEditor(final Object element) {
editing = true;
final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), TraceType.getDisplayNames(), SWT.READ_ONLY);
combo.setValue(getValue(element));
return combo;
}
@Override
protected Object getValue(final Object element) {
return ((ModelItem) element).getTraceType().ordinal();
}
@Override
protected void setValue(final Object element, final Object value) {
final TraceType trace_type = TraceType.values()[(((Integer) value).intValue())];
final ModelItem item = (ModelItem) element;
if (trace_type != item.getTraceType())
new ChangeTraceTypeCommand(operations_manager, item, trace_type);
editing = false;
}
});
// Line Width Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.TraceLineWidth, 40, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(Integer.toString(item.getLineWidth()));
}
@Override
public String getToolTipText(Object element) {
return Messages.TraceLineWidthTT;
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected Object getValue(final Object element) {
return Integer.toString(((ModelItem) element).getLineWidth());
}
@Override
protected CellEditor getCellEditor(Object element) {
editing = true;
return super.getCellEditor(element);
}
@Override
protected void setValue(final Object element, final Object value) {
int width;
try {
width = Integer.parseInt(value.toString().trim());
} catch (NumberFormatException ex) {
width = 0;
}
final ModelItem item = (ModelItem) element;
if (width != item.getLineWidth())
new ChangeLineWidthCommand(operations_manager, item, width);
editing = false;
}
});
// Point Type Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.PointType, 75, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(item.getPointType().toString());
}
@Override
public String getToolTipText(Object element) {
return Messages.PointTypeTT;
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected CellEditor getCellEditor(final Object element) {
editing = true;
final ComboBoxCellEditor combo = new ComboBoxCellEditor(table_viewer.getTable(), PointType.getDisplayNames(), SWT.READ_ONLY);
combo.setValue(getValue(element));
return combo;
}
@Override
protected Object getValue(final Object element) {
return ((ModelItem) element).getPointType().ordinal();
}
@Override
protected void setValue(final Object element, final Object value) {
final PointType point_type = PointType.values()[((Integer) value).intValue()];
final ModelItem item = (ModelItem) element;
if (point_type != item.getPointType())
new ChangePointTypeCommand(operations_manager, item, point_type);
editing = false;
}
});
// Point Size Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.PointSize, 40, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(Integer.toString(item.getPointSize()));
}
@Override
public String getToolTipText(Object element) {
return Messages.PointSizeTT;
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected Object getValue(final Object element) {
return Integer.toString(((ModelItem) element).getPointSize());
}
@Override
protected CellEditor getCellEditor(Object element) {
editing = true;
return super.getCellEditor(element);
}
@Override
protected void setValue(final Object element, final Object value) {
int size;
try {
size = Integer.parseInt(value.toString().trim());
} catch (NumberFormatException ex) {
size = 0;
}
final ModelItem item = (ModelItem) element;
if (size != item.getPointSize())
new ChangePointSizeCommand(operations_manager, item, size);
editing = false;
}
});
// Request Type Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.RequestType, 75, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
if (item instanceof PVItem)
cell.setText(((PVItem) item).getRequestType().toString());
else
cell.setText(Messages.NotApplicable);
}
@Override
public String getToolTipText(Object element) {
return Messages.RequestTypeTT;
}
});
// Edit as boolean: Raw == false, Optimized == true
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected boolean canEdit(final Object element) {
return element instanceof PVItem;
}
@Override
protected CellEditor getCellEditor(final Object element) {
editing = true;
return new CheckboxCellEditor(((TableViewer) getViewer()).getTable());
}
@Override
protected Object getValue(final Object element) {
return ((PVItem) element).getRequestType() == RequestType.OPTIMIZED;
}
@Override
protected void setValue(final Object element, final Object value) {
final PVItem item = (PVItem) element;
final RequestType request_type = ((Boolean) value).booleanValue() ? RequestType.OPTIMIZED : RequestType.RAW;
if (request_type == RequestType.RAW && prompt_for_raw_data_request) {
if (!MessageDialog.openQuestion(shell, Messages.RequestTypeWarning, Messages.RequestTypeWarningDetail))
return;
prompt_for_raw_data_request = false;
}
new ChangeRequestTypeCommand(operations_manager, item, request_type);
editing = false;
}
});
// Waveform Index Column ----------
view_col = TableHelper.createColumn(table_layout, table_viewer, Messages.WaveformIndexCol, 40, 10);
view_col.setLabelProvider(new CellLabelProvider() {
@Override
public void update(final ViewerCell cell) {
final ModelItem item = (ModelItem) cell.getElement();
cell.setText(Integer.toString(item.getWaveformIndex()));
}
@Override
public String getToolTipText(Object element) {
return Messages.WaveformIndexColTT;
}
});
view_col.setEditingSupport(new EditSupportBase(table_viewer) {
@Override
protected Object getValue(final Object element) {
return Integer.toString(((ModelItem) element).getWaveformIndex());
}
@Override
protected CellEditor getCellEditor(Object element) {
editing = true;
return super.getCellEditor(element);
}
@Override
protected void setValue(final Object element, final Object value) {
int index;
try {
index = Integer.parseInt(value.toString().trim());
if (index < 0)
return;
final ModelItem item = (ModelItem) element;
if (index != item.getWaveformIndex())
new ChangeWaveformIndexCommand(operations_manager, item, index);
} catch (NumberFormatException ex) {
return;
} finally {
editing = false;
}
}
});
ColumnViewerToolTipSupport.enableFor(table_viewer);
}
use of org.csstudio.javafx.rtplot.PointType in project org.csstudio.display.builder by kasemir.
the class TracePainter method paint.
/**
* @param gc GC
* @param bounds Clipping bounds within which to paint
* @param opacity Opacity (0 .. 100 %) of 'area'
* @param x_transform Coordinate transform used by the x axis
* @param trace Trace, has reference to its value axis
*/
public final void paint(final Graphics2D gc, final Rectangle bounds, final int opacity, final ScreenTransform<XTYPE> x_transform, final YAxisImpl<XTYPE> y_axis, final Trace<XTYPE> trace) {
if (!trace.isVisible())
return;
x_min = bounds.x - OUTSIDE;
x_max = bounds.x + bounds.width + OUTSIDE;
y_min = bounds.y - OUTSIDE;
y_max = bounds.y + bounds.height + OUTSIDE;
final Color old_color = gc.getColor();
final Color old_bg = gc.getBackground();
final Stroke old_width = gc.getStroke();
final Color color = GraphicsUtils.convert(trace.getColor());
final Color tpcolor = new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity);
gc.setColor(color);
// TODO Optimize drawing
//
// Determine first sample to draw via PlotDataSearch.findSampleLessOrEqual(),
// then end drawing when reaching right end of area.
//
// Loop only once, performing drawMinMax, drawStdDev, drawValueStaircase in one loop
//
// For now, main point is that this happens in non-UI thread,
// so the slower the better to test UI responsiveness.
final PlotDataProvider<XTYPE> data = trace.getData();
try {
if (!data.getLock().tryLock(10, TimeUnit.SECONDS))
throw new TimeoutException();
} catch (Exception ex) {
logger.log(Level.WARNING, "Skip painting " + trace + ", cannot lock " + data, ex);
return;
}
try {
final TraceType type = trace.getType();
logger.log(Level.ALL, "Painting trace type " + type.toString());
switch(type) {
case NONE:
break;
case AREA:
gc.setPaint(tpcolor);
drawMinMaxArea(gc, x_transform, y_axis, data);
gc.setPaint(color);
drawStdDevLines(gc, x_transform, y_axis, data, trace.getWidth());
drawValueStaircase(gc, x_transform, y_axis, data, trace.getWidth());
break;
case AREA_DIRECT:
gc.setPaint(tpcolor);
drawMinMaxArea(gc, x_transform, y_axis, data);
gc.setPaint(color);
drawStdDevLines(gc, x_transform, y_axis, data, trace.getWidth());
drawValueLines(gc, x_transform, y_axis, data, trace.getWidth());
break;
case LINES:
drawMinMaxLines(gc, x_transform, y_axis, data, trace.getWidth());
gc.setPaint(tpcolor);
drawStdDevLines(gc, x_transform, y_axis, data, trace.getWidth());
gc.setPaint(color);
drawValueStaircase(gc, x_transform, y_axis, data, trace.getWidth());
break;
case LINES_DIRECT:
drawMinMaxLines(gc, x_transform, y_axis, data, trace.getWidth());
gc.setPaint(tpcolor);
drawStdDevLines(gc, x_transform, y_axis, data, trace.getWidth());
gc.setPaint(color);
drawValueLines(gc, x_transform, y_axis, data, trace.getWidth());
break;
case SINGLE_LINE:
drawValueStaircase(gc, x_transform, y_axis, data, trace.getWidth());
break;
case SINGLE_LINE_DIRECT:
drawValueLines(gc, x_transform, y_axis, data, trace.getWidth());
break;
case LINES_ERROR_BARS:
drawErrorBars(gc, x_transform, y_axis, data, trace.getPointSize());
drawValueLines(gc, x_transform, y_axis, data, trace.getWidth());
break;
case ERROR_BARS:
// Compare error bars to area and min/max lines
// gc.setPaint(tpcolor);
// drawMinMaxArea(gc, x_transform, y_axis, data);
// gc.setPaint(color);
// drawMinMaxLines(gc, x_transform, y_axis, data, trace.getWidth());
drawErrorBars(gc, x_transform, y_axis, data, trace.getPointSize());
break;
case BARS:
final int width = trace.getWidth();
if (width > 0)
drawBars(gc, x_transform, y_axis, data, width);
else
drawHistogram(gc, x_transform, y_axis, data);
break;
default:
drawValueStaircase(gc, x_transform, y_axis, data, trace.getWidth());
}
final PointType point_type = trace.getPointType();
if (point_type != PointType.NONE)
drawPoints(gc, x_transform, y_axis, data, point_type, trace.getPointSize());
} finally {
data.getLock().unlock();
}
gc.setStroke(old_width);
gc.setBackground(old_bg);
gc.setColor(old_color);
}
Aggregations