Search in sources :

Example 26 with RoundRectangle2D

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

the class MolecularTypeLargeShape method paintSpecies.

// --------------------------------------------------------------------------------------
private void paintSpecies(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Font fontOld = g2.getFont();
    Color colorOld = g2.getColor();
    Stroke strokeOld = g2.getStroke();
    Color primaryColor = null;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (mt == null && mtp == null) {
        // plain species context
        Color exterior;
        if (owner == null) {
            // for plain species, we just draw a circle based on height!!! we ignore width!!!
            // error
            exterior = Color.red.darker();
        } else {
            if (!shapePanel.isShowMoleculeColor()) {
                exterior = Color.GRAY;
            } else {
                // plain species
                exterior = Color.green.darker().darker();
            }
        }
        Point2D center = new Point2D.Float(xPos + baseHeight / 3, yPos + baseHeight / 3);
        float radius = baseHeight * 0.5f;
        Point2D focus = new Point2D.Float(xPos + baseHeight / 3 - 1, yPos + baseHeight / 3 - 1);
        float[] dist = { 0.1f, 1.0f };
        Color[] colors = { Color.white, exterior };
        RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
        g2.setPaint(p);
        Ellipse2D circle = new Ellipse2D.Double(xPos, yPos, baseHeight, baseHeight);
        g2.fill(circle);
        Ellipse2D circle2 = new Ellipse2D.Double(xPos - 1, yPos - 1, baseHeight + 0.7, baseHeight + 0.7);
        g2.setPaint(getDefaultColor(Color.DARK_GRAY));
        int z = shapePanel.getZoomFactor();
        g2.setStroke(new BasicStroke(2.0f + 0.14f * z));
        g2.draw(circle2);
        if (owner == null) {
            Font font = fontOld.deriveFont(Font.BOLD);
            g.setFont(font);
            g.setColor(Color.red.darker().darker());
            g2.drawString("Error parsing generated species!", xPos + baseHeight + 10, yPos + baseHeight - 9);
        }
        g2.setFont(fontOld);
        g2.setColor(colorOld);
        g2.setStroke(strokeOld);
        return;
    } else {
        // molecular type, species pattern, observable
        if (mt == null || mt.getModel() == null) {
            primaryColor = Color.blue.darker().darker();
        } else {
            if (shapePanel.getDisplayMode() == DisplayMode.participantSignatures) {
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                    int index = mtList.indexOf(mt);
                    index = index % 7;
                    primaryColor = colorTable[index].darker().darker();
                }
                if (shapePanel.isShowDifferencesOnly()) {
                    ReactionRule reactionRule = (ReactionRule) owner;
                    switch(shapePanel.hasNoMatch(reactionRule.getName(), mtp)) {
                        case CHANGED:
                            primaryColor = AbstractComponentShape.deepOrange;
                            break;
                        case // keep whatever color we set above
                        UNCHANGED:
                            break;
                        case ANALYSISFAILED:
                            ArrayList<Issue> issueList = new ArrayList<Issue>();
                            reactionRule.gatherIssues(new IssueContext(), issueList);
                            boolean bRuleHasErrorIssues = false;
                            for (Issue issue : issueList) {
                                if (issue.getSeverity() == Severity.ERROR) {
                                    bRuleHasErrorIssues = true;
                                    break;
                                }
                            }
                            if (bRuleHasErrorIssues) {
                                primaryColor = AbstractComponentShape.componentHidden;
                            } else {
                                System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                                primaryColor = Color.red.darker();
                            }
                            break;
                        default:
                            break;
                    }
                }
            } else if (shapePanel.getDisplayMode() == DisplayMode.rules) {
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                    int index = mtList.indexOf(mt);
                    index = index % 7;
                    primaryColor = colorTable[index].darker().darker();
                }
                // if we show difference, we apply that now and override the color
                if (shapePanel.isShowDifferencesOnly()) {
                    ReactionRule reactionRule = (ReactionRule) owner;
                    switch(shapePanel.hasNoMatch(mtp)) {
                        case CHANGED:
                            primaryColor = AbstractComponentShape.deepOrange;
                            break;
                        case // keep whatever color we set above
                        UNCHANGED:
                            break;
                        case ANALYSISFAILED:
                            ArrayList<Issue> issueList = new ArrayList<Issue>();
                            reactionRule.gatherIssues(new IssueContext(), issueList);
                            boolean bRuleHasErrorIssues = false;
                            for (Issue issue : issueList) {
                                if (issue.getSeverity() == Severity.ERROR) {
                                    bRuleHasErrorIssues = true;
                                    break;
                                }
                            }
                            if (bRuleHasErrorIssues) {
                                primaryColor = AbstractComponentShape.componentHidden;
                            } else {
                                System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                                primaryColor = Color.red.darker();
                            }
                            break;
                        default:
                            break;
                    }
                }
            } else {
                // TODO: do we ever get here legitimately? if not throw an exception!
                RbmModelContainer rbmmc = mt.getModel().getRbmModelContainer();
                List<MolecularType> mtList = rbmmc.getMolecularTypeList();
                int index = mtList.indexOf(mt);
                index = index % 7;
                if (!shapePanel.isShowMoleculeColor()) {
                    primaryColor = AbstractComponentShape.componentVeryLightGray;
                } else {
                    primaryColor = isHighlighted() == true ? Color.white : colorTable[index].darker().darker();
                }
                if (hasErrorIssues(owner, mt)) {
                    primaryColor = isHighlighted() ? Color.white : Color.red;
                }
            }
        }
    }
    // paint the structure contour if applicable (only for anchored molecules!)
    if (structure != null && mt != null && !mt.isAnchorAll() && mt.getAnchors().size() > 0) {
        paintNarrowCompartmentRight(g);
    } else if (owner instanceof MolecularType && !mt.isAnchorAll()) {
        paintNarrowCompartmentRight(g);
    }
    // paint the shape of the molecule and fill it with color
    GradientPaint p = new GradientPaint(xPos, yPos, primaryColor, xPos, yPos + baseHeight / 2, Color.WHITE, true);
    g2.setPaint(p);
    RoundRectangle2D rect = new RoundRectangle2D.Float(xPos, yPos, width, baseHeight, cornerArc, cornerArc);
    g2.fill(rect);
    RoundRectangle2D inner = new RoundRectangle2D.Float(xPos + 1, yPos + 1, width - 2, baseHeight - 2, cornerArc - 3, cornerArc - 3);
    if (isHighlighted()) {
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red);
        } else {
            g2.setPaint(getDefaultColor(Color.BLACK));
        }
        g2.draw(inner);
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red);
        } else {
            g2.setPaint(getDefaultColor(Color.BLACK));
        }
        g2.draw(rect);
    } else {
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red.darker());
        } else {
            g2.setPaint(getDefaultColor(Color.GRAY));
        }
        g2.draw(inner);
        if (hasErrorIssues(owner, mt)) {
            g2.setPaint(Color.red.darker());
        } else {
            g2.setPaint(getDefaultColor(Color.DARK_GRAY));
        }
        g2.draw(rect);
    }
    // paint the anchor glyph
    Rectangle r = getAnchorHotspot();
    if (r != null) {
        // g2.drawRect(r.x, r.y, r.width, r.height);	// anchor tooltip hotspot area
        int z = shapePanel.getZoomFactor();
        int w = r.width;
        int x = r.x + w / 2;
        int y = r.y;
        int h = 12 + z / 2;
        h = z < -2 ? h - 1 : h;
        h = z < -4 ? h - 1 : h;
        Line2D line = new Line2D.Float(x, y, x, y + h);
        g2.setPaint(getDefaultColor(Color.RED.darker().darker()));
        g2.setStroke(new BasicStroke(2.6f + 0.13f * z));
        g2.draw(line);
        // TODO: adjust the arc at deep zoom!
        double a1 = z < -3 ? 245 : 240;
        // 60
        double a2 = z < -3 ? 52 : 59;
        Arc2D arc = new Arc2D.Double(x - h, y - h, 2 * h, 2 * h, a1, a2, Arc2D.OPEN);
        g2.setStroke(new BasicStroke(2.6f + 0.20f * z));
        g2.draw(arc);
        g2.setPaint(colorOld);
        g2.setStroke(strokeOld);
    }
    // the text inside the molecule shape
    if (mt == null && mtp == null) {
    // plain species context
    // don't write any text inside
    } else {
        // molecular type, species pattern
        Graphics gc = shapePanel.getGraphics();
        Font font = deriveMoleculeFontBold(g, shapePanel);
        g.setFont(font);
        // font color
        g.setColor(getDefaultColor(Color.BLACK));
        int fontSize = font.getSize();
        int textX = xPos + 11;
        int textY = yPos + baseHeight - (baseHeight - fontSize) / 2;
        g2.drawString(name, textX, textY);
        if (owner instanceof ReactionRule && mtp != null && mtp.hasExplicitParticipantMatch()) {
            int z = shapePanel.getZoomFactor();
            if (z >= LargeShapeCanvas.SmallestZoomFactorWithText) {
                // hide the matching too when we don't display the name
                FontMetrics fm = gc.getFontMetrics(font);
                int stringWidth = fm.stringWidth(name);
                Font smallerFont = font.deriveFont(font.getSize() * 0.8F);
                g.setFont(smallerFont);
                g2.drawString(mtp.getParticipantMatchLabel(), textX + stringWidth + 2, textY + 2);
            }
        }
    }
    g.setFont(fontOld);
    g.setColor(colorOld);
    g2.setStroke(strokeOld);
    for (MolecularComponentLargeShape mcls : componentShapes) {
        // paint the components
        mcls.paintSelf(g);
    }
    g2.setFont(fontOld);
    g2.setColor(colorOld);
    g2.setStroke(strokeOld);
}
Also used : BasicStroke(java.awt.BasicStroke) Issue(org.vcell.util.Issue) RoundRectangle2D(java.awt.geom.RoundRectangle2D) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) RadialGradientPaint(java.awt.RadialGradientPaint) GradientPaint(java.awt.GradientPaint) Line2D(java.awt.geom.Line2D) Arc2D(java.awt.geom.Arc2D) Font(java.awt.Font) Ellipse2D(java.awt.geom.Ellipse2D) Point2D(java.awt.geom.Point2D) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) FontMetrics(java.awt.FontMetrics) IssueContext(org.vcell.util.IssueContext) ArrayList(java.util.ArrayList) List(java.util.List) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) ReactionRule(cbit.vcell.model.ReactionRule) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D) MolecularType(org.vcell.model.rbm.MolecularType) Graphics(java.awt.Graphics)

Example 27 with RoundRectangle2D

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

the class MolecularTypeLargeShape method paintDummy.

public static void paintDummy(Graphics g, int xPos, int yPos, LargeShapeCanvas shapePanel) {
    Graphics2D g2 = (Graphics2D) g;
    Color colorOld = g2.getColor();
    Stroke strokeOld = g2.getStroke();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    final float[] dash1 = { 6.0f };
    final BasicStroke dashed = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
    g2.setStroke(dashed);
    int w = getDummyWidth(shapePanel);
    int h = calculateBasHeight(shapePanel);
    int c = calculateCornerArc(shapePanel);
    RoundRectangle2D rect = new RoundRectangle2D.Float(xPos, yPos, w, h, c, c);
    // RoundRectangle2D inner = new RoundRectangle2D.Float(xPos+1, yPos+1, w-2, h-2, c-3, c-3);
    g2.setPaint(Color.LIGHT_GRAY);
    // g2.draw(inner);
    g2.setPaint(Color.LIGHT_GRAY);
    g2.draw(rect);
    g2.setColor(colorOld);
    g2.setStroke(strokeOld);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 28 with RoundRectangle2D

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

the class ReactionRuleDiagramShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2D, int absPosX, int absPosY) {
    Color newBackgroundColor = backgroundColor;
    int shapeHeight = getSpaceManager().getSize().height;
    int shapeWidth = getSpaceManager().getSize().width;
    // this is the "inside" of the shape; note it's 1 pixel larger than the approximate area occupied by the 2 yellow rectangles we use to depict the rule
    // Rectangle2D contour = new Rectangle2D.Double(absPosX, absPosY, shapeWidth, shapeHeight);
    // g2D.setColor(Color.gray);
    // g2D.draw(contour);
    int offsetX = 0;
    int offsetY = shapeHeight - circleDiameter;
    for (int i = 0; i < 2; i++) {
        int x = absPosX + offsetX + i * displacement;
        int y = absPosY + offsetY - i * displacement;
        RoundRectangle2D icon = new RoundRectangle2D.Double(x, y, circleDiameter, circleDiameter, circleDiameter / 2, circleDiameter / 2);
        g2D.setColor(newBackgroundColor);
        g2D.fill(icon);
        g2D.setColor(forgroundColor);
        g2D.draw(icon);
    }
    // draw label
    if (getDisplayLabels() || isSelected()) {
        g2D.setColor(forgroundColor);
        int textX = absPosX + shapeWidth / 2 - getLabelSize().width / 2;
        int textY = absPosY + offsetY - getLabelSize().height / 2;
        if (getLabel() != null && getLabel().length() > 0) {
            if (isSelected()) {
                Rectangle outlineRectangle = getLabelOutline(absPosX, absPosY);
                drawRaisedOutline(outlineRectangle.x, outlineRectangle.y, outlineRectangle.width, outlineRectangle.height, g2D, Color.white, Color.black, Color.black);
            }
            g2D.drawString(getLabel(), textX, textY);
        }
    }
    if (linkText != null && linkText != "") {
        ShapePaintUtil.paintLinkMarkRule(g2D, this, Color.BLACK);
    }
}
Also used : Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle(java.awt.Rectangle)

Example 29 with RoundRectangle2D

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

the class MolecularTypeSmallShape method paintDummy.

public static void paintDummy(Graphics g, int xPos, int yPos) {
    Graphics2D g2 = (Graphics2D) g;
    Color colorOld = g2.getColor();
    Stroke strokeOld = g2.getStroke();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    final float[] dash1 = { 2.0f };
    final BasicStroke dashed = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
    g2.setStroke(dashed);
    int w = getDummyWidth();
    int h = baseHeight;
    int c = cornerArc;
    RoundRectangle2D rect = new RoundRectangle2D.Float(xPos + 1, yPos + 1, w - 1, h - 1, c - 3, c);
    // RoundRectangle2D inner = new RoundRectangle2D.Float(xPos+1, yPos+1, w-2, h-2, c-3, c-3);
    // g2.setPaint(Color.LIGHT_GRAY);
    // g2.draw(inner);
    g2.setPaint(Color.LIGHT_GRAY);
    g2.draw(rect);
    g2.setColor(colorOld);
    g2.setStroke(strokeOld);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) RadialGradientPaint(java.awt.RadialGradientPaint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 30 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)

Aggregations

RoundRectangle2D (java.awt.geom.RoundRectangle2D)45 Color (java.awt.Color)14 Graphics2D (java.awt.Graphics2D)13 Paint (java.awt.Paint)12 BasicStroke (java.awt.BasicStroke)11 Stroke (java.awt.Stroke)10 GradientPaint (java.awt.GradientPaint)8 Ellipse2D (java.awt.geom.Ellipse2D)8 Area (java.awt.geom.Area)7 Rectangle2D (java.awt.geom.Rectangle2D)7 Line2D (java.awt.geom.Line2D)6 RadialGradientPaint (java.awt.RadialGradientPaint)5 Rectangle (java.awt.Rectangle)5 Point (java.awt.Point)4 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)3 FontMetrics (java.awt.FontMetrics)3 Arc2D (java.awt.geom.Arc2D)3 Point2D (java.awt.geom.Point2D)3 MolecularType (org.vcell.model.rbm.MolecularType)3 Font (java.awt.Font)2