List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java
/** * Returns a regular <code>num_sides</code>-sided * <code>Polygon</code> whose bounding * box's width and height are defined by this instance's size and * aspect ratio functions for this vertex. * @param num_sides the number of sides of the polygon; must be >= 3. *//*from www. j av a2 s . c o m*/ public Shape getRegularPolygon(V v, int num_sides) { if (num_sides < 3) throw new IllegalArgumentException("Number of sides must be >= 3"); Rectangle2D frame = getRectangle(v); float width = (float) frame.getWidth(); float height = (float) frame.getHeight(); // generate coordinates double angle = 0; thePolygon.reset(); thePolygon.moveTo(0, 0); thePolygon.lineTo(width, 0); double theta = (2 * Math.PI) / num_sides; for (int i = 2; i < num_sides; i++) { angle -= theta; float delta_x = (float) (width * Math.cos(angle)); float delta_y = (float) (width * Math.sin(angle)); Point2D prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); } thePolygon.closePath(); // scale polygon to be right size, translate to center at (0,0) Rectangle2D r = thePolygon.getBounds2D(); double scale_x = width / r.getWidth(); double scale_y = height / r.getHeight(); float translationX = (float) (r.getMinX() + r.getWidth() / 2); float translationY = (float) (r.getMinY() + r.getHeight() / 2); AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y); at.translate(-translationX, -translationY); Shape shape = at.createTransformedShape(thePolygon); return shape; }
From source file:org.apache.fop.render.svg.SVGRenderer.java
/** {@inheritDoc} */ public void renderPage(PageViewport pageViewport) throws IOException { log.debug("Rendering page: " + pageViewport.getPageNumberString()); // Get a DOMImplementation DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); // Create an instance of org.w3c.dom.Document this.document = domImpl.createDocument(null, "svg", null); // Create an SVGGeneratorContext to customize SVG generation SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(this.document); ctx.setComment("Generated by " + userAgent.getProducer() + " with Batik SVG Generator"); ctx.setEmbeddedFontsOn(true);/* w ww .j a va2 s . c om*/ // Create an instance of the SVG Generator this.svgGenerator = new SVGGraphics2D(ctx, true); Rectangle2D viewArea = pageViewport.getViewArea(); Dimension dim = new Dimension(); dim.setSize(viewArea.getWidth() / 1000, viewArea.getHeight() / 1000); this.svgGenerator.setSVGCanvasSize(dim); AffineTransform at = this.svgGenerator.getTransform(); this.state = new Java2DGraphicsState(this.svgGenerator, this.fontInfo, at); try { //super.renderPage(pageViewport); renderPageAreas(pageViewport.getPage()); } finally { this.state = null; } writeSVGFile(pageViewport.getPageIndex()); this.svgGenerator = null; this.document = null; }
From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java
/** * Calculates the size of a chart for a given fixed plot width and height * /* w ww.j a v a 2 s . co m*/ * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotSize(ChartViewer myChart, double plotWidth, double plotHeight, int iterations) { makeChartResizable(myChart); // estimate plotwidth / height double estimatedChartWidth = plotWidth + 200; double estimatedChartHeight = plotHeight + 200; double lastW = estimatedChartWidth; double lastH = estimatedChartHeight; // paint and get closer try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.getCanvas().setWidth((int) estimatedChartWidth); myChart.getCanvas().setHeight((int) estimatedChartHeight); myChart.getCanvas().draw(); // rendering info ChartRenderingInfo info = myChart.getRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // // calc title space: will be added later to the right plot size // double titleWidth = chartArea.getWidth()-dataArea.getWidth(); // double titleHeight = chartArea.getHeight()-dataArea.getHeight(); // calc width and height estimatedChartWidth = estimatedChartWidth - dataArea.getWidth() + plotWidth; estimatedChartHeight = estimatedChartHeight - dataArea.getHeight() + plotHeight; if ((int) lastW == (int) estimatedChartWidth && (int) lastH == (int) estimatedChartHeight) break; else { lastW = estimatedChartWidth; lastH = estimatedChartHeight; } } } catch (Exception ex) { ex.printStackTrace(); } return new Dimension((int) estimatedChartWidth, (int) estimatedChartHeight); }
From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java
/** * Returns a regular <code>Polygon</code> of <code>num_points</code> * points whose bounding // www . j a v a 2 s .co m * box's width and height are defined by this instance's size and * aspect ratio functions for this vertex. * @param num_points the number of points of the polygon; must be >= 5. */ public Shape getRegularStar(V v, int num_points) { if (num_points < 5) throw new IllegalArgumentException("Number of sides must be >= 5"); Rectangle2D frame = getRectangle(v); float width = (float) frame.getWidth(); float height = (float) frame.getHeight(); // generate coordinates double theta = (2 * Math.PI) / num_points; double angle = -theta / 2; thePolygon.reset(); thePolygon.moveTo(0, 0); float delta_x = width * (float) Math.cos(angle); float delta_y = width * (float) Math.sin(angle); Point2D prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); for (int i = 1; i < num_points; i++) { angle += theta; delta_x = width * (float) Math.cos(angle); delta_y = width * (float) Math.sin(angle); prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); angle -= theta * 2; delta_x = width * (float) Math.cos(angle); delta_y = width * (float) Math.sin(angle); prev = thePolygon.getCurrentPoint(); thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y); } thePolygon.closePath(); // scale polygon to be right size, translate to center at (0,0) Rectangle2D r = thePolygon.getBounds2D(); double scale_x = width / r.getWidth(); double scale_y = height / r.getHeight(); float translationX = (float) (r.getMinX() + r.getWidth() / 2); float translationY = (float) (r.getMinY() + r.getHeight() / 2); AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y); at.translate(-translationX, -translationY); Shape shape = at.createTransformedShape(thePolygon); return shape; }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Calculates the size of a chart for a given fixed plot width and height * //ww w .j a v a 2 s. co m * @param chart * @param plotWidth * @return */ public static Dimension calcSizeForPlotSize(ChartPanel myChart, double plotWidth, double plotHeight, int iterations) { makeChartResizable(myChart); // estimate plotwidth / height double estimatedChartWidth = plotWidth + 200; double estimatedChartHeight = plotHeight + 200; double lastW = estimatedChartWidth; double lastH = estimatedChartHeight; // paint and get closer try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) estimatedChartWidth, (int) estimatedChartHeight); myChart.paintImmediately(myChart.getBounds()); // rendering info ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // // calc title space: will be added later to the right plot size // double titleWidth = chartArea.getWidth()-dataArea.getWidth(); // double titleHeight = chartArea.getHeight()-dataArea.getHeight(); // calc width and height estimatedChartWidth = estimatedChartWidth - dataArea.getWidth() + plotWidth; estimatedChartHeight = estimatedChartHeight - dataArea.getHeight() + plotHeight; if ((int) lastW == (int) estimatedChartWidth && (int) lastH == (int) estimatedChartHeight) break; else { lastW = estimatedChartWidth; lastH = estimatedChartHeight; } } } catch (Exception ex) { ex.printStackTrace(); } return new Dimension((int) estimatedChartWidth, (int) estimatedChartHeight); }
From source file:com.willwinder.universalgcodesender.uielements.helpers.Overlay.java
/** Updates the Overlay. It is assumed this method will be called only once per frame.//from w ww .java 2 s. c o m */ public void draw(String text) { if (StringUtils.isNotBlank(text)) { text = text.trim(); renderer.beginRendering(drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); Rectangle2D bounds = renderer.getBounds(text); int width = (int) bounds.getWidth(); int height = (int) bounds.getHeight(); int offset = (int) (height * 0.5f); // Figure out the location at which to draw the text int x = 0; int y = 0; switch (textLocation) { case UPPER_LEFT: x = offset; y = drawable.getSurfaceHeight() - height - offset; break; case UPPER_RIGHT: x = drawable.getSurfaceWidth() - width - offset; y = drawable.getSurfaceHeight() - height - offset; break; case LOWER_LEFT: x = offset; y = offset; break; case LOWER_RIGHT: x = drawable.getSurfaceWidth() - width - offset; y = offset; break; default: break; } renderer.draw(text, x, y); renderer.endRendering(); } }
From source file:com.projity.pm.graphic.xbs.XbsLayout.java
protected int updateBounds(Point2D origin, Rectangle2D ref) {//cache in current version isn't a tree double x = origin.getX() + ref.getWidth() / 2; double y = origin.getY() + ref.getHeight() / 2; GraphicNode node, previous = null;/*w ww .java 2 s . co m*/ int maxLevel = 0; for (ListIterator i = cache.getIterator(); i.hasNext();) { node = (GraphicNode) i.next(); if (node.getLevel() > maxLevel) maxLevel = node.getLevel(); if (previous != null && node.getLevel() <= previous.getLevel()) { setShape(previous, ref, x, y + (previous.getLevel() - 1) * (ref.getMaxY())); x += ref.getMaxX(); } previous = node; } if (previous != null) { setShape(previous, ref, x, y + (previous.getLevel() - 1) * (ref.getMaxY())); } return maxLevel; }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static Rectangle2D getDomainMaskFrame(RangeMask mask, Rectangle2D imageArea, JFreeChart chart) { XYPlot plot = chart.getXYPlot();/* w w w . j av a 2 s . c o m*/ // boolean isDomainInverted = plot.getDomainAxis().isInverted(); // Range domainRange = plot.getDomainAxis().getRange(); // Range imageRange = new Range(imageArea.getMinX(), imageArea.getMaxX()); // Range dataRange = translateDomainRange(mask.getRange(), // imageRange, domainRange, isDomainInverted); double lowerData = plot.getDomainAxis().valueToJava2D(mask.getMin(), imageArea, RectangleEdge.BOTTOM); double upperData = plot.getDomainAxis().valueToJava2D(mask.getMax(), imageArea, RectangleEdge.BOTTOM); return new Rectangle2D.Double(Math.min(lowerData, upperData), imageArea.getMinY(), Math.abs(upperData - lowerData), imageArea.getHeight()); }
From source file:org.jfree.eastwood.GCategoryAxis.java
/** * Creates a temporary list of ticks that can be used when drawing the axis. * * @param g2 the graphics device (used to get font measurements). * @param state the axis state.// w w w . ja v a2s . co m * @param dataArea the area inside the axes. * @param edge the location of the axis. * * @return A list of ticks. */ public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { List ticks = new java.util.ArrayList(); // sanity check for data area... if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) { return ticks; } CategoryPlot plot = (CategoryPlot) getPlot(); List categories = null; if (this.labels == null) { categories = plot.getCategories(); } else { categories = new java.util.ArrayList(this.labels); // handle a little quirk in the Google Chart API - for a horizontal // bar chart, the labels on the axis get applied in reverse order // relative to the data values if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { Collections.reverse(categories); } } double max = 0.0; if (categories != null) { CategoryLabelPosition position = getCategoryLabelPositions().getLabelPosition(edge); float r = getMaximumCategoryLabelWidthRatio(); if (r <= 0.0) { r = position.getWidthRatio(); } float l = 0.0f; if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) { l = (float) calculateCategorySize(categories.size(), dataArea, edge); } else { if (RectangleEdge.isLeftOrRight(edge)) { l = (float) dataArea.getWidth(); } else { l = (float) dataArea.getHeight(); } } int categoryIndex = 0; Iterator iterator = categories.iterator(); while (iterator.hasNext()) { Comparable category = (Comparable) iterator.next(); TextBlock label = createLabel(category, l * r, edge, g2); if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) { max = Math.max(max, calculateTextBlockHeight(label, position, g2)); } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) { max = Math.max(max, calculateTextBlockWidth(label, position, g2)); } Tick tick = new CategoryTick(category, label, position.getLabelAnchor(), position.getRotationAnchor(), position.getAngle()); ticks.add(tick); categoryIndex = categoryIndex + 1; } } state.setMax(max); return ticks; }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.PanHandlerFX.java
/** * Handles a mouse pressed event by recording the initial mouse pointer * location.//from w w w. j a v a 2 s . com * * @param canvas the JavaFX canvas (<code>null</code> not permitted). * @param e the mouse event (<code>null</code> not permitted). */ @Override public void handleMousePressed(ChartCanvas canvas, MouseEvent e) { Plot plot = canvas.getChart().getPlot(); if (!(plot instanceof Pannable)) { canvas.clearLiveHandler(); return; } Pannable pannable = (Pannable) plot; if (pannable.isDomainPannable() || pannable.isRangePannable()) { Point2D point = new Point2D.Double(e.getX(), e.getY()); Rectangle2D dataArea = canvas.findDataArea(point); if (dataArea != null && dataArea.contains(point)) { this.panW = dataArea.getWidth(); this.panH = dataArea.getHeight(); this.panLast = point; canvas.setCursor(javafx.scene.Cursor.MOVE); } } // the actual panning occurs later in the mouseDragged() method }