001package votorola.s.gwt.mediawiki; // 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 votorola.s.gwt.stage.*;
005import votorola.s.gwt.stage.light.*;
006import votorola.s.gwt.stage.vote.*;
007
008import static votorola.a.count.CountNode.DART_SECTOR_MAX;
009
010
011/** The stage light for {@linkplain DifferenceShadows difference shadows}.
012  */
013final class ShadowLight extends DifferenceLight<ShadowedDiff>
014{
015
016
017    /** Creates the ShadowLight.  Create at most one for the entire life of the document,
018      * as currently it does not unregister its listeners or otherwise clean up after
019      * itself.
020      */
021    ShadowLight( DifferenceShadows _shadows, DifferenceShadowsV _shadowsV, final Stage stage )
022    {
023        super( VoteTrack.i(stage) );
024        shadows = _shadows;
025        shadowsV = _shadowsV;
026        init( stage );
027    }
028
029
030
031   // - D i f f e r e n c e - L i g h t --------------------------------------------------
032
033
034    protected ShadowedDiff differenceFor( final String personName, final String pollName )
035    {
036        return shadows.diffFor( personName, pollName );
037    }
038
039
040
041    protected boolean hasDiffLooks() { return true; }
042
043
044
045    protected @Override LightableDifference redirect()
046    {
047        final ShadowedDiff diff = (ShadowedDiff)super.redirect(); // safe cast, no setScene
048        final DifferenceShadowsV.TopBox topBox = shadowsV.topBox();
049        final Text segCounter = topBox.segCounter();
050        final String bridgeImgSrc;
051        if( diff == null )
052        {
053            bridgeImgSrc = DifferenceShadowsV.SRC_DIFF_DISABLED;
054            segCounter.setData( "\u00a0" ); // non-breaking space
055            segCounter.getParentElement().getStyle().setVisibility( Style.Visibility.HIDDEN );
056              // counter span
057            topBox.segCounterArrow().getStyle().setVisibility( Style.Visibility.HIDDEN );
058        }
059        else
060        {
061            bridgeImgSrc = DifferenceShadowsV.SRC_DIFF;
062            segCounter.setData( Integer.toString( diff.segmentCount() ));
063            segCounter.getParentElement().getStyle().clearVisibility(); // to default
064            topBox.segCounterArrow().getStyle().clearVisibility(); // to default
065        }
066     // ImageElement.as(topBox.bridgeLink().getFirstChild()).setSrc( bridgeImgSrc );
067     /// GWT BUG, 'as' resolves to Element
068        ((ImageElement)topBox.bridgeLink().getFirstChild()).setSrc( bridgeImgSrc );
069        return diff;
070    }
071
072
073
074    protected void run( final LightableDifference.Runner<ShadowedDiff> r ) { shadows.run( r ); }
075
076
077
078//// P r i v a t e ///////////////////////////////////////////////////////////////////////
079
080
081    private final DifferenceShadows shadows;
082
083
084
085    private final DifferenceShadowsV shadowsV;
086
087
088}