Search in sources :

Example 6 with ReactionArrow

use of com.actelion.research.chem.reaction.ReactionArrow in project openchemlib by Actelion.

the class ExtendedDepictor method layoutReaction.

private void layoutReaction(Object g) {
    Rectangle2D.Double[] boundingRect = new Rectangle2D.Double[mMolecule.length];
    double totalWidth = 0.0;
    double totalHeight = 0.0;
    for (int i = 0; i < mMolecule.length; i++) {
        mDepictor[i].validateView(g, null, AbstractDepictor.cModeInflateToMaxAVBL);
        boundingRect[i] = mDepictor[i].getBoundingRect();
        totalWidth += boundingRect[i].width;
        totalHeight = Math.max(totalHeight, boundingRect[i].height);
    }
    final double catalystScale = 0.7;
    double catalystSpacing = 0.5 * AbstractDepictor.cOptAvBondLen;
    Rectangle2D.Double[] catalystBoundingRect = new Rectangle2D.Double[mCatalyst.length];
    double totalCatalystWidth = 0.0;
    double totalCatalystHeight = 0.0;
    for (int i = 0; i < mCatalyst.length; i++) {
        mCatalystDepictor[i].validateView(g, null, AbstractDepictor.cModeInflateToMaxAVBL + (int) (catalystScale * AbstractDepictor.cOptAvBondLen));
        catalystBoundingRect[i] = mCatalystDepictor[i].getBoundingRect();
        totalCatalystWidth = Math.max(totalCatalystWidth, catalystBoundingRect[i].width);
        totalCatalystHeight += catalystBoundingRect[i].height + catalystSpacing;
    }
    double spacing = 1.5 * AbstractDepictor.cOptAvBondLen;
    double arrowWidth = Math.max(2 * AbstractDepictor.cOptAvBondLen, totalCatalystWidth + AbstractDepictor.cOptAvBondLen);
    totalHeight = Math.max(totalHeight, AbstractDepictor.cOptAvBondLen + 2 * totalCatalystHeight);
    int arrow = -1;
    if (mDrawingObjectList == null) {
        mDrawingObjectList = new DrawingObjectList();
        mDrawingObjectList.add(new ReactionArrow());
        arrow = 0;
    } else {
        for (int i = 0; i < mDrawingObjectList.size(); i++) {
            if (mDrawingObjectList.get(i) instanceof ReactionArrow) {
                arrow = i;
                break;
            }
        }
        if (arrow == -1) {
            arrow = mDrawingObjectList.size();
            mDrawingObjectList.add(new ReactionArrow());
        }
    }
    double rawX = 0.5 * spacing;
    for (int i = 0; i < mMolecule.length; i++) {
        if (i == mReactantOrCoreCount) {
            ((ReactionArrow) mDrawingObjectList.get(arrow)).setCoordinates(rawX - spacing / 2, totalHeight / 2, rawX - spacing / 2 + arrowWidth, totalHeight / 2);
            double catX = rawX + 0.5 * (AbstractDepictor.cOptAvBondLen - spacing);
            double catY = 0.5 * (totalHeight - catalystSpacing) - totalCatalystHeight;
            for (int j = 0; j < mCatalyst.length; j++) {
                double dx = catX + 0.5 * (totalCatalystWidth - catalystBoundingRect[j].width) - catalystBoundingRect[j].x;
                double dy = catY - catalystBoundingRect[j].y;
                mCatalystDepictor[j].applyTransformation(new DepictorTransformation(1.0, dx, dy));
                catY += catalystSpacing + catalystBoundingRect[j].height;
            }
            rawX += arrowWidth;
        }
        double dx = rawX - boundingRect[i].x;
        double dy = 0.5 * (totalHeight - boundingRect[i].height) - boundingRect[i].y;
        mDepictor[i].applyTransformation(new DepictorTransformation(1.0, dx, dy));
        rawX += spacing + boundingRect[i].width;
    }
    mReactionLayoutNeeded = false;
}
Also used : ReactionArrow(com.actelion.research.chem.reaction.ReactionArrow)

Aggregations

ReactionArrow (com.actelion.research.chem.reaction.ReactionArrow)6 Rectangle2D (java.awt.geom.Rectangle2D)2 CoordinateInventor (com.actelion.research.chem.coords.CoordinateInventor)1 Reaction (com.actelion.research.chem.reaction.Reaction)1