Example usage for org.jfree.data Range Range

List of usage examples for org.jfree.data Range Range

Introduction

In this page you can find the example usage for org.jfree.data Range Range.

Prototype

public Range(double lower, double upper) 

Source Link

Document

Creates a new range.

Usage

From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java

public void mouseReleased(MouseEvent e) {
    if (MouseUtils.isPopupTrigger(e)) {
        // clear all
        if (zoom_rectangle != null) {
            Graphics2D g2 = (Graphics2D) getGraphics();
            g2.setXORMode(java.awt.Color.gray);
            g2.draw(zoom_rectangle);/* www.  j av a  2  s  . co m*/
            g2.dispose();
        }
        mouse_start_point = null;
        zoom_rectangle = null;

        // open popup
        current_peak = findPeakAt(e.getPoint());
        enforceSelection(current_peak);
        createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY());
    } else {
        if (zoom_rectangle != null && mouse_start_point != null) {
            if (Math.abs(e.getX() - mouse_start_point.getX()) > 10) {
                //if( e.getX() < mouse_start_point.getX() ) {
                // unzoom all
                //    onZoomNone();
                //}
                //else {        

                // zoom area           
                double start_x = Math.min(e.getX(), mouse_start_point.getX());
                double end_x = Math.max(e.getX(), mouse_start_point.getX());

                Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x,
                        (int) mouse_start_point.getY());

                double new_lower_bound = screenToDataCoordX(start_x);
                double new_upper_bound = screenToDataCoordX(Math.min(end_x, data_area.getMaxX()));
                thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound));
            } else {
                // clear rectangle
                Graphics2D g2 = (Graphics2D) getGraphics();
                g2.setXORMode(java.awt.Color.gray);
                g2.draw(zoom_rectangle);
                g2.dispose();
            }
        }

        // restore zooming
        if (!was_moving && is_moving)
            onActivateZooming();

        zoom_rectangle = null;
        mouse_start_point = null;
    }
}

From source file:de.laures.cewolf.jfree.ThermometerPlot.java

/**
 * Sets the axis range to the current values in the rangeInfo array.
 *//*from   w  ww .ja v  a2s .  c  om*/
protected void setAxisRange() {
    if ((this.subrange >= 0) && (this.followDataInSubranges)) {
        this.rangeAxis.setRange(new Range(this.subrangeInfo[this.subrange][DISPLAY_LOW],
                this.subrangeInfo[this.subrange][DISPLAY_HIGH]));
    } else {
        this.rangeAxis.setRange(this.lowerBound, this.upperBound);
    }
}

From source file:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java

/**
 * Display the chart in the UI thread, using the loaded interval.
 * /*from   w  ww  .j a  v  a 2s  .c o m*/
 * @param chart
 *            jfreechart chart
 * @param histogramInterval
 *            displayed interval
 * @param first
 *            flag indicating if it is the first refresh for a given load
 */
private void displayChart(final JFreeChart chart, final TimeInterval displayed, final boolean first) {
    // prepare the new histogram UI
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            // Clean parent
            for (Control c : compositeChart.getChildren()) {
                c.dispose();
            }
            // histogram chart
            chartFrame = new ChartComposite(compositeChart, SWT.NONE, chart, USE_BUFFER) {

                @Override
                public void mouseMove(MouseEvent e) {
                    super.mouseMove(e);

                    // update cursor
                    if (!isInDataArea(e.x, e.y)) {
                        getShell().setCursor(ARROW_CURSOR);
                    } else {
                        if (dragInProgress || (activeSelection && (isNear(e.x, selectedTs0))
                                || isNear(e.x, selectedTs1))) {
                            getShell().setCursor(IBEAM_CURSOR);
                        } else {
                            getShell().setCursor(ARROW_CURSOR);
                        }
                    }

                    // update marker
                    long v = getTimestampAt(e.x);
                    if (dragInProgress) {
                        // when drag is in progress, the moving side is always Ts1
                        selectedTs1 = v;
                        long min = Math.min(selectedTs0, selectedTs1);
                        long max = Math.max(selectedTs0, selectedTs1);
                        marker.setStartValue(min);
                        marker.setEndValue(max);
                        timeChanged = true;
                        timeBar.setSelection(min, max);
                    }

                    // update status line
                    updateStatusLine(v);
                }

                @Override
                public void mouseUp(MouseEvent e) {
                    super.mouseUp(e);

                    dragInProgress = false;
                    selectedTs1 = getTimestampAt(e.x);
                    if (selectedTs0 > selectedTs1) {
                        // reorder Ts0 and Ts1
                        long tmp = selectedTs1;
                        selectedTs1 = selectedTs0;
                        selectedTs0 = tmp;
                    } else if (selectedTs0 == selectedTs1) {
                        marker.setStartValue(selectedTs0);
                        marker.setEndValue(selectedTs0);
                        activeSelection = false;
                        timeBar.setSelection(loadedInterval);
                        updateStatusLine(selectedTs0);
                    }
                }

                @Override
                public void mouseDown(MouseEvent e) {
                    super.mouseDown(e);

                    if (activeSelection) {
                        if (isNear(e.x, selectedTs0)) {
                            // swap in order to have Ts1 as moving side
                            long tmp = selectedTs0;
                            selectedTs0 = selectedTs1;
                            selectedTs1 = tmp;
                        } else if (isNear(e.x, selectedTs1)) {
                            // nothing to do if the moving side is already Ts1
                        } else {
                            // near to no one: remove marker and add a new one
                            removeMarker();
                            selectedTs0 = getTimestampAt(e.x);
                            addNewMarker(selectedTs0, selectedTs0);
                        }
                    } else {
                        removeMarker();
                        selectedTs0 = getTimestampAt(e.x);
                        addNewMarker(selectedTs0, selectedTs0);
                    }
                    activeSelection = true;
                    dragInProgress = true;
                }

                private boolean isNear(int pos, long value) {
                    final int RANGE = 3;
                    int vPos = getPosAt(value);
                    if (Math.abs(vPos - pos) <= RANGE) {
                        return true;
                    }
                    return false;
                }

                boolean isInDataArea(int x, int y) {
                    if (chartFrame != null) {
                        org.eclipse.swt.graphics.Rectangle swtRect = chartFrame.getScreenDataArea();
                        Rectangle2D screenDataArea = new Rectangle();
                        screenDataArea.setRect(swtRect.x, swtRect.y, swtRect.width, swtRect.height);
                        return swtRect.contains(x, y);
                    }
                    return false;
                }
            };

            chartFrame.addMouseWheelListener(new MouseWheelListener() {

                @Override
                public void mouseScrolled(MouseEvent e) {
                    if ((e.stateMask & SWT.CTRL) == SWT.CTRL) {
                        if (e.count > 0) {
                            // zoom in
                            zoomChartAxis(true, e.x, e.y);
                        } else {
                            // zoom out
                            zoomChartAxis(false, e.x, e.y);
                        }
                    }
                }

                private void zoomChartAxis(boolean increase, int x, int y) {
                    double min = plot.getDomainAxis().getRange().getLowerBound();
                    double max = plot.getDomainAxis().getRange().getUpperBound();
                    X_FORMAT.setContext((long) min, (long) max, true);
                    Point2D p = chartFrame.translateScreenToJava2D(new Point(x, y));
                    PlotRenderingInfo plotInfo = chartFrame.getChartRenderingInfo().getPlotInfo();

                    if (increase) {
                        double dmin = min;
                        double dmax = max;
                        if (dmin <= 0) {
                            double inc = -2 * dmin + 1;
                            dmin += inc;
                            dmax += inc;
                        }
                        double diff = (dmax - dmin) / dmin;
                        if (diff >= 0.01) {
                            // zoom only if the (max - min) is at least 1% of the min
                            plot.zoomDomainAxes(0.5, plotInfo, p, true);
                        }
                    } else {
                        // XXX On Fedora 17 this always dezoom all
                        plot.zoomDomainAxes(-0.5, plotInfo, p, true);
                    }

                    // adjust
                    min = plot.getDomainAxis().getRange().getLowerBound();
                    max = plot.getDomainAxis().getRange().getUpperBound();
                    Range maxRange = new Range(Math.max(loadedInterval.startTimestamp, min),
                            Math.min(loadedInterval.endTimestamp, max));
                    plot.getDomainAxis().setRange(maxRange);

                }
            });

            // - size
            chartFrame.setSize(compositeChart.getSize());
            // - prevent y zooming
            chartFrame.setRangeZoomable(false);
            // - prevent x zooming (we do it manually with wheel)
            chartFrame.setDomainZoomable(false);
            // - workaround for last xaxis tick not shown (jfreechart bug)
            RectangleInsets insets = plot.getInsets();
            plot.setInsets(new RectangleInsets(insets.getTop(), insets.getLeft(), insets.getBottom(), 25));
            // - time bounds
            plot.getDomainAxis().setLowerBound(displayed.startTimestamp);
            plot.getDomainAxis().setUpperBound(displayed.endTimestamp);
            // producers and types
            if (first) {
                for (ConfigurationData data : configurationMap.values()) {
                    data.tree.getViewer().setInput(data.roots);
                    data.tree.setCheckedElements(data.checked);
                    data.tree.getViewer().refresh();
                    data.tree.getViewer().expandAll();
                }
            }
            // timebar
            timeBar.setSelection(loadedInterval);
        }
    });

}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.//from  w ww  .j ava 2 s .  com
 *
 * @param dataset  the dataset ({@code null} not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * @param visibleSeriesKeys  the visible series keys.
 *
 * @return The range (possibly {@code null}).
 *
 * @since 1.0.13
 */
public static Range iterateToFindRangeBounds(CategoryDataset dataset, List visibleSeriesKeys,
        boolean includeInterval) {

    Args.nullNotPermitted(dataset, "dataset");
    Args.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");

    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int columnCount = dataset.getColumnCount();
    if (includeInterval && dataset instanceof BoxAndWhiskerCategoryDataset) {
        // handle special case of BoxAndWhiskerDataset
        BoxAndWhiskerCategoryDataset bx = (BoxAndWhiskerCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            int itemCount = dataset.getColumnCount();
            for (int item = 0; item < itemCount; item++) {
                Number lvalue = bx.getMinRegularValue(series, item);
                if (lvalue == null) {
                    lvalue = bx.getValue(series, item);
                }
                Number uvalue = bx.getMaxRegularValue(series, item);
                if (uvalue == null) {
                    uvalue = bx.getValue(series, item);
                }
                if (lvalue != null) {
                    minimum = Math.min(minimum, lvalue.doubleValue());
                }
                if (uvalue != null) {
                    maximum = Math.max(maximum, uvalue.doubleValue());
                }
            }
        }
    } else if (includeInterval && dataset instanceof IntervalCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number lvalue, uvalue;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                lvalue = icd.getStartValue(series, column);
                uvalue = icd.getEndValue(series, column);
                if (lvalue != null && !Double.isNaN(lvalue.doubleValue())) {
                    minimum = Math.min(minimum, lvalue.doubleValue());
                }
                if (uvalue != null && !Double.isNaN(uvalue.doubleValue())) {
                    maximum = Math.max(maximum, uvalue.doubleValue());
                }
            }
        }
    } else if (includeInterval && dataset instanceof MultiValueCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        MultiValueCategoryDataset mvcd = (MultiValueCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                List values = mvcd.getValues(series, column);
                Iterator valueIterator = values.iterator();
                while (valueIterator.hasNext()) {
                    Object o = valueIterator.next();
                    if (o instanceof Number) {
                        double v = ((Number) o).doubleValue();
                        if (!Double.isNaN(v)) {
                            minimum = Math.min(minimum, v);
                            maximum = Math.max(maximum, v);
                        }
                    }
                }
            }
        }
    } else if (includeInterval && dataset instanceof StatisticalCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        StatisticalCategoryDataset scd = (StatisticalCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                Number meanN = scd.getMeanValue(series, column);
                if (meanN != null) {
                    double std = 0.0;
                    Number stdN = scd.getStdDevValue(series, column);
                    if (stdN != null) {
                        std = stdN.doubleValue();
                        if (Double.isNaN(std)) {
                            std = 0.0;
                        }
                    }
                    double mean = meanN.doubleValue();
                    if (!Double.isNaN(mean)) {
                        minimum = Math.min(minimum, mean - std);
                        maximum = Math.max(maximum, mean + std);
                    }
                }
            }
        }
    } else {
        // handle the standard case (plain CategoryDataset)
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                Number value = dataset.getValue(series, column);
                if (value != null) {
                    double v = value.doubleValue();
                    if (!Double.isNaN(v)) {
                        minimum = Math.min(minimum, v);
                        maximum = Math.max(maximum, v);
                    }
                }
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:net.sf.jasperreports.engine.fill.JRFillChart.java

/**
 * Converts a JasperReport data range into one understood by JFreeChart.
 *
 * @param dataRange the JasperReport version of the range
 * @param evaluation current expression evaluation phase
 * @return the JFreeChart version of the range
 * @throws JRException thrown when the low value of the range is greater than the
 *                   high value/*from w ww  .j  a  v a 2 s  .c  o  m*/
 */
protected Range convertRange(JRDataRange dataRange, byte evaluation) throws JRException {
    if (dataRange == null) {
        return null;
    }
    Number low = (Number) evaluateExpression(dataRange.getLowExpression(), evaluation);
    Number high = (Number) evaluateExpression(dataRange.getHighExpression(), evaluation);
    return new Range(low != null ? low.doubleValue() : 0.0, high != null ? high.doubleValue() : 100.0);
}

From source file:lucee.runtime.tag.Chart.java

private void setScale(JFreeChart chart) {
    Plot plot = chart.getPlot();/* ww  w. ja v  a2  s.c  o m*/
    if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        Range r = rangeAxis.getRange();
        double lower = r.getLowerBound();
        double upper = r.getUpperBound();

        if (labelFormat == LabelFormatUtil.LABEL_FORMAT_DATE && rangeAxis.getRange().getLowerBound() == 0) {
            lower = smallest;
            upper = biggest;
            try {
                DateTime d = Caster.toDate(Caster.toDouble(lower), true, null, null);
                lower = DateAdd.call(pageContext, "yyyy", -1, d).castToDoubleValue(lower);
            } catch (PageException e) {
            }
        }
        if (!Double.isNaN(scalefrom))
            lower = scalefrom;
        if (!Double.isNaN(scaleto))
            upper = scaleto;
        rangeAxis.setRange(new Range(lower, upper), true, true);
    } else if (plot instanceof XYPlot) {
        XYPlot cp = (XYPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        Range r = rangeAxis.getRange();
        double lower = r.getLowerBound();
        double upper = r.getUpperBound();

        if (labelFormat == LabelFormatUtil.LABEL_FORMAT_DATE && rangeAxis.getRange().getLowerBound() == 0) {
            lower = smallest;
            upper = biggest;
            try {
                DateTime d = Caster.toDate(Caster.toDouble(lower), true, null, null);
                lower = DateAdd.call(pageContext, "yyyy", -1, d).castToDoubleValue(lower);
            } catch (PageException e) {
            }
        }
        if (!Double.isNaN(scalefrom))
            lower = scalefrom;
        if (!Double.isNaN(scaleto))
            upper = scaleto;
        rangeAxis.setRange(new Range(lower, upper), true, true);
    }
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Iterates over the data item of the category dataset to find
 * the range bounds.//  ww w .j a v  a  2  s.c  o  m
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines whether or not the
 *                         y-interval is taken into account.
 * @param visibleSeriesKeys  the visible series keys.
 *
 * @return The range (possibly <code>null</code>).
 *
 * @since 1.0.13
 */
public static Range iterateToFindRangeBounds(CategoryDataset dataset, List visibleSeriesKeys,
        boolean includeInterval) {

    ParamChecks.nullNotPermitted(dataset, "dataset");
    ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");

    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int columnCount = dataset.getColumnCount();
    if (includeInterval && dataset instanceof BoxAndWhiskerCategoryDataset) {
        // handle special case of BoxAndWhiskerDataset
        BoxAndWhiskerCategoryDataset bx = (BoxAndWhiskerCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            int itemCount = dataset.getColumnCount();
            for (int item = 0; item < itemCount; item++) {
                Number lvalue = bx.getMinRegularValue(series, item);
                if (lvalue == null) {
                    lvalue = bx.getValue(series, item);
                }
                Number uvalue = bx.getMaxRegularValue(series, item);
                if (uvalue == null) {
                    uvalue = bx.getValue(series, item);
                }
                if (lvalue != null) {
                    minimum = Math.min(minimum, lvalue.doubleValue());
                }
                if (uvalue != null) {
                    maximum = Math.max(maximum, uvalue.doubleValue());
                }
            }
        }
    } else if (includeInterval && dataset instanceof IntervalCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        IntervalCategoryDataset icd = (IntervalCategoryDataset) dataset;
        Number lvalue, uvalue;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                lvalue = icd.getStartValue(series, column);
                uvalue = icd.getEndValue(series, column);
                if (lvalue != null && !Double.isNaN(lvalue.doubleValue())) {
                    minimum = Math.min(minimum, lvalue.doubleValue());
                }
                if (uvalue != null && !Double.isNaN(uvalue.doubleValue())) {
                    maximum = Math.max(maximum, uvalue.doubleValue());
                }
            }
        }
    } else if (includeInterval && dataset instanceof MultiValueCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        MultiValueCategoryDataset mvcd = (MultiValueCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                List values = mvcd.getValues(series, column);
                Iterator valueIterator = values.iterator();
                while (valueIterator.hasNext()) {
                    Object o = valueIterator.next();
                    if (o instanceof Number) {
                        double v = ((Number) o).doubleValue();
                        if (!Double.isNaN(v)) {
                            minimum = Math.min(minimum, v);
                            maximum = Math.max(maximum, v);
                        }
                    }
                }
            }
        }
    } else if (includeInterval && dataset instanceof StatisticalCategoryDataset) {
        // handle the special case where the dataset has y-intervals that
        // we want to measure
        StatisticalCategoryDataset scd = (StatisticalCategoryDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                Number meanN = scd.getMeanValue(series, column);
                if (meanN != null) {
                    double std = 0.0;
                    Number stdN = scd.getStdDevValue(series, column);
                    if (stdN != null) {
                        std = stdN.doubleValue();
                        if (Double.isNaN(std)) {
                            std = 0.0;
                        }
                    }
                    double mean = meanN.doubleValue();
                    if (!Double.isNaN(mean)) {
                        minimum = Math.min(minimum, mean - std);
                        maximum = Math.max(maximum, mean + std);
                    }
                }
            }
        }
    } else {
        // handle the standard case (plain CategoryDataset)
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.getRowIndex(seriesKey);
            for (int column = 0; column < columnCount; column++) {
                Number value = dataset.getValue(series, column);
                if (value != null) {
                    double v = value.doubleValue();
                    if (!Double.isNaN(v)) {
                        minimum = Math.min(minimum, v);
                        maximum = Math.max(maximum, v);
                    }
                }
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:gda.plots.SimplePlot.java

/**
 * Creates the JPopupMenu, overrides (but uses) the super class method adding items for the Magnification and
 * Logarithmic axes./*from   www  .j ava 2  s .co m*/
 * 
 * @param properties
 *            boolean if true appears on menu
 * @param save
 *            boolean if true appears on menu
 * @param print
 *            boolean if true appears on menu
 * @param zoom
 *            boolean if true appears on menu
 * @return the popup menu
 */
@Override
protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) {
    // Create the popup without the zooming parts
    JPopupMenu jpm = super.createPopupMenu(properties, false, print, false);

    // as the save function on the chartpanel doesn't remember its location,
    // we shall remove it and and create a new save option
    if (save) {
        jpm.add(new JSeparator());

        // The save button

        saveButton = new JMenuItem("Save As");
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveAs();
            }
        });

        jpm.add(saveButton);
    }

    jpm.add(new JSeparator());

    // This button toggles the data-type magnification
    magnifyDataButton = new JCheckBoxMenuItem("Magnify(Data)");
    magnifyDataButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setMagnifyingData(!isMagnifyingData());
        }
    });
    jpm.add(magnifyDataButton);

    jpm.add(new JSeparator());

    // The zoomButton toggles the value of zooming.
    zoomButton = new JCheckBoxMenuItem("Zoom");
    zoomButton.setHorizontalTextPosition(SwingConstants.LEFT);
    zoomButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setZooming(!isZooming());
        }
    });
    jpm.add(zoomButton);

    // The unZoomButton is not a toggle, it undoes the last zoom.
    unZoomButton = new JMenuItem("UnZoom");
    unZoomButton.setEnabled(false);
    unZoomButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            unZoom();
        }
    });
    jpm.add(unZoomButton);

    if (type == LINECHART) {
        jpm.add(new JSeparator());

        turboModeButton = new JCheckBoxMenuItem("Turbo Mode");
        turboModeButton.setHorizontalTextPosition(SwingConstants.LEFT);
        turboModeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setTurboMode(!isTurboMode());
            }
        });
        turboModeButton.setSelected(isTurboMode());
        jpm.add(turboModeButton);

        stripModeButton = new JCheckBoxMenuItem("StripChart Mode");
        stripModeButton.setHorizontalTextPosition(SwingConstants.LEFT);
        stripModeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String widthStr = "";
                {
                    double width = lastDomainBoundsLeft != null ? lastDomainBoundsLeft.getLength()
                            : Double.MAX_VALUE;
                    widthStr = getXAxisNumberFormat().format(width);
                    widthStr = JOptionPane.showInputDialog(null,
                            "Enter the x strip width - clear for autorange", widthStr);
                    if (widthStr == null) //cancel
                        return;
                }
                Double newStripWidth = null;
                if (!widthStr.isEmpty()) {
                    try {
                        newStripWidth = Double.valueOf(widthStr);
                    } catch (Exception ex) {
                        logger.error(ex.getMessage(), ex);
                    }
                }
                setStripWidth(newStripWidth);
            }
        });
        stripModeButton.setSelected(isStripMode());
        jpm.add(stripModeButton);

        xLimitsButton = new JCheckBoxMenuItem("Fix X Axis Limits");
        xLimitsButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String minStr = "";
                {
                    double min = lastDomainBoundsLeft != null ? lastDomainBoundsLeft.getLowerBound()
                            : Double.MAX_VALUE;
                    minStr = getXAxisNumberFormat().format(min);
                    minStr = JOptionPane.showInputDialog(null, "Enter the min x value - clear for autorange",
                            minStr);
                    if (minStr == null) //cancel
                        return;

                }
                String maxStr = "";
                if (!minStr.isEmpty()) {
                    double max = lastDomainBoundsLeft != null ? lastDomainBoundsLeft.getUpperBound()
                            : -Double.MAX_VALUE;
                    maxStr = getXAxisNumberFormat().format(max);
                    maxStr = JOptionPane.showInputDialog(null, "Enter the max x value - clear for autorange",
                            maxStr);
                    if (maxStr == null) //cancel
                        return;
                }
                Range newBounds = null;
                if (!maxStr.isEmpty() && !minStr.isEmpty()) {
                    try {
                        newBounds = new Range(Double.valueOf(minStr), Double.valueOf(maxStr));
                    } catch (Exception ex) {
                        logger.error(ex.getMessage(), ex);
                    }
                }
                setDomainBounds(newBounds);
            }
        });
        xLimitsButton.setSelected(false);
        jpm.add(xLimitsButton);

    }

    jpm.add(new JSeparator());

    xLogLinButton = new JMenuItem("Logarithmic X axis");
    xLogLinButton.setEnabled(true);
    xLogLinButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setXAxisLogarithmic(!isXAxisLogarithmic());
        }
    });
    jpm.add(xLogLinButton);

    yLogLinButton = new JMenuItem("Logarithmic Y axis");
    yLogLinButton.setEnabled(true);
    yLogLinButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setYAxisLogarithmic(!isYAxisLogarithmic());
        }
    });
    jpm.add(yLogLinButton);

    y2LogLinButton = new JMenuItem("Logarithmic Y2 axis");
    y2LogLinButton.setEnabled(false);
    y2LogLinButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setYAxisTwoLogarithmic(!isYAxisTwoLogarithmic());
        }
    });

    jpm.add(y2LogLinButton);

    jpm.add(new JSeparator());

    // Adding a new button to allow the user to select the formatting they
    // want on the x and y axis
    xFormatButton = new JMenuItem("X Axis Format");
    xFormatButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String Format = getXAxisNumberFormat().format(0.0);
            String input = JOptionPane.showInputDialog(null,
                    "Enter the new formatting for the X axis, of the form 0.0000E00", Format);
            // try forcing this into some objects
            try {
                setScientificXAxis(new DecimalFormat(input));
            } catch (Exception err) {
                logger.error("Could not use this format due to {}", e);
            }
        }
    });
    jpm.add(xFormatButton);

    // Adding a new button to allow the user to select the formatting they
    // want on the x and y axis
    yFormatButton = new JMenuItem("Y Axis Format");
    yFormatButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String Format = getYAxisNumberFormat().format(0.0);
            String input = JOptionPane.showInputDialog(null,
                    "Enter the new formatting for the Y axis, of the form 0.0000E00", Format);
            // try forcing this into some objects
            try {
                setScientificYAxis(new DecimalFormat(input));
            } catch (Exception err) {
                logger.error("Could not use this format due to {}", e);
            }
        }
    });
    jpm.add(yFormatButton);

    // The zoomButton toggles the value of zooming.
    xAxisVerticalTicksButton = new JCheckBoxMenuItem("Vertical X Ticks");
    xAxisVerticalTicksButton.setHorizontalTextPosition(SwingConstants.LEFT);
    xAxisVerticalTicksButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setVerticalXAxisTicks(xAxisVerticalTicksButton.isSelected());
        }
    });
    jpm.add(xAxisVerticalTicksButton);

    return jpm;
}

From source file:com.att.aro.ui.view.diagnostictab.GraphPanel.java

private CombinedDomainXYPlot getPlot() {
    if (plot == null) {
        axis = new NumberAxis();
        axis.setStandardTickUnits(graphHelper.getTickUnits());
        axis.setRange(new Range(0, DEFAULT_TIMELINE));
        axis.setLowerBound(0);/*  w  w w. ja v  a 2 s  . c  o m*/

        axis.setAutoTickUnitSelection(true);
        axis.setTickMarkInsideLength(1);
        axis.setTickMarkOutsideLength(1);

        axis.setMinorTickMarksVisible(true);
        axis.setMinorTickMarkInsideLength(2f);
        axis.setMinorTickMarkOutsideLength(2f);
        axis.setTickMarkInsideLength(4f);
        axis.setTickMarkOutsideLength(4f);

        plot = new CombinedDomainXYPlot(axis);
        plot.setOrientation(PlotOrientation.VERTICAL);
        plot.setGap(0.1);
    }
    return plot;
}

From source file:org.glotaran.core.datadisplayers.multispec.MultiSpecEditorTopComponent.java

@Override
public void chartChanged(ChartChangeEvent cce) {
    XYPlot plot = this.chartMultiSpec.getXYPlot();
    double lowBound = plot.getDomainAxis().getRange().getLowerBound();
    double upBound = plot.getDomainAxis().getRange().getUpperBound();
    boolean recreate = false;
    int lowInd, upInd;

    if (lowBound < wholeXRange.getLowerBound()) {
        lowBound = wholeXRange.getLowerBound();
        recreate = true;// w w w.  j a v  a  2s.com
    }
    if (upBound > wholeXRange.getUpperBound()) {
        upBound = wholeXRange.getUpperBound();
        recreate = true;
    }
    if (recreate) {
        plot.getDomainAxis().setRange(new Range(lowBound, upBound));
    }
    recreate = false;
    lowBound = plot.getRangeAxis().getRange().getLowerBound();
    upBound = plot.getRangeAxis().getRange().getUpperBound();
    if (lowBound < wholeYRange.getLowerBound()) {
        lowBound = wholeYRange.getLowerBound();
        recreate = true;
    }
    if (upBound > wholeYRange.getUpperBound()) {
        upBound = wholeYRange.getUpperBound();
        recreate = true;
    }
    if (recreate) {
        plot.getRangeAxis().setRange(new Range(lowBound, upBound));
        //            this.chartMain.getPlot().getDomainAxis().setRange(new Range(lowBound, upBound));
    }

    if (!plot.getDomainAxis().getRange().equals(this.lastXRange)) {
        this.lastXRange = plot.getDomainAxis().getRange();
        XYPlot plot2 = (XYPlot) this.subchartHorisontalTrace.getPlot();
        lowInd = (int) (this.lastXRange.getLowerBound());
        upInd = (int) (this.lastXRange.getUpperBound() - 1);
        double lowIndValue = data.getIntenceImY()[lowInd];
        double upIndValue = data.getIntenceImY()[upInd];
        Range domainAxisRange = lowIndValue > upIndValue ? (new Range(upIndValue, lowIndValue))
                : (new Range(lowIndValue, upIndValue));
        plot2.getDomainAxis().setRange(domainAxisRange);
        jSVerticalCut.setMinimum(lowInd);
        jSVerticalCut.setMaximum(upInd);

    }

    if (!plot.getRangeAxis().getRange().equals(this.lastYRange)) {
        this.lastYRange = plot.getRangeAxis().getRange();
        XYPlot plot1 = (XYPlot) this.subchartVerticalCutTrace.getPlot();
        lowInd = (int) (this.wholeYRange.getUpperBound() - this.lastYRange.getUpperBound());
        upInd = (int) (this.wholeYRange.getUpperBound() - this.lastYRange.getLowerBound() - 1);
        plot1.getDomainAxis().setRange(new Range(data.getIntenceImX()[lowInd], data.getIntenceImX()[upInd]));
        plot1.getRangeAxis().setAutoRange(true);
        jsHorisontalCut.setMinimum(lowInd);
        jsHorisontalCut.setMaximum(upInd);
    }

}