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.*; import votorola.g.web.gwt.*; import votorola.g.web.gwt.event.*; import votorola.g.web.gwt.svg.*; import votorola.s.gwt.stage.vote.*; import static votorola.s.gwt.stage.vote.PeerBoardV.PIN_IMG_WIDTH; /** A component of the bridge/stage {@linkplain DIn tie overlay} that visually ties the * selected drafter's link (sLink) at top left of the bridge scene to the pin indicator * in the vote track.
  *
  *                                       pin       +
  *                                    indicator   / \
  *                                               +-+-+
  *                                                 |
  *                                                 |
  *    sLink  +-------------------------------------+
*/ final class AnchorLine extends Connector { /** Creates an AnchorLine. Create at most one for the entire life of the document as * currently it does not unregister its listeners or otherwise clean up after itself. */ AnchorLine( final VoteTrackV trackV ) { super( "sLink" ); // invisible pending first repaint peersBoardV = trackV.peersBoardV(); addClassNameBaseVal( "AnchorLine" ); new Painter(); } private static AnchorLine instance; { if( instance != null ) throw new IllegalStateException(); instance = AnchorLine.this; } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final PeerBoardV peersBoardV; private void repaint() { final ImageElement pinImg = peersBoardV.pinImg(); if( pinImg == null ) { assert false: "track is pinned"; assert !isVisible(); return; } final int linkHeight = link().getOffsetHeight(); final int linkRight = link().getAbsoluteRight(); final int x0 = linkRight + /*margin*/(int)(linkHeight * 0.4f); final int midX = pinImg.getAbsoluteLeft() + PIN_IMG_WIDTH / 2; // image's absolute position readable even though it was set just now and is // probably not yet rendered, because it really *is* absolutely positioned if( isLongEnough( x0, midX, linkHeight )) setVisible( true ); else { setVisible( false ); return; } // - - ---+---+----------------+---+---+---+ // \ \ \ \ \ \ // + + + + + + + // / / / \ / / / / // - - ---+---+-------/ \----+---+---+---+ // margin / \ // | pinImg +---+---+ // |-| | 2 // | // link +-------------------------------------+ 1 (midX,y) // 0 final int y = link().getAbsoluteTop() + linkSink(linkHeight); final OMSVGPathSegList sL = getPathSegList(); PathSeg.movetoAbs( sL, 0, x0, y ); PathSeg.lineToAbs( sL, 1, midX, y ); PathSeg.lineToAbs( sL, 2, midX, pinImg.getAbsoluteBottom() ); } // ==================================================================================== private final class Painter implements ChangeHandler { Painter() { GWTX.i().bus().addHandlerToSource( Change.TYPE, /*source*/peersBoardV.painter(), Painter.this ); // no need to unregister, registry does not outlive this listener if( peersBoardV.isVisible() ) repaint(); // init } public final void onChange( Change _e ) { repaint(); } } }