001package votorola.s.gwt.wic; // Copyright 2012-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.
002
003import com.google.gwt.dom.client.*;
004import org.vectomatic.dom.svg.*;
005import org.vectomatic.dom.svg.utils.OMSVGParser;
006import votorola.a.web.gwt.*;
007import votorola.s.gwt.stage.*;
008import votorola.s.gwt.stage.link.*;
009import votorola.s.gwt.stage.vote.*;
010
011import static votorola.s.gwt.stage.vote.LightableDifference.REL_CANDIDATE;
012import static votorola.s.gwt.stage.vote.LightableDifference.REL_CO;
013import static votorola.s.gwt.stage.vote.LightableDifference.REL_TIGHT_CYCLE;
014import static votorola.s.gwt.stage.vote.LightableDifference.REL_UNKNOWN;
015import static votorola.s.gwt.stage.vote.LightableDifference.REL_VOTER;
016
017
018/** The GWT entry module for embedding the Crossforum Theatre {@linkplain
019  * votorola.s.gwt.stage.Stage stage} in the Wicket {@linkplain votorola.s.wic.diff.WP_D
020  * difference bridge}.  An instance of this class is automatically constructed and
021  * invoked per module definition <a
022  * href='../../../../../../s/gwt/wic/DIn.gwt.xml'>DIn.gwt.xml</a>.  It overlays the
023  * bridge scene with an {@linkplain AnchorLine anchor line} that ties the selected
024  * drafter's link (sLink) at the top left of the bridge to the pin indicator in the vote
025  * track, plus an {@linkplain AlterTie alter tie} that ties the other drafter's link
026  * (tLink) to his/her corresponding node in the track.<pre>
027  *
028  *                                                               --
029  *    >>>>>>>>>>>>>>>>>>>>> --- >>>>>>>>>>>>>>>>>>>> --- >>>>>    | vote track
030  *            -----                           /\                 --
031  *              | alter tie                   /                   |
032  *    tLink - - +                            /                    | bridge scene
033  *    sLink - - - - - - - - - - - - - - - - +  anchor line        |
034  *                                                                |</pre>
035  *
036  * <p>Acknowledgement: Thomas von der Elbe assisted in troubleshooting the visualization
037  * problems that led to the design of these ties.  See the thread <a
038  * href='http://mail.zelea.com/list/votorola/2012-September/thread.html'
039  * target='_top'>Difference lighting and cross-linking on the bridge</a>.</p>
040  */
041public final class DIn implements EntryPointS
042{
043
044
045   // - E n t r y - P o i n t ------------------------------------------------------------
046
047
048    public final void onModuleLoad()
049    {
050        StageIn.insertStageV();
051        EntryPointS.U.schedule( DIn.this );
052        EntryPointS.U.execute(); // because all modules are now loaded
053        Stage.i().addInitializer( new TheatreInitializerC() // auto-removed
054        {
055            public void initComplete( Stage _s, boolean _rPending )
056            {
057              // HTML view.
058              // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
059                final Document htmlDoc = Document.get();
060                final Element div = htmlDoc.createDivElement(); // for HTML styling, per WP_D.css
061                div.addClassName( "BridgeOverlay" );
062                htmlDoc.getBody().appendChild( div );
063
064              // SVG view.
065              // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
066                final OMSVGSVGElement svg = OMSVGParser.createDocument().createSVGSVGElement();
067                div.appendChild( svg.getElement() );
068                final VoteTrackV trackV = VoteTrackV.i( StageV.i() );
069                if( trackV == null ) throw new IllegalStateException();
070
071                final char rel = DifferenceLight.sceneRel();
072                final NodeV.Box nodeBox;
073                if( rel == REL_VOTER ) nodeBox = trackV.votersBoardV();
074                else if( rel == REL_CO ) nodeBox = trackV.peersBoardV();
075                else if( rel == REL_CANDIDATE || rel == REL_TIGHT_CYCLE )
076                {
077                    nodeBox = trackV.candidateV();
078                    // In tight cycle, candidate is also voter and will also appear in
079                    // votersBoardV.  We might draw 2nd under-bracket there to show the
080                    // cycle.  But that would be difficult.  And no need; lighting effects
081                    // already show the cycle well enough.
082                }
083                else if( rel == REL_UNKNOWN ) nodeBox = null;
084                else throw new IllegalStateException( "rel = " + rel );
085
086                svg.appendChild( new AnchorLine( trackV ));
087                if( nodeBox != null ) svg.appendChild( new AlterTie( nodeBox, trackV.track() ));
088            }
089        });
090    }
091
092
093
094   // - S c h e d u l e r . S c h e d u l e d - C o m m a n d ----------------------------
095
096
097    public void execute() { StageV.i().initEmbeddedDisplay(); }
098
099
100}