Search in sources :

Example 1 with PlotListener

use of org.csstudio.trends.databrowser3.ui.PlotListener in project org.csstudio.display.builder by kasemir.

the class PlotDemo method createGUI.

// final private PlotListener listener = new PlotListener()
// {
// @Override
// public void scrollRequested(final boolean enable_scrolling)
// {
// System.out.println("Scroll enabled: " + enable_scrolling);
// scroll = enable_scrolling;
// }
// 
// @Override
// public void timeConfigRequested()
// {
// System.out.println("Time Config requested");
// }
// 
// @Override
// public void timeAxisChanged(final long start_ms, final long end_ms)
// {
// start_time = TimestampHelper.fromMillisecs(start_ms);
// end_time = TimestampHelper.fromMillisecs(end_ms);
// System.out.println("Time axis: " + start_time + " ... " + end_time);
// }
// 
// @Override
// public void valueAxisChanged(final int index, final double lower, final double upper)
// {
// System.out.println("Value axis " + index + ": " + lower + " ... " + upper);
// }
// 
// @Override
// public void droppedName(final String name)
// {
// System.out.println("Name dropped: " + name);
// }
// 
// @Override
// public void droppedPVName(final ProcessVariable name, final ArchiveDataSource archive)
// {
// System.out.println("PV Name dropped: " + name);
// }
// 
// @Override
// public void droppedFilename(final String file_name)
// {
// System.out.println("File Name dropped: " + file_name);
// }
// 
// @Override
// public void xyGraphConfigChanged(XYGraph newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void removeAnnotationChanged(Annotation oldValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void addAnnotationChanged(Annotation newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void backgroundColorChanged(Color newValue) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void timeAxisForegroundColorChanged(Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisForegroundColorChanged(int index, Color oldColor,
// Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisTitleChanged(int index, String oldTitle,
// String newTitle) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisAutoScaleChanged(int index, boolean oldAutoScale,
// boolean newAutoScale) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceNameChanged(int index, String oldName, String newName) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceYAxisChanged(int index, AxisConfig oldConfig,
// AxisConfig config) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceTypeChanged(int index, TraceType old,
// TraceType newTraceType) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void traceColorChanged(int index, Color old, Color newColor) {
// // TODO Auto-generated method stub
// 
// }
// 
// @Override
// public void valueAxisLogScaleChanged(int index, boolean old,
// boolean logScale) {
// // TODO Auto-generated method stub
// 
// }
// };
private void createGUI(final Composite parent) {
    final GridLayout layout = new GridLayout(1, false);
    parent.setLayout(layout);
    ModelBasedPlot plot;
    try {
        plot = new ModelBasedPlot(true);
    } catch (Exception e1) {
        e1.printStackTrace();
        return;
    }
    final FXCanvas canvas = new FXCanvas(parent, SWT.NONE);
    canvas.setScene(new Scene(plot.getPlot()));
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, layout.numColumns, 1));
    // [Done] button to end demo
    final Button ok = new Button(parent, SWT.PUSH);
    ok.setText("Done");
    ok.setLayoutData(new GridData(SWT.RIGHT, 0, true, false));
    ok.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            run = false;
        }
    });
    // plot.addListener(listener);
    // Create demo samples
    final List<PlotSample> values = new ArrayList<PlotSample>();
    for (int i = 1; i < 10; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    values.add(new PlotSample("Test", TestHelper.makeError(15, "Disconnected")));
    // Single value. Line should continue until the following 'disconnect'.
    values.add(new PlotSample("Test", TestHelper.makeValue(17)));
    values.add(new PlotSample("Test", TestHelper.makeError(18, "Disconnected")));
    for (int i = 20; i < 30; ++i) values.add(new PlotSample("Test", TestHelper.makeValue(i)));
    final PlotSampleArray samples = new PlotSampleArray();
    samples.set(values);
    // Add item with demo samples
    final ModelItem item = new ModelItem("Demo") {

        @Override
        public PlotSamples getSamples() {
            return samples;
        }

        @Override
        public void write(final PrintWriter writer) {
        // NOP
        }
    };
    // TODO: Fix or remove
    // item.setColor(new RGB(0, 0, 255));
    plot.addTrace(item);
// start_time = VTypeHelper.getTimestamp(samples.getSample(0).getValue());
// end_time = VTypeHelper.getTimestamp(samples.getSample(samples.getSize()-1).getValue());
// plot.setTimeRange(start_time, end_time);
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) ModelItem(org.csstudio.trends.databrowser3.model.ModelItem) Scene(javafx.scene.Scene) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PlotSample(org.csstudio.trends.databrowser3.model.PlotSample) PlotSampleArray(org.csstudio.trends.databrowser3.model.PlotSampleArray) FXCanvas(javafx.embed.swt.FXCanvas) PrintWriter(java.io.PrintWriter)

Example 2 with PlotListener

use of org.csstudio.trends.databrowser3.ui.PlotListener in project org.csstudio.display.builder by kasemir.

the class DataBrowserEditor method hookDragAndDrop.

/**
 * Allow 'drop' of PV name, archive, ..
 *  @param canvas FXCanvas
 */
private void hookDragAndDrop(final Control canvas) {
    // CS-Studio uses the ControlSystemDragSource
    // and ControlSystemDropTarget to transfer its own
    // data types, using the SWT drag-and-drop API
    // plus some class loader hacking to de-serialize
    // types from other plugins.
    // 
    // The JavaFX plot is inside an FXCanvas.
    // The FXCanvas establishes an SWT DropTarget
    // to forward drops from SWT to the hosted JavaFX scene.
    // 
    // Issues:
    // The FXCanvas only reliably forwards standard transfers
    // (string, ..), and not custom data types.
    // SWT generally doesn't allow multiple drop targets.
    // 
    // Option 1)
    // Use the JavaFX drop API on the plot, and parse the received strings.
    // -> Don't want to parse possibly arbitrary strings.
    // 
    // Option 2)
    // Change the ControlSystemDropTarget to use
    // getSite().getService(IDragAndDropService.class).addMergedDropTarget(..)
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162192
    // This would allow 'adding' another DropTarget,
    // but requires changes to the ControlSystemDropTarget,
    // would only work in RCP, not plain SWT.
    // Who then receives the drop events would depend on the order
    // in which drop targets are added and which transfers they use.
    // 
    // Option 3)
    // Hack around the SWT limitation by fetching
    // the FXCanva's DropTarget via
    // control.getData(DND.DROP_TARGET_KEY);
    // and disposing it.
    // Checking the source code for the SWT DropTarget
    // on Windows, Mac and Linux for SWT 3.104,
    // this detaches the DropTarget and allows us
    // to add our own.
    final DropTarget old = (DropTarget) canvas.getData(DND.DROP_TARGET_KEY);
    if (old != null)
        old.dispose();
    if (canvas.getData(DND.DROP_TARGET_KEY) != null)
        throw new IllegalStateException("Cannot remove FXCanvas's DropTarget");
    // Allow dropped arrays
    new ControlSystemDropTarget(canvas, ChannelInfo[].class, ProcessVariable[].class, ArchiveDataSource[].class, File.class, String.class) {

        @Override
        public void handleDrop(final Object item) {
            final PlotListener lst = plot.getListener();
            if (lst == null)
                return;
            if (item instanceof ChannelInfo[]) {
                final ChannelInfo[] channels = (ChannelInfo[]) item;
                final int N = channels.length;
                final ProcessVariable[] pvs = new ProcessVariable[N];
                final ArchiveDataSource[] archives = new ArchiveDataSource[N];
                for (int i = 0; i < N; ++i) {
                    pvs[i] = channels[i].getProcessVariable();
                    archives[i] = channels[i].getArchiveDataSource();
                }
                lst.droppedPVNames(pvs, archives);
            } else if (item instanceof ProcessVariable[]) {
                final ProcessVariable[] pvs = (ProcessVariable[]) item;
                lst.droppedPVNames(pvs, null);
            } else if (item instanceof ArchiveDataSource[]) {
                final ArchiveDataSource[] archives = (ArchiveDataSource[]) item;
                lst.droppedPVNames(null, archives);
            } else if (item instanceof String) {
                final List<String> pvs = new ArrayList<>();
                // Allow passing in many names, assuming that white space separates them
                // $NON-NLS-1$
                final String[] names = ((String) item).split("[\\r\\n\\t ]+");
                for (String one_name : names) {
                    // Might also have received "[pv1, pv2, pv2]", turn that into "pv1", "pv2", "pv3"
                    String suggestion = one_name;
                    if (suggestion.startsWith("["))
                        suggestion = suggestion.substring(1);
                    if (suggestion.endsWith("]") && !suggestion.contains("["))
                        suggestion = suggestion.substring(0, suggestion.length() - 1);
                    if (suggestion.endsWith(","))
                        suggestion = suggestion.substring(0, suggestion.length() - 1);
                    pvs.add(suggestion);
                }
                if (pvs.size() > 0)
                    lst.droppedNames(pvs.toArray(new String[pvs.size()]));
            } else if (item instanceof String[]) {
                // File names arrive as String[]...
                final String[] files = (String[]) item;
                try {
                    for (String filename : files) lst.droppedFilename(filename);
                } catch (Exception ex) {
                    ExceptionDetailsErrorDialog.openError(canvas.getShell(), Messages.Error, ex);
                }
            }
        }
    };
}
Also used : PlotListener(org.csstudio.trends.databrowser3.ui.PlotListener) ProcessVariable(org.csstudio.csdata.ProcessVariable) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) ChannelInfo(org.csstudio.trends.databrowser3.model.ChannelInfo) ControlSystemDropTarget(org.csstudio.ui.util.dnd.ControlSystemDropTarget) PartInitException(org.eclipse.ui.PartInitException) List(java.util.List) ArrayList(java.util.ArrayList) ControlSystemDropTarget(org.csstudio.ui.util.dnd.ControlSystemDropTarget) DropTarget(org.eclipse.swt.dnd.DropTarget)

Aggregations

ArrayList (java.util.ArrayList)2 PrintWriter (java.io.PrintWriter)1 List (java.util.List)1 FXCanvas (javafx.embed.swt.FXCanvas)1 Scene (javafx.scene.Scene)1 ProcessVariable (org.csstudio.csdata.ProcessVariable)1 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)1 ChannelInfo (org.csstudio.trends.databrowser3.model.ChannelInfo)1 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)1 PlotSample (org.csstudio.trends.databrowser3.model.PlotSample)1 PlotSampleArray (org.csstudio.trends.databrowser3.model.PlotSampleArray)1 PlotListener (org.csstudio.trends.databrowser3.ui.PlotListener)1 ControlSystemDropTarget (org.csstudio.ui.util.dnd.ControlSystemDropTarget)1 DropTarget (org.eclipse.swt.dnd.DropTarget)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 PartInitException (org.eclipse.ui.PartInitException)1