package 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. import com.google.gwt.core.client.JsArray; import com.google.gwt.dom.client.Style; import com.google.web.bindery.event.shared.HandlerRegistration; import votorola.a.count.gwt.*; import votorola.a.web.gwt.*; import votorola.s.gwt.scene.*; import votorola.g.hold.*; import votorola.g.lang.*; import votorola.g.web.gwt.*; import votorola.g.web.gwt.event.*; import static votorola.s.gwt.scene.vote.VotespaceV.MOSQUITO_BAR_DIVISOR; /** A circular view of base candidate nodes, to be situated at the center of votespace. * The nodes are ordered clockwise by dart sector, with the final node (20) at the top, * and the first node (1) just to its right. */ final class CenterCircle extends Circle { /** Constructs a CenterCircle. */ CenterCircle( final VotespaceV votespaceV ) { super( null, 0, votespaceV ); for( int dS = capacity(); dS > 0; --dS ) { final CenterNodeV v = new CenterNodeV( votespaceV, dS ); v.setParent( CenterCircle.this ); } } // ------------------------------------------------------------------------------------ /** The radius of the center circle. */ static final float CENTER_CIRCLE_RADIUS = 10.6f; // - C i r c l e ---------------------------------------------------------------------- NodeV candidateV() { return null; } float nodularStandOff() { return 1.9f; } // - S V G - P a r a - N e s t ------------------------------------------------------ public @Override void setParent( final VotespaceV v ) { super.setParent( v ); new Modeller(); } //// P r i v a t e /////////////////////////////////////////////////////////////////////// // ==================================================================================== private final class Modeller implements PropertyChangeHandler { private Modeller() { votespaceV().spool().add( new Hold() { final HandlerRegistration hR = GWTX.i().bus().addHandlerToSource( PropertyChange.TYPE, /*source*/votespaceV().model(), Modeller.this ); public void release() { hR.removeHandler(); } }); remodel(); // init state } public void onPropertyChange( final PropertyChange e ) { final String n = e.propertyName(); if( "count".equals( n )) remodel(); else if( "votepath".equals( n )) outCircle().remodelOut(); } private final @Warning("init call") void remodel() { final CountJS count = votespaceV().model().count(); if( count == null ) { setVisible( false ); return; } setMosquitoBar( count.voteSuperaccount().castVolume() / MOSQUITO_BAR_DIVISOR ); final JsArray baseCandidates = count.baseCandidates(); for( int n = 0, nN = capacity(); n < nN; ++n ) { final NodeV v = nodeV( n ); v.setModel( baseCandidates.get( n )); } registerPainter().repaintLater(); outCircle().remodelOut(); setVisible( true ); } } }