001package 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. 002 003import com.google.gwt.dom.client.*; 004import com.google.gwt.user.client.ui.Widget; 005import votorola.a.count.*; 006import votorola.g.hold.*; 007import votorola.g.web.gwt.*; 008import votorola.g.web.gwt.event.*; 009 010 011/** A major component of a {@linkplain VoteTrackV track view}. 012 */ 013public abstract class MajorV extends Widget 014{ 015 016 017 /** Creates a new MajorV. 018 * 019 * @see #place() 020 * @see #trackV() 021 */ 022 MajorV( XCastRelation _place, VoteTrackV _trackV ) 023 { 024 place = _place; 025 trackV = _trackV; 026 } 027 028 029 030 // ------------------------------------------------------------------------------------ 031 032 033 /** The relative location of this view within its {@linkplain VoteTrackV parent}; one 034 * of {@linkplain XCastRelation#VOTER VOTER} (left) {@linkplain 035 * XCastRelation#CO_VOTER CO_VOTER} (center) or {@linkplain XCastRelation#CANDIDATE 036 * CANDIDATE} (right). Co-voters are understood to include {@linkplain 037 * votorola.a.count.XCastRelation#CO_BASE base co-candidates}, and are collectively 038 * referred to as "cast peers". 039 */ 040 public final XCastRelation place() { return place; } 041 042 043 private final XCastRelation place; 044 045 046 047 /** The spool for the release of associated holds. When unwound it releases the holds 048 * of this view, thereby disabling it. 049 */ 050 final Spool spool() { return spool; } 051 052 053 private final Spool spool = new Spool1(); 054 055 056 057 /** The overall view of which this view is a component. 058 */ 059 final VoteTrackV trackV() 060 { 061 // return (VoteTrackV)getParent().getParent(); /* ignore sporadic [cast] redundancy 062 // warning. Left out it fails anyway (1.7 compiler bug?) */ 063 //// too fragile during init, when parent may be unknown (failed on upgrade to GWT 2.5) 064 return trackV; 065 } 066 067 068 private final VoteTrackV trackV; 069 070 071 072 // - W i d g e t ---------------------------------------------------------------------- 073 074 075 protected @Override final void onUnload() 076 { 077 super.onUnload(); 078 spool.unwind(); 079 } 080 081 082 083 public @Override final void removeFromParent() 084 { 085 if( super.getParent() != null ) throw new UnsupportedOperationException(); 086 } 087 088 089 090 // - U I - O b j e c t --------------------------------------------------------------- 091 092 093 /** Answers whether this view is nominally visible. Returns false if the visibility 094 * style is "hidden", true otherwise. The value is bound via the {@linkplain 095 * GWTX#bus() event bus} to property name <tt>visible</tt>. 096 * 097 * @see #setVisible(boolean) 098 */ 099 public @Override final boolean isVisible() 100 { 101 return !"hidden".equals( getElement().getStyle().getVisibility() ); 102 } 103 104 105 106 public @Override final void setVisible( final boolean toBe ) 107 { 108 if( toBe == isVisible() ) return; 109 110 if( toBe ) getElement().getStyle().clearVisibility(); 111 else getElement().getStyle().setVisibility( Style.Visibility.HIDDEN ); 112 // as opposed to display='none', so it still affects spacing of layout 113 GWTX.i().bus().fireEventFromSource( new PropertyChange("visible"), MajorV.this ); 114 } 115 116 117}