package votorola.s.gwt.stage.vote; // Copyright 2012-2013, 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 votorola.a.count.*; import votorola.a.web.gwt.*; import votorola.g.hold.*; import votorola.s.gwt.stage.*; //import static votorola.a.count.CountNode.DART_SECTOR_MAX; /** A view of a peer board rendered as an HTML table cell containing an SVG drawing. It * differs from an ordinary board view in having a pin indicator. The {@linkplain * #pinImg() pin indicator} decorates the node view of the anchor whenever the anchor is * contained within the board and is {@linkplain VoteTrack#toPin(Stage) pinned}. The * bottom of the indicator extends below the boundary of the track, overlapping whatever * is beneath. Its pointer events are therefore disabled.
  *
  *   +---+---+--------+---+- -    -+---+----------------+---+---+---+
  *    \   \   \        \   \        \   \                \   \   \   \
  *     +   +   +        +   +        +   +       +        +   +   +   +
  *    /   /   /        /   /        /   /       / \      /   /   /   /
  *   +---+---+--------+---+- -    -+---+-------/   \----+---+---+---+
  *     0   1     2      3  . . .     16       / pin \     18  19  20
  *                                           +-------+
* *

Acknowledgement: Thomas von der Elbe assisted in troubleshooting the visualization * problems that led to the design of the pin indicator. See the thread Difference lighting and cross-linking on the bridge.

*/ public final class PeerBoardV extends BoardV { /** Partially constructs a PeerBoardV for {@linkplain #init() init} to finish. * * @param _board the board on which the view is modelled. * @param element the outermost HTML element of which the view is composed. */ PeerBoardV( PeerBoard _board, final VoteTrackV trackV, final TableCellElement element ) { super( _board, trackV, element, XCastRelation.CO_VOTER ); trackV.track().initWaitSpool().add( new Hold() { public void release() { if( !VoteTrack.toPin( Stage.i() )) return; pinImgOrNull = Document.get().createImageElement(); pinImgOrNull.setSrc( App.i().staticContextLocation() + "/stage/vote/pin.png" ); pinImgOrNull.setClassName( "pin" ); pinImgOrNull.getStyle().setDisplay( Style.Display.NONE ); // till repaint // element.getFirstChildElement().appendChild( pinImgOrNull ); // to div element.appendChild( pinImgOrNull ); } }); } /** Completes the construction of this BoardV. Call once only. */ @Override void init() { init( new Painter() { private final boolean isBottomFixed = trackV() == VoteTrackV.iBottomFixed(); @Override void repaint2( final float protrusion, int y, final float halfThickness, final float xAnchor, final float lengthAnchor ) { if( pinImgOrNull != null ) { final Style pinStyle = pinImgOrNull.getStyle(); if( xAnchor == -1 ) pinStyle.setDisplay( Style.Display.NONE ); else { pinStyle.clearDisplay(); float xPin = xAnchor - PIN_IMG_WIDTH/2f + protrusion + lengthAnchor/2 - /*correction for perfect centering*/1; xPin += getAbsoluteLeft(); // from left of table cell (or row?) float yPin = isBottomFixed? y - halfThickness: y + halfThickness; pinStyle.setLeft( xPin, Style.Unit.PX ); pinStyle.setTop( yPin, Style.Unit.PX ); } } } }); } // ------------------------------------------------------------------------------------ /** The width of the pin indicator image. */ public static final int PIN_IMG_WIDTH = 16; /** The image element that indicates the {@linkplain VoteTrack#toPin(Stage) pinned} * anchor, or null if this board has no pinned anchor. */ public ImageElement pinImg() { return pinImgOrNull; } private ImageElement pinImgOrNull; // rendered as HTML image instead of SVG graphic because SVG cannot be drawn // outside of container. https://bugzilla.mozilla.org/show_bug.cgi?id=378923 }