Java Code Examples for org.jfree.chart.ChartPanel#getChart()

The following examples show how to use org.jfree.chart.ChartPanel#getChart() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegionSelectionHandler.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse pressed event.
 *
 * @param e  the event.
 */
public void mousePressed(MouseEvent e) {
    ChartPanel panel = (ChartPanel) e.getSource();
    JFreeChart chart = panel.getChart();
    if (chart == null) {
        return;
    }
    if (!(chart.getPlot() instanceof Selectable)) {
        return;
    }
    Selectable s = (Selectable) chart.getPlot();
    if (!s.canSelectByRegion()) {
        return;
    }
    Rectangle2D dataArea = panel.getScreenDataArea();
    if (dataArea.contains(e.getPoint())) {
        if (!e.isShiftDown()) {
            s.clearSelection();
            chart.setNotify(true);
        }
        Point pt = e.getPoint();
        this.selection.moveTo((float) pt.getX(), (float) pt.getY());
        this.lastPoint = new Point(pt);
    }
}
 
Example 2
Source File: RegionSelectionHandler.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles a mouse released event.
 *
 * @param e  the event.
 */
public void mouseReleased(MouseEvent e) {
    if (this.lastPoint == null) {
        return;  // we never started a selection
    }
    ChartPanel panel = (ChartPanel) e.getSource();
    this.selection.closePath();

    // do something with the selection shape
    JFreeChart chart = panel.getChart();
    Plot plot = chart.getPlot();
    if (!(plot instanceof Selectable)) {
        return;
    }
    Selectable p = (Selectable) plot;
    if (p.canSelectByRegion()) {
        p.select(this.selection, panel.getScreenDataArea(), panel);
    }
    panel.setSelectionShape(null);
    this.selection.reset();
    this.lastPoint = null;
    panel.repaint();
    //panel.clearLiveMouseHandler();
}
 
Example 3
Source File: RegionSelectionHandler.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handle a mouse click - if the plot supports it, a single data item
 * can be selected (or added to the selection).
 *
 * @param e  the event.
 */
public void mouseClicked(MouseEvent e) {
    System.out.println("mouseClicked(): " + e);
    ChartPanel panel = (ChartPanel) e.getSource();
    Rectangle2D dataArea = panel.getScreenDataArea();
    if (dataArea.contains(e.getPoint())) {
        JFreeChart chart = panel.getChart();
        if (chart.getPlot() instanceof Selectable) {
            Selectable s = (Selectable) chart.getPlot();
            if (s.canSelectByPoint()) {
                Point pt = e.getPoint();
                s.select(pt.getX(), pt.getY(), dataArea, panel);
            }
        }
    }
}
 
Example 4
Source File: PanHandler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handles a mouse dragged event.  This is where the panning occurs.
 *
 * @param e  the event.
 */
public void mouseDragged(MouseEvent e) {
    // handle panning if we have a start point
    if (this.panLast == null) {
        return;
    }
    ChartPanel panel = (ChartPanel) e.getSource();
    JFreeChart chart = panel.getChart();
    double dx = e.getX() - this.panLast.getX();
    double dy = e.getY() - this.panLast.getY();
    if (dx == 0.0 && dy == 0.0) {
        return;
    }
    double wPercent = -dx / this.panW;
    double hPercent = dy / this.panH;
    boolean old = chart.getPlot().isNotify();
    chart.getPlot().setNotify(false);
    Pannable p = (Pannable) chart.getPlot();
    PlotRenderingInfo info = panel.getChartRenderingInfo().getPlotInfo();
    if (p.getOrientation() == PlotOrientation.VERTICAL) {
        p.panDomainAxes(wPercent, info, this.panLast);
        p.panRangeAxes(hPercent, info, this.panLast);
    }
    else {
        p.panDomainAxes(hPercent, info, this.panLast);
        p.panRangeAxes(wPercent, info, this.panLast);
    }
    this.panLast = e.getPoint();
    chart.getPlot().setNotify(old);
    return;
}
 
Example 5
Source File: MouseMarker.java    From grammarviz2_src with GNU General Public License v2.0 4 votes vote down vote up
public MouseMarker(ChartPanel panel) {
  this.panel = panel;
  this.chart = panel.getChart();
  this.plot = (XYPlot) chart.getPlot();
}