Search in sources :

Example 41 with Rectangle2D

use of java.awt.geom.Rectangle2D in project android by JetBrains.

the class ConnectionDraw method drawCircledText.

/**
     * Utility function to draw a circle text centered at coordinates (x, y)
     *
     * @param g    graphics context
     * @param font the font we use to draw the text
     * @param text the text to display
     * @param x    x coordinate
     * @param y    y coordinate
     */
public static void drawCircledText(Graphics2D g, Font font, String text, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics();
    int padding = 4;
    Rectangle2D bounds = fm.getStringBounds(text, g2);
    double th = bounds.getHeight();
    double tw = bounds.getWidth();
    float radius = (float) (Math.max(th, tw) / 2f + padding);
    Ellipse2D.Float circle = new Ellipse2D.Float(x - radius, y - radius, 2 * radius + 1, 2 * radius + 1);
    g2.fill(circle);
    g2.setColor(Color.BLACK);
    g2.drawString(text, (int) (x - tw / 2), (y + fm.getAscent() / 2));
    if (DEBUG) {
        g2.setColor(Color.RED);
        g2.drawLine(x - 50, y, x + 50, y);
        g2.drawLine(x, y - 50, x, y + 50);
    }
    g2.dispose();
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D) Ellipse2D(java.awt.geom.Ellipse2D) Graphics2D(java.awt.Graphics2D)

Example 42 with Rectangle2D

use of java.awt.geom.Rectangle2D in project GDSC-SMLM by aherbert.

the class FIRE method initialise.

/**
	 * Initialise this instance with localisation results for the FIRE computation.
	 *
	 * @param results
	 *            the results
	 * @param results2
	 *            the second set of results (can be null)
	 */
public void initialise(MemoryPeakResults results, MemoryPeakResults results2) {
    this.results = verify(results);
    this.results2 = verify(results2);
    nmPerPixel = 1;
    units = "px";
    if (this.results == null)
        return;
    // Use the float data bounds. This prevents problems if the data is far from the origin.
    dataBounds = results.getDataBounds();
    if (this.results2 != null) {
        Rectangle2D dataBounds2 = results.getDataBounds();
        dataBounds = dataBounds.createUnion(dataBounds2);
    }
    if (results.getCalibration() != null) {
        // Calibration must match between datasets
        if (this.results2 != null) {
            if (results2.getNmPerPixel() != results.getNmPerPixel()) {
                IJ.log(TITLE + " Error: Calibration between the two input datasets does not match, defaulting to pixels");
                return;
            }
        }
        nmPerPixel = results.getNmPerPixel();
        units = "nm";
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Example 43 with Rectangle2D

use of java.awt.geom.Rectangle2D in project poi by apache.

the class ApacheconEU08 method slide4.

public static void slide4(SlideShow<?, ?> ppt) throws IOException {
    Slide<?, ?> slide = ppt.createSlide();
    String[][] txt1 = { { "Note" }, { "This presentation was created programmatically using POI HSLF" } };
    TableShape<?, ?> table1 = slide.createTable(2, 1);
    for (int i = 0; i < txt1.length; i++) {
        for (int j = 0; j < txt1[i].length; j++) {
            TableCell<?, ?> cell = table1.getCell(i, j);
            cell.setText(txt1[i][j]);
            TextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
            rt.setFontSize(10d);
            rt.setFontFamily("Arial");
            rt.setBold(true);
            if (i == 0) {
                rt.setFontSize(32d);
                rt.setFontColor(Color.white);
                cell.setFillColor(new Color(0, 153, 204));
            } else {
                rt.setFontSize(28d);
                cell.setFillColor(new Color(235, 239, 241));
            }
            cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
        }
    }
    DrawTableShape dts = new DrawTableShape(table1);
    dts.setAllBorders(1.0, Color.black);
    dts.setOutsideBorders(4.0);
    table1.setColumnWidth(0, 450);
    table1.setRowHeight(0, 50);
    table1.setRowHeight(1, 80);
    Dimension dim = ppt.getPageSize();
    Rectangle2D oldAnchor = table1.getAnchor();
    table1.setAnchor(new Rectangle2D.Double((dim.width - 450) / 2d, 100, oldAnchor.getWidth(), oldAnchor.getHeight()));
    TextBox<?, ?> box1 = slide.createTextBox();
    box1.setHorizontalCentered(true);
    box1.getTextParagraphs().get(0).getTextRuns().get(0).setFontSize(24d);
    box1.setText("The source code is available at\r" + "http://people.apache.org/~yegor/apachecon_eu08/");
    box1.setAnchor(new Rectangle(80, 356, 553, 65));
}
Also used : Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) TextRun(org.apache.poi.sl.usermodel.TextRun) Dimension(java.awt.Dimension) DrawTableShape(org.apache.poi.sl.draw.DrawTableShape)

Example 44 with Rectangle2D

use of java.awt.geom.Rectangle2D in project poi by apache.

the class TestXSLFHyperlink method bug47291.

@Test
public void bug47291() throws IOException {
    Rectangle2D anchor = new Rectangle2D.Double(100, 100, 100, 100);
    XMLSlideShow ppt1 = new XMLSlideShow();
    XSLFSlide slide1 = ppt1.createSlide();
    XSLFTextBox tb1 = slide1.createTextBox();
    tb1.setAnchor(anchor);
    XSLFTextRun r1 = tb1.setText("page1");
    XSLFHyperlink hl1 = r1.createHyperlink();
    hl1.linkToEmail("dev@poi.apache.org");
    XSLFTextBox tb2 = ppt1.createSlide().createTextBox();
    tb2.setAnchor(anchor);
    XSLFTextRun r2 = tb2.setText("page2");
    XSLFHyperlink hl2 = r2.createHyperlink();
    hl2.linkToLastSlide();
    XSLFSlide sl3 = ppt1.createSlide();
    XSLFTextBox tb3 = sl3.createTextBox();
    tb3.setAnchor(anchor);
    tb3.setText("text1 ");
    tb3.appendText("link", false);
    tb3.appendText(" text2", false);
    List<XSLFTextRun> tb3runs = tb3.getTextParagraphs().get(0).getTextRuns();
    // "lin"
    tb3runs.get(1).createHyperlink().linkToSlide(slide1);
    // "k"
    tb3runs.get(3).createHyperlink().linkToSlide(slide1);
    XSLFTextBox tb4 = ppt1.createSlide().createTextBox();
    tb4.setAnchor(anchor);
    XSLFTextRun r4 = tb4.setText("page4");
    XSLFHyperlink hl4 = r4.createHyperlink();
    hl4.linkToUrl("http://poi.apache.org");
    XSLFTextBox tb5 = ppt1.createSlide().createTextBox();
    tb5.setAnchor(anchor);
    tb5.setText("page5");
    XSLFHyperlink hl5 = tb5.createHyperlink();
    hl5.linkToFirstSlide();
    XMLSlideShow ppt2 = XSLFTestDataSamples.writeOutAndReadBack(ppt1);
    ppt1.close();
    List<XSLFSlide> slides = ppt2.getSlides();
    tb1 = (XSLFTextBox) slides.get(0).getShapes().get(0);
    hl1 = tb1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
    assertNotNull(hl1);
    assertEquals("dev@poi.apache.org", hl1.getLabel());
    assertEquals(HyperlinkType.EMAIL, hl1.getTypeEnum());
    tb2 = (XSLFTextBox) slides.get(1).getShapes().get(0);
    hl2 = tb2.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
    assertNotNull(hl2);
    assertEquals("lastslide", hl2.getXmlObject().getAction().split("=")[1]);
    assertEquals(HyperlinkType.DOCUMENT, hl2.getTypeEnum());
    tb3 = (XSLFTextBox) slides.get(2).getShapes().get(0);
    XSLFHyperlink hl3 = tb3.getTextParagraphs().get(0).getTextRuns().get(1).getHyperlink();
    assertNotNull(hl3);
    hl3 = tb3.getTextParagraphs().get(0).getTextRuns().get(3).getHyperlink();
    assertNotNull(hl3);
    assertEquals("/ppt/slides/slide1.xml", hl3.getAddress());
    assertEquals(HyperlinkType.DOCUMENT, hl3.getTypeEnum());
    tb4 = (XSLFTextBox) slides.get(3).getShapes().get(0);
    hl4 = tb4.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
    assertNotNull(hl4);
    assertEquals("http://poi.apache.org", hl4.getLabel());
    assertEquals(HyperlinkType.URL, hl4.getTypeEnum());
    tb5 = (XSLFTextBox) slides.get(4).getShapes().get(0);
    hl5 = tb5.getHyperlink();
    assertNotNull(hl5);
    assertEquals("firstslide", hl5.getXmlObject().getAction().split("=")[1]);
    assertEquals(HyperlinkType.DOCUMENT, hl5.getTypeEnum());
    ppt2.close();
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.Test)

Example 45 with Rectangle2D

use of java.awt.geom.Rectangle2D in project poi by apache.

the class HSLFTable method setColumnWidth.

@Override
public void setColumnWidth(int col, final double width) {
    if (col < 0 || col >= cells[0].length) {
        throw new IllegalArgumentException("Column index '" + col + "' is not within range [0-" + (cells[0].length - 1) + "]");
    }
    double currentWidth = cells[0][col].getAnchor().getWidth();
    double dx = width - currentWidth;
    for (HSLFTableCell[] cols : cells) {
        Rectangle2D anchor = cols[col].getAnchor();
        anchor.setRect(anchor.getX(), anchor.getY(), width, anchor.getHeight());
        cols[col].setAnchor(anchor);
        if (col < cols.length - 1) {
            for (int j = col + 1; j < cols.length; j++) {
                anchor = cols[j].getAnchor();
                anchor.setRect(anchor.getX() + dx, anchor.getY(), anchor.getWidth(), anchor.getHeight());
                cols[j].setAnchor(anchor);
            }
        }
    }
    Rectangle2D tblanchor = getAnchor();
    tblanchor.setRect(tblanchor.getX(), tblanchor.getY(), tblanchor.getWidth() + dx, tblanchor.getHeight());
    setExteriorAnchor(tblanchor);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)262 Graphics2D (java.awt.Graphics2D)42 AffineTransform (java.awt.geom.AffineTransform)34 Color (java.awt.Color)33 Paint (java.awt.Paint)28 Point2D (java.awt.geom.Point2D)26 BufferedImage (java.awt.image.BufferedImage)23 Font (java.awt.Font)21 FontMetrics (java.awt.FontMetrics)20 Dimension (java.awt.Dimension)19 RoundRectangle2D (java.awt.geom.RoundRectangle2D)18 Rectangle (java.awt.Rectangle)16 FontRenderContext (java.awt.font.FontRenderContext)15 Point (java.awt.Point)11 BasicStroke (java.awt.BasicStroke)10 ArrayList (java.util.ArrayList)10 GradientPaint (java.awt.GradientPaint)9 TextLayout (java.awt.font.TextLayout)9 RadialGradientPaint (java.awt.RadialGradientPaint)8 Shape (java.awt.Shape)7