package votorola.s.gwt.stage.vote; // Copyright 2012, 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.JavaScriptObject;
import votorola.a.count.XCastRelation;
import votorola.g.lang.Typifier;
import votorola.g.web.gwt.JavaScriptObjectX;
/** A difference that is lightable by a DifferenceLight. It corresponds to the difference
* (perhaps empty) between a position represented in the vote track and that of the
* {@linkplain VoteTrack#anchor() anchoring author}. Difference lighting in general is
* mediated by style classes set on the #{@linkplain votorola.s.gwt.stage.StageV
* StageV-top} element and the document body. The #StageV-top
element gets
* classes for all differences (up to {@linkplain DifferenceLight#MAX_DIFFS MAX_DIFFS})
* that have representation in the track, each class being named after the cast relation
* of the {@linkplain votorola.s.gwt.stage.light.PositionSensor#personName() other
* author} in regard to the {@linkplain VoteTrack#anchor() anchoring author}. At most
* one of these differences is spotlit at a given time, the spotlight being implemented
* by two or three classes set on document body as detailed in the following table.
*
*
*
* Relation |
* {@linkplain #stageRelClass() stageRelClass} |
* {@linkplain #bodyRelClass() bodyRelClass} |
* {@linkplain #bodySecClass() bodySecClass} |
* Ordinal |
* {@linkplain #bodyOrdClass() bodyOrdClass} |
*
* {@linkplain XCastRelation#VOTER Voter} |
*
* vDS |
*
* voLiDi-rel-v |
*
* voLiDi-DS |
*
* a |
*
* voLiDi-ord-a |
*
*
*
* {@linkplain XCastRelation#CO_VOTER Co-voter} |
*
* oDS |
*
* voLiDi-rel-o |
*
* voLiDi-DS |
*
* a |
*
* voLiDi-ord-a |
*
*
* b |
*
* voLiDi-ord-b |
*
*
*
* Tight cycler |
*
* y |
*
* voLiDi-rel-y |
*
* none |
*
* a |
*
* voLiDi-ord-a |
*
*
* b |
*
* voLiDi-ord-b |
*
*
*
* {@linkplain XCastRelation#CO_BASE Base co-candidate} |
*
* oDS |
*
* voLiDi-rel-o |
*
* voLiDi-DS |
*
* a |
*
* voLiDi-ord-a |
*
*
* b |
*
* voLiDi-ord-b |
*
*
* {@linkplain XCastRelation#CANDIDATE Candidate} |
*
* c |
*
* voLiDi-rel-c |
*
* none |
*
* b |
*
* voLiDi-ord-b |
*
*
*
*
* The variable DS is the other author's dart sector, from 0 to {@value
* votorola.a.count.CountNode#DART_SECTOR_MAX}.
*/
public interface LightableDifference
{
/** The base {@value} for all values of {@linkplain #actorLinkVariant()
* actorLinkVariant}(), which is itself a valid default variant.
*/
public static final String ACTOR_LINK_VARIANT_BASE = "VoteTrack-spotlit";
/** The common prefix {@value} for all values of the {@linkplain #bodyRelClass()
* bodyRelClass}().
*/
public static final String BODY_REL_PREFIX = "voLiDi-rel-";
/** The common prefix {@value} for all values of the {@linkplain #bodyRelClass()
* bodyRelClass}().
*/
public static final String BODY_SEC_PREFIX = "voLiDi-";
/** The style symbol 'c' for the candidate cast relation.
*/
public static final char REL_CANDIDATE = XCastRelation.CANDIDATE.symbol();
/** The style symbol 'o' for the co-voter and base co-candidate cast relations.
*/
public static final char REL_CO = XCastRelation.CO_VOTER.symbol();
/** The style symbol 'y' for the base co-candidate cast relation when there is a tight
* cycle between the anchor and the other person.
*/
public static final char REL_TIGHT_CYCLE = 'y';
/** The style symbol 'u' for the unknown cast relation.
*/
public static final char REL_UNKNOWN = 'u';
/** The style symbol 'v' for the voter cast relation.
*/
public static final char REL_VOTER = XCastRelation.VOTER.symbol();
// - L i g h t a b l e - D i f f e r e n c e ------------------------------------------
/** The style variant for actor dependent links in the {@linkplain
* votorola.s.gwt.stage.link.LinkTrackV#getActorLinkVariant() link track}.
*/
public String actorLinkVariant();
/** The name of the ordinal style class to set on the document body when this
* lightable difference is lit.
*
* @see Normal order
*/
public String bodyOrdClass(); // used by TYPIFIER
/** The name of the {@linkplain XCastRelation cast-relational} style class to set on
* the document body when this lightable difference is lit.
*/
public String bodyRelClass();
/** The name of the {@linkplain votorola.a.count.CountNode#dartSector() dart-sectoral}
* style class to set on the document body when this lightable difference is lit, or
* null of there is none.
*/
public String bodySecClass();
/** The name of the {@linkplain votorola.s.gwt.stage.light.PositionSensor#personName()
* other author}, as opposed to the {@linkplain VoteTrack#anchor() anchoring author}.
*/
public String personName();
/** The name of the poll.
*/
public String pollName(); // used by TYPIFIER
/** The name of the {@linkplain XCastRelation cast-relational} style class to set on
* the #{@linkplain votorola.s.gwt.stage.StageV StageV-top} element, indicating the
* existence of this lightable difference.
*/
public String stageRelClass();
/** A typifier for LightableDifference.
*/
public static final Typifier TYPIFIER = new Typifier()
{
public boolean isInstance( final Object o )
{
return o instanceof JavaScriptObject?
JavaScriptObjectX._isDuckType((JavaScriptObject)o, "bodyOrdClass", "pollName"):
o instanceof LightableDifference;
}
};
// ====================================================================================
/** A routine that runs in the context of a lightable difference.
*/
public interface Runner
{
// - L i g h t a b l e - D i f f e r e n c e . R u n n e r ------------------------
/** Runs this routine in the context of the specified difference.
*/
public void run( final D diff );
}
}