List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
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// w w w .j a v a 2 s .co m * @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:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
public void selectRectangle(Rectangle2D selection, MouseEvent selectionEvent) { Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY()); if (selection.getHeight() > 0 && selection.getWidth() > 0) { double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth(); double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight(); double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight(); Plot p = this.chart.getPlot(); if (p instanceof XYPlot) { XYPlot plot = (XYPlot) p;/*from w w w . j a v a 2s . c om*/ Selection selectionObject = new Selection(); for (int i = 0; i < plot.getDomainAxisCount(); i++) { ValueAxis domain = plot.getDomainAxis(i); double lowerDomain = domain.getLowerBound(); double upperDomain = domain.getUpperBound(); Range axisRange = new Range(lowerDomain + (upperDomain - lowerDomain) * hLower, lowerDomain + (upperDomain - lowerDomain) * hUpper); for (String axisName : axisNameResolver.resolveXAxis(i)) { selectionObject.addDelimiter(axisName, axisRange); } } for (int i = 0; i < plot.getRangeAxisCount(); i++) { ValueAxis range = plot.getRangeAxis(i); double lowerRange = range.getLowerBound(); double upperRange = range.getUpperBound(); Range axisRange = new Range(lowerRange + (upperRange - lowerRange) * vLower, lowerRange + (upperRange - lowerRange) * vUpper); for (String axisName : axisNameResolver.resolveYAxis(i)) { selectionObject.addDelimiter(axisName, axisRange); } } informSelectionListener(selectionObject, selectionEvent); } } }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Applies any scaling that is in effect for the chart drawing to the given rectangle. * /*w w w . j a v a 2 s . co m*/ * @param rect * the rectangle (<code>null</code> not permitted). * * @return A new scaled rectangle. */ @Override public Rectangle2D scale(Rectangle2D rect) { Insets insets = getInsets(); double x = rect.getX() * getScaleX() + insets.left; double y = rect.getY() * getScaleY() + insets.top; double w = rect.getWidth() * getScaleX(); double h = rect.getHeight() * getScaleY(); return new Rectangle2D.Double(x, y, w, h); }
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer).//from w ww . j a va 2 s . co m * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); if (info != null) { info.setPlotArea(area); info.setDataArea(area); } drawBackground(g2, area); //drawOutline(g2, area); Shape savedClip = g2.getClip(); g2.clip(area); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { int seriesCount = 0, catCount = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { seriesCount = this.dataset.getRowCount(); catCount = this.dataset.getColumnCount(); } else { seriesCount = this.dataset.getColumnCount(); catCount = this.dataset.getRowCount(); } // ensure we have a maximum value to use on the axes if (this.maxValue == DEFAULT_MAX_VALUE) calculateMaxValue(seriesCount, catCount); // Next, setup the plot area // adjust the plot area by the interior spacing value double gapHorizontal = area.getWidth() * getInteriorGap(); double gapVertical = area.getHeight() * getInteriorGap(); double X = area.getX() + gapHorizontal / 2; double Y = area.getY() + gapVertical / 2; double W = area.getWidth() - gapHorizontal; double H = area.getHeight() - gapVertical; double headW = area.getWidth() * this.headPercent; double headH = area.getHeight() * this.headPercent; // make the chart area a square double min = Math.min(W, H) / 2; X = (X + X + W) / 2 - min; Y = (Y + Y + H) / 2 - min; W = 2 * min; H = 2 * min; Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2); Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H); // draw the axis and category label for (int cat = 0; cat < catCount; cat++) { double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3)); Point2D endPoint = getWebPoint(radarArea, angle, 1); // 1 = end of axis Line2D line = new Line2D.Double(centre, endPoint); g2.setPaint(this.axisLinePaint); g2.setStroke(this.axisLineStroke); g2.draw(line); drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / (catCount > 2 ? catCount : 3)); } // Now actually plot each of the series polygons.. for (int series = 0; series < seriesCount; series++) { drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW); } } else { drawNoDataMessage(g2, area); } g2.setClip(savedClip); g2.setComposite(originalComposite); //drawOutline(g2, area); }
From source file:knop.psfj.BeadImage.java
/** * Gets the bead preview./* ww w. ja va 2 s. c o m*/ * * @param trials the trials * @return the bead preview */ public ImageProcessor getBeadPreview(int trials) { if (trials == 0) { return null; } if (preview == null) { try { System.out.println("generating new preview"); preview = getMiddleImage(); if (preview == null) { return new ShortProcessor(previewWidth, previewHeight); } preview = preview.convertToRGB(); for (BeadFrame frame : getBeadFrameList()) { Rectangle2D r = frame.getBoundaries(); if (frame.isValid() == true) { preview.setColor(Color.green); } else { preview.setColor(Color.yellow); } if (frame.isValid() == false) { r = getEnlargedFrame((Rectangle) r, MathUtils.round(r.getWidth() / 2)); } preview.drawRect(round(r.getX()), round(r.getY()), round(r.getWidth()), round(r.getHeight())); if (frame.getId() == null) { continue; } } status = "Done."; progress = 100; notifyObservers(MSG_PREVIEW_UPDATED, "Done.", 100, null); } catch (Exception e) { trials--; getBeadPreview(trials); } } return preview; }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Handles a 'mouse dragged' event./* w w w . j a v a 2 s . c om*/ * * @param e * the mouse event. */ public void mouseDragged(MouseEvent e) { // if the popup menu has already been triggered, then ignore dragging... if (this.popup != null && this.popup.isShowing()) { return; } // if no initial zoom point was set, ignore dragging... if (this.zoomPoint == null) { return; } Graphics2D g2 = (Graphics2D) getGraphics(); // Erase the previous zoom rectangle (if any)... drawZoomRectangle(g2); boolean hZoom = false; boolean vZoom = false; if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } Rectangle2D scaledDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY()); if (hZoom && vZoom) { // selected rectangle shouldn't extend outside the data area... double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(), xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY()); } else if (hZoom) { double xmax = Math.min(e.getX(), scaledDataArea.getMaxX()); this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(), xmax - this.zoomPoint.getX(), scaledDataArea.getHeight()); } else if (vZoom) { double ymax = Math.min(e.getY(), scaledDataArea.getMaxY()); this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(), scaledDataArea.getWidth(), ymax - this.zoomPoint.getY()); } // Draw the new zoom rectangle... drawZoomRectangle(g2); g2.dispose(); }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Handles a 'mouse pressed' event./*ww w. java2s . c o m*/ * <P> * This event is the popup trigger on Unix/Linux. For Windows, the popup trigger is the 'mouse * released' event. * * @param e * The mouse event. */ @Override public void mousePressed(MouseEvent e) { if (this.chart == null) { return; } Plot plot = this.chart.getPlot(); int mods = e.getModifiers(); if ((mods & this.panMask) == this.panMask) { // can we pan this plot? if (plot instanceof Pannable) { Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY()); if (screenDataArea != null && screenDataArea.contains(e.getPoint())) { this.panW = screenDataArea.getWidth(); this.panH = screenDataArea.getHeight(); this.panLast = e.getPoint(); setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } } } else if (this.selectionRectangle == null) { Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY()); if (screenDataArea != null) { this.zoomPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea); } else { this.zoomPoint = null; } if (e.isPopupTrigger()) { if (this.popup != null) { displayPopupMenu(e.getX(), e.getY()); } } } }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Returns the data area for the chart (the area inside the axes) with the current scaling * applied (that is, the area as it appears on screen). * //from www. j a v a 2s . co m * @return The scaled data area. */ @Override public Rectangle2D getScreenDataArea() { Rectangle2D dataArea = this.info.getPlotInfo().getDataArea(); Insets insets = getInsets(); double x = dataArea.getX() * this.scaleX + insets.left; double y = dataArea.getY() * this.scaleY + insets.top; double w = dataArea.getWidth() * this.scaleX; double h = dataArea.getHeight() * this.scaleY; return new Rectangle2D.Double(x, y, w, h); }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, but allowing for the * insets (which will be non-zero if a border has been set for this component). To increase * performance (at the expense of memory), an off-screen buffer image can be used. * /*w w w .j av a 2s.c o m*/ * @param g * the graphics device for drawing on. */ @Override public void paintComponent(Graphics g) { if (this.chart == null) { return; } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); this.scaleX = 1.0; this.scaleY = 1.0; if (drawWidth < this.minimumDrawWidth) { this.scaleX = drawWidth / this.minimumDrawWidth; drawWidth = this.minimumDrawWidth; scale = true; } else if (drawWidth > this.maximumDrawWidth) { this.scaleX = drawWidth / this.maximumDrawWidth; drawWidth = this.maximumDrawWidth; scale = true; } if (drawHeight < this.minimumDrawHeight) { this.scaleY = drawHeight / this.minimumDrawHeight; drawHeight = this.minimumDrawHeight; scale = true; } else if (drawHeight > this.maximumDrawHeight) { this.scaleY = drawHeight / this.maximumDrawHeight; drawHeight = this.maximumDrawHeight; scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // redrawing the chart every time... AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY); g2.transform(st); } this.chart.draw(g2, chartArea, this.anchor, this.info); g2.setTransform(saved); Iterator<Overlay> iterator = this.overlays.iterator(); while (iterator.hasNext()) { Overlay overlay = iterator.next(); overlay.paintOverlay(g2, this); } // redraw the zoom rectangle (if present) - if useBuffer is false, // we use XOR so we can XOR the rectangle away again without redrawing // the chart drawSelectionRectangle(g2); g2.dispose(); this.anchor = null; this.verticalTraceLine = null; this.horizontalTraceLine = null; }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Handles a 'mouse released' event. On Windows, we need to check if this * is a popup trigger, but only if we haven't already been tracking a zoom * rectangle./* www . j a va2s . c o m*/ * * @param e information about the event. */ public void mouseReleased(MouseEvent e) { if (this.zoomRectangle != null) { boolean hZoom = false; boolean vZoom = false; if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance; boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance; if (zoomTrigger1 || zoomTrigger2) { if ((hZoom && (e.getX() < this.zoomPoint.getX())) || (vZoom && (e.getY() < this.zoomPoint.getY()))) { // restore the the range for the domain and range axis from // the history Plot p = this.chart.getPlot(); if (p instanceof XYPlot && !rangeHistory.empty()) { XYPlot xyPlot = (XYPlot) p; ValueAxis rangeAxis = xyPlot.getRangeAxis(); ValueAxis domainAxis = xyPlot.getDomainAxis(); if (rangeAxis.getRange().equals(rangeHistory.pop()) && domainAxis.getRange().equals(rangeHistory.pop())) { xyPlot.getRangeAxis().setRange(rangeHistory.pop()); xyPlot.getDomainAxis().setRange(rangeHistory.pop()); if (!rangeHistory.empty()) { rangeHistory.push(domainAxis.getRange()); rangeHistory.push(rangeAxis.getRange()); } } else { rangeHistory.clear(); restoreAutoBounds(); } } else { restoreAutoBounds(); } } else { double x, y, w, h; Rectangle2D screenDataArea = 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); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { // Erase the zoom rectangle Graphics2D g2 = (Graphics2D) getGraphics(); drawZoomRectangle(g2); g2.dispose(); this.zoomPoint = null; this.zoomRectangle = null; } } else if (e.isPopupTrigger()) { if (this.popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }