@author <A HREF="mailto:burton@apache.org">Kevin A. Burton</A>
@version $Id: PollPortlet.java,v 1.3 2001/03/07 07:12:35 taylor Exp $
*/
private ConcreteElement getResults( RunData rundata ) {
ElementContainer ec = new ElementContainer();
AnswerGroup ag = this.getAnswerGroup();
Answer[] answers = ag.getAnswers();
int top = ag.getTopAnswer().getVoteCount();
ConcreteElement nbsp = new ClearElement( " " );
//make sure the user hasn't voted before.
if ( this.hasVoted( rundata ) ) {
ec.addElement( new I().addElement( "You have already voted!" ) );
ec.addElement( new BR() );
}
//add the question to the Portlet so that he user knows what they just
//voted on.
ec.addElement( new B().addElement( this.getQuestion().getTitle() ) );
Table table = new Table();
for( int i = 0; i < answers.length; ++i ) {
Answer answer = answers[i];
//compute the width of this vote item.
int width = 0;
TR row = new TR();
row.addElement( getColumn( answer.getTitle() ) );
if ( answer.getVoteCount() == 0 ) {
width = 1;
} else {
width = ( DEFAULT_IMG_WIDTH / top ) * answer.getVoteCount();
}
TD result = getColumn( new IMG().setSrc( IMG_MAINBAR )
.setWidth( width )
.setHeight( DEFAULT_IMG_HEIGHT ) );
//get the current vote count and percentage
result.addElement( nbsp );
result.addElement( Integer.toString( answer.getVoteCount() ) +
" / " +
Integer.toString( ag.getPercentage( answer ) ) +
"%" );
row.addElement( result );
row.addElement( new TD().setWidth( "100%" ) );
table.addElement( row );
}
ec.addElement( table );
//now add the total number of votes.
ec.addElement( new BR() );
ec.addElement( new B()
.addElement( Integer.toString( this.getAnswerGroup().getTotal() ) +
" total vote(s)" ) );
//add the warning
ec.addElement( new BR() );
ec.addElement( WARNING );
return ec;
}