List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.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 * 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.//from ww w . ja v a 2 s .c o m */ 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; } rendererPane.paintComponent(g, component, screenDevice, x + h_offset, y + v_offset, d.width, d.height, true); }
From source file:org.apache.pdfbox.contentstream.PDFStreamEngine.java
/** * Process the given annotation with the specified appearance stream. * * @param annotation The annotation containing the appearance stream to process. * @param appearance The appearance stream to process. *///w w w . jav a 2 s.c om protected void processAnnotation(PDAnnotation annotation, PDAppearanceStream appearance) throws IOException { PDResources parent = pushResources(appearance); Stack<PDGraphicsState> savedStack = saveGraphicsStack(); PDRectangle bbox = appearance.getBBox(); PDRectangle rect = annotation.getRectangle(); Matrix matrix = appearance.getMatrix(); // zero-sized rectangles are not valid if (rect.getWidth() > 0 && rect.getHeight() > 0) { // transformed appearance box fixme: may be an arbitrary shape Rectangle2D transformedBox = bbox.transform(matrix).getBounds2D(); // compute a matrix which scales and translates the transformed appearance box to align // with the edges of the annotation's rectangle Matrix a = Matrix.getTranslateInstance(rect.getLowerLeftX(), rect.getLowerLeftY()); a.concatenate(Matrix.getScaleInstance((float) (rect.getWidth() / transformedBox.getWidth()), (float) (rect.getHeight() / transformedBox.getHeight()))); a.concatenate( Matrix.getTranslateInstance((float) -transformedBox.getX(), (float) -transformedBox.getY())); // Matrix shall be concatenated with A to form a matrix AA that maps from the appearance's // coordinate system to the annotation's rectangle in default user space Matrix aa = Matrix.concatenate(matrix, a); // make matrix AA the CTM getGraphicsState().setCurrentTransformationMatrix(aa); // clip to bounding box clipToRect(bbox); processStreamOperators(appearance); } restoreGraphicsStack(savedStack); popResources(parent); }
From source file:com.rapidminer.gui.plotter.charts.ChartPanelShiftController.java
@Override public void mouseDragged(MouseEvent mouseEvent) { if (!mouseEvent.isControlDown()) { return;/*from w w w . j a v a2s . c o m*/ } if (oldx > -1 && oldy > -1) { int xdif = mouseEvent.getX() - oldx; int ydif = mouseEvent.getY() - oldy; final Rectangle2D scaledDataArea = chartPanel.getScreenDataArea(); ValueAxis[] domAxes = getPlotAxis(chartPanel.getChart(), !axesSwaped); if (domAxes != null) { double[] xDelta = new double[domAxes.length]; for (int i = 0; i < domAxes.length; i++) { xDelta[i] = xdif * domAxes[i].getRange().getLength() / (scaledDataArea.getWidth()); } for (int i = 0; i < domAxes.length; i++) { domAxes[i].setRange(domAxes[i].getLowerBound() - xDelta[i], domAxes[i].getUpperBound() - xDelta[i]); } } ValueAxis[] rngAxes = getPlotAxis(chartPanel.getChart(), axesSwaped); if (rngAxes != null) { double[] yDelta = new double[rngAxes.length]; for (int i = 0; i < rngAxes.length; i++) { yDelta[i] = ydif * rngAxes[i].getRange().getLength() / (scaledDataArea.getHeight()); } if (!onlyXShift) { for (int i = 0; i < rngAxes.length; i++) { rngAxes[i].setRange(rngAxes[i].getLowerBound() + yDelta[i], rngAxes[i].getUpperBound() + yDelta[i]); } } } } oldx = mouseEvent.getX(); oldy = mouseEvent.getY(); }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.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>. * 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>. *///from www. j a va 2s . co m 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); 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); } }
From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java
private int drawText(Graphics2D graphics, String text, int hOffset) { Rectangle r = getTextBoundsRectangle(); Rectangle2D textBounds = graphics.getFontMetrics().getStringBounds(text, graphics); if (textBounds.getWidth() > r.getWidth() - 4) { int y = coords[1] + hOffset; AttributedString attributedString = new AttributedString(text); attributedString.addAttribute(TextAttribute.FONT, graphics.getFont()); AttributedCharacterIterator characterIterator = attributedString.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, graphics.getFontRenderContext()); while (measurer.getPosition() < characterIterator.getEndIndex()) { TextLayout textLayout = measurer.nextLayout((float) r.getWidth() - 4); y += textLayout.getAscent(); float x = (float) (r.getCenterX() + 2 - textLayout.getBounds().getCenterX()); textLayout.draw(graphics, x, y); y += textLayout.getDescent() + textLayout.getLeading(); }//from w w w .jav a2s . c o m return y - coords[1]; } else { graphics.drawString(text, (float) (r.getCenterX() + 2 - textBounds.getCenterX()), (float) (coords[1] + textBounds.getHeight() + hOffset)); return (int) (textBounds.getHeight() + hOffset + 3); } }
From source file:savant.view.tracks.BAMTrackRenderer.java
private void renderSNPMode(Graphics2D g2, GraphPaneAdapter gp, Resolution r) throws RenderingException { Genome genome = GenomeController.getInstance().getGenome(); if (!genome.isSequenceSet()) { throw new RenderingException("No reference sequence loaded\nSwitch to standard display mode", RenderingException.WARNING_PRIORITY); }//from w w w . ja va2 s. c om AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); List<Pileup> pileups = new ArrayList<Pileup>(); // make the pileups int length = axisRange.getXMax() - axisRange.getXMin() + 1; assert Math.abs(axisRange.getXMin()) <= Integer.MAX_VALUE; int startPosition = (int) axisRange.getXMin(); for (int j = 0; j < length; j++) { pileups.add(new Pileup(startPosition + j)); } // Go through the samrecords and edit the pileups for (Record record : data) { SAMRecord samRecord = ((BAMIntervalRecord) record).getSAMRecord(); updatePileupsFromSAMRecord(pileups, samRecord, startPosition); } double maxHeight = 0; for (Pileup p : pileups) { int current = p.getTotalCoverage(null); if (current > maxHeight) { maxHeight = current; } } gp.setXRange(axisRange.getXRange()); gp.setYRange(new Range(0, (int) Math.rint((double) maxHeight / 0.9))); double unitHeight = (Math.rint(gp.transformYPos(0) * 0.9)) / maxHeight; double unitWidth = gp.getUnitWidth(); ColourAccumulator accumulator = new ColourAccumulator(cs); List<Rectangle2D> insertions = new ArrayList<Rectangle2D>(); for (Pileup p : pileups) { int totalCoverage = p.getTotalCoverage(null); if (totalCoverage > 0) { double bottom = gp.transformYPos(0); double x = gp.transformXPos(p.getPosition()); VariantType genomeNuc = VariantType.fromChar((char) refSeq[p.getPosition() - startPosition]); VariantType snpNuc = genomeNuc; // Only record a shape if we have at least some mismatches. if (totalCoverage > p.getCoverage(genomeNuc, null)) { // Reduce height for insertions, since they don't contribute to the height. double h = unitHeight * (totalCoverage - p.getCoverage(VariantType.INSERTION, null)); recordToShapeMap.put(new PileupRecord(p, false), new Rectangle2D.Double(x, bottom - h, unitWidth, h)); } while ((genome.isSequenceSet() && (snpNuc = p.getLargestVariantType(genomeNuc)) != null) || ((snpNuc = p.getLargestVariantType(VariantType.OTHER)) != null)) { double h = unitHeight * p.getCoverage(snpNuc, null); Rectangle2D rect = new Rectangle2D.Double(x, bottom - h, unitWidth, h); accumulator.addShape(getSubPileColour(snpNuc, genomeNuc), rect); if (snpNuc == VariantType.INSERTION) { insertions.add(rect); } else { bottom -= h; } p.clearVariantType(snpNuc); } } } accumulator.fill(g2); for (Rectangle2D ins : insertions) { drawInsertion(g2, ins.getX(), ins.getY(), ins.getWidth(), ins.getHeight()); } }
From source file:de.codesourcery.planning.swing.PlanningCanvas.java
protected BoundingBox renderTitle(RenderContext ctx, boolean layoutOnly) { final String label = this.labelProvider.getTitle(); if (StringUtils.isBlank(label)) { return null; }/* ww w .jav a 2 s. c o m*/ final Rectangle2D labelBox = ctx.getLabelBounds(label); final int labelWidth = (int) labelBox.getWidth(); final int xCenter = ctx.viewport.getX() + (ctx.viewport.getWidth() / 2); final int xDraw = (int) Math.round(xCenter - (labelWidth / 2.0d)); final int yDraw = ctx.viewport.getY(); ctx.currentY += labelBox.getHeight() + ctx.options.getTitleYOffset(); if (!layoutOnly) { ctx.drawLabel(xDraw, yDraw, label); return null; } return createBoundingBox(ctx.viewport.getX(), ctx.viewport.getY(), labelBox) .incHeight(ctx.options.getTitleYOffset()); // include Y offset in bounding box }
From source file:de.iteratec.iteraplan.businesslogic.exchange.visio.informationflow.VisioInformationFlowExport.java
private Rectangle2D createLegends(Rectangle2D bounds) throws MasterNotFoundException { Page page = getTargetPage();// w w w . j a v a 2 s . c om double legendsBlockLeftX = bounds.getWidth() + MARGIN_IN; double legendsBlockTopY = bounds.getY() + bounds.getHeight() + MARGIN_IN; Coordinates position = new Coordinates(legendsBlockLeftX, legendsBlockTopY); Shape descriptionLegend = createDescriptionLegend(informationFlowOptions, page, position); double legendsBlockWidth = descriptionLegend.getWidth(); double legendsBlockHeight = descriptionLegend.getHeight(); position.incX(InchConverter.cmToInches(LEGEND_DESCRIPTION_WIDTH_CM - LEGEND_STANDARD_CELL_WIDTH_CM)); position.incY(-(MARGIN_IN + descriptionLegend.getHeight())); legendsBlockHeight += MARGIN_IN; ColorDimensionOptionsBean colorsBean = informationFlowOptions.getColorOptionsBean(); if (GraphicalExportBaseOptions.NOTHING_SELECTED != colorsBean.getDimensionAttributeId().intValue()) { double colorLegendHeight = createColorLegend(colorsBean, page, position, VISIO_SHAPE_NAME_COLOR_INDEX_SQUARE, getFieldValueFromDimension(getColorDimension()), TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE); position.incY(-(MARGIN_IN + colorLegendHeight)); legendsBlockHeight += colorLegendHeight + MARGIN_IN; } LineDimensionOptionsBean lineTypeBean = informationFlowOptions.getLineOptionsBean(); if (GraphicalExportBaseOptions.NOTHING_SELECTED != lineTypeBean.getDimensionAttributeId().intValue()) { legendsBlockHeight += createLineTypeLegend(lineTypeBean, page, position, VISIO_SHAPE_NAME_LINE_FIELD, getFieldValueFromDimension(lineDimension), TypeOfBuildingBlock.INFORMATIONSYSTEMRELEASE); } return new Rectangle2D.Double(legendsBlockLeftX, legendsBlockTopY, legendsBlockWidth, legendsBlockHeight); }
From source file:savant.view.tracks.BAMTrackRenderer.java
private void renderStrandSNPMode(Graphics2D g2, GraphPaneAdapter gp, Resolution r) throws RenderingException { Genome genome = GenomeController.getInstance().getGenome(); if (!genome.isSequenceSet()) { throw new RenderingException("No reference sequence loaded\nSwitch to standard display mode", RenderingException.WARNING_PRIORITY); }/*w w w.j a v a 2 s .c o m*/ AxisRange axisRange = (AxisRange) instructions.get(DrawingInstruction.AXIS_RANGE); int xMin = axisRange.getXMin(); int xMax = axisRange.getXMax(); ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME); List<Pileup> pileups = new ArrayList<Pileup>(); // make the pileups for (int j = xMin; j <= xMax; j++) { pileups.add(new Pileup(j)); } // Go through the samrecords and edit the pileups for (Record record : data) { SAMRecord samRecord = ((BAMIntervalRecord) record).getSAMRecord(); updatePileupsFromSAMRecord(pileups, samRecord, xMin); } double maxHeight = 0.0; for (Pileup p : pileups) { int current1 = p.getTotalCoverage(Strand.REVERSE); int current2 = p.getTotalCoverage(Strand.FORWARD); if (current1 > maxHeight) { maxHeight = current1; } if (current2 > maxHeight) { maxHeight = current2; } } int yMax = (int) Math.ceil(maxHeight / 0.9); gp.setYRange(new Range(-yMax, yMax)); instructions.put(DrawingInstruction.AXIS_RANGE, new AxisRange(xMin, xMax, -yMax, yMax)); ColourAccumulator accumulator = new ColourAccumulator(cs); List<Rectangle2D> insertions = new ArrayList<Rectangle2D>(); double unitHeight = gp.getUnitHeight(); double unitWidth = gp.getUnitWidth(); double axis = gp.transformYPos(0.0); for (Pileup p : pileups) { if (p.getTotalCoverage(null) > 0) { VariantType snpNuc = null; double bottom = axis; double top = axis; double x = gp.transformXPos(p.getPosition()); VariantType genomeNuc = null; if (genome.isSequenceSet()) { genomeNuc = VariantType.fromChar((char) refSeq[p.getPosition() - xMin]); snpNuc = genomeNuc; } // Only record a shape if we have at least some mismatches. int totalCoverage = p.getTotalCoverage(null); if (totalCoverage > p.getCoverage(genomeNuc, null)) { double h = unitHeight * (totalCoverage - p.getCoverage(VariantType.INSERTION, null)); recordToShapeMap .put(new PileupRecord(p, true), new Rectangle2D.Double(x, bottom - unitHeight * (p.getTotalCoverage(Strand.FORWARD) - p.getCoverage(VariantType.INSERTION, Strand.FORWARD)), unitWidth, h)); } while ((genome.isSequenceSet() && (snpNuc = p.getLargestVariantType(genomeNuc)) != null) || ((snpNuc = p.getLargestVariantType(null)) != null)) { int forwardCoverage = p.getCoverage(snpNuc, Strand.FORWARD); int reverseCoverage = p.getCoverage(snpNuc, Strand.REVERSE); ColourKey col = getSubPileColour(snpNuc, genomeNuc); if (forwardCoverage > 0) { double h = unitHeight * forwardCoverage; Rectangle2D rect = new Rectangle2D.Double(x, bottom - h, unitWidth, h); accumulator.addShape(col == ColourKey.REVERSE_STRAND ? ColourKey.FORWARD_STRAND : col, rect); if (snpNuc == VariantType.INSERTION) { insertions.add(rect); } else { bottom -= h; } } if (reverseCoverage > 0) { double h = unitHeight * reverseCoverage; Rectangle2D rect = new Rectangle2D.Double(x, top, unitWidth, h); accumulator.addShape(col, rect); if (snpNuc == VariantType.INSERTION) { insertions.add(rect); } else { top += h; } } p.clearVariantType(snpNuc); } } } accumulator.fill(g2); for (Rectangle2D ins : insertions) { drawInsertion(g2, ins.getX(), ins.getY(), ins.getWidth(), ins.getHeight()); } g2.setColor(Color.BLACK); g2.draw(new Line2D.Double(0, axis, gp.getWidth(), axis)); }
From source file:com.newatlanta.bluedragon.CategoryAxis.java
public AxisSpace reserveSpace(Graphics2D g2, Plot plot, Rectangle2D plotArea, RectangleEdge edge, AxisSpace space) {//from ww w . j a v a 2s . c om // create a new space object if one wasn't supplied... if (space == null) { space = new AxisSpace(); } // if the axis is not visible, no additional space is required... if (!isVisible()) { return space; } // calculate the max size of the tick labels (if visible)... double tickLabelHeight = 0.0; double tickLabelWidth = 0.0; if (isTickLabelsVisible()) { g2.setFont(getTickLabelFont()); AxisState state = new AxisState(); // we call refresh ticks just to get the maximum width or height if (RectangleEdge.isTopOrBottom(edge)) { // BEGIN fix for category labels that wrap // If space has been reserved to the left and right then we need to // reduce the plot area // by this amount so that the space needed by category labels that wrap // on to multiple lines // will be calculated properly. Rectangle2D newPlotArea = new Rectangle2D.Double(plotArea.getX(), plotArea.getY(), plotArea.getWidth() - space.getLeft() - space.getRight(), plotArea.getHeight()); refreshTicks(g2, state, newPlotArea, edge); // END fix for category labels that wrap } else { refreshTicks(g2, state, plotArea, edge); } if (edge == RectangleEdge.TOP) { tickLabelHeight = state.getMax(); } else if (edge == RectangleEdge.BOTTOM) { tickLabelHeight = state.getMax(); } else if (edge == RectangleEdge.LEFT) { tickLabelWidth = state.getMax(); } else if (edge == RectangleEdge.RIGHT) { tickLabelWidth = state.getMax(); } } // get the axis label size and update the space object... Rectangle2D labelEnclosure = getLabelEnclosure(g2, edge); double labelHeight = 0.0; double labelWidth = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { labelHeight = labelEnclosure.getHeight(); space.add(labelHeight + tickLabelHeight + this.getCategoryLabelPositionOffset(), edge); } else if (RectangleEdge.isLeftOrRight(edge)) { labelWidth = labelEnclosure.getWidth(); space.add(labelWidth + tickLabelWidth + this.getCategoryLabelPositionOffset(), edge); } return space; }