001package 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. 002 003import com.google.gwt.dom.client.*; 004import votorola.a.count.*; 005import votorola.a.web.gwt.*; 006import votorola.g.hold.*; 007import votorola.s.gwt.stage.*; 008 009//import static votorola.a.count.CountNode.DART_SECTOR_MAX; 010 011 012/** A view of a peer board rendered as an HTML table cell containing an SVG drawing. It 013 * differs from an ordinary board view in having a pin indicator. The {@linkplain 014 * #pinImg() pin indicator} decorates the node view of the anchor whenever the anchor is 015 * contained within the board and is {@linkplain VoteTrack#toPin(Stage) pinned}. The 016 * bottom of the indicator extends below the boundary of the track, overlapping whatever 017 * is beneath. Its pointer events are therefore disabled.<pre> 018 * 019 * +---+---+--------+---+- - -+---+----------------+---+---+---+ 020 * \ \ \ \ \ \ \ \ \ \ \ 021 * + + + + + + + + + + + + 022 * / / / / / / / / \ / / / / 023 * +---+---+--------+---+- - -+---+-------/ \----+---+---+---+ 024 * 0 1 2 3 . . . 16 / pin \ 18 19 20 025 * +-------+</pre> 026 * 027 * <p>Acknowledgement: Thomas von der Elbe assisted in troubleshooting the visualization 028 * problems that led to the design of the pin indicator. See the thread <a 029 * href='http://mail.zelea.com/list/votorola/2012-August/thread.html' 030 * target='_top'>Difference lighting and cross-linking on the bridge</a>.</p> 031 */ 032public final class PeerBoardV extends BoardV 033{ 034 035 036 /** Partially constructs a PeerBoardV for {@linkplain #init() init} to finish. 037 * 038 * @param _board the board on which the view is modelled. 039 * @param element the outermost HTML element of which the view is composed. 040 */ 041 PeerBoardV( PeerBoard _board, final VoteTrackV trackV, final TableCellElement element ) 042 { 043 super( _board, trackV, element, XCastRelation.CO_VOTER ); 044 trackV.track().initWaitSpool().add( new Hold() 045 { 046 public void release() 047 { 048 if( !VoteTrack.toPin( Stage.i() )) return; 049 050 pinImgOrNull = Document.get().createImageElement(); 051 pinImgOrNull.setSrc( App.i().staticContextLocation() + "/stage/vote/pin.png" ); 052 pinImgOrNull.setClassName( "pin" ); 053 pinImgOrNull.getStyle().setDisplay( Style.Display.NONE ); // till repaint 054 // element.getFirstChildElement().appendChild( pinImgOrNull ); // to div 055 element.appendChild( pinImgOrNull ); 056 } 057 }); 058 } 059 060 061 062 /** Completes the construction of this BoardV. Call once only. 063 */ 064 @Override void init() 065 { 066 init( new Painter() 067 { 068 private final boolean isBottomFixed = trackV() == VoteTrackV.iBottomFixed(); 069 070 @Override void repaint2( final float protrusion, int y, final float halfThickness, 071 final float xAnchor, final float lengthAnchor ) 072 { 073 if( pinImgOrNull != null ) 074 { 075 final Style pinStyle = pinImgOrNull.getStyle(); 076 if( xAnchor == -1 ) pinStyle.setDisplay( Style.Display.NONE ); 077 else 078 { 079 pinStyle.clearDisplay(); 080 float xPin = xAnchor - PIN_IMG_WIDTH/2f + protrusion + lengthAnchor/2 - 081 /*correction for perfect centering*/1; 082 xPin += getAbsoluteLeft(); // from left of table cell (or row?) 083 float yPin = isBottomFixed? y - halfThickness: y + halfThickness; 084 pinStyle.setLeft( xPin, Style.Unit.PX ); 085 pinStyle.setTop( yPin, Style.Unit.PX ); 086 } 087 } 088 } 089 }); 090 } 091 092 093 094 // ------------------------------------------------------------------------------------ 095 096 097 /** The width of the pin indicator image. 098 */ 099 public static final int PIN_IMG_WIDTH = 16; 100 101 102 103 /** The image element that indicates the {@linkplain VoteTrack#toPin(Stage) pinned} 104 * anchor, or null if this board has no pinned anchor. 105 */ 106 public ImageElement pinImg() { return pinImgOrNull; } 107 108 109 private ImageElement pinImgOrNull; 110 // rendered as HTML image instead of SVG graphic because SVG cannot be drawn 111 // outside of container. https://bugzilla.mozilla.org/show_bug.cgi?id=378923 112 113 114}