List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void mouseReleased(MouseEvent e) { // if we've been panning, we need to reset now that the mouse is // released... Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle"); Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint"); if (getChartFieldValueByName("panLast") != null) { setChartFieldValue((getChartFieldByName("panLast")), null); setCursor(Cursor.getDefaultCursor()); } else if (zoomRectangle != null) { boolean hZoom = false; boolean vZoom = false; if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) { hZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); vZoom = (Boolean) getChartFieldValueByName("domainZoomable"); } else {/*from w w w. j a v a 2s . c o m*/ hZoom = (Boolean) getChartFieldValueByName("domainZoomable"); vZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); } boolean zoomTrigger1 = hZoom && Math .abs(e.getX() - zoomPoint.getX()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance"); boolean zoomTrigger2 = vZoom && Math .abs(e.getY() - zoomPoint.getY()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance"); if (zoomTrigger1 || zoomTrigger2) { if ((hZoom && (e.getX() < zoomPoint.getX())) || (vZoom && (e.getY() < zoomPoint.getY()))) { restoreAutoBounds(); } else { double x, y, w, h; Rectangle2D screenDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) 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 = zoomPoint.getX(); y = screenDataArea.getMinY(); w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX()); h = screenDataArea.getHeight(); } else if (!hZoom) { x = screenDataArea.getMinX(); y = zoomPoint.getY(); w = screenDataArea.getWidth(); h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY()); } else { x = zoomPoint.getX(); y = zoomPoint.getY(); w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX()); h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } setChartFieldValue(getChartFieldByName("zoomPoint"), null); setChartFieldValue(getChartFieldByName("zoomRectangle"), null); } else { // erase the zoom rectangle Graphics2D g2 = (Graphics2D) getGraphics(); if ((Boolean) getChartFieldValueByName("useBuffer")) { repaint(); } else { drawZoomRectangle(g2, true); } g2.dispose(); setChartFieldValue(getChartFieldByName("zoomPoint"), null); setChartFieldValue(getChartFieldByName("zoomRectangle"), null); } } else if (e.isPopupTrigger()) { if (getChartFieldValueByName("popup") != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java
/** * Adjusts the page size to the containing shapes, with a margin, and also moves all shapes on the page * so their positions are actually within the page bounds. *//*w ww .jav a2 s . co m*/ private Point2D adjustPage(Rectangle2D graphAreaBounds, Shape title, List<Shape> queryInfo, Rectangle2D legendsBox) { double pageWidth = graphAreaBounds.getWidth() + 3 * MARGIN_IN + legendsBox.getWidth(); double graphAreaPlusTitleHeight = graphAreaBounds.getHeight() + title.getHeight() + getQueryInfoHeight(queryInfo) + MARGIN_IN; double pageHeight = Math.max(graphAreaPlusTitleHeight, legendsBox.getHeight()) + 2 * MARGIN_IN; getTargetPage().setSize(pageWidth, pageHeight); double deltaY = pageHeight - graphAreaPlusTitleHeight - MARGIN_IN; for (Shape shape : getTargetPage().getShapes()) { shape.setPosition(shape.getPinX() + MARGIN_IN, shape.getPinY() + deltaY); } return new Point2D.Double(MARGIN_IN, deltaY); }
From source file:org.dwfa.ace.graph.AceGraphRenderer.java
/** * Labels the specified vertex with the specified label. * Uses the font specified by this instance's * <code>VertexFontFunction</code>. (If the font is unspecified, the * existing//from w w w. j a v a 2s . c o m * font for the graphics context is used.) If vertex label centering * is active, the label is centered on the position of the vertex; otherwise * the label is offset slightly. */ protected void labelVertex(Graphics g, Vertex v, String label, int x, int y) { Component component = prepareRenderer(graphLabelRenderer, label, isPicked(v), v); Dimension d = component.getPreferredSize(); int h_offset; int v_offset; if (centerVertexLabel) { h_offset = -d.width / 2; v_offset = -d.height / 2; } else { Rectangle2D bounds = vertexShapeFunction.getShape(v).getBounds2D(); h_offset = (int) (bounds.getWidth() / 2) + 5; v_offset = (int) (bounds.getHeight() / 2) + 5 - d.height; } component.setBackground(Color.white); rendererPane.paintComponent(g, component, screenDevice, x + h_offset, y + v_offset, d.width, d.height, true); }
From source file:savant.view.tracks.BAMTrackRenderer.java
/** * Render the individual bases on top of the read. Depending on the drawing * mode this can be either bases read or mismatches. *//* w ww .ja v a 2 s. c om*/ private void renderBases(Graphics2D g2, GraphPaneAdapter gp, SAMRecord samRecord, int level, byte[] refSeq, Range range, double unitHeight) { ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); boolean baseQualityEnabled = (Boolean) instructions.get(DrawingInstruction.BASE_QUALITY); boolean drawingAllBases = lastMode == DrawingMode.SEQUENCE || baseQualityEnabled; double unitWidth = gp.getUnitWidth(); int offset = gp.getOffset(); // Cutoffs to determine when not to draw double leftMostX = gp.transformXPos(range.getFrom()); double rightMostX = gp.transformXPos(range.getTo()) + unitWidth; int alignmentStart = samRecord.getAlignmentStart(); byte[] readBases = samRecord.getReadBases(); byte[] baseQualities = samRecord.getBaseQualities(); boolean sequenceSaved = readBases.length > 0; Cigar cigar = samRecord.getCigar(); // Absolute positions in the reference sequence and the read bases, set after each cigar operator is processed int sequenceCursor = alignmentStart; int readCursor = alignmentStart; List<Rectangle2D> insertions = new ArrayList<Rectangle2D>(); FontMetrics fm = g2.getFontMetrics(MISMATCH_FONT); Rectangle2D charRect = fm.getStringBounds("G", g2); boolean fontFits = charRect.getWidth() <= unitWidth && charRect.getHeight() <= unitHeight; if (fontFits) { g2.setFont(MISMATCH_FONT); } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (CigarElement cigarElement : cigar.getCigarElements()) { int operatorLength = cigarElement.getLength(); CigarOperator operator = cigarElement.getOperator(); Rectangle2D.Double opRect = null; double opStart = gp.transformXPos(sequenceCursor); double opWidth = operatorLength * unitWidth; // Cut off start and width so no drawing happens off-screen, must be done in the order w, then x, since w depends on first value of x double x2 = Math.min(rightMostX, opStart + opWidth); opStart = Math.max(leftMostX, opStart); opWidth = x2 - opStart; switch (operator) { case D: // Deletion if (opWidth > 0.0) { renderDeletion(g2, gp, opStart, level, operatorLength, unitHeight); } break; case I: // Insertion insertions.add(new Rectangle2D.Double(gp.transformXPos(sequenceCursor), gp.transformYPos(0) - ((level + 1) * unitHeight) - gp.getOffset(), unitWidth, unitHeight)); break; case M: // Match or mismatch case X: case EQ: // some SAM files do not contain the read bases if (sequenceSaved || operator == CigarOperator.X) { for (int i = 0; i < operatorLength; i++) { // indices into refSeq and readBases associated with this position in the cigar string int readIndex = readCursor - alignmentStart + i; boolean mismatched = false; if (operator == CigarOperator.X) { mismatched = true; } else { int refIndex = sequenceCursor + i - range.getFrom(); if (refIndex >= 0 && refSeq != null && refIndex < refSeq.length) { mismatched = refSeq[refIndex] != readBases[readIndex]; } } if (mismatched || drawingAllBases) { Color col; if ((mismatched && lastMode != DrawingMode.STANDARD) || lastMode == DrawingMode.SEQUENCE) { col = cs.getBaseColor((char) readBases[readIndex]); } else { col = cs.getColor(samRecord.getReadNegativeStrandFlag() ? ColourKey.REVERSE_STRAND : ColourKey.FORWARD_STRAND); } if (baseQualityEnabled && col != null) { col = new Color(col.getRed(), col.getGreen(), col.getBlue(), getConstrainedAlpha( (int) Math.round((baseQualities[readIndex] * 0.025) * 255))); } double xCoordinate = gp.transformXPos(sequenceCursor + i); double top = gp.transformYPos(0) - ((level + 1) * unitHeight) - offset; if (col != null) { opRect = new Rectangle2D.Double(xCoordinate, top, unitWidth, unitHeight); g2.setColor(col); g2.fill(opRect); } if (lastMode != DrawingMode.SEQUENCE && mismatched && fontFits) { // If it's a real mismatch, we want to draw the base letter (space permitting). g2.setColor(new Color(10, 10, 10)); String s = new String(readBases, readIndex, 1); charRect = fm.getStringBounds(s, g2); g2.drawString(s, (float) (xCoordinate + (unitWidth - charRect.getWidth()) * 0.5), (float) (top + fm.getAscent() + (unitHeight - charRect.getHeight()) * 0.5)); } } } } break; case N: // Skipped opRect = new Rectangle2D.Double(opStart, gp.transformYPos(0) - ((level + 1) * unitHeight) - offset, opWidth, unitHeight); g2.setColor(cs.getColor(ColourKey.SKIPPED)); g2.fill(opRect); break; default: // P - passing, H - hard clip, or S - soft clip break; } if (operator.consumesReadBases()) { readCursor += operatorLength; } if (operator.consumesReferenceBases()) { sequenceCursor += operatorLength; } } for (Rectangle2D ins : insertions) { drawInsertion(g2, ins.getX(), ins.getY(), ins.getWidth(), ins.getHeight()); } }
From source file:org.tsho.dmc2.core.chart.LyapunovRenderer.java
public boolean renderArea(Graphics2D g2, Rectangle2D dataArea) { g2.setPaint(plot.paint);//from w w w. j ava 2s .com if (pass == 1) { if (image != null) { double x = dataArea.getX(); double y = dataArea.getY(); //there is a problem when using Graphics2D with affine transform //and BufferedImage; using subclass of Image returned below. //rescaling needed because adding legend causes dataArea to change. Image scaledImage = image.getScaledInstance((int) dataArea.getWidth() - 1, (int) dataArea.getHeight() - 1, Image.SCALE_DEFAULT); g2.drawImage(scaledImage, (int) x + 1, (int) y + 1, (int) dataArea.getWidth() - 1, (int) dataArea.getHeight() - 1, this); //g2.translate(-1,-1); //g2.drawRect((int) x, (int) y, (int) dataArea.getWidth(),(int) dataArea.getHeight()); //g2.translate(1,1); } return true; } final double parHStep, parVStep; double parHLower = plot.getDomainAxis().getRange().getLowerBound(); double parHUpper = plot.getDomainAxis().getRange().getUpperBound(); double parVLower = plot.getRangeAxis().getRange().getLowerBound(); double parVUpper = plot.getRangeAxis().getRange().getUpperBound(); parHStep = Math.abs(parHUpper - parHLower) / dataArea.getWidth(); parVStep = Math.abs(parVUpper - parVLower) / dataArea.getHeight(); image = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster raster = image.getRaster(); DataBufferInt dataBuffer = (DataBufferInt) raster.getDataBuffer(); int[] data = dataBuffer.getData(); final double parHStart = parHLower + parHStep / 2; final double parVStart = parVUpper - parVStep / 2; if (model instanceof ODE) { double step = stepSize; // stepSize and timeStep probably mean the same thing, one for discrete another for ODE double[] result = new double[model.getNVar()]; for (int i = 0; i < (int) dataArea.getWidth(); i++) { for (int j = 0; j < (int) dataArea.getHeight(); j++) { parameters.put(firstParLabel, parHStart + i * parHStep); parameters.put(secondParLabel, parVStart - j * parVStep); int color; result = Lua.evaluateLyapunovExponentsODE(model, parameters, initialPoint, timePeriod, stepSize); if (result == null) { System.out.println("i: " + i + " j: " + j); System.out.println("par1: " + parHStart + i * parHStep); System.out.println("par2: " + parVStart + j * parVStep); g2.drawImage(image, null, (int) dataArea.getX() + 1, (int) dataArea.getY() + 1); return false; } int zer = 0; int pos = 0; int neg = 0; int nan = 0; for (int ii = 0; ii < result.length; ii++) { if (Math.abs(result[ii]) == (1.0 / 0.0)) nan++; else if (Math.abs(result[ii]) <= epsilon) zer++; else if (result[ii] > epsilon) pos++; else if (result[ii] < (-epsilon)) neg++; else nan++; } color = (lyapunovColors.getColor(zer, pos, neg, nan)).getRGB(); ExpsSigns es = new ExpsSigns(zer, pos, neg, nan); if (!signsSet.contains(es)) signsSet.add(es); data[i + j * (int) dataArea.getWidth()] = color; if (stopped == true) return false; if (j == (int) dataArea.getHeight() - 1) { g2.drawImage(image, null, (int) dataArea.getX() + 1, (int) dataArea.getY() + 1); } } //end for } //end for } //end if ODE else { for (int i = 0; i < (int) dataArea.getWidth(); i++) { for (int j = 0; j < (int) dataArea.getHeight(); j++) { parameters.put(firstParLabel, parHStart + i * parHStep); parameters.put(secondParLabel, parVStart - j * parVStep); double[] result; int color; result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); if (result == null) { System.out.println("i: " + i + " j: " + j); System.out.println("par1: " + parHStart + i * parHStep); System.out.println("par2: " + parVStart + j * parVStep); g2.drawImage(image, null, (int) dataArea.getX() + 1, (int) dataArea.getY() + 1); return false; } int zer = 0; int pos = 0; int neg = 0; int nan = 0; for (int ii = 0; ii < result.length; ii++) { if (Math.abs(result[ii]) == (1.0 / 0.0)) nan++; else if (Math.abs(result[ii]) <= epsilon) zer++; else if (result[ii] > epsilon) pos++; else if (result[ii] < (-epsilon)) neg++; else nan++; } color = (lyapunovColors.getColor(zer, pos, neg, nan)).getRGB(); ExpsSigns es = new ExpsSigns(zer, pos, neg, nan); if (!signsSet.contains(es)) signsSet.add(es); data[i + j * (int) dataArea.getWidth()] = color; if (stopped == true) return false; if (j == (int) dataArea.getHeight() - 1) g2.drawImage(image, null, (int) dataArea.getX() + 1, (int) dataArea.getY() + 1); } //end for } //end for } //end else return true; }
From source file:extern.NpairsBoxAndWhiskerRenderer.java
/** * Initialises the renderer. This method gets called once at the start of * the process of drawing a chart.//from w w w . ja v a2 s .com * * @param g2 the graphics device. * @param dataArea the area in which the data is to be plotted. * @param plot the plot. * @param rendererIndex the renderer index. * @param info collects chart rendering information for return to caller. * * @return The renderer state. */ public CategoryItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, CategoryPlot plot, int rendererIndex, PlotRenderingInfo info) { prevX = -1.0; prevY = -1.0; CategoryItemRendererState state = super.initialise(g2, dataArea, plot, rendererIndex, info); // calculate the box width CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex); CategoryDataset dataset = plot.getDataset(rendererIndex); if (dataset != null) { int columns = dataset.getColumnCount(); int rows = dataset.getRowCount(); double space = 0.0; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { space = dataArea.getHeight(); } else if (orientation == PlotOrientation.VERTICAL) { space = dataArea.getWidth(); } double maxWidth = space * getMaximumBarWidth(); double categoryMargin = 0.0; double currentItemMargin = 0.0; if (columns > 1) { categoryMargin = domainAxis.getCategoryMargin(); } if (rows > 1) { currentItemMargin = getItemMargin(); } double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin() - categoryMargin - currentItemMargin); if ((rows * columns) > 0) { state.setBarWidth(Math.min(used / (dataset.getColumnCount() * dataset.getRowCount()), maxWidth)); } else { state.setBarWidth(Math.min(used, maxWidth)); } } return state; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private boolean updateInvestPoint(Point2D _investPoint) { if (_investPoint == null) { return false; }//from www . j ava2s.c o m final ChartPanel chartPanel = this.investmentFlowChartJDialog.getChartPanel(); final JFreeChart chart = chartPanel.getChart(); final XYPlot plot = (XYPlot) chart.getPlot(); final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(); final TimeSeries timeSeries = timeSeriesCollection.getSeries(0); // I also not sure why. This is what are being done in Mouse Listener Demo 4. // // Don't use it. It will cause us to lose precision. //final Point2D p2 = chartPanel.translateScreenToJava2D((Point)_investPoint); /* Try to get correct main chart area. */ final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); /* Believe it? When there is another thread keep updateing time series data, * and keep calling setDirty, _plotArea can be 0 size sometimes. Ignore it. * Just assume we had processed it. */ if (_plotArea.getWidth() == 0.0 && _plotArea.getHeight() == 0.0) { /* Cheat the caller. */ return true; } final ValueAxis domainAxis = plot.getDomainAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); final double coordinateX = domainAxis.java2DToValue(_investPoint.getX(), _plotArea, domainAxisEdge); int low = 0; int high = timeSeries.getItemCount() - 1; Date date = new Date((long) coordinateX); final long time = date.getTime(); long bestDistance = Long.MAX_VALUE; int bestMid = 0; while (low <= high) { int mid = (low + high) >>> 1; final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(mid); final Day day = (Day) timeSeriesDataItem.getPeriod(); final long search = day.getFirstMillisecond(); final long cmp = search - time; if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { bestDistance = 0; bestMid = mid; break; } final long abs_cmp = Math.abs(cmp); if (abs_cmp < bestDistance) { bestDistance = abs_cmp; bestMid = mid; } } final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(bestMid); final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond(); final double yValue = timeSeriesDataItem.getValue().doubleValue(); final double xJava2D = domainAxis.valueToJava2D(xValue, _plotArea, domainAxisEdge); final double yJava2D = rangeAxis.valueToJava2D(yValue, _plotArea, rangeAxisEdge); final int tmpIndex = bestMid; // Do not perform translation as this will cause precision losing. // We might experience unstable point. For example, // // this.investPoint is 700.9, there are 2 data points which are 700 and // 701. // During first updateInvestPoint(this.investPoint) call, data point 701 // will be chosen, and this.investPoint has been truncated to 700. // During second updateInvestPoint(this.investPoint) call, data point 700 // will be chosen. We may observe an unstable point swings between 700 // and 701. // // translateJava2DToScreen will internally convert Point2D.Double to Point. //final Point2D tmpPoint = chartPanel.translateJava2DToScreen(new Point2D.Double(xJava2D, yJava2D)); final Point2D tmpPoint = new Point2D.Double(xJava2D, yJava2D); this.drawArea.setRect(_plotArea); if (this.drawArea.contains(tmpPoint)) { this.investPointIndex = tmpIndex; this.investPoint = tmpPoint; return true; } return false; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private boolean updateROIPoint(Point2D _ROIPoint) { if (_ROIPoint == null) { return false; }//from w ww . ja v a2s . co m final ChartPanel chartPanel = this.investmentFlowChartJDialog.getChartPanel(); final JFreeChart chart = chartPanel.getChart(); final XYPlot plot = (XYPlot) chart.getPlot(); // Dataset 0 are the invest information. 1 is the ROI information. final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(1); final TimeSeries timeSeries = timeSeriesCollection.getSeries(0); // I also not sure why. This is what are being done in Mouse Listener Demo 4. // // Don't use it. It will cause us to lose precision. //final Point2D p2 = chartPanel.translateScreenToJava2D((Point)_ROIPoint); /* Try to get correct main chart area. */ final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); /* Believe it? When there is another thread keep updateing time series data, * and keep calling setDirty, _plotArea can be 0 size sometimes. Ignore it. * Just assume we had processed it. */ if (_plotArea.getWidth() == 0.0 && _plotArea.getHeight() == 0.0) { /* Cheat the caller. */ return true; } final ValueAxis domainAxis = plot.getDomainAxis(); final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); final ValueAxis rangeAxis = plot.getRangeAxis(); final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); final double coordinateX = domainAxis.java2DToValue(_ROIPoint.getX(), _plotArea, domainAxisEdge); int low = 0; int high = timeSeries.getItemCount() - 1; Date date = new Date((long) coordinateX); final long time = date.getTime(); long bestDistance = Long.MAX_VALUE; int bestMid = 0; while (low <= high) { int mid = (low + high) >>> 1; final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(mid); final Day day = (Day) timeSeriesDataItem.getPeriod(); final long search = day.getFirstMillisecond(); final long cmp = search - time; if (cmp < 0) { low = mid + 1; } else if (cmp > 0) { high = mid - 1; } else { bestDistance = 0; bestMid = mid; break; } final long abs_cmp = Math.abs(cmp); if (abs_cmp < bestDistance) { bestDistance = abs_cmp; bestMid = mid; } } final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(bestMid); final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond(); final double yValue = timeSeriesDataItem.getValue().doubleValue(); final double xJava2D = domainAxis.valueToJava2D(xValue, _plotArea, domainAxisEdge); final double yJava2D = rangeAxis.valueToJava2D(yValue, _plotArea, rangeAxisEdge); final int tmpIndex = bestMid; // Do not perform translation as this will cause precision losing. // We might experience unstable point. For example, // // this.ROIPoint is 700.9, there are 2 data points which are 700 and // 701. // During first updateROIPoint(this.ROIPoint) call, data point 701 // will be chosen, and this.ROIPoint has been truncated to 700. // During second updateROIPoint(this.ROIPoint) call, data point 700 // will be chosen. We may observe an unstable point swings between 700 // and 701. // // translateJava2DToScreen will internally convert Point2D.Double to Point. //final Point2D tmpPoint = chartPanel.translateJava2DToScreen(new Point2D.Double(xJava2D, yJava2D)); final Point2D tmpPoint = new Point2D.Double(xJava2D, yJava2D); this.drawArea.setRect(_plotArea); if (this.drawArea.contains(tmpPoint)) { this.ROIPointIndex = tmpIndex; this.ROIPoint = tmpPoint; return true; } return false; }
From source file:org.apache.fop.render.ps.PSRenderer.java
/** * {@inheritDoc}/*from w w w .j av a 2s . com*/ */ protected void startVParea(CTM ctm, Rectangle2D clippingRect) { saveGraphicsState(); if (clippingRect != null) { clipRect((float) clippingRect.getX() / 1000f, (float) clippingRect.getY() / 1000f, (float) clippingRect.getWidth() / 1000f, (float) clippingRect.getHeight() / 1000f); } // multiply with current CTM final double[] matrix = ctm.toArray(); matrix[4] /= 1000f; matrix[5] /= 1000f; concatMatrix(matrix); }
From source file:org.dwfa.ace.graph.AceGraphRenderer.java
/** * Draws the edge <code>e</code>, whose endpoints are at * <code>(x1,y1)</code> and <code>(x2,y2)</code>, on the graphics context * <code>g</code>./*from www.ja v a2 s. c o m*/ * The <code>Shape</code> provided by the <code>EdgeShapeFunction</code> * instance * is scaled in the x-direction so that its width is equal to the distance * between <code>(x1,y1)</code> and <code>(x2,y2)</code>. */ protected void drawSimpleEdge(Graphics2D g, Edge e, int x1, int y1, int x2, int y2) { Pair endpoints = e.getEndpoints(); Vertex v1 = (Vertex) endpoints.getFirst(); Vertex v2 = (Vertex) endpoints.getSecond(); boolean isLoop = v1.equals(v2); Shape s2 = vertexShapeFunction.getShape(v2); Shape edgeShape = edgeShapeFunction.getShape(e); boolean edgeHit = true; boolean arrowHit = true; Rectangle deviceRectangle = null; if (screenDevice != null) { Dimension d = screenDevice.getSize(); if (d.width <= 0 || d.height <= 0) { d = screenDevice.getPreferredSize(); } deviceRectangle = new Rectangle(0, 0, d.width, d.height); } AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); if (isLoop) { // this is a self-loop. scale it is larger than the vertex // it decorates and translate it so that its nadir is // at the center of the vertex. Rectangle2D s2Bounds = s2.getBounds2D(); xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight()); xform.translate(0, -edgeShape.getBounds2D().getWidth() / 2); } else { // this is a normal edge. Rotate it to the angle between // vertex endpoints, then scale it to the distance between // the vertices float dx = x2 - x1; float dy = y2 - y1; float thetaRadians = (float) Math.atan2(dy, dx); xform.rotate(thetaRadians); float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist, 1.0); } edgeShape = xform.createTransformedShape(edgeShape); if (deviceRectangle == null) { edgeHit = false; } else { edgeHit = viewTransformer.transform(edgeShape).intersects(deviceRectangle); } if (edgeHit == true) { Paint oldPaint = g.getPaint(); // get Paints for filling and drawing // (filling is done first so that drawing and label use same Paint) Paint fill_paint = edgePaintFunction.getFillPaint(e); if (fill_paint != null) { g.setPaint(fill_paint); g.fill(edgeShape); } Paint draw_paint = edgePaintFunction.getDrawPaint(e); if (draw_paint != null) { g.setPaint(draw_paint); g.draw(edgeShape); } float scalex = (float) g.getTransform().getScaleX(); float scaley = (float) g.getTransform().getScaleY(); // see if arrows are too small to bother drawing if (scalex < .3 || scaley < .3) return; if (edgeArrowPredicate.evaluate(e)) { Shape destVertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getSecond()); AffineTransform xf = AffineTransform.getTranslateInstance(x2, y2); destVertexShape = xf.createTransformedShape(destVertexShape); arrowHit = viewTransformer.transform(destVertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getArrowTransform((GeneralPath) edgeShape, destVertexShape); else at = getArrowTransform(new GeneralPath(edgeShape), destVertexShape); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); // note that arrows implicitly use the edge's draw paint g.fill(arrow); } if (e instanceof UndirectedEdge) { Shape vertexShape = vertexShapeFunction.getShape((Vertex) e.getEndpoints().getFirst()); xf = AffineTransform.getTranslateInstance(x1, y1); vertexShape = xf.createTransformedShape(vertexShape); arrowHit = viewTransformer.transform(vertexShape).intersects(deviceRectangle); if (arrowHit) { AffineTransform at; if (edgeShape instanceof GeneralPath) at = getReverseArrowTransform((GeneralPath) edgeShape, vertexShape, !isLoop); else at = getReverseArrowTransform(new GeneralPath(edgeShape), vertexShape, !isLoop); if (at == null) return; Shape arrow = edgeArrowFunction.getArrow(e); arrow = at.createTransformedShape(arrow); g.fill(arrow); } } } // use existing paint for text if no draw paint specified if (draw_paint == null) g.setPaint(oldPaint); String label = edgeStringer.getLabel(e); if (label != null) { labelEdge(g, e, label, x1, x2, y1, y2); } // restore old paint g.setPaint(oldPaint); } }