Example usage for org.jfree.chart ChartPanel getInsets

List of usage examples for org.jfree.chart ChartPanel getInsets

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel getInsets.

Prototype

@BeanProperty(expert = true)
public Insets getInsets() 

Source Link

Document

If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.

Usage

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param chartPanel//from w w  w.ja  v  a 2s  . co m
 * @param x1
 * @param y1
 * @return
 */
public static AffineTransform getModelToViewTransformXY(ChartPanel chartPanel, double x1, double y1) {
    double zoomX = chartPanel.getScaleX();
    double zoomY = chartPanel.getScaleY();
    Insets insets = chartPanel.getInsets();
    AffineTransform at = getTranslateInstance(insets.left, insets.top);
    at.concatenate(getScaleInstance(zoomX, zoomY));
    Plot plot = chartPanel.getChart().getPlot();
    if (plot instanceof XYPlot) {
        XYPlot xyp = (XYPlot) plot;
        RectangleEdge xAxisLocation = xyp.getDomainAxisEdge();
        RectangleEdge yAxisLocation = xyp.getRangeAxisEdge();
        PlotOrientation orientation = xyp.getOrientation();
        Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        double transX = xyp.getDomainAxis().valueToJava2D(x1, dataArea, xAxisLocation);
        double transY = xyp.getRangeAxis().valueToJava2D(y1, dataArea, yAxisLocation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            double tmp = transX;
            transX = transY;
            transY = tmp;
        }
        at.concatenate(getTranslateInstance(transX, transY));
        return at;
    }
    throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass());
}

From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java

/**
 *
 * @param chartPanel//from   w  w w  . ja va 2 s.  c  om
 * @param category
 * @param y
 * @return
 */
public static AffineTransform getModelToViewTransformCategory(ChartPanel chartPanel, int category, double y) {
    double zoomX = chartPanel.getScaleX();
    double zoomY = chartPanel.getScaleY();
    Insets insets = chartPanel.getInsets();
    AffineTransform at = getTranslateInstance(insets.left, insets.top);
    at.concatenate(getScaleInstance(zoomX, zoomY));
    Plot plot = chartPanel.getChart().getPlot();
    if (plot instanceof CategoryPlot) {
        CategoryPlot xyp = (CategoryPlot) plot;
        CategoryDataset cds = xyp.getDataset();
        RectangleEdge xAxisLocation = xyp.getDomainAxisEdge();
        RectangleEdge yAxisLocation = xyp.getRangeAxisEdge();
        PlotOrientation orientation = xyp.getOrientation();
        Comparable<?> categoryKey = cds.getColumnKey(category);
        Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
        double transX = xyp.getDomainAxis().getCategoryMiddle(categoryKey, cds.getColumnKeys(), dataArea,
                xAxisLocation);
        double transY = xyp.getRangeAxis().valueToJava2D(y, dataArea, yAxisLocation);
        if (orientation == PlotOrientation.HORIZONTAL) {
            double tmp = transX;
            transX = transY;
            transY = tmp;
        }
        at.concatenate(getTranslateInstance(transX, transY));
        return at;
    }
    throw new IllegalArgumentException("Unsupported plot type: " + plot.getClass());
}

From source file:ec.util.chart.swing.Charts.java

public static void copyChart(@Nonnull ChartPanel chartPanel) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = chartPanel.getInsets();
    int w = chartPanel.getWidth() - insets.left - insets.right;
    int h = chartPanel.getHeight() - insets.top - insets.bottom;
    Transferable selection = new ChartTransferable2(chartPanel.getChart(), w, h,
            chartPanel.getMinimumDrawWidth(), chartPanel.getMinimumDrawHeight(),
            chartPanel.getMaximumDrawWidth(), chartPanel.getMaximumDrawHeight(), true);
    clipboard.setContents(selection, null);
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * //from  w ww.j a  va2s .  com
 * @param chart
 * @param mx mouse coordinates
 * @param my mouse coordinates
 * @return
 */
public static ChartEntity findChartEntity(ChartPanel chart, double mx, double my) {
    // TODO check if insets were needed
    // coordinates to find chart entities
    Insets insets = chart.getInsets();
    int x = (int) ((mx - insets.left) / chart.getScaleX());
    int y = (int) ((my - insets.top) / chart.getScaleY());

    ChartRenderingInfo info = chart.getChartRenderingInfo();
    ChartEntity entity = null;
    if (info != null) {
        EntityCollection entities = info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }
    return entity;
}

From source file:net.sf.mzmine.chartbasics.gui.swing.ChartGestureMouseAdapter.java

/**
 * Find chartentities like JFreeChartEntity, AxisEntity, PlotEntity, TitleEntity, XY...
 * /*from  www  . ja v  a  2 s .  c o  m*/
 * @param chartPanel
 * @param x
 * @param y
 * @return
 */
private ChartEntity findChartEntity(ChartPanel chartPanel, MouseEvent e) {
    // coordinates to find chart entities
    Insets insets = chartPanel.getInsets();
    int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX());
    int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY());

    if (lastEntity != null && x == lastEntityX && y == lastEntityY)
        return lastEntity;
    else {
        ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
        ChartEntity entity = null;
        if (info != null) {
            EntityCollection entities = info.getEntityCollection();
            if (entities != null) {
                entity = entities.getEntity(x, y);
            }
        }
        return entity;
    }
}