[virtualcommons-svn] SF.net SVN: virtualcommons:[327] irrigation/trunk/src/main
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-10-23 00:28:06
|
Revision: 327 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=327&view=rev Author: alllee Date: 2009-10-23 00:27:56 +0000 (Fri, 23 Oct 2009) Log Message: ----------- interface improvements, getting rid of timer, not creating new canal panels every time. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 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-22 20:12:59 UTC (rev 326) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-10-23 00:27:56 UTC (rev 327) @@ -245,6 +245,13 @@ repaint(); } } + + public void stopTimer() { + if (timer != null) { + timer.stop(); + timer = null; + } + } /* * This will process the balls according to their position 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-22 20:12:59 UTC (rev 326) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-23 00:27:56 UTC (rev 327) @@ -40,7 +40,7 @@ private Random generator = new Random(); - private boolean enableBallAnimation = true; + private final static boolean enableBallAnimation = true; private int maximumIrrigationCapacity; @@ -61,10 +61,17 @@ public CanalPanel(ClientDataModel clientDataModel) { super(); //when totalContributed bandwidth = 1.0, you dont see the canal line - this.maximumIrrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); - this.clientDataModel = clientDataModel; - initialize(); + setClientDataModel(clientDataModel); } + + public void setClientDataModel(ClientDataModel clientDataModel) { + if (timer != null) { + timer.stop(); + } + this.maximumIrrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + this.clientDataModel = clientDataModel; + initialize(); + } /** * @@ -112,25 +119,23 @@ graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); //////////////////////Animation Logic//////////////////////////// - if (enableBallAnimation) { - graphics.setColor(Color.white); - // int ballCounter = 0; - for(int i=0;i<BALLCOUNT;i++){ - 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()); - } - } - } + graphics.setColor(Color.white); + // int ballCounter = 0; + for(int i=0;i<BALLCOUNT;i++){ + 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()); + } + } } } @@ -412,7 +417,10 @@ } public void endRound() { - initializeBalls(); + if (timer != null) { + timer.stop(); + } + timer = null; closeAllGates(); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-10-22 20:12:59 UTC (rev 326) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-10-23 00:27:56 UTC (rev 327) @@ -1,9 +1,7 @@ package edu.asu.commons.irrigation.client; import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Dimension; -import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; @@ -13,12 +11,12 @@ import java.util.List; import java.util.Map; -import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.JProgressBar; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTextPane; @@ -72,6 +70,7 @@ } private class TextEntryPanel extends JPanel { + private JProgressBar timeLeftProgressBar; private JLabel timeLeftLabel; private JTextField chatField; private Identifier targetIdentifier = Identifier.ALL; @@ -94,12 +93,17 @@ } }); JPanel timeLeftPanel = new JPanel(); - timeLeftPanel.setLayout(new BoxLayout(timeLeftPanel, BoxLayout.LINE_AXIS)); - timeLeftLabel = new JLabel("40"); - timeLeftLabel.setFont(new Font("Arial", Font.BOLD, 14)); - timeLeftLabel.setForeground(new Color(0x0000dd)); - timeLeftPanel.add(new JLabel(" Time left: ")); - timeLeftPanel.add(timeLeftLabel); +// timeLeftPanel.setLayout(new BoxLayout(timeLeftPanel, BoxLayout.LINE_AXIS)); + +// timeLeftLabel = new JLabel("40"); +// timeLeftLabel.setFont(new Font("Arial", Font.BOLD, 14)); +// timeLeftLabel.setForeground(new Color(0x0000dd)); +// timeLeftPanel.add(new JLabel(" Time left: ")); +// timeLeftPanel.add(timeLeftLabel); + timeLeftProgressBar = new JProgressBar(0, 60); + timeLeftProgressBar.setStringPainted(true); + timeLeftPanel.setLayout(new BorderLayout()); + timeLeftPanel.add(timeLeftProgressBar, BorderLayout.CENTER); add(timeLeftPanel, BorderLayout.PAGE_START); add(chatField, BorderLayout.CENTER); @@ -118,8 +122,10 @@ chatField.requestFocusInWindow(); } - private void setTimeRemaining(long timeRemaining) { - timeLeftLabel.setText(String.format(" %d s", timeRemaining / 1000L)); + private void setTimeLeft(long timeLeft) { + int timeLeftInSeconds = (int) (timeLeft / 1000L); + timeLeftProgressBar.setValue(timeLeftInSeconds); + timeLeftProgressBar.setString(String.format("%d sec", timeLeftInSeconds)); } } @@ -166,8 +172,8 @@ .addStyle("italic", defaultStyle), true); } - public void setTimeRemaining(long timeRemaining) { - textEntryPanel.setTimeRemaining(timeRemaining); + public void setTimeLeft(long timeLeft) { + textEntryPanel.setTimeLeft(timeLeft); } private String getChatHandle(Identifier identifier) { 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-22 20:12:59 UTC (rev 326) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-23 00:27:56 UTC (rev 327) @@ -40,7 +40,6 @@ * * The root experiment window placed in the client's JFrame. * - * FIXME: refactor this class. * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev$ @@ -107,8 +106,6 @@ private int numberOfGeneralInstructionPages; - private JLabel infrastructureEfficiencyLabel = new JLabel("Current infrastructure efficiency: "); - public ExperimentGameWindow(IrrigationClient client) { this.client = client; this.clientDataModel = client.getClientDataModel(); @@ -142,30 +139,14 @@ tokenInstructionsEditorPane = createInstructionsEditorPane(); tokenInstructionsScrollPane = new JScrollPane(tokenInstructionsEditorPane); investTokensPanel.add(tokenInstructionsScrollPane, BorderLayout.CENTER); - tokenInstructionsEditorPane.setText(getServerConfiguration().getInvestmentInstructions()); tokenInstructionsEditorPane.setCaretPosition(0); tokenInstructionsEditorPane.repaint(); investTokensPanel.add(getSubmitTokenPanel(), BorderLayout.SOUTH); - investTokensPanel.add(infrastructureEfficiencyLabel, BorderLayout.NORTH); investTokensPanel.setBackground(Color.WHITE); } return investTokensPanel; } - public void updateInfrastructureEfficiencyLabel() { - GroupDataModel group = clientDataModel.getGroupDataModel(); - RoundConfiguration roundConfiguration = clientDataModel.getRoundConfiguration(); - int infrastructureEfficiency = 0; - if (roundConfiguration.isPracticeRound() || roundConfiguration.isFirstRound()) { - infrastructureEfficiency = roundConfiguration.getInitialInfrastructureEfficiency(); - } - else { - System.err.println("group was not null, efficiency is: " + group.getInfrastructureEfficiency() + " degrading by " + clientDataModel.getRoundConfiguration().getInfrastructureDegradationFactor()); - infrastructureEfficiency = group.getInfrastructureEfficiency() - roundConfiguration.getInfrastructureDegradationFactor(); - } - infrastructureEfficiencyLabel.setText("Current infrastructure efficiency: " + infrastructureEfficiency); - } - private JPanel getSubmitTokenPanel() { if (submitTokenPanel == null) { submitTokenPanel = new JPanel(); @@ -233,6 +214,7 @@ getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); } else { + getInstructionsPanel().remove(getCanalAnimationPanel()); } getInstructionsPanel().revalidate(); @@ -272,7 +254,7 @@ return nextButton; } - private JPanel getCanalAnimationPanel() { + private CanalAnimationPanel getCanalAnimationPanel() { if (canalAnimationPanel == null) { canalAnimationPanel = new CanalAnimationPanel(40); } @@ -337,7 +319,7 @@ else { investedTokensTextField.setText(""); instructionsBuilder.delete(0, instructionsBuilder.length()); - instructionsBuilder.append("\nPlease enter your tokens within the range 0 - 10"); + instructionsBuilder.append("<h3>Please enter your tokens within the range 0 - 10</h3>"); instructionsBuilder.append(getServerConfiguration().getInvestmentInstructions()); tokenInstructionsEditorPane.setText(instructionsBuilder.toString()); } @@ -345,7 +327,7 @@ catch(NumberFormatException e){ investedTokensTextField.setText(""); instructionsBuilder.delete(0, instructionsBuilder.length()); - instructionsBuilder.append("\nYou only have between 0 and 10 to invest. Please choose a number between 0 and 10 and try again."); + instructionsBuilder.append("<h3>You only have between 0 and 10 to invest. Please choose a number between 0 and 10 and try again.</h3>"); instructionsBuilder.append(getServerConfiguration().getInvestmentInstructions()); tokenInstructionsEditorPane.setText(instructionsBuilder.toString()); } @@ -380,6 +362,7 @@ public void startRound(final RoundConfiguration configuration) { Runnable runnable = new Runnable() { public void run() { + getCanalAnimationPanel().stopTimer(); disableInstructions(); addCenterComponent(irrigationGamePanel); irrigationGamePanel.startRound(); @@ -394,7 +377,7 @@ /* * updates the mainIrrigationGameWindow Panel and adds - * instructionsScrollPane with the debreifing information + * instructionsScrollPane with the debriefing information */ public void endRound(final EndRoundEvent event) { irrigationGamePanel.endRound(); @@ -583,8 +566,25 @@ public void updateSubmitTokenScreenDisplay() { Runnable runnable = new Runnable() { public void run() { + GroupDataModel group = clientDataModel.getGroupDataModel(); + RoundConfiguration roundConfiguration = clientDataModel.getRoundConfiguration(); + int infrastructureEfficiency = 0; + if (roundConfiguration.isPracticeRound() || roundConfiguration.isFirstRound()) { + infrastructureEfficiency = roundConfiguration.getInitialInfrastructureEfficiency(); + } + else { + System.err.println("group was not null, efficiency is: " + group.getInfrastructureEfficiency() + " degrading by " + clientDataModel.getRoundConfiguration().getInfrastructureDegradationFactor()); + infrastructureEfficiency = group.getInfrastructureEfficiency() - roundConfiguration.getInfrastructureDegradationFactor(); + } addCenterComponent(getInvestTokensPanel()); - updateInfrastructureEfficiencyLabel(); + StringBuilder builder = new StringBuilder(); + builder.append( + String.format("<h2>The current infrastructure efficiency is %d%%, with an irrigation flow capacity of %d cubic feet per second.</h2>", + infrastructureEfficiency, + group.calculateFlowCapacity(infrastructureEfficiency) + )); + builder.append(getServerConfiguration().getInvestmentInstructions()); + tokenInstructionsEditorPane.setText(builder.toString()); getInvestedTokensTextField().requestFocusInWindow(); } }; @@ -647,18 +647,9 @@ timer = null; } else { - chatPanel.setTimeRemaining(timeRemaining); + chatPanel.setTimeLeft(timeRemaining); } } - - private void sleep() { - long prevTime = System.currentTimeMillis(); - while((System.currentTimeMillis() - prevTime) < 5000) { - - chatPanel.setEnabled(false); - } - - } }); timer.start(); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-22 20:12:59 UTC (rev 326) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-23 00:27:56 UTC (rev 327) @@ -8,7 +8,6 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.BoxLayout; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JLabel; @@ -46,19 +45,10 @@ private JPanel jPanelDownStreamWindow = null; private JPanel downloadScreenPanel = null; - private ScoreBoxPanel scoreBoxPanel; + private IrrigationClient client; - /** - * This is the default constructor - */ - public IrrigationClient client; + private JProgressBar timeLeftProgressBar; - public Dimension screenSize; - - public JProgressBar timeLeftProgressBar; - - public JProgressBar timeRemainingjProgressBar = null; - private JLabel timeRemainingjLabel = null; private JTextField timeRemainingjText; @@ -73,7 +63,7 @@ private MiddleWindowPanel middleWindowPanel; - private JLabel dashBoardLabel = null; + private JLabel gateSwitchLabel = null; private JLabel scoreBoardLabel = null; @@ -158,10 +148,10 @@ scoreBoardLabel.setBounds(new Rectangle(582,225+100+35,530,20)); scoreBoardLabel.setHorizontalAlignment(SwingConstants.CENTER); scoreBoardLabel.setText("WATER COLLECTED TO TOKENS EARNED TABLE"); - dashBoardLabel = new JLabel(); - dashBoardLabel.setBounds(new Rectangle(13,225+100+35,530,20)); - dashBoardLabel.setHorizontalAlignment(SwingConstants.CENTER); - dashBoardLabel.setText("YOUR DASHBOARD"); + gateSwitchLabel = new JLabel(); + gateSwitchLabel.setBounds(new Rectangle(13,225+100+35,530,20)); + gateSwitchLabel.setHorizontalAlignment(SwingConstants.CENTER); + gateSwitchLabel.setText("DASHBOARD"); totalContributedBandwidthTextjLabel = new JLabel(); totalContributedBandwidthTextjLabel.setBounds(new Rectangle(200, 18, 55, 17)); totalContributedBandwidthTextjLabel.setText(""); @@ -174,14 +164,10 @@ downloadScreenPanel = new JPanel(); downloadScreenPanel.setLayout(null); downloadScreenPanel.setName("downloadScreenPanel"); - downloadScreenPanel.setBackground(Color.white); + downloadScreenPanel.setBackground(Color.WHITE); downloadScreenPanel.add(getCenterPanel(),null); downloadScreenPanel.add(getTimeLeftProgressBar(), null); - // downloadScreenPanel.add(timeRemainingjLabel, null); - // downloadScreenPanel.add(timeRemainingjText,null); - // downloadScreenPanel.add(totalContributedBandwidthjLabel, null); - // downloadScreenPanel.add(totalContributedBandwidthTextjLabel, null); - downloadScreenPanel.add(dashBoardLabel, null); + downloadScreenPanel.add(gateSwitchLabel, null); downloadScreenPanel.add(scoreBoardLabel, null); } return downloadScreenPanel; @@ -209,10 +195,14 @@ return centerPanel; } - private JPanel createCanalPanel(ClientDataModel clientDataModel) { - canalPanel = new CanalPanel(clientDataModel); - canalPanel.setSize(new Dimension(1098, 123)); - + private JPanel getCanalPanel(ClientDataModel clientDataModel) { + if (canalPanel == null) { + canalPanel = new CanalPanel(clientDataModel); + canalPanel.setSize(new Dimension(1098, 123)); + } + else { + canalPanel.setClientDataModel(clientDataModel); + } return canalPanel; } @@ -227,26 +217,27 @@ jPanelUpStreamWindow.setLayout(new BorderLayout()); jPanelUpStreamWindow.setBackground(new Color(186, 226, 237)); jPanelUpStreamWindow.setBounds(new Rectangle(13, 225+100+50, 530, 326)); - jPanelUpStreamWindow.add(getGateSwitchButton(), BorderLayout.CENTER); + jPanelUpStreamWindow.add(getGateSwitchButton(), BorderLayout.NORTH); + jPanelUpStreamWindow.add(getControlPanel(), BorderLayout.CENTER); } return jPanelUpStreamWindow; } - private final static String OPEN_GATE_LABEL = "Click here to open your gate"; - private final static String CLOSE_GATE_LABEL = "Click here to close your gate"; + private final static String OPEN_GATE_LABEL = "OPEN YOUR GATE"; + private final static String CLOSE_GATE_LABEL = "CLOSE YOUR GATE"; private JButton getGateSwitchButton() { if (gateSwitchButton == null) { gateSwitchButton = new JButton(OPEN_GATE_LABEL); gateSwitchButton.setFont(new Font("sansserif", Font.TRUETYPE_FONT, 18)); - // gateSwitchButton.setPreferredSize(new Dimension(100, 100)); gateSwitchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { open = !open; - gateSwitchButton.setText( open ? CLOSE_GATE_LABEL : OPEN_GATE_LABEL ); if (open) { client.openGate(); + gateSwitchButton.setText(CLOSE_GATE_LABEL); } else { client.closeGate(); + gateSwitchButton.setText(OPEN_GATE_LABEL); } } }); @@ -255,11 +246,6 @@ } private JPanel getControlPanel() { - JPanel panel = new JPanel(); - panel.setPreferredSize(new Dimension(530, 326)); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - panel.add(getGateSwitchButton()); - JPanel bottomInformationPanel = new JPanel(); GroupLayout layout = new GroupLayout(bottomInformationPanel); bottomInformationPanel.setLayout(layout); @@ -294,8 +280,7 @@ .addComponent(getTotalTokensEarnedLabel()).addComponent(getTotalTokensEarnedTextField())); layout.setVerticalGroup(verticalGroup); - panel.add(bottomInformationPanel); - return panel; + return bottomInformationPanel; } private JTextField getWaterCollectedTextField() { @@ -405,11 +390,11 @@ private void setProgressBarColor(int timeLeft) { if (timeLeft < 10) { // timeLeftProgressBar.setForeground( Color.RED ); - timeLeftProgressBar.setBackground( Color.RED ); +// timeLeftProgressBar.setBackground( Color.RED ); // return Color.RED; } else { - timeLeftProgressBar.setBackground( Color.GREEN ); +// timeLeftProgressBar.setBackground( Color.GREEN ); } } /** @@ -422,7 +407,7 @@ String timeLeftString = String.format("%d sec", timeLeft); timeLeftProgressBar.setValue( timeLeft ); timeLeftProgressBar.setString(timeLeftString); - setProgressBarColor(timeLeft); +// setProgressBarColor(timeLeft); for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { if (clientData.isGateOpen()) { canalPanel.openGate(clientData.getPriority()); @@ -555,8 +540,7 @@ * fills in the panels depending on the priority of the client */ public void fillPanels(ClientDataModel clientDataModel) { - // TODO Auto-generated method stub - centerPanel.add(createCanalPanel(clientDataModel)); + centerPanel.add(getCanalPanel(clientDataModel)); //switch(clientGameState.getPriority()){ downloadScreenPanel.add(getJPanelUpStreamWindow(),null); Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml =================================================================== --- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 2009-10-22 20:12:59 UTC (rev 326) +++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 2009-10-23 00:27:56 UTC (rev 327) @@ -312,7 +312,7 @@ Given an existing infrastructure efficiency of 20%, if the five participants invest a <b>total of 29 additional tokens</b>, what is the new irrigation infrastructure efficiency? -<br> +(<b>Note: only enter a number, you don't need to add the % sign</b>)<br> <input type="text" name="q3" value = ""> <br><br> @@ -320,7 +320,7 @@ Given an existing infrastructure efficiency of 50%, if <b>two participants invest 10 tokens each</b> while the <b>three other participants invest 2 tokens each</b>, what is the new irrigation infrastructure efficiency? -<br> +(<b>Note: only enter a number, you don't need to add the % sign</b>)<br> <input type="text" name="q4" value = ""> <br><br> <input type="submit" name="submit" value="Submit"><br> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |