Search in sources :

Example 11 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project vcell by virtualcell.

the class SpeciesSizeShapeIcon method paintIcon.

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    if (c == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) g;
    Color colorOld = g2.getColor();
    Paint paintOld = g2.getPaint();
    Stroke strokeOld = g2.getStroke();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int offset;
    if (state == State.normal) {
        offset = 0;
    } else {
        offset = 1;
    }
    int xx = x + 1 + offset;
    int yy = y + 1 + offset;
    double h = diameter - 5;
    g2.setStroke(new BasicStroke(1.6f));
    g2.setPaint(Color.darkGray);
    DoubleArrow arrow = new DoubleArrow(xx + 13, yy, h);
    g2.draw(arrow);
    if (kind == Kind.equal) {
        g2.setStroke(new BasicStroke(2.4f));
        g2.setPaint(Color.magenta.darker().darker());
        Line2D upper = new Line2D.Double(xx, yy + 9, xx + 7, yy + 9);
        g2.draw(upper);
        Line2D lower = new Line2D.Double(xx, yy + 13, xx + 7, yy + 13);
        g2.draw(lower);
    } else if (kind == Kind.weight) {
        g2.setStroke(new BasicStroke(1.2f));
        RoundRectangle2D rr = new RoundRectangle2D.Double(xx, yy + 9, 7, 7, 2, 2);
        g2.setPaint(Color.yellow);
        g2.fill(rr);
        g2.setPaint(Color.gray);
        g2.draw(rr);
    } else if (kind == Kind.length) {
        g2.setStroke(new BasicStroke(1.5f));
        g2.setPaint(Color.blue.darker());
        Line2D upper = new Line2D.Double(xx - 2, yy + 9, xx + 1, yy + 9);
        g2.draw(upper);
        Line2D mid = new Line2D.Double(xx - 2, yy + 12, xx + 4, yy + 12);
        g2.draw(mid);
        Line2D lower = new Line2D.Double(xx - 2, yy + 15, xx + 7, yy + 15);
        g2.draw(lower);
    }
    g2.setStroke(strokeOld);
    g2.setColor(colorOld);
    g2.setPaint(paintOld);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 12 with RoundRectangle2D

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

the class TrashCanIcon method paintIcon.

@Override
protected void paintIcon(Graphics2D g2, int width, int height, float scale) {
    // calculate the gradient for shading
    Color shadow = PaintUtils.mixColors(fill, edge, 0.3f);
    GradientPaint gradient = new GradientPaint(0, 0, fill, width, 0, shadow);
    // draw the can
    float s2 = 2 * scale;
    int hPad = (int) s2;
    int ww = width - 2 * hPad - 2;
    int top = (int) (2 * scale + 1);
    RoundRectangle2D can = new //
    RoundRectangle2D.Float(//
    hPad, //
    top, ww, height - top - 1, s2, s2);
    g2.setPaint(gradient);
    g2.fill(can);
    g2.setColor(edge);
    g2.draw(can);
    // draw lines on the can
    int lineSpacing = Math.min(5, Math.max(2, ww / 5));
    int lineIndent = Math.max(2, (lineSpacing + ww % lineSpacing) / 2);
    for (int x = hPad + lineIndent; x < can.getMaxX() - 1; x += lineSpacing) g2.drawLine(x, top, x, height - 3);
    // draw the handle
    hPad = (int) (5 * scale);
    ww = width - 2 * hPad - 2;
    g2.setStroke(new BasicStroke(1));
    g2.setColor(edge);
    g2.draw(new RoundRectangle2D.Float(hPad, 0, ww, 3 * scale, s2, s2));
    // draw the lid
    hPad = (int) scale;
    ww = width - 2 * hPad - 2;
    int lh = (int) (2 * scale + 0.5);
    Area lid = new Area();
    lid.add(new Area(new //
    RoundRectangle2D.Float(//
    hPad, //
    2 * hPad, ww, lh * 2, s2, s2)));
    lid.intersect(new Area(new Rectangle2D.Float(hPad, 2 * hPad, ww, lh)));
    g2.setPaint(gradient);
    g2.fill(lid);
    g2.setPaint(edge);
    g2.draw(lid);
}
Also used : BasicStroke(java.awt.BasicStroke) Area(java.awt.geom.Area) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint)

Example 13 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project hid-serial by rayshobby.

the class GScrollbar method updateBuffer.

protected void updateBuffer() {
    if (bufferInvalid) {
        bufferInvalid = false;
        Graphics2D g2d = buffer.g2;
        buffer.beginDraw();
        if (opaque) {
            buffer.background(buffer.color(255, 0));
            buffer.fill(palette[6]);
            buffer.noStroke();
            buffer.rect(8, 0, width - 16, height);
        } else
            buffer.background(buffer.color(255, 0));
        // Draw the track
        buffer.fill(palette[TRACK]);
        buffer.noStroke();
        buffer.rect(8, 3, width - 8, height - 5);
        g2d.setStroke(pen_1_0);
        // Draw the low cap
        buffer.strokeWeight(1.2f);
        if (currSpot == 1) {
            g2d.setColor(jpalette[OVER_FILL]);
            g2d.fill(lowCap);
            g2d.setColor(jpalette[OVER_STROKE]);
            g2d.draw(lowCap);
        } else {
            g2d.setColor(jpalette[OFF_FILL]);
            g2d.fill(lowCap);
            g2d.setColor(jpalette[OFF_STROKE]);
            g2d.draw(lowCap);
        }
        // Draw the high cap
        if (currSpot == 2) {
            g2d.setColor(jpalette[OVER_FILL]);
            g2d.fill(highCap);
            g2d.setColor(jpalette[OVER_STROKE]);
            g2d.draw(highCap);
        } else {
            g2d.setColor(jpalette[OFF_FILL]);
            g2d.fill(highCap);
            g2d.setColor(jpalette[OFF_STROKE]);
            g2d.draw(highCap);
        }
        // draw thumb
        float thumbWidth = (width - 32) * filler;
        RoundRectangle2D thumb = new RoundRectangle2D.Float(1, 1, thumbWidth - 1, height - 2, 6, 6);
        buffer.translate((width - 32) * value + 16, 0);
        if (currSpot == 10 || isValueChanging) {
            g2d.setColor(jpalette[OVER_FILL]);
            g2d.fill(thumb);
            g2d.setColor(jpalette[OVER_STROKE]);
            g2d.draw(thumb);
        } else {
            g2d.setColor(jpalette[OFF_FILL]);
            g2d.fill(thumb);
            g2d.setColor(jpalette[OFF_STROKE]);
            g2d.draw(thumb);
        }
        buffer.endDraw();
    }
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D) Graphics2D(java.awt.Graphics2D)

Example 14 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D in project scriptographer by scriptographer.

the class AbstractGraphics2D method drawRoundRect.

/**
     * Draws an outlined round-cornered rectangle using this graphics
     * context's current color. The left and right edges of the rectangle
     * are at <code>x</code> and <code>x&nbsp;+&nbsp;width</code>,
     * respectively. The top and bottom edges of the rectangle are at
     * <code>y</code> and <code>y&nbsp;+&nbsp;height</code>.
     * @param      x the <i>x</i> coordinate of the rectangle to be drawn.
     * @param      y the <i>y</i> coordinate of the rectangle to be drawn.
     * @param      width the width of the rectangle to be drawn.
     * @param      height the height of the rectangle to be drawn.
     * @param      arcWidth the horizontal diameter of the arc
     *                    at the four corners.
     * @param      arcHeight the vertical diameter of the arc
     *                    at the four corners.
     * @see        java.awt.Graphics#fillRoundRect
     */
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
    RoundRectangle2D rect = new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight);
    draw(rect);
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D)

Example 15 with RoundRectangle2D

use of java.awt.geom.RoundRectangle2D 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)

Aggregations

RoundRectangle2D (java.awt.geom.RoundRectangle2D)24 Color (java.awt.Color)10 Graphics2D (java.awt.Graphics2D)9 BasicStroke (java.awt.BasicStroke)8 Paint (java.awt.Paint)8 Stroke (java.awt.Stroke)7 GradientPaint (java.awt.GradientPaint)6 RadialGradientPaint (java.awt.RadialGradientPaint)5 Rectangle (java.awt.Rectangle)4 Ellipse2D (java.awt.geom.Ellipse2D)4 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)3 Area (java.awt.geom.Area)3 Line2D (java.awt.geom.Line2D)3 Point2D (java.awt.geom.Point2D)3 MolecularType (org.vcell.model.rbm.MolecularType)3 Font (java.awt.Font)2 Graphics (java.awt.Graphics)2 Point (java.awt.Point)2 Rectangle2D (java.awt.geom.Rectangle2D)2 ArrayList (java.util.ArrayList)2