Thread: [virtualcommons-svn] SF.net SVN: virtualcommons:[300] irrigation/trunk/src/main/java/edu/asu/ commo
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-10-17 22:23:31
|
Revision: 300 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=300&view=rev Author: alllee Date: 2009-10-17 22:23:23 +0000 (Sat, 17 Oct 2009) Log Message: ----------- minor hygiene, referring to client data model instead of client primarily Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.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 Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-16 23:02:53 UTC (rev 299) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-17 22:23:23 UTC (rev 300) @@ -10,6 +10,7 @@ import edu.asu.commons.event.EventChannel; import edu.asu.commons.experiment.DataModel; import edu.asu.commons.irrigation.conf.RoundConfiguration; +import edu.asu.commons.irrigation.conf.ServerConfiguration; import edu.asu.commons.irrigation.events.ClientUpdateEvent; import edu.asu.commons.irrigation.events.RoundStartedEvent; import edu.asu.commons.irrigation.server.ClientData; @@ -34,8 +35,6 @@ private RoundConfiguration roundConfiguration; - private int priority = 0; - private int timeLeft = 0; public ClientDataModel(EventChannel channel, IrrigationClient client) { @@ -60,15 +59,8 @@ setTimeLeft( (int) (getRoundConfiguration().getRoundDuration().getDelta() / 1000L) ); } - /** - * Setting priority for this client. - */ - public void setPriority(int priority){ - this.priority = priority; - } - public int getPriority(){ - return priority; + return getClientData().getPriority(); } public void update(ClientUpdateEvent clientUpdateEvent) { @@ -92,6 +84,10 @@ this.roundConfiguration = roundConfiguration; } + public ServerConfiguration getServerConfiguration() { + return roundConfiguration.getParentConfiguration(); + } + public void setGroupDataModel(GroupDataModel groupDataModel) { this.groupDataModel = groupDataModel; setRoundConfiguration(groupDataModel.getRoundConfiguration()); 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-16 23:02:53 UTC (rev 299) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-17 22:23:23 UTC (rev 300) @@ -140,7 +140,7 @@ instructionsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); instructionsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); // create a quiz listener and then initialize the instructions. - instructionsEditorPane.setActionListener(createQuizListener(client.getServerConfiguration())); + instructionsEditorPane.setActionListener(createQuizListener(clientDataModel.getServerConfiguration())); instructionsEditorPane.setCaretPosition(0); setInstructions(getGeneralInstructions(0)); @@ -181,14 +181,14 @@ } public void updateInfrastructureEfficiencyLabel() { - GroupDataModel group = client.getClientDataModel().getGroupDataModel(); - RoundConfiguration roundConfiguration = client.getRoundConfiguration(); + 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 " + client.getRoundConfiguration().getInfrastructureDegradationFactor()); + 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); @@ -399,7 +399,7 @@ animationPanel.add(canalAnimationPanel,BorderLayout.CENTER); animationInstructionsEditorPane = createInstructionsEditorPane(); animationInstructionsScrollPane = new JScrollPane(animationInstructionsEditorPane); - animationInstructionsEditorPane.setActionListener(createQuizListener(client.getServerConfiguration())); + animationInstructionsEditorPane.setActionListener(createQuizListener(clientDataModel.getServerConfiguration())); animationInstructionsEditorPane.setCaretPosition(0); animationPanel.add(animationInstructionsScrollPane, BorderLayout.SOUTH); //setInstructions(getGeneralInstructions(11)); @@ -421,7 +421,8 @@ * @return */ private String getGeneralInstructions(int pageNumber, int pagesTraversed) { - return client.getServerConfiguration().getGeneralInstructions(pageNumber, pagesTraversed, client.getClientDataModel().getPriority()); + + return clientDataModel.getServerConfiguration().getGeneralInstructions(pageNumber, pagesTraversed, client.getClientDataModel().getPriority()); } private String getGeneralInstructions(int pageNumber) { @@ -623,11 +624,11 @@ allClientData[3].getTotalTokensEarned(), allClientData[4].getTotalTokensEarned(), - (float)allClientData[0].getRoundConfiguration().getDollarsPerToken()*allClientData[0].getTotalTokensEarned(), - (float)allClientData[1].getRoundConfiguration().getDollarsPerToken()*allClientData[1].getTotalTokensEarned(), - (float)allClientData[2].getRoundConfiguration().getDollarsPerToken()*allClientData[2].getTotalTokensEarned(), - (float)allClientData[3].getRoundConfiguration().getDollarsPerToken()*allClientData[3].getTotalTokensEarned(), - (float)allClientData[4].getRoundConfiguration().getDollarsPerToken()*allClientData[4].getTotalTokensEarned() + (float)dollarsPerToken*allClientData[0].getTotalTokensEarned(), + (float)dollarsPerToken*allClientData[1].getTotalTokensEarned(), + (float)dollarsPerToken*allClientData[2].getTotalTokensEarned(), + (float)dollarsPerToken*allClientData[3].getTotalTokensEarned(), + (float)dollarsPerToken*allClientData[4].getTotalTokensEarned() /* event.getClientData().getContributedTokens(),otherClientData.getContributedTokens(), @@ -647,12 +648,12 @@ (float)dollarsPerToken*clientData.getTotalTokens() + client.getServerConfiguration().getShowUpPayment() )); //append the added practice round instructions - if(client.getRoundConfiguration().isPracticeRound()) { + if(clientDataModel.getRoundConfiguration().isPracticeRound()) { instructionsBuilder.append(" However, this is a practice round and the earnings mentioned are only for illustrative purposes " + "and will not count towards your actual payments"); } else if (event.isLastRound()) { - instructionsBuilder.append(client.getServerConfiguration().getFinalInstructions()); + instructionsBuilder.append(clientDataModel.getServerConfiguration().getFinalInstructions()); } setInstructions(instructionsBuilder.toString()); } @@ -669,7 +670,6 @@ }); } - private ActionListener createQuizListener(final ServerConfiguration configuration) { return new ActionListener() { public void actionPerformed(ActionEvent e){ @@ -816,13 +816,13 @@ + "\n\nActual total flow capacity: " + df.format(clientData.getGroupDataModel().getMaximumAvailableFlowCapacity()) + " cubic feet per second \n\n" + "\n\nMaximum tokens that could have been contributed: " - + client.getRoundConfiguration().getMaximumTotalInvestedTokens() + + clientDataModel.getRoundConfiguration().getMaximumTotalInvestedTokens() + "\n\nTotal tokens contributed: " + totalContributedTokensPerGroup + "\n\nYour token contribution: " + clientData.getInvestedTokens() + "\n\nTotal flow capacity that could have been generated: " - + client.getRoundConfiguration().getMaximumCanalFlowCapacity() + + clientDataModel.getRoundConfiguration().getMaximumCanalFlowCapacity() + " cubic feet per second"; @@ -853,7 +853,7 @@ private JPanel getPieChartPanel() { if (pieChartPanel == null) { - ClientData clientData = client.getClientDataModel().getClientData(); + ClientData clientData = clientDataModel.getClientData(); pieChartPanel = new JPanel(); xySeriesDemo = new ChartWindowPanelTokenBandwidth(client); xySeriesDemo.setVisible(true); 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-16 23:02:53 UTC (rev 299) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-17 22:23:23 UTC (rev 300) @@ -161,7 +161,7 @@ channel.add(this, new EventTypeProcessor<RegistrationEvent>(RegistrationEvent.class) { public void handle(RegistrationEvent event) { RoundConfiguration configuration = event.getRoundConfiguration(); - setRoundConfiguration(configuration); + clientDataModel.setRoundConfiguration(configuration); experimentGameWindow.updateRoundInstructions(configuration); } }); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-07 22:59:04
|
Revision: 355 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=355&view=rev Author: alllee Date: 2009-11-07 22:58:44 +0000 (Sat, 07 Nov 2009) Log Message: ----------- more refactoring / cleanup in preparation for http://opensource.asu.edu/jira/browse/COMMONS-5 Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java Removed Paths: ------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 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-11-04 20:24:26 UTC (rev 354) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-11-07 22:58:44 UTC (rev 355) @@ -1,8 +1,6 @@ package edu.asu.commons.irrigation.client; import java.awt.Dimension; -import java.util.LinkedHashMap; -import java.util.Map; import javax.swing.JFrame; import javax.swing.SwingUtilities; @@ -26,7 +24,6 @@ import edu.asu.commons.irrigation.events.RegistrationEvent; import edu.asu.commons.irrigation.events.RoundStartedEvent; import edu.asu.commons.irrigation.events.ShowInstructionsRequest; -import edu.asu.commons.irrigation.server.ClientData; import edu.asu.commons.net.ClientDispatcher; import edu.asu.commons.net.DispatcherFactory; import edu.asu.commons.net.Identifier; @@ -34,6 +31,8 @@ /** * $Id$ * + * Irrigation client main entry point / controller that ties together the GUI component, networking logic via the Dispatcher, + * and general game logic. * * @author <a href='mailto:All...@as...'>Allen Lee</a>, Sanket Joshi * @version $Rev$ @@ -52,18 +51,12 @@ private Identifier id; - // private MainIrrigationGameWindow mainIrrigationGameWindow; - private ExperimentGameWindow experimentGameWindow; - IrrigationGameWindow currentWindow = null; - private ClientDataModel clientDataModel; private final EventChannel channel; - Map<Identifier, ClientData> updatedClientDataMap = new LinkedHashMap<Identifier, ClientData>(); - private IrrigationClient() { this(EventChannelFactory.create(), new ServerConfiguration()); } @@ -83,15 +76,14 @@ } public void connect() { - System.err.println("connecting to: " + serverConfiguration.getServerAddress() - + " state: " + state); if (state != ClientState.UNCONNECTED) return; id = clientDispatcher.connect(serverConfiguration.getServerAddress()); if (id == null) { - throw new RuntimeException("Null ID from Dispatcher. Server: <" - + serverConfiguration.getServerAddress() + "> is probably down."); + throw new RuntimeException( + "Null ID from Dispatcher. Server: <" + + serverConfiguration.getServerAddress() + "> is probably down."); } state = ClientState.CONNECTED; } Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 2009-11-04 20:24:26 UTC (rev 354) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 2009-11-07 22:58:44 UTC (rev 355) @@ -1,679 +0,0 @@ -package edu.asu.commons.irrigation.client; - -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridLayout; -import java.awt.Rectangle; - -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; -import javax.swing.JTextField; -import javax.swing.SwingUtilities; - -import edu.asu.commons.irrigation.conf.RoundConfiguration; -import edu.asu.commons.irrigation.server.ClientData; - -/** - * $Id$ - * - * Contains the primary open gate button, etc. - * - * - * @author <a href='mailto:All...@as...'>Allen Lee</a> - * @version $Rev$ - */ - -public class IrrigationGameWindow extends JPanel { - - private static final long serialVersionUID = -1737783671891265064L; - - private JPanel jPanelIrrigationGameWindow = null; - - private JPanel jPanelIrrigationWindow = null; - - private JPanel jPanelIrrigationWindowLeft = null; - - private JPanel jPanelIrrigationWindowRight = null; - - private JPanel jPanelIrrigationWindowLeftUp = null; - - private JPanel jPanelIrrigationWindowLeftDown = null; - - private JPanel jPanelIrrigationGameWindowLeftUpFiles = null; - - public JButton openGateButton = null; - - private JPanel jPanelIrrigationGameWindowLeftDownButtons = null; - - private JPanel jPanelIrrigationGameWindowLeftDownProgress = null; - - // public JButton StopDownload = null; - - public JProgressBar fileDownloadedProgressBar = null; - - public JPanel jPanelIrrigationGameWindowRightDown = null; - - private JPanel jPanelIrrigationWindowRightUp = null; - - private JPanel jPanelIrrigationGameWindowRightUp2 = null; - - private JPanel jPanelIrrigationGameWindowRightUp1 = null; - - private JPanel jPanelIrrigationGameWindowRightUp3 = null; - - private JLabel availableBandwidthLabel = null; - - public JProgressBar availableBandwidthTxt = null; - - private JLabel profitEarned = null; - - public JTextField moneyEarnedTextField = null; - - private JLabel fileDownloadedtxt = null; - - private IrrigationClient irrigationClient; - - private String name = null; - - public ChartWindowPanel xySeriesDemo; - - public JButton pauseDownload = null; - - private ClientData clientData; // @jve:decl-index=0: - - private JLabel availableFlowCapacityLabel = null; - - private JLabel currentBandwidthAvailableTextjLabel = null; - - private IrrigationGamePanel mainIrrigationWindow; - - public IrrigationGameWindow(Dimension screenSize, IrrigationClient client, - IrrigationGamePanel mainIrrigationWindow) { - this.mainIrrigationWindow = mainIrrigationWindow; - this.irrigationClient = client; - initialize(screenSize); - } - - /** - * Initializes the GUI. - * - * @return void - */ - private void initialize(Dimension screenSize) { - // why use card layout? - this.setLayout(new CardLayout()); - this.setSize(530, 326); - this.add(getJPanelIrrigationGameWindow(), getJPanelIrrigationGameWindow().getName()); - } - - public void startRound(final RoundConfiguration experimentRoundConfiguration) { - /** - * Here the logic would come for the starting of round, initialization , - * starting of the GUI, etc, etc. - */ - initEnable(); - } - - // public void endRound(EndRoundEvent event){ - public void endRound() { - /** - * here the end code and debreifing logic should be written - */ - refreshButtons(); - moneyEarnedTextField.setText("0"); - } - - /** - * This method initializes jPanel - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationGameWindow() { - if (jPanelIrrigationGameWindow == null) { - jPanelIrrigationGameWindow = new JPanel(); - jPanelIrrigationGameWindow.setLayout(new CardLayout()); - jPanelIrrigationGameWindow.setName("jPanel"); - jPanelIrrigationGameWindow.add(getJPanelIrrigationWindow(), getJPanelIrrigationWindow().getName()); - } - return jPanelIrrigationGameWindow; - } - - /** - * Returns the primary irrigation window. - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationWindow() { - if (jPanelIrrigationWindow == null) { - GridLayout gridLayout = new GridLayout(); - gridLayout.setRows(1); - jPanelIrrigationWindow = new JPanel(); - jPanelIrrigationWindow.setLayout(gridLayout); - jPanelIrrigationWindow.setName("Primary Irrigation Window"); - jPanelIrrigationWindow.add(getJPanelIrrigationWindowLeft(), null); - jPanelIrrigationWindow.add(getJPanelIrrigationWindowRight(), null); - } - return jPanelIrrigationWindow; - } - - /** - * These methods would be updated externally by irrigationClientGameState. - */ - public void updateFileDownloaded(double percentFileDownloaded) { - - } - - public void updateProfitEarned(final int award) { - moneyEarnedTextField.setText(new Integer(award).toString()); - - } - - /** - * This method initializes jPanel31 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationWindowLeft() { - if (jPanelIrrigationWindowLeft == null) { - GridLayout gridLayout3 = new GridLayout(); - gridLayout3.setRows(2); - jPanelIrrigationWindowLeft = new JPanel(); - jPanelIrrigationWindowLeft.setLayout(gridLayout3); - jPanelIrrigationWindowLeft.add(getJPanelIrrigationWindowLeftUp(), - null); - jPanelIrrigationWindowLeft.add(getJPanelIrrigationWindowLeftDown(), - null); - } - return jPanelIrrigationWindowLeft; - } - - /** - * This method initializes jPanel32 - * - * @return javax.swing.JPanel - */ - public JPanel getJPanelIrrigationWindowRight() { - if (jPanelIrrigationWindowRight == null) { - GridLayout gridLayout5 = new GridLayout(); - gridLayout5.setRows(2); - jPanelIrrigationWindowRight = new JPanel(); - jPanelIrrigationWindowRight.setLayout(gridLayout5); - jPanelIrrigationWindowRight.add( - getJPanelIrrigationGameWindowRightUp1(), null); - jPanelIrrigationWindowRight.add(getJPanelIrrigationWindowRightUp(), - null); - } - return jPanelIrrigationWindowRight; - } - - /** - * This method initializes jPanel311 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationWindowLeftUp() { - if (jPanelIrrigationWindowLeftUp == null) { - jPanelIrrigationWindowLeftUp = new JPanel(); - jPanelIrrigationWindowLeftUp.setLayout(new BorderLayout()); - jPanelIrrigationWindowLeftUp.add(getJPanelIrrigationGameWindowLeftUpFiles(), BorderLayout.CENTER); - } - return jPanelIrrigationWindowLeftUp; - } - - /** - * This method initializes jPanel312 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationWindowLeftDown() { - if (jPanelIrrigationWindowLeftDown == null) { - GridLayout gridLayout4 = new GridLayout(); - gridLayout4.setRows(2); - jPanelIrrigationWindowLeftDown = new JPanel(); - jPanelIrrigationWindowLeftDown.setLayout(gridLayout4); - jPanelIrrigationWindowLeftDown.add( - getJPanelIrrigationGameWindowLeftDownProgress(), null); - jPanelIrrigationWindowLeftDown.add( - getJPanelIrrigationGameWindowLeftDownButtons(), null); - } - return jPanelIrrigationWindowLeftDown; - } - - /** - * This method initializes jPanel3111 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationGameWindowLeftUpFiles() { - if (jPanelIrrigationGameWindowLeftUpFiles == null) { - jPanelIrrigationGameWindowLeftUpFiles = new JPanel(); - jPanelIrrigationGameWindowLeftUpFiles.setLayout(null); - jPanelIrrigationGameWindowLeftUpFiles.setVisible(true); - jPanelIrrigationGameWindowLeftUpFiles.setBackground(new Color(238, 238, 238)); - jPanelIrrigationGameWindowLeftUpFiles.add(getOpenGateButton(), null); - } - return jPanelIrrigationGameWindowLeftUpFiles; - } - - /** - * This method initializes File1 - * - * @return javax.swing.JButton - */ - private JButton getOpenGateButton() { - if (openGateButton == null) { - openGateButton = new JButton(); - openGateButton.setText("Grow"); - openGateButton.setForeground(Color.black); - openGateButton.setSelected(true); - openGateButton.setBackground(new Color(186, 236, 237)); - openGateButton.setBounds(new Rectangle(48, 5, 63, 15)); - // TODO Auto-generated method stub - openGateButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - /** - * undisrupted Bandwidth Extensions - */ - if(clientData != null){ - if(clientData.getAvailableFlowCapacity() > 0){ - //file1.setBackground(Color.RED); - openGateButton.setEnabled(false); - openGate(); - } - } - else - System.out.println("ClientData is null"); - } - }); - } - return openGateButton; - } - - /** - * this will start the download for fileNo - * - * @param fileNo - */ - private void openGate() { - /* - * System.out.println("Before downloading file " + fileNo + "Current - * time" + System.currentTimeMillis() / 1000); - */ - - irrigationClient.openGate(); - initEnable(); - - - } - - /** - * This method initializes jPanel3121 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationGameWindowLeftDownButtons() { - if (jPanelIrrigationGameWindowLeftDownButtons == null) { - jPanelIrrigationGameWindowLeftDownButtons = new JPanel(); - jPanelIrrigationGameWindowLeftDownButtons.setLayout(null); - /* - * jPanelIrrigationGameWindowLeftDownButtons.add(getStopDownload(), - * null); - */ - jPanelIrrigationGameWindowLeftDownButtons.add(getPauseDownload(), - null); - } - return jPanelIrrigationGameWindowLeftDownButtons; - } - - /** - * This method initializes jPanel3122- - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationGameWindowLeftDownProgress() { - if (jPanelIrrigationGameWindowLeftDownProgress == null) { - fileDownloadedtxt = new JLabel(); - fileDownloadedtxt.setText("% Crop Grown:"); - fileDownloadedtxt.setBounds(new Rectangle(64, 32, 145, 16)); - jPanelIrrigationGameWindowLeftDownProgress = new JPanel(); - jPanelIrrigationGameWindowLeftDownProgress.setLayout(null); - jPanelIrrigationGameWindowLeftDownProgress.add(getFileDownloaded(), - null); - jPanelIrrigationGameWindowLeftDownProgress.add(fileDownloadedtxt, - null); - } - return jPanelIrrigationGameWindowLeftDownProgress; - } - - /** - * This method initializes StopDownload - * - * @return javax.swing.JButton - */ - // Removing the Stop Button Functionality - /* - * private JButton getStopDownload() { if (StopDownload == null) { - * StopDownload = new JButton(); StopDownload.setText("Stop "); - * StopDownload.setBounds(new Rectangle(16, 6, 103, 25)); - * StopDownload.setBackground(new Color(186, 226, 237)); - * StopDownload.setEnabled(false); StopDownload.addActionListener(new - * java.awt.event.ActionListener() { public void - * actionPerformed(java.awt.event.ActionEvent e) { - * PauseDownload.setEnabled(true); StopDownload.setEnabled(true); - * client.stopDownload(fileNo); enableFiles(); initDisable(); } - *//** - * just check this and implement later - * - * @param fileNo - */ - /* - * - * }); } return StopDownload; } - */ - - /** - * This method initializes FileDownloaded - * - * @return javax.swing.JProgressBar - */ - private JProgressBar getFileDownloaded() { - if (fileDownloadedProgressBar == null) { - fileDownloadedProgressBar = new JProgressBar(); - fileDownloadedProgressBar.setBounds(new Rectangle(63, 15, 148, 14)); - fileDownloadedProgressBar.setBackground(Color.white); - fileDownloadedProgressBar.setForeground(Color.green); - fileDownloadedProgressBar - .setFont(new Font("Dialog", Font.BOLD, 12)); - fileDownloadedProgressBar.setStringPainted(true); - } - return fileDownloadedProgressBar; - } - - /** - * This method initializes jPanel321 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationWindowRightUp() { - if (jPanelIrrigationWindowRightUp == null) { - GridLayout gridLayout7 = new GridLayout(); - gridLayout7.setRows(1); - GridLayout gridLayout6 = new GridLayout(); - gridLayout6.setRows(1); - jPanelIrrigationWindowRightUp.add( - getJPanelIrrigationGameWindowRightUp2(), null); - jPanelIrrigationWindowRightUp.add( - getJPanelIrrigationGameWindowRightUp1(), null); - } - return jPanelIrrigationWindowRightUp; - } - - /** - * This method initializes jPanel322 - * - * @return javax.swing.JPanel - */ - - public JPanel getJPanelIrrigationGameWindowRightDown(int file) { - if (jPanelIrrigationGameWindowRightDown == null) { - jPanelIrrigationGameWindowRightDown = new JPanel(); - jPanelIrrigationGameWindowRightDown.setLayout(null); - jPanelIrrigationGameWindowRightDown.setSize(530 / 2, 326 / 2); - jPanelIrrigationGameWindowRightDown.add(getJGraph(file)); - } - return jPanelIrrigationGameWindowRightDown; - } - - public JPanel getJGraph(int numberFileDownloaded) { - // TODO Auto-generated method stub - if (xySeriesDemo == null) { - xySeriesDemo = new ChartWindowPanel(numberFileDownloaded); - xySeriesDemo.setVisible(true); - } - return xySeriesDemo; - } - - /** - * This method initializes jPanel321 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationGameWindowRightUp1() { - if (jPanelIrrigationWindowRightUp == null) { - GridLayout gridLayout8 = new GridLayout(); - gridLayout8.setRows(3); - jPanelIrrigationWindowRightUp = new JPanel(); - jPanelIrrigationWindowRightUp.setLayout(gridLayout8); - jPanelIrrigationWindowRightUp.add(getJPanel32122(), null); - jPanelIrrigationWindowRightUp.add( - getJPanelIrrigationGameWindowRightUp2(), null); - jPanelIrrigationWindowRightUp.add( - getJPanelIrrigationGameWindowRightUp3(), null); - } - return jPanelIrrigationWindowRightUp; - } - - /** - * This method initializes jPanel3211 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationGameWindowRightUp2() { - if (jPanelIrrigationGameWindowRightUp2 == null) { - currentBandwidthAvailableTextjLabel = new JLabel(); - currentBandwidthAvailableTextjLabel.setBounds(new Rectangle(180, - 15, 65, 16)); - currentBandwidthAvailableTextjLabel.setText(""); - availableBandwidthLabel = new JLabel(); - availableBandwidthLabel.setText("% of capacity available:"); - availableBandwidthLabel.setBounds(new Rectangle(8, 5, 254, 18)); - jPanelIrrigationGameWindowRightUp2 = new JPanel(); - jPanelIrrigationGameWindowRightUp2.setLayout(null); - jPanelIrrigationGameWindowRightUp2.add( - getAvailableFlowCapacityLabel(), null); - jPanelIrrigationGameWindowRightUp2.add( - currentBandwidthAvailableTextjLabel, null); - } - return jPanelIrrigationGameWindowRightUp2; - } - - /** - * This method initializes jPanel3212 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanel32122() { - if (jPanelIrrigationGameWindowRightUp1 == null) { - profitEarned = new JLabel(); - profitEarned.setText("Tokens Collected:"); - profitEarned.setBounds(new Rectangle(17, 18, 114, 21)); - jPanelIrrigationGameWindowRightUp1 = new JPanel(); - jPanelIrrigationGameWindowRightUp1.setLayout(null); - jPanelIrrigationGameWindowRightUp1.add(profitEarned, null); - jPanelIrrigationGameWindowRightUp1.add(getProfitEarnedTextField(), null); - } - return jPanelIrrigationGameWindowRightUp1; - } - - /** - * This method initializes jPanel3213 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelIrrigationGameWindowRightUp3() { - if (jPanelIrrigationGameWindowRightUp3 == null) { - jPanelIrrigationGameWindowRightUp3 = new JPanel(); - jPanelIrrigationGameWindowRightUp3.setLayout(null); - jPanelIrrigationGameWindowRightUp3.add(availableBandwidthLabel, - null); - jPanelIrrigationGameWindowRightUp3.add(getAvailableBandwidthtxt(), - null); - } - return jPanelIrrigationGameWindowRightUp3; - } - - /** - * This method initializes AvailableBandwidthtxt - * - * @return javax.swing.JProgressBar - */ - private JProgressBar getAvailableBandwidthtxt() { - if (availableBandwidthTxt == null) { - availableBandwidthTxt = new JProgressBar(); - availableBandwidthTxt.setMaximum(25); - availableBandwidthTxt.setBounds(new Rectangle(15, 31, 240, 14)); - availableBandwidthTxt.setStringPainted(true); - availableBandwidthTxt.setBackground(Color.white); - availableBandwidthTxt.setForeground(new Color(51, 153, 255)); - availableBandwidthTxt.setValue(25); - } - return availableBandwidthTxt; - } - - /** - * This method initializes ProfitEarnedtxt - * - * @return javax.swing.JTextField - */ - private JTextField getProfitEarnedTextField() { - if (moneyEarnedTextField == null) { - moneyEarnedTextField = new JTextField(); - moneyEarnedTextField.setText(new Integer(mainIrrigationWindow - .getClientDataModel().getClientData().getAllTokensEarnedThisRound()) - .toString()); - moneyEarnedTextField.setBounds(new Rectangle(161, 17, 86, 21)); - moneyEarnedTextField.setFont(new Font("Dialog", Font.PLAIN, 14)); - moneyEarnedTextField.setEditable(false); - } - return moneyEarnedTextField; - } - - /** - * This method initializes PauseDownload - * - * @return javax.swing.JButton - */ - private JButton getPauseDownload() { - if (pauseDownload == null) { - pauseDownload = new JButton(); - pauseDownload.setBounds(new Rectangle(40, 7, 191, 25)); - pauseDownload.setText("Pause"); - pauseDownload.setBackground(new Color(186, 226, 237)); - pauseDownload.setEnabled(false); - pauseDownload.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - - if (pauseDownload.getText() == "Pause") { - pauseDownload.setText("Resume"); - // StopDownload.setEnabled(true); - irrigationClient.pause(); - } else if (pauseDownload.getText() == "Resume") { - pauseDownload.setText("Pause"); - irrigationClient.openGate(); - } - } - }); - } - return pauseDownload; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void initEnable() { - // TODO Auto-generated method stub - // StartDownload.setEnabled(false); - // StopDownload.setEnabled(true); - pauseDownload.setEnabled(true); - } - - public void initDisable() { - // TODO Auto-generated method stub - // StartDownload.setEnabled(false); - // StopDownload.setEnabled(false); - pauseDownload.setEnabled(false); - } - - /** - * refreshes the file buttons for the main irrigation window - */ - public void refreshButtons() { - openGateButton.setEnabled(true); - openGateButton.setBackground(new Color(186, 226, 237)); - } - - public void update(ClientData data) { - this.clientData = data; - Runnable createGuiRunnable = new Runnable() { - public void run() { - availableBandwidthTxt.setValue((int) clientData - .getAvailableFlowCapacity()); - if (clientData.getAvailableFlowCapacity() > 25) { - currentBandwidthAvailableTextjLabel.setText(new Double(25) - .toString()); - } else { - currentBandwidthAvailableTextjLabel.setText(new Double( - clientData.getAvailableFlowCapacity()).toString()); - } - - /* - * if(clientData.getAvailableBandwidth() == - * clientData.getMaximumAvailableBandwidth()){ - * bandwidthusedOtherTextjLabel.setText("0"); } else{ - * bandwidthusedOtherTextjLabel.setText(new - * Double(clientData.getMaximumAvailableBandwidth()- - * clientData.getAvailableBandwidth()).toString()); } - */ - -// fileDownloadedProgressBar.setValue((int) clientData.getPercentFileDownload()); - // checks whether the file has been downlaoded - /* - if (clientData.isFileDownloaded()) { - - moneyEarnedTextField.setText(new Integer(clientData.getTotalTokensEarned()) - .toString()); - // StopDownload.setEnabled(false); - pauseDownload.setEnabled(false); - } - else if(clientData.isGateOpen() || clientData.isPaused()){ - initEnable(); - } - /** - * undisrupted Bandwidth extensions - */ - if(clientData.getAvailableFlowCapacity() <= 0 && - irrigationClient.getServerConfiguration().isUndisruptedFlowRequired() ) - { - pauseDownload.setEnabled(false); - } - - } - }; - SwingUtilities.invokeLater(createGuiRunnable); - } - - /** - * This method initializes currentBandwidthAvailablejLabel - * - * @return javax.swing.JLabel - */ - private JLabel getAvailableFlowCapacityLabel() { - if (availableFlowCapacityLabel == null) { - availableFlowCapacityLabel = new JLabel(); - availableFlowCapacityLabel.setText("Your available flow capacity:"); - availableFlowCapacityLabel.setBounds(new Rectangle(17, 15, - 153, 16)); - } - return availableFlowCapacityLabel; - } -} 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-11-04 20:24:26 UTC (rev 354) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-11-07 22:58:44 UTC (rev 355) @@ -36,8 +36,6 @@ private static final long serialVersionUID = 5900368694556557132L; - public IrrigationGameWindow controlPanel; - private CanalPanel canalPanel; private JPanel jPanelMain = null; @@ -52,16 +50,6 @@ private JProgressBar timeLeftProgressBar; - 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; @@ -72,7 +60,7 @@ private JButton gateSwitchButton; - protected boolean open; + private boolean open; private JTextField waterCollectedTextField; @@ -104,29 +92,10 @@ super(); this.client = client; setName("main irrigation game window"); - initialize(); + initGuiComponents(); } - /** - * 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); - + private void initGuiComponents() { this.setLayout(new BorderLayout(4,4)); this.setSize(1130, 558); this.add(getPanel(),null); @@ -161,15 +130,6 @@ 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(""); - 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(""); mainInterfacePanel = new JPanel(); mainInterfacePanel.setLayout(null); mainInterfacePanel.setName("Main interface panel"); @@ -446,68 +406,18 @@ }); } - // //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 + * end of round interface cleanup. */ - - /* - * 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_LABEL); } - }); open = false; } @@ -517,19 +427,7 @@ */ 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() { @@ -545,40 +443,20 @@ waterSupply)); 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) { centerPanel.add(getCanalPanel(clientDataModel)); - //switch(clientGameState.getPriority()){ - mainInterfacePanel.add(getJPanelUpStreamWindow(),null); mainInterfacePanel.add(getJPanelDownStreamWindow(),null); - //adding the in between Panel mainInterfacePanel.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(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-17 01:32:07
|
Revision: 366 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=366&view=rev Author: alllee Date: 2009-11-17 01:31:57 +0000 (Tue, 17 Nov 2009) Log Message: ----------- fixing NPE in instructions Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 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-11-17 00:42:32 UTC (rev 365) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-11-17 01:31:57 UTC (rev 366) @@ -102,14 +102,13 @@ void initialize() { cardLayout = new CardLayout(); setLayout(cardLayout); - setInstructions(getServerConfiguration().getWelcomeInstructions()); addToCardLayout(getInstructionsPanel()); -// irrigationGamePanel = new IrrigationGamePanel(client); irrigationGamePanel = new MainIrrigationGameWindow(client); addToCardLayout(irrigationGamePanel); addToCardLayout(getTokenInvestmentPanel()); addToCardLayout(getChatPanel()); addToCardLayout(getContributionInformationPanel()); + setInstructions(getServerConfiguration().getWelcomeInstructions()); } private void addToCardLayout(Component component) { @@ -201,15 +200,13 @@ nextButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { previousButton.setEnabled(true); - if (currentQuizPageNumber >= quizzesAnswered){ - nextButton.setEnabled(false); - } + currentQuizPageNumber++; if (currentQuizPageNumber < getServerConfiguration().getNumberOfQuestionPages()) { - currentQuizPageNumber++; setInstructions(getQuizPage()); } else { setInstructions(instructionsBuilder.toString()); + nextButton.setEnabled(false); } } }); 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-11-17 00:42:32 UTC (rev 365) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-11-17 01:31:57 UTC (rev 366) @@ -124,14 +124,12 @@ private JPanel getMainInterfacePanel() { if(mainInterfacePanel == null){ - scoreBoardLabel = new JLabel(); + scoreBoardLabel = new JLabel("EARNINGS GRAPH"); scoreBoardLabel.setBounds(new Rectangle(582,225+100+35,530,20)); scoreBoardLabel.setHorizontalAlignment(SwingConstants.CENTER); - scoreBoardLabel.setText("WATER COLLECTED TO TOKENS EARNED TABLE"); - gateSwitchLabel = new JLabel(); + gateSwitchLabel = new JLabel("DASHBOARD"); gateSwitchLabel.setBounds(new Rectangle(13,225+100+35,530,20)); gateSwitchLabel.setHorizontalAlignment(SwingConstants.CENTER); - gateSwitchLabel.setText("DASHBOARD"); mainInterfacePanel = new JPanel(); mainInterfacePanel.setLayout(null); mainInterfacePanel.setName("Main interface panel"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |