List of usage examples for org.jfree.chart.plot PlotRenderingInfo getDataArea
public Rectangle2D getDataArea()
From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java
/** * Multiplies the range on the range axis by the specified factor. * * @param factor the zoom factor./*from w w w .j av a2 s. co m*/ * @param info the plot rendering info. * @param source the source point (in Java2D space). * @param useAnchor use source point as zoom anchor? * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { if (useAnchor) { // get the source coordinate - this plot has always a VERTICAL // orientation double sourceY = source.getY(); double anchorY = this.rangeAxis.java2DToValue(sourceY, info.getDataArea(), RectangleEdge.LEFT); this.rangeAxis.resizeRange2(factor, anchorY); } else { this.rangeAxis.resizeRange(factor); } }
From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java
/** * Multiplies the range on the domain axis by the specified factor. * * @param factor the zoom factor./* w w w . j a v a 2s.c o m*/ * @param info the plot rendering info. * @param source the source point (in Java2D space). * @param useAnchor use source point as zoom anchor? * * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { if (useAnchor) { // get the source coordinate - this plot has always a VERTICAL // orientation double sourceX = source.getX(); double anchorX = this.domainAxis.java2DToValue(sourceX, info.getDataArea(), RectangleEdge.BOTTOM); this.domainAxis.resizeRange2(factor, anchorX); } else { this.domainAxis.resizeRange(factor); } }
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 ww. j av a 2 s.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(); }
From source file:ucar.unidata.idv.control.chart.MyXYPlot.java
/** * Handles a 'click' on the plot by updating the anchor values... * * @param x the x-coordinate, where the click occurred, in Java2D space. * @param y the y-coordinate, where the click occurred, in Java2D space. * @param info object containing information about the plot dimensions. *///w w w . j a v a2 s. co m public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { // set the anchor value for the horizontal axis... ValueAxis da = getDomainAxis(); if (da != null) { double hvalue = da.java2DToValue(x, info.getDataArea(), getDomainAxisEdge()); setDomainCrosshairValue(hvalue); } // set the anchor value for the vertical axis... ValueAxis ra = getRangeAxis(); if (ra != null) { double vvalue = ra.java2DToValue(y, info.getDataArea(), getRangeAxisEdge()); setRangeCrosshairValue(vvalue); } } }