Example usage for org.jfree.chart.plot PlotRenderingInfo getPlotArea

List of usage examples for org.jfree.chart.plot PlotRenderingInfo getPlotArea

Introduction

In this page you can find the example usage for org.jfree.chart.plot PlotRenderingInfo getPlotArea.

Prototype

public Rectangle2D getPlotArea() 

Source Link

Document

Returns the plot area (in Java2D space).

Usage

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

private void configureGradientAreaFill(Graphics2D g2, CategoryPlot plot, Paint itemPaint,
        PlotRenderingInfo info, GradientLineAreaFill gradientLineAreaFill) {
    double plotWidth = info.getPlotArea().getWidth();
    double plotHeight = info.getPlotArea().getHeight();
    Double mainColorTransparency = gradientLineAreaFill.getMaxValueTransparency();
    Double bgColorTransparency = gradientLineAreaFill.getMinValueTransparency();

    if (itemPaint instanceof Color) {
        Color itemColor = (Color) itemPaint;
        int red = itemColor.getRed();
        int green = itemColor.getGreen();
        int blue = itemColor.getBlue();
        int mainColorAlpha = (mainColorTransparency >= 0.0 && mainColorTransparency <= 1.0)
                ? Math.round(255 * mainColorTransparency.floatValue())
                : 150;/*from   w w  w. j  a  v  a  2  s.  c  o  m*/
        int bgColorAlpha = (bgColorTransparency >= 0.0 && bgColorTransparency <= 1.0)
                ? Math.round(255 * bgColorTransparency.floatValue())
                : 128;

        Color mainColor = new Color(red, green, blue, mainColorAlpha);
        Paint bgColor = getBackgroundPaint();
        if (bgColor == null) {
            bgColor = plot.getBackgroundPaint();
        }
        Color secondaryColor = getSecondaryColor(bgColorAlpha, bgColor);
        Paint areaPaint = getAreaFillPaint(plot, plotWidth, plotHeight, mainColor, secondaryColor);

        g2.setPaint(areaPaint);
    } else {
        g2.setPaint(itemPaint);
    }
}

From source file:com.epiq.bitshark.ui.FrequencyDomainPanel.java

/**
 * /*  w  w w .  ja  va 2s .c o  m*/
 * @param point
 */
protected void updateMouseMarker(Point point) {

    double xValue = 0;

    if (!markerLocked) {
        double pointerX = point.getX();

        PlotRenderingInfo renderingInfo = chartPanel.getChartRenderingInfo().getPlotInfo();
        Rectangle2D dataArea = renderingInfo.getDataArea();
        Rectangle2D plotArea = renderingInfo.getPlotArea();
        RectangleEdge domainEdge = plot.getDomainAxisEdge();

        xValue = frequencyAxis.java2DToValue(pointerX, dataArea, domainEdge);

        previousMarkerX = xValue;

    } else {
        xValue = previousMarkerX;
    }

    int bin = (int) Math.round(xValue);

    try {
        XYDataItem item = series.getDataItem(bin);
        if (item != null) {
            double yValue = item.getYValue();
            markerAnnotation.setXY(xValue, yValue);
            markerAnnotation.setVisible(true);

            plot.setDomainCrosshairValue(xValue);
            plot.setDomainCrosshairVisible(true);

            markerTitle.setText("Frequency: " + binToFrequencyStr(bin) + " \nPower: "
                    + String.format("%5.1f", PowerAxis.valueToDb(yValue)) + " dB");

            markerTitle.setVisible(true);
        } else {
            markerAnnotation.setVisible(false);
            plot.setDomainCrosshairVisible(false);
        }
    } catch (Exception e) {
        markerAnnotation.setVisible(false);
        plot.setDomainCrosshairVisible(false);
    }
}

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private void configureGradientAreaFill(Graphics2D g2, XYPlot plot, PlotRenderingInfo info, Paint itemPaint,
        GradientLineAreaFill gradientLineAreaFill) {
    final Rectangle2D plotArea = info.getPlotArea();
    double plotWidth = plotArea.getWidth();
    double plotHeight = plotArea.getHeight();
    Double mainColorTransparency = gradientLineAreaFill.getMaxValueTransparency();
    Double bgColorTransparency = gradientLineAreaFill.getMinValueTransparency();

    if (itemPaint instanceof Color) {
        Color itemColor = (Color) itemPaint;
        int red = itemColor.getRed();
        int green = itemColor.getGreen();
        int blue = itemColor.getBlue();
        int mainColorAlpha = (mainColorTransparency >= 0.0 && mainColorTransparency <= 1.0)
                ? Math.round(255 * mainColorTransparency.floatValue())
                : 150;/*www  .  j  av a2 s  .co  m*/
        int bgColorAlpha = (bgColorTransparency >= 0.0 && bgColorTransparency <= 1.0)
                ? Math.round(255 * bgColorTransparency.floatValue())
                : 128;

        Color mainColor = new Color(red, green, blue, mainColorAlpha);
        Paint bgColor = getBackgroundPaint();
        if (bgColor == null) {
            bgColor = plot.getBackgroundPaint();
        }
        Color secondaryColor = getSecondaryColor(bgColorAlpha, bgColor);

        Paint areaPaint = getAreaFillPaint(plot, plotWidth, plotHeight, mainColor, secondaryColor);
        g2.setPaint(areaPaint);
    } else {
        g2.setPaint(itemPaint);
    }
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIComponent.java

/***********************************************************************************************
 * Create or refresh the Chart on a separate thread.
 * Only create or update if asked to do so via the generate flag.
 *
 * @param dao/*from  w w  w .  java  2s  .c om*/
 * @param generateflag
 * @param message
 */

private synchronized void doRefreshChart(final ObservatoryInstrumentDAOInterface dao,
        final boolean generateflag, final String message) {
    //final String SOURCE = "ChartUIComponent.refreshChart() ";
    final String SOURCE = message;
    final ChartUIComponentPlugin thisUI;
    final boolean boolDebug;

    boolDebug = true;
    //        boolDebug = LOADER_PROPERTIES.isMetadataDebug()
    //                    || LOADER_PROPERTIES.isChartDebug();

    // For use in inner classes
    thisUI = this;

    // Stop any existing SwingWorker
    if ((getHostInstrument() != null) && (dao != null)) {
        LOGGER.debug(boolDebug, SOURCE + "DAO [dao.classname=" + dao.getClass().getName()
                + "] [instrument.name=" + dao.getInstrumentName() + "] [generate.flag=" + generateflag + "]");

        LOGGER.debug(boolDebug, SOURCE + "SwingWorker.controlledStop()");
    }

    SwingWorker.disposeWorker(workerRefresh, true, SWING_WORKER_STOP_DELAY >> 1);

    // Fire off another thread to process the Chart
    workerRefresh = new SwingWorker(REGISTRY.getThreadGroup(), SOURCE + "SwingWorker [group="
            + REGISTRY.getThreadGroup().getName() + "] [thread=" + getChartName() + "]") {
        public Object construct() {
            LOGGER.debug(boolDebug, SOURCE
                    + "SwingWorker START -------------------------------------------------------------------------!");

            // The result of this Thread is a JFreeChart
            // which may have been produced in a long process...
            if ((!isStopping()) && (getHostInstrument() != null)
                    && (getHostInstrument().getInstrumentState().isOn())) {
                try {
                    final JFreeChart chart;
                    final Calendar calObservatory;

                    // Either find the Current Observatory calendar, or provide a default
                    calObservatory = ObservatoryInstrumentHelper
                            .getCurrentObservatoryCalendar(REGISTRY.getFramework(), dao, boolDebug);

                    //-----------------------------------------------------------------------------
                    // Debug the data we are trying to display

                    if (boolDebug) {
                        // Dump the (partial) contents of each Series in the composite XYdataset
                        ChartHelper.dumpXYDataset(boolDebug, calObservatory, getPrimaryXYDataset(), 4, SOURCE
                                + "Original unmodified Primary XYDataset before channel or domain selection");

                        if ((getSecondaryXYDatasets() != null) && (!getSecondaryXYDatasets().isEmpty())) {
                            for (int intDatasetIndex = 0; intDatasetIndex < getSecondaryXYDatasets()
                                    .size(); intDatasetIndex++) {
                                ChartHelper.dumpXYDataset(boolDebug, calObservatory,
                                        getSecondaryXYDatasets().get(intDatasetIndex), 4,
                                        SOURCE + "Original unmodified Secondary XYDataset [" + intDatasetIndex
                                                + "] before channel or domain selection");
                            }
                        } else {
                            LOGGER.debug(boolDebug,
                                    SOURCE + "There are no SecondaryXYDatasets associated with this Chart");
                        }
                    }

                    //-----------------------------------------------------------------------------
                    // Apply a ChartUI and its Metadata to the specified DAO

                    ChartHelper.associateChartUIWithDAO(thisUI, getMetadata(), dao);

                    //-----------------------------------------------------------------------------
                    // Create a new Channel Selector showing the channels of the Primary Dataset

                    if ((getChannelSelectorOccupant() != null)
                            && (getHostInstrument().getInstrumentState().isOn()) && (dao != null)
                            && (generateflag)) {
                        LOGGER.debug(boolDebug,
                                SOURCE + "SwingWorker --> ChannelSelector --> createOrUpdateSelectors()");

                        // The Channel Selector will be empty until an XYDataset is loaded
                        // Note that ChannelCount etc. must be set before calling createOrUpdateSelectors()
                        getChannelSelectorOccupant().setChannelCount(getChannelCount());
                        getChannelSelectorOccupant().setTemperatureChannel(hasTemperatureChannel());
                        getChannelSelectorOccupant().setMetadata(getMetadata());
                        getChannelSelectorOccupant().setUpdateType(getUpdateType());

                        // Force a rebuild of the Channel Selector only if necessary
                        getChannelSelectorOccupant().createOrUpdateSelectors(getDatasetType(),
                                getPrimaryXYDataset(), getSecondaryXYDatasets(), dao.isDatasetTypeChanged(),
                                dao.isChannelCountChanged(), dao.isMetadataChanged(), dao.isRawDataChanged(),
                                dao.isProcessedDataChanged(), isRefreshable(), isClickRefresh(), boolDebug);
                    } else {
                        // This debug ASSUMES the Instrument is not NULL
                        LOGGER.debug(boolDebug, SOURCE + "Unable to configure the Channel Selector UIComponent"
                                + "  [has.channelselector=" + (hasChannelSelector())
                                + "] [channelselector.notnull=" + (getChannelSelectorOccupant() != null)
                                + "] [isselectedinstrument="
                                + ObservatoryUIHelper.isSelectedInstrument(getHostInstrument())
                                + "] [isinstrument.on=" + getHostInstrument().getInstrumentState().isOn()
                                + "] [dao.notnull=" + (dao != null) + "] [generateflag=" + generateflag + "]");
                    }

                    //-----------------------------------------------------------------------------
                    // Force a rebuild of the DatasetDomain Control only if necessary

                    if ((hasDatasetDomainControl()) && (getDatasetDomainControlOccupant() != null)
                            && (getHostInstrument().getInstrumentState().isOn()) && (dao != null)
                            && (generateflag)) {
                        LOGGER.debug(boolDebug, SOURCE
                                + "SwingWorker --> DatasetDomainControl --> createOrUpdateDomainControl()");

                        // Note that ChannelCount etc. must be set before calling createOrUpdateDomainControl()
                        getDatasetDomainControlOccupant().setRawDataChannelCount(getChannelCount());
                        getDatasetDomainControlOccupant().setTemperatureChannel(hasTemperatureChannel());
                        getDatasetDomainControlOccupant().setMetadata(getMetadata());
                        getDatasetDomainControlOccupant().setUpdateType(getUpdateType());

                        getDatasetDomainControlOccupant().createOrUpdateDomainControl(getDatasetType(),
                                getPrimaryXYDataset(), getSecondaryXYDatasets(), dao.isDatasetTypeChanged(),
                                dao.isChannelCountChanged(), dao.isMetadataChanged(), dao.isRawDataChanged(),
                                dao.isProcessedDataChanged(), isRefreshable(), isClickRefresh(), boolDebug);
                    } else {
                        // This debug ASSUMES the Instrument is not NULL
                        LOGGER.debug(boolDebug, SOURCE
                                + "Unable to configure the DatasetDomainControl UIComponent"
                                + "  [has.domaincontrol=" + (hasDatasetDomainControl())
                                + "] [domaincontrol.notnull=" + (getDatasetDomainControlOccupant() != null)
                                + "] [isselectedinstrument="
                                + ObservatoryUIHelper.isSelectedInstrument(getHostInstrument())
                                + "] [isinstrument.on=" + getHostInstrument().getInstrumentState().isOn()
                                + "] [dao.notnull=" + (dao != null) + "] [generateflag=" + generateflag + "]");
                    }

                    // Do this anyway, because it doesn't affect the UI
                    updateSliderLocalValues();

                    //-----------------------------------------------------------------------------
                    // If the Chart does not exist, create it
                    // If the Chart structure has changed, recreate it using the new configuration
                    // If only the data have changed, update the existing JFreeChart
                    // and return NULL here, to avoid redrawing

                    LOGGER.debug(boolDebug, SOURCE + "SwingWorker --> createOrUpdateChart()");

                    // Use the Observatory ResourceKey
                    setDisplayLimit(
                            REGISTRY.getIntegerProperty(getHostInstrument().getHostAtom().getResourceKey()
                                    + ResourceKeys.KEY_DISPLAY_DATA_MAX));

                    // Only create or update if asked to do so
                    // This is the last step, so can reset the DAO changed status flags
                    chart = ChartHelper.createOrUpdateChart(getHostInstrument(), thisUI, dao, generateflag,
                            getDatasetType(), getPrimaryXYDataset(), getSecondaryXYDatasets(), getUpdateType(),
                            isRefreshable(), isClickRefresh(), getDisplayLimit(), getDatasetDomainStartPoint(),
                            getDatasetDomainEndPoint(), getChannelSelectorOccupant(), boolDebug);
                    return (chart);
                }

                catch (final Exception exception) {
                    LOGGER.debug(boolDebug, SOURCE + "SwingWorker Thread GENERIC EXCEPTION");
                    exception.printStackTrace();
                    return null;
                }
            } else {
                LOGGER.debug(boolDebug,
                        SOURCE + "SwingWorker Thread stopping, or the Instrument has been turned OFF...");
                return (null);
            }
        }

        // Return a JFreeChart or NULL, depending on the outcome of createOrUpdateChart()
        // If NULL, don't affect the ChartPanel contents
        public void finished() {
            MetadataHelper.showMetadataList(getMetadata(), SOURCE + "Chart Metadata on arrival at finished()",
                    boolDebug);

            // Update the Chart on the Event Dispatching Thread
            // Check thoroughly that there is some point to this update...
            if ((workerRefresh != null) && (workerRefresh.get() != null)
                    && (workerRefresh.get() instanceof JFreeChart) && (SwingUtilities.isEventDispatchThread())
                    && (!isStopping()) && (getHostInstrument() != null)
                    && (getHostInstrument().getInstrumentState().isOn())) {
                // See if we already have a ChartPanel to hold the new JFreeChart
                if (getChartPanel() != null) {
                    LOGGER.debug(boolDebug, SOURCE
                            + "finished() Apply the JFreeChart returned by get() to exisiting ChartPanel");

                    getChartPanel().setChart((JFreeChart) workerRefresh.get());
                } else {
                    // There is NO ChartPanel, so start again from scratch
                    LOGGER.debug(boolDebug, SOURCE
                            + "finished() Create a NEW ChartPanel and apply the JFreeChart returned by get()");

                    setChartPanel(ChartPanelFactory.createChartPanel((JFreeChart) workerRefresh.get()));
                }

                // NOTE: Chart applied to the specified DAO which was passed as a parameter
                LOGGER.debug(boolDebug, SOURCE + "finished() returned JFreeChart on a ChartPanel");

                getChartContainer().removeAll();
                getChartContainer().add(getChartPanel(), BorderLayout.CENTER);
                getChartPanel().getChart().fireChartChanged();
                getChartContainer().revalidate();
            } else {
                // We failed to return a JFreeChart for some reason

                if (getPrimaryXYDataset() == null) {
                    LOGGER.debug(boolDebug, SOURCE
                            + "finished() No JFreeChart returned, Dataset is NULL, show BlankUIComponent");

                    // Getting here with a NULL dataset should mean no Chart!
                    // ChartContainer is always NOT NULL
                    getChartContainer().removeAll();
                    getChartContainer().add(
                            new BlankUIComponent(MSG_WAITING_FOR_DATA, DEFAULT_COLOUR_CANVAS, COLOUR_INFO_TEXT),
                            BorderLayout.CENTER);
                    getChartContainer().revalidate();

                    // ToDo Consider setting DAO Chart and ChartPanel Chart to NULL?
                    //SOURCE + "finished() No JFreeChart returned, Dataset is NULL, set Chart to NULL if possible");

                    //                        if (getChartPanel() != null)
                    //                            {
                    //                            getChartPanel().setChart(null);
                    //                            }
                } else {
                    // We have some data, if we also have a Chart, just display it again
                    if ((getChartPanel() != null) && (getChartPanel().getChart() != null)) {
                        LOGGER.debug(boolDebug, SOURCE
                                + "finished() No JFreeChart returned, Dataset is NOT NULL, redraw data on existing ChartPanel");

                        getChartContainer().removeAll();
                        getChartContainer().add(getChartPanel(), BorderLayout.CENTER);
                        getChartPanel().getChart().fireChartChanged();
                        getChartContainer().revalidate();
                    } else {
                        LOGGER.error(SOURCE
                                + "finished() No JFreeChart returned, Dataset is NOT NULL, but no Chart for display, no action taken");
                    }
                }
            }

            // Handle the DatasetDomainControl

            if ((getChartPanel() != null) && (hasDatasetDomainControl())
                    && (getDatasetDomainControlOccupant() != null)
                    && (getDatasetDomainControlOccupant().getDatasetDomainContainer() != null)) {
                final ChartRenderingInfo infoChart;
                final PlotRenderingInfo infoPlot;
                final Rectangle2D rectPlot;
                final Rectangle2D rectData;

                infoChart = getChartPanel().getChartRenderingInfo();
                infoPlot = infoChart.getPlotInfo();
                rectPlot = infoPlot.getPlotArea();
                rectData = infoPlot.getDataArea();

                // Trap the cases where the Plot hasn't been rendered, or there's nothing to lay out,
                // in which cases use the default sizes
                if ((rectPlot != null) && (rectData != null) && ((int) rectData.getWidth() > 0)
                        && ((int) rectData.getHeight() > 0) && ((int) rectData.getX() > 0)
                        && ((int) rectData.getY() > 0)) {
                    int intLeft;
                    int intRight;

                    // Try to get the slider to align with the extents of the data area
                    // Ideally this should happen also after WindowResizing events
                    intLeft = (int) rectData.getX();
                    intRight = (int) (getChartPanel().getWidth() - rectData.getWidth() - rectData.getX());

                    LOGGER.debug(boolDebug,
                            "DatasetDomainControl -- PANEL, PLOT & DATA AREAS" + "  [panel.width="
                                    + getChartPanel().getWidth() + "] [panel.height="
                                    + getChartPanel().getHeight() + "] [plot.width=" + rectPlot.getWidth()
                                    + "] [plot.height=" + rectPlot.getHeight() + "] [plot.x=" + rectPlot.getX()
                                    + "] [plot.y=" + rectPlot.getY() + "] [data.width=" + rectData.getWidth()
                                    + "] [data.height=" + rectData.getHeight() + "] [data.x=" + rectData.getX()
                                    + "] [data.y=" + rectData.getY() + "] [indent.left=" + intLeft
                                    + "] [indent.right=" + intRight + "]");

                    if (intLeft < 0) {
                        intLeft = 0;
                    }

                    if (intRight < 0) {
                        intRight = 0;
                    }

                    if ((intLeft + rectData.getWidth() + intRight) > getChartPanel().getWidth()) {
                        intRight = 5;
                    }

                    getDatasetDomainControlOccupant().getDatasetDomainContainer()
                            .setBorder(BorderFactory.createEmptyBorder(0, intLeft, 5, intRight));
                } else {
                    getDatasetDomainControlOccupant().getDatasetDomainContainer()
                            .setBorder(BorderFactory.createEmptyBorder(0, INDENT_LEFT, 5, INDENT_RIGHT));
                }

                // Layout the Domain slider control again
                getDatasetDomainControlOccupant().getDatasetDomainContainer().revalidate();
            }

            LOGGER.debug(boolDebug, SOURCE
                    + "SwingWorker.finished() STOP ---------------------------------------------------------------!\n");
        }
    };

    // Start the Thread we have prepared...
    workerRefresh.start();
}