001package votorola.s.gwt.wic; // Copyright 2012, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import org.vectomatic.dom.svg.*;
004import votorola.g.web.gwt.svg.*;
005
006
007/** A component of the bridge/stage {@linkplain DIn connector overlay} that visually ties
008  * the other (non-anchor) drafter's link (tLink) at top left of the bridge scene to the
009  * {@linkplain AlterBracket alter bracket}.<pre>
010  *
011  *                             alter   |             |
012  *                            bracket  +------+------+
013  *                                            |
014  *    tLink  +--------------------------------+</pre>
015  */
016final class AlterLine extends Connector
017{
018
019
020    /** Creates an AlterLine.
021      */
022    AlterLine()
023    {
024        super( "tLink" ); // invisible pending AlterBracket.Visibilizer
025        addClassNameBaseVal( "AlterLine" );
026    }
027
028
029
030   // ------------------------------------------------------------------------------------
031
032
033    /** Redraws this line to connect with the bracket, or sets it invisible if the bracket
034      * is too close to the link.
035      */
036    void repaint( final AlterBracket bracket )
037    {
038        final int linkHeight = link().getOffsetHeight();
039        final int linkRight = link().getAbsoluteRight();
040        final int x0 = linkRight + /*margin*/(int)(linkHeight * 0.2f);
041        final OMSVGPathSegMovetoAbs p0 = bracket.p0();
042        final int midX = (int)( p0.getX() + bracket.length() / 2 );
043        if( isLongEnough( x0, midX, linkHeight )) setVisible( true );
044        else
045        {
046            setVisible( false );
047            return;
048        }
049
050          //                              p0 +                  +  -
051          //      margin                     |      bracket     |  | depth
052          //        |                        +--------+---------+  -
053          //       |-|                                | 2
054          //                                          |
055          //   link  +--------------------------------+ 1  (midX,y)
056          //         0
057
058        final int y = link().getAbsoluteTop() + linkSink(linkHeight);
059        final OMSVGPathSegList sL = getPathSegList();
060        PathSeg.movetoAbs( sL, 0, x0, y );
061        PathSeg.lineToAbs( sL, 1, midX, y );
062        PathSeg.lineToAbs( sL, 2, midX, p0.getY() + bracket.depth() );
063    }
064
065
066}