[virtualcommons-svn] SF.net SVN: virtualcommons:[299] irrigation/trunk/src/main/java/edu/asu/ commo
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-10-16 23:03:08
|
Revision: 299 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=299&view=rev Author: alllee Date: 2009-10-16 23:02:53 +0000 (Fri, 16 Oct 2009) Log Message: ----------- Still cleaning up the initial stages of the experiment, namely the instructions and quiz pages. Next up is to properly deal with the actual experiment interface. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-10-15 00:12:05 UTC (rev 298) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-10-16 23:02:53 UTC (rev 299) @@ -1,6 +1,7 @@ package edu.asu.commons.irrigation.client; import java.awt.Color; +import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagLayout; @@ -18,100 +19,75 @@ * * FIXME: needs heavy refactoring. * - * @author Sanket + * @author Sanket Joshi + * @author Allen Lee * @version $Rev$ */ public class CanalAnimationPanel extends JPanel { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2049547253093489218L; - /** - * This is the default constructor - */ - private int x1UpStream; + //private IrrigationClientGameState clientGameState; - private int y1UpStream; + //////////////////animation logic parameters////////////////////////////// + private Timer timer; - private int x2UpStream = 420; + private final int DELAY = 20; - private int y2UpStream = 100; + private Ball balls[]; - private int y2DownStream = 100; + private int BALLCOUNT = 500; - private int x2DownStream = 950; + private Gate gate[] = new Gate[6]; - private int y1DownStream; + private int gateHeight = 20; - private int x1DownStream; + Random generator = new Random(); - private Graphics2D graphics2D; + private boolean enableBallAnimation = true; - private boolean flagDownStream = false; + private double totalContributedBandwidth; - private boolean flagUpStream = false; - - //private IrrigationClientGameState clientGameState; - - //////////////////animation logic parameters////////////////////////////// - private Timer timer; - - private final int DELAY = 20; + private long prev_time; - private Ball balls[]; - - private int BALLCOUNT = 500; - - private Gate gate[] = new Gate[6]; + private int gateCount = 0; - private int gateHeight = 20; - - Random generator = new Random(); + //////////////////////////////////////////////////////////////////////////// - private boolean enableBallAnimation = true; + public CanalAnimationPanel(double totalContributedBandwidth) { + super(); + this.totalContributedBandwidth = totalContributedBandwidth; + initialize(); + } - private double totalContributedBandwidth; + /** + * + * @return void + */ + private void initialize() { + this.setPreferredSize(new Dimension(1098,150)); + this.setLayout(new GridBagLayout()); + this.setBackground(Color.white); + //initializing the constructor for Gates + for(int i=0;i<6;i++){ + gate[i] = new Gate(totalContributedBandwidth,i); + //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); + } - private long prev_time; + initializexy(); - private int gateCount = 0; + timer = new Timer(DELAY, new ReboundListener()); // setup the Timer to do an action + // every DELAY times. + prev_time = System.currentTimeMillis(); + timer.start(); // starts the timer. + } - //////////////////////////////////////////////////////////////////////////// + private void gateReboundListener(){ - public CanalAnimationPanel(double totalContributedBandwidth) { - super(); - this.totalContributedBandwidth = totalContributedBandwidth; - initialize(); - } - - /** - * This method initializes this - * - * @return void - */ - private void initialize() { - this.setSize(1098,150); - this.setLayout(new GridBagLayout()); - this.setBackground(Color.white); - //initializing the constructor for Gates - for(int i=0;i<6;i++){ - gate[i] = new Gate(totalContributedBandwidth,i); - //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); - } - - initializexy(); - - timer = new Timer(DELAY, new ReboundListener()); // setup the Timer to do an action - // every DELAY times. - prev_time = System.currentTimeMillis(); - timer.start(); // starts the timer. - } - - private void gateReboundListener(){ - - openGates(gateCount ); - if(!(gateCount == 0)) - closeGates(gateCount-1); - /*if(!gate[0].isOpenGate() && flagDownStream == false){ + openGates(gateCount ); + if(!(gateCount == 0)) + closeGates(gateCount-1); + /*if(!gate[0].isOpenGate() && flagDownStream == false){ System.out.println("Opening gates"); closeGates(0); openGates(1); @@ -132,435 +108,396 @@ closeGates(0); //closeGates(1); } -*/} - - + */} - protected void paintComponent(Graphics graphics){ - updateGUI(); - super.paintComponent(graphics); // needed! - Graphics2D graphics2D = (Graphics2D)graphics; - this.graphics2D = graphics2D; - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(0,0,100,100); - //draw the other gates - for(int i=0;i<5;i++){ - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); - this.graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), - gate[i].getOpeningsHeight()); - this.graphics2D.setColor(Color.BLACK); - this.graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); - } - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); - //System.out.println("Gate :"+5+" X: "+gate[5].getX()+" Y :"+gate[5].getY()); - - //////////////////////Animation Logic//////////////////////////// - if(enableBallAnimation == true) - { - graphics.setColor(Color.white); - int ballCounter = 0; - for(int i=0;i<BALLCOUNT;i++){ - /*if(!(balls[i].isInServer == false && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() == 0)){ - if(!(flagDownStream == true && flagUpStream == true && balls[i].x >= 950)) - if(!(flagUpStream == true && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() <=25 && balls[i].x >=420)){ - if(flagUpStream == true && balls[i].x >=420 && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() >=25 ){ - if(!(flagDownStream == false && balls[i].y >= 80)) - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - } - else{ - - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); // paints a whole new circle, with changing coords - - } - - } - - } - */ - //System.out.println("ball sposition x :"+balls[i].x+" y:"+balls[i].y); - //get the position information of the ball. and then recheck the condition for height. - if((balls[i].getPosition() == 1)||(balls[i].getPosition() == 2) || (balls[i].getPosition()==3) - || (balls[i].getPosition() == 4) || (balls[i].getPosition() == 5)){ - if(!((!gate[balls[i].getPosition()-1].isOpenGate())&& balls[i].getY() >= (gate[balls[i].getPosition()-1].getY()+gate[balls[i].getPosition()-1].getHeight()))) - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - - - } - else{ - if(balls[i].getPosition() != 0){ - if(gate[balls[i].getPosition() - 6].getHeight() != 0) - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - } - else{ - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - } - } - } - } - - } - - - - private void updateGUI() { - // TODO Auto-generated method stub - for(int i=1;i<6;i++){ - if(gate[i-1].isOpenGate()){ - if(!(gate[i-1].getHeight() - gateHeight < 0)){ - gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); - } - else{ - gate[i].setHeight(0); - } - } - else{ - gate[i].setHeight(gate[i-1].getHeight()); - - } - //order matters here - if(!(i == 5)){ - gate[i].setOpeningsHeight((totalContributedBandwidth*0.8) - - gate[i].getHeight()); - gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); - - //opening the lid logic - if(gate[i].isOpenGate()){ - gate[i].setx1(gate[i].getx2()); - if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) - gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); - else - gate[i].sety1(gate[i].getOpeningsY()); - } - else{ - gate[i].setx1(gate[i].getdefaultx1()); - gate[i].sety1(gate[i].getdefaulty1()); - } - - if(gate[0].isOpenGate()){ - gate[0].setx1(gate[0].getx2()); - if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) - gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); - else - gate[0].sety1(gate[0].getY()); - } - else{ - gate[0].setx1(gate[0].getdefaultx1()); - gate[0].sety1(gate[0].getdefaulty1()); - } - - } - } - } + protected void paintComponent(Graphics graphics){ + updateGUI(); + super.paintComponent(graphics); // needed! + Graphics2D graphics2D = (Graphics2D)graphics; + graphics2D = graphics2D; + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(0,0,100,100); + //draw the other gates + for(int i=0;i<5;i++){ + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); + graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), + gate[i].getOpeningsHeight()); + graphics2D.setColor(Color.BLACK); + graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); + } - /* - * initialize the Balls - */ - private void initializexy() { - // TODO Auto-generated method stub - balls = new Ball[BALLCOUNT]; - if(balls == null){ - System.out.println("Ball is null"); - } - - for(int i=0;i<BALLCOUNT;i++){ - balls[i] = new Ball(generator); - - } - } + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); - // this is the private class the Timer will look at every DELAY seconds - private class ReboundListener implements ActionListener{ - Random generator = new Random(); - public void actionPerformed(ActionEvent e) { - if((System.currentTimeMillis() - prev_time) > 5000){ - //System.out.println("Change the time"); - prev_time = System.currentTimeMillis(); - gateCount++; - if(gateCount > 4) - gateCount = 0; - gateReboundListener(); - } - for(int i=0;i<BALLCOUNT;i++){ - //updateGUI(); - balls[i].x += balls[i].moveX; - balls[i].y += balls[i].moveY; - process(i); - - } - repaint(); - } - } + //////////////////////Animation Logic//////////////////////////// + // FIXME: good lord, refactor this. + if (enableBallAnimation) { + graphics.setColor(Color.white); + for(int i=0;i<BALLCOUNT;i++){ + //get the position information of the ball. and then recheck the condition for height. + if((balls[i].getPosition() == 1)||(balls[i].getPosition() == 2) || (balls[i].getPosition()==3) + || (balls[i].getPosition() == 4) || (balls[i].getPosition() == 5)){ + if(!((!gate[balls[i].getPosition()-1].isOpenGate())&& balls[i].getY() >= (gate[balls[i].getPosition()-1].getY()+gate[balls[i].getPosition()-1].getHeight()))) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + else { + if(balls[i].getPosition() != 0){ + if(gate[balls[i].getPosition() - 6].getHeight() != 0) { + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + } + else { + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + } + } + } - /* - * This will process the balls according to their position - */ - private void process(int i){ - // TODO Auto-generated method stub - - switch(balls[i].getPosition()){ - - case 0: if((balls[i].x >= (100 - 20) && balls[i].x <= 100) && (balls[i].y >= 100-(int)(totalContributedBandwidth*0.8) && + } + + + + private void updateGUI() { + for(int i=1;i<6;i++){ + if(gate[i-1].isOpenGate()){ + if(!(gate[i-1].getHeight() - gateHeight < 0)){ + gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); + + } + else{ + gate[i].setHeight(0); + } + } + else{ + gate[i].setHeight(gate[i-1].getHeight()); + + } + //order matters here + if(!(i == 5)){ + gate[i].setOpeningsHeight((totalContributedBandwidth*0.8) + - gate[i].getHeight()); + gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); + + //opening the lid logic + if(gate[i].isOpenGate()){ + gate[i].setx1(gate[i].getx2()); + if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) + gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); + else + gate[i].sety1(gate[i].getOpeningsY()); + } + else{ + gate[i].setx1(gate[i].getdefaultx1()); + gate[i].sety1(gate[i].getdefaulty1()); + } + + if(gate[0].isOpenGate()){ + gate[0].setx1(gate[0].getx2()); + if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) + gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); + else + gate[0].sety1(gate[0].getY()); + } + else{ + gate[0].setx1(gate[0].getdefaultx1()); + gate[0].sety1(gate[0].getdefaulty1()); + } + + } + } + } + + /* + * initialize the Balls + */ + private void initializexy() { + balls = new Ball[BALLCOUNT]; + if(balls == null){ + System.out.println("Ball is null"); + } + + for(int i=0;i<BALLCOUNT;i++){ + balls[i] = new Ball(generator); + + } + } + + // this is the private class the Timer will look at every DELAY seconds + private class ReboundListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + if((System.currentTimeMillis() - prev_time) > 5000){ + //System.out.println("Change the time"); + prev_time = System.currentTimeMillis(); + gateCount++; + if(gateCount > 4) + gateCount = 0; + gateReboundListener(); + } + for(int i=0;i<BALLCOUNT;i++){ + //updateGUI(); + balls[i].x += balls[i].moveX; + balls[i].y += balls[i].moveY; + process(i); + + } + repaint(); + } + } + + /* + * This will process the balls according to their position + */ + private void process(int i){ + switch(balls[i].getPosition()) { + + case 0: + if((balls[i].x >= (100 - 20) && balls[i].x <= 100) + && (balls[i].y >= 100-(int)(totalContributedBandwidth*0.8) + && balls[i].y <= 100)) + { + balls[i].setPosition(1); + setBounds(i); + } + //still in server + else { + setBounds(i); + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + balls[i].moveX = balls[i].moveX * -1; + } + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveY = balls[i].moveY * -1; + } + break; + + case 1: /*if(gate[0].isOpenGate() && (balls[i].x >= 400 && balls[i].x <= 420) && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(1); - setBounds(i); - } - //still in server - else{ - setBounds(i); - if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ - balls[i].moveX = balls[i].moveX * -1; - } - if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) - balls[i].moveY = balls[i].moveY * -1; - } - break; - - case 1: /*if(gate[0].isOpenGate() && (balls[i].x >= 400 && balls[i].x <= 420) && (balls[i].y >= 80 && - balls[i].y <= 100)){ - */ if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(7); - //directly pass in the information - setBounds(i); - /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + */ if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(7); + //directly pass in the information + setBounds(i); + /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER);*/ - /* balls[i].xBOUNDSUPPER = 420; + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + } + else{ + setBounds(i); + /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); - */ - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(2); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - - break; - - case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(8); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + */ + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(2); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + + break; + + case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(8); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(3); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - - case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(9); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(3); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + + case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(9); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(4); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(10); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(4); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(10); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(5); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(11); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(5); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(11); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(6); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - case 6: setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - /*balls[i].setX(generator.nextInt(100)); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(6); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 6: setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + /*balls[i].setX(generator.nextInt(100)); balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); balls[i].setPosition(0); setBounds(i);*/ - setBallinServer(i); - } - - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - break; - } - - if((balls[i].getPosition() == 11) || (balls[i].getPosition() == 7) || (balls[i].getPosition() == 8) - || (balls[i].getPosition() == 9) || (balls[i].getPosition() == 10)){ - if(balls[i].getY() >= 150){ - /*balls[i].setX(generator.nextInt(100)); + setBallInTank(i); + } + + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + break; + } + + if((balls[i].getPosition() == 11) || (balls[i].getPosition() == 7) || (balls[i].getPosition() == 8) + || (balls[i].getPosition() == 9) || (balls[i].getPosition() == 10)){ + if(balls[i].getY() >= 150){ + /*balls[i].setX(generator.nextInt(100)); balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); //balls[i].setY(generator.nextInt(100)); balls[i].setPosition(0); setBounds(i); - */ - setBallinServer(i); - } - else{ - setBounds(i); - //System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER - //+" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); - } - } - } + */ + setBallInTank(i); + } + else{ + setBounds(i); + //System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + //+" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); + } + } + } - private void setBallinServer(int i) { - // TODO Auto-generated method stub - generator.setSeed(i*(i+1)); - balls[i].setX(generator.nextInt(100)); - balls[i].setY(generator.nextInt(100)); - - //balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); - balls[i].setPosition(0); - if(balls[i].moveX == 0) - balls[i].moveX = generator.nextInt(15); - setBounds(i); - } + private void setBallInTank(int i) { + // FIXME: is this supposed to be a random seed? + generator.setSeed(i*(i+1)); + balls[i].setX(generator.nextInt(100)); + balls[i].setY(generator.nextInt(100)); - private void setBounds(int ballIndex) { - // TODO Auto-generated method stub - //ball is in the server - if(balls[ballIndex].getPosition() == 0){ - balls[ballIndex].xBOUNDSUPPER = 100; - balls[ballIndex].xBOUNDSLOWER = 0; - balls[ballIndex].yBOUNDSUPPER = 100; - balls[ballIndex].yBOUNDSLOWER = 0; - //balls[ballIndex].moveX = generator.nextInt(6); - //balls[ballIndex].moveY = generator.nextInt(6); - //balls[ballIndex].moveX = 3; - //balls[ballIndex].moveY = 3; - } - else{ - if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) - || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ - - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getY(); - //balls[ballIndex].moveX = 3; - //balls[ballIndex].moveY = 3; - - } - //the ball is in one of the openings - else{ - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); - balls[ballIndex].moveX = 0; - balls[ballIndex].moveY = 3; - } - } - } + //balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); + balls[i].setPosition(0); + if(balls[i].moveX == 0) { + balls[i].moveX = generator.nextInt(15); + } + setBounds(i); + } - public void openGates(int priority) { - // TODO Auto-generated method stub - - gate[priority].setGateOpen(true); - - //set the height of all the canal panls depending on the state of the game - paintComponent(graphics2D); - } + private void setBounds(int ballIndex) { + // ball is in the server + if(balls[ballIndex].getPosition() == 0){ + balls[ballIndex].xBOUNDSUPPER = 100; + balls[ballIndex].xBOUNDSLOWER = 0; + balls[ballIndex].yBOUNDSUPPER = 100; + balls[ballIndex].yBOUNDSLOWER = 0; + //balls[ballIndex].moveX = generator.nextInt(6); + //balls[ballIndex].moveY = generator.nextInt(6); + //balls[ballIndex].moveX = 3; + //balls[ballIndex].moveY = 3; + } + else{ + if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) + || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ - public void closeGates(int priority) { - // TODO Auto-generated method stub - gate[priority].setGateOpen(false); - gate[priority].setx1(gate[priority].getdefaultx1()); - gate[priority].sety1(gate[priority].getdefaulty1()); - /*if(!(priority == 0)) - gate[priority].setHeight(gate[priority-1].getHeight());*/ - paintComponent(graphics2D); - } + balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); + balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); + balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; + balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getY(); + //balls[ballIndex].moveX = 3; + //balls[ballIndex].moveY = 3; - public void endRound() { - // TODO Auto-generated method stub - flagDownStream = false; - flagDownStream = false; + } + //the ball is in one of the openings + else{ + balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); + balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); + balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); + balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); + balls[ballIndex].moveX = 0; + balls[ballIndex].moveY = 3; + } + } + } - x2UpStream = 420; + public void openGates(int priority) { + gate[priority].setGateOpen(true); + // set the height of all the canal panels depending on the state of the game + repaint(); + } - y2UpStream = 100; + public void closeGates(int priority) { + gate[priority].setGateOpen(false); + gate[priority].setx1(gate[priority].getdefaultx1()); + gate[priority].sety1(gate[priority].getdefaulty1()); + /*if(!(priority == 0)) + gate[priority].setHeight(gate[priority-1].getHeight());*/ + repaint(); + } - y2DownStream = 100; - - x2DownStream = 950; - - initializexy(); - } + public void endRound() { + initializexy(); + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-15 00:12:05 UTC (rev 298) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-16 23:02:53 UTC (rev 299) @@ -1,45 +1,3 @@ - -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation; - * either version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this - * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ----------------- - * XYSeriesDemo.java - * ----------------- - * (C) Copyright 2002-2004, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * $Id$ - * - * Changes - * ------- - * 08-Apr-2002 : Version 1 (DG); - * 11-Jun-2002 : Inserted value out of order to see that it works (DG); - * 11-Oct-2002 : Fixed issues reported by Checkstyle (DG); - * - */ - package edu.asu.commons.irrigation.client; import java.awt.CardLayout; @@ -57,140 +15,117 @@ import edu.asu.commons.irrigation.server.GroupDataModel; - /** - * A simple demo showing a dataset created using the {@link XYSeriesCollection} class. + * $Id$ + * * + * @author Sanket Joshi + * @version $Rev$ */ -//public class XYSeriesDemo extends ApplicationFrame { +public class ChartWindowPanelTokenBandwidth extends JPanel { - public class ChartWindowPanelTokenBandwidth extends JPanel { + private static final long serialVersionUID = 5555080117985336199L; - /** - * - */ - private static final long serialVersionUID = 5555080117985336199L; + private int numberofFilesDownloaded = 10; - private int numberofFilesDownloaded = 10; + private Dimension screenSize; - private Dimension screenSize; + private JPanel jPanel; - private JPanel jPanel; - - private IrrigationClient client; + private IrrigationClient client; - + /** * A demonstration application showing an XY series containing a null value. * * @param title the frame title. */ public ChartWindowPanelTokenBandwidth(IrrigationClient client) { - - //super(title); - this.client = client; - initialize(); + this.client = client; + initialize(); } - public void initialize() { - // TODO Auto-generated method stub - this.setLayout(new CardLayout()); - this.setSize(new Dimension(530/2, 326/2)); - //this.setSize(screenSize.width, screenSize.height); - this.add(getJPanel(), getJPanel().getName()); - repaint(); + public void initialize() { + this.setLayout(new CardLayout()); + this.setSize(new Dimension(530/2, 326/2)); + //this.setSize(screenSize.width, screenSize.height); + this.add(getJPanel(), getJPanel().getName()); + repaint(); - } + } - /** - * This method initializes jPanel - * - * @return javax.swing.JPanel - */ - private JPanel getJPanel() { - if (jPanel == null) { - jPanel = new JPanel(); - GridLayout gridLayout = new GridLayout(); - gridLayout.setColumns(2); - jPanel.setLayout(gridLayout); - jPanel.add(getChartPanel()); - //jPanel.add(getchartPanel1()); - jPanel.setName("jPanel"); - } - return jPanel; - } + /** + * This method initializes jPanel + * + * @return javax.swing.JPanel + */ + private JPanel getJPanel() { + if (jPanel == null) { + jPanel = new JPanel(); + GridLayout gridLayout = new GridLayout(); + gridLayout.setColumns(2); + jPanel.setLayout(gridLayout); + jPanel.add(getChartPanel()); + //jPanel.add(getchartPanel1()); + jPanel.setName("jPanel"); + } + return jPanel; + } - private ChartPanel getChartPanel() { - // TODO Auto-generated method stub - final XYSeries actualFlowCapacitySeries = new XYSeries("Actual"); - final XYSeries potentialFlowCapacitySeries = new XYSeries("Potential"); -// final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); - final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); - int x,y; - GroupDataModel group = client.getClientDataModel().getGroupDataModel(); - final int infrastructureEfficiency = group.getInfrastructureEfficiency(); - final int actualFlowCapacity = group.getFlowCapacity(); - for(y = 0; y <= actualFlowCapacity; y++) { - actualFlowCapacitySeries.add(infrastructureEfficiency, y); - } - for(x =0; x<=client.getRoundConfiguration().getMaximumInfrastructureEfficiency();x++){ - y = group.calculateFlowCapacity(x); - potentialFlowCapacitySeries.add(x,y); - } - final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); - final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); - for (y = 0; y <= initialFlowCapacity; y++) { - initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); - } + private ChartPanel getChartPanel() { + // TODO Auto-generated method stub + final XYSeries actualFlowCapacitySeries = new XYSeries("Actual"); + final XYSeries potentialFlowCapacitySeries = new XYSeries("Potential"); + // final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); + final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); + int x,y; + GroupDataModel group = client.getClientDataModel().getGroupDataModel(); + final int infrastructureEfficiency = group.getInfrastructureEfficiency(); + final int actualFlowCapacity = group.getFlowCapacity(); + for(y = 0; y <= actualFlowCapacity; y++) { + actualFlowCapacitySeries.add(infrastructureEfficiency, y); + } + for(x =0; x<=client.getRoundConfiguration().getMaximumInfrastructureEfficiency();x++){ + y = group.calculateFlowCapacity(x); + potentialFlowCapacitySeries.add(x,y); + } + final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); + final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); + for (y = 0; y <= initialFlowCapacity; y++) { + initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); + } -// for(y = 0; y <= actualFlowCapacity; y++) { -// actualFlowCapacitySeriesY.add(infrastructureEfficiency,y); -// } - repaint(); + // for(y = 0; y <= actualFlowCapacity; y++) { + // actualFlowCapacitySeriesY.add(infrastructureEfficiency,y); + // } - final XYSeriesCollection data = new XYSeriesCollection(); - data.addSeries(initialInfrastructureEfficiencySeries); - data.addSeries(actualFlowCapacitySeries); - data.addSeries(potentialFlowCapacitySeries); + final XYSeriesCollection data = new XYSeriesCollection(); + data.addSeries(initialInfrastructureEfficiencySeries); + data.addSeries(actualFlowCapacitySeries); + data.addSeries(potentialFlowCapacitySeries); -// data.addSeries(actualFlowCapacitySeriesY); + // data.addSeries(actualFlowCapacitySeriesY); - final JFreeChart chart = ChartFactory.createXYLineChart( - "Total Flow Capacity", - "Infrastructure Efficiency", - "Actual Flow Capacity", - data, - PlotOrientation.VERTICAL, - true, - true, - false - ); - final ChartPanel chartPanel = new ChartPanel(chart); - //chartPanel.chartProgress(arg0) - chartPanel.setLayout(new CardLayout()); - chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); - //setContentPane(chartPanel); - return chartPanel; - //y=4*x; - } - // **************************************************************************** - // * JFREECHART DEVELOPER GUIDE * - // * The JFreeChart Developer Guide, written by David Gilbert, is available * - // * to purchase from Object Refinery Limited: * - // * * - // * http://www.object-refinery.com/jfreechart/guide.html * - // * * - // * Sales are used to provide funding for the JFreeChart project - please * - // * support us so that we can continue developing free software. * - // **************************************************************************** - - /** - * Starting point for the demonstration application. - * - * @param args ignored. - */ - - } \ No newline at end of file + final JFreeChart chart = ChartFactory.createXYLineChart( + "Total Flow Capacity", + "Infrastructure Efficiency", + "Actual Flow Capacity", + data, + PlotOrientation.VERTICAL, + true, + true, + false + ); + final ChartPanel chartPanel = new ChartPanel(chart); + //chartPanel.chartProgress(arg0) + chartPanel.setLayout(new CardLayout()); + chartPanel.setPreferredSize(new Dimension(500, 270)); + repaint(); + //setContentPane(chartPanel); + return chartPanel; + //y=4*x; + } +} \ No newline at end of file Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-15 00:12:05 UTC (rev 298) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-16 23:02:53 UTC (rev 299) @@ -9,10 +9,11 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.lang.reflect.InvocationTargetException; import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -58,7 +59,7 @@ private JPanel graphPanel; - private JTextField tokenEntryTextField; + private JTextField investedTokensTextField; private JButton submitTokensButton; @@ -72,7 +73,7 @@ private int totalContributedTokensPerGroup; - private JTextArea contributionStatusInformationjTextArea; + private JTextArea contributionInformationTextArea; private JButton nextButton; @@ -92,7 +93,7 @@ private int NUMBER_INSTRUCTIONS = 9; - private JLabel quizLabel; + private JLabel quizMessageLabel; private JLabel quizAnimationLabel = new JLabel(); @@ -112,26 +113,22 @@ private JScrollPane animationInstructionsScrollPane; - private JPanel chartPanel; + private JPanel pieChartPanel; private PieChart pieChart; - public ClientData clientData; - private CanalAnimationPanel canalAnimationPanel; private CardLayout cardLayout; private JLabel infrastructureEfficiencyLabel = new JLabel("Current infrastructure efficiency: "); - public ExperimentGameWindow(Dimension screenSize, IrrigationClient client) { + public ExperimentGameWindow(IrrigationClient client) { this.client = client; this.clientDataModel = client.getClientDataModel(); - // FIXME: set the actual screen size dimensions after this JPanel has - // been initialized... - // this.screenSize = getParent().getSize(); - // feed subject view the available screen size so that - // it can adjust appropriately when given a board size + } + + void initialize(Dimension screenSize) { initGuiComponents(screenSize); } @@ -150,7 +147,7 @@ addToCardLayout(getInstructionsPanel()); irrigationGamePanel = new IrrigationGamePanel(screenSize, client); addToCardLayout(irrigationGamePanel); - // add any other panels that need to be switched out. + // add any other panels that need to be switched to.. // FIXME: see if we can simplify the number of instructions panes that Sanket has created. // addToCardLayout(getInstructionsEditorPane()); } @@ -202,7 +199,7 @@ if (submitTokenPanel == null) { submitTokenPanel = new JPanel(); submitTokenPanel.setLayout(new BorderLayout()); - submitTokenPanel.add(getTokenEntryTextField(), BorderLayout.CENTER); + submitTokenPanel.add(getInvestedTokensTextField(), BorderLayout.CENTER); submitTokenPanel.add(getSubmitTokensButton(), BorderLayout.EAST); return submitTokenPanel; } @@ -218,52 +215,78 @@ instructionsPanel.add(getInstructionsNavigationPanel(), BorderLayout.PAGE_END); } return instructionsPanel; - } - + private JPanel getInstructionsNavigationPanel() { if (instructionsNavigationPanel == null) { instructionsNavigationPanel = new JPanel(); instructionsNavigationPanel.setLayout(new BorderLayout()); instructionsNavigationPanel.add(getPreviousButton(), BorderLayout.LINE_START); instructionsNavigationPanel.add(getNextButton(), BorderLayout.LINE_END); - // this is just to add spacing I think. - quizLabel = new JLabel(); - instructionsNavigationPanel.add(quizLabel, BorderLayout.CENTER); + // displays quiz messages (correct/incorrect answer). + quizMessageLabel = new JLabel(); + instructionsNavigationPanel.add(quizMessageLabel, BorderLayout.CENTER); } return instructionsNavigationPanel; } + private JButton getPreviousButton() { + if (previousButton == null) { + previousButton = new JButton(); + previousButton.setText("Previous"); + previousButton.setEnabled(false); + previousButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + quizMessageLabel.setText(""); + // getting the next instruction Number + if (instructionNumber > 1) { + instructionNumber--; + } + previousButton.setEnabled(instructionNumber > 1); + nextButton.setEnabled(true); + System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); + setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); + // FIXME: get rid of hardcoded animation on page 5. Should instead + // just be an animated gif or something like that. + // should be more like "if instructions.hasAnimation()" + if(instructionNumber == 5) { + getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); + } + else { + getInstructionsPanel().remove(getCanalAnimationPanel()); + } + validate(); + } + }); + } + return previousButton; + } + private JButton getNextButton() { if (nextButton == null) { nextButton = new JButton(); nextButton.setText("Next"); nextButton.setEnabled(false); - nextButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); - + nextButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + quizMessageLabel.setText(""); previousButton.setEnabled(true); - if(instructionNumber >= pagesTraversed){ + if (instructionNumber >= pagesTraversed){ nextButton.setEnabled(false); } // getting the next instruction Number - if (instructionNumber == NUMBER_INSTRUCTIONS) { - - } - else + if (instructionNumber < NUMBER_INSTRUCTIONS) { instructionNumber++; - System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); + } setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - if(instructionNumber == 5){ - quizAnimationLabel.setText(""); - addCenterComponent(getAnimationInstructionPane()); - //addCenterComponent(getTokenScreenPanel()); + if(instructionNumber == 5) { + getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); } else { - addCenterComponent(getInstructionsPanel()); + getInstructionsPanel().remove(getCanalAnimationPanel()); } + validate(); } }); @@ -272,14 +295,14 @@ return nextButton; } - private JPanel getAnimationInstructionPane() { + private JPanel getAnimationInstructionPanel() { if (animationInstructionPanel == null) { animationInstructionPanel = new JPanel(); animationInstructionPanel.setName("Animated instruction panel"); animationInstructionPanel.setLayout(new BorderLayout()); - animationInstructionPanel.add(getAnimationPane(), BorderLayout.CENTER); + animationInstructionPanel.add(getAnimationPanel(), BorderLayout.CENTER); - animationInstructionPanel.add(getNavigationAnimationPanel(), BorderLayout.SOUTH); + animationInstructionPanel.add(getNavigationAnimationPanel(), BorderLayout.PAGE_END); animationInstructionPanel.setBackground(Color.WHITE); return animationInstructionPanel; } @@ -291,8 +314,8 @@ private JPanel getNavigationAnimationPanel() { if (navigationAnimationPanel == null) { - navigationAnimationPanel = new JPanel(); + navigationAnimationPanel.setName("Navigation animation panel"); navigationAnimationPanel.setLayout(new BorderLayout()); navigationAnimationPanel.add(getNextAnimationButton(), BorderLayout.EAST); navigationAnimationPanel.add(getPreviousAnimationButton(), BorderLayout.WEST); @@ -310,7 +333,7 @@ previousAnimationButton.setEnabled(true); previousAnimationButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); + quizMessageLabel.setText(""); // getting the next instruction Number nextButton.setEnabled(true); if (instructionNumber > 1) { @@ -332,7 +355,7 @@ nextAnimationButton.setEnabled(false); nextAnimationButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - quizLabel.setText(""); + quizMessageLabel.setText(""); previousButton.setEnabled(true); if(instructionNumber >= pagesTraversed) nextButton.setEnabled(false); @@ -342,26 +365,36 @@ } System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - if(instructionNumber == 5){ - addCenterComponent(getAnimationInstructionPane()); + // FIXME: horrifyingly hard coded + if(instructionNumber == 5) { //addCenterComponent(getTokenScreenPanel()); + getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); } else { - addCenterComponent(getInstructionsPanel()); + getInstructionsPanel().remove(getCanalAnimationPanel()); +// addCenterComponent(getInstructionsPanel()); } + validate(); } }); } return nextAnimationButton; } + + private JPanel getCanalAnimationPanel() { + if (canalAnimationPanel == null) { + canalAnimationPanel = new CanalAnimationPanel(40); + } + return canalAnimationPanel; + } - private JPanel getAnimationPane() { + private JPanel getAnimationPanel() { if (animationPanel == null) { animationPanel = new JPanel(); + animationPanel.setName("Animation panel"); animationPanel.setLayout(new BorderLayout()); //FIXME: Here the animation panel needs to be decided on fly - //canalPanelAnimation = new CanalPanelAnimation(40); canalAnimationPanel = new CanalAnimationPanel(40); animationPanel.add(canalAnimationPanel,BorderLayout.CENTER); animationInstructionsEditorPane = createInstructionsEditorPane(); @@ -375,42 +408,10 @@ animationInstructionsEditorPane.setCaretPosition(0); animationInstructionsEditorPane.repaint(); animationPanel.setBackground(Color.WHITE); - return animationPanel; } - return animationPanel; } - private JButton getPreviousButton() { - if (previousButton == null) { - previousButton = new JButton(); - previousButton.setText("Previous"); - previousButton.setEnabled(false); - previousButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); - // getting the next instruction Number - nextButton.setEnabled(true); - if (instructionNumber !=... [truncated message content] |