[virtualcommons-svn] SF.net SVN: virtualcommons:[311] irrigation/trunk
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-10-21 00:29:27
|
Revision: 311 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=311&view=rev Author: alllee Date: 2009-10-21 00:29:19 +0000 (Wed, 21 Oct 2009) Log Message: ----------- fixed canalpanel flickering, adding jfreechart and jcommon dependencies to client.jnlp Modified Paths: -------------- irrigation/trunk/pom.xml irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.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/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java irrigation/trunk/src/main/resources/web/client.jnlp Modified: irrigation/trunk/pom.xml =================================================================== --- irrigation/trunk/pom.xml 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/pom.xml 2009-10-21 00:29:19 UTC (rev 311) @@ -56,6 +56,16 @@ <artifactId>jfreechart</artifactId> <version>1.0.13</version> </dependency> + <dependency> + <groupId>jgoodies</groupId> + <artifactId>looks</artifactId> + <version>1.2.2</version> + </dependency> + <dependency> + <groupId>jgoodies</groupId> + <artifactId>forms</artifactId> + <version>1.0.5</version> + </dependency> </dependencies> <build> <finalName>irrigation</finalName> Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-21 00:29:19 UTC (rev 311) @@ -1,7 +1,6 @@ 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.event.ActionEvent; @@ -11,6 +10,8 @@ import javax.swing.JPanel; import javax.swing.Timer; +import edu.asu.commons.irrigation.server.ClientData; + /** * $Id$ * @@ -35,15 +36,15 @@ private int gateHeight = 20; - Random generator = new Random(); + private Random generator = new Random(); private boolean enableBallAnimation = true; - private double totalContributedBandwidth; + private int maximumIrrigationCapacity; - private ClientDataModel clientGameState; + private ClientDataModel clientDataModel; - private int numberofGates = 6; + private int numberOfGates = 6; private int serverHeight = 100; @@ -55,15 +56,11 @@ //////////////////////////////////////////////////////////////////////////// - public CanalPanel(ClientDataModel clientGameState) { + public CanalPanel(ClientDataModel clientDataModel) { super(); //when totalContributed bandwidth = 1.0, you dont see the canal line - this.totalContributedBandwidth = clientGameState.getGroupDataModel().getMaximumAvailableFlowCapacity(); - this.clientGameState = clientGameState; - if(totalContributedBandwidth == 1.0){ - totalContributedBandwidth = 2.0; - } - + this.maximumIrrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + this.clientDataModel = clientDataModel; initialize(); } @@ -73,12 +70,11 @@ * @return void */ private void initialize() { - this.setPreferredSize(new Dimension(1098,150)); - this.setBackground(Color.white); +// this.setPreferredSize(new Dimension(1098,150)); + this.setBackground(Color.WHITE); //initializing the constructor for Gates - for(int i=0;i<numberofGates ;i++){ - gate[i] = new Gate(totalContributedBandwidth,i); - //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); + for(int i=0;i<numberOfGates ;i++){ + gate[i] = new Gate(maximumIrrigationCapacity,i); } initializeBalls(); @@ -96,12 +92,12 @@ graphics2D.setColor(Color.BLUE); graphics2D.fillRect(0,0,serverHeight,serverWidth); //draw the other gates - for(int i=0;i<numberofGates-1;i++){ + for(int i=0;i<numberOfGates-1;i++){ graphics2D.setColor(Color.BLUE); graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); } - int numClients = clientGameState.getAllClientIdentifiers().size(); + int numClients = clientDataModel.getAllClientIdentifiers().size(); for(int i=0;i<numClients;i++) { graphics2D.setColor(Color.BLUE); graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), @@ -157,7 +153,7 @@ } //order matters here if(!(i == 5)){ - gate[i].setOpeningsHeight((totalContributedBandwidth*bandWidthCanalHeightMapping) + gate[i].setOpeningsHeight((maximumIrrigationCapacity*bandWidthCanalHeightMapping) - gate[i].getHeight()); gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); @@ -195,13 +191,8 @@ */ private void initializeBalls() { 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); - } } @@ -222,11 +213,9 @@ * 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 >= (serverWidth - gateBuffer ) && balls[i].x <= serverWidth) && (balls[i].y >= serverHeight-(int)(totalContributedBandwidth*bandWidthCanalHeightMapping) && + case 0: if((balls[i].x >= (serverWidth - gateBuffer ) && balls[i].x <= serverWidth) && (balls[i].y >= serverHeight-(int)(maximumIrrigationCapacity*bandWidthCanalHeightMapping) && balls[i].y <= serverHeight)){ balls[i].setPosition(1); setBounds(i); @@ -337,7 +326,7 @@ case 6: setBounds(i); if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - setBallinServer(i); + setBallInServer(i); } if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ @@ -350,7 +339,7 @@ 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){ - setBallinServer(i); + setBallInServer(i); } else{ setBounds(i); @@ -359,8 +348,7 @@ } - private void setBallinServer(int i) { - // TODO Auto-generated method stub + private void setBallInServer(int i) { generator.setSeed(i*(i+1)); balls[i].setX(generator.nextInt(serverWidth)); balls[i].setY(generator.nextInt(serverHeight)); @@ -406,14 +394,14 @@ } } - public void openGates(int priority) { + public void openGate(int priority) { gate[priority].setGateOpen(true); // paintComponent(graphics2D); repaint(); } - public void closeGates(int priority) { + public void closeGate(int priority) { gate[priority].setGateOpen(false); gate[priority].setx1(gate[priority].getdefaultx1()); gate[priority].sety1(gate[priority].getdefaulty1()); @@ -424,6 +412,13 @@ public void endRound() { initializeBalls(); + closeAllGates(); } + + private void closeAllGates() { + for (ClientData clientData: clientDataModel.getClientDataMap().values()) { + closeGate(clientData.getPriority()); + } + } } 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-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-21 00:29:19 UTC (rev 311) @@ -125,7 +125,6 @@ private void initGuiComponents(Dimension screenSize) { cardLayout = new CardLayout(); setLayout(cardLayout); - instructionsScrollPane = new JScrollPane(getInstructionsEditorPane()); instructionsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); instructionsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); @@ -230,8 +229,8 @@ nextButton.setEnabled(true); 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()" + // just be an animated gif or something more like + // if instructions.hasAnimation() if (instructionNumber == 5) { getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); } @@ -261,9 +260,6 @@ instructionNumber++; setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); } -// else { -// setInstructions(clientDataModel.getRoundConfiguration().getInstructions()); -// } if(instructionNumber == 5) { getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); } @@ -382,6 +378,7 @@ public void startRound(final RoundConfiguration configuration) { Runnable runnable = new Runnable() { public void run() { + disableInstructions(); addCenterComponent(irrigationGamePanel); irrigationGamePanel.startRound(); } @@ -397,15 +394,12 @@ * updates the mainIrrigationGameWindow Panel and adds * instructionsScrollPane with the debreifing information */ - public void updateEndRoundEvent(final EndRoundEvent event) { + public void endRound(final EndRoundEvent event) { irrigationGamePanel.endRound(); Runnable runnable = new Runnable() { public void run() { investedTokensTextField.setText(""); addDebriefingText(event); - // generate debriefing text from data culled from the Event -// addCenterComponent(instructionsEditorPane); - // FIXME: this is probably wrong. addCenterComponent(getInstructionsPanel()); } }; @@ -710,10 +704,14 @@ timer.start(); } } + + private void disableInstructions() { + quizMessageLabel.setText(""); + getInstructionsPanel().remove(getInstructionsNavigationPanel()); + } public void enableInstructions() { setInstructions(getGeneralInstructions(1,pagesTraversed)); addCenterComponent(getInstructionsPanel()); - } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-21 00:29:19 UTC (rev 311) @@ -181,7 +181,7 @@ }); channel.add(this, new EventTypeProcessor<EndRoundEvent>(EndRoundEvent.class) { public void handle(EndRoundEvent event) { - experimentGameWindow.updateEndRoundEvent(event); + experimentGameWindow.endRound(event); } }); channel.add(this, new EventTypeProcessor<ClientUpdateEvent>(ClientUpdateEvent.class) { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-21 00:29:19 UTC (rev 311) @@ -4,13 +4,13 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Font; -import java.awt.GridLayout; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException; import javax.swing.BoxLayout; +import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; @@ -18,6 +18,8 @@ import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; +import javax.swing.GroupLayout.Alignment; +import javax.swing.GroupLayout.ParallelGroup; import edu.asu.commons.irrigation.server.ClientData; @@ -127,16 +129,48 @@ panel.add(getGateSwitchButton()); JPanel bottomPanel = new JPanel(); - bottomPanel.setLayout(new GridLayout(4, 2)); - bottomPanel.add(getWaterUsedLabel()); - bottomPanel.add(getWaterUsedTextField()); - bottomPanel.add(getTokensNotInvestedLabel()); - bottomPanel.add(getTokensNotInvestedTextField()); - bottomPanel.add(getTokensEarnedLabel()); - bottomPanel.add(getTokensEarnedTextField()); - bottomPanel.add(getTotalTokensEarnedLabel()); - bottomPanel.add(getTotalTokensEarnedTextField()); + GroupLayout layout = new GroupLayout(bottomPanel); + bottomPanel.setLayout(layout); + layout.setAutoCreateContainerGaps(true); + layout.setAutoCreateGaps(true); + + GroupLayout.SequentialGroup horizontalGroup = layout.createSequentialGroup(); + ParallelGroup labelsGroup = layout.createParallelGroup(); + labelsGroup.addComponent(getWaterUsedLabel()).addComponent(getTokensNotInvestedLabel()).addComponent(getTokensEarnedLabel()).addComponent(getTotalTokensEarnedLabel()); + + horizontalGroup.addGroup(labelsGroup); + ParallelGroup textFieldGroup = layout.createParallelGroup(); + textFieldGroup.addComponent(getWaterUsedTextField()); + textFieldGroup.addComponent(getTokensNotInvestedTextField()); + textFieldGroup.addComponent(getTokensEarnedTextField()); + textFieldGroup.addComponent(getTotalTokensEarnedTextField()); + horizontalGroup.addGroup(textFieldGroup); + layout.setHorizontalGroup(horizontalGroup); + + GroupLayout.SequentialGroup verticalGroup = layout.createSequentialGroup(); + verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + .addComponent(getWaterUsedLabel()).addComponent(getWaterUsedTextField())); + + verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + .addComponent(getTokensNotInvestedLabel()).addComponent(getTokensNotInvestedTextField())); + + verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + .addComponent(getTokensEarnedLabel()).addComponent(getTokensEarnedTextField())); + + verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + .addComponent(getTotalTokensEarnedLabel()).addComponent(getTotalTokensEarnedTextField())); + + layout.setVerticalGroup(verticalGroup); +// bottomPanel.add(getWaterUsedLabel()); +// bottomPanel.add(getWaterUsedTextField()); +// bottomPanel.add(getTokensNotInvestedLabel()); +// bottomPanel.add(getTokensNotInvestedTextField()); +// bottomPanel.add(getTokensEarnedLabel()); +// bottomPanel.add(getTokensEarnedTextField()); +// bottomPanel.add(getTotalTokensEarnedLabel()); +// bottomPanel.add(getTotalTokensEarnedTextField()); + panel.add(bottomPanel); return panel; } @@ -145,6 +179,7 @@ if (waterUsedTextField == null) { waterUsedTextField = new JTextField(); waterUsedTextField.setEditable(false); + waterUsedTextField.setBackground(Color.GRAY); } return waterUsedTextField; } @@ -354,15 +389,16 @@ irrigationCapacityLabel.setText( String.format("Irrigation capacity: %d cubic feet per second (cfps)", irrigationCapacity)); - for(final ClientData clientData : clientDataModel.getClientDataMap().values()){ + for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { + System.err.println("changing canal gate for client: " + clientData.getPriority() + ":" + clientData.isGateOpen()); if (clientData.isGateOpen()) { - canalPanel.openGates(clientData.getPriority()); + canalPanel.openGate(clientData.getPriority()); } else if(clientData.isPaused()){ - canalPanel.closeGates(clientData.getPriority()); + canalPanel.closeGate(clientData.getPriority()); } else if(clientData.isGateClosed()){ - canalPanel.closeGates(clientData.getPriority()); + canalPanel.closeGate(clientData.getPriority()); } } ClientData clientData = clientDataModel.getClientData(); @@ -370,7 +406,9 @@ tokensNotInvestedTextField.setText("" + clientData.getUninvestedTokens()); tokensEarnedTextField.setText("" + clientData.waterToTokenFunction()); totalTokensEarnedTextField.setText("" + clientData.getTotalTokensEarned()); - scoreBoxPanel.update(clientDataModel); + getScoreBoxPanel().update(clientDataModel); +// getMiddleWindowPanel().update(clientDataModel); + } }; @@ -396,10 +434,11 @@ public void endRound() { Runnable createGuiRunnable = new Runnable(){ public void run() { - //Refreshing the screen and preparing the main Irrigation Window for the next round - //provided we have already got the updatedClientDataMap - irrigationGameWindow.endRound(); - upperPanel.removeAll(); + if (canalPanel != null) { + System.err.println("Removing canal panel"); + upperPanel.remove(canalPanel); + } + System.err.println("ending round for canal panel"); canalPanel.endRound(); } }; @@ -432,7 +471,8 @@ public void startRound() { upperPanel.add(getCanalPanel(), BorderLayout.CENTER); open = false; - scoreBoxPanel.initialize(clientDataModel); + getScoreBoxPanel().initialize(clientDataModel); + getMiddleWindowPanel().initialize(clientDataModel); revalidate(); // mainIrrigationPanel.add(getJPanelUpStreamWindow(),null); // mainIrrigationPanel.add(getJPanelDownStreamWindow(),null); @@ -440,12 +480,9 @@ // mainIrrigationPanel.add(getJPanelMiddleWindow(),null); } - private JPanel getJPanelMiddleWindow() { + private MiddleWindowPanel getMiddleWindowPanel() { if(middleWindowPanel == null){ - if(clientDataModel != null){ - System.out.println("Main Irrigation Window clientGameState is not null"); - } - middleWindowPanel = new MiddleWindowPanel(clientDataModel); + middleWindowPanel = new MiddleWindowPanel(); } return middleWindowPanel; } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-21 00:29:19 UTC (rev 311) @@ -19,140 +19,83 @@ */ public class MiddleScorePanel extends JPanel { - private static final long serialVersionUID = -1329890496417714604L; - - private JLabel positionText; - - private JLabel currentBandwidthText; - - private JLabel filesDownloadedText; - - private JLabel tokensText; - - private JLabel fileLabel; - - private int priority; - - private ClientData clientData; // @jve:decl-index=0: + private static final long serialVersionUID = -1329890496417714604L; - private ClientDataModel clientGameState; // @jve:decl-index=0: - - public MiddleScorePanel(int priority,ClientDataModel clientGameState){ - super(); - this.priority = priority; - /*this.clientGameState = clientGameState; - */ - initialize(clientGameState); - } + private JLabel positionText; - private void initialize(ClientDataModel clientGameState) { - // TODO Auto-generated method stub - /*GridLayout gridLayout = new GridLayout(); - gridLayout.setColumns(1); - gridLayout.setRows(4); - this.setLayout(gridLayout); - */ - this.setLayout(null); - this.clientGameState = clientGameState; - /*if(this.clientGameState == null) - System.out.println("client GameState is null in MiddleScorePanel initialize"); - */ - if(clientGameState.getPriority() == priority) - this.setBackground(Color.GREEN); - else - this.setBackground(Color.YELLOW); - this.setSize(new Dimension(60,200)); -// this.add(getFileLabel()); - this.add(getPositionText(priority),null); - this.add(getFilesDownLoadedText(priority),null); - this.add(getCurrentBandwidth(),null); - this.add(getTokensCollected(),null); - - - } + private JLabel currentBandwidthText; -// private JLabel getFileLabel() { -// if(fileLabel == null){ -// URL fileUrl = ResourceLoader.getResourceAsUrl("images/file.gif"); -// fileLabel = new JLabel(); -// fileLabel.setBounds(new Rectangle(10,50,30,32)); -// fileLabel.setIcon(new ImageIcon(fileUrl)); -// fileLabel.setVisible(false); -// } -// return fileLabel; -// } + private JLabel waterUsedTextField; - private JLabel getTokensCollected() { - // TODO Auto-generated method stub - if(tokensText == null){ - tokensText = new JLabel(); - tokensText.setBounds(new Rectangle(5,50+32+10+20+10+20+10+20+10,30,20)); - tokensText.setText(""); - } - return tokensText; - } + private JLabel totalTokensEarnedTextField; - private JLabel getCurrentBandwidth() { - // TODO Auto-generated method stub - if(currentBandwidthText == null){ - currentBandwidthText = new JLabel(); - currentBandwidthText.setBounds(new Rectangle(5,50+32+10+20+10,30,20)); - currentBandwidthText.setText(""); - } - return currentBandwidthText; - } + private int priority; - private JLabel getPositionText(int priority) { - // TODO Auto-generated method stub - if(positionText == null){ - positionText = new JLabel(); - positionText.setBounds(new Rectangle(5,50+32+10,30,20)); - switch(priority){ - case 0: positionText.setText("A"); - break; - - case 1: positionText.setText("B"); - break; - - case 2: positionText.setText("C"); - break; - - case 3: positionText.setText("D"); - break; - - case 4: positionText.setText("E"); - break; - - } - } - - return positionText; - } - + private ClientData clientData; - private JLabel getFilesDownLoadedText(int priority) { - if(filesDownloadedText == null){ - filesDownloadedText = new JLabel(); - filesDownloadedText.setBounds(new Rectangle(5,50+32+10+20+10+20+10,30,20)); - filesDownloadedText.setText(new Integer(priority).toString()); - } - return filesDownloadedText; - } + public MiddleScorePanel(int priority, ClientData clientData){ + super(); + this.priority = priority; + initialize(clientData); + } - public void update(ClientData clientData) { - this.clientData = clientData; - - if(clientData.getAvailableFlowCapacity() > 25){ - currentBandwidthText.setText(new Double(25).toString()); - } - else - currentBandwidthText.setText(new Double(clientData.getAvailableFlowCapacity()).toString()); - - filesDownloadedText.setText(new Integer(clientData.getWaterUsed()).toString()); - tokensText.setText(new Integer(clientData.getTotalTokensEarned()).toString()); - - if(clientData.isGateOpen() && clientData.getAvailableFlowCapacity() > 0) { - // show that client is actively irrigating - } - } + private void initialize(ClientData clientData) { + this.setLayout(null); + this.clientData = clientData; + setBackground( clientData.getPriority() == priority ? Color.GREEN : Color.YELLOW); + this.setPreferredSize(new Dimension(60,200)); + this.add(getPositionText(),null); + this.add(getWaterUsedTextField(),null); + this.add(getCurrentBandwidth(),null); + this.add(getTokensCollected(),null); + + + } + + private JLabel getTokensCollected() { + if(totalTokensEarnedTextField == null){ + totalTokensEarnedTextField = new JLabel(); + totalTokensEarnedTextField.setBounds(new Rectangle(5,50+32+10+20+10+20+10+20+10,30,20)); + totalTokensEarnedTextField.setText(""); + } + return totalTokensEarnedTextField; + } + + private JLabel getCurrentBandwidth() { + if(currentBandwidthText == null){ + currentBandwidthText = new JLabel(); + currentBandwidthText.setBounds(new Rectangle(5,50+32+10+20+10,30,20)); + currentBandwidthText.setText(""); + } + return currentBandwidthText; + } + + private JLabel getPositionText() { + if (positionText == null){ + positionText = new JLabel(clientData.getPriorityAsString()); + positionText.setBounds(new Rectangle(5,50+32+10,30,20)); + } + return positionText; + } + + + private JLabel getWaterUsedTextField() { + if(waterUsedTextField == null){ + waterUsedTextField = new JLabel("0"); + waterUsedTextField.setBounds(new Rectangle(5,50+32+10+20+10+20+10,30,20)); + } + return waterUsedTextField; + } + + public void update(ClientData clientData) { + this.clientData = clientData; + currentBandwidthText.setText("" + clientData.getAvailableFlowCapacity()); + waterUsedTextField.setText("" + clientData.getWaterUsed()); + totalTokensEarnedTextField.setText("" + clientData.getTotalTokensEarned()); + + if(clientData.isGateOpen() && clientData.getAvailableFlowCapacity() > 0) { + // show that client is actively irrigating + + } + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java 2009-10-21 00:29:19 UTC (rev 311) @@ -6,7 +6,9 @@ import java.awt.Dimension; import java.awt.Rectangle; +import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import javax.swing.JLabel; @@ -20,82 +22,65 @@ */ public class MiddleWindowPanel extends JPanel { - /** - * - */ - private static final long serialVersionUID = 2892921110280857458L; + private static final long serialVersionUID = 2892921110280857458L; - //Map<Integer, MiddleScorePanel>middleScorePanelMap = new LinkedHashMap<Integer, MiddleScorePanel>(); - Map<Integer, JLabel>jLabelMap = new LinkedHashMap<Integer, JLabel>(); // @jve:decl-index=0: - - Map<Integer, MiddleScorePanel> middleScorePanelMap = new LinkedHashMap<Integer, MiddleScorePanel>(); + //Map<Integer, MiddleScorePanel>middleScorePanelMap = new LinkedHashMap<Integer, MiddleScorePanel>(); + Map<Integer, JLabel>jLabelMap = new LinkedHashMap<Integer, JLabel>(); // @jve:decl-index=0: - JLabel positionLabel; - JLabel availableBandwidthLabel; - JLabel filesDownLoadedLabel; - JLabel tokensCollectedLabel; - - - private ClientDataModel clientGameState; +// Map<Integer, MiddleScorePanel> middleScorePanelMap = new LinkedHashMap<Integer, MiddleScorePanel>(); + private List<MiddleScorePanel> middleScorePanels = new ArrayList<MiddleScorePanel>(); - public MiddleWindowPanel(ClientDataModel clientGameState){ - super(); - this.clientGameState = clientGameState; - initialize(); - - - } + JLabel positionLabel; + JLabel availableBandwidthLabel; + JLabel filesDownLoadedLabel; + JLabel tokensCollectedLabel; - private void initialize() { - // TODO Auto-generated method stub - //this.setLayout(null); - - this.setLayout(null); - this.setBounds(new Rectangle(13,100 + 100 - 50,1093,100+50+50)); - this.setSize(new Dimension(1093,200)); - - positionLabel = new JLabel(); - positionLabel.setBounds(new Rectangle(80,50+32+10,150,20)); - positionLabel.setText("Position"); - - availableBandwidthLabel = new JLabel(); - availableBandwidthLabel.setBounds(new Rectangle(80,50+32+10+20+10,150,20)); - availableBandwidthLabel.setText("Available Flow Capacity"); - - filesDownLoadedLabel = new JLabel(); - filesDownLoadedLabel.setBounds(new Rectangle(80,50+32+10+20+10+20+10, 150,20)); - filesDownLoadedLabel.setText("Crops Grown"); - - tokensCollectedLabel = new JLabel(); - tokensCollectedLabel.setBounds(new Rectangle(80,50+32+10+20+10+20+10+20+10, 150,20)); - tokensCollectedLabel.setText("Tokens Collected"); - - this.add(positionLabel, null); - this.add(availableBandwidthLabel, null); - this.add(filesDownLoadedLabel, null); - this.add(tokensCollectedLabel, null); - - for(int i=0;i<clientGameState.getRoundConfiguration().getClientsPerGroup();i++){ - /*JLabel jTextLabel = new JLabel(); - jLabelMap.put(new Integer(i), jTextLabel); - jTextLabel.setBounds(new Rectangle((258 + 20 + i*198),35,60,50)); - this.add(jTextLabel,null); - */ - if(this.clientGameState != null) - System.out.println("Middle Window clientGameState is not null"); - MiddleScorePanel middleScorePanel = new MiddleScorePanel(i,this.clientGameState); - middleScorePanel.setBounds(new Rectangle((258 + 20 + i*198)-20,0,60,100+50+50)); - middleScorePanelMap.put(new Integer(i), middleScorePanel); - this.add(middleScorePanel, null); - - } - } + public MiddleWindowPanel() { + this.setLayout(null); + this.setBounds(new Rectangle(13,100 + 100 - 50,1093,100+50+50)); + this.setSize(new Dimension(1093,200)); - public void update(ClientData clientData) { - // TODO Auto-generated method stub - //jLabelMap.get(new Integer(clientData.getPriority())).setText(new Integer(clientData.getFilesDownloaded()).toString()); - middleScorePanelMap.get(new Integer(clientData.getPriority())).update(clientData); - } - + positionLabel = new JLabel(); + positionLabel.setBounds(new Rectangle(80,50+32+10,150,20)); + positionLabel.setText("Position"); + + availableBandwidthLabel = new JLabel(); + availableBandwidthLabel.setBounds(new Rectangle(80,50+32+10+20+10,150,20)); + availableBandwidthLabel.setText("Available Flow Capacity"); + + filesDownLoadedLabel = new JLabel(); + filesDownLoadedLabel.setBounds(new Rectangle(80,50+32+10+20+10+20+10, 150,20)); + filesDownLoadedLabel.setText("Crops Grown"); + + tokensCollectedLabel = new JLabel(); + tokensCollectedLabel.setBounds(new Rectangle(80,50+32+10+20+10+20+10+20+10, 150,20)); + tokensCollectedLabel.setText("Tokens Collected"); + + this.add(positionLabel, null); + this.add(availableBandwidthLabel, null); + this.add(filesDownLoadedLabel, null); + this.add(tokensCollectedLabel, null); + } + + public void initialize(ClientDataModel clientDataModel) { + removeAll(); + middleScorePanels.clear(); + for (ClientData clientData : clientDataModel.getClientDataSortedByPriority()) { + int priority = clientData.getPriority(); + MiddleScorePanel middleScorePanel = new MiddleScorePanel(clientDataModel.getPriority(), clientData); + middleScorePanel.setBounds(new Rectangle((258 + 20 + priority*198)-20,0,60,100+50+50)); + middleScorePanels.add(middleScorePanel); + add(middleScorePanel, null); + } + } + + public void update(ClientDataModel clientDataModel) { + // TODO Auto-generated method stub + //jLabelMap.get(new Integer(clientData.getPriority())).setText(new Integer(clientData.getFilesDownloaded()).toString()); + for (ClientData clientData : clientDataModel.getClientDataSortedByPriority()) { + middleScorePanels.get(clientData.getPriority()).update(clientData); + } + } + } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-21 00:29:19 UTC (rev 311) @@ -60,7 +60,7 @@ private void initializeEventProcessors() { channel.add(this, new EventTypeProcessor<RegistrationEvent>(RegistrationEvent.class) { public void handle(RegistrationEvent registrationEvent) { - facilitatorWindow.setText(registrationEvent.getRoundConfiguration().getInstructions()); + facilitatorWindow.addInstructions(registrationEvent.getRoundConfiguration().getInstructions()); } }); channel.add(this, new EventTypeProcessor<FacilitatorEndRoundEvent>(FacilitatorEndRoundEvent.class) { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-21 00:29:19 UTC (rev 311) @@ -47,6 +47,8 @@ private JButton showInstructionsButton; private JButton displayInvestmentButton; + + private StringBuilder builder = new StringBuilder(); /** * This is the default constructor */ @@ -165,8 +167,8 @@ * @return javax.swing.JButton */ public void endRound(FacilitatorEndRoundEvent event) { + builder = new StringBuilder(); ServerDataModel model = event.getServerDataModel(); - StringBuilder builder = new StringBuilder(); builder.append("<h3>Facilitator Debriefing:</h3>"); builder.append("<table><thead><th>Participant</th><th>Current tokens</th><th>Current Income</th><th>Total Income</th></thead><tbody>"); Map<Identifier, ClientData> clientDataMap = new HashMap<Identifier, ClientData>(); @@ -195,5 +197,10 @@ } setText(builder.toString()); } + + public void addInstructions(String instructions) { + builder.append(instructions); + setText(builder.toString()); + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-21 00:29:19 UTC (rev 311) @@ -51,7 +51,7 @@ private final Map<Identifier, ClientData> clients = new LinkedHashMap<Identifier, ClientData>(); - private final static int SERVER_SLEEP_INTERVAL = 333; + private final static int SERVER_SLEEP_INTERVAL = 100; private final Object roundSignal = new Object(); @@ -194,6 +194,11 @@ public void handle(DisconnectionRequest request) { getLogger().warning("irrigation server handling disconnection request: " + request); Identifier disconnectedClientId = request.getId(); + if (disconnectedClientId.equals(facilitatorId)) { + getLogger().warning("Disconnecting facilitator."); + facilitatorId = null; + return; + } synchronized (clients) { clients.remove(disconnectedClientId); serverDataModel.removeClient(disconnectedClientId); @@ -303,14 +308,11 @@ int timeLeft = (int) (currentRoundDuration.getTimeLeft() / 1000); // allocate bandwidth to each client for (ClientData clientData : group.getClientDataMap().values()) { - /** - * undisrupted bandwith extensions - */ - if(clientData.getAvailableFlowCapacity() <= 0 && getConfiguration().isUndisruptedFlowRequired()){ - clientData.init(group.getCurrentlyAvailableFlowCapacity()); - } + // for undisrupted flow extensions, disabled for the time being. +// if (clientData.getAvailableFlowCapacity() <= 0 && getConfiguration().isUndisruptedFlowRequired()){ +// clientData.init(group.getCurrentlyAvailableFlowCapacity()); +// } if (clientData.isGateOpen()) { - //System.out.println("Downloading file"+clientData.getFileNumber()+"Current time"+System.currentTimeMillis()/1000); group.allocateFlowCapacity(clientData); } else if (clientData.isGateClosed()) { @@ -338,9 +340,11 @@ private class IrrigationServerStateMachine implements StateMachine { private IrrigationServerState state; + + private long lastTime; + + private Duration secondTick = Duration.create(1000L); - private final Duration secondTick = Duration.create(1000L); - public void initialize() { // FIXME: may want to change this as we add more states. state = IrrigationServerState.WAITING; @@ -357,11 +361,13 @@ // start timers currentRoundDuration = getRoundConfiguration().getRoundDuration(); currentRoundDuration.start(); + state = IrrigationServerState.ROUND_IN_PROGRESS; secondTick.start(); - state = IrrigationServerState.ROUND_IN_PROGRESS; +// lastTime = System.currentTimeMillis(); } private void processRound() { +// if ((System.currentTimeMillis() - lastTime) / 1000 > 1) { if (secondTick.hasExpired()) { for (GroupDataModel group: serverDataModel.getAllGroupDataModels()) { // reset available bandwidth for this group to calculate new allocations for the group @@ -374,6 +380,7 @@ getLogger().throwing(IrrigationServerStateMachine.class.getName(), "processRound", exception); } } +// lastTime = System.currentTimeMillis(); secondTick.restart(); } } Modified: irrigation/trunk/src/main/resources/web/client.jnlp =================================================================== --- irrigation/trunk/src/main/resources/web/client.jnlp 2009-10-20 09:58:30 UTC (rev 310) +++ irrigation/trunk/src/main/resources/web/client.jnlp 2009-10-21 00:29:19 UTC (rev 311) @@ -10,7 +10,9 @@ <resources> <j2se version="1.6+"/> <jar href="client.jar"/> - <jar href='@FRAMEWORK_JAR@'/> + <jar href='csidex.jar'/> + <jar href='jcommon.jar'/> + <jar href='jfreechart.jar'/> </resources> <application-desc main-class="@MAIN_CLASS@"/> </jnlp> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |