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 votorola.a.voter.*; import votorola.g.lang.*; import votorola.g.web.gwt.*; import votorola.g.web.gwt.svg.*; /** A view of a count node. */ abstract class NodeV extends SVGParaNest> { /** Constructs a NodeV. * * @see #dartSector() */ NodeV( final VotespaceV votespaceV, int _dartSector ) { dartSector = _dartSector; final OMSVGDocument document = votespaceV.document(); svgView = document.createSVGGElement(); setVisible( false ); // hide by default localView = document.createSVGGElement(); svgView.appendChild( localView ); localView.addClassNameBaseVal( "countNode" ); localView.addClickHandler( votespaceV.pathExtender() ); // no need to unregister, registry does not outlive the handler mnemonicTextNode = document.createTextNode( "" ); // mnemonicTextNode.setData( Integer.toString( dartSector )); // TEST code } // - C o u n t - N o d e - V ---------------------------------------------------------- /** The dart sector of this view. * * @see votorola.a.count.CountNode#dartSector() */ final int dartSector() { return dartSector; } private final int dartSector; /** Answers whether this node is to be shown as a "mosquito", because its vote volume * falls below the circle's mosquito bar. * * @see Circle#mosquitoBar() */ final boolean isMosquito() { return isMosquito; } private boolean isMosquito; /** Sets whether this node is to be shown as a "mosquito". */ final void setMosquito( final boolean is ) { if( is == isMosquito ) return; if( is ) localView.addClassNameBaseVal( "mosquito" ); else localView.removeClassNameBaseVal( "mosquito" ); isMosquito = is; } /** Answers whether the SVG component is nominally visible, returning false if the * display style is "none"; true otherwise. * * @see #svgView() * @see #setVisible(boolean) */ final boolean isVisible() { return !"none".equals( svgView().getStyle().getDisplay() ); } /** Sets the visibility of the SVG component. * * @see #isVisible() */ private final void setVisible( boolean toBe ) { final Style style = svgView.getStyle(); if( toBe ) style.clearDisplay(); else style.setDisplay( Style.Display.NONE ); } /** The view of the node in itself, separate from any radial line or surrounding * circles of voters. The local view is oriented upright (inverse rotation from * parent SVG view) for sake of readability. It is also made clickable. * * @see #svgView() */ final OMSVGGElement localView() { return localView; } private final OMSVGGElement localView; /** The count node on which this view is modelled, or null if none is modelled. * * @see #setModel(CountNodeJS) */ final CountNodeJS model() { return model; } private CountNodeJS model; /** Sets the count node on which this view is modelled, and adjusts rotation, * styles and other view properties to match the current ancestry of the node. * This assumes no subsequent changes among ancestor properties from model * changes or rotation transforms. * * @return true if the model was set, false if it already was set. * @throws IllegalArgumentException if the model does not have the same dart * sector as this view. */ boolean setModel( final CountNodeJS newModel ) { if( ObjectX.nullEquals( newModel, model )) return false; model = newModel; if( model == null ) { setVisible( false ); // mnemonicTextNode.setData( Integer.toString( dartSector )); // TEST code // mnemonicTextNode.setData( "X" ); return true; } if( model.dartSector() != dartSector ) throw new IllegalArgumentException( "dart sector mismatch" ); final OMSVGMatrix currentTransforms = svgView.getCTM(); final OMSVGMatrix i = currentTransforms.inverse(); localView.setAttribute( "transform", "matrix(" // inverse rotation only + i.getA() + " " + i.getB() + " " + i.getC() + " " + i.getD() + " 0 0)" ); mnemonicTextNode.setData( IDPair.buildUserMnemonic( model.name(), GWTX.stringBuilderClear() ).toString() ); setVisible( true ); return true; } /** A text node that shows the abbreviated username. */ final OMText mnemonicTextNode() { return mnemonicTextNode; } private final OMText mnemonicTextNode; /** Repaints the view of the superaccount register. * * @see SacJS#accountName() */ abstract void repaintRegister( CountingMethodJS.SwitchMnemonic mCM, String accountName ); /** The radix 21 votepath from this view. The value is set by subclasses as the * "votepath" property of the underlying local view, whence it is accessible to event * handlers. * * @see #setModel(CountNodeJS) * @see #localView() * @see DartScoping#votepath() */ final String votepath() { return localView().getElement().getPropertyString( "votepath" ); } // see possible fix for this hack in votorola.g.web.gwt.SVGNest.parent() // - S V G - P a r a - N e s t ------------------------------------------------------ public final @Override void setParent( final Circle circle ) { super.setParent( circle ); circle.setCountNodeV( NodeV.this, dartSector - 1 ); } // - S V G - W r a p p e r ---------------------------------------------------------- /** @see #localView() */ public final OMSVGGElement svgView() { return svgView; } private final OMSVGGElement svgView; }