Search in sources :

Example 86 with Point2D

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

the class ReactionParticipantShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2D, int parentOffsetX, int parentOffsetY) {
    if (startShape.isSelected()) {
        forgroundColor = Color.red.darker();
    } else {
        forgroundColor = Color.black;
    }
    if (isSelected()) {
        forgroundColor = Color.red;
    }
    // draw cubic spline with horizontal reactant-end (p' = 0) at reaction
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    CubicCurve2D.Double cubicCurve = getCurve();
    // render curve (make CatalystShapes draw with a dashed line)
    g2D.setColor(forgroundColor);
    if (getLineStyle() == LINE_STYLE_DASHED) {
        Stroke oldStroke = g2D.getStroke();
        g2D.setStroke(DASHED_STROKE);
        g2D.draw(cubicCurve);
        g2D.setStroke(oldStroke);
    } else {
        g2D.draw(cubicCurve);
    }
    int arrowDirection = 0;
    if (this instanceof ProductShape) {
        arrowDirection = 1;
    }
    if (this instanceof ReactantShape) {
        arrowDirection = -1;
    }
    if (arrowDirection == 1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    if (arrowDirection == -1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2 + 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    // draw label
    if (getLabel() != null && getLabel().length() > 0) {
        int x = start.x + (int) (start.x * correctionFactor);
        int y = start.y + (int) (start.y * correctionFactor);
        g2D.drawString(getLabel(), (x + end.x) / 2, (y + end.y) / 2);
    }
    return;
}
Also used : Stroke(java.awt.Stroke) GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) CubicCurve2D(java.awt.geom.CubicCurve2D) Point(java.awt.Point)

Example 87 with Point2D

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

the class RuleParticipantEdgeDiagramShape method paintSelf.

@Override
public void paintSelf(Graphics2D g2D, int parentOffsetX, int parentOffsetY) {
    // draw cubic spline with horizontal reactant-end (p' = 0) at reaction
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    CubicCurve2D.Double cubicCurve = getCurve();
    // render curve (make CatalystShapes draw with a dashed line)
    g2D.setColor(forgroundColor);
    if (getLineStyle() == LINE_STYLE_DASHED) {
        Stroke oldStroke = g2D.getStroke();
        g2D.setStroke(DASHED_STROKE);
        g2D.draw(cubicCurve);
        g2D.setStroke(oldStroke);
    } else {
        g2D.draw(cubicCurve);
    }
    int arrowDirection = 0;
    if (this instanceof ProductPatternEdgeDiagramShape) {
        arrowDirection = 1;
    }
    if (this instanceof ReactantPatternEdgeDiagramShape) {
        arrowDirection = -1;
    }
    if (arrowDirection == 1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    if (arrowDirection == -1) {
        double arcLength = integrateArcLength(cubicCurve, 0.0, 1.0, 10);
        double centerT = getParameterAtArcLength(cubicCurve, 0.0, 1.0, arcLength / 2 + 2, 20);
        Point2D center = evaluate(cubicCurve, centerT);
        double backT = intersectWithCircle(cubicCurve, centerT, 0.0, center.getX(), center.getY(), 4);
        Point2D back = evaluate(cubicCurve, backT);
        double frontT = intersectWithCircle(cubicCurve, centerT, 1.0, center.getX(), center.getY(), 4);
        Point2D front = evaluate(cubicCurve, frontT);
        GeneralPath arrow = getArrow(front, back, 7);
        g2D.fill(arrow);
    }
    // draw label
    if (getLabel() != null && getLabel().length() > 0) {
        g2D.drawString(getLabel(), (start.x + end.x) / 2, (start.y + end.y) / 2);
    }
    return;
}
Also used : Stroke(java.awt.Stroke) GeneralPath(java.awt.geom.GeneralPath) Point2D(java.awt.geom.Point2D) CubicCurve2D(java.awt.geom.CubicCurve2D) Point(java.awt.Point)

Example 88 with Point2D

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

the class RuleParticipantSignatureDiagramShape method paintSelf.

// TODO: Override ElipseShape::isInside()
// our shape here is rounded rectangle while IsInside thinks it's an ellipse, which means
// that clicking near the corners of a long shape (with many molecules) fails to select the shape
// TODO: the RoundRectangle2D contour below needs to be recalculated with updated width, using the
// species pattern in the RuleParticipantSignature
@Override
public void paintSelf(Graphics2D g, int absPosX, int absPosY) {
    if (!bVisible) {
        return;
    }
    // we reserve space for at least 1 molecule
    int numMolecules = Math.max(1, ruleParticipantSignature.getSpeciesPattern().getMolecularTypePatterns().size());
    width = leftmargin + circleDiameter + displacement * (numMolecules - 1) + 1;
    getSpaceManager().setSize(width, height);
    int shapeHeight = getSpaceManager().getSize().height;
    int shapeWidth = getSpaceManager().getSize().width;
    Graphics2D g2D = g;
    Paint oldPaint = g2D.getPaint();
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color exterior;
    // draw the contour around the whole rule participant
    // no need to really draw it if the shapes of the molecules fill it perfectly, because it won't be visible anyway
    // however, the "isInside" function will need exactly this RoundRectangle2D to compute whether the point is inside the shape
    RoundRectangle2D contour = new RoundRectangle2D.Double(absPosX, absPosY, shapeWidth, shapeHeight, shapeHeight, shapeHeight);
    g2D.setPaint(isSelected() ? AbstractComponentShape.componentMediumPalePink : AbstractComponentShape.componentPaleGreen);
    g2D.fill(contour);
    exterior = isSelected() ? Color.red.darker().darker() : Color.darkGray;
    g.setColor(exterior);
    g2D.draw(contour);
    Model model = ((ReactionCartoon) graphModel).getModel();
    RbmModelContainer rbmmc = model.getRbmModelContainer();
    List<MolecularType> mtList = rbmmc.getMolecularTypeList();
    List<MolecularType> ruleSignatureMolecularTypes = ruleParticipantSignature.getMolecularTypes();
    // draw the molecules (they are properly drawn because we use the sp as it is in the associated RuleParticipantSignature object)
    for (int i = 0; i < ruleSignatureMolecularTypes.size(); i++) {
        double offsetx = leftmargin + i * displacement - 1.4;
        int offsety = getSpaceManager().getSize().height - circleDiameter - 2;
        Ellipse2D icon = new Ellipse2D.Double(absPosX + offsetx, absPosY + offsety, circleDiameter, circleDiameter);
        // int offsetx = leftmargin + i*displacement;
        // int offsety = 0;
        // Rectangle2D icon = new Rectangle2D.Double(absPosX + offsetx, absPosY + offsety, displacement, shapeHeight-1);
        MolecularType mt = ruleSignatureMolecularTypes.get(i);
        int index = mtList.indexOf(mt);
        index = index % 7;
        defaultBG = Color.lightGray;
        Color interior = Color.white;
        if (graphModel instanceof ReactionCartoonFull) {
            // take color from molecular type color selection
            defaultBG = MolecularTypeLargeShape.colorTable[index];
        }
        backgroundColor = defaultBG;
        // darkerBackground = backgroundColor.darker().darker();
        exterior = !isSelected() ? backgroundColor.darker().darker() : backgroundColor.darker();
        Color[] colors = { interior, exterior };
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Point2D center = new Point2D.Double(absPosX + offsetx + circleDiameter / 2, absPosY + offsety + circleDiameter / 2);
        float radius = circleDiameter * 0.5f;
        Point2D focus = new Point2D.Double(absPosX + offsetx + circleDiameter / 2 - 2, absPosY + offsety + circleDiameter / 2 - 2);
        float[] dist = { 0.1f, 1.0f };
        RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
        // Paint p = defaultBG.darker().darker();
        g2D.setPaint(p);
        g2D.fill(icon);
        g.setColor(forgroundColor);
        g2D.draw(icon);
    }
    // TODO: see if RefreshLabel below works properly, if it does make a similar call to refresh the width!!!
    if (getLabel() != null && getLabel().length() > 0) {
        if (isSelected()) {
            // clear background and outline to make selected label stand out
            Rectangle outlineRectangle = getLabelOutline(absPosX, absPosY);
            drawRaisedOutline(outlineRectangle.x, outlineRectangle.y, outlineRectangle.width, outlineRectangle.height, g, Color.white, forgroundColor, Color.gray);
        }
        if (bDisplayLabel || isSelected()) {
            g.setColor(forgroundColor);
            g.drawString((isSelected() || smallLabel == null ? getLabel() : smallLabel), (isSelected() || smallLabel == null ? getLabelPos().x : smallLabelPos.x) + absPosX, getLabelPos().y - 2 + absPosY);
        }
    }
    if (linkText != null && linkText != "") {
        ShapePaintUtil.paintLinkMark(g2D, this, Color.BLACK);
    }
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2D.setPaint(oldPaint);
}
Also used : Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle(java.awt.Rectangle) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) RadialGradientPaint(java.awt.RadialGradientPaint) Point(java.awt.Point) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) Ellipse2D(java.awt.geom.Ellipse2D) Graphics2D(java.awt.Graphics2D) MolecularType(org.vcell.model.rbm.MolecularType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Point2D(java.awt.geom.Point2D) Model(cbit.vcell.model.Model)

Example 89 with Point2D

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

the class SpeciesContextShape method paintSelf.

@Override
public void paintSelf(Graphics2D g, int absPosX, int absPosY) {
    boolean isBound = false;
    SpeciesContext sc = (SpeciesContext) getModelObject();
    boolean bHasPCLink = false;
    if (graphModel instanceof ModelCartoon) {
        ModelCartoon mc = (ModelCartoon) graphModel;
        // check if species has Pathway Commons link by querying VCMetadata : if it does, need to change color of speciesContext.
        try {
            MiriamManager miriamManager = mc.getModel().getVcMetaData().getMiriamManager();
            Map<MiriamRefGroup, MIRIAMQualifier> miriamRefGroups = miriamManager.getAllMiriamRefGroups(sc.getSpecies());
            if (miriamRefGroups != null && miriamRefGroups.size() > 0) {
                bHasPCLink = true;
            }
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
    }
    if (sc.getSpecies().getDBSpecies() != null || bHasPCLink) {
        isBound = true;
    }
    int shapeHeight = getSpaceManager().getSize().height;
    int shapeWidth = getSpaceManager().getSize().width;
    int offsetX = (shapeWidth - circleDiameter) / 2;
    int offsetY = (shapeHeight - circleDiameter) / 2;
    Graphics2D g2D = g;
    // if (icon == null) {
    icon = new Area();
    icon.add(new Area(new Ellipse2D.Double(offsetX, offsetY, circleDiameter, circleDiameter)));
    // icon.add(new Area(new RoundRectangle2D.Double(offsetX, offsetY,circleDiameter,circleDiameter,circleDiameter/2,circleDiameter/2)));
    // }
    Area movedIcon = icon.createTransformedArea(AffineTransform.getTranslateInstance(absPosX, absPosY));
    if (sc.getSpeciesPattern() == null) {
        defaultBG = java.awt.Color.green;
    } else {
        defaultBG = java.awt.Color.blue;
    }
    if (isCatalyst == true) {
        defaultBG = java.awt.Color.magenta;
    }
    backgroundColor = defaultBG;
    darkerBackground = backgroundColor.darker().darker();
    // g.setColor((!isBound && !isSelected()?darkerBackground:backgroundColor));
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color exterior = !isBound && !isSelected() ? darkerBackground : backgroundColor;
    // Color interior = exterior.brighter().brighter();
    Point2D center = new Point2D.Float(absPosX + circleDiameter * 0.5f, absPosY + circleDiameter * 0.5f);
    float radius = circleDiameter * 0.5f;
    Point2D focus = new Point2D.Float(absPosX + circleDiameter * 0.4f, absPosY + circleDiameter * 0.4f);
    float[] dist = { 0.1f, 1.0f };
    Color[] colors = { Color.white, exterior };
    // Color[] colors = {interior, exterior};
    RadialGradientPaint p = new RadialGradientPaint(center, radius, focus, dist, colors, CycleMethod.NO_CYCLE);
    g2D.setPaint(p);
    g2D.fill(movedIcon);
    g.setColor(forgroundColor);
    g2D.draw(movedIcon);
    // draw label
    if (getLabel() != null && getLabel().length() > 0) {
        if (isSelected()) {
            // clear background and outline to make selected label stand out
            Rectangle outlineRectangle = getLabelOutline(absPosX, absPosY);
            drawRaisedOutline(outlineRectangle.x, outlineRectangle.y, outlineRectangle.width, outlineRectangle.height, g, Color.white, forgroundColor, Color.gray);
        }
        g.setColor(forgroundColor);
        g.drawString((isSelected() || smallLabel == null ? getLabel() : smallLabel), (isSelected() || smallLabel == null ? getLabelPos().x : smallLabelPos.x) + absPosX, getLabelPos().y + absPosY);
    }
    if (linkText != null && linkText != "") {
        ShapePaintUtil.paintLinkMark(g2D, this, Color.BLACK);
    }
}
Also used : MiriamManager(cbit.vcell.biomodel.meta.MiriamManager) Color(java.awt.Color) Rectangle(java.awt.Rectangle) SpeciesContext(cbit.vcell.model.SpeciesContext) RadialGradientPaint(java.awt.RadialGradientPaint) Point(java.awt.Point) RadialGradientPaint(java.awt.RadialGradientPaint) Graphics2D(java.awt.Graphics2D) Area(java.awt.geom.Area) Point2D(java.awt.geom.Point2D) MIRIAMQualifier(org.vcell.sybil.models.miriam.MIRIAMQualifier) MiriamRefGroup(cbit.vcell.biomodel.meta.MiriamManager.MiriamRefGroup)

Example 90 with Point2D

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

the class FRAPData method createCircularBinaryKernel.

private KernelJAI createCircularBinaryKernel(int radius) {
    int enclosingBoxSideLength = radius * 2 + 1;
    float[] kernalData = new float[enclosingBoxSideLength * enclosingBoxSideLength];
    Point2D kernalPoint = new Point2D.Float(0f, 0f);
    int index = 0;
    for (int y = -radius; y <= radius; y++) {
        for (int x = -radius; x <= radius; x++) {
            if (kernalPoint.distance(x, y) <= radius) {
                kernalData[index] = 1.0f;
            }
            index++;
        }
    }
    return new KernelJAI(enclosingBoxSideLength, enclosingBoxSideLength, radius, radius, kernalData);
}
Also used : Point2D(java.awt.geom.Point2D) KernelJAI(javax.media.jai.KernelJAI)

Aggregations

Point2D (java.awt.geom.Point2D)193 Color (java.awt.Color)22 Rectangle2D (java.awt.geom.Rectangle2D)20 RadialGradientPaint (java.awt.RadialGradientPaint)19 Graphics2D (java.awt.Graphics2D)18 Point (java.awt.Point)18 Paint (java.awt.Paint)17 Line2D (java.awt.geom.Line2D)12 AffineTransform (java.awt.geom.AffineTransform)11 Rectangle (java.awt.Rectangle)9 BasicStroke (java.awt.BasicStroke)8 Stroke (java.awt.Stroke)8 Ellipse2D (java.awt.geom.Ellipse2D)8 BufferedImage (java.awt.image.BufferedImage)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 Element (org.jdom2.Element)6 GradientPaint (java.awt.GradientPaint)5 Arc2D (java.awt.geom.Arc2D)5 GeneralPath (java.awt.geom.GeneralPath)5