Search in sources :

Example 11 with Ellipse2D

use of java.awt.geom.Ellipse2D in project Activiti by Activiti.

the class DefaultProcessDiagramCanvas method drawStartEvent.

public void drawStartEvent(GraphicInfo graphicInfo, BufferedImage image, double scaleFactor) {
    Paint originalPaint = g.getPaint();
    g.setPaint(EVENT_COLOR);
    Ellipse2D circle = new Ellipse2D.Double(graphicInfo.getX(), graphicInfo.getY(), graphicInfo.getWidth(), graphicInfo.getHeight());
    g.fill(circle);
    g.setPaint(EVENT_BORDER_COLOR);
    g.draw(circle);
    g.setPaint(originalPaint);
    if (image != null) {
        // calculate coordinates to center image
        int imageX = (int) Math.round(graphicInfo.getX() + (graphicInfo.getWidth() / 2) - (image.getWidth() / 2 * scaleFactor));
        int imageY = (int) Math.round(graphicInfo.getY() + (graphicInfo.getHeight() / 2) - (image.getHeight() / 2 * scaleFactor));
        g.drawImage(image, imageX, imageY, (int) (image.getWidth() / scaleFactor), (int) (image.getHeight() / scaleFactor), null);
    }
}
Also used : Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) Point(java.awt.Point) Paint(java.awt.Paint)

Example 12 with Ellipse2D

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

the class DeviceDefinitionPreview method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    GraphicsUtil.setupAntialiasing(g);
    GraphicsUtil.setupAAPainting(g);
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(JBColor.background());
    g2d.fillRect(0, 0, getWidth(), getHeight());
    g2d.setColor(JBColor.foreground());
    g2d.setFont(STANDARD_FONT);
    if (myDeviceData.name().get().equals(DO_NOT_DISPLAY)) {
        FontMetrics metrics = g2d.getFontMetrics();
        g2d.drawString(NO_DEVICE_SELECTED, (getWidth() - metrics.stringWidth(NO_DEVICE_SELECTED)) / 2, (getHeight() - metrics.getHeight()) / 2);
        return;
    }
    boolean isCircular = myDeviceData.isWear().get() && myDeviceData.isScreenRound().get();
    // Paint our icon
    Icon icon = getIcon(myDeviceData);
    icon.paintIcon(this, g, PADDING / 2, PADDING / 2);
    // Paint the device name
    g2d.setFont(TITLE_FONT);
    FontMetrics metrics = g.getFontMetrics(TITLE_FONT);
    g2d.drawString(myDeviceData.name().get(), JBUI.scale(50), PADDING + metrics.getHeight() / 2);
    g2d.drawLine(0, JBUI.scale(50), getWidth(), JBUI.scale(50));
    // Paint the device outline with dimensions labelled
    Dimension screenSize = getScaledDimension();
    Dimension pixelScreenSize = myDeviceData.getDeviceScreenDimension();
    if (screenSize != null) {
        if (screenSize.getHeight() <= 0) {
            screenSize.height = 1;
        }
        if (screenSize.getWidth() <= 0) {
            screenSize.width = 1;
        }
        RoundRectangle2D roundRect = new RoundRectangle2D.Double(PADDING, JBUI.scale(100), screenSize.width, screenSize.height, JBUI.scale(10), JBUI.scale(10));
        g2d.setStroke(new BasicStroke(DIMENSION_LINE_WIDTH));
        g2d.setColor(OUR_GRAY);
        g2d.setFont(FIGURE_FONT);
        metrics = g2d.getFontMetrics(FIGURE_FONT);
        int stringHeight = metrics.getHeight() - metrics.getDescent();
        // Paint the width dimension
        String widthString = Integer.toString(pixelScreenSize.width) + "px";
        int widthLineY = JBUI.scale(95) - (metrics.getHeight() - metrics.getDescent()) / 2;
        g2d.drawLine(PADDING, widthLineY, round(PADDING + screenSize.width), widthLineY);
        // Erase the part of the line that the text overlays
        g2d.setColor(JBColor.background());
        int widthStringWidth = metrics.stringWidth(widthString);
        int widthTextX = round(PADDING + (screenSize.width - widthStringWidth) / 2);
        g2d.drawLine(widthTextX - FIGURE_PADDING, widthLineY, widthTextX + widthStringWidth + FIGURE_PADDING, widthLineY);
        // Paint the width text
        g2d.setColor(JBColor.foreground());
        g2d.drawString(widthString, widthTextX, JBUI.scale(95));
        // Paint the height dimension
        g2d.setColor(OUR_GRAY);
        String heightString = Integer.toString(pixelScreenSize.height) + "px";
        int heightLineX = round(PADDING + screenSize.width + JBUI.scale(15));
        g2d.drawLine(heightLineX, JBUI.scale(100), heightLineX, round(JBUI.scale(100) + screenSize.height));
        // Erase the part of the line that the text overlays
        g2d.setColor(JBColor.background());
        int heightTextY = round(JBUI.scale(100) + (screenSize.height + stringHeight) / 2);
        g2d.drawLine(heightLineX, heightTextY + FIGURE_PADDING, heightLineX, heightTextY - stringHeight - FIGURE_PADDING);
        // Paint the height text
        g2d.setColor(JBColor.foreground());
        g2d.drawString(heightString, heightLineX - JBUI.scale(10), heightTextY);
        // Paint the diagonal dimension
        g2d.setColor(OUR_GRAY);
        String diagString = FORMAT.format(myDeviceData.diagonalScreenSize().get());
        int diagTextX = round(PADDING + (screenSize.width - metrics.stringWidth(diagString)) / 2);
        int diagTextY = round(JBUI.scale(100) + (screenSize.height + stringHeight) / 2);
        double chin = (double) myDeviceData.screenChinSize().get();
        chin *= screenSize.getWidth() / myDeviceData.getDeviceScreenDimension().getWidth();
        Line2D diagLine = new Line2D.Double(PADDING, JBUI.scale(100) + screenSize.height + chin, PADDING + screenSize.width, JBUI.scale(100));
        if (isCircular) {
            // Move the endpoints of the line to within the circle. Each endpoint must move towards the center axis of the circle by
            // 0.5 * (l - l/sqrt(2)) where l is the diameter of the circle.
            double dist = 0.5 * (screenSize.width - screenSize.width / Math.sqrt(2));
            diagLine.setLine(diagLine.getX1() + dist, diagLine.getY1() - dist, diagLine.getX2() - dist, diagLine.getY2() + dist);
        }
        g2d.draw(diagLine);
        // Erase the part of the line that the text overlays
        g2d.setColor(JBColor.background());
        Rectangle erasureRect = new Rectangle(diagTextX - FIGURE_PADDING, diagTextY - stringHeight - FIGURE_PADDING, metrics.stringWidth(diagString) + FIGURE_PADDING * 2, stringHeight + FIGURE_PADDING * 2);
        g2d.fill(erasureRect);
        // Paint the diagonal text
        g2d.setColor(JBColor.foreground());
        g2d.drawString(diagString, diagTextX, diagTextY);
        // Finally, paint the outline
        g2d.setStroke(new BasicStroke(OUTLINE_LINE_WIDTH));
        g2d.setColor(JBColor.foreground());
        if (isCircular) {
            double x = roundRect.getX();
            double y = roundRect.getY();
            Ellipse2D circle = new Ellipse2D.Double(x, y, screenSize.width, screenSize.height + chin);
            g2d.draw(circle);
            if (chin > 0) {
                erasureRect = new Rectangle((int) x, (int) (y + screenSize.height + OUTLINE_LINE_WIDTH / 2 + 1), screenSize.width, (int) chin + OUTLINE_LINE_WIDTH / 2 + 1);
                g2d.setColor(JBColor.background());
                g2d.fill(erasureRect);
                g2d.setColor(JBColor.foreground());
                double halfChinWidth = Math.sqrt(chin * (screenSize.width - chin)) - OUTLINE_LINE_WIDTH / 2;
                int chinX = (int) (x + screenSize.width / 2 - halfChinWidth);
                g2d.drawLine(chinX, (int) (y + screenSize.height), (int) (chinX + halfChinWidth * 2), (int) (y + screenSize.height));
            }
        } else {
            g2d.draw(roundRect);
        }
        // Paint the details. If it's a portrait phone, then paint to the right of the rect.
        // If it's a landscape tablet/tv, paint below.
        g2d.setFont(STANDARD_FONT);
        metrics = g2d.getFontMetrics(STANDARD_FONT);
        stringHeight = metrics.getHeight();
        int infoSegmentX;
        int infoSegmentY;
        if (myDeviceData.getDefaultDeviceOrientation().equals(ScreenOrientation.PORTRAIT)) {
            infoSegmentX = round(PADDING + screenSize.width + metrics.stringWidth(heightString) + PADDING);
            infoSegmentY = JBUI.scale(100);
        } else {
            infoSegmentX = PADDING;
            infoSegmentY = round(JBUI.scale(100) + screenSize.height + PADDING);
        }
        infoSegmentY += stringHeight;
        ScreenSize size = AvdScreenData.getScreenSize(myDeviceData.diagonalScreenSize().get());
        g2d.drawString("Size:      " + size.getResourceValue(), infoSegmentX, infoSegmentY);
        infoSegmentY += stringHeight;
        ScreenRatio ratio = AvdScreenData.getScreenRatio(myDeviceData.screenResolutionWidth().get(), myDeviceData.screenResolutionHeight().get());
        g2d.drawString("Ratio:    " + ratio.getResourceValue(), infoSegmentX, infoSegmentY);
        infoSegmentY += stringHeight;
        Density pixelDensity = myDeviceData.density().get();
        if (pixelDensity == Density.NODPI) {
            // We need to calculate the density
            pixelDensity = AvdScreenData.getScreenDensity(myDeviceData.isTv().get(), myDeviceData.screenDpi().get(), myDeviceData.screenResolutionHeight().get());
        }
        g2d.drawString("Density: " + pixelDensity.getResourceValue(), infoSegmentX, infoSegmentY);
    }
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D) ScreenRatio(com.android.resources.ScreenRatio) Line2D(java.awt.geom.Line2D) Density(com.android.resources.Density) Ellipse2D(java.awt.geom.Ellipse2D) ScreenSize(com.android.resources.ScreenSize)

Example 13 with Ellipse2D

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

the class PPGraphics2D method drawOval.

/**
     * Draws the outline of an oval.
     * The result is a circle or ellipse that fits within the
     * rectangle specified by the <code>x</code>, <code>y</code>,
     * <code>width</code>, and <code>height</code> arguments.
     * <p>
     * The oval covers an area that is
     * <code>width&nbsp;+&nbsp;1</code> pixels wide
     * and <code>height&nbsp;+&nbsp;1</code> pixels tall.
     * @param       x the <i>x</i> coordinate of the upper left
     *                     corner of the oval to be drawn.
     * @param       y the <i>y</i> coordinate of the upper left
     *                     corner of the oval to be drawn.
     * @param       width the width of the oval to be drawn.
     * @param       height the height of the oval to be drawn.
     * @see         java.awt.Graphics#fillOval
     */
public void drawOval(int x, int y, int width, int height) {
    Ellipse2D oval = new Ellipse2D.Float(x, y, width, height);
    draw(oval);
}
Also used : Ellipse2D(java.awt.geom.Ellipse2D)

Example 14 with Ellipse2D

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

the class PPGraphics2D method fillOval.

/**
     * Fills an oval bounded by the specified rectangle with the
     * current color.
     * @param       x the <i>x</i> coordinate of the upper left corner
     *                     of the oval to be filled.
     * @param       y the <i>y</i> coordinate of the upper left corner
     *                     of the oval to be filled.
     * @param       width the width of the oval to be filled.
     * @param       height the height of the oval to be filled.
     * @see         java.awt.Graphics#drawOval
     */
public void fillOval(int x, int y, int width, int height) {
    Ellipse2D oval = new Ellipse2D.Float(x, y, width, height);
    fill(oval);
}
Also used : Ellipse2D(java.awt.geom.Ellipse2D)

Example 15 with Ellipse2D

use of java.awt.geom.Ellipse2D in project processdash by dtuma.

the class StandardDiscItemRenderer method drawItem.

public void drawItem(Graphics2D g2, DiscItemRendererState state, Rectangle2D dataArea, Ellipse2D discLocation, PlotRenderingInfo info, DiscPlot plot, PieDataset dataset, int item) {
    Ellipse2D shape = plot.getDiscDistributor().getDiscLocation(item);
    if (shape == null)
        return;
    Comparable key = dataset.getKey(item);
    Paint discPaint = lookupDiscPaint(key, true);
    drawDisc(g2, shape, discPaint, item);
    drawLabel(g2, plot, dataset, shape, key, discPaint);
    drawOutline(g2, shape, key);
    if (info != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            String tip = null;
            if (plot.getToolTipGenerator() != null) {
                tip = plot.getToolTipGenerator().generateToolTip(dataset, key);
            }
            String url = null;
            if (plot.getUrlGenerator() != null) {
                url = plot.getUrlGenerator().generateURL(dataset, key, item);
            }
            DiscItemEntity entity = new DiscItemEntity(shape, dataset, item, key, tip, url);
            entities.add(entity);
        }
    }
}
Also used : EntityCollection(org.jfree.chart.entity.EntityCollection) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D)

Aggregations

Ellipse2D (java.awt.geom.Ellipse2D)15 Paint (java.awt.Paint)6 BasicStroke (java.awt.BasicStroke)3 Stroke (java.awt.Stroke)3 Point (java.awt.Point)2 Area (java.awt.geom.Area)2 Density (com.android.resources.Density)1 ScreenRatio (com.android.resources.ScreenRatio)1 ScreenSize (com.android.resources.ScreenSize)1 Color (java.awt.Color)1 Arc2D (java.awt.geom.Arc2D)1 Line2D (java.awt.geom.Line2D)1 Path2D (java.awt.geom.Path2D)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1