Example usage for org.jfree.chart.event AxisChangeEvent getAxis

List of usage examples for org.jfree.chart.event AxisChangeEvent getAxis

Introduction

In this page you can find the example usage for org.jfree.chart.event AxisChangeEvent getAxis.

Prototype

public Axis getAxis() 

Source Link

Document

Returns the axis that generated the event.

Usage

From source file:net.sf.mzmine.chartbasics.listener.AxisRangeChangedListener.java

@Override
public void axisChanged(AxisChangeEvent e) {
    ValueAxis a = (ValueAxis) e.getAxis();
    Range r = a.getRange();/* w w  w  .  jav a2s.  c o  m*/

    if (r != null && (lastRange == null || !r.equals(lastRange))) {
        // range has changed
        axisRangeChanged(chart, a, lastRange, r);
    }
    lastRange = r;
}

From source file:net.sf.mzmine.chartbasics.listener.AxesRangeChangedListener.java

@Override
public void axisChanged(AxisChangeEvent e) {
    ValueAxis a = (ValueAxis) e.getAxis();
    Range r = a.getRange();/*from  w w w .  j  ava2s  .c o m*/

    boolean found = false;
    int i = 0;
    for (i = 0; i < axis.length && !found; i++) {
        // get index of axis
        if (axis[i] == null)
            break;
        if (a.equals(axis[i])) {
            found = true;
            break;
        }
    }
    if (i >= axis.length)
        i = axis.length - 1;
    // insert if not found
    if (!found) {
        axis[i] = a;
    }

    if (r != null && (lastRange[i] == null || !r.equals(lastRange[i]))) {
        // range has changed
        axesRangeChanged(chart, a, lastRange[i], r);
    }
    lastRange[i] = r;
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Receives notification of an axis change event.
 *
 * @param event the event.//from   w w w .j a v a2s  .co  m
 */
public void axisChanged(AxisChangeEvent event) {
    if (event.getAxis() == domainAxis) {
        domainZoomMultiplier = domainAxisLength / domainAxis.getRange().getLength();
    } else if (event.getAxis() == rangeAxis) {
        rangeZoomMultiplier = rangeAxisLength / rangeAxis.getRange().getLength();
    }
}

From source file:org.esa.beam.visat.toolviews.spectrum.SpectrumToolView.java

@Override
public JComponent createControl() {
    final JFreeChart chart = ChartFactory.createXYLineChart(CHART_TITLE, "Wavelength (nm)", "", null,
            PlotOrientation.VERTICAL, true, true, false);
    chart.getXYPlot().getRangeAxis().addChangeListener(new AxisChangeListener() {
        @Override//from w ww.  j a  va2s .c  om
        public void axisChanged(AxisChangeEvent axisChangeEvent) {
            if (!isCodeInducedAxisChange) {
                rangeAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange();
            }
        }
    });
    chart.getXYPlot().getDomainAxis().addChangeListener(new AxisChangeListener() {
        @Override
        public void axisChanged(AxisChangeEvent axisChangeEvent) {
            if (!isCodeInducedAxisChange) {
                domainAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange();
            }
        }
    });
    chart.getXYPlot().getRangeAxis().setAutoRange(false);
    rangeAxisAdjustmentIsFrozen = false;
    chart.getXYPlot().getDomainAxis().setAutoRange(false);
    domainAxisAdjustmentIsFrozen = false;
    chartPanel = new ChartPanel(chart);
    chartHandler = new ChartHandler(chart);
    final XYPlotMarker plotMarker = new XYPlotMarker(chartPanel, new XYPlotMarker.Listener() {
        @Override
        public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) {
            if (hasDiagram()) {
                if (cursorSynchronizer == null) {
                    cursorSynchronizer = new CursorSynchronizer(VisatApp.getApp());
                }
                if (!cursorSynchronizer.isEnabled()) {
                    cursorSynchronizer.setEnabled(true);
                }
            }
        }

        @Override
        public void pointDeselected() {
            cursorSynchronizer.setEnabled(false);
        }
    });

    titleBase = getDescriptor().getTitle();
    filterButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Filter24.gif"), false);
    filterButton.setName("filterButton");
    filterButton.setEnabled(false);
    filterButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectSpectralBands();
            recreateChart();
        }
    });

    showSpectrumForCursorButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/CursorSpectrum24.gif"), true);
    showSpectrumForCursorButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            recreateChart();
        }
    });
    showSpectrumForCursorButton.setName("showSpectrumForCursorButton");
    showSpectrumForCursorButton.setSelected(true);
    showSpectrumForCursorButton.setToolTipText("Show spectrum at cursor position.");

    showSpectraForSelectedPinsButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/SelectedPinSpectra24.gif"), true);
    showSpectraForSelectedPinsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isShowingSpectraForAllPins()) {
                showSpectraForAllPinsButton.setSelected(false);
            } else if (!isShowingSpectraForSelectedPins()) {
                plotMarker.setInvisible();
            }
            recreateChart();
        }
    });
    showSpectraForSelectedPinsButton.setName("showSpectraForSelectedPinsButton");
    showSpectraForSelectedPinsButton.setToolTipText("Show spectra for selected pins.");

    showSpectraForAllPinsButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/PinSpectra24.gif"), true);
    showSpectraForAllPinsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isShowingSpectraForSelectedPins()) {
                showSpectraForSelectedPinsButton.setSelected(false);
            } else if (!isShowingSpectraForAllPins()) {
                plotMarker.setInvisible();
            }
            recreateChart();
        }
    });
    showSpectraForAllPinsButton.setName("showSpectraForAllPinsButton");
    showSpectraForAllPinsButton.setToolTipText("Show spectra for all pins.");

    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        showAveragePinSpectrumButton = ToolButtonFactory.createButton(
    //                UIUtils.loadImageIcon("icons/AverageSpectrum24.gif"), true);
    //        showAveragePinSpectrumButton.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                // todo - implement
    //            }
    //        });
    //        showAveragePinSpectrumButton.setName("showAveragePinSpectrumButton");
    //        showAveragePinSpectrumButton.setToolTipText("Show average spectrum of all pin spectra.");

    showGridButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/SpectrumGrid24.gif"), true);
    showGridButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            chartHandler.setGridVisible(showGridButton.isSelected());
        }
    });
    showGridButton.setName("showGridButton");
    showGridButton.setToolTipText("Show diagram grid.");

    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        showGraphPointsButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/GraphPoints24.gif"), true);
    //        showGraphPointsButton.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                // todo - implement
    //                JOptionPane.showMessageDialog(null, "Not implemented");
    //            }
    //        });
    //        showGraphPointsButton.setName("showGraphPointsButton");
    //        showGraphPointsButton.setToolTipText("Show graph points grid.");

    AbstractButton exportSpectraButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);
    exportSpectraButton.addActionListener(new SpectraExportAction(this));
    exportSpectraButton.setToolTipText("Export spectra to text file.");
    exportSpectraButton.setName("exportSpectraButton");

    AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"),
            false);
    helpButton.setName("helpButton");
    helpButton.setToolTipText("Help."); /*I18N*/

    final JPanel buttonPane = GridBagUtils.createPanel();
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.fill = GridBagConstraints.NONE;
    gbc.insets.top = 2;
    gbc.gridy = 0;
    buttonPane.add(filterButton, gbc);
    gbc.gridy++;
    buttonPane.add(showSpectrumForCursorButton, gbc);
    gbc.gridy++;
    buttonPane.add(showSpectraForSelectedPinsButton, gbc);
    gbc.gridy++;
    buttonPane.add(showSpectraForAllPinsButton, gbc);
    gbc.gridy++;
    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        buttonPane.add(showAveragePinSpectrumButton, gbc);
    //        gbc.gridy++;
    buttonPane.add(showGridButton, gbc);
    gbc.gridy++;
    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        buttonPane.add(showGraphPointsButton, gbc);
    //        gbc.gridy++;
    buttonPane.add(exportSpectraButton, gbc);

    gbc.gridy++;
    gbc.insets.bottom = 0;
    gbc.fill = GridBagConstraints.VERTICAL;
    gbc.weighty = 1.0;
    gbc.gridwidth = 2;
    buttonPane.add(new JLabel(" "), gbc); // filler
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 0.0;
    gbc.gridy = 10;
    gbc.anchor = GridBagConstraints.EAST;
    buttonPane.add(helpButton, gbc);

    chartPanel.setPreferredSize(new Dimension(300, 200));
    chartPanel.setBackground(Color.white);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createBevelBorder(BevelBorder.LOWERED), BorderFactory.createEmptyBorder(2, 2, 2, 2)));
    chartPanel.addChartMouseListener(plotMarker);

    JPanel mainPane = new JPanel(new BorderLayout(4, 4));
    mainPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    mainPane.add(BorderLayout.CENTER, chartPanel);
    mainPane.add(BorderLayout.EAST, buttonPane);
    mainPane.setPreferredSize(new Dimension(320, 200));

    if (getDescriptor().getHelpId() != null) {
        HelpSys.enableHelpOnButton(helpButton, getDescriptor().getHelpId());
        HelpSys.enableHelpKey(mainPane, getDescriptor().getHelpId());
    }

    // Add an internal frame listener to VISAT so that we can update our
    // spectrum dialog with the information of the currently activated
    // product scene view.
    //
    VisatApp.getApp().addInternalFrameListener(new SpectrumIFL());

    VisatApp.getApp().getProductManager().addListener(new ProductManager.Listener() {
        @Override
        public void productAdded(ProductManager.Event event) {
            // ignored
        }

        @Override
        public void productRemoved(ProductManager.Event event) {
            final Product product = event.getProduct();
            if (getCurrentProduct() == product) {
                chartPanel.getChart().getXYPlot().setDataset(null);
                setCurrentView(null);
                setCurrentProduct(null);
            }
            if (productToAllSpectraMap.containsKey(product)) {
                productToAllSpectraMap.remove(product);
            }
            if (productToBandsMap.containsKey(product)) {
                productToBandsMap.remove(product);
            }
            PlacemarkGroup pinGroup = product.getPinGroup();
            for (int i = 0; i < pinGroup.getNodeCount(); i++) {
                chartHandler.removePinInformation(pinGroup.get(i));
            }
        }
    });

    final ProductSceneView view = VisatApp.getApp().getSelectedProductSceneView();
    if (view != null) {
        handleViewActivated(view);
    } else {
        setCurrentView(view);
    }
    updateUIState();
    return mainPane;
}

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

/**
 * Prepare the plot//w w w.j  av a2s  . c  o m
 * 
 * @param chart
 *            jfreechart chart
 * @param displayed
 *            displayed time interval
 */
private void preparePlot(boolean first, JFreeChart chart, TimeInterval displayed) {
    // Plot customization
    plot = chart.getXYPlot();
    // Grid and background colors
    plot.setBackgroundPaint(BACKGROUND_PAINT);
    plot.setDomainGridlinePaint(DOMAIN_GRIDLINE_PAINT);
    plot.setRangeGridlinePaint(RANGE_GRIDLINE_PAINT);
    // Tooltip
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseToolTipGenerator(TOOLTIP_GENERATOR);
    // Disable bar white stripes
    XYBarRenderer barRenderer = (XYBarRenderer) plot.getRenderer();
    barRenderer.setBarPainter(new StandardXYBarPainter());
    // X axis
    X_FORMAT.setTimeUnit(TimeUnit.getTimeUnit(currentShownTrace.getTimeUnit()));
    X_FORMAT.setContext(displayed.startTimestamp, displayed.endTimestamp, true);
    NumberAxis xaxis = (NumberAxis) plot.getDomainAxis();
    xaxis.setTickLabelFont(TICK_LABEL_FONT);
    xaxis.setLabelFont(LABEL_FONT);
    xaxis.setNumberFormatOverride(X_FORMAT);
    TickDescriptor des = X_FORMAT.getTickDescriptor(displayed.startTimestamp, displayed.endTimestamp,
            numberOfTicks);
    xaxis.setTickUnit(new NumberTickUnit(des.delta));
    xaxis.addChangeListener(new AxisChangeListener() {
        @Override
        public void axisChanged(AxisChangeEvent arg) {
            long max = ((Double) plot.getDomainAxis().getRange().getUpperBound()).longValue();
            long min = ((Double) plot.getDomainAxis().getRange().getLowerBound()).longValue();
            TickDescriptor des = X_FORMAT.getTickDescriptor(min, max, numberOfTicks);
            NumberTickUnit newUnit = new NumberTickUnit(des.delta);
            NumberTickUnit currentUnit = ((NumberAxis) arg.getAxis()).getTickUnit();
            // ensure we don't loop
            if (!currentUnit.equals(newUnit)) {
                ((NumberAxis) arg.getAxis()).setTickUnit(newUnit);
            }
        }
    });
    // Y axis
    NumberAxis yaxis = (NumberAxis) plot.getRangeAxis();
    yaxis.setTickLabelFont(TICK_LABEL_FONT);
    yaxis.setLabelFont(LABEL_FONT);
    // remove the marker, if any
    if (marker != null) {
        plot.removeDomainMarker(marker);
        marker = null;
    }
}