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

The following examples show how to use org.jfree.chart.ChartPanel#setSelectionShape() . 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 dragged event.
 *
 * @param e  the event.
 */
public void mouseDragged(MouseEvent e) {
    if (this.lastPoint == null) {
        return;  // we never started a selection
    }
    ChartPanel panel = (ChartPanel) e.getSource();
    Point pt = e.getPoint();
    Point2D pt2 = ShapeUtilities.getPointInRectangle(pt.x, pt.y,
            panel.getScreenDataArea());
    if (pt2.distance(this.lastPoint) > 5) {
        this.selection.lineTo((float) pt2.getX(), (float) pt2.getY());
        this.lastPoint = pt2;
    }
    panel.setSelectionShape(selection);
    panel.setSelectionFillPaint(this.fillPaint);
    panel.setSelectionOutlinePaint(this.outlinePaint);
    panel.repaint();
}
 
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();
}