List of usage examples for java.awt.geom Rectangle2D getMaxY
public double getMaxY()
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Draws a horizontal line used to trace the mouse position to the vertical axis. * /*from ww w. j av a 2 s .co m*/ * @param g2 * the graphics device. * @param y * the y-coordinate of the trace line. */ private void drawVerticalAxisTrace(Graphics2D g2, int y) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { if (this.horizontalTraceLine != null) { g2.draw(this.horizontalTraceLine); this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } else { this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } g2.draw(this.horizontalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Returns a point based on (x, y) but constrained to be within the bounds of the given * rectangle. This method could be moved to JCommon. * //from w w w .ja va2 s . c om * @param x * the x-coordinate. * @param y * the y-coordinate. * @param area * the rectangle (<code>null</code> not permitted). * @return A point within the rectangle. */ private Point getPointInRectangle(int x, int y, Rectangle2D area) { x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x, Math.floor(area.getMaxX()))); y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y, Math.floor(area.getMaxY()))); return new Point(x, y); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse released' event.//from www .j a v a 2 s.c om * <P> * On Windows, we need to check if this is a popup trigger, but only if we * haven't already been tracking a zoom rectangle. * * @param e Information about the event. */ public void mouseReleased(MouseEvent e) { if (zoomRectangle != null) { // if (Math.abs(e.getX() - zoomPoint.getX()) >= MINIMUM_DRAG_ZOOM_SIZE) { if (Math.abs(e.getX() - zoomPoint.getX()) >= 7) { if (e.getX() < zoomPoint.getX() || e.getY() < zoomPoint.getY()) { autoRangeBoth(); } else { double x, y, w, h; Rectangle2D scaledDataArea = getScaledDataArea(); //for a mouseReleased event, (horizontalZoom || verticalZoom) //will be true, so we can just test for either being false; //otherwise both are true if (!verticalZoom) { x = zoomPoint.getX(); y = scaledDataArea.getMinY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = scaledDataArea.getHeight(); } else if (!horizontalZoom) { x = scaledDataArea.getMinX(); y = zoomPoint.getY(); w = scaledDataArea.getWidth(); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } else { x = zoomPoint.getX(); y = zoomPoint.getY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } g2.dispose(); this.zoomRectangle = null; } // notify a redraw event CoreStatusEvent ev = new CoreStatusEvent(this); ev.setType(CoreStatusEvent.REDRAW); ((AbstractDmcPlot) chart.getPlot()).notifyCoreStatusListeners(ev); } else if (e.isPopupTrigger()) { if (popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Draws a horizontal line used to trace the mouse position to the vertical * axis.//from ww w .j a v a 2 s.co m * * @param g2 the graphics device. * @param y the y-coordinate of the trace line. */ private void drawVerticalAxisTrace(Graphics2D g2, int y) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { if (this.horizontalTraceLine != null) { g2.draw(this.horizontalTraceLine); this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } else { this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y); } g2.draw(this.horizontalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
From source file:org.gumtree.vis.hist2d.Hist2DPanel.java
private void makeNewMask(MouseEvent e, EntityCollection entities) { if (this.maskPoint == null) { return;// w w w.j a v a2s . c o m } Graphics2D g2 = (Graphics2D) getGraphics(); // erase the previous zoom rectangle (if any). We only need to do // this is we are using XOR mode, which we do when we're not using // the buffer (if there is a buffer, then at the end of this method we // just trigger a repaint) if (!isDoubleBuffered()) { // drawZoomRectangle(g2, true); ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart()); } // 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.maskPoint.getX(), (int) this.maskPoint.getY()); // Working on the current mask. Only create one new mask per drag-drawing. if (currentMaskRectangle == null) { boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0; boolean isEllipse = (e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0; if (isEllipse) { currentMaskRectangle = new EllipseMask(isInclusive); } else { currentMaskRectangle = new RectangleMask(isInclusive); } // currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive)); // getMasks().add(currentMaskRectangle); addMask(currentMaskRectangle); } // 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()); // Update the current mask. ChartEntity startEntity = null; ChartEntity endEntity = null; boolean isMaskUpdated = false; if (entities != null) { // EntityCollection entities = this.info.getEntityCollection(); // if (entities != null) { Insets insets = getInsets(); double screenX = (maskPoint.getX() - insets.left) / getScaleX(); double screenY = (maskPoint.getY() - insets.top) / getScaleY(); startEntity = entities.getEntity(screenX, screenY); screenX = (xmax - insets.left) / getScaleX(); screenY = (ymax - insets.top) / getScaleY(); if (screenX >= scaledDataArea.getMaxX()) { screenX = scaledDataArea.getMaxX() - 0.001; } if (screenY >= scaledDataArea.getMaxY()) { screenY = scaledDataArea.getMaxY() - 0.001; } endEntity = entities.getEntity(screenX, screenY); // System.out.println("Try to update mask"); if (startEntity instanceof XYItemEntity && endEntity instanceof XYItemEntity) { isMaskUpdated = updateCurrentMaskRectangle((XYItemEntity) startEntity, (XYItemEntity) endEntity); } // } } if (!isMaskUpdated) { currentMaskRectangle.setRectangleFrame(new Rectangle2D.Double(maskPoint.getX(), this.maskPoint.getY(), xmax - this.maskPoint.getX(), ymax - this.maskPoint.getY())); } // Draw the new zoom rectangle... if (isDoubleBuffered()) { repaint(); } else { // with no buffer, we use XOR to draw the rectangle "over" the // chart... ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart()); } g2.dispose(); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Draws a vertical line used to trace the mouse position to the horizontal axis. * //from w ww .j ava 2s.c o m * @param g2 * the graphics device. * @param x * the x-coordinate of the trace line. */ private void drawHorizontalAxisTrace(Graphics2D g2, int x) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { if (this.verticalTraceLine != null) { g2.draw(this.verticalTraceLine); this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } else { this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } g2.draw(this.verticalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Handles a 'mouse dragged' event.//from ww w . j a v a 2 s .co 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)... 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.isti.traceview.common.TraceViewChartPanel.java
/** * Zooms in on a selected region.//from w w w. j a v a 2s . c om * * @param selection * the selected region. */ 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 = this.info.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 = this.chart.getPlot(); if (p instanceof Zoomable) { Zoomable z = (Zoomable) p; if (z.getOrientation() == PlotOrientation.HORIZONTAL) { z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin); z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin); } else { z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin); z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin); } } } }
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./*from w ww. java2s . 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()); } } }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Draws a vertical line used to trace the mouse position to the horizontal * axis.//from w w w .ja v a 2 s.c om * * @param g2 the graphics device. * @param x the x-coordinate of the trace line. */ private void drawHorizontalAxisTrace(Graphics2D g2, int x) { Rectangle2D dataArea = getScreenDataArea(); g2.setXORMode(Color.orange); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { if (this.verticalTraceLine != null) { g2.draw(this.verticalTraceLine); this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } else { this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()); } g2.draw(this.verticalTraceLine); } // Reset to the default 'overwrite' mode g2.setPaintMode(); }