package 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. import com.google.gwt.dom.client.*; import org.vectomatic.dom.svg.*; /** A connecting path in the bridge/stage {@linkplain DIn tie overlay}. */ abstract class Connector extends OMSVGPathElement { /** Creates a Connector. It is initially {@linkplain #isVisible() invisible}. * * @param linkID the 'id' attribute of the link. */ Connector( final String linkID ) { link = Document.get().getElementById( linkID ); setVisible( false ); final OMSVGPathSegList sL = getPathSegList(); /*0*/sL.appendItem( createSVGPathSegMovetoAbs( 0,0 )); /*1*/sL.appendItem( createSVGPathSegLinetoAbs( 0,0 )); /*2*/sL.appendItem( createSVGPathSegLinetoAbs( 0,0 )); } // ------------------------------------------------------------------------------------ /** Answers whether the path is long enough to bother drawing. */ final boolean isLongEnough( final int x0, final int midX, final int linkHeight ) { return midX - x0 > linkHeight / 2; } /** Answers whether this connector is nominally visible. Returns false if the display * style is "none", true otherwise. * * @see #setVisible(boolean) */ final boolean isVisible() { return !"none".equals( getStyle().getDisplay() ); } /** Sets the visibility of this connector. * * @see #isVisible() */ final void setVisible( final boolean toBe ) { if( toBe ) getStyle().clearDisplay(); else getStyle().setDisplay( Style.Display.NONE ); } /** The link that is joined to the vote track by this connector. */ final Element link() { return link; } private final Element link; /** The vertical distance from the top of the link to where the connector is drawn. * * @param height the height of the link element. */ final int linkSink( final int height ) { return (int)( height * 0.65f ); } }