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

The following examples show how to use org.jfree.chart.ChartPanel#getScreenDataArea() . 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: PanHandler.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();
    Plot plot = panel.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        return;  // there's nothing for us to do
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Rectangle2D screenDataArea = panel.getScreenDataArea(e.getX(),
                e.getY());
        if (screenDataArea != null && screenDataArea.contains(
                e.getPoint())) {
            this.panW = screenDataArea.getWidth();
            this.panH = screenDataArea.getHeight();
            this.panLast = e.getPoint();
            panel.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }
    }
    // the actual panning occurs later in the mouseDragged() method
}
 
Example 2
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 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: ZoomHandler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void mousePressed(MouseEvent e) {
    ChartPanel chartPanel = (ChartPanel) e.getSource();
    Rectangle2D screenDataArea = chartPanel.getScreenDataArea(e.getX(),
            e.getY());
    if (screenDataArea != null) {
        this.zoomPoint = ShapeUtilities.getPointInRectangle(e.getX(),
                e.getY(), screenDataArea);
    }
    else {
        this.zoomPoint = null;
    }
}
 
Example 5
Source File: XYPlotMarker.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    if (viewPoint != null) {
        Shape oldClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        g2.setClip(dataArea);

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Ellipse2D.Double ellipse = new Ellipse2D.Double(viewPoint.getX() - 0.5 * markerSize,
                                                        viewPoint.getY() - 0.5 * markerSize,
                                                        markerSize,
                                                        markerSize);
        g2.setPaint(fillPaint);
        g2.fill(ellipse);
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(ellipse);

        Rectangle2D box = new Rectangle2D.Double(dataArea.getX() + 5, dataArea.getY() + 5, 100, 52);
        g2.setPaint(fillPaint);
        g2.fill(box);
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(box);

        g2.drawString(String.format("x = %.3f", dataPoint.getX()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 20));
        g2.drawString(String.format("y = %.3f", dataPoint.getY()), (int) (dataArea.getX() + 5 + 5), (int) (dataArea.getY() + 5 + 40));

        g2.setClip(oldClip);
    }
}
 
Example 6
Source File: MouseListenerValue.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static int getChartXLocation( final Point point, final ChartPanel panel )
{
	final Point2D p = panel.translateScreenToJava2D( point );
	final Rectangle2D plotArea = panel.getScreenDataArea();
	final XYPlot plot = (XYPlot) panel.getChart().getPlot();
	final double chartX = plot.getDomainAxis().java2DToValue( p.getX(), plotArea, plot.getDomainAxisEdge() );
	//final double chartY = plot.getRangeAxis().java2DToValue( p.getY(), plotArea, plot.getRangeAxisEdge() );

	return (int)Math.round( chartX );
}
 
Example 7
Source File: MouseListenerTimelapse.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static int getChartXLocation( final Point point, final ChartPanel panel )
{
	final Point2D p = panel.translateScreenToJava2D( point );
	final Rectangle2D plotArea = panel.getScreenDataArea();
	final XYPlot plot = (XYPlot) panel.getChart().getPlot();
	final double chartX = plot.getDomainAxis().java2DToValue( p.getX(), plotArea, plot.getDomainAxisEdge() );
	//final double chartY = plot.getRangeAxis().java2DToValue( p.getY(), plotArea, plot.getRangeAxisEdge() );

	return (int)Math.round( chartX );
}
 
Example 8
Source File: MouseListenerTimelapse.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static int getChartXLocation( final Point point, final ChartPanel panel )
{
	final Point2D p = panel.translateScreenToJava2D( point );
	final Rectangle2D plotArea = panel.getScreenDataArea();
	final XYPlot plot = (XYPlot) panel.getChart().getPlot();
	final double chartX = plot.getDomainAxis().java2DToValue( p.getX(), plotArea, plot.getDomainAxisEdge() );
	//final double chartY = plot.getRangeAxis().java2DToValue( p.getY(), plotArea, plot.getRangeAxisEdge() );
	
	return (int)Math.round( chartX );			
}
 
Example 9
Source File: ZoomHandler.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void mouseReleased(MouseEvent e) {

        if (this.zoomRectangle == null) {
            return;
        }
        ChartPanel panel = (ChartPanel) e.getSource();
        boolean hZoom = false;
        boolean vZoom = false;
        if (panel.getOrientation() == PlotOrientation.HORIZONTAL) {
            hZoom = panel.isRangeZoomable();
            vZoom = panel.isDomainZoomable();
        }
        else {
            hZoom = panel.isDomainZoomable();
            vZoom = panel.isRangeZoomable();
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX()
                - this.zoomPoint.getX()) >= panel.getZoomTriggerDistance();
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY()
                - this.zoomPoint.getY()) >= panel.getZoomTriggerDistance();
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < this.zoomPoint.getX()))
                    || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
                panel.restoreAutoBounds();
            }
            else {
                double x, y, w, h;
                Rectangle2D screenDataArea = panel.getScreenDataArea(
                        (int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                double maxX = screenDataArea.getMaxX();
                double maxY = screenDataArea.getMaxY();
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            maxX - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                }
                else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.zoomRectangle.getHeight(),
                            maxY - this.zoomPoint.getY());
                }
                else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            maxX - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(),
                            maxY - this.zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                panel.zoom(zoomArea);
            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
            panel.setZoomRectangle(null);
            panel.clearLiveMouseHandler();
        }
        else {
            // erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) panel.getGraphics();
            if (panel.getUseBuffer()) {
                panel.repaint();
            }
            else {
                drawZoomRectangle(panel, g2, true);
            }
            g2.dispose();
            this.zoomPoint = null;
            this.zoomRectangle = null;
            panel.setZoomRectangle(null);
            panel.clearLiveMouseHandler();
        }
    }