List of usage examples for java.awt.geom Rectangle2D getMaxX
public double getMaxX()
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void mouseDragged(MouseEvent e) { if (mouse_start_point != null && theDocument.getNoScans() > 0) { if (is_moving) { // moving double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX()); if (mz_delta > 0.) { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getPeakDataAt(current_ind).getMaxMZ()); double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getPeakDataAt(current_ind).getMinMZ()); double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); }//from w ww. ja v a 2 s . c o m mouse_start_point = e.getPoint(); } else { // zooming Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics(); g2.setXORMode(java.awt.Color.gray); // delete old rectangle if (zoom_rectangle != null) g2.draw(zoom_rectangle); // create new rectangle double start_x = Math.min(e.getX(), mouse_start_point.getX()); double end_x = Math.max(e.getX(), mouse_start_point.getX()); Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x, (int) mouse_start_point.getY()); double xmax = Math.min(end_x, data_area.getMaxX()); zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x, data_area.getHeight()); // draw new rectangle g2.draw(zoom_rectangle); g2.dispose(); } } }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void mousePressed(MouseEvent e) { super.mousePressed(e); Rectangle2D origArea = this.getScreenDataArea(); Plot plot = chart.getPlot();/*from w w w . j a va 2 s.com*/ if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = chart.getXYPlot(); String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel(); if (SwingUtilities.isRightMouseButton(e)) { return; } for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) { if (panel != this) { Plot otherPlot = panel.getChart().getPlot(); if (!(otherPlot instanceof XYPlot)) { continue; } Rectangle2D otherArea = panel.getScreenDataArea(); XYPlot otherXYPlot = panel.getChart().getXYPlot(); String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel(); if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) { double origRangeX = origArea.getMaxX() - origArea.getMinX(); double origRangeY = origArea.getMaxY() - origArea.getMinY(); double otherRangeX = otherArea.getMaxX() - otherArea.getMinX(); double otherRangeY = otherArea.getMaxY() - otherArea.getMinY(); double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX; double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY; MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false); panel.syncMousePressed(syncEvent); } } } }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void mouseDragged(MouseEvent e) { super.mouseDragged(e); Rectangle2D origArea = this.getScreenDataArea(); Plot plot = chart.getPlot();/*from w ww . j a va 2s . c om*/ if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = chart.getXYPlot(); String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel(); if (SwingUtilities.isRightMouseButton(e)) { return; } for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) { if (panel != this) { Plot otherPlot = panel.getChart().getPlot(); if (!(otherPlot instanceof XYPlot)) { continue; } Rectangle2D otherArea = panel.getScreenDataArea(); XYPlot otherXYPlot = panel.getChart().getXYPlot(); String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel(); if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) { double origRangeX = origArea.getMaxX() - origArea.getMinX(); double origRangeY = origArea.getMaxY() - origArea.getMinY(); double otherRangeX = otherArea.getMaxX() - otherArea.getMinX(); double otherRangeY = otherArea.getMaxY() - otherArea.getMinY(); double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX; double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY; MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false); panel.syncMouseDragged(syncEvent); } } } }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Rectangle2D origArea = this.getScreenDataArea(); Plot plot = chart.getPlot();/* w w w. j ava 2s . c o m*/ if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = chart.getXYPlot(); String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel(); if (SwingUtilities.isRightMouseButton(e)) { return; } for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) { if (panel != this) { Plot otherPlot = panel.getChart().getPlot(); if (!(otherPlot instanceof XYPlot)) { continue; } Rectangle2D otherArea = panel.getScreenDataArea(); XYPlot otherXYPlot = panel.getChart().getXYPlot(); String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel(); if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) { double origRangeX = origArea.getMaxX() - origArea.getMinX(); double origRangeY = origArea.getMaxY() - origArea.getMinY(); double otherRangeX = otherArea.getMaxX() - otherArea.getMinX(); double otherRangeY = otherArea.getMaxY() - otherArea.getMinY(); double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX; double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY; MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false); panel.syncMouseReleased(syncEvent); } } } }
From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.panel.Chromatogram2DViewerPanel.java
public void setViewport(Rectangle2D rect) { //ignore viewport changes if we have the focus if (hasFocus()) { Logger.getLogger(getClass().getName()).info("Ignoring viewport update since we have the focus!"); } else {// www. ja v a2s . com //otherwise, clear our own viewport and set to new value if (this.viewport != null) { this.content.remove(this.viewport); } this.viewport = new Chromatogram2DViewViewport(rect); Logger.getLogger(getClass().getName()).info("Setting viewport!"); removeAxisListener(); this.chartPanel.getChart().getXYPlot().getDomainAxis().setLowerBound(rect.getMinX()); this.chartPanel.getChart().getXYPlot().getDomainAxis().setUpperBound(rect.getMaxX()); this.chartPanel.getChart().getXYPlot().getRangeAxis().setLowerBound(rect.getMinY()); this.chartPanel.getChart().getXYPlot().getRangeAxis().setUpperBound(rect.getMaxY()); addAxisListener(); } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java
public void mouseReleased(MouseEvent e) { if (MouseUtils.isPopupTrigger(e)) { // clear all if (zoom_rectangle != null) { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle);// w w w. j a va2 s. c om g2.dispose(); } mouse_start_point = null; zoom_rectangle = null; // open popup current_peak = findPeakAt(e.getPoint()); enforceSelection(current_peak); createPopupMenu(current_peak != null).show(theChartPanel, e.getX(), e.getY()); } else { if (zoom_rectangle != null && mouse_start_point != null) { if (Math.abs(e.getX() - mouse_start_point.getX()) > 10) { //if( e.getX() < mouse_start_point.getX() ) { // unzoom all // onZoomNone(); //} //else { // zoom area double start_x = Math.min(e.getX(), mouse_start_point.getX()); double end_x = Math.max(e.getX(), mouse_start_point.getX()); Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x, (int) mouse_start_point.getY()); double new_lower_bound = screenToDataCoordX(start_x); double new_upper_bound = screenToDataCoordX(Math.min(end_x, data_area.getMaxX())); thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { // clear rectangle Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); g2.draw(zoom_rectangle); g2.dispose(); } } // restore zooming if (!was_moving && is_moving) onActivateZooming(); zoom_rectangle = null; mouse_start_point = null; } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void zoom(Rectangle2D selection) { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D( new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY()))); PlotRenderingInfo plotInfo = getChartRenderingInfo().getPlotInfo(); 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 = getChart().getPlot();//from ww w. j a v a2 s. c o m if (p instanceof LinkAndBrushPlot) { PlotOrientation orientation = null; if (p instanceof XYPlot) { XYPlot xyPlot = (XYPlot) p; orientation = xyPlot.getOrientation(); } if (p instanceof CategoryPlot) { CategoryPlot categoryPlot = (CategoryPlot) p; orientation = categoryPlot.getOrientation(); } // here we tweak the notify flag on the plot so that only // one notification happens even though we update multiple // axes... boolean savedNotify = p.isNotify(); p.setNotify(false); LinkAndBrushPlot LABPlot = (LinkAndBrushPlot) p; List<Pair<Integer, Range>> zoomedDomainAxisRanges = new LinkedList<Pair<Integer, Range>>(); List<Pair<Integer, Range>> zoomedRangeAxisRanges = new LinkedList<Pair<Integer, Range>>(); if (orientation == PlotOrientation.HORIZONTAL) { zoomedDomainAxisRanges .addAll(LABPlot.calculateDomainAxesZoom(vLower, vUpper, zoomOnLinkAndBrushSelection)); zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(hLower, hUpper, plotInfo, selectOrigin, zoomOnLinkAndBrushSelection)); } else { zoomedDomainAxisRanges .addAll(LABPlot.calculateDomainAxesZoom(hLower, hUpper, zoomOnLinkAndBrushSelection)); zoomedRangeAxisRanges.addAll(LABPlot.calculateRangeAxesZoom(vLower, vUpper, plotInfo, selectOrigin, zoomOnLinkAndBrushSelection)); } p.setNotify(savedNotify); if (zoomOnLinkAndBrushSelection) { informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.ZOOM_IN, zoomedDomainAxisRanges, zoomedRangeAxisRanges)); } else { informLinkAndBrushSelectionListeners(new LinkAndBrushSelection(SelectionType.SELECTION, zoomedDomainAxisRanges, zoomedRangeAxisRanges)); } } else { super.zoom(selection); } } }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Handles a 'mouse dragged' event./*from ww w. j a v a2 s.c o m*/ * * @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)... drawRectangle(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... drawRectangle(g2); g2.dispose(); }
From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java
public void setViewport(Rectangle2D rect) { //ignore viewport changes if we have the focus if (hasFocus()) { Logger.getLogger(getClass().getName()).info("Ignoring viewport update since we have the focus!"); } else {//ww w . j av a2 s. co m //otherwise, clear our own viewport and set to new value if (this.viewport != null) { this.content.remove(this.viewport); } this.viewport = new ChromatogramViewViewport(rect); Logger.getLogger(getClass().getName()).info("Setting viewport!"); removeAxisListener(); this.chartPanel.getChart().getXYPlot().getDomainAxis().setLowerBound(rect.getMinX()); this.chartPanel.getChart().getXYPlot().getDomainAxis().setUpperBound(rect.getMaxX()); this.chartPanel.getChart().getXYPlot().getRangeAxis().setLowerBound(rect.getMinY()); this.chartPanel.getChart().getXYPlot().getRangeAxis().setUpperBound(rect.getMaxY()); addAxisListener(); } }
From source file:org.proteosuite.FastScatterPlot.java
/** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device.//from w ww. j a v a 2s.c om * @param dataArea the data area. * @param ticks the ticks. */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { // draw the range grid lines, if any... if (isRangeGridlinesVisible()) { Stroke gridStroke = getRangeGridlineStroke(); Paint gridPaint = getRangeGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { Iterator<ValueTick> iterator = ticks.iterator(); while (iterator.hasNext()) { ValueTick tick = (ValueTick) iterator.next(); double v = this.rangeAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); g2.setPaint(gridPaint); g2.setStroke(gridStroke); g2.draw(line); } } } }