List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java
public void mouseDragged(MouseEvent e) { if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) { if (this.coElutionStart == null) { return; }//from w w w . j av a2 s .com Graphics2D g2 = (Graphics2D) _cp.getGraphics(); if (this.coElutionRegion != null) drawCoElutionRegion(g2); if (e.getX() < this.coElutionStart.getX()) return; // Erase the previous zoom rectangle (if any)... Rectangle2D scaledDataArea = _cp.getScreenDataArea((int) this.coElutionStart.getX(), (int) this.coElutionStart.getY()); // 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.coElutionRegion = new Rectangle2D.Double( this.coElutionStart.getX(), this.coElutionStart.getY(), xmax - this.coElutionStart.getX(), ymax - this.coElutionStart.getY()); */ this.coElutionRegion = new Rectangle2D.Double(this.coElutionStart.getX(), scaledDataArea.getMinY(), Math.abs(e.getX() - coElutionStart.getX()), scaledDataArea.getHeight()); // Draw the new zoom rectangle... drawCoElutionRegion(g2); g2.dispose(); } else { _cp.mouseDragged(e); } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void updateChart() { // auto zoom// www .ja v a 2s. co m if (theDocument.size() > 0) { Range mz_range = thePlot.getDomainAxis().getRange(); // update data double mz_toll = screenToDataX(1.); double[][] data = theDocument.getData(mz_range.getLowerBound(), mz_range.getUpperBound()); // update visible data and compute intensity range visibleData.clear(); double min_int = (data[0].length > 0) ? data[1][0] : 0.; double max_int = (data[0].length > 0) ? data[1][0] : 0.; for (int i = 0; i < data[0].length; i++) { min_int = Math.min(min_int, data[1][i]); max_int = Math.max(max_int, data[1][i]); visibleData.put(data[0][i], data[1][i]); } //Range new_int_range = new Range(min_int,max_int); Range new_int_range = new Range(0., max_int); // make space for annotations Rectangle2D data_area = theChartPanel.getScreenDataArea(); if (data_area.getHeight() > 0) new_int_range = Range.expand(new_int_range, 0., 12. / data_area.getHeight()); // resize y axis thePlot.getRangeAxis().setRange(new_int_range); // reload dataset theDataset.removeSeries("intensities"); theDataset.addSeries("intensities", data); } else { thePlot.getRangeAxis().setRange(new Range(0., 1.)); theDataset.removeSeries("intensities"); } // restore annotation shapes showSelection(); }
From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java
public boolean renderArea(Graphics2D g2, Rectangle2D dataArea) { CoreStatusEvent statusEv = new CoreStatusEvent(this); g2.setPaint(paint);//from w ww . j a v a 2 s. co m final double parHStep, parVStep; double parHLower = domainAxis.getRange().getLowerBound(); double parHUpper = domainAxis.getRange().getUpperBound(); double parVLower = rangeAxis.getRange().getLowerBound(); double parVUpper = rangeAxis.getRange().getUpperBound(); parHStep = Math.abs(parHUpper - parHLower) / dataArea.getWidth(); parVStep = Math.abs(parVUpper - parVLower) / dataArea.getHeight(); final BufferedImage 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; 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; try { result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); } catch (ModelException e) { String mess = "Exception while:\n" + dumpVariableDoubles(parameters) + dumpVariableDoubles(initialPoint); throw new ModelException(mess, e); } 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); statusEv.setStatusString("exception"); statusEv.setType(CoreStatusEvent.STRING); notifyCoreStatusListeners(statusEv); return false; } // both zero if (Math.abs(result[0]) < epsilon && Math.abs(result[1]) < epsilon) { color = Color.black.getRGB(); } // one zero one positive else if (Math.abs(result[0]) < epsilon && result[1] > 0 || Math.abs(result[1]) < epsilon && result[0] > 0) { color = Color.red.getRGB(); } // one zero one negative else if (Math.abs(result[0]) < epsilon && result[1] < 0 || Math.abs(result[1]) < epsilon && result[0] < 0) { color = Color.blue.getRGB(); } // one positive one negative else if (result[0] < 0 && result[1] > 0 || result[1] < 0 && result[0] > 0) { color = Color.green.getRGB(); } // both positive else if (result[0] > 0 && result[1] > 0) { color = Color.orange.getRGB(); } // both negative else if (result[0] < 0 && result[1] < 0) { color = Color.pink.getRGB(); } else { // impossible color = Color.yellow.getRGB(); } 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); statusEv.setPercent(0); statusEv.setType(CoreStatusEvent.COUNT | CoreStatusEvent.PERCENT); notifyCoreStatusListeners(statusEv); } } } return true; }
From source file:org.apache.pdfbox.contentstream.PDFStreamEngine.java
/** * Process the given tiling pattern. Allows the pattern matrix to be overridden for custom * rendering./*w w w. j a v a2 s. c o m*/ * * @param tilingPattern the tiling pattern * @param color color to use, if this is an uncoloured pattern, otherwise null. * @param colorSpace color space to use, if this is an uncoloured pattern, otherwise null. * @param patternMatrix the pattern matrix, may be overridden for custom rendering. */ protected final void processTilingPattern(PDTilingPattern tilingPattern, PDColor color, PDColorSpace colorSpace, Matrix patternMatrix) throws IOException { PDResources parent = pushResources(tilingPattern); Matrix parentMatrix = initialMatrix; initialMatrix = Matrix.concatenate(initialMatrix, patternMatrix); // save the original graphics state Stack<PDGraphicsState> savedStack = saveGraphicsStack(); // save a clean state (new clipping path, line path, etc.) Rectangle2D bbox = tilingPattern.getBBox().transform(patternMatrix).getBounds2D(); PDRectangle rect = new PDRectangle((float) bbox.getX(), (float) bbox.getY(), (float) bbox.getWidth(), (float) bbox.getHeight()); graphicsStack.push(new PDGraphicsState(rect)); // non-colored patterns have to be given a color if (colorSpace != null) { color = new PDColor(color.getComponents(), colorSpace); getGraphicsState().setNonStrokingColorSpace(colorSpace); getGraphicsState().setNonStrokingColor(color); getGraphicsState().setStrokingColorSpace(colorSpace); getGraphicsState().setStrokingColor(color); } // transform the CTM using the stream's matrix getGraphicsState().getCurrentTransformationMatrix().concatenate(patternMatrix); // clip to bounding box clipToRect(tilingPattern.getBBox()); processStreamOperators(tilingPattern); initialMatrix = parentMatrix; restoreGraphicsStack(savedStack); popResources(parent); }
From source file:org.kalypsodeegree_impl.model.geometry.GM_Envelope_Impl.java
/** * returns a new GM_Envelope object representing the intersection of this GM_Envelope with the specified GM_Envelope. * * Note: If there is no intersection at all GM_Envelope will be null. * //from ww w . j a v a 2 s . c om * @param bb * the GM_Envelope to be intersected with this GM_Envelope * @return the largest GM_Envelope contained in both the specified GM_Envelope and in this GM_Envelope. */ @Override public GM_Envelope createIntersection(final GM_Envelope bb) { Rectangle2D rect = new Rectangle2D.Double(bb.getMin().getX(), bb.getMin().getY(), bb.getWidth(), bb.getHeight()); final Rectangle2D rect2 = new Rectangle2D.Double(getMin().getX(), getMin().getY(), getWidth(), getHeight()); if (rect2.intersects(bb.getMin().getX(), bb.getMin().getY(), bb.getWidth(), bb.getHeight())) { rect = rect.createIntersection(rect2); } else { rect = null; } if (rect == null) { return null; } final double xmin = rect.getX(); final double ymin = rect.getY(); final double xmax = rect.getX() + rect.getWidth(); final double ymax = rect.getY() + rect.getHeight(); // TODO Check coordinate systems, if equal. return new GM_Envelope_Impl(xmin, ymin, xmax, ymax, m_coordinateSystem); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Transform the tree layout so that it fits nicely in the given image * dimensions//from www .j a v a 2 s . c o m * @param treeLayout * the layout to transform * @param imageWidth * the image width * @param imageHeight * the image height */ private void transformTreeLayout(VisualTreeNode treeLayout, int imageWidth, int imageHeight, FontRenderContext frc) { Dimension2D maximalNodeLabelDimension = this.calculateMaximalNodeDimension(treeLayout, frc); double widthBuffer = maximalNodeLabelDimension.getWidth() + BORDER_WHITE_SPACE; double heightBuffer = maximalNodeLabelDimension.getHeight() + BORDER_WHITE_SPACE; // perform rotation to improve the use of space { // center around 0, 0 VisualTreeNode[] mostDistantPair = this.getMostDistantNodePair(treeLayout); Point2D distantPoint1 = mostDistantPair[0].getPosition(); Point2D distantPoint2 = mostDistantPair[1].getPosition(); double xDiff = distantPoint1.getX() - distantPoint2.getX(); double yDiff = distantPoint1.getY() - distantPoint2.getY(); this.translateTreeLayout(treeLayout, (xDiff / 2.0) - distantPoint1.getX(), (yDiff / 2.0) - distantPoint2.getY()); // rotate double thetaRadians = Math.atan2(yDiff, xDiff); if (imageWidth >= imageHeight) { this.rotateTreeLayout(treeLayout, -thetaRadians); } else { this.rotateTreeLayout(treeLayout, (Math.PI / 2.0 - thetaRadians)); } } Rectangle2D boundingRectangle = this.calculateBounds(treeLayout, null); // center around the middle of the display area this.translateTreeLayout(treeLayout, -boundingRectangle.getX(), -boundingRectangle.getY()); // grow the image to fill a larger area double xScale = (imageWidth - widthBuffer) / boundingRectangle.getWidth(); double yScale = (imageHeight - heightBuffer) / boundingRectangle.getHeight(); double smallerScale = Math.min(xScale, yScale); this.scaleTreeLayout(treeLayout, smallerScale); // center around the middle of the display area boundingRectangle = this.calculateBounds(treeLayout, null); this.translateTreeLayout(treeLayout, ((imageWidth - boundingRectangle.getWidth()) / 2.0) - boundingRectangle.getX(), ((imageHeight - boundingRectangle.getHeight()) / 2.0) - boundingRectangle.getY()); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.ColoredBlockContainer.java
/** * Disclaimer: this is a "works for me" implementation, and probably only works as long as the * items are arranged horizontally in exactly one line, since it brutally enforces the items to * be aligned vertically centered.//from www.ja v a2 s.c o m */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { area = drawFill(g2, area); // check if we need to collect chart entities from the container EntityBlockParams ebp = null; StandardEntityCollection sec = null; if (params instanceof EntityBlockParams) { ebp = (EntityBlockParams) params; if (ebp.getGenerateEntities()) { sec = new StandardEntityCollection(); } } Rectangle2D contentArea = (Rectangle2D) area.clone(); contentArea = trimMargin(contentArea); drawBorder(g2, contentArea); contentArea = trimBorder(contentArea); contentArea = trimPadding(contentArea); Iterator iterator = getBlocks().iterator(); while (iterator.hasNext()) { Block block = (Block) iterator.next(); Rectangle2D bounds = block.getBounds(); // enforce vertically centered alignment double y = area.getY() + (area.getHeight() - bounds.getHeight()) / 2.0; Rectangle2D drawArea = new Rectangle2D.Double(bounds.getX() + area.getX(), y, bounds.getWidth(), bounds.getHeight()); Object r = block.draw(g2, drawArea, params); if (sec != null) { if (r instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) r; EntityCollection ec = ebr.getEntityCollection(); sec.addAll(ec); } } } BlockResult result = null; if (sec != null) { result = new BlockResult(); result.setEntityCollection(sec); } return result; }
From source file:it.unibo.alchemist.boundary.monitors.Generic2DDisplay.java
private Shape convertObstacle(final Obstacle2D o) { final Rectangle2D r = o.getBounds2D(); final Position[] points = new Position[] { new Continuous2DEuclidean(r.getX(), r.getY()), new Continuous2DEuclidean(r.getX() + r.getWidth(), r.getY()), new Continuous2DEuclidean(r.getX() + r.getWidth(), r.getY() + r.getHeight()), new Continuous2DEuclidean(r.getX(), r.getY() + r.getHeight()) }; final Path2D path = new GeneralPath(); for (int i = 0; i < points.length; i++) { final Point pt = wormhole.getViewPoint(points[i]); if (i == 0) { path.moveTo(pt.getX(), pt.getY()); }/*from w w w .ja v a 2 s . co m*/ path.lineTo(pt.getX(), pt.getY()); } path.closePath(); return path; }
From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java
/** * Draws the fast scatter plot on a Java 2D graphics device (such as the screen or * a printer).//from w ww . jav a 2 s . c o m * * @param g2 the graphics device. * @param plotArea the area within which the plot (including axis labels) should be drawn. * @param info collects chart drawing information (<code>null</code> permitted). */ public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo info) { // if (data == null) // return; // set up info collection... if (info != null) { info.setPlotArea(plotArea); } // adjust the drawing area for plot insets (if any)... Insets insets = getInsets(); if (insets != null) { plotArea.setRect(plotArea.getX() + insets.left, plotArea.getY() + insets.top, plotArea.getWidth() - insets.left - insets.right, plotArea.getHeight() - insets.top - insets.bottom); } AxisSpace space = new AxisSpace(); space = this.domainAxis.reserveSpace(g2, this, plotArea, RectangleEdge.BOTTOM, space); space = this.rangeAxis.reserveSpace(g2, this, plotArea, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(plotArea, null); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); /* if automatic bounds... */ if (!isNoData()) { if (this instanceof DmcRenderablePlot) { DmcPlotRenderer renderer; renderer = ((DmcRenderablePlot) this).getPlotRenderer(); if (renderer != null) { renderer.initialize(); if (renderer.getState() == DmcPlotRenderer.STATE_STOPPED) { return; } } } } AxisState domainAxisState = null, rangeAxisState = null; if (this.domainAxis != null) { double cursor; cursor = dataArea.getMaxY(); domainAxisState = this.domainAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM, info); // cursor = info.getCursor(); } if (this.rangeAxis != null) { double cursor; cursor = dataArea.getMinX(); rangeAxisState = this.rangeAxis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT, info); } if (drawGridlines == true && domainAxisState != null && rangeAxisState != null) { drawGridlines(g2, dataArea, domainAxisState.getTicks(), rangeAxisState.getTicks()); } Shape originalClip = g2.getClip(); g2.clip(dataArea); // Composite originalComposite = g2.getComposite(); // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, // getForegroundAlpha())); // g2.setStroke(new BasicStroke(12.0F)); if (isNoData()) { drawNoDataMessage(g2, plotArea); } else { drawPlot(g2, dataArea, info); } g2.setClip(originalClip); drawOutline(g2, dataArea); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (getChart() == null) { return;/*from ww w .j a v a 2 s .c om*/ } 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(); setChartFieldValue(getChartFieldByName("scaleX"), 1.0); // this.scaleX = 1.0; setChartFieldValue(getChartFieldByName("scaleY"), 1.0); // this.scaleY = 1.0; if (drawWidth < getMinimumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMinimumDrawWidth()); // this.scaleX = drawWidth / getMinimumDrawWidth(); drawWidth = getMinimumDrawWidth(); scale = true; } else if (drawWidth > getMaximumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMaximumDrawWidth()); // this.scaleX = drawWidth / getMaximumDrawWidth(); drawWidth = getMaximumDrawWidth(); scale = true; } if (drawHeight < getMinimumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMinimumDrawHeight()); // this.scaleY = drawHeight / getMinimumDrawHeight(); drawHeight = getMinimumDrawHeight(); scale = true; } else if (drawHeight > getMaximumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMaximumDrawHeight()); // this.scaleY = drawHeight / getMaximumDrawHeight(); drawHeight = getMaximumDrawHeight(); scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if ((Boolean) getChartFieldValueByName("useBuffer")) { // do we need to resize the buffer? if ((getChartFieldValueByName("chartBuffer") == null) || ((Integer) getChartFieldValueByName("chartBufferWidth") != available.getWidth()) || ((Integer) getChartFieldValueByName("chartBufferHeight") != available.getHeight())) { setChartFieldValue(getChartFieldByName("chartBufferWidth"), (int) available.getWidth()); // this.chartBufferWidth = (int) available.getWidth(); setChartFieldValue(getChartFieldByName("chartBufferHeight"), (int) available.getHeight()); // this.chartBufferHeight = (int) available.getHeight(); GraphicsConfiguration gc = g2.getDeviceConfiguration(); setChartFieldValue(getChartFieldByName("chartBuffer"), gc.createCompatibleImage((Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight"), Transparency.TRANSLUCENT)); // this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth, // this.chartBufferHeight, Transparency.TRANSLUCENT); setRefreshBuffer(true); } // do we need to redraw the buffer? if (getRefreshBuffer()) { setRefreshBuffer(false); // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); Graphics2D bufferG2 = (Graphics2D) ((Image) getChartFieldValueByName("chartBuffer")).getGraphics(); Rectangle r = new Rectangle(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); bufferG2.setPaint(getBackground()); bufferG2.fill(r); if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance( (Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); bufferG2.transform(st); getChart().draw(bufferG2, chartArea, getAnchor(), getChartRenderingInfo()); bufferG2.setTransform(saved); } else { getChart().draw(bufferG2, bufferArea, getAnchor(), getChartRenderingInfo()); } } // zap the buffer onto the panel... g2.drawImage((Image) getChartFieldValueByName("chartBuffer"), insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance((Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); g2.transform(st); } getChart().draw(g2, chartArea, getAnchor(), getChartRenderingInfo()); g2.setTransform(saved); } Iterator iterator = ((List) getChartFieldValueByName("overlays")).iterator(); while (iterator.hasNext()) { Overlay 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 drawZoomRectangle(g2, !(Boolean) getChartFieldValueByName("useBuffer")); g2.dispose(); setAnchor(null); setVerticalTraceLine(null); setHorizontalTraceLine(null); }