001package votorola.s.gwt.scene.vote; // Copyright 2011, 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.core.client.JsArray;
004import com.google.gwt.dom.client.Style;
005import com.google.web.bindery.event.shared.HandlerRegistration;
006import votorola.a.count.gwt.*;
007import votorola.a.web.gwt.*;
008import votorola.s.gwt.scene.*;
009import votorola.g.hold.*;
010import votorola.g.lang.*;
011import votorola.g.web.gwt.*;
012import votorola.g.web.gwt.event.*;
013
014import static votorola.s.gwt.scene.vote.VotespaceV.MOSQUITO_BAR_DIVISOR;
015
016
017/** A circular view of base candidate nodes, to be situated at the center of votespace.
018  * The nodes are ordered clockwise by dart sector, with the final node (20) at the top,
019  * and the first node (1) just to its right.
020  */
021final class CenterCircle extends Circle<VotespaceV>
022{
023
024
025    /** Constructs a CenterCircle.
026      */
027    CenterCircle( final VotespaceV votespaceV )
028    {
029        super( null, 0, votespaceV );
030        for( int dS = capacity(); dS > 0; --dS )
031        {
032            final CenterNodeV v = new CenterNodeV( votespaceV, dS );
033            v.setParent( CenterCircle.this );
034        }
035    }
036
037
038
039   // ------------------------------------------------------------------------------------
040
041
042    /** The radius of the center circle.
043      */
044    static final float CENTER_CIRCLE_RADIUS = 10.6f;
045
046
047
048   // - C i r c l e ----------------------------------------------------------------------
049
050
051    NodeV candidateV() { return null; }
052
053
054
055    float nodularStandOff() { return 1.9f; }
056
057
058
059   // - S  V  G - P a r a - N e s t ------------------------------------------------------
060
061
062    public @Override void setParent( final VotespaceV v )
063    {
064        super.setParent( v );
065        new Modeller();
066    }
067
068
069
070//// P r i v a t e ///////////////////////////////////////////////////////////////////////
071
072
073   // ====================================================================================
074
075
076    private final class Modeller implements PropertyChangeHandler
077    {
078
079        private Modeller()
080        {
081            votespaceV().spool().add( new Hold()
082            {
083                final HandlerRegistration hR = GWTX.i().bus().addHandlerToSource(
084                  PropertyChange.TYPE, /*source*/votespaceV().model(), Modeller.this );
085                public void release() { hR.removeHandler(); }
086            });
087            remodel(); // init state
088        }
089
090
091        public void onPropertyChange( final PropertyChange e )
092        {
093            final String n = e.propertyName();
094            if( "count".equals( n )) remodel();
095            else if( "votepath".equals( n )) outCircle().remodelOut();
096        }
097
098
099        private final @Warning("init call") void remodel()
100        {
101            final CountJS count = votespaceV().model().count();
102            if( count == null )
103            {
104                setVisible( false );
105                return;
106            }
107
108            setMosquitoBar( count.voteSuperaccount().castVolume() / MOSQUITO_BAR_DIVISOR );
109            final JsArray<CountNodeJS> baseCandidates = count.baseCandidates();
110            for( int n = 0, nN = capacity(); n < nN; ++n )
111            {
112                final NodeV v = nodeV( n );
113                v.setModel( baseCandidates.get( n ));
114            }
115            registerPainter().repaintLater();
116            outCircle().remodelOut();
117            setVisible( true );
118        }
119
120
121    }
122
123
124
125}