List of usage examples for java.awt.geom Rectangle2D getWidth
public abstract double getWidth();
From source file:de.fhg.igd.mapviewer.BasicMapKit.java
/** * Zoom in and center on the given {@link GeoPosition}s * //ww w . ja v a 2 s. c o m * @param positions the {@link GeoPosition}s */ public void zoomToPositions(Set<GeoPosition> positions) { if (positions.size() == 0) return; positions = equalizeEpsg(positions); int epsg = positions.iterator().next().getEpsgCode(); double minX = 0, maxX = 0, minY = 0, maxY = 0; boolean init = false; for (GeoPosition pos : positions) { if (!init) { // first pos minY = maxY = pos.getY(); minX = maxX = pos.getX(); init = true; } else { if (pos.getY() < minY) minY = pos.getY(); else if (pos.getY() > maxY) maxY = pos.getY(); if (pos.getX() < minX) minX = pos.getX(); else if (pos.getX() > maxX) maxX = pos.getX(); } } // center on positions setCenterPosition(new GeoPosition((minX + maxX) / 2.0, (minY + maxY) / 2.0, epsg)); // initial zoom int zoom = getMainMap().getTileFactory().getTileProvider().getMinimumZoom(); try { if (positions.size() >= 2) { int viewWidth = (int) getMainMap().getViewportBounds().getWidth(); int viewHeight = (int) getMainMap().getViewportBounds().getHeight(); Rectangle2D rect = generateBoundingRect(minX, minY, maxX, maxY, epsg, zoom); while ((viewWidth < rect.getWidth() || viewHeight < rect.getHeight()) && zoom < getMainMap().getTileFactory().getTileProvider().getMaximumZoom()) { zoom++; rect = generateBoundingRect(minX, minY, maxX, maxY, epsg, zoom); } } setZoom(zoom); } catch (IllegalGeoPositionException e) { log.warn("Error zooming to positions");// , e); //$NON-NLS-1$ } }
From source file:org.talend.dataprofiler.chart.preview.HideSeriesGanttRenderer.java
/** * Calculates the coordinate of the first "side" of a bar. This will be the minimum x-coordinate for a vertical bar, * and the minimum y-coordinate for a horizontal bar. * // w w w . j a v a2 s.c om * @param plot the plot. * @param orientation the plot orientation. * @param dataArea the data area. * @param domainAxis the domain axis. * @param state the renderer state (has the bar width precalculated). * @param row the row index. * @param column the column index. * * @return The coordinate. */ @Override protected double calculateBarW0(CategoryPlot plot, PlotOrientation orientation, Rectangle2D dataArea, CategoryAxis domainAxis, CategoryItemRendererState state, int row, int column) { // calculate bar width... double space = 0.0; if (orientation == PlotOrientation.HORIZONTAL) { space = dataArea.getHeight(); } else { space = dataArea.getWidth(); } double barW0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); int seriesCount = getRowCount(); int categoryCount = getColumnCount(); if (seriesCount > 1) { double seriesGap = space * getItemMargin() / (categoryCount * (seriesCount - 1)); double seriesW = calculateSeriesWidth(space, domainAxis, categoryCount, seriesCount); barW0 = barW0 + row * (seriesW + seriesGap) + (seriesW / 2.0) - (state.getBarWidth() / 2.0); } else { barW0 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()) - state.getBarWidth() / 2.0; } return barW0; }
From source file:org.jfree.experimental.chart.plot.dial.DialValueIndicator.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//* www. ja va 2s . com*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.font); String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); }
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();/*from ww w .j av 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: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;//w w w . j a v a 2s . 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:net.fenyo.gnetwatch.GUI.BasicComponent.java
/** * Computes new margins./*from w ww . ja v a 2s. c o m*/ * @param none. * @return void. */ // AWT thread // lock survey: sync_update << sync_value_per_vinterval << HERE // synchro << sync_tree << sync_update << sync_value_per_vinterval << events << HERE // sync_value_per_vinterval << HERE private void setMargin() { /* final String left_values_str = "" + (int) (value_per_vinterval * (1 + (dimension.height - axis_margin_top - axis_margin_bottom) / pixels_per_vinterval)); */ final String left_values_str = "1000M"; final TextLayout layout = new TextLayout(left_values_str, backing_g.getFont(), backing_g.getFontRenderContext()); final Rectangle2D bounds = layout.getBounds(); axis_margin_left = (int) bounds.getWidth() + 5 + 10; }
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// w ww .j a va 2 s .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:com.projity.pm.graphic.pert.PertLayout.java
public void updateBounds() { dependencyGraph.updatePertLevels();/*ww w .j a v a2 s .c o m*/ GraphicConfiguration config = GraphicConfiguration.getInstance(); Point2D origin = new Point2D.Double(config.getPertXOffset(), config.getPertYOffset()); Rectangle2D ref = new Rectangle2D.Double(config.getPertXOffset(), config.getPertYOffset(), config.getPertCellWidth(), config.getPertCellHeight()); int row = 0; int col = -1; setEmpty(); for (Iterator i = cache.getIterator(); i.hasNext();) { GraphicNode current = (GraphicNode) i.next(); int currentCol = cache.getPertLevel(current) - 1; if (currentCol <= col) row++; col = currentCol; TexturedShape texturedShape = findShape(current); if (texturedShape == null) continue; double centerX = origin.getX() + ref.getMaxX() * col + ref.getWidth() / 2; double centerY = origin.getY() + ref.getMaxY() * row + ref.getHeight() / 2; //System.out.println(centerX+"/"+centerY); GeneralPath shape = texturedShape.toGeneralPath(ref.getWidth(), ref.getHeight(), centerX - ref.getWidth() / 2, centerY, null); current.setPertShape(shape, centerX, centerY); Rectangle cellBounds = network.scale(shape.getBounds()); if (isEmpty()) bounds.setBounds(cellBounds); else Rectangle.union(bounds, cellBounds, bounds); } fireLayoutChanged(); }
From source file:org.pentaho.reporting.engine.classic.core.modules.parser.simple.readhandlers.LineReadHandler.java
private void createLineElementFromBounds(final float x1, final float y1, final float x2, final float y2, final Stroke stroke, final String name, final Color c, final Rectangle2D bounds) { if (x1 == x2) { // assume that we have a vertical line final VerticalLineElementFactory elementFactory = new VerticalLineElementFactory(); elementFactory.setName(name);// w w w . ja v a 2s. c om elementFactory.setColor(c); elementFactory.setStroke(stroke); elementFactory.setX(new Float(bounds.getX())); elementFactory.setY(new Float(bounds.getY())); elementFactory.setMinimumWidth(new Float(bounds.getWidth())); elementFactory.setMinimumHeight(new Float(bounds.getHeight())); elementFactory.setScale(Boolean.TRUE); elementFactory.setKeepAspectRatio(Boolean.FALSE); elementFactory.setShouldDraw(Boolean.TRUE); element = elementFactory.createElement(); } else if (y1 == y2) { // assume that we have a horizontal line final HorizontalLineElementFactory elementFactory = new HorizontalLineElementFactory(); elementFactory.setName(name); elementFactory.setColor(c); elementFactory.setStroke(stroke); elementFactory.setX(new Float(bounds.getX())); elementFactory.setY(new Float(bounds.getY())); elementFactory.setMinimumWidth(new Float(bounds.getWidth())); elementFactory.setMinimumHeight(new Float(bounds.getHeight())); elementFactory.setScale(Boolean.TRUE); elementFactory.setKeepAspectRatio(Boolean.FALSE); elementFactory.setShouldDraw(Boolean.TRUE); element = elementFactory.createElement(); } else { // here comes the magic - we transform the line into the absolute space; // this should preserve the general appearance. Heck, and if not, then // it is part of the users reponsibility to resolve that. Magic does not // solve all problems, you know. final Line2D line = new Line2D.Float(Math.abs(x1), Math.abs(y1), Math.abs(x2), Math.abs(y2)); final Rectangle2D shapeBounds = line.getBounds2D(); final Shape transformedShape = ShapeTransform.translateShape(line, -shapeBounds.getX(), -shapeBounds.getY()); // and use that shape with the user's bounds to create the element. final ContentElementFactory elementFactory = new ContentElementFactory(); elementFactory.setName(name); elementFactory.setColor(c); elementFactory.setStroke(stroke); elementFactory.setX(new Float(shapeBounds.getX())); elementFactory.setY(new Float(shapeBounds.getY())); elementFactory.setMinimumWidth(new Float(shapeBounds.getWidth())); elementFactory.setMinimumHeight(new Float(shapeBounds.getHeight())); elementFactory.setContent(transformedShape); elementFactory.setScale(Boolean.TRUE); elementFactory.setKeepAspectRatio(Boolean.FALSE); elementFactory.setShouldDraw(Boolean.TRUE); element = elementFactory.createElement(); } }
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public Point textExtent(String text) { String[] lines = text.split(Const.CR); int maxWidth = 0; for (String line : lines) { Rectangle2D bounds = TextUtilities.getTextBounds(line, gc, gc.getFontMetrics()); if (bounds.getWidth() > maxWidth) { maxWidth = (int) bounds.getWidth(); }// ww w . ja va 2 s . c o m } int height = gc.getFontMetrics().getHeight() * lines.length; return new Point(maxWidth, height); }