Example usage for java.awt Rectangle getCenterY

List of usage examples for java.awt Rectangle getCenterY

Introduction

In this page you can find the example usage for java.awt Rectangle getCenterY.

Prototype

public double getCenterY() 

Source Link

Document

Returns the Y coordinate of the center of the framing rectangle of the Shape in double precision.

Usage

From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java

/**
 * Draw a filled arc representing a single feature. The thickness and height of the arc are proportional to the
 * depth of coverage.  Some of this gets a bit arcane -- the result of lots of visual tweaking.
 *
 * @param pixelFeatureStart  the starting position of the feature, whether on-screen or not
 * @param pixelFeatureEnd    the ending position of the feature, whether on-screen or not
 * @param pixelJunctionStart the starting position of the junction, whether on-screen or not
 * @param pixelJunctionEnd   the ending position of the junction, whether on-screen or not
 * @param depth              coverage depth
 * @param trackRectangle/*from  www. j  a  v  a  2 s  .c o  m*/
 * @param context
 * @param strand
 * @param junctionFeature
 * @param shouldHighlight
 * @param featureColor       the color specified for this feature.  May be null.
 */
protected void drawFeature(int pixelFeatureStart, int pixelFeatureEnd, int pixelJunctionStart,
        int pixelJunctionEnd, float depth, Rectangle trackRectangle, RenderContext context, Strand strand,
        SpliceJunctionFeature junctionFeature, boolean shouldHighlight, Color featureColor,
        boolean shouldShowFlankingRegions) {

    boolean isPositiveStrand = true;
    // Get the feature's direction, color appropriately
    if (strand != null && strand.equals(Strand.NEGATIVE))
        isPositiveStrand = false;

    //If the feature color is specified, use it, except that we set our own alpha depending on whether
    //the feature is highlighted.  Otherwise default based on strand and highlight.
    Color color;
    if (featureColor != null) {
        int r = featureColor.getRed();
        int g = featureColor.getGreen();
        int b = featureColor.getBlue();
        int alpha = shouldHighlight ? 255 : 140;
        color = new Color(r, g, b, alpha);
    } else {
        if (isPositiveStrand)
            color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_POS : ARC_COLOR_POS;
        else
            color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG;
    }

    Graphics2D g2D = context.getGraphic2DForColor(color);
    if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) {
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }
    //Height of top of an arc of maximum depth
    int maxPossibleArcHeight = (trackRectangle.height - 1) / 2;

    if (shouldShowFlankingRegions) {
        if (junctionFeature.hasFlankingRegionDepthArrays()) {
            //draw a wigglegram of the splice junction flanking region depth of coverage

            int startFlankingRegionPixelLength = pixelJunctionStart - pixelFeatureStart;
            int endFlankingRegionPixelLength = pixelFeatureEnd - pixelJunctionEnd;

            drawFlankingRegion(g2D, pixelFeatureStart, startFlankingRegionPixelLength,
                    junctionFeature.getStartFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle,
                    isPositiveStrand);
            drawFlankingRegion(g2D, pixelJunctionEnd + 1, endFlankingRegionPixelLength,
                    junctionFeature.getEndFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle,
                    isPositiveStrand);
        } else {
            //Draw rectangles indicating the overlap on each side of the junction
            int overlapRectHeight = 3;
            int overlapRectTopX = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -2 : 0);
            if (pixelFeatureStart < pixelJunctionStart) {
                g2D.fillRect(pixelFeatureStart, overlapRectTopX, pixelJunctionStart - pixelFeatureStart,
                        overlapRectHeight);
            }
            if (pixelJunctionEnd < pixelFeatureEnd) {
                g2D.fillRect(pixelJunctionEnd, overlapRectTopX, pixelFeatureEnd - pixelJunctionEnd,
                        overlapRectHeight);
            }
        }
    }

    //Create a path describing the arc, using Bezier curves. The Bezier control points for the top and
    //bottom arcs are based on the boundary points of the rectangles containing the arcs

    //proportion of the maximum arc height used by a minimum-height arc
    double minArcHeightProportion = 0.33;

    int innerArcHeight = (int) (maxPossibleArcHeight * minArcHeightProportion);
    float depthProportionOfMax = Math.min(1, depth / maxDepth);
    int arcWidth = Math.max(1,
            (int) ((1 - minArcHeightProportion) * maxPossibleArcHeight * depthProportionOfMax));
    int outerArcHeight = innerArcHeight + arcWidth;

    //Height of bottom of the arc
    int arcBeginY = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -1 : 1);
    int outerArcPeakY = isPositiveStrand ? arcBeginY - outerArcHeight : arcBeginY + outerArcHeight;
    int innerArcPeakY = isPositiveStrand ? arcBeginY - innerArcHeight : arcBeginY + innerArcHeight;
    //dhmay: I don't really understand Bezier curves.  For some reason I have to put the Bezier control
    //points farther up or down than I want the arcs to extend.  This multiplier seems about right
    int outerBezierY = arcBeginY + (int) (1.3 * (outerArcPeakY - arcBeginY));
    int innerBezierY = arcBeginY + (int) (1.3 * (innerArcPeakY - arcBeginY));

    //Putting the Bezier control points slightly off to the sides of the arc 
    int bezierXPad = Math.max(1, (pixelJunctionEnd - pixelJunctionStart) / 30);

    GeneralPath arcPath = new GeneralPath();
    arcPath.moveTo(pixelJunctionStart, arcBeginY);
    arcPath.curveTo(pixelJunctionStart - bezierXPad, outerBezierY, //Bezier 1
            pixelJunctionEnd + bezierXPad, outerBezierY, //Bezier 2
            pixelJunctionEnd, arcBeginY); //Arc end
    arcPath.curveTo(pixelJunctionEnd + bezierXPad, innerBezierY, //Bezier 1
            pixelJunctionStart - bezierXPad, innerBezierY, //Bezier 2
            pixelJunctionStart, arcBeginY); //Arc end

    //Draw the arc, to ensure outline is drawn completely (fill won't do it, necessarily). This will also
    //give the arc a darker outline
    g2D.draw(arcPath);
    //Fill the arc
    g2D.fill(arcPath);

    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);

}

From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java

public Point getBendpoint() {
    Rectangle allRect = getRectangle();
    return new Point((int) allRect.getCenterX(), (int) allRect.getCenterY());
}

From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java

protected AngleInfo getTransitionAngle(double x, double y) {
    Rectangle rect = getRectangle();
    double cx = rect.getCenterX();
    double cy = rect.getCenterY();
    if (x == cx) {
        return y - cy > 0 ? new AngleInfo(Double.MAX_VALUE, AngleInfo.QUARTER_IV)
                : new AngleInfo(Double.MAX_VALUE, AngleInfo.QUARTER_II);
    } else {//from  www .  j  a  v  a 2 s. c o  m
        double critAngle = rect.getHeight() / rect.getWidth();
        AngleInfo angleInfo = new AngleInfo();
        angleInfo.setAngle((y - cy) / (x - cx));
        if (Math.abs(angleInfo.getAngle()) > critAngle) {
            if (y - cy > 0) {
                // IV
                angleInfo.setQuarter(AngleInfo.QUARTER_IV);
            } else {
                // II
                angleInfo.setQuarter(AngleInfo.QUARTER_II);
            }
        } else {
            if (x - cx > 0) {
                // I
                angleInfo.setQuarter(AngleInfo.QUARTER_I);
            } else {
                // III
                angleInfo.setQuarter(AngleInfo.QUARTER_III);
            }
        }
        return angleInfo;
    }
}

From source file:ru.runa.wfe.graph.image.figure.AbstractFigure.java

public Point getTransitionPoint(Transition transition, double x, double y) {
    AngleInfo angle = getTransitionAngle(x, y);

    Rectangle r = getRectangle();
    double cx = r.getCenterX();
    double cy = r.getCenterY();

    Line line1 = createBorderLine(angle);
    Line line2 = LineUtils.createLine(new Point((int) cx, (int) cy), angle.getAngle());
    Point intersectionPoint = LineUtils.getIntersectionPoint(line1, line2);
    return intersectionPoint;
}