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.dom.client.Style;
004import org.vectomatic.dom.svg.*;
005import votorola.a.count.gwt.*;
006
007import static org.vectomatic.dom.svg.OMSVGLength.SVG_LENGTHTYPE_PX;
008import static votorola.s.gwt.scene.vote.VotespaceV.SUB_MNEMONIC_DROP;
009
010
011/** A view of a central candidate's count node.
012  */
013final class CenterNodeV extends NodeV
014{
015
016
017    /** Constructs a CenterNodeV.
018      *
019      *     @see #dartSector()
020      */
021    CenterNodeV( final VotespaceV vV, final int dartSector )
022    {
023        super( vV, dartSector );
024        localView().getElement().setPropertyString( "votepath",
025          Character.toString( DartScoping.DIGIT_ENCODER.charAt( dartSector )));
026        localView().addClassNameBaseVal( "clickable" );
027
028      // LAYOUT  rightward of poll name
029      // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
030        float y = 0;
031
032      // Mnemonic.
033      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
034        {
035            final OMSVGTextElement text = vV.document().createSVGTextElement();
036            localView().appendChild( text );
037            text.addClassNameBaseVal( "mnemonic" );
038            vV.append( text.getY(), y += -0.2f ); // up, center in nodular standoff
039
040            text.appendChild( mnemonicTextNode() );
041        }
042
043      // Receive volume.
044      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
045        receiveVolumeV = new FlowVolumeV( vV );
046        localView().appendChild( receiveVolumeV );
047        vV.append( receiveVolumeV.getY(), y += SUB_MNEMONIC_DROP );
048
049      // TRANSFORM  angularly and radially
050      // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
051        final float pxPerEm = vV.pxPerEm();
052        final float interAngle = 18f; // between nodes
053        final float angle = (dartSector - 5) * interAngle; // align 20 at top
054        svgView().setAttribute( "transform", "rotate(" + angle
055          + ") translate(" + CenterCircle.CENTER_CIRCLE_RADIUS * pxPerEm + ")" );
056    }
057
058
059
060   // - C o u n t - N o d e - V ----------------------------------------------------------
061
062
063    @Override void repaintRegister( final CountingMethodJS.SwitchMnemonic mCM,
064      final String accountName )
065    {
066        final CountNodeJS node = model();
067        if( node == null ) return;
068
069        long receiveVolume = -1L; // meaning no such superaccount, till proven otherwise
070        if( mCM == CountingMethodJS.SwitchMnemonic.q )
071        {
072            final SacRegisterJS_q r = node.register( mCM.fullName(), accountName );
073            if( r != null ) receiveVolume = r.receiveVolume();
074        }
075        else if( mCM == CountingMethodJS.SwitchMnemonic.v )
076        {
077            final SacRegisterJS_v r = node.register( mCM.fullName(), accountName );
078            if( r != null ) receiveVolume = r.receiveVolume();
079        }
080        else throw new IllegalArgumentException();
081
082        if( receiveVolume >= 0L )
083        {
084            receiveVolumeV.set( receiveVolume );
085            receiveVolumeV.getStyle().clearDisplay();
086        }
087        else receiveVolumeV.getStyle().setDisplay( Style.Display.NONE ); // no such superaccount
088    }
089
090
091
092    @Override boolean setModel( final CountNodeJS node )
093    {
094        if( !super.setModel( node )) return false;
095
096        if( node != null )
097        {
098            final long receiveVolume = node.voteRegister().receiveVolume();
099            setMosquito( receiveVolume < parent().mosquitoBar() );
100        }
101        return true;
102    }
103
104
105
106//// P r i v a t e ///////////////////////////////////////////////////////////////////////
107
108
109    private final FlowVolumeV receiveVolumeV;
110
111
112}