[virtualcommons-svn] SF.net SVN: virtualcommons:[316] irrigation/trunk/src/main/java/edu/asu/ commo
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-10-22 06:25:32
|
Revision: 316 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=316&view=rev Author: alllee Date: 2009-10-22 06:25:19 +0000 (Thu, 22 Oct 2009) Log Message: ----------- revived Sanket's old MainIrrigationGameWindow since there's not enough time to properly re-implement the hard-coded layout that he had set up. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java 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/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/conf/ServerConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java Added Paths: ----------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java 2009-10-22 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java 2009-10-22 06:25:19 UTC (rev 316) @@ -4,7 +4,7 @@ public class Ball { - private int size = 2; + private int size = 3; public int x; 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 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-10-22 06:25:19 UTC (rev 316) @@ -116,7 +116,6 @@ 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 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 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-22 06:25:19 UTC (rev 316) @@ -1,8 +1,10 @@ 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; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; @@ -69,9 +71,10 @@ * @return void */ private void initialize() { -// this.setPreferredSize(new Dimension(1098,150)); + this.setSize(new Dimension(1098,150)); + setLayout(new GridBagLayout()); this.setBackground(Color.WHITE); - //initializing the constructor for Gates + //initialize each gate for(int i=0;i<numberOfGates ;i++){ gate[i] = new Gate(maximumIrrigationCapacity,i); } @@ -109,8 +112,7 @@ graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); //////////////////////Animation Logic//////////////////////////// - if(enableBallAnimation == true) - { + if (enableBallAnimation) { graphics.setColor(Color.white); // int ballCounter = 0; for(int i=0;i<BALLCOUNT;i++){ 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 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-22 06:25:19 UTC (rev 316) @@ -15,6 +15,7 @@ import java.util.Map; import java.util.Properties; +import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JLabel; @@ -67,8 +68,10 @@ private InfrastructureEfficiencyChartPanel infrastructureEfficiencyChartPanel = null; private IrrigationClient client; + +// private MainIrrigationGameWindow mainIrrigationGameWindow; - private IrrigationGamePanel irrigationGamePanel; + private MainIrrigationGameWindow irrigationGamePanel; private StringBuilder instructionsBuilder = new StringBuilder(); @@ -119,7 +122,8 @@ setInstructions(getGeneralInstructions(0)); addToCardLayout(getInstructionsPanel()); - irrigationGamePanel = new IrrigationGamePanel(client); +// irrigationGamePanel = new IrrigationGamePanel(client); + irrigationGamePanel = new MainIrrigationGameWindow(client); addToCardLayout(irrigationGamePanel); addToCardLayout(getInvestTokensPanel()); addToCardLayout(getChatPanel()); @@ -549,8 +553,9 @@ if (graphPanel == null) { graphPanel = new JPanel(); graphPanel.setName("Graph panel"); - graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.X_AXIS)); + graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS)); graphPanel.add(getPieChartPanel()); + graphPanel.add(Box.createVerticalStrut(10)); contributionInformationTextArea = new JTextArea(); contributionInformationTextArea.setEditable(false); @@ -565,8 +570,8 @@ infrastructureEfficiencyChartPanel = new InfrastructureEfficiencyChartPanel(client); pieChart = new TokenInvestmentPieChartPanel(); GridLayout gridLayout = new GridLayout(); - gridLayout.setRows(2); - gridLayout.setColumns(1); + gridLayout.setRows(1); + gridLayout.setColumns(2); pieChartPanel.setLayout(gridLayout); pieChartPanel.add(infrastructureEfficiencyChartPanel); pieChartPanel.add(pieChart); 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-22 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-22 06:25:19 UTC (rev 316) @@ -1,5 +1,6 @@ package edu.asu.commons.irrigation.client; +import java.awt.Dimension; import java.util.LinkedHashMap; import java.util.Map; @@ -108,7 +109,8 @@ IrrigationClient client = new IrrigationClient(); client.initialize(); frame.setTitle("Virtual Commons Experiment Client: " + client.id); -// frame.setSize(1130, 600); + frame.setPreferredSize(new Dimension(1024, 768)); +// frame.setResizable(false); frame.getContentPane().add(client.getExperimentGameWindow()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); 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-22 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-22 06:25:19 UTC (rev 316) @@ -3,6 +3,8 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException; @@ -19,6 +21,7 @@ import javax.swing.GroupLayout.ParallelGroup; import edu.asu.commons.irrigation.server.ClientData; +import edu.asu.commons.util.HtmlEditorPane; /** * $Id$ @@ -39,7 +42,7 @@ private CanalPanel canalPanel; //this contains the CanalPanel - private JPanel upperPanel; + private JPanel centerPanel; private ScoreBoxPanel scoreBoxPanel; @@ -83,6 +86,8 @@ private JTextField irrigationCapacityTextField; + private HtmlEditorPane waterCollectedToTokensTable; + public IrrigationGamePanel(IrrigationClient client) { setName("Irrigation Game Panel"); this.client = client; @@ -102,18 +107,22 @@ setLayout(new BorderLayout()); add(topmostPanel, BorderLayout.PAGE_START); - add(getUpperPanel(), BorderLayout.CENTER); + add(getCenterPanel(), BorderLayout.CENTER); add(getBottomPanel(), BorderLayout.PAGE_END); } private JPanel getBottomPanel() { - JPanel panel = new JPanel(); - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - panel.add(getGateSwitchButton()); + JPanel bottomPanel = new JPanel(); + bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS)); + bottomPanel.add(getGateSwitchButton()); + + JPanel bottomMostPanel = new JPanel(); + bottomMostPanel.setLayout(new BoxLayout(bottomMostPanel, BoxLayout.X_AXIS)); + - JPanel bottomPanel = new JPanel(); - GroupLayout layout = new GroupLayout(bottomPanel); - bottomPanel.setLayout(layout); + JPanel bottomInformationPanel = new JPanel(); + GroupLayout layout = new GroupLayout(bottomInformationPanel); + bottomInformationPanel.setLayout(layout); layout.setAutoCreateContainerGaps(true); layout.setAutoCreateGaps(true); @@ -145,19 +154,25 @@ .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()); + + bottomMostPanel.add(bottomInformationPanel); + + bottomMostPanel.add(getWaterCollectedToTokensTable()); + + bottomPanel.add(bottomMostPanel); + return bottomPanel; + } - panel.add(bottomPanel); - return panel; + + private HtmlEditorPane getWaterCollectedToTokensTable() { + if (waterCollectedToTokensTable == null) { + waterCollectedToTokensTable = new HtmlEditorPane(); + waterCollectedToTokensTable.setEditable(false); + waterCollectedToTokensTable.setText(client.getServerConfiguration().getWaterCollectedToTokensTable()); + } + return waterCollectedToTokensTable; } - + private JTextField getWaterCollectedTextField() { if (waterCollectedTextField == null) { waterCollectedTextField = createTextField(); @@ -224,6 +239,7 @@ if (irrigationCapacityLabel == null) { irrigationCapacityLabel = new JLabel(); irrigationCapacityLabel.setLabelFor(getIrrigationCapacityTextField()); + irrigationCapacityLabel.setFont(new Font("sansserif", Font.BOLD, 16)); } return irrigationCapacityLabel; } @@ -235,41 +251,22 @@ return irrigationCapacityTextField; } - // private JPanel getMainIrrigationPanel() { - // if (mainIrrigationPanel == null) { - // irrigationCapacityLabel = new JLabel(); - // irrigationCapacityLabel.setText("Irrigation capacity: "); - // mainIrrigationPanel = new JPanel(); - // - // - // mainIrrigationPanel.setName("downloadScreenPanel"); - // mainIrrigationPanel.setBackground(Color.white); - // mainIrrigationPanel.add(getUpperPanel(),null); - // mainIrrigationPanel.add(timeRemainingLabel, null); - // mainIrrigationPanel.add(timeRemainingTextField,null); - // - // mainIrrigationPanel.add(irrigationCapacityLabel, null); - // mainIrrigationPanel.add(maximumAvailableFlowCapacityLabel, null); - // mainIrrigationPanel.add(dashBoardLabel, null); - // mainIrrigationPanel.add(scoreBoardLabel, null); - // } - // return mainIrrigationPanel; - // } - - private JPanel getUpperPanel() { - if (upperPanel == null) { - upperPanel = new JPanel(); - upperPanel.setLayout(new BorderLayout()); - upperPanel.add(getScoreBoxPanel(), BorderLayout.PAGE_END); + private JPanel getCenterPanel() { + if (centerPanel == null) { + centerPanel = new JPanel(); +// centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); +// centerPanel.setLayout(new BorderLayout()); +// centerPanel.add(getMiddleWindowPanel(), BorderLayout.PAGE_END); +// upperPanel.add(getScoreBoxPanel(), BorderLayout.PAGE_END); } - return upperPanel; + return centerPanel; } private JButton getGateSwitchButton() { if (gateSwitchButton == null) { gateSwitchButton = new JButton("Open gate"); - gateSwitchButton.setPreferredSize(new Dimension(100, 100)); +// gateSwitchButton.setPreferredSize(new Dimension(100, 100)); gateSwitchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { open = !open; @@ -287,8 +284,12 @@ } private JPanel createCanalPanel() { + JPanel panel = new JPanel(); canalPanel = new CanalPanel(clientDataModel); - return canalPanel; + canalPanel.setSize(new Dimension(1098, 123)); + panel.add(canalPanel); + panel.setBounds(new Rectangle(13, 64, 1098, 123)); + return panel; } // private IrrigationGameWindow getIrrigationGameWindow() { @@ -364,16 +365,11 @@ SwingUtilities.invokeLater(new Runnable() { public void run() { int timeLeft = clientDataModel.getTimeLeft(); - int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); String timeLeftString = String.format("%d sec", timeLeft); timeLeftProgressBar.setValue( timeLeft ); timeLeftProgressBar.setString(timeLeftString); timeLeftProgressBar.setForeground( getProgressBarColor(timeLeft) ); - irrigationCapacityLabel.setText( - String.format("Irrigation capacity: %d cubic feet per second (cfps)", - irrigationCapacity)); for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { - System.err.println("changing canal gate for client: " + clientData.getPriority() + ":" + clientData.isGateOpen()); if (clientData.isGateOpen()) { canalPanel.openGate(clientData.getPriority()); } @@ -389,8 +385,8 @@ tokensNotInvestedTextField.setText("" + clientData.getUninvestedTokens()); tokensEarnedTextField.setText("" + clientData.getTokensEarnedFromWaterCollected()); totalTokensEarnedTextField.setText("" + clientData.getAllTokensEarnedThisRound()); - getScoreBoxPanel().update(clientDataModel); -// getMiddleWindowPanel().update(clientDataModel); +// getScoreBoxPanel().update(clientDataModel); + getMiddleWindowPanel().update(clientDataModel); } @@ -411,7 +407,7 @@ gateSwitchButton.setText("Open gate"); if (canalPanel != null) { System.err.println("Removing canal panel"); - upperPanel.remove(canalPanel); + centerPanel.removeAll(); canalPanel.endRound(); } System.err.println("ending round for canal panel"); @@ -437,13 +433,21 @@ /** - * fills in the panels depending on the priority of the client + * Updates all GUI related components that are dependent on the client data model being properly initialized + * with the GroupDataModel, RoundConfiguration, ClientData, etc. */ public void startRound() { open = false; - upperPanel.add(createCanalPanel(), BorderLayout.CENTER); - getScoreBoxPanel().initialize(clientDataModel); + centerPanel.add(createCanalPanel(), null); + centerPanel.add(getMiddleWindowPanel(), null); +// getWaterCollectedToTokensTable().setText(clientDataModel.getServerConfiguration().getWaterCollectedToTokensTable()); +// getScoreBoxPanel().initialize(clientDataModel); getMiddleWindowPanel().initialize(clientDataModel); + int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + irrigationCapacityLabel.setText( + String.format("Irrigation capacity: %d cubic feet per second (cfps)", + irrigationCapacity)); + revalidate(); // mainIrrigationPanel.add(getJPanelUpStreamWindow(),null); // mainIrrigationPanel.add(getJPanelDownStreamWindow(),null); Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-22 06:25:19 UTC (rev 316) @@ -0,0 +1,582 @@ +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.Rectangle; +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; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +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; +import edu.asu.commons.util.HtmlEditorPane; + + + +public class MainIrrigationGameWindow extends JPanel { + + //public ChartWindowPanelTokenBandwidth xySeriesDemo; + + public IrrigationGameWindow controlPanel; + + //public ActivitySummaryPanel activitySummaryWindow; + + public CanalPanel canalPanel; + + private static final long serialVersionUID = 1L; + + private JPanel jPanelMain = null; + //this contains the CanalPanel + private JPanel centerPanel = null; + //this contains the upstream and downstream Panel + private JPanel jPanelUpStreamWindow = null; + private JPanel jPanelDownStreamWindow = null; + private JPanel downloadScreenPanel = null; + + private ScoreBoxPanel scoreBoxPanel; + + /** + * This is the default constructor + */ + public IrrigationClient client; + + public Dimension screenSize; + + public JProgressBar timeLeftProgressBar; + + public JProgressBar timeRemainingjProgressBar = null; + + private JLabel timeRemainingjLabel = null; + + private JTextField timeRemainingjText; + + private JLabel priorityjLabel = null; + + private JLabel totalContributedBandwidthjLabel = null; + + private JLabel totalContributedBandwidthTextjLabel = null; + + private ClientDataModel clientDataModel; // @jve:decl-index=0: + + private MiddleWindowPanel middleWindowPanel; + + private JLabel dashBoardLabel = null; + + private JLabel scoreBoardLabel = null; + + private JButton gateSwitchButton; + + protected boolean open; + + private JTextField waterCollectedTextField; + + private JLabel waterCollectedLabel; + + private JTextField tokensNotInvestedTextField; + + private JLabel tokensNotInvestedLabel; + + private JTextField tokensEarnedTextField; + + private JLabel tokensEarnedLabel; + + private JTextField totalTokensEarnedTextField; + + private JLabel totalTokensEarnedLabel; + + private JLabel irrigationCapacityLabel; + + private JTextField irrigationCapacityTextField; + + private HtmlEditorPane waterCollectedToTokensTable; + + private JScrollPane waterCollectedToTokensScrollPane; + + public MainIrrigationGameWindow(IrrigationClient client) { + super(); + this.client = client; + setName("main irrigation game window"); + initialize(); + } + /** + * This method initializes this + * + * @return void + */ + + private void initialize() { + timeRemainingjLabel = new JLabel(); + timeRemainingjLabel.setBounds(new Rectangle(469, 39, 146, 23)); + timeRemainingjLabel.setHorizontalAlignment(SwingConstants.CENTER); + timeRemainingjLabel.setHorizontalTextPosition(SwingConstants.CENTER); + timeRemainingjLabel.setText("TIME REMAINING"); + timeRemainingjText = new JTextField(); + timeRemainingjText.setEditable(false); + timeRemainingjText.setBounds(new Rectangle(620, 39, 61, 23)); + timeRemainingjText.setText("50 sec"); + timeRemainingjText.setBackground(Color.white); + timeRemainingjText.setFont(new Font("serif", Font.BOLD, 14)); + timeRemainingjText.setForeground(new Color(102, 204, 255)); + timeRemainingjText.setHorizontalAlignment(SwingConstants.CENTER); + + this.setLayout(new BorderLayout(4,4)); + this.setSize(1130, 558); + this.add(getJPanelMain(),null); + + } + + private JPanel getJPanelMain() { + // TODO Auto-generated method stub + if(jPanelMain == null){ + jPanelMain = new JPanel(); + jPanelMain.setLayout(new BorderLayout(4,4)); + jPanelMain.setBackground(Color.WHITE); + jPanelMain.setForeground(Color.BLACK); + jPanelMain.add(getIrrigationCapacityLabel(), BorderLayout.NORTH); + jPanelMain.add(getDownloadScreenPanel(), BorderLayout.CENTER); + return jPanelMain; + } + return jPanelMain; + } + + private JPanel getDownloadScreenPanel() { + if(downloadScreenPanel == null){ + scoreBoardLabel = new JLabel(); + 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"); + totalContributedBandwidthTextjLabel = new JLabel(); + totalContributedBandwidthTextjLabel.setBounds(new Rectangle(200, 18, 55, 17)); + totalContributedBandwidthTextjLabel.setText(""); + totalContributedBandwidthjLabel = new JLabel(); + totalContributedBandwidthjLabel.setBounds(new Rectangle(19, 17, 170, 16)); + totalContributedBandwidthjLabel.setText("Total Water Availability Capacity: "); + priorityjLabel = new JLabel(); + priorityjLabel.setBounds(new Rectangle(780, 16, 44, 16)); + priorityjLabel.setText(""); + downloadScreenPanel = new JPanel(); + downloadScreenPanel.setLayout(null); + downloadScreenPanel.setName("downloadScreenPanel"); + 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(scoreBoardLabel, null); + } + return downloadScreenPanel; + } + + private JProgressBar getTimeLeftProgressBar() { + if (timeLeftProgressBar == null) { + timeLeftProgressBar = new JProgressBar(0, 50); + timeLeftProgressBar.setBounds(new Rectangle(360, 15, 370, 17)); + timeLeftProgressBar.setStringPainted(true); + } + return timeLeftProgressBar; + } + /** + * This method initializes jPanel + * + * @return javax.swing.JPanel + */ + private JPanel getCenterPanel() { + if (centerPanel == null) { + centerPanel = new JPanel(); + centerPanel.setLayout(null); + centerPanel.setBounds(new Rectangle(13, 64, 1098, 123)); + } + return centerPanel; + } + + private JPanel createCanalPanel(ClientDataModel clientDataModel) { + canalPanel = new CanalPanel(clientDataModel); + canalPanel.setSize(new Dimension(1098, 123)); + + return canalPanel; + } + + /** + * This method initializes jPanel1 + * + * @return javax.swing.JPanel + */ + private JPanel getJPanelUpStreamWindow() { + if (jPanelUpStreamWindow == null) { + jPanelUpStreamWindow = new JPanel(); + 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); + } + return jPanelUpStreamWindow; + } + + private JButton getGateSwitchButton() { + if (gateSwitchButton == null) { + gateSwitchButton = new JButton("Open gate"); + // gateSwitchButton.setPreferredSize(new Dimension(100, 100)); + gateSwitchButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + open = !open; + gateSwitchButton.setText( open ? "Close gate" : "Open gate"); + if (open) { + client.openGate(); + } + else { + client.closeGate(); + } + } + }); + } + return gateSwitchButton; + } + + 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); + layout.setAutoCreateContainerGaps(true); + layout.setAutoCreateGaps(true); + + GroupLayout.SequentialGroup horizontalGroup = layout.createSequentialGroup(); + ParallelGroup labelsGroup = layout.createParallelGroup(); + labelsGroup.addComponent(getWaterCollectedLabel()).addComponent(getTokensNotInvestedLabel()).addComponent(getTokensEarnedLabel()).addComponent(getTotalTokensEarnedLabel()); + + horizontalGroup.addGroup(labelsGroup); + + ParallelGroup textFieldGroup = layout.createParallelGroup(); + textFieldGroup.addComponent(getWaterCollectedTextField()); + 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(getWaterCollectedLabel()).addComponent(getWaterCollectedTextField())); + + 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); + panel.add(bottomInformationPanel); + return panel; + } + + private JTextField getWaterCollectedTextField() { + if (waterCollectedTextField == null) { + waterCollectedTextField = createTextField(); + } + return waterCollectedTextField; + } + + private JTextField createTextField() { + JTextField textField = new JTextField(); + textField.setEditable(false); + textField.setBackground(Color.LIGHT_GRAY); + return textField; + } + + private JLabel getWaterCollectedLabel() { + if (waterCollectedLabel == null) { + waterCollectedLabel = new JLabel("Total water applied to your field: "); + } + return waterCollectedLabel; + } + + private JTextField getTokensNotInvestedTextField() { + if (tokensNotInvestedTextField == null) { + tokensNotInvestedTextField = createTextField(); + } + return tokensNotInvestedTextField; + } + private JLabel getTokensNotInvestedLabel() { + if (tokensNotInvestedLabel == null) { + tokensNotInvestedLabel = new JLabel("Tokens not invested: "); + } + return tokensNotInvestedLabel; + } + + private JTextField getTokensEarnedTextField() { + if (tokensEarnedTextField == null) { + tokensEarnedTextField = createTextField(); + } + return tokensEarnedTextField; + } + private JLabel getTokensEarnedLabel() { + if (tokensEarnedLabel == null) { + tokensEarnedLabel = new JLabel("Tokens earned by crop production: "); + } + return tokensEarnedLabel; + } + + private JTextField getTotalTokensEarnedTextField() { + if (totalTokensEarnedTextField == null) { + totalTokensEarnedTextField = createTextField(); + } + return totalTokensEarnedTextField; + + } + + private JLabel getTotalTokensEarnedLabel() { + if (totalTokensEarnedLabel == null) { + totalTokensEarnedLabel = new JLabel("Total tokens earned this round: "); + } + return totalTokensEarnedLabel; + } + + private JLabel getIrrigationCapacityLabel() { + if (irrigationCapacityLabel == null) { + irrigationCapacityLabel = new JLabel(); + irrigationCapacityLabel.setLabelFor(getIrrigationCapacityTextField()); + irrigationCapacityLabel.setFont(new Font("sansserif", Font.BOLD, 16)); + } + return irrigationCapacityLabel; + } + + private JTextField getIrrigationCapacityTextField() { + if (irrigationCapacityTextField == null) { + irrigationCapacityTextField = createTextField(); + } + return irrigationCapacityTextField; + } + /** + * This method initializes jPanel3 + * summary scoreboard + * @return javax.swing.JPanel + */ + private JPanel getJPanelDownStreamWindow() { + if (jPanelDownStreamWindow == null) { + jPanelDownStreamWindow = new JPanel(); + jPanelDownStreamWindow.setLayout(new BorderLayout()); + jPanelDownStreamWindow.setBackground(new Color(186, 226, 237)); + jPanelDownStreamWindow.setBounds(new Rectangle(582, 225 + 100+50, 530, 326)); + jPanelDownStreamWindow.add(getWaterCollectedToTokensTable(),BorderLayout.CENTER); + } + return jPanelDownStreamWindow; + } + + private JScrollPane getWaterCollectedToTokensTable() { + if (waterCollectedToTokensTable == null) { + waterCollectedToTokensTable = new HtmlEditorPane(); + waterCollectedToTokensTable.setEditable(false); + waterCollectedToTokensTable.setText(client.getServerConfiguration().getWaterCollectedToTokensTable()); + waterCollectedToTokensScrollPane = new JScrollPane(waterCollectedToTokensTable); + waterCollectedToTokensScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + } + return waterCollectedToTokensScrollPane; + } + + private Color getProgressBarColor(int timeLeft) { + if (timeLeft < 10) { + return Color.RED; + } + return Color.BLACK; + } + /** + * Should be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. + */ + public void updateClientStatus(final ClientDataModel clientDataModel) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + int timeLeft = clientDataModel.getTimeLeft(); + String timeLeftString = String.format("%d sec", timeLeft); + timeLeftProgressBar.setValue( timeLeft ); + timeLeftProgressBar.setString(timeLeftString); + timeLeftProgressBar.setForeground( getProgressBarColor(timeLeft) ); + for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { + if (clientData.isGateOpen()) { + canalPanel.openGate(clientData.getPriority()); + } + else if(clientData.isPaused()){ + canalPanel.closeGate(clientData.getPriority()); + } + else if(clientData.isGateClosed()){ + canalPanel.closeGate(clientData.getPriority()); + } + } + ClientData clientData = clientDataModel.getClientData(); + getWaterCollectedTextField().setText("" + clientData.getWaterCollected()); + getTokensNotInvestedTextField().setText("" + clientData.getUninvestedTokens()); + getTokensEarnedTextField().setText("" + clientData.getTokensEarnedFromWaterCollected()); + getTotalTokensEarnedTextField().setText("" + clientData.getAllTokensEarnedThisRound()); + // getScoreBoxPanel().update(clientDataModel); + getMiddleWindowPanel().update(clientDataModel); + + } + + }); + } + // //this event gets called every second in the experiment. + // public void updateSendFileProgress(final ClientDataModel clientGameState) { + // // TODO Auto-generated method stub + // ////////////new code//////////////////////////////////////////////////////////// + // Runnable createGuiRunnable = new Runnable(){ + // public void run() { + // for(final ClientData clientData : clientGameState.getClientDataMap().values()){ + // timeRemainingjText.setText((new Integer(((int)clientGameState.getTimeLeft()))).toString()+"sec"); + // timeRemainingjProgressBar.setValue((int)clientGameState.getTimeLeft()); + // totalContributedBandwidthTextjLabel.setText((new Double(clientData.getGroupDataModel().getMaximumAvailableFlowCapacity())).toString()+" cubic feet per second (cfps)"); + // middleWindowPanel.update(clientGameState); + // if(clientGameState.getPriority() == clientData.getPriority()){ + // controlPanel.update(clientData); + // //per parameter score panel + //// scoreBoxPanel.update(clientData); + // } + // else{ + //// scoreBoxPanel.update(clientData); + // } + // if(clientData.isDownloading() == true){ + // upperPanel.openGates(clientData.getPriority()); + // + // } + // else if(clientData.isPaused() == true){ + // upperPanel.closeGates(clientData.getPriority()); + // } + // if(clientData.isStopped() == true){ + // upperPanel.closeGates(clientData.getPriority()); + // } + // } + // } + // + // }; + // try { + // SwingUtilities.invokeAndWait(createGuiRunnable); + // } catch (InterruptedException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (InvocationTargetException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + // } + + /** + * changes the file button color to red when started downloading + * @param file + */ + + /* + * updates the irrigation window + */ + public void endRound() { + System.out.println("End of round."); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + // controlPanel.endRound(); + centerPanel.removeAll(); + canalPanel.endRound(); + gateSwitchButton.setText("Open gate"); + } + + }); + open = false; + } + + /** + * assigns the priority to the window and prepares the irrigationWindowMap + */ + public void setClientDataModel(final ClientDataModel clientDataModel) { + this.clientDataModel = clientDataModel; + //Here a map is created with the map consisting of the + //irrigation window as the value and the priority value as the key. This is handled here , because + //the event contains the priority for every client, and the priority can act as a unique key for the + //game window. + + //checking the client priority and assigning the activity summary and client panel to the + //doownloadScreenPanel + fillPanels(clientDataModel); + + //This is helpful, if we need to scale the game to more than two users. We can declare + //more panels like middleStream Window, etc and add them in this switch case statement + + //case 2 : irrigationWindowMap.put(new Integer(clientData.getPriority()), middleStreamWindow); + } + + public void startRound() { + open = false; + getMiddleWindowPanel().initialize(clientDataModel); + int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + irrigationCapacityLabel.setText( + String.format("Irrigation capacity: %d cubic feet per second (cfps)", + irrigationCapacity)); + + revalidate(); + // mainIrrigationPanel.add(getJPanelUpStreamWindow(),null); + // mainIrrigationPanel.add(getJPanelDownStreamWindow(),null); + //adding the in between Panel + // mainIrrigationPanel.add(getJPanelMiddleWindow(),null); + } + + + + + + /** + * 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)); + //switch(clientGameState.getPriority()){ + + downloadScreenPanel.add(getJPanelUpStreamWindow(),null); + downloadScreenPanel.add(getJPanelDownStreamWindow(),null); + //adding the in between Panel + downloadScreenPanel.add(getMiddleWindowPanel(),null); + /*case 0 : downloadScreenPanel.add(getJPanelUpStreamWindow(0),null); + downloadScreenPanel.add(getJPanelDownStreamWindow(0),null); + //Assigning the Priorities on the Priority Label + break; + + case 1 : downloadScreenPanel.add(getJPanelUpStreamWindow(1),null); + downloadScreenPanel.add(getJPanelDownStreamWindow(1),null); + //Assigning the Priorities on the Priority Label + break; + */ } + + private MiddleWindowPanel getMiddleWindowPanel() { + // TODO Auto-generated method stub + if(middleWindowPanel == null) { + middleWindowPanel = new MiddleWindowPanel(); + } + return middleWindowPanel; + } + + public ClientDataModel getClientDataModel() { + return clientDataModel; + } +} \ No newline at end of file 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-22 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-22 06:25:19 UTC (rev 316) @@ -23,11 +23,11 @@ private JLabel positionText; - private JLabel currentBandwidthText; + private JLabel availableFlowCapacityLabel; - private JLabel waterUsedTextField; + private JLabel waterCollectedLabel; - private JLabel totalTokensEarnedTextField; + private JLabel tokensCollectedLabel; private int priority; @@ -44,33 +44,33 @@ 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); + this.add(getPositionLabel(),null); + this.add(getWaterCollectedLabel(),null); + this.add(getAvailableFlowCapacityLabel(),null); + this.add(getTokensCollectedLabel(),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(""); + private JLabel getTokensCollectedLabel() { + if(tokensCollectedLabel == null){ + tokensCollectedLabel = new JLabel(); + tokensCollectedLabel.setBounds(new Rectangle(5,50+32+10+20+10+20+10+20+10,30,20)); + tokensCollectedLabel.setText(""); } - return totalTokensEarnedTextField; + return tokensCollectedLabel; } - private JLabel getCurrentBandwidth() { - if(currentBandwidthText == null){ - currentBandwidthText = new JLabel(); - currentBandwidthText.setBounds(new Rectangle(5,50+32+10+20+10,30,20)); - currentBandwidthText.setText(""); + private JLabel getAvailableFlowCapacityLabel() { + if(availableFlowCapacityLabel == null){ + availableFlowCapacityLabel = new JLabel(); + availableFlowCapacityLabel.setBounds(new Rectangle(5,50+32+10+20+10,30,20)); + availableFlowCapacityLabel.setText(""); } - return currentBandwidthText; + return availableFlowCapacityLabel; } - private JLabel getPositionText() { + private JLabel getPositionLabel() { if (positionText == null){ positionText = new JLabel(clientData.getPriorityString()); positionText.setBounds(new Rectangle(5,50+32+10,30,20)); @@ -79,19 +79,19 @@ } - private JLabel getWaterUsedTextField() { - if(waterUsedTextField == null){ - waterUsedTextField = new JLabel("0"); - waterUsedTextField.setBounds(new Rectangle(5,50+32+10+20+10+20+10,30,20)); + private JLabel getWaterCollectedLabel() { + if(waterCollectedLabel == null){ + waterCollectedLabel = new JLabel("0"); + waterCollectedLabel.setBounds(new Rectangle(5,50+32+10+20+10+20+10,30,20)); } - return waterUsedTextField; + return waterCollectedLabel; } public void update(ClientData clientData) { this.clientData = clientData; - currentBandwidthText.setText("" + clientData.getAvailableFlowCapacity()); - waterUsedTextField.setText("" + clientData.getWaterCollected()); - totalTokensEarnedTextField.setText("" + clientData.getAllTokensEarnedThisRound()); + availableFlowCapacityLabel.setText("" + clientData.getAvailableFlowCapacity()); + waterCollectedLabel.setText("" + clientData.getWaterCollected()); + tokensCollectedLabel.setText("" + clientData.getAllTokensEarnedThisRound()); 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-22 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java 2009-10-22 06:25:19 UTC (rev 316) @@ -1,15 +1,10 @@ -/** - * - */ package edu.asu.commons.irrigation.client; 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; import javax.swing.JPanel; @@ -17,23 +12,23 @@ import edu.asu.commons.irrigation.server.ClientData; /** - * @author Sanket - * + * $Id$ + * + * + * @author Allen Lee, Sanket Joshi */ public class MiddleWindowPanel extends JPanel { 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>(); private List<MiddleScorePanel> middleScorePanels = new ArrayList<MiddleScorePanel>(); - JLabel positionLabel; - JLabel availableBandwidthLabel; - JLabel filesDownLoadedLabel; - JLabel tokensCollectedLabel; + private JLabel positionLabel; + private JLabel availableWaterLabel; + private JLabel waterCollectedLabel; + private JLabel tokensEarnedLabel; + private JLabel tokensNotInvestedLabel; + private JLabel totalTokensEarnedLabel; public MiddleWindowPanel() { @@ -42,30 +37,32 @@ this.setSize(new Dimension(1093,200)); positionLabel = new JLabel(); - positionLabel.setBounds(new Rectangle(80,50+32+10,150,20)); + positionLabel.setBounds(new Rectangle(30,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"); + availableWaterLabel = new JLabel(); + availableWaterLabel.setBounds(new Rectangle(30,50+32+10+20+10,200,20)); + availableWaterLabel.setText("Available water per second"); - filesDownLoadedLabel = new JLabel(); - filesDownLoadedLabel.setBounds(new Rectangle(80,50+32+10+20+10+20+10, 150,20)); - filesDownLoadedLabel.setText("Crops Grown"); + waterCollectedLabel = new JLabel(); + waterCollectedLabel.setBounds(new Rectangle(30,50+32+10+20+10+20+10, 150,20)); + waterCollectedLabel.setText("Water collected"); - tokensCollectedLabel = new JLabel(); - tokensCollectedLabel.setBounds(new Rectangle(80,50+32+10+20+10+20+10+20+10, 150,20)); - tokensCollectedLabel.setText("Tokens Collected"); + tokensEarnedLabel = new JLabel(); + tokensEarnedLabel.setBounds(new Rectangle(30,50+32+10+20+10+20+10+20+10, 200,20)); + tokensEarnedLabel.setText("Tokens earned "); this.add(positionLabel, null); - this.add(availableBandwidthLabel, null); - this.add(filesDownLoadedLabel, null); - this.add(tokensCollectedLabel, null); + this.add(availableWaterLabel, null); + this.add(waterCollectedLabel, null); + this.add(tokensEarnedLabel, null); } public void initialize(ClientDataModel clientDataModel) { - removeAll(); - middleScorePanels.clear(); + for (MiddleScorePanel panel: middleScorePanels) { + remove(panel); + } + middleScorePanels.clear(); for (ClientData clientData : clientDataModel.getClientDataSortedByPriority()) { int priority = clientData.getPriority(); MiddleScorePanel middleScorePanel = new MiddleScorePanel(clientDataModel.getPriority(), clientData); @@ -76,8 +73,6 @@ } 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/conf/ServerConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-22 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-22 06:25:19 UTC (rev 316) @@ -145,6 +145,10 @@ "general-instructions"+pageNumber, "<b>No instructions available for this round</b>"); } + + public String getWaterCollectedToTokensTable() { + return assistant.getProperty("water-collected-to-tokens-table"); + } public String getFinalInstructions() { return assistant.getProperty("final-instructions", "<b>The experiment is now over. Thanks for participating!</b>"); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java 2009-10-22 00:04:03 UTC (rev 315) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java 2009-10-22 06:25:19 UTC (rev 316) @@ -4,8 +4,12 @@ import edu.asu.commons.net.Identifier; /** - * + * $Id$ + * + * Signifies that a client opened a gate. * + * @author Allen Lee + * @revision $Rev$ */ public class OpenGateEvent extends AbstractPersistableEvent { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |