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 <code>RoundRectangle2D</code> whose width and * height are defined by this instance's size and * aspect ratio functions for this vertex. The arc size is * set to be half the minimum of the height and width of the frame. *///from ww w.j a v a2 s .c o m public RoundRectangle2D getRoundRectangle(V v) { Rectangle2D frame = getRectangle(v); float arc_size = (float) Math.min(frame.getHeight(), frame.getWidth()) / 2; theRoundRectangle.setRoundRect(frame.getX(), frame.getY(), frame.getWidth(), frame.getHeight(), arc_size, arc_size); return theRoundRectangle; }
From source file:de.codesourcery.planning.swing.PlanningCanvas.java
protected static BoundingBox createBoundingBox(int x, int y, Rectangle2D stringBounds) { return BoundingBox.createFromCoordinates(new Rectangle2D.Float(x, y, x + Math.round(stringBounds.getWidth()), y + Math.round(stringBounds.getHeight()))); }
From source file:FontTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; String message = "Hello, World!"; Font f = new Font("Serif", Font.BOLD, 36); g2.setFont(f);//from w ww . ja v a2 s. c om // measure the size of the message FontRenderContext context = g2.getFontRenderContext(); Rectangle2D bounds = f.getStringBounds(message, context); // set (x,y) = top left corner of text double x = (getWidth() - bounds.getWidth()) / 2; double y = (getHeight() - bounds.getHeight()) / 2; // add ascent to y to reach the baseline double ascent = -bounds.getY(); double baseY = y + ascent; // draw the message g2.drawString(message, (int) x, (int) baseY); g2.setPaint(Color.LIGHT_GRAY); // draw the baseline g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY)); // draw the enclosing rectangle Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight()); g2.draw(rect); }
From source file:org.mwc.debrief.track_shift.views.CachedTickDateAxis.java
@SuppressWarnings("rawtypes") @Override// w w w . j a va 2 s.c o m protected List refreshTicksVertical(final Graphics2D g2, final Rectangle2D dataArea, final RectangleEdge edge) { // do we have a height? if (_lastHeight != null) { // is the new height different to our last one? if (Math.abs(dataArea.getHeight() - _lastHeight.doubleValue()) > 60) { // yes - ditch the ticks _myTicks = null; } } // do we have any ticks? if (_myTicks == null) { // nope, better create some _myTicks = super.refreshTicksVertical(g2, dataArea, edge); _lastHeight = dataArea.getHeight(); } return _myTicks; }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java
private double percentH(double y, Rectangle2D r) { return (y - r.getMinY()) / r.getHeight(); }
From source file:org.springframework.cloud.stream.app.image.recognition.processor.ImageRecognitionOutputMessageBuilder.java
/** * Augment the input image by adding the recognized classes. * * @param imageBytes input image as byte array * @param result computed recognition labels * @return the image augmented with recognized labels. *///from w w w.java 2 s.c o m private byte[] drawLabels(byte[] imageBytes, Object result) { try { if (result != null) { BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageBytes)); Graphics2D g = originalImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); FontMetrics fm = g.getFontMetrics(); Tuple resultTuple = new JsonStringToTupleConverter().convert(result.toString()); ArrayList<Tuple> labels = (ArrayList) resultTuple.getValues().get(0); int x = 1; int y = 1; for (Tuple l : labels) { String labelName = l.getFieldNames().get(0); int probability = (int) (100 * l.getFloat(0)); String title = labelName + ": " + probability + "%"; Rectangle2D rect = fm.getStringBounds(title, g); g.setColor(bgColor); g.fillRect(x, y, (int) rect.getWidth() + 6, (int) rect.getHeight()); g.setColor(textColor); g.drawString(title, x + 3, (int) (y + rect.getHeight() - 3)); y = (int) (y + rect.getHeight() + 1); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(originalImage, IMAGE_FORMAT, baos); baos.flush(); imageBytes = baos.toByteArray(); baos.close(); } } catch (IOException e) { logger.error("Failed to draw labels in the input image", e); } return imageBytes; }
From source file:com.rapidminer.gui.graphs.ExtendedVertexShapeTransformer.java
@Override public Shape transform(V object) { if (graphCreator.isLeaf(object)) { // leaf/*from ww w . j a v a 2 s . c o m*/ String text = graphCreator.getVertexName(object); Rectangle2D stringBounds = GraphViewer.VERTEX_BOLD_FONT.getStringBounds(text, new FontRenderContext(null, false, false)); float width = (float) stringBounds.getWidth(); float height = (float) stringBounds.getHeight(); int minWidth = graphCreator.getMinLeafWidth(); int minHeight = graphCreator.getMinLeafHeight(); width = Math.max(width, minWidth); height = Math.max(height, minHeight); return new Rectangle2D.Float(-width / 2.0f - 6.0f, -height / 2.0f - 2.0f, width + 8.0f, height + 4.0f); } else { // inner nodes String text = graphCreator.getVertexName(object); Rectangle2D stringBounds = GraphViewer.VERTEX_PLAIN_FONT.getStringBounds(text, new FontRenderContext(null, false, false)); float width = (float) stringBounds.getWidth(); float height = (float) stringBounds.getHeight(); RoundRectangle2D.Float shape = new RoundRectangle2D.Float(-width / 2.0f - 6.0f, -height / 2.0f - 4.0f, width + 10.0f, height + 8.0f, 10.0f, 10.0f); return shape; } }
From source file:com.projity.pm.graphic.xbs.XbsLayout.java
protected void updateBounds(int level, Point2D origin, Rectangle2D ref) {//cache in current version isn't a tree double y = origin.getY() + ref.getHeight() / 2 + ref.getMaxY() * (level - 1); Point2D childCenter, center;//from ww w .j a va 2 s . c o m double x0, x1; GraphicNode node, child; boolean hasChild; for (ListIterator i = cache.getIterator(); i.hasNext();) { node = (GraphicNode) i.next(); if (node.getLevel() == level) { x0 = -1; x1 = -1; hasChild = false; while (i.hasNext()) { child = (GraphicNode) i.next(); if (child.getLevel() <= level) { i.previous(); break; } else if (child.getLevel() == level + 1) { hasChild = true; childCenter = child.getXbsCenter(); if (x0 == -1 || childCenter.getX() < x0) x0 = childCenter.getX(); if (x1 == -1 || childCenter.getX() > x1) x1 = childCenter.getX(); dependencies.add(new GraphicDependency(node, child, null)); } } if (hasChild) setShape(node, ref, (x0 + x1) / 2, y); } } }
From source file:org.fhaes.fhrecorder.util.NumericCategoryAxis.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from ww w.j a v a 2 s. c o m*/ 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 = plot.getCategoriesForAxis(this); double max = 0.0; if (categories != null) { CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge); float r = this.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(); try { Integer intcategory = Integer.valueOf(category.toString()); int modulus = intcategory % labelEveryXCategories; if (modulus != 0) category = " "; } catch (NumberFormatException e) { } 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:com.neophob.sematrix.generator.Textwriter.java
/** * create image.// ww w . ja va 2 s . com * * @param text the text */ public void createTextImage(String text) { //only load if needed if (StringUtils.equals(text, this.text)) { return; } this.text = text; BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); FontRenderContext frc = g2.getFontRenderContext(); TextLayout layout = new TextLayout(text, font, frc); Rectangle2D rect = layout.getBounds(); int h = (int) (0.5f + rect.getHeight()); maxXPos = (int) (0.5f + rect.getWidth()) + 5; ypos = internalBufferYSize - (internalBufferYSize - h) / 2; img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_INT_RGB); g2 = img.createGraphics(); g2.setColor(color); g2.setFont(font); g2.setClip(0, 0, maxXPos, internalBufferYSize); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.drawString(text, xpos, ypos); DataBufferInt dbi = (DataBufferInt) img.getRaster().getDataBuffer(); textBuffer = dbi.getData(); g2.dispose(); wait = 0; xofs = 0; scrollRight = false; }