Search in sources :

Example 1 with ChangeAxisRanges

use of org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges in project org.csstudio.display.builder by kasemir.

the class Plot method enableAutoScale.

/**
 * Enable autoscale
 *
 *  <p>.. for the value axis currently under the cursor,
 *  or all axes.
 */
public void enableAutoScale() {
    final Point2D current = mouse_current.orElse(null);
    if (current == null)
        return;
    // Which axes to autoscale?
    final List<YAxisImpl<XTYPE>> axes = new ArrayList<>();
    final List<AxisRange<Double>> ranges = new ArrayList<>();
    final List<Boolean> original_auto = new ArrayList<>();
    final List<Boolean> new_auto = new ArrayList<>();
    // Autoscale all if mouse in general plot region
    final boolean all = plot_area.getBounds().contains(current.getX(), current.getY());
    for (YAxisImpl<XTYPE> axis : y_axes) if (all || axis.getBounds().contains(current.getX(), current.getY())) {
        // Autoscale this axis
        if (!axis.isAutoscale()) {
            axes.add(axis);
            ranges.add(axis.getValueRange());
            original_auto.add(false);
            new_auto.add(true);
        }
        // Only this axis?
        if (!all)
            break;
    }
    if (!axes.isEmpty())
        undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In, null, null, null, false, false, axes, ranges, ranges, original_auto, new_auto));
}
Also used : ChangeAxisRanges(org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges) Point2D(javafx.geometry.Point2D) AxisRange(org.csstudio.javafx.rtplot.AxisRange) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with ChangeAxisRanges

use of org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges in project org.csstudio.display.builder by kasemir.

the class Plot method mouseUp.

/**
 * setOnMouseReleased
 */
private void mouseUp(final MouseEvent e) {
    deselectPlotMarker();
    deselectMouseAnnotation();
    final Point2D start = mouse_start.orElse(null);
    final Point2D current = mouse_current.orElse(null);
    if (start == null || current == null)
        return;
    if (mouse_mode == MouseMode.PAN_X) {
        mouseMove(e);
        undo.add(new ChangeAxisRanges<XTYPE>(this, Messages.Pan_X, x_axis, mouse_start_x_range, x_axis.getValueRange(), false, false));
        fireXAxisChange();
        mouse_mode = MouseMode.PAN;
    } else if (mouse_mode == MouseMode.PAN_Y) {
        mouseMove(e);
        final YAxisImpl<XTYPE> y_axis = y_axes.get(mouse_y_axis);
        undo.add(new ChangeAxisRanges<XTYPE>(this, Messages.Pan_Y, Arrays.asList(y_axis), mouse_start_y_ranges, Arrays.asList(y_axis.getValueRange()), pre_pan_auto_scales));
        if (y_axis.setAutoscale(false))
            fireAutoScaleChange(y_axis);
        fireYAxisChange(y_axis);
        mouse_mode = MouseMode.PAN;
    } else if (mouse_mode == MouseMode.PAN_PLOT) {
        mouseMove(e);
        final List<AxisRange<Double>> current_y_ranges = new ArrayList<>();
        for (YAxisImpl<XTYPE> axis : y_axes) current_y_ranges.add(axis.getValueRange());
        undo.add(new ChangeAxisRanges<XTYPE>(this, Messages.Pan, x_axis, mouse_start_x_range, x_axis.getValueRange(), false, false, y_axes, mouse_start_y_ranges, current_y_ranges, pre_pan_auto_scales));
        fireXAxisChange();
        for (YAxisImpl<XTYPE> axis : y_axes) {
            if (axis.setAutoscale(false))
                fireAutoScaleChange(axis);
            fireYAxisChange(axis);
        }
        mouse_mode = MouseMode.PAN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_X) {
        // X axis increases going _right_ just like mouse 'x' coordinate
        if (Math.abs(start.getX() - current.getX()) > ZOOM_PIXEL_THRESHOLD) {
            final int low = (int) Math.min(start.getX(), current.getX());
            final int high = (int) Math.max(start.getX(), current.getX());
            final AxisRange<XTYPE> original_x_range = x_axis.getValueRange();
            final AxisRange<XTYPE> new_x_range = new AxisRange<>(x_axis.getValue(low), x_axis.getValue(high));
            undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In_X, x_axis, original_x_range, new_x_range, x_axis.isAutoscale(), false));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_Y) {
        // Mouse 'y' increases going _down_ the screen
        if (Math.abs(start.getY() - current.getY()) > ZOOM_PIXEL_THRESHOLD) {
            final int high = (int) Math.min(start.getY(), current.getY());
            final int low = (int) Math.max(start.getY(), current.getY());
            final YAxisImpl<XTYPE> axis = y_axes.get(mouse_y_axis);
            undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In_Y, Arrays.asList(axis), Arrays.asList(axis.getValueRange()), Arrays.asList(new AxisRange<Double>(axis.getValue(low), axis.getValue(high))), Arrays.asList(axis.isAutoscale())));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    } else if (mouse_mode == MouseMode.ZOOM_IN_PLOT) {
        if (Math.abs(start.getX() - current.getX()) > ZOOM_PIXEL_THRESHOLD || Math.abs(start.getY() - current.getY()) > ZOOM_PIXEL_THRESHOLD) {
            // X axis increases going _right_ just like mouse 'x' coordinate
            int low = (int) Math.min(start.getX(), current.getX());
            int high = (int) Math.max(start.getX(), current.getX());
            final AxisRange<XTYPE> original_x_range = x_axis.getValueRange();
            final AxisRange<XTYPE> new_x_range = new AxisRange<>(x_axis.getValue(low), x_axis.getValue(high));
            // Mouse 'y' increases going _down_ the screen
            final List<AxisRange<Double>> original_y_ranges = new ArrayList<>();
            final List<AxisRange<Double>> new_y_ranges = new ArrayList<>();
            final List<Boolean> original_autoscale_values = new ArrayList<>();
            high = (int) Math.min(start.getY(), current.getY());
            low = (int) Math.max(start.getY(), current.getY());
            for (YAxisImpl<XTYPE> axis : y_axes) {
                original_y_ranges.add(axis.getValueRange());
                new_y_ranges.add(new AxisRange<Double>(axis.getValue(low), axis.getValue(high)));
                original_autoscale_values.add(axis.isAutoscale());
            }
            undo.execute(new ChangeAxisRanges<XTYPE>(this, Messages.Zoom_In, x_axis, original_x_range, new_x_range, x_axis.isAutoscale(), false, y_axes, original_y_ranges, new_y_ranges, original_autoscale_values));
        }
        mouse_mode = MouseMode.ZOOM_IN;
    }
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ChangeAxisRanges(org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges) Point2D(javafx.geometry.Point2D) AxisRange(org.csstudio.javafx.rtplot.AxisRange) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Point2D (javafx.geometry.Point2D)2 AxisRange (org.csstudio.javafx.rtplot.AxisRange)2 ChangeAxisRanges (org.csstudio.javafx.rtplot.internal.undo.ChangeAxisRanges)2 List (java.util.List)1