public void layout(RenderableNode start) { LayoutTree layoutTree = new LayoutTree(start); TreeLayout<RenderableNode> layout = new TreeLayout<>(layoutTree, new FixedNodeExtentProvider<RenderableNode>(10, 5), new DefaultConfiguration<RenderableNode>(4, 2)); Map<RenderableNode, Rectangle2D.Double> bounds = layout.getNodeBounds(); for (Map.Entry<RenderableNode, Rectangle2D.Double> entry : bounds.entrySet()) { RenderableNode node = entry.getKey(); Rectangle2D.Double rect = entry.getValue(); node.setPosition((float) rect.getX(), (float) rect.getY()); } }
private void clearPathGraphics(Rectangle2D.Double bounds, Graphics2D gfx) throws IOException { Color transparent = new Color(255, 255, 255, 0); gfx.setColor(transparent); gfx.fillRect(0, 0, (int) bounds.getWidth() * 2, (int) bounds.getHeight() * 2); Color fill = pdfColorToColor(state.getNonStrokingColor()); Color stroke = pdfColorToColor(state.getStrokingColor()); // crop off rendered path whitespace gfx.translate(-bounds.getX(), -bounds.getY()); gfx.setPaint(stroke); gfx.setColor(fill); }
private static void createOutputFiles(Bin[] bins) throws IOException { for (int i = 0; i < bins.length; i++) { PrintWriter writer = new PrintWriter("Bin-" + String.valueOf(i + 1) + ".txt", "UTF-8"); writer.println(bins[i].getPlacedPieces().length); MArea[] areasInThisbin = bins[i].getPlacedPieces(); for (MArea area : areasInThisbin) { double offsetX = area.getBoundingBox2D().getX(); double offsetY = area.getBoundingBox2D().getY(); writer.println(area.getID() + " " + area.getRotation() + " " + offsetX + "," + offsetY); } writer.close(); System.out.println("Generated points file for bin " + String.valueOf(i + 1)); } }
private void drawTextBox(Graphics2D g2D, String text, int x0, int y0, Color color) { final FontMetrics fontMetrics = g2D.getFontMetrics(); final Rectangle2D textBounds = fontMetrics.getStringBounds(text, g2D); x0 -= textBounds.getWidth() / 2; textBounds.setRect(textBounds.getX() - 1, textBounds.getY(), textBounds.getWidth(), textBounds.getHeight()); Rectangle2D.Double r = new Rectangle2D.Double(x0 + textBounds.getX() - 2.0, y0 + textBounds.getY() - 2.0, textBounds.getWidth() + 4.0, textBounds.getHeight() + 4.0); if (r.getMaxX() > getWidth()) { r.setRect(getWidth() - r.getWidth(), r.getY(), r.getWidth(), r.getHeight()); } if (r.getMinX() < 0) { r.setRect(0, r.getY(), r.getWidth(), r.getHeight()); } if (r.getMaxY() > getHeight()) { r.setRect(r.getX(), getHeight() - r.getHeight(), r.getWidth(), r.getHeight()); } if (r.getMinY() < 0) { r.setRect(r.getX(), 0, r.getWidth(), r.getHeight()); } g2D.setColor(color); g2D.fill(r); g2D.setColor(Color.black); g2D.draw(r); g2D.drawString(text, x0, y0); }
/** * Divides the rectangular space where a piece was just placed following the * maximal rectangles splitting strategy. Method called from * {@link #boundingBoxPacking} * * @param usedFreeArea rectangular area that contains the newly placed piece. * @param justPlacedPieceBB bounding box of the newly placed piece. * @param freeRectangles list of free spaces in the bin. */ private void splitScheme(Rectangle2D.Double usedFreeArea, Rectangle2D.Double justPlacedPieceBB, ArrayList<Rectangle2D.Double> freeRectangles) { freeRectangles.remove(usedFreeArea); // top double widht = usedFreeArea.getWidth(); double height = justPlacedPieceBB.getY() - usedFreeArea.getY(); if (height > 0) { Rectangle2D.Double upR = new Rectangle2D.Double(usedFreeArea.getX(), usedFreeArea.getY(), widht, height); freeRectangles.add(upR); } // right widht = usedFreeArea.getMaxX() - justPlacedPieceBB.getMaxX(); height = usedFreeArea.getHeight(); if (widht > 0) { Rectangle2D.Double rightR = new Rectangle2D.Double(justPlacedPieceBB.getMaxX(), usedFreeArea.getY(), widht, height); freeRectangles.add(rightR); } }
protected void updateWidget() { Font font = editedFigure.getFont(); font = font.deriveFont(font.getStyle(), (float) (editedFigure.getFontSize() * view.getScaleFactor())); textField.setFont(font); textField.setForeground(editedFigure.getTextColor()); textField.setBackground(editedFigure.getFillColor()); Rectangle2D.Double fDrawBounds = editedFigure.getBounds(); Point2D.Double fDrawLoc = new Point2D.Double(fDrawBounds.getX(), fDrawBounds.getY()); if (editedFigure.get(TRANSFORM) != null) { editedFigure.get(TRANSFORM).transform(fDrawLoc, fDrawLoc); } Point fViewLoc = view.drawingToView(fDrawLoc); Rectangle fViewBounds = view.drawingToView(fDrawBounds); fViewBounds.x = fViewLoc.x; fViewBounds.y = fViewLoc.y; Dimension tfDim = textField.getPreferredSize(); Insets tfInsets = textField.getInsets(); float fontBaseline = textField.getGraphics().getFontMetrics(font).getMaxAscent(); double fBaseline = editedFigure.getBaseline() * view.getScaleFactor(); textField.setBounds( fViewBounds.x - tfInsets.left, fViewBounds.y - tfInsets.top - (int) (fontBaseline - fBaseline), Math.max(fViewBounds.width + tfInsets.left + tfInsets.right, tfDim.width), Math.max(fViewBounds.height + tfInsets.top + tfInsets.bottom, tfDim.height) ); }
private void drawTiles(final Graphics2D g, final List<Tile> images, final GameData data, final Rectangle2D.Double bounds, final List<Tile> undrawn) { for (final Tile tile : tileManager.getTiles(bounds)) { tile.acquireLock(); try { final Image img; if (tile.isDirty()) { // take what we can get to avoid screen flicker undrawn.add(tile); img = tile.getRawImage(); } else { img = tile.getImage(data, uiContext.getMapData()); images.add(tile); } if (img != null) { final AffineTransform t = new AffineTransform(); t.translate(scale * (tile.getBounds().x - bounds.getX()), scale * (tile.getBounds().y - bounds.getY())); g.drawImage(img, t, this); } } finally { tile.releaseLock(); } } }
public ImageResource drawPath(List<PathSegment> path) throws IOException { if (path.size() == 0) return new ImageResource("PathImage", new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)); Rectangle2D.Double bounds = getPathBounds(path); if (bounds.getHeight() <= 0 || bounds.getWidth() <= 0) { bounds.width = bounds.height = 1; log.info("Filled curved paths are not yet supported by Pdf2Dom."); } BufferedImage image = new BufferedImage((int) bounds.getWidth(), (int) bounds.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gfx = image.createGraphics(); clearPathGraphics(bounds, gfx); drawPathSegments(path, gfx); gfx.dispose(); // keep track of whitespace cropped off for html element positioning ImageResource drawnPath = new ImageResource("PathImage", image); drawnPath.setX(bounds.getX()); drawnPath.setY(bounds.getY()); return drawnPath; }
private void updateRectanglesForDragCursor() { Rectangle2D.Double rectangleForDragCursor = new Rectangle2D.Double(movableRectangle.getX() + OFFSET, movableRectangle.getY() + OFFSET, movableRectangle.getWidth() - 2 * OFFSET, movableRectangle.getHeight() - 2 * OFFSET); rectangleMap.get(MOVE).setRect(rectangleForDragCursor); final double x = rectangleForDragCursor.getX(); final double y = rectangleForDragCursor.getY(); final double width = rectangleForDragCursor.getWidth(); final double height = rectangleForDragCursor.getHeight(); setRectangle(DEFAULT, x - 2 * OFFSET, y - 2 * OFFSET, width + 4 * OFFSET, height + 4 * OFFSET); setRectangle(NORTH, x, y - 2 * OFFSET, width, 2 * OFFSET); setRectangle(SOUTH, x, y + height, width, 2 * OFFSET); setRectangle(WEST, x - 2 * OFFSET, y, 2 * OFFSET, height); setRectangle(EAST, x + width, y, 2 * OFFSET, height); setRectangle(NORTH_WEST, x - 2 * OFFSET, y - 2 * OFFSET, 2 * OFFSET, 2 * OFFSET); setRectangle(NORTH_EAST, x + width, y - 2 * OFFSET, 2 * OFFSET, 2 * OFFSET); setRectangle(SOUTH_WEST, x - 2 * OFFSET, y + height, 2 * OFFSET, 2 * OFFSET); setRectangle(SOUTH_EAST, x + width, y + height, 2 * OFFSET, 2 * OFFSET); }
private Rectangle2D getTextBox(final Graphics2D g2d, final String text, final int x0, final int y0) { final FontMetrics fontMetrics = g2d.getFontMetrics(); final Rectangle2D textBounds = fontMetrics.getStringBounds(text, g2d); Rectangle2D.Double r = new Rectangle2D.Double(x0 + textBounds.getX() - 2.0, y0 + textBounds.getY() - 2.0, textBounds.getWidth() + 4.0, textBounds.getHeight() + 4.0); if (r.getMaxX() > getWidth()) { r.setRect(getWidth() - r.getWidth(), r.getY(), r.getWidth(), r.getHeight()); } if (r.getMinX() < 0) { r.setRect(0, r.getY(), r.getWidth(), r.getHeight()); } if (r.getMaxY() > getHeight()) { r.setRect(r.getX(), getHeight() - r.getHeight(), r.getWidth(), r.getHeight()); } if (r.getMinY() < 0) { r.setRect(r.getX(), 0, r.getWidth(), r.getHeight()); } return r; }
private void updateRectanglesForDragCursor() { Rectangle2D.Double rectangleForDragCursor = new Rectangle2D.Double(movableRectangle.getX() + OFFSET, movableRectangle.getY() + OFFSET, movableRectangle.getWidth() - 2 * OFFSET, movableRectangle.getHeight() - 2 * OFFSET); rectangleMap.get(MOVE).setRect(rectangleForDragCursor); final double x = rectangleForDragCursor.getX(); final double y = rectangleForDragCursor.getY(); final double width = rectangleForDragCursor.getWidth(); final double height = rectangleForDragCursor.getHeight(); setRectangle(DEFAULT, x - 2 * OFFSET, y - 2 * OFFSET, width + 4 * OFFSET, height + 4 * OFFSET); setRectangle(NORTH, x, y - 2 * OFFSET, width, 2 * OFFSET); setRectangle(SOUTH, x, y + height, width, 2 * OFFSET); setRectangle(WEST, x - 2 * OFFSET, y, 2 * OFFSET, height); setRectangle(EAST, x + width, y, 2 * OFFSET, height); setRectangle(NORTH_WEST, x - 2 * OFFSET, y - 2 * OFFSET, 2 * OFFSET, 2 * OFFSET); setRectangle(NORTH_EAST, x + width, y - 2 * OFFSET, 2 * OFFSET, 2 * OFFSET); setRectangle(SOUTH_WEST, x - 2 * OFFSET, y + height, 2 * OFFSET, 2 * OFFSET); setRectangle(SOUTH_EAST, x + width, y + height, 2 * OFFSET, 2 * OFFSET); }
private Set<Node> getNodesInTravelZone(final Network network) { double minX = travelZone.getX(); double maxX = travelZone.getWidth() + minX; double minY = travelZone.getY(); double maxY = travelZone.getHeight() + minY; // largen the zone... maxX += (maxX - minX) * ZONE_EXPANSION; minX -= (maxX - minX) * ZONE_EXPANSION; maxY += (maxY - minY) * ZONE_EXPANSION; minY -= (maxY - minY) * ZONE_EXPANSION; Set<Node> resultNodes = new TreeSet<Node>(); for (Node n : network.getNodes().values()) { if (n.getCoord().getX() <= maxX && n.getCoord().getX() >= minX && n.getCoord().getY() <= maxY && n.getCoord().getY() >= minY) { resultNodes.add(n); } } return resultNodes; }
/** * Moves the figure. This is the * method that subclassers override. Clients usually * call displayBox. */ @Override public void setBounds(Point2D.Double anchor, Point2D.Double lead) { if (getLayouter() == null) { super.setBounds(anchor, lead); basicSetPresentationFigureBounds(anchor, lead); } else { Rectangle2D.Double r = getLayouter().layout(this, anchor, lead); basicSetPresentationFigureBounds(new Point2D.Double(r.getX(), r.getY()), new Point2D.Double( Math.max(lead.x, (int) r.getMaxX()), Math.max(lead.y, (int) r.getMaxY()))); invalidate(); } }
@Override public void paint(Graphics2D g2) { if (snappingWidth == 0 || snappingHeight == 0) return; Color oldColor = g2.getColor(); Rectangle2D.Double bounds = getBounds(g2); g2.setColor(Color.WHITE); g2.fill(bounds); g2.setColor(ThemeManager.getInstance().getTheme().getGridColor()); Stroke oldStroke = g2.getStroke(); for (double x = bounds.getX(); x < bounds.getMaxX(); x += snappingWidth) g2.draw(new Line2D.Double(x, bounds.getY(), x, bounds.getMaxY())); for (double y = bounds.getY(); y < bounds.getMaxY(); y += snappingHeight) g2.draw(new Line2D.Double(bounds.getX(), y, bounds.getMaxX(), y)); g2.setStroke(oldStroke); g2.setColor(oldColor); }
private void createOutputFiles(Bin[] bins) throws IOException { for (int i = 0; i < bins.length; i++) { PrintWriter writer = new PrintWriter("Bin-" + String.valueOf(i + 1) + ".txt", "UTF-8"); writer.println(bins[i].getPlacedPieces().length); MArea[] areasInThisbin = bins[i].getPlacedPieces(); for (MArea area : areasInThisbin) { double offsetX = area.getBoundingBox2D().getX(); double offsetY = area.getBoundingBox2D().getY(); writer.println(area.getID() + " " + area.getRotation() + " " + offsetX + "," + offsetY); } writer.close(); System.out.println("Generated points file for bin " + String.valueOf(i + 1)); } } }
private Rectangle2D.Double createRectangle(Rectangle2D.Double rectangularShape) { return new Rectangle2D.Double(rectangularShape.getX(), rectangularShape.getY(), rectangularShape.getWidth(), rectangularShape.getHeight()); }
public final void insert(final Rectangle2D.Double rect, final T sampled) { samplesRTree.insert(new float[]{(float) rect.getX(), (float) rect.getY()}, new float[]{(float) rect.getWidth(), (float) rect.getHeight()}, sampled); }
private Rectangle2D.Double createRectangle(Rectangle2D.Double rectangularShape) { return new Rectangle2D.Double(rectangularShape.getX(), rectangularShape.getY(), rectangularShape.getWidth(), rectangularShape.getHeight()); }
/** * Gets the text position. * * @return the text position */ public static Point getTextPosition() { createTextArea(); return new Point( (int) (splashTextArea.getX() + TEXTPOSITION_X_OFFSET), (int) (splashTextArea.getY() + TEXTPOSITION_Y_OFFSET)); }