package votorola.s.gwt.stage.vote; // Copyright 2013, 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.*; import votorola.g.lang.*; import votorola.g.web.gwt.*; import votorola.s.gwt.stage.*; import votorola.s.gwt.stage.light.*; /** A stage light to indicate the dart sector and cast relation of the {@linkplain * NodeV.Sensor node sensor} pointed by the user. */ final class DartLight implements Light { /** Creates the {@linkplain #i() single instance} of DartLight. */ DartLight() { Stage.i().lightBank().addLight( DartLight.this ); // no need to remove, co-extant } /** The single instance of DartLight. */ static DartLight i() { return instance; } private static DartLight instance; { if( instance != null ) throw new IllegalStateException(); instance = DartLight.this; } // - L i g h t ------------------------------------------------------------------------ public Actuator assignActuator( final NodeV.Sensor sensor ) { return new ActuatorD( sensor ); } public final NodeV.Sensor tryCast( final Sensor sensor ) { return sensor instanceof NodeV.Sensor? (NodeV.Sensor)sensor: null; } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private ActuatorD actuatorLit; private String bodyClassLit; // ==================================================================================== private final class ActuatorD implements Actuator { ActuatorD( final NodeV.Sensor sensor ) { nodeV = sensor.view(); resetBodyClass(); } private String bodyClass; // for the assigned sensor private @Warning("init call") void resetBodyClass() { bodyClass = nodeV.isTightCycler()? "voDartLight-y": // tight cycle, to light both voter and candidate as they are same person "voDartLight-" + nodeV.dartLightClassName(); } private final NodeV nodeV; private void relight( final String bodyClassNew ) { if( ObjectX.nullEquals( bodyClassLit, bodyClassNew )) return; ElementX.replaceNullClassName( bodyClassLit, bodyClassNew, Document.get().getBody() ); bodyClassLit = bodyClassNew; } // - A c t u a t o r -------------------------------------------------------------- public void changed( NodeV.Sensor sensor_ ) { resetBodyClass(); if( actuatorLit == ActuatorD.this ) relight( bodyClass ); } public Light light() { return DartLight.this; } public void out( final NodeV.Sensor sensor ) { if( actuatorLit == ActuatorD.this ) actuatorLit = null; relight( null ); } public void over( final NodeV.Sensor sensor ) { actuatorLit = ActuatorD.this; relight( bodyClass ); } } }