Example usage for javax.swing JComponent getBounds

List of usage examples for javax.swing JComponent getBounds

Introduction

In this page you can find the example usage for javax.swing JComponent getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Gets the bounds of this component in the form of a Rectangle object.

Usage

From source file:ucar.unidata.idv.flythrough.ChartDecorator.java

/**
 * _more_//w  w  w  .j  ava  2s.  c om
 *
 * @param g2 _more_
 * @param comp _more_
 *
 * @return _more_
 */
public boolean paintDashboard(Graphics2D g2, JComponent comp) {
    try {
        List<SampleInfo> infos = new ArrayList<SampleInfo>(sampleInfos);
        if (infos.size() == 0) {
            return false;
        }
        Rectangle b = comp.getBounds();
        JFrame dummyFrame = new JFrame("");
        XYSeriesCollection dataset = new XYSeriesCollection();
        JFreeChart chart = Flythrough.createChart(dataset);
        XYPlot xyPlot = (XYPlot) chart.getPlot();

        int chartHeight = b.height - flythrough.getDashboardImage().getHeight(null);
        chartHeight = Math.max(chartHeight, 50);
        int chartWidth = Math.min(chartHeight * 4, b.width);

        int dx = b.width / 2 - chartWidth / 2;
        int dy = 0;

        Image lastImage = lastChartImage;
        if ((lastImage != null) && (lastImage.getWidth(null) == chartWidth)
                && (lastImage.getHeight(null) == chartHeight)) {
            g2.translate(dx, dy);
            g2.drawImage(lastImage, 0, 0, null);
            g2.translate(-dx, -dy);
            return false;
        }

        for (int i = 0; i < infos.size(); i++) {
            SampleInfo info = infos.get(i);
            ValueAxis rangeAxis = new NumberAxis(info.getName());
            if (info.getRange() != null) {
                rangeAxis
                        .setRange(new org.jfree.data.Range(info.getRange().getMin(), info.getRange().getMax()));
            }
            dataset = new XYSeriesCollection();
            dataset.addSeries(info.getSeries());
            xyPlot.setRangeAxis(i, rangeAxis, false);
            xyPlot.setDataset(i, dataset);
            xyPlot.mapDatasetToRangeAxis(i, i);
            final Color color = COLORS[i % COLORS.length];
            XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
                public Paint xgetItemPaint(final int row, final int column) {
                    return color;
                }
            };
            renderer.setSeriesPaint(0, color);
            xyPlot.setRenderer(i, renderer);
        }

        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(chartWidth, chartHeight));
        dummyFrame.setContentPane(chartPanel);
        dummyFrame.pack();
        Image image = ImageUtils.getImage(chartPanel);
        lastChartImage = image;
        g2.translate(dx, dy);
        g2.drawImage(image, 0, 0, null);
        g2.translate(-dx, -dy);
    } catch (Exception exc) {
        logException("Painting chart", exc);

    }

    return false;

}

From source file:ca.phon.ipamap.IpaMap.java

public void onGoto(PhonActionEvent pae) {
    JComponent comp = (JComponent) pae.getData();
    scrollPane.getViewport().setViewPosition(new Point(comp.getBounds().x, comp.getBounds().y));
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** Centers the image when the user maximized the viewer. */
void maximizeWindow() {
    JComponent c = model.getBrowser().getUI();
    c.setBounds(c.getBounds());
}