List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:org.csa.rstb.dat.toolviews.HaAlphaPlotPanel.java
private ChartPanel createChartPanel(JFreeChart chart) { densityPlotDisplay = new ChartPanel(chart); MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, densityPlotDisplay, "scatter_plot_area", "Mask generated from selected scatter plot area", Color.RED, PlotAreaSelectionTool.AreaType.ELLIPSE) { @Override// w ww. ja va 2s . c o m protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) { Rectangle2D bounds = shape.getBounds2D(); return createMaskExpression(bounds.getCenterX(), bounds.getCenterY(), 0.5 * bounds.getWidth(), 0.5 * bounds.getHeight()); } protected String createMaskExpression(double x0, double y0, double dx, double dy) { return String.format("sqrt(sqr((%s - %s)/%s) + sqr((%s - %s)/%s)) < 1.0", BandArithmetic.createExternalName(dataSourceConfig.xBand.getName()), x0, dx, BandArithmetic.createExternalName(dataSourceConfig.yBand.getName()), y0, dy); } }; densityPlotDisplay.getPopupMenu().addSeparator(); densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem()); densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem()); densityPlotDisplay.getPopupMenu().addSeparator(); densityPlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return densityPlotDisplay; }
From source file:com.appnativa.rare.ui.chart.jfreechart.XYPlotEx.java
@Override protected void fillBackground(Graphics2D g2, Rectangle2D area, PlotOrientation orientation) { Paint p = this.getBackgroundPaint(); if (p == null) { return;/*ww w . ja v a 2 s. c om*/ } iPainter painter = ChartHelper.getPainter(p); if (painter == null) { super.fillBackground(g2, area, orientation); return; } Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getBackgroundAlpha())); graphics = SwingGraphics.fromGraphics(g2, null, graphics); float x = UIScreen.snapToPosition(area.getX()); float y = UIScreen.snapToPosition(area.getY()); float w = UIScreen.snapToSize(area.getWidth()); float h = UIScreen.snapToSize(area.getHeight()); painter.paint(graphics, x, y, w, h, iPainter.UNKNOWN); g2.setComposite(originalComposite); }
From source file:VASSAL.tools.image.svg.SVGRenderer.java
public BufferedImage render(double angle, double scale, Rectangle2D aoi) { // The renderer needs the bounds unscaled---scaling comes from the // width and height hints. AffineTransform px = AffineTransform.getRotateInstance(angle * DEGTORAD, defaultW / 2.0, defaultH / 2.0); r.setTransform(px);/*from ww w .j a va 2s . c o m*/ px = new AffineTransform(px); px.scale(scale, scale); final Rectangle2D rect = new Rectangle2D.Float(0, 0, defaultW, defaultH); r.addTranscodingHint(Rasterizer.KEY_WIDTH, (float) aoi.getWidth()); r.addTranscodingHint(Rasterizer.KEY_HEIGHT, (float) aoi.getHeight()); r.addTranscodingHint(Rasterizer.KEY_AOI, aoi); try { r.transcode(new TranscoderInput(doc), null); return r.getBufferedImage(); } // FIXME: review error message catch (BridgeException e) { logger.error("", e); } catch (TranscoderException e) { logger.error("", e); } return null; }
From source file:ucar.unidata.idv.control.chart.TrackSegment.java
/** * Draws the wayPoint.// w w w .j a va2 s . c o m * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { super.setGraphicsState(g2); if (!getPlotWrapper().okToDraw(this)) { return; } WayPoint leftWayPoint = getLeft(); WayPoint rightWayPoint = getRight(); g2.setStroke(new BasicStroke()); int x1 = leftWayPoint.getXFromValue(dataArea, domainAxis); int x2 = rightWayPoint.getXFromValue(dataArea, domainAxis); int top = (int) (dataArea.getY()); int bottom = (int) (dataArea.getY() + dataArea.getHeight()); FontMetrics fm = g2.getFontMetrics(); int width = fm.stringWidth(getName()); int height = fm.getAscent() + fm.getDescent(); if (getSelected()) { g2.setColor(Color.red); } else { g2.setColor(Color.black); } // int y = bottom-3; y = top - 2; int textLeft = x1 + (x2 - x1) / 2 - width / 2; g2.drawString(getName(), textLeft, y); g2.setStroke(new BasicStroke(2.0f)); g2.drawLine(x1, top + 1, x2, top + 1); g2.setStroke(new BasicStroke(1.0f)); g2.setColor(Color.gray); g2.drawLine(x1, top, x1, bottom - WayPoint.ANNOTATION_WIDTH); g2.drawLine(x2, top, x2, bottom - WayPoint.ANNOTATION_WIDTH); }
From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java
public void zoomToProduct(Product product) { final GeoPos[][] selGeoBoundaries = dataModel.getSelectedGeoBoundaries(); if ((product == null || product.getSceneGeoCoding() == null) && selGeoBoundaries.length == 0) { return;// www .ja v a 2 s. c om } //NESTMOD final GeneralPath[] generalPaths; if (product != null && product.getSceneGeoCoding() != null) { generalPaths = getGeoBoundaryPaths(product); } else { final ArrayList<GeneralPath> pathList = assemblePathList(selGeoBoundaries[0]); generalPaths = pathList.toArray(new GeneralPath[pathList.size()]); } Rectangle2D modelArea = new Rectangle2D.Double(); final Viewport viewport = layerCanvas.getViewport(); for (GeneralPath generalPath : generalPaths) { final Rectangle2D rectangle2D = generalPath.getBounds2D(); if (modelArea.isEmpty()) { if (!viewport.isModelYAxisDown()) { modelArea.setFrame(rectangle2D.getX(), rectangle2D.getMaxY(), rectangle2D.getWidth(), rectangle2D.getHeight()); } modelArea = rectangle2D; } else { modelArea.add(rectangle2D); } } Rectangle2D modelBounds = modelArea.getBounds2D(); modelBounds.setFrame(modelBounds.getX() - 2, modelBounds.getY() - 2, modelBounds.getWidth() + 4, modelBounds.getHeight() + 4); modelBounds = cropToMaxModelBounds(modelBounds); viewport.zoom(modelBounds); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * A recursive version of/*from w ww .j av a2 s . c om*/ * {@link #calculateMaximalNodeDimension(VisualTreeNode, FontRenderContext)} * @param maximalNodeDimension * the biggest width and height * @param treeLayout * the tree layout * @param frc * the {@link FontRenderContext} */ private void calculateMaximalNodeDimensionRecursive(Dimension2DDouble maximalNodeDimension, VisualTreeNode treeLayout, FontRenderContext frc) { Shape textShape = this.getLabelShape(treeLayout, frc); Shape borderShape = this.getLabelBorder(textShape); Rectangle2D borderBounds = borderShape.getBounds2D(); if (borderBounds.getWidth() > maximalNodeDimension.getWidth()) { maximalNodeDimension.setWidth(borderBounds.getWidth()); } if (borderBounds.getHeight() > maximalNodeDimension.getHeight()) { maximalNodeDimension.setHeight(borderBounds.getHeight()); } for (VisualTreeNode childNode : treeLayout.getChildNodes()) { this.calculateMaximalNodeDimensionRecursive(maximalNodeDimension, childNode, frc); } }
From source file:org.esa.snap.rcp.statistics.DensityPlotPanel.java
private ChartPanel createChartPanel(JFreeChart chart) { densityPlotDisplay = new ChartPanel(chart); MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, densityPlotDisplay, "scatter_plot_area", "Mask generated from selected scatter plot area", Color.RED, PlotAreaSelectionTool.AreaType.ELLIPSE) { @Override//from w w w. ja va 2s . co m protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) { Rectangle2D bounds = shape.getBounds2D(); return createMaskExpression(bounds.getCenterX(), bounds.getCenterY(), 0.5 * bounds.getWidth(), 0.5 * bounds.getHeight()); } protected String createMaskExpression(double x0, double y0, double dx, double dy) { return String.format("sqrt(sq((%s - %s)/%s) + sq((%s - %s)/%s)) < 1.0", BandArithmetic.createExternalName(dataSourceConfig.xBand.getName()), x0, dx, BandArithmetic.createExternalName(dataSourceConfig.yBand.getName()), y0, dy); } }; densityPlotDisplay.getPopupMenu().addSeparator(); densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem()); densityPlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem()); densityPlotDisplay.getPopupMenu().addSeparator(); densityPlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem()); return densityPlotDisplay; }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();/*w w w. jav a 2s .c o m*/ Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); JFreeChart chart = chartPanel.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); ValueAxis yAxis = plot.getRangeAxis(); RectangleEdge xAxisEdge = plot.getDomainAxisEdge(); RectangleEdge yAxisEdge = plot.getRangeAxisEdge(); Rectangle2D entityBounds = entity.getBounds2D(); double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge); double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge); double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge); double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge); PlotOrientation orientation = plot.getOrientation(); //transform model to origin (0,0) in model coordinates AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(), -entityBounds.getCenterY()); //transform from origin (0,0) to model location AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(), entityBounds.getCenterY()); //transform from model scale to view scale double scaleX = viewW / entityBounds.getWidth(); double scaleY = viewH / entityBounds.getHeight(); Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}", new Object[] { scaleX, scaleY }); AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY); AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f); AffineTransform modelToView = new AffineTransform(toOrigin); modelToView.preConcatenate(flipTransform); modelToView.preConcatenate(toViewScale); modelToView.preConcatenate(toViewLocation); // // if (orientation == PlotOrientation.HORIZONTAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewY, // viewX); // } else if (orientation == PlotOrientation.VERTICAL) { // entity = ShapeUtilities.createTranslatedShape(entity, viewX, // viewY); // } FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity) .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void renderRange(LongRange pRange, LongRange pStartRange, LongRange pArriveRange, boolean pIsStartRange, boolean pIsArriveRange, Graphics2D pG2D, TimeSpan pSpanForRange, HashMap<String, Object> pPopupInfo) { int rangeStart = 0; int rangeWidth = 0; if (pRange.overlapsRange(pStartRange)) { //start range rendering long startDelta = pStartRange.getMinimumLong(); rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE); // int rangeEnd = Math.round((pRange.getMaximumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE); rangeWidth = Math/*from w w w .ja va 2 s . c o m*/ .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE); } else if (pRange.overlapsRange(pArriveRange)) { //end range rendering long startDelta = pStartRange.getMinimumLong(); rangeStart = Math.round((pRange.getMinimumLong() - startDelta) / DateUtils.MILLIS_PER_MINUTE); // int rangeEnd = Math.round((pRange.getMaximumLong() - arriveDelta) / DateUtils.MILLIS_PER_MINUTE); rangeWidth = Math .round((pRange.getMaximumLong() - pRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE); } //correct small widths if (rangeWidth == 0) { rangeWidth = 5; } long max = Math.round( (pArriveRange.getMaximumLong() - pStartRange.getMinimumLong()) / DateUtils.MILLIS_PER_MINUTE); if (rangeStart > max) { return; } SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy HH:mm:ss"); String labelString = ""; if (pSpanForRange != null) { labelString = pSpanForRange.toString(); } else { labelString = f.format(new Date(pRange.getMinimumLong())) + " bis " + f.format(new Date(pRange.getMaximumLong())); } Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(labelString, pG2D); if (pIsStartRange) { pG2D.setColor(Color.RED); pG2D.fillRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.BLACK); pG2D.drawRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.RED); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f)); pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight()); } else if (pIsArriveRange) { pG2D.setColor(Color.GREEN.darker()); pG2D.fillRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.BLACK); pG2D.drawRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.GREEN.darker()); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 14.0f)); pG2D.drawString(labelString, rangeStart, (int) labelBounds.getHeight() + 40); } else { pG2D.fillRect(rangeStart, 20, rangeWidth, 20); pG2D.setColor(Color.BLACK); pG2D.drawRect(rangeStart, 20, rangeWidth, 20); Point loc = getMousePosition(); if (loc != null && new Rectangle(rangeStart, 20, rangeWidth, 20).contains(loc)) { pPopupInfo.put("popup.location", loc); pPopupInfo.put("popup.label", labelString); pPopupInfo.put("active.range", pRange); pPopupInfo.put("span.for.range", pSpanForRange); } } }
From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java
public void drawString(Graphics g, String text, RectangularShape bounds, Align align, double angle, boolean multiline) { Graphics2D g2 = (Graphics2D) g; Font font = g2.getFont();/*from w ww. ja v a 2 s . c o m*/ if (angle != 0) { g2.setFont(font.deriveFont(AffineTransform.getRotateInstance(Math.toRadians(angle)))); } Rectangle2D sSize = g2.getFontMetrics().getStringBounds(text, g2); Point2D pos = getPoint(bounds, align); double x = pos.getX(); double y = pos.getY() + sSize.getHeight(); switch (align) { case TopCenter: case BottomCenter: case Center: x -= (sSize.getWidth() / 2); break; case TopRight: case MiddleRight: case BottomRight: x -= (sSize.getWidth()); break; case BottomLeft: case MiddleLeft: case TopLeft: break; } if (multiline) { // Create a new LineBreakMeasurer from the paragraph. // It will be cached and re-used. //if (lineMeasurer == null) { AttributedCharacterIterator paragraph = new AttributedString(text).getIterator(); paragraphStart = paragraph.getBeginIndex(); paragraphEnd = paragraph.getEndIndex(); FontRenderContext frc = g2.getFontRenderContext(); lineMeasurer = new LineBreakMeasurer(paragraph, frc); //} // Set break width to width of Component. float breakWidth = (float) bounds.getWidth(); float drawPosY = (float) y; // Set position to the index of the first character in the paragraph. lineMeasurer.setPosition(paragraphStart); // Get lines until the entire paragraph has been displayed. while (lineMeasurer.getPosition() < paragraphEnd) { // Retrieve next layout. A cleverer program would also cache // these layouts until the component is re-sized. TextLayout layout = lineMeasurer.nextLayout(breakWidth); // Compute pen x position. If the paragraph is right-to-left we // will align the TextLayouts to the right edge of the panel. // Note: this won't occur for the English text in this sample. // Note: drawPosX is always where the LEFT of the text is placed. float drawPosX = layout.isLeftToRight() ? (float) x : (float) x + breakWidth - layout.getAdvance(); // Move y-coordinate by the ascent of the layout. drawPosY += layout.getAscent(); // Draw the TextLayout at (drawPosX, drawPosY). layout.draw(g2, drawPosX, drawPosY); // Move y-coordinate in preparation for next layout. drawPosY += layout.getDescent() + layout.getLeading(); } } else { g2.drawString(text, (float) x, (float) y); } g2.setFont(font); }