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.dom.client.Style; import org.vectomatic.dom.svg.*; import votorola.a.count.gwt.*; import static org.vectomatic.dom.svg.OMSVGLength.SVG_LENGTHTYPE_PX; import static votorola.s.gwt.scene.vote.VotespaceV.SUB_MNEMONIC_DROP; /** A view of a central candidate's count node. */ final class CenterNodeV extends NodeV { /** Constructs a CenterNodeV. * * @see #dartSector() */ CenterNodeV( final VotespaceV vV, final int dartSector ) { super( vV, dartSector ); localView().getElement().setPropertyString( "votepath", Character.toString( DartScoping.DIGIT_ENCODER.charAt( dartSector ))); localView().addClassNameBaseVal( "clickable" ); // LAYOUT rightward of poll name // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = float y = 0; // Mnemonic. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { final OMSVGTextElement text = vV.document().createSVGTextElement(); localView().appendChild( text ); text.addClassNameBaseVal( "mnemonic" ); vV.append( text.getY(), y += -0.2f ); // up, center in nodular standoff text.appendChild( mnemonicTextNode() ); } // Receive volume. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - receiveVolumeV = new FlowVolumeV( vV ); localView().appendChild( receiveVolumeV ); vV.append( receiveVolumeV.getY(), y += SUB_MNEMONIC_DROP ); // TRANSFORM angularly and radially // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = final float pxPerEm = vV.pxPerEm(); final float interAngle = 18f; // between nodes final float angle = (dartSector - 5) * interAngle; // align 20 at top svgView().setAttribute( "transform", "rotate(" + angle + ") translate(" + CenterCircle.CENTER_CIRCLE_RADIUS * pxPerEm + ")" ); } // - C o u n t - N o d e - V ---------------------------------------------------------- @Override void repaintRegister( final CountingMethodJS.SwitchMnemonic mCM, final String accountName ) { final CountNodeJS node = model(); if( node == null ) return; long receiveVolume = -1L; // meaning no such superaccount, till proven otherwise if( mCM == CountingMethodJS.SwitchMnemonic.q ) { final SacRegisterJS_q r = node.register( mCM.fullName(), accountName ); if( r != null ) receiveVolume = r.receiveVolume(); } else if( mCM == CountingMethodJS.SwitchMnemonic.v ) { final SacRegisterJS_v r = node.register( mCM.fullName(), accountName ); if( r != null ) receiveVolume = r.receiveVolume(); } else throw new IllegalArgumentException(); if( receiveVolume >= 0L ) { receiveVolumeV.set( receiveVolume ); receiveVolumeV.getStyle().clearDisplay(); } else receiveVolumeV.getStyle().setDisplay( Style.Display.NONE ); // no such superaccount } @Override boolean setModel( final CountNodeJS node ) { if( !super.setModel( node )) return false; if( node != null ) { final long receiveVolume = node.voteRegister().receiveVolume(); setMosquito( receiveVolume < parent().mosquitoBar() ); } return true; } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final FlowVolumeV receiveVolumeV; }