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 com.google.gwt.dom.client.*;
004import org.vectomatic.dom.svg.*;
005
006
007/** A connecting path in the bridge/stage {@linkplain DIn tie overlay}.
008  */
009abstract class Connector extends OMSVGPathElement
010{
011
012
013    /** Creates a Connector.  It is initially {@linkplain #isVisible() invisible}.
014      *
015      *     @param linkID the 'id' attribute of the link.
016      */
017    Connector( final String linkID )
018    {
019        link = Document.get().getElementById( linkID );
020        setVisible( false );
021        final OMSVGPathSegList sL = getPathSegList();
022   /*0*/sL.appendItem( createSVGPathSegMovetoAbs( 0,0 ));
023   /*1*/sL.appendItem( createSVGPathSegLinetoAbs( 0,0 ));
024   /*2*/sL.appendItem( createSVGPathSegLinetoAbs( 0,0 ));
025    }
026
027
028
029   // ------------------------------------------------------------------------------------
030
031
032    /** Answers whether the path is long enough to bother drawing.
033      */
034    final boolean isLongEnough( final int x0, final int midX, final int linkHeight )
035    {
036        return midX - x0 > linkHeight / 2;
037    }
038
039
040
041    /** Answers whether this connector is nominally visible.  Returns false if the display
042      * style is "none", true otherwise.
043      *
044      *     @see #setVisible(boolean)
045      */
046    final boolean isVisible() { return !"none".equals( getStyle().getDisplay() ); }
047
048
049        /** Sets the visibility of this connector.
050          *
051          *     @see #isVisible()
052          */
053        final void setVisible( final boolean toBe )
054        {
055            if( toBe ) getStyle().clearDisplay();
056            else getStyle().setDisplay( Style.Display.NONE );
057        }
058
059
060
061    /** The link that is joined to the vote track by this connector.
062      */
063    final Element link() { return link; }
064
065
066        private final Element link;
067
068
069
070    /** The vertical distance from the top of the link to where the connector is drawn.
071      *
072      *     @param height the height of the link element.
073      */
074    final int linkSink( final int height ) { return (int)( height * 0.65f ); }
075
076
077}