Thread: [virtualcommons-svn] SF.net SVN: virtualcommons:[292] irrigation/trunk/src/main/java/edu/asu/ commo
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-10-10 01:16:40
|
Revision: 292 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=292&view=rev Author: alllee Date: 2009-10-10 01:16:33 +0000 (Sat, 10 Oct 2009) Log Message: ----------- minor hygiene, tracking down connection event errors when a client disconnects. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-09 06:26:41 UTC (rev 291) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-10 01:16:33 UTC (rev 292) @@ -141,9 +141,7 @@ // } public boolean isUndisruptedBandwidth(){ - if(assistant.getBooleanProperty("undisrupted-bandwidth")== true) - return true; - return false; + return assistant.getBooleanProperty("undisruptedBandwidth", false); } public double getShowUpPayment() { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-09 06:26:41 UTC (rev 291) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-10 01:16:33 UTC (rev 292) @@ -29,34 +29,34 @@ */ public class Facilitator { - private final static Facilitator INSTANCE = new Facilitator(); - - private Identifier id; // @jve:decl-index=0: + private final static Facilitator INSTANCE = new Facilitator(); - private ClientDispatcher dispatcher; - - private ServerConfiguration configuration; - - private ServerDataModel serverGameState; // @jve:decl-index=0: - - private FacilitatorWindow irrigationFacilitatorWindow; - - private boolean stopExperiment = false; - - private boolean experimentRunning = false; - + private Identifier id; // @jve:decl-index=0: + + private ClientDispatcher dispatcher; + + private ServerConfiguration configuration; + + private ServerDataModel serverGameState; // @jve:decl-index=0: + + private FacilitatorWindow irrigationFacilitatorWindow; + + private boolean stopExperiment = false; + + private boolean experimentRunning = false; + private final EventTypeChannel channel = new EventTypeChannel(); - - private Facilitator() { + + private Facilitator() { this(new ServerConfiguration()); } - + public Facilitator(ServerConfiguration configuration) { dispatcher = DispatcherFactory.getInstance().createClientDispatcher(channel); setConfiguration(configuration); initializeEventProcessors(); } - + @SuppressWarnings("unchecked") private void initializeEventProcessors() { channel.add(new EventTypeProcessor<ConfigurationEvent>(ConfigurationEvent.class) { @@ -66,7 +66,7 @@ }); channel.add(new EventTypeProcessor<FacilitatorEndRoundEvent>(FacilitatorEndRoundEvent.class) { public void handle(FacilitatorEndRoundEvent event) { -// serverGameState = null; + // serverGameState = null; irrigationFacilitatorWindow.endRound(event); configuration.nextRound(); } @@ -76,7 +76,7 @@ public static Facilitator getInstance(){ return INSTANCE; } - + public void setConfiguration(ServerConfiguration configuration) { if (configuration == null) { System.err.println("attempt to setConfiguration with null, ignoring"); @@ -86,11 +86,11 @@ this.configuration = configuration; } } - - /** - * @param args - */ - + + /** + * @param args + */ + /* * Connects facilitator to the server and registers with the server as a facilitator. * @@ -101,124 +101,118 @@ public void connect() { connect(configuration.getServerAddress()); } - + public void connect(InetSocketAddress address) { id = dispatcher.connect(address); if (id != null) { - transmit(new FacilitatorRegistrationRequest(id)); + transmit(new FacilitatorRegistrationRequest(id)); } - + } - + void createFacilitatorWindow(Dimension dimension) { irrigationFacilitatorWindow = new FacilitatorWindow(dimension, this); - //if (id == null) { - // configure for unconnected functionality - // facilitatorWindow.configureForReplay(); - //} } - + /* * Sends requests to the server */ public void transmit(Event event) { dispatcher.transmit(event); } - + public static void main(String[] args) { - - Runnable createGuiRunnable = new Runnable(){ - public void run() { - // TODO Auto-generated method stub - Dimension dimension = new Dimension(500, 600); - Facilitator facilitator = Facilitator.getInstance(); - facilitator.connect(); - JFrame frame = new JFrame(); - frame.setTitle("Facilitator window: " + facilitator.id); - frame.setSize((int) dimension.getWidth(), (int) dimension.getHeight()); - facilitator.createFacilitatorWindow(dimension); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.getContentPane().add(facilitator.getFacilitatorWindow()); - frame.setVisible(true); + Runnable createGuiRunnable = new Runnable(){ + public void run() { + Dimension dimension = new Dimension(500, 600); + Facilitator facilitator = Facilitator.getInstance(); + facilitator.connect(); + JFrame frame = new JFrame(); + frame.setTitle("Facilitator window: " + facilitator.id); + frame.setSize((int) dimension.getWidth(), (int) dimension.getHeight()); + facilitator.createFacilitatorWindow(dimension); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.getContentPane().add(facilitator.getFacilitatorWindow()); + frame.setVisible(true); } - }; - SwingUtilities.invokeLater(createGuiRunnable); - } + }; + SwingUtilities.invokeLater(createGuiRunnable); + } - public void accept(Identifier id, Object event) { - // TODO Auto-generated method stub - if (event instanceof ConfigurationEvent) { - ConfigurationEvent configEvent = (ConfigurationEvent) event; - setConfiguration((ServerConfiguration)configEvent.getConfiguration()); - } - else if(event instanceof ServerGameStateEvent){ - ServerGameStateEvent serverGameStateEvent = (ServerGameStateEvent)event; - if (!stopExperiment) { - if (serverGameState == null) { - System.err.println("about to display game.."); - experimentRunning = true; - // FIXME: could use configuration from this event... serverGameStateEvent.getServerGameState().getConfiguration(); - serverGameState = serverGameStateEvent.getServerGameState(); - /** - * Here I need to display Game..this goes to the facilitator window. - */ - //facilitatorWindow.displayGame(); - } - else { - // synchronous updates - serverGameState = serverGameStateEvent.getServerGameState(); - } - } - //facilitatorWindow.updateWindow(serverGameStateEvent.getTimeLeft()); - } - else if (event instanceof FacilitatorEndRoundEvent){ - FacilitatorEndRoundEvent endRoundEvent = (FacilitatorEndRoundEvent)event; - serverGameState = null; - /** - * This method goes to facilitator widow. - */ - //facilitatorWindow.endRound(endRoundEvent); - } - - } + // public void accept(Identifier id, Object event) { + // // TODO Auto-generated method stub + // if (event instanceof ConfigurationEvent) { + // ConfigurationEvent configEvent = (ConfigurationEvent) event; + // setConfiguration((ServerConfiguration)configEvent.getConfiguration()); + // } + // else if(event instanceof ServerGameStateEvent){ + // ServerGameStateEvent serverGameStateEvent = (ServerGameStateEvent)event; + // if (!stopExperiment) { + // if (serverGameState == null) { + // System.err.println("about to display game.."); + // experimentRunning = true; + // // FIXME: could use configuration from this event... serverGameStateEvent.getServerGameState().getConfiguration(); + // serverGameState = serverGameStateEvent.getServerGameState(); + // /** + // * Here I need to display Game..this goes to the facilitator window. + // */ + // //facilitatorWindow.displayGame(); + // } + // else { + // // synchronous updates + // serverGameState = serverGameStateEvent.getServerGameState(); + // } + // } + // //facilitatorWindow.updateWindow(serverGameStateEvent.getTimeLeft()); + // } + // else if (event instanceof FacilitatorEndRoundEvent){ + // FacilitatorEndRoundEvent endRoundEvent = (FacilitatorEndRoundEvent)event; + // serverGameState = null; + // /** + // * This method goes to facilitator widow. + // */ + // //facilitatorWindow.endRound(endRoundEvent); + // } + // + // } - /* + /* * Send a request to server to start an experiment */ void sendBeginExperimentRequest(){ - System.out.println("I am in sendBeginExperiment"); - transmit(new BeginExperimentRequest(id)); - //sendBeginRoundRequest(); - stopExperiment = false; - } - - /* + System.out.println("I am in sendBeginExperiment"); + transmit(new BeginExperimentRequest(id)); + //sendBeginRoundRequest(); + stopExperiment = false; + } + + /* * Send a request to start a round */ public void sendBeginRoundRequest() { transmit(new BeginRoundRequest(id)); } - -// /* -// * Send a request to stop an experiment -// */ -// -// public void sendStopExperimentRequest() { -// transmit(new EndExperimentRequest(id)); -// endExperiment(); -// } - -// public void endExperiment() { -// configuration.resetExperimentRoundConfiguration(); -// serverGameState = null; -// stopExperiment = true; -// experimentRunning = false; -// //facilitatorWindow.updateMenuItems(); -// } + + // /* + // * Send a request to stop an experiment + // */ + // + // public void sendStopExperimentRequest() { + // transmit(new EndExperimentRequest(id)); + // endExperiment(); + // } + + // public void endExperiment() { + // configuration.resetExperimentRoundConfiguration(); + // serverGameState = null; + // stopExperiment = true; + // experimentRunning = false; + // //facilitatorWindow.updateMenuItems(); + // } /* * Send a request to stop a round */ - + public void sendEndRoundRequest() { transmit(new EndRoundRequest(id)); } @@ -228,31 +222,31 @@ public void sendSetConfigRequest() { dispatcher.transmit(new ConfigurationEvent(id, getConfiguration())); } - + public FacilitatorWindow getFacilitatorWindow() { return irrigationFacilitatorWindow; } - + public Identifier getIdentifier(){ - return id; + return id; } public ServerDataModel getServerGameState(){ - return serverGameState; + return serverGameState; } - + public ServerConfiguration getConfiguration(){ - return configuration; + return configuration; } - + public boolean isExperimentRunning(){ - return experimentRunning; + return experimentRunning; } - - public RoundConfiguration getCurrentRoundConfiguration() { + + public RoundConfiguration getCurrentRoundConfiguration() { return configuration.getCurrentParameters(); } - + public void setServerGameState(ServerDataModel serverGameState) { this.serverGameState = serverGameState; } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-09 06:26:41 UTC (rev 291) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-10 01:16:33 UTC (rev 292) @@ -219,12 +219,12 @@ * This would initialize the clientData before the start of each download. * */ - public void init(double availableBandwidth) { + public void init(double availableFlowCapacity) { resetFileInformation(); //maximumDeliveryBandwidth = getRoundConfiguration().getBtmax()/getRoundConfiguration().getClientsPerGroup(); maximumIndividualFlowCapacity = getRoundConfiguration().getMaximumIndividualFlowCapacity(); //currentBandwidth = totalContributedBandwidth; - this.availableFlowCapacity = availableBandwidth; + this.availableFlowCapacity = availableFlowCapacity; } private void resetFileInformation() { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-09 06:26:41 UTC (rev 291) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-10 01:16:33 UTC (rev 292) @@ -141,12 +141,12 @@ } /** - * The main transfer function that maps the number of tokens generated to the Bandwidth Bi + * This function maps flow capacity to infrastructure efficiency. Returns an int representing + * the flow capacity given the infrastructure efficiency. * this needs to be designed. * @param totalTokens * @return */ - public int calculateFlowCapacity(final int infrastructureEfficiency) { if (infrastructureEfficiency <= 45) { return 0; @@ -190,7 +190,6 @@ currentlyAvailableFlowCapacity = maximumAvailableFlowCapacity; } - public void allocateFlowCapacity(ClientData clientData) { if (currentlyAvailableFlowCapacity >= clientData.getMaximumIndividualFlowCapacity()) { currentlyAvailableFlowCapacity -= clientData.getMaximumIndividualFlowCapacity(); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-09 06:26:41 UTC (rev 291) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-10 01:16:33 UTC (rev 292) @@ -19,22 +19,23 @@ import edu.asu.commons.irrigation.conf.RoundConfiguration; import edu.asu.commons.irrigation.conf.ServerConfiguration; import edu.asu.commons.irrigation.events.BeginCommunicationRequest; +import edu.asu.commons.irrigation.events.CloseGateEvent; import edu.asu.commons.irrigation.events.DisplaySubmitTokenRequest; import edu.asu.commons.irrigation.events.EndRoundEvent; import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; -import edu.asu.commons.irrigation.events.OpenGateEvent; import edu.asu.commons.irrigation.events.InstructionEnableRequest; import edu.asu.commons.irrigation.events.InvestedTokensEvent; +import edu.asu.commons.irrigation.events.OpenGateEvent; +import edu.asu.commons.irrigation.events.PauseEvent; import edu.asu.commons.irrigation.events.QuizCompletedEvent; import edu.asu.commons.irrigation.events.RegistrationEvent; import edu.asu.commons.irrigation.events.RoundStartedEvent; import edu.asu.commons.irrigation.events.SendContributionStatusEvent; import edu.asu.commons.irrigation.events.SendFileProgressEvent; -import edu.asu.commons.irrigation.events.PauseEvent; -import edu.asu.commons.irrigation.events.CloseGateEvent; import edu.asu.commons.net.Dispatcher; import edu.asu.commons.net.Identifier; import edu.asu.commons.net.event.ConnectionEvent; +import edu.asu.commons.net.event.DisconnectionEvent; import edu.asu.commons.net.event.DisconnectionRequest; import edu.asu.commons.util.Duration; @@ -152,32 +153,32 @@ private void initializeClientHandlers() { // client handlers addEventProcessor(new EventTypeProcessor<ConnectionEvent>(ConnectionEvent.class) { + @Override public void handle(ConnectionEvent event) { // handle incoming connections Identifier identifier = event.getId(); ClientData clientData = new ClientData(identifier); synchronized (clients) { clients.put(identifier, clientData); + serverDataModel.addClient(clientData); } - serverDataModel.addClient(clientData); + transmit(new RegistrationEvent(clientData.getId(), getRoundConfiguration(), clientData)); } }); addEventProcessor(new EventTypeProcessor<DisconnectionRequest>(DisconnectionRequest.class) { - public void handle(DisconnectionRequest event) { + @Override + public void handleInExperimentThread(DisconnectionRequest request) { + getLogger().warning("disconnecting: " + request); + Identifier disconnectedClientId = request.getId(); synchronized (clients) { - // FIXME: thread-safe? - //removing the entire group from the client list, when one of the members get disconnected - GroupDataModel groupDataModel =clients.get(event.getId()).getGroupDataModel(); - for(ClientData clientData : groupDataModel.getClientDataMap().values()){ - System.out.println("Removing the client id :"+clientData.getId()); - clients.remove(clientData.getId()); - } - //clients.remove(event.getId()); + clients.remove(request.getId()); + serverDataModel.removeClient(request.getId()); } } }); addEventProcessor(new EventTypeProcessor<ChatRequest>(ChatRequest.class) { + @Override public void handle(ChatRequest request) { Identifier source = request.getSource(); Identifier target = request.getTarget(); @@ -282,7 +283,6 @@ * @param group */ private void process(GroupDataModel group) { - // reset group's available bandwidth and re-allocate client delivery bandwidths. group.resetCurrentlyAvailableFlowCapacity(); long time = currentRoundDuration.getTimeLeft() / 1000; @@ -299,10 +299,10 @@ //System.out.println("Downloading file"+clientData.getFileNumber()+"Current time"+System.currentTimeMillis()/1000); group.allocateFlowCapacity(clientData); } - else if (clientData.isGateClosed()) { clientData.init(group.getCurrentlyAvailableFlowCapacity()); } + // right now the clients cannot be paused. else if (clientData.isPaused()) { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-14 22:10:34
|
Revision: 297 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=297&view=rev Author: alllee Date: 2009-10-14 22:10:26 +0000 (Wed, 14 Oct 2009) Log Message: ----------- starting to simplify/disentangle the irrigation experiment's GUI code. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Gate.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.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/client/PieChart.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RoundStartedEvent.java Added Paths: ----------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/SummaryPanel.java Removed Paths: ------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClientGameState.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java 2009-10-13 17:09:51 UTC (rev 296) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanel.java 2009-10-14 22:10:26 UTC (rev 297) @@ -1,132 +0,0 @@ -/** - * - */ -package edu.asu.commons.irrigation.client; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.GridLayout; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import edu.asu.commons.irrigation.server.ClientData; - -/** - * @author Sanket - * - */ -public class ActivitySummaryPanel extends JPanel { - - /** - * - */ - private static final long serialVersionUID = -2400441194759984763L; - private JLabel currentBandwidthTextjLabel = null; - private JLabel filesDownloadedjLabel = null; - private JLabel filesDownloadedTextjLabel = null; - private JLabel tokensCollectedjLabel = null; - private JLabel currentBandwidthjLabel = null; - private JLabel tokensCollectedTextjLabel = null; - - private JLabel positionjLabel = null; - private JLabel positionTextjLabel = null; - - private ClientData clientData; // @jve:decl-index=0: - /** - * This method initializes - * - */ - public ActivitySummaryPanel(int i) { - super(); - initialize(i); - } - - /** - * This method initializes this - * - */ - private void initialize(int i) { - tokensCollectedTextjLabel = new JLabel(); - tokensCollectedTextjLabel.setText(""); - currentBandwidthjLabel = new JLabel(); - currentBandwidthjLabel.setText("Current Flow Capacity:"); - tokensCollectedjLabel = new JLabel(); - tokensCollectedjLabel.setText("Tokens Collected:"); - filesDownloadedTextjLabel = new JLabel(); - filesDownloadedTextjLabel.setText(""); - filesDownloadedjLabel = new JLabel(); - filesDownloadedjLabel.setText("Crops Grown:"); - currentBandwidthTextjLabel = new JLabel(); - currentBandwidthTextjLabel.setText(""); - - positionjLabel = new JLabel(); - positionjLabel.setText("Position :"); - - positionTextjLabel = new JLabel(); - positionTextjLabel.setText(""); - - GridLayout gridLayout = new GridLayout(); - gridLayout.setRows(4); - gridLayout.setColumns(2); - this.setLayout(gridLayout); - this.setSize(new Dimension(430,126)); - switch(i) - { - case 0: this.setBackground(Color.PINK); - break; - - case 1: this.setBackground(Color.GREEN); - break; - - case 2: this.setBackground(Color.WHITE); - break; - - case 3: this.setBackground(Color.CYAN); - break; - - case 4: this.setBackground(Color.YELLOW); - break; - } - this.add(positionjLabel, null); - this.add(positionTextjLabel, null); - this.add(currentBandwidthjLabel, null); - this.add(currentBandwidthTextjLabel, null); - this.add(filesDownloadedjLabel, null); - this.add(filesDownloadedTextjLabel, null); - this.add(tokensCollectedjLabel, null); - this.add(tokensCollectedTextjLabel, null); - } - - public void update(ClientData data) { - this.clientData = data; - // TODO Auto-generated method stub - //System.out.println("Client Data Prioriity"+clientData.getPriority()+"Avaiable bandwidth"+ - //clientData.getAvailableBandwidth()); - - Runnable createGuiRunnable = new Runnable(){ - public void run() { - //System.out.println("In the UPdate facilitator"); - positionTextjLabel.setText(new Integer(clientData.getPriority()).toString()); - tokensCollectedTextjLabel.setText(new Integer(clientData.getTotalTokensEarned()).toString()); - if(clientData.getAvailableFlowCapacity() > 25){ - currentBandwidthTextjLabel.setText(new Double(25).toString()); - } - else - currentBandwidthTextjLabel.setText(new Double(clientData.getAvailableFlowCapacity()).toString()); - filesDownloadedTextjLabel.setText(new Integer(clientData.getCropsGrown()).toString()); - } - }; - SwingUtilities.invokeLater(createGuiRunnable); - } - - public void endRound() { - // TODO Auto-generated method stub - currentBandwidthTextjLabel.setText(""); - filesDownloadedTextjLabel.setText(""); - tokensCollectedTextjLabel.setText(""); - - } - -} // @jve:decl-index=0:visual-constraint="10,10" Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java 2009-10-13 17:09:51 UTC (rev 296) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ActivitySummaryPanelNew.java 2009-10-14 22:10:26 UTC (rev 297) @@ -1,221 +0,0 @@ -/** - * - */ -package edu.asu.commons.irrigation.client; - -import java.awt.Color; -import java.awt.Font; -import java.awt.Rectangle; -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JProgressBar; - -import edu.asu.commons.irrigation.server.ClientData; - - -/** - * @author Sanket - * - */ -public class ActivitySummaryPanelNew extends JPanel { - - /** - * - */ - private static final long serialVersionUID = 2393688647176774993L; - - //create three Maps for every parameter - Map<Integer,JProgressBar>availableBandwidthMap = new LinkedHashMap<Integer, JProgressBar>(); - Map<Integer, JLabel>filesDownLoadedMap = new LinkedHashMap<Integer, JLabel>(); - Map<Integer, JLabel>tokensCollectedMap = new LinkedHashMap<Integer, JLabel>(); - - JLabel labelA; - - JLabel labelB; - - JLabel labelC; - - JLabel labelD; - - JLabel labelE; - - JLabel titleLabel[] = new JLabel[3]; - - //private int NUMBER_OF_PARTICIPANTS_PERGROUP = 2; - - private int parameterIndex; - - IrrigationClient client; // @jve:decl-index=0: - - public ActivitySummaryPanelNew(int parameterIndex, IrrigationClient client) { - // TODO Auto-generated constructor stub - super(); - initialize(parameterIndex,client); - } - - private void initialize(int parameterIndex,IrrigationClient client) { - // TODO Auto-generated method stub - this.parameterIndex = parameterIndex; - - this.client = client; - - this.setLayout(null); - /*else{ - GridLayout gridLayout = new GridLayout(); - gridLayout.setColumns(1); - gridLayout.setRows(5); - this.setLayout(gridLayout); - }*/ - //add the parameters depending on the parameter Index - //initialize Labels - - for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ - System.out.println("I reach here"); - switch(i){ - case 0 :labelA = new JLabel(); - labelA.setBounds(new Rectangle(0,30+15*(i+i),25,15)); - if(client.getClientGameState().getPriority() == i){ - labelA.setText("YOU"); - } - else - labelA.setText("A"); - this.add(labelA); - break; - - case 1: labelB = new JLabel(); - labelB.setBounds(new Rectangle(0,30+15*(i+i),25,15)); - if(client.getClientGameState().getPriority() == i){ - labelB.setText("YOU"); - } - else - labelB.setText("B"); - this.add(labelB); - break; - - case 2: labelC = new JLabel(); - labelC.setBounds(new Rectangle(0,30+15*(i+i),25,15)); - if(client.getClientGameState().getPriority() == i){ - labelC.setText("YOU"); - } - else - labelC.setText("C"); - this.add(labelC); - break; - - case 3: labelD = new JLabel(); - labelD.setBounds(new Rectangle(0,30+15*(i+i),25,15)); - if(client.getClientGameState().getPriority() == i){ - labelD.setText("YOU"); - } - else - labelD.setText("D"); - this.add(labelD); - break; - - case 4: labelE = new JLabel(); - labelE.setBounds(new Rectangle(0,30+15*(i+i),25,15)); - if(client.getClientGameState().getPriority() == i){ - labelE.setText("YOU"); - } - else - labelE.setText("E"); - this.add(labelE); - break; - } - } - switch(parameterIndex){ - - case 0 : //add the progress Bbar - this.setBackground(Color.PINK); - titleLabel[0] = new JLabel(); - titleLabel[0].setText("Available Flow Capacity"); - titleLabel[0].setBounds(new Rectangle(60,5,200,20)); - this.add(titleLabel[0],null); - for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ - JProgressBar availableBandwidthProgressBar = new JProgressBar(); - availableBandwidthProgressBar.setMaximum(25); - availableBandwidthProgressBar.setBounds(new Rectangle(40,30+15*(i+i),150,15)); - availableBandwidthProgressBar.setStringPainted(true); - if(i == client.getClientGameState().getPriority()){ - availableBandwidthProgressBar.setForeground(Color.ORANGE); - } - else - availableBandwidthProgressBar.setForeground(new Color(51, 153, 255)); - availableBandwidthProgressBar.setBackground(Color.white); - availableBandwidthProgressBar.setValue(25); - this.add(availableBandwidthProgressBar); - availableBandwidthMap.put(new Integer(i), availableBandwidthProgressBar); - } - break; - - case 1 : //add the number of files downloaded - this.setBackground(Color.WHITE); - titleLabel[1] = new JLabel(); - titleLabel[1].setText("Crops Grown"); - titleLabel[1].setBounds(new Rectangle(60,5,200,20)); - this.add(titleLabel[1],null); - for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ - JLabel filesDownLoaded = new JLabel(); - filesDownLoaded.setFont(new Font("Serif", Font.BOLD, 14)); - if(i == client.getClientGameState().getPriority()){ - filesDownLoaded.setForeground(Color.ORANGE); - } - else - filesDownLoaded.setForeground(new Color(51,153,255)); - filesDownLoaded.setBounds(new Rectangle(132,30+15*(i+i),100,15)); - this.add(filesDownLoaded); - filesDownLoaded.setText(""); - filesDownLoadedMap.put(new Integer(i),filesDownLoaded); - } - break; - - case 2: //add the number of tokens collected - this.setBackground(Color.WHITE); - titleLabel[2] = new JLabel(); - titleLabel[2].setText("Tokens Collected"); - titleLabel[2].setBounds(new Rectangle(60,5,200,20)); - this.add(titleLabel[2],null); - for(int i=0;i<client.getRoundConfiguration().getClientsPerGroup();i++){ - JLabel tokensCollected = new JLabel(); - tokensCollected.setFont(new Font("Comic Sans MS", Font.BOLD, 14)); - if(i == client.getClientGameState().getPriority()){ - tokensCollected.setForeground(Color.ORANGE); - } - else - tokensCollected.setForeground(new Color(51,153,255)); - tokensCollected.setBounds(new Rectangle(132,30+15*(i+i),100,15)); - this.add(tokensCollected); - tokensCollected.setText(""); - tokensCollectedMap.put(new Integer(i),tokensCollected); - } - break; - } - } - - public void update(ClientData clientData) { - // TODO Auto-generated method stub - switch(parameterIndex){ - case 0 : - availableBandwidthMap.get(new Integer(clientData.getPriority())).setValue((int) clientData.getAvailableFlowCapacity()); - break; - - case 1: - filesDownLoadedMap.get(new Integer(clientData.getPriority())).setText(new Integer(clientData.getCropsGrown()).toString()); - break; - - case 2: - tokensCollectedMap.get(new Integer(clientData.getPriority())).setText(new Integer(clientData.getTotalTokensEarned()).toString()); - break; - } - } - - //implement this Later on - public void endRound() { - // TODO Auto-generated method stub - //implement this later on. - } - -} 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-13 17:09:51 UTC (rev 296) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-14 22:10:26 UTC (rev 297) @@ -65,7 +65,7 @@ private double totalContributedBandwidth; - private IrrigationClientGameState clientGameState; + private ClientDataModel clientGameState; private int numberofGates = 6; @@ -79,7 +79,7 @@ //////////////////////////////////////////////////////////////////////////// - public CanalPanel(IrrigationClientGameState clientGameState) { + public CanalPanel(ClientDataModel clientGameState) { super(); //when totalContributed bandwidth = 1.0, you dont see the canal line this.totalContributedBandwidth = clientGameState.getGroupDataModel().getMaximumAvailableFlowCapacity(); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-13 17:09:51 UTC (rev 296) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-14 22:10:26 UTC (rev 297) @@ -130,7 +130,7 @@ // final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); int x,y; - GroupDataModel group = client.getClientGameState().getGroupDataModel(); + GroupDataModel group = client.getClientDataModel().getGroupDataModel(); final int infrastructureEfficiency = group.getInfrastructureEfficiency(); final int actualFlowCapacity = group.getFlowCapacity(); for(y = 0; y <= actualFlowCapacity; y++) { Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java (from rev 296, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClientGameState.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-14 22:10:26 UTC (rev 297) @@ -0,0 +1,109 @@ +/** + * + */ +package edu.asu.commons.irrigation.client; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import edu.asu.commons.event.EventChannel; +import edu.asu.commons.experiment.DataModel; +import edu.asu.commons.irrigation.conf.RoundConfiguration; +import edu.asu.commons.irrigation.events.ClientUpdateEvent; +import edu.asu.commons.irrigation.events.RoundStartedEvent; +import edu.asu.commons.irrigation.server.ClientData; +import edu.asu.commons.irrigation.server.GroupDataModel; +import edu.asu.commons.net.Identifier; + +/** + * $Id$ + * + * The client side data model, simply wraps a GroupDataModel. + * + * @author <a href='mailto:All...@as...'>Allen Lee</a> + * @version $Rev$ + */ +public class ClientDataModel implements DataModel<RoundConfiguration> { + + private static final long serialVersionUID = -3424256672940188027L; + + private GroupDataModel groupDataModel; + + private IrrigationClient client; + + private RoundConfiguration roundConfiguration; + + private int priority = 0; + + private int timeLeft = 0; + + public ClientDataModel(EventChannel channel, IrrigationClient client) { + this.client = client; + } + + public ClientData getClientData() { + return groupDataModel.getClientData( getId() ); + } + + public Identifier getId() { + return client.getId(); + } + + public List<Identifier> getAllClientIdentifiers() { + return new ArrayList<Identifier>(groupDataModel.getClientIdentifiers()); + } + + public synchronized void initialize(RoundStartedEvent event) { + groupDataModel.clear(); + setGroupDataModel(event.getGroupDataModel()); + setTimeLeft( (int) (getRoundConfiguration().getRoundDuration().getDelta() / 1000L) ); + } + + /** + * Setting priority for this client. + */ + public void setPriority(int priority){ + this.priority = priority; + } + + public int getPriority(){ + return priority; + } + + public void update(ClientUpdateEvent clientUpdateEvent) { + setGroupDataModel(clientUpdateEvent.getGroupDataModel()); + setTimeLeft(clientUpdateEvent.getTimeLeft()); + } + + public void setTimeLeft(int timeLeft) { + this.timeLeft = timeLeft; + } + + public int getTimeLeft() { + return timeLeft; + } + + public RoundConfiguration getRoundConfiguration() { + return roundConfiguration; + } + + public void setRoundConfiguration(RoundConfiguration roundConfiguration) { + this.roundConfiguration = roundConfiguration; + } + + public void setGroupDataModel(GroupDataModel groupDataModel) { + this.groupDataModel = groupDataModel; + setRoundConfiguration(groupDataModel.getRoundConfiguration()); + } + + public GroupDataModel getGroupDataModel() { + return groupDataModel; + } + + public Map<Identifier, ClientData> getClientDataMap() { + return groupDataModel.getClientDataMap(); + } + + +} 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-13 17:09:51 UTC (rev 296) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-14 22:10:26 UTC (rev 297) @@ -1,6 +1,7 @@ package edu.asu.commons.irrigation.client; import java.awt.BorderLayout; +import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -25,7 +26,6 @@ import javax.swing.SwingUtilities; import javax.swing.Timer; -import edu.asu.commons.event.EventChannel; import edu.asu.commons.irrigation.conf.RoundConfiguration; import edu.asu.commons.irrigation.conf.ServerConfiguration; import edu.asu.commons.irrigation.events.EndRoundEvent; @@ -39,6 +39,7 @@ /** * $Id$ * + * The root experiment window placed in the client's JFrame. * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev$ @@ -47,16 +48,12 @@ private static final long serialVersionUID = -5636795631355367711L; - private IrrigationClientGameState state; + private ClientDataModel clientDataModel; - private Component currentCenterComponent; - private JScrollPane instructionsScrollPane; private HtmlEditorPane instructionsEditorPane; - private JPanel subjectWindow; - private JPanel tokenScreenPanel = null; private JPanel graphPanel; @@ -69,9 +66,9 @@ private IrrigationClient client; - private MainIrrigationGameWindow mainIrrigationWindow; + private IrrigationGamePanel irrigationGamePanel; - private StringBuilder instructionsBuilder = new StringBuilder(); // @jve:decl-index=0: + private StringBuilder instructionsBuilder = new StringBuilder(); private int totalContributedTokensPerGroup; @@ -79,104 +76,98 @@ private JButton nextButton; - private JPanel navigationPane; + private JPanel instructionsNavigationPanel; private JButton previousButton; - private JPanel welcomeInstructionsPane; + private JPanel instructionsPanel; private int instructionNumber = 1; private JPanel submitTokenPanel; - private EventChannel channel; + private HtmlEditorPane tokenInstructionsEditorPane; - private HtmlEditorPane tokenInstructionsEditorPane; + private JScrollPane tokenInstructionsScrollPane; - private JScrollPane tokenInstructionsScrollPane; + private int NUMBER_INSTRUCTIONS = 9; - private int NUMBER_INSTRUCTIONS = 9; + private JLabel quizLabel; - private JLabel quizLabel; - - private JLabel quizAnimationLabel = new JLabel(); - - private int pagesTraversed = 0; + private JLabel quizAnimationLabel = new JLabel(); - private JPanel animationInstructionPanel; + private int pagesTraversed = 0; - private JPanel animationPanel; - - private JPanel navigationAnimationPanel; + private JPanel animationInstructionPanel; - private JButton nextAnimationButton; + private JPanel animationPanel; - private JButton previousAnimationButton; + private JPanel navigationAnimationPanel; - private HtmlEditorPane animationInstructionsEditorPane; + private JButton nextAnimationButton; - private JScrollPane animationInstructionsScrollPane; + private JButton previousAnimationButton; - private JPanel chartPanel; + private HtmlEditorPane animationInstructionsEditorPane; - private PieChart pieChart; + private JScrollPane animationInstructionsScrollPane; - public ClientData clientData; + private JPanel chartPanel; - private CanalAnimationPanel canalPanelAnimationNew; + private PieChart pieChart; + public ClientData clientData; + + private CanalAnimationPanel canalAnimationPanel; + + private CardLayout cardLayout; + + private JLabel infrastructureEfficiencyLabel = new JLabel("Current infrastructure efficiency: "); + public ExperimentGameWindow(Dimension screenSize, IrrigationClient client) { this.client = client; - this.state = client.getClientGameState(); + this.clientDataModel = client.getClientDataModel(); // FIXME: set the actual screen size dimensions after this JPanel has // been initialized... // this.screenSize = getParent().getSize(); - this.channel = client.getEventChannel(); // feed subject view the available screen size so that // it can adjust appropriately when given a board size - mainIrrigationWindow = new MainIrrigationGameWindow(screenSize, client); - initGuiComponents(); + initGuiComponents(screenSize); } - private void initGuiComponents() { - setLayout(new BorderLayout()); - instructionsEditorPane = createInstructionsEditorPane(); - instructionsScrollPane = new JScrollPane(instructionsEditorPane); + private void initGuiComponents(Dimension screenSize) { + cardLayout = new CardLayout(); + setLayout(cardLayout); + + instructionsScrollPane = new JScrollPane(getInstructionsEditorPane()); instructionsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); instructionsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - // getting the initial general instructions + // create a quiz listener and then initialize the instructions. instructionsEditorPane.setActionListener(createQuizListener(client.getServerConfiguration())); instructionsEditorPane.setCaretPosition(0); setInstructions(getGeneralInstructions(0)); - addCenterComponent(getWelcomeInstructionsPane()); - add(getWelcomeInstructionsPane(), BorderLayout.CENTER); - /*setInstructions(getGeneralInstructions(1)); - currentCenterComponent = WelcomeInstructionPane; - *///currentCenterComponent = getWelcomeInstructionPane(); - // setup the Subject Window, add the experiment view - subjectWindow = new JPanel(new BorderLayout(4, 4)); - subjectWindow.setBackground(Color.WHITE); - subjectWindow.setForeground(Color.BLACK); - subjectWindow.add(mainIrrigationWindow, BorderLayout.CENTER); - // setup the SubmitToken View, add the Submit token View - setBackground(Color.WHITE); + + add(getInstructionsPanel(), getInstructionsPanel().getName()); + irrigationGamePanel = new IrrigationGamePanel(screenSize, client); + add(irrigationGamePanel, irrigationGamePanel.getName()); + // add any other panels that need to be switched out. + // FIXME: see if we can simplify the number of instructions panes that Sanket has created. + add(getInstructionsEditorPane()); } - private JLabel infrastructureEfficiencyLabel = new JLabel("Current infrastructure efficiency: "); - - private JPanel getTokenScreenPanel() { + private JPanel getTokenScreenPanel() { if (tokenScreenPanel == null) { - tokenScreenPanel = new JPanel(); + tokenScreenPanel = new JPanel(); tokenScreenPanel.setLayout(new BorderLayout()); tokenInstructionsEditorPane = createInstructionsEditorPane(); tokenInstructionsScrollPane = new JScrollPane(tokenInstructionsEditorPane); tokenScreenPanel.add(tokenInstructionsScrollPane, BorderLayout.CENTER); //setInstructions(getGeneralInstructions(11)); -// StringBuilder tokenSubmissionInstructionsBuilder = new StringBuilder("<h3>The current infrastructure efficiency is: "); -// -// tokenSubmissionInstructionsBuilder.append("% </h3>"); -// tokenSubmissionInstructionsBuilder.append( + // StringBuilder tokenSubmissionInstructionsBuilder = new StringBuilder("<h3>The current infrastructure efficiency is: "); + // + // tokenSubmissionInstructionsBuilder.append("% </h3>"); + // tokenSubmissionInstructionsBuilder.append( StringBuilder tokenSubmissionInstructionsBuilder = new StringBuilder(getGeneralInstructions(11, pagesTraversed)); tokenInstructionsEditorPane.setText(tokenSubmissionInstructionsBuilder.toString()); tokenInstructionsEditorPane.setCaretPosition(0); @@ -188,22 +179,22 @@ updateInfrastructureEfficiencyLabel(); return tokenScreenPanel; } - - public void updateInfrastructureEfficiencyLabel() { - GroupDataModel group = client.getClientGameState().getGroupDataModel(); - RoundConfiguration roundConfiguration = client.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()); - infrastructureEfficiency = group.getInfrastructureEfficiency() - roundConfiguration.getInfrastructureDegradationFactor(); - } - infrastructureEfficiencyLabel.setText("Current infrastructure efficiency: " + infrastructureEfficiency); - infrastructureEfficiencyLabel.repaint(); - } + public void updateInfrastructureEfficiencyLabel() { + GroupDataModel group = client.getClientDataModel().getGroupDataModel(); + RoundConfiguration roundConfiguration = client.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()); + infrastructureEfficiency = group.getInfrastructureEfficiency() - roundConfiguration.getInfrastructureDegradationFactor(); + } + infrastructureEfficiencyLabel.setText("Current infrastructure efficiency: " + infrastructureEfficiency); + infrastructureEfficiencyLabel.repaint(); + } + private JPanel getSubmitTokenPanel() { if (submitTokenPanel == null) { submitTokenPanel = new JPanel(); @@ -215,27 +206,29 @@ return submitTokenPanel; } - private JPanel getWelcomeInstructionsPane() { - if (welcomeInstructionsPane == null) { - welcomeInstructionsPane = new JPanel(); - welcomeInstructionsPane.setLayout(new BorderLayout()); - welcomeInstructionsPane.add(instructionsScrollPane, BorderLayout.CENTER); - welcomeInstructionsPane.add(getNavigationButtonPane(), BorderLayout.SOUTH); - } - return welcomeInstructionsPane; + private JPanel getInstructionsPanel() { + if (instructionsPanel == null) { + instructionsPanel = new JPanel(); + instructionsPanel.setName("General instructions panel"); + instructionsPanel.setLayout(new BorderLayout()); + instructionsPanel.add(instructionsScrollPane, BorderLayout.CENTER); + instructionsPanel.add(getInstructionsNavigationPanel(), BorderLayout.PAGE_END); + } + return instructionsPanel; } - private JPanel getNavigationButtonPane() { - if (navigationPane == null) { - navigationPane = new JPanel(); - navigationPane.setLayout(new BorderLayout()); - navigationPane.add(getNextButton(), BorderLayout.EAST); - navigationPane.add(getPreviousButton(), BorderLayout.WEST); + private JPanel getInstructionsNavigationPanel() { + if (instructionsNavigationPanel == null) { + instructionsNavigationPanel = new JPanel(); + instructionsNavigationPanel.setLayout(new BorderLayout()); + instructionsNavigationPanel.add(getNextButton(), BorderLayout.LINE_START); + instructionsNavigationPanel.add(getPreviousButton(), BorderLayout.LINE_END); + // this is just to add spacing I think. quizLabel = new JLabel(); - navigationPane.add(quizLabel, BorderLayout.CENTER); + instructionsNavigationPanel.add(quizLabel, BorderLayout.CENTER); } - return navigationPane; + return instructionsNavigationPanel; } private JButton getNextButton() { @@ -244,15 +237,15 @@ nextButton.setText("Next"); nextButton.setEnabled(false); nextButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); - - previousButton.setEnabled(true); - if(instructionNumber >= pagesTraversed){ - nextButton.setEnabled(false); - } - - // getting the next instruction Number + public void actionPerformed(java.awt.event.ActionEvent e) { + quizLabel.setText(""); + + previousButton.setEnabled(true); + if(instructionNumber >= pagesTraversed){ + nextButton.setEnabled(false); + } + + // getting the next instruction Number if (instructionNumber == NUMBER_INSTRUCTIONS) { } @@ -261,122 +254,123 @@ System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); if(instructionNumber == 5){ - quizAnimationLabel.setText(""); - addCenterComponent(getAnimationInstructionPane()); - //addCenterComponent(getTokenScreenPanel()); + quizAnimationLabel.setText(""); + addCenterComponent(getAnimationInstructionPane()); + //addCenterComponent(getTokenScreenPanel()); } else { - addCenterComponent(getWelcomeInstructionsPane()); + addCenterComponent(getInstructionsPanel()); } } - + }); } return nextButton; } - private JPanel getAnimationInstructionPane() { + private JPanel getAnimationInstructionPane() { if (animationInstructionPanel == null) { - animationInstructionPanel = new JPanel(); + animationInstructionPanel = new JPanel(); + animationInstructionPanel.setName("Animated instruction panel"); animationInstructionPanel.setLayout(new BorderLayout()); - animationInstructionPanel.add(getAnimationPane(), BorderLayout.CENTER); - + animationInstructionPanel.add(getAnimationPane(), BorderLayout.CENTER); + animationInstructionPanel.add(getNavigationAnimationPanel(), BorderLayout.SOUTH); animationInstructionPanel.setBackground(Color.WHITE); return animationInstructionPanel; } //System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); animationInstructionsEditorPane.setText(getGeneralInstructions(instructionNumber,pagesTraversed)); - return animationInstructionPanel; - } - - + return animationInstructionPanel; + } + + private JPanel getNavigationAnimationPanel() { if (navigationAnimationPanel == null) { - + navigationAnimationPanel = new JPanel(); navigationAnimationPanel.setLayout(new BorderLayout()); navigationAnimationPanel.add(getNextAnimationButton(), BorderLayout.EAST); navigationAnimationPanel.add(getPreviousAnimationButton(), BorderLayout.WEST); - + quizAnimationLabel.setText(""); navigationAnimationPanel.add(quizAnimationLabel, BorderLayout.CENTER); } return navigationAnimationPanel; - } + } - private JButton getPreviousAnimationButton() { - if (previousAnimationButton == null) { - previousAnimationButton = new JButton(); - previousAnimationButton.setText("Previous"); - previousAnimationButton.setEnabled(true); - previousAnimationButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); - // getting the next instruction Number - nextButton.setEnabled(true); - if (instructionNumber == 1) { - - } else - instructionNumber--; - if(instructionNumber > 1) - previousButton.setEnabled(true); - else - previousButton.setEnabled(false); - System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); - setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - addCenterComponent(getWelcomeInstructionsPane()); - } - }); - return previousAnimationButton; + private JButton getPreviousAnimationButton() { + if (previousAnimationButton == null) { + previousAnimationButton = new JButton(); + previousAnimationButton.setText("Previous"); + previousAnimationButton.setEnabled(true); + previousAnimationButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + quizLabel.setText(""); + // getting the next instruction Number + nextButton.setEnabled(true); + if (instructionNumber == 1) { - } - return previousAnimationButton; - } + } else + instructionNumber--; + if(instructionNumber > 1) + previousButton.setEnabled(true); + else + previousButton.setEnabled(false); + System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); + setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); + addCenterComponent(getInstructionsPanel()); + } + }); + return previousAnimationButton; - private JButton getNextAnimationButton() { - if (nextAnimationButton == null) { - nextAnimationButton = new JButton(); - nextAnimationButton.setText("Next"); - nextAnimationButton.setEnabled(false); - nextAnimationButton.addActionListener(new java.awt.event.ActionListener() { - + } + return previousAnimationButton; + } - public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); - previousButton.setEnabled(true); - if(instructionNumber >= pagesTraversed) - nextButton.setEnabled(false); - // getting the next instruction Number - if (instructionNumber != NUMBER_INSTRUCTIONS) { - instructionNumber++; - } - System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); - setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - if(instructionNumber == 5){ - addCenterComponent(getAnimationInstructionPane()); - //addCenterComponent(getTokenScreenPanel()); - } - else - addCenterComponent(getWelcomeInstructionsPane()); - } - - }); + private JButton getNextAnimationButton() { + if (nextAnimationButton == null) { + nextAnimationButton = new JButton(); + nextAnimationButton.setText("Next"); + nextAnimationButton.setEnabled(false); + nextAnimationButton.addActionListener(new java.awt.event.ActionListener() { - } - return nextAnimationButton; - - } - private JPanel getAnimationPane() { + public void actionPerformed(java.awt.event.ActionEvent e) { + quizLabel.setText(""); + previousButton.setEnabled(true); + if(instructionNumber >= pagesTraversed) + nextButton.setEnabled(false); + // getting the next instruction Number + if (instructionNumber != NUMBER_INSTRUCTIONS) { + instructionNumber++; + } + System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); + setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); + if(instructionNumber == 5){ + addCenterComponent(getAnimationInstructionPane()); + //addCenterComponent(getTokenScreenPanel()); + } + else + addCenterComponent(getInstructionsPanel()); + } + + }); + + } + return nextAnimationButton; + + } + + private JPanel getAnimationPane() { if (animationPanel == null) { - animationPanel = new JPanel(); - animationPanel.setLayout(new BorderLayout()); - //FIXME: Here the animation panel needs to be decided on fly - //canalPanelAnimation = new CanalPanelAnimation(40); - canalPanelAnimationNew = new CanalAnimationPanel(40); - animationPanel.add(canalPanelAnimationNew,BorderLayout.CENTER); + animationPanel = new JPanel(); + animationPanel.setLayout(new BorderLayout()); + //FIXME: Here the animation panel needs to be decided on fly + //canalPanelAnimation = new CanalPanelAnimation(40); + canalAnimationPanel = new CanalAnimationPanel(40); + animationPanel.add(canalAnimationPanel,BorderLayout.CENTER); animationInstructionsEditorPane = createInstructionsEditorPane(); animationInstructionsScrollPane = new JScrollPane(animationInstructionsEditorPane); animationInstructionsEditorPane.setActionListener(createQuizListener(client.getServerConfiguration())); @@ -390,38 +384,38 @@ animationPanel.setBackground(Color.WHITE); return animationPanel; } - + return animationPanel; - } + } - private JButton getPreviousButton() { + private JButton getPreviousButton() { if (previousButton == null) { previousButton = new JButton(); previousButton.setText("Previous"); previousButton.setEnabled(false); previousButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); + quizLabel.setText(""); // getting the next instruction Number - nextButton.setEnabled(true); + nextButton.setEnabled(true); if (instructionNumber == 1) { - + } else instructionNumber--; if(instructionNumber > 1) - previousButton.setEnabled(true); + previousButton.setEnabled(true); else - previousButton.setEnabled(false); + previousButton.setEnabled(false); System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); if(instructionNumber == 5){ - quizAnimationLabel.setText(""); - nextAnimationButton.setEnabled(true); - addCenterComponent(getAnimationInstructionPane()); - //addCenterComponent(getTokenScreenPanel()); + quizAnimationLabel.setText(""); + nextAnimationButton.setEnabled(true); + addCenterComponent(getAnimationInstructionPane()); + //addCenterComponent(getTokenScreenPanel()); } else - addCenterComponent(getWelcomeInstructionsPane()); + addCenterComponent(getInstructionsPanel()); } }); return previousButton; @@ -438,31 +432,31 @@ * @return */ private String getGeneralInstructions(int pageNumber, int pagesTraversed) { - /*if(pageNumber == 2){ + /*if(pageNumber == 2){ if(client.getClientGameState().getPriority()== 0) return client.getServerConfiguration().getGeneralInstructions(20); else return client.getServerConfiguration().getGeneralInstructions(21); }*/ - + return client.getServerConfiguration().getGeneralInstructions(pageNumber,pagesTraversed, - client.getClientGameState().getPriority()); + client.getClientDataModel().getPriority()); } - + private String getGeneralInstructions(int pageNumber) { - return client.getServerConfiguration().getGeneralInstructions(pageNumber); - } + return client.getServerConfiguration().getGeneralInstructions(pageNumber); + } private JTextField getEnterTokens() { if (enterTokens == null) { enterTokens = new JTextField(); enterTokens.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - submitInvestedTokens(); - } + public void actionPerformed(ActionEvent event) { + submitInvestedTokens(); + } }); } - + return enterTokens; } @@ -473,15 +467,15 @@ submitTokensButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { try{ - submitInvestedTokens(); + submitInvestedTokens(); } - catch(NumberFormatException e1){ - enterTokens.setText(""); + catch(NumberFormatException e1){ + enterTokens.setText(""); instructionsBuilder.delete(0, instructionsBuilder.length()); instructionsBuilder.append("\nPlease Enter your tokens within the range 0 -10"); instructionsBuilder.append(getGeneralInstructions(11,pagesTraversed)); tokenInstructionsEditorPane.setText(instructionsBuilder.toString()); - } + } } @@ -490,18 +484,14 @@ } return submitTokensButton; } - + private void submitInvestedTokens() throws NumberFormatException { - int token = Integer.parseInt(enterTokens.getText()); - // validating token range + int token = Integer.parseInt(enterTokens.getText()); + // validating token range if (token >= 0 && token <= 10) { - client.transmitTokenContributed(token); + client.transmitTokenContributed(token); updateInstructions("Please wait while the server computes your total flow capacity based on your group's total token contribution investment."); - addCenterComponent(instructionsEditorPane); - - /* setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - addCenterComponent(getWelcomeInstructionPane());*/ - + addCenterComponent(getInstructionsEditorPane()); } else { enterTokens.setText(""); @@ -514,30 +504,39 @@ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// - private HtmlEditorPane createInstructionsEditorPane() { + private HtmlEditorPane getInstructionsEditorPane() { // JEditorPane pane = new JEditorPane("text/html", // "Costly Sanctioning Experiment"); - final HtmlEditorPane htmlPane = new HtmlEditorPane(); - htmlPane.setPreferredSize(new Dimension(400, 400)); - htmlPane.setEditable(false); - htmlPane.setFont(new Font("serif", Font.PLAIN, 12)); - return htmlPane; + if (instructionsEditorPane == null) { + instructionsEditorPane = createInstructionsEditorPane(); + } + return instructionsEditorPane; } - + private HtmlEditorPane createInstructionsEditorPane() { + HtmlEditorPane htmlEditorPane = new HtmlEditorPane(); + htmlEditorPane.setPreferredSize(new Dimension(400, 400)); + htmlEditorPane.setEditable(false); + htmlEditorPane.setFont(new Font("serif", Font.PLAIN, 12)); + return htmlEditorPane; + } + + + private void addCenterComponent(Component newCenterComponent) { - if (currentCenterComponent != null) { - currentCenterComponent.setVisible(false); - remove(currentCenterComponent); - add(newCenterComponent, BorderLayout.CENTER); - newCenterComponent.setVisible(true); - invalidate(); - validate(); - newCenterComponent.repaint(); - repaint(); - } - currentCenterComponent = newCenterComponent; + cardLayout.show(this, newCenterComponent.getName()); + // if (currentCenterComponent != null) { + // currentCenterComponent.setVisible(false); + // remove(currentCenterComponent); + // add(newCenterComponent, BorderLayout.CENTER); + // newCenterComponent.setVisible(true); + // invalidate(); + // validate(); + // newCenterComponent.repaint(); + // repaint(); + // } + // currentCenterComponent = newCenterComponent; } public void startRound(final RoundConfiguration configuration) { @@ -545,9 +544,9 @@ // currentExperimentConfiguration = configuration; Runnable runnable = new Runnable() { public void run() { - addCenterComponent(subjectWindow); +// addCenterComponent(subjectWindow); requestFocusInWindow(); - + } }; SwingUtilities.invokeLater(runnable); @@ -558,11 +557,11 @@ * rid of the sendContributionStatus then */ public void updateContributions() { - mainIrrigationWindow.updateContributions(state); + irrigationGamePanel.updateContributions(clientDataModel); } public void update() { - mainIrrigationWindow.updateClientStatus(state); + irrigationGamePanel.updateClientStatus(clientDataModel); } /* @@ -570,8 +569,7 @@ * instructionsScrollPane with the debreifing information */ public void updateEndRoundEvent(final EndRoundEvent event) { - // TODO Auto-generated method stub - mainIrrigationWindow.updateEndRoundEvent(); + irrigationGamePanel.endRound(); Runnable runnable = new Runnable() { public void run() { enterTokens.setText(""); @@ -598,58 +596,58 @@ private void addDebriefingText(EndRoundEvent event) { instructionsBuilder.delete(0, instructionsBuilder.length()); - + Map<Identifier,ClientData>clientDataMap = event.getClientDataMap(); - + //create a map of clientData based on priority as the index structure Map<Integer,ClientData>clientDataMapIndexInteger = new LinkedHashMap<Integer,ClientData>(); - - String position = "Your Position is :"; - position = position+mapClientPosition(client.getClientGameState().getPriority()); + + String position = "Your position is :"; + position = position+mapClientPosition(client.getClientDataModel().getPriority()); for(ClientData clientData : clientDataMap.values()){ - clientDataMapIndexInteger.put(new Integer(clientData.getPriority()), clientData); + clientDataMapIndexInteger.put(new Integer(clientData.getPriority()), clientData); } // FIXME: this is horrendous instructionsBuilder.append(String.format( - position+ - "<table><thead><th></th><th></th><th>A</th><th></th><th>B</th><th></th><th>C</th><th></th><th>D</th><th></th><th>E</th></thead><tbody>"+ - "<tr><td>A Initial endowment</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td></tr>"+ - "<tr><td>B Infrastructure investment</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>C Kept endowment (A - B)</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>D Return from growing crops</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>E Total tokens earned in last round(D+C)</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>F Total dollars earned in this round (E*0.1$)</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td></tr>", - clientDataMapIndexInteger.get(new Integer(0)).getContributedTokens(), - clientDataMapIndexInteger.get(new Integer(1)).getContributedTokens(), - clientDataMapIndexInteger.get(new Integer(2)).getContributedTokens(), - clientDataMapIndexInteger.get(new Integer(3)).getContributedTokens(), - clientDataMapIndexInteger.get(new Integer(4)).getContributedTokens(), - - 10 - clientDataMapIndexInteger.get(new Integer(0)).getContributedTokens(), - 10 - clientDataMapIndexInteger.get(new Integer(1)).getContributedTokens(), - 10 - clientDataMapIndexInteger.get(new Integer(2)).getContributedTokens(), - 10 - clientDataMapIndexInteger.get(new Integer(3)).getContributedTokens(), - 10 - clientDataMapIndexInteger.get(new Integer(4)).getContributedTokens(), - - clientDataMapIndexInteger.get(new Integer(0)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(0)).getContributedTokens()), - clientDataMapIndexInteger.get(new Integer(1)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(1)).getContributedTokens()), - clientDataMapIndexInteger.get(new Integer(2)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(2)).getContributedTokens()), - clientDataMapIndexInteger.get(new Integer(3)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(3)).getContributedTokens()), - clientDataMapIndexInteger.get(new Integer(4)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(4)).getContributedTokens()), - - clientDataMapIndexInteger.get(new Integer(0)).getTotalTokensEarned(), - clientDataMapIndexInteger.get(new Integer(1)).getTotalTokensEarned(), - clientDataMapIndexInteger.get(new Integer(2)).getTotalTokensEarned(), - clientDataMapIndexInteger.get(new Integer(3)).getTotalTokensEarned(), - clientDataMapIndexInteger.get(new Integer(4)).getTotalTokensEarned(), - - (float)clientDataMapIndexInteger.get(new Integer(0)).getRoundConfiguration().getDollarsPerToken()*clientDataMapIndexInteger.get(new Integer(0)).getTotalTokensEarned(), - (float)clientDataMapIndexInteger.get(new Integer(1)).getRoundConfiguration().getDollarsPerToken()*clientDataMapIndexInteger.get(new Integer(1)).getTotalTokensEarned(), - (float)clientDataMapIndexInteger.get(new Integer(2)).getRoundConfiguration().getDollarsPerToken()*clientDataMapIndexInteger.get(new Integer(2)).getTotalTokensEarned(), - (float)clientDataMapIndexInteger.get(new Integer(3)).getRoundConfiguration().getDollarsPerToken()*clientDataMapIndexInteger.get(new Integer(3)).getTotalTokensEarned(), - (float)clientDataMapIndexInteger.get(new Integer(4)).getRoundConfiguration().getDollarsPerToken()*clientDataMapIndexInteger.get(new Integer(4)).getTotalTokensEarned() - - /* + position+ + "<table><thead><th></th><th></th><th>A</th><th></th><th>B</th><th></th><th>C</th><th></th><th>D</th><th></th><th>E</th></thead><tbody>"+ + "<tr><td>A Initial endowment</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td></tr>"+ + "<tr><td>B Infrastructure investment</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ + "<tr><td>C Kept endowment (A - B)</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ + "<tr><td>D Return from growing crops</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ + "<tr><td>E Total tokens earned in last round(D+C)</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ + "<tr><td>F Total dollars earned in this round (E*0.1$)</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td></tr>", + clientDataMapIndexInteger.get(new Integer(0)).getContributedTokens(), + clientDataMapIndexInteger.get(new Integer(1)).getContributedTokens(), + clientDataMapIndexInteger.get(new Integer(2)).getContributedTokens(), + clientDataMapIndexInteger.get(new Integer(3)).getContributedTokens(), + clientDataMapIndexInteger.get(new Integer(4)).getContributedTokens(), + + 10 - clientDataMapIndexInteger.get(new Integer(0)).getContributedTokens(), + 10 - clientDataMapIndexInteger.get(new Integer(1)).getContributedTokens(), + 10 - clientDataMapIndexInteger.get(new Integer(2)).getContributedTokens(), + 10 - clientDataMapIndexInteger.get(new Integer(3)).getContributedTokens(), + 10 - clientDataMapIndexInteger.get(new Integer(4)).getContributedTokens(), + + clientDataMapIndexInteger.get(new Integer(0)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(0)).getContributedTokens()), + clientDataMapIndexInteger.get(new Integer(1)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(1)).getContributedTokens()), + clientDataMapIndexInteger.get(new Integer(2)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(2)).getContributedTokens()), + clientDataMapIndexInteger.get(new Integer(3)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(3)).getContributedTokens()), + clientDataMapIndexInteger.get(new Integer(4)).getTotalTokensEarned() - (10 - clientDataMapIndexInteger.get(new Integer(4)).getContributedTokens()), + + clientDataMapIndexInteger.get(new Integer(0)).getTotalTokensEarned(), + clientDataMapIndexInteger.get(new Integer(1)).getTotalTokensEarned(), + clientDataMapIndexInteger.get(new Integer(2)).getTotalTokensEarned(), + clientDataMapIndexInteger.get(new Integer(3)).getTotalTokensEarned(), + clientDataMapIndexInteger.get(new Integer(4)).getTotalTokensEarned(), + + (float)clientDataMapIndexInteger.g... [truncated message content] |
From: <al...@us...> - 2009-10-15 00:15:18
|
Revision: 298 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=298&view=rev Author: alllee Date: 2009-10-15 00:12:05 +0000 (Thu, 15 Oct 2009) Log Message: ----------- initial general instructions appears to work with new CardLayout. Modified Paths: -------------- 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/conf/ServerConfiguration.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-10-14 22:10:26 UTC (rev 297) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-15 00:12:05 UTC (rev 298) @@ -58,7 +58,7 @@ private JPanel graphPanel; - private JTextField enterTokens; + private JTextField tokenEntryTextField; private JButton submitTokensButton; @@ -147,15 +147,18 @@ instructionsEditorPane.setCaretPosition(0); setInstructions(getGeneralInstructions(0)); - add(getInstructionsPanel(), getInstructionsPanel().getName()); + addToCardLayout(getInstructionsPanel()); irrigationGamePanel = new IrrigationGamePanel(screenSize, client); - add(irrigationGamePanel, irrigationGamePanel.getName()); + addToCardLayout(irrigationGamePanel); // add any other panels that need to be switched out. // FIXME: see if we can simplify the number of instructions panes that Sanket has created. - add(getInstructionsEditorPane()); +// addToCardLayout(getInstructionsEditorPane()); } + + private void addToCardLayout(Component component) { + add(component, component.getName()); + } - private JPanel getTokenScreenPanel() { if (tokenScreenPanel == null) { tokenScreenPanel = new JPanel(); @@ -199,7 +202,7 @@ if (submitTokenPanel == null) { submitTokenPanel = new JPanel(); submitTokenPanel.setLayout(new BorderLayout()); - submitTokenPanel.add(getEnterTokens(), BorderLayout.CENTER); + submitTokenPanel.add(getTokenEntryTextField(), BorderLayout.CENTER); submitTokenPanel.add(getSubmitTokensButton(), BorderLayout.EAST); return submitTokenPanel; } @@ -222,8 +225,8 @@ if (instructionsNavigationPanel == null) { instructionsNavigationPanel = new JPanel(); instructionsNavigationPanel.setLayout(new BorderLayout()); - instructionsNavigationPanel.add(getNextButton(), BorderLayout.LINE_START); - instructionsNavigationPanel.add(getPreviousButton(), BorderLayout.LINE_END); + instructionsNavigationPanel.add(getPreviousButton(), BorderLayout.LINE_START); + instructionsNavigationPanel.add(getNextButton(), BorderLayout.LINE_END); // this is just to add spacing I think. quizLabel = new JLabel(); instructionsNavigationPanel.add(quizLabel, BorderLayout.CENTER); @@ -310,21 +313,14 @@ quizLabel.setText(""); // getting the next instruction Number nextButton.setEnabled(true); - if (instructionNumber == 1) { - - } else + if (instructionNumber > 1) { instructionNumber--; - if(instructionNumber > 1) - previousButton.setEnabled(true); - else - previousButton.setEnabled(false); - System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); + } + previousButton.setEnabled( instructionNumber > 1 ); setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); addCenterComponent(getInstructionsPanel()); } }); - return previousAnimationButton; - } return previousAnimationButton; } @@ -334,10 +330,8 @@ nextAnimationButton = new JButton(); nextAnimationButton.setText("Next"); nextAnimationButton.setEnabled(false); - nextAnimationButton.addActionListener(new java.awt.event.ActionListener() { - - - public void actionPerformed(java.awt.event.ActionEvent e) { + nextAnimationButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { quizLabel.setText(""); previousButton.setEnabled(true); if(instructionNumber >= pagesTraversed) @@ -352,12 +346,11 @@ addCenterComponent(getAnimationInstructionPane()); //addCenterComponent(getTokenScreenPanel()); } - else + else { addCenterComponent(getInstructionsPanel()); + } } - }); - } return nextAnimationButton; @@ -398,47 +391,35 @@ quizLabel.setText(""); // getting the next instruction Number nextButton.setEnabled(true); - if (instructionNumber == 1) { - - } else + if (instructionNumber != 1) { instructionNumber--; - if(instructionNumber > 1) - previousButton.setEnabled(true); - else - previousButton.setEnabled(false); + } + previousButton.setEnabled(instructionNumber > 1); System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - if(instructionNumber == 5){ + if(instructionNumber == 5) { quizAnimationLabel.setText(""); nextAnimationButton.setEnabled(true); addCenterComponent(getAnimationInstructionPane()); //addCenterComponent(getTokenScreenPanel()); } - else + else { addCenterComponent(getInstructionsPanel()); + } } }); - return previousButton; - } return previousButton; } /** - * This returns the string of general instructions from the round0.xml files + * This returns the string of general instructions from the irrigation.xml file * where the general instructions are stored * @param pagesTraversed * * @return */ private String getGeneralInstructions(int pageNumber, int pagesTraversed) { - /*if(pageNumber == 2){ - if(client.getClientGameState().getPriority()== 0) - return client.getServerConfiguration().getGeneralInstructions(20); - else - return client.getServerConfiguration().getGeneralInstructions(21); - }*/ - return client.getServerConfiguration().getGeneralInstructions(pageNumber,pagesTraversed, client.getClientDataModel().getPriority()); } @@ -447,17 +428,11 @@ return client.getServerConfiguration().getGeneralInstructions(pageNumber); } - private JTextField getEnterTokens() { - if (enterTokens == null) { - enterTokens = new JTextField(); - enterTokens.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - submitInvestedTokens(); - } - }); + private JTextField getTokenEntryTextField() { + if (tokenEntryTextField == null) { + tokenEntryTextField = new JTextField(); } - - return enterTokens; + return tokenEntryTextField; } private JButton getSubmitTokensButton() { @@ -470,31 +445,29 @@ submitInvestedTokens(); } catch(NumberFormatException e1){ - enterTokens.setText(""); + tokenEntryTextField.setText(""); instructionsBuilder.delete(0, instructionsBuilder.length()); - instructionsBuilder.append("\nPlease Enter your tokens within the range 0 -10"); + instructionsBuilder.append("\nYou only have between 0 and 10 to invest. Please choose a number between 0 and 10 and try again."); instructionsBuilder.append(getGeneralInstructions(11,pagesTraversed)); +// setInstructions(instructionsBuilder.toString()); tokenInstructionsEditorPane.setText(instructionsBuilder.toString()); } } - - }); - return submitTokensButton; } return submitTokensButton; } private void submitInvestedTokens() throws NumberFormatException { - int token = Integer.parseInt(enterTokens.getText()); + int token = Integer.parseInt(tokenEntryTextField.getText()); // validating token range if (token >= 0 && token <= 10) { client.transmitTokenContributed(token); - updateInstructions("Please wait while the server computes your total flow capacity based on your group's total token contribution investment."); + setInstructions("Please wait while the server computes your total flow capacity based on your group's total token contribution investment."); addCenterComponent(getInstructionsEditorPane()); } else { - enterTokens.setText(""); + tokenEntryTextField.setText(""); instructionsBuilder.delete(0, instructionsBuilder.length()); instructionsBuilder.append("\nPlease Enter your tokens within the range 0 - 10"); instructionsBuilder.append(getGeneralInstructions(11,pagesTraversed)); @@ -505,10 +478,9 @@ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// private HtmlEditorPane getInstructionsEditorPane() { - // JEditorPane pane = new JEditorPane("text/html", - // "Costly Sanctioning Experiment"); if (instructionsEditorPane == null) { instructionsEditorPane = createInstructionsEditorPane(); + instructionsEditorPane.setName("Instructions editor pane"); } return instructionsEditorPane; } @@ -522,8 +494,6 @@ } - - private void addCenterComponent(Component newCenterComponent) { cardLayout.show(this, newCenterComponent.getName()); // if (currentCenterComponent != null) { @@ -537,6 +507,7 @@ // repaint(); // } // currentCenterComponent = newCenterComponent; + repaint(); } public void startRound(final RoundConfiguration configuration) { @@ -572,7 +543,7 @@ irrigationGamePanel.endRound(); Runnable runnable = new Runnable() { public void run() { - enterTokens.setText(""); + tokenEntryTextField.setText(""); addDebriefingText(event); // generate debriefing text from data culled from the Event addCenterComponent(instructionsEditorPane); @@ -671,13 +642,12 @@ setInstructions(instructionsBuilder.toString()); if (event.isLastRound()) { - instructionsBuilder - .append(String - .format( + instructionsBuilder.append( + String.format( "<p><b>The experiment is now almost over. There is a survey" - + " for you to fill out" - + " while the facilitator prepares your earnings. When the facilitator is ready " - + "and you have completed the survey, your computer number will be called. You will then go to " + + " for you to fill out while the facilitator prepares your earnings. " + + " When the facilitator is ready and you have completed the survey, " + + "your computer number will be called. You will then go to " + "the room next door to receive payment.</b></p>", event.getId())); setInstructions(instructionsBuilder.toString()); @@ -700,12 +670,15 @@ } // adding the instructions into the instruction Panel - private void setInstructions(String s) { - instructionsEditorPane.setText(s); - instructionsEditorPane.setCaretPosition(0); - invalidate(); - validate(); - instructionsScrollPane.requestFocusInWindow(); + private void setInstructions(final String instructions) { + System.err.println("Setting instructions: " + instructions); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + instructionsEditorPane.setText(instructions); + instructionsEditorPane.setCaretPosition(0); + instructionsScrollPane.requestFocusInWindow(); + } + }); } @@ -840,13 +813,6 @@ } - public void updateInstructions(final String s) { - // setting the initial instructions - // FIXME: endRound should do the addCenterComponent(..) - //addCenterComponent(instructionsEditorPane); - setInstructions(s); - } - public void updateGraphDisplay(final ClientData clientData) { // TODO Auto-generated method stub this.clientData = clientData; @@ -893,7 +859,6 @@ } private JPanel getChartPanel(ClientData clientData) { - // TODO Auto-generated method stub chartPanel = new JPanel(); xySeriesDemo = new ChartWindowPanelTokenBandwidth( @@ -924,16 +889,23 @@ /*roundEndsOn = (configuration.getRoundTime() * 1000L) + System.currentTimeMillis(); update();*/ addCenterComponent(getTokenScreenPanel()); - getEnterTokens().requestFocusInWindow(); + getTokenEntryTextField().requestFocusInWindow(); } }; SwingUtilities.invokeLater(runnable); } - public void updateRoundInstructions(String instructions, int priority) { - instructionsBuilder.append(instructions); - updateInstructions(instructionsBuilder.toString()); - addCenterComponent(instructionsEditorPane); + public void updateRoundInstructions(RoundConfiguration roundConfiguration) { + System.err.println("Updating round instructions: " + roundConfiguration.getInstructions()); + // if this is the first round, show the general instructions. + if (roundConfiguration.isFirstRound()) { +// setInstructions(roundConfiguration.getParentConfiguration().getInitialInstructions()); + } + else { + instructionsBuilder.append(roundConfiguration.getInstructions()); + setInstructions(instructionsBuilder.toString()); + } + addCenterComponent(getInstructionsPanel()); } private ChatPanel chatPanel; @@ -971,7 +943,7 @@ if (timeRemaining < 0) { sleep(); addCenterComponent(getTokenScreenPanel()); - getEnterTokens().requestFocusInWindow(); + getTokenEntryTextField().requestFocusInWindow(); timer.stop(); timer = null; } @@ -981,7 +953,6 @@ } private void sleep() { - // TODO Auto-generated method stub long prevTime = System.currentTimeMillis(); while((System.currentTimeMillis() - prevTime) < 5000) { //System.out.println("Prev "+prevTime); @@ -996,7 +967,6 @@ } public void enableInstructions() { - // TODO Auto-generated method stub setInstructions(getGeneralInstructions(1,pagesTraversed)); addCenterComponent(getInstructionsPanel()); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-14 22:10:26 UTC (rev 297) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-15 00:12:05 UTC (rev 298) @@ -64,18 +64,17 @@ Map<Identifier, ClientData> updatedClientDataMap = new LinkedHashMap<Identifier, ClientData>(); - private IrrigationClient(Dimension screenSize) { - this(EventChannelFactory.create(), screenSize, new ServerConfiguration()); + private IrrigationClient() { + this(EventChannelFactory.create(), new ServerConfiguration()); } - public IrrigationClient(EventChannel channel, Dimension screenSize, - ServerConfiguration configuration) { + public IrrigationClient(EventChannel channel, ServerConfiguration serverConfiguration) { this.channel = channel; - this.serverConfiguration = configuration; - // moved this line down to the connect so that we get a new instance - // of a dispatcher every time we connect - - clientDispatcher = DispatcherFactory.getInstance().createClientDispatcher(channel); + this.serverConfiguration = serverConfiguration; + this.clientDispatcher = DispatcherFactory.getInstance().createClientDispatcher(channel); + } + + private void initialize(Dimension screenSize) { clientDataModel = new ClientDataModel(channel, this); experimentGameWindow = new ExperimentGameWindow(screenSize, this); // clientGameState.setMainIrrigationGameWindow(irrigationGameWindow1); @@ -101,7 +100,8 @@ public void run() { Dimension defaultDimension = new Dimension(500, 500); JFrame frame = new JFrame(); - IrrigationClient client = new IrrigationClient(defaultDimension); + IrrigationClient client = new IrrigationClient(); + client.initialize(defaultDimension); client.connect(); frame.setTitle("Client Window: " + client.id); frame.setSize(1130, 600); @@ -162,12 +162,7 @@ public void handle(RegistrationEvent event) { RoundConfiguration configuration = event.getRoundConfiguration(); setRoundConfiguration(configuration); - int priority = event.getClientData().getPriority(); - clientDataModel.setPriority(priority); - // FIXME: display priority - if (! configuration.isPracticeRound() || configuration.isSecondPracticeRound()) { - experimentGameWindow.updateRoundInstructions(configuration.getInstructions(),priority); - } + experimentGameWindow.updateRoundInstructions(configuration); } }); channel.add(this, new EventTypeProcessor<GroupUpdateEvent>(GroupUpdateEvent.class) { @@ -219,8 +214,7 @@ } public RoundConfiguration getRoundConfiguration() { - - return clientDataModel.getRoundConfiguration(); + return clientDataModel.getRoundConfiguration(); } public void setRoundConfiguration(RoundConfiguration roundConfiguration) { 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-14 22:10:26 UTC (rev 297) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-15 00:12:05 UTC (rev 298) @@ -26,12 +26,12 @@ */ public class IrrigationGamePanel extends JPanel { - public IrrigationGameWindow controlPanel; + private static final long serialVersionUID = -3878952269498777014L; + + public IrrigationGameWindow controlPanel; public CanalPanel upperPanel; - private static final long serialVersionUID = 1L; - private JPanel jPanelMain = null; //this contains the CanalPanel private JPanel jPanelUpperWindow = null; 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-14 22:10:26 UTC (rev 297) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-15 00:12:05 UTC (rev 298) @@ -147,6 +147,10 @@ public double getShowUpPayment() { return assistant.getDoubleProperty("showup-payment", 5.0d); } + + public String getInitialInstructions() { + return assistant.getProperty("initial-instructions"); + } public Map<String, String> getQuizAnswers() { //System.out.println("I am in the beginning of getquiz"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-16 23:03:08
|
Revision: 299 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=299&view=rev Author: alllee Date: 2009-10-16 23:02:53 +0000 (Fri, 16 Oct 2009) Log Message: ----------- Still cleaning up the initial stages of the experiment, namely the instructions and quiz pages. Next up is to properly deal with the actual experiment interface. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-10-15 00:12:05 UTC (rev 298) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-10-16 23:02:53 UTC (rev 299) @@ -1,6 +1,7 @@ package edu.asu.commons.irrigation.client; import java.awt.Color; +import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagLayout; @@ -18,100 +19,75 @@ * * FIXME: needs heavy refactoring. * - * @author Sanket + * @author Sanket Joshi + * @author Allen Lee * @version $Rev$ */ public class CanalAnimationPanel extends JPanel { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2049547253093489218L; - /** - * This is the default constructor - */ - private int x1UpStream; + //private IrrigationClientGameState clientGameState; - private int y1UpStream; + //////////////////animation logic parameters////////////////////////////// + private Timer timer; - private int x2UpStream = 420; + private final int DELAY = 20; - private int y2UpStream = 100; + private Ball balls[]; - private int y2DownStream = 100; + private int BALLCOUNT = 500; - private int x2DownStream = 950; + private Gate gate[] = new Gate[6]; - private int y1DownStream; + private int gateHeight = 20; - private int x1DownStream; + Random generator = new Random(); - private Graphics2D graphics2D; + private boolean enableBallAnimation = true; - private boolean flagDownStream = false; + private double totalContributedBandwidth; - private boolean flagUpStream = false; - - //private IrrigationClientGameState clientGameState; - - //////////////////animation logic parameters////////////////////////////// - private Timer timer; - - private final int DELAY = 20; + private long prev_time; - private Ball balls[]; - - private int BALLCOUNT = 500; - - private Gate gate[] = new Gate[6]; + private int gateCount = 0; - private int gateHeight = 20; - - Random generator = new Random(); + //////////////////////////////////////////////////////////////////////////// - private boolean enableBallAnimation = true; + public CanalAnimationPanel(double totalContributedBandwidth) { + super(); + this.totalContributedBandwidth = totalContributedBandwidth; + initialize(); + } - private double totalContributedBandwidth; + /** + * + * @return void + */ + private void initialize() { + this.setPreferredSize(new Dimension(1098,150)); + this.setLayout(new GridBagLayout()); + this.setBackground(Color.white); + //initializing the constructor for Gates + for(int i=0;i<6;i++){ + gate[i] = new Gate(totalContributedBandwidth,i); + //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); + } - private long prev_time; + initializexy(); - private int gateCount = 0; + timer = new Timer(DELAY, new ReboundListener()); // setup the Timer to do an action + // every DELAY times. + prev_time = System.currentTimeMillis(); + timer.start(); // starts the timer. + } - //////////////////////////////////////////////////////////////////////////// + private void gateReboundListener(){ - public CanalAnimationPanel(double totalContributedBandwidth) { - super(); - this.totalContributedBandwidth = totalContributedBandwidth; - initialize(); - } - - /** - * This method initializes this - * - * @return void - */ - private void initialize() { - this.setSize(1098,150); - this.setLayout(new GridBagLayout()); - this.setBackground(Color.white); - //initializing the constructor for Gates - for(int i=0;i<6;i++){ - gate[i] = new Gate(totalContributedBandwidth,i); - //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); - } - - initializexy(); - - timer = new Timer(DELAY, new ReboundListener()); // setup the Timer to do an action - // every DELAY times. - prev_time = System.currentTimeMillis(); - timer.start(); // starts the timer. - } - - private void gateReboundListener(){ - - openGates(gateCount ); - if(!(gateCount == 0)) - closeGates(gateCount-1); - /*if(!gate[0].isOpenGate() && flagDownStream == false){ + openGates(gateCount ); + if(!(gateCount == 0)) + closeGates(gateCount-1); + /*if(!gate[0].isOpenGate() && flagDownStream == false){ System.out.println("Opening gates"); closeGates(0); openGates(1); @@ -132,435 +108,396 @@ closeGates(0); //closeGates(1); } -*/} - - + */} - protected void paintComponent(Graphics graphics){ - updateGUI(); - super.paintComponent(graphics); // needed! - Graphics2D graphics2D = (Graphics2D)graphics; - this.graphics2D = graphics2D; - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(0,0,100,100); - //draw the other gates - for(int i=0;i<5;i++){ - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); - this.graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), - gate[i].getOpeningsHeight()); - this.graphics2D.setColor(Color.BLACK); - this.graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); - } - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); - //System.out.println("Gate :"+5+" X: "+gate[5].getX()+" Y :"+gate[5].getY()); - - //////////////////////Animation Logic//////////////////////////// - if(enableBallAnimation == true) - { - graphics.setColor(Color.white); - int ballCounter = 0; - for(int i=0;i<BALLCOUNT;i++){ - /*if(!(balls[i].isInServer == false && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() == 0)){ - if(!(flagDownStream == true && flagUpStream == true && balls[i].x >= 950)) - if(!(flagUpStream == true && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() <=25 && balls[i].x >=420)){ - if(flagUpStream == true && balls[i].x >=420 && clientGameState.getGroupDataModel().getMaximumAvailableBandwidth() >=25 ){ - if(!(flagDownStream == false && balls[i].y >= 80)) - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - } - else{ - - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); // paints a whole new circle, with changing coords - - } - - } - - } - */ - //System.out.println("ball sposition x :"+balls[i].x+" y:"+balls[i].y); - //get the position information of the ball. and then recheck the condition for height. - if((balls[i].getPosition() == 1)||(balls[i].getPosition() == 2) || (balls[i].getPosition()==3) - || (balls[i].getPosition() == 4) || (balls[i].getPosition() == 5)){ - if(!((!gate[balls[i].getPosition()-1].isOpenGate())&& balls[i].getY() >= (gate[balls[i].getPosition()-1].getY()+gate[balls[i].getPosition()-1].getHeight()))) - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - - - } - else{ - if(balls[i].getPosition() != 0){ - if(gate[balls[i].getPosition() - 6].getHeight() != 0) - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - } - else{ - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); - } - } - } - } - - } - - - - private void updateGUI() { - // TODO Auto-generated method stub - for(int i=1;i<6;i++){ - if(gate[i-1].isOpenGate()){ - if(!(gate[i-1].getHeight() - gateHeight < 0)){ - gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); - } - else{ - gate[i].setHeight(0); - } - } - else{ - gate[i].setHeight(gate[i-1].getHeight()); - - } - //order matters here - if(!(i == 5)){ - gate[i].setOpeningsHeight((totalContributedBandwidth*0.8) - - gate[i].getHeight()); - gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); - - //opening the lid logic - if(gate[i].isOpenGate()){ - gate[i].setx1(gate[i].getx2()); - if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) - gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); - else - gate[i].sety1(gate[i].getOpeningsY()); - } - else{ - gate[i].setx1(gate[i].getdefaultx1()); - gate[i].sety1(gate[i].getdefaulty1()); - } - - if(gate[0].isOpenGate()){ - gate[0].setx1(gate[0].getx2()); - if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) - gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); - else - gate[0].sety1(gate[0].getY()); - } - else{ - gate[0].setx1(gate[0].getdefaultx1()); - gate[0].sety1(gate[0].getdefaulty1()); - } - - } - } - } + protected void paintComponent(Graphics graphics){ + updateGUI(); + super.paintComponent(graphics); // needed! + Graphics2D graphics2D = (Graphics2D)graphics; + graphics2D = graphics2D; + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(0,0,100,100); + //draw the other gates + for(int i=0;i<5;i++){ + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); + graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), + gate[i].getOpeningsHeight()); + graphics2D.setColor(Color.BLACK); + graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); + } - /* - * initialize the Balls - */ - private void initializexy() { - // TODO Auto-generated method stub - balls = new Ball[BALLCOUNT]; - if(balls == null){ - System.out.println("Ball is null"); - } - - for(int i=0;i<BALLCOUNT;i++){ - balls[i] = new Ball(generator); - - } - } + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); - // this is the private class the Timer will look at every DELAY seconds - private class ReboundListener implements ActionListener{ - Random generator = new Random(); - public void actionPerformed(ActionEvent e) { - if((System.currentTimeMillis() - prev_time) > 5000){ - //System.out.println("Change the time"); - prev_time = System.currentTimeMillis(); - gateCount++; - if(gateCount > 4) - gateCount = 0; - gateReboundListener(); - } - for(int i=0;i<BALLCOUNT;i++){ - //updateGUI(); - balls[i].x += balls[i].moveX; - balls[i].y += balls[i].moveY; - process(i); - - } - repaint(); - } - } + //////////////////////Animation Logic//////////////////////////// + // FIXME: good lord, refactor this. + if (enableBallAnimation) { + graphics.setColor(Color.white); + for(int i=0;i<BALLCOUNT;i++){ + //get the position information of the ball. and then recheck the condition for height. + if((balls[i].getPosition() == 1)||(balls[i].getPosition() == 2) || (balls[i].getPosition()==3) + || (balls[i].getPosition() == 4) || (balls[i].getPosition() == 5)){ + if(!((!gate[balls[i].getPosition()-1].isOpenGate())&& balls[i].getY() >= (gate[balls[i].getPosition()-1].getY()+gate[balls[i].getPosition()-1].getHeight()))) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + else { + if(balls[i].getPosition() != 0){ + if(gate[balls[i].getPosition() - 6].getHeight() != 0) { + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + } + else { + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + } + } + } - /* - * This will process the balls according to their position - */ - private void process(int i){ - // TODO Auto-generated method stub - - switch(balls[i].getPosition()){ - - case 0: if((balls[i].x >= (100 - 20) && balls[i].x <= 100) && (balls[i].y >= 100-(int)(totalContributedBandwidth*0.8) && + } + + + + private void updateGUI() { + for(int i=1;i<6;i++){ + if(gate[i-1].isOpenGate()){ + if(!(gate[i-1].getHeight() - gateHeight < 0)){ + gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); + + } + else{ + gate[i].setHeight(0); + } + } + else{ + gate[i].setHeight(gate[i-1].getHeight()); + + } + //order matters here + if(!(i == 5)){ + gate[i].setOpeningsHeight((totalContributedBandwidth*0.8) + - gate[i].getHeight()); + gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); + + //opening the lid logic + if(gate[i].isOpenGate()){ + gate[i].setx1(gate[i].getx2()); + if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) + gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); + else + gate[i].sety1(gate[i].getOpeningsY()); + } + else{ + gate[i].setx1(gate[i].getdefaultx1()); + gate[i].sety1(gate[i].getdefaulty1()); + } + + if(gate[0].isOpenGate()){ + gate[0].setx1(gate[0].getx2()); + if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) + gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); + else + gate[0].sety1(gate[0].getY()); + } + else{ + gate[0].setx1(gate[0].getdefaultx1()); + gate[0].sety1(gate[0].getdefaulty1()); + } + + } + } + } + + /* + * initialize the Balls + */ + private void initializexy() { + balls = new Ball[BALLCOUNT]; + if(balls == null){ + System.out.println("Ball is null"); + } + + for(int i=0;i<BALLCOUNT;i++){ + balls[i] = new Ball(generator); + + } + } + + // this is the private class the Timer will look at every DELAY seconds + private class ReboundListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + if((System.currentTimeMillis() - prev_time) > 5000){ + //System.out.println("Change the time"); + prev_time = System.currentTimeMillis(); + gateCount++; + if(gateCount > 4) + gateCount = 0; + gateReboundListener(); + } + for(int i=0;i<BALLCOUNT;i++){ + //updateGUI(); + balls[i].x += balls[i].moveX; + balls[i].y += balls[i].moveY; + process(i); + + } + repaint(); + } + } + + /* + * This will process the balls according to their position + */ + private void process(int i){ + switch(balls[i].getPosition()) { + + case 0: + if((balls[i].x >= (100 - 20) && balls[i].x <= 100) + && (balls[i].y >= 100-(int)(totalContributedBandwidth*0.8) + && balls[i].y <= 100)) + { + balls[i].setPosition(1); + setBounds(i); + } + //still in server + else { + setBounds(i); + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + balls[i].moveX = balls[i].moveX * -1; + } + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveY = balls[i].moveY * -1; + } + break; + + case 1: /*if(gate[0].isOpenGate() && (balls[i].x >= 400 && balls[i].x <= 420) && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(1); - setBounds(i); - } - //still in server - else{ - setBounds(i); - if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ - balls[i].moveX = balls[i].moveX * -1; - } - if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) - balls[i].moveY = balls[i].moveY * -1; - } - break; - - case 1: /*if(gate[0].isOpenGate() && (balls[i].x >= 400 && balls[i].x <= 420) && (balls[i].y >= 80 && - balls[i].y <= 100)){ - */ if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(7); - //directly pass in the information - setBounds(i); - /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + */ if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(7); + //directly pass in the information + setBounds(i); + /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER);*/ - /* balls[i].xBOUNDSUPPER = 420; + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + } + else{ + setBounds(i); + /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); - */ - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(2); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - - break; - - case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(8); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + */ + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(2); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + + break; + + case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(8); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(3); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - - case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(9); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(3); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + + case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(9); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(4); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(10); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(4); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(10); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(5); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+20)) - && (balls[i].y >= 80 && balls[i].y <= 100)){ - balls[i].setPosition(11); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(5); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+20)) + && (balls[i].y >= 80 && balls[i].y <= 100)){ + balls[i].setPosition(11); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(6); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - case 6: setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - /*balls[i].setX(generator.nextInt(100)); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(6); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 6: setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + /*balls[i].setX(generator.nextInt(100)); balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); balls[i].setPosition(0); setBounds(i);*/ - setBallinServer(i); - } - - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - break; - } - - if((balls[i].getPosition() == 11) || (balls[i].getPosition() == 7) || (balls[i].getPosition() == 8) - || (balls[i].getPosition() == 9) || (balls[i].getPosition() == 10)){ - if(balls[i].getY() >= 150){ - /*balls[i].setX(generator.nextInt(100)); + setBallInTank(i); + } + + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + break; + } + + if((balls[i].getPosition() == 11) || (balls[i].getPosition() == 7) || (balls[i].getPosition() == 8) + || (balls[i].getPosition() == 9) || (balls[i].getPosition() == 10)){ + if(balls[i].getY() >= 150){ + /*balls[i].setX(generator.nextInt(100)); balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); //balls[i].setY(generator.nextInt(100)); balls[i].setPosition(0); setBounds(i); - */ - setBallinServer(i); - } - else{ - setBounds(i); - //System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER - //+" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); - } - } - } + */ + setBallInTank(i); + } + else{ + setBounds(i); + //System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER + //+" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); + } + } + } - private void setBallinServer(int i) { - // TODO Auto-generated method stub - generator.setSeed(i*(i+1)); - balls[i].setX(generator.nextInt(100)); - balls[i].setY(generator.nextInt(100)); - - //balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); - balls[i].setPosition(0); - if(balls[i].moveX == 0) - balls[i].moveX = generator.nextInt(15); - setBounds(i); - } + private void setBallInTank(int i) { + // FIXME: is this supposed to be a random seed? + generator.setSeed(i*(i+1)); + balls[i].setX(generator.nextInt(100)); + balls[i].setY(generator.nextInt(100)); - private void setBounds(int ballIndex) { - // TODO Auto-generated method stub - //ball is in the server - if(balls[ballIndex].getPosition() == 0){ - balls[ballIndex].xBOUNDSUPPER = 100; - balls[ballIndex].xBOUNDSLOWER = 0; - balls[ballIndex].yBOUNDSUPPER = 100; - balls[ballIndex].yBOUNDSLOWER = 0; - //balls[ballIndex].moveX = generator.nextInt(6); - //balls[ballIndex].moveY = generator.nextInt(6); - //balls[ballIndex].moveX = 3; - //balls[ballIndex].moveY = 3; - } - else{ - if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) - || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ - - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getY(); - //balls[ballIndex].moveX = 3; - //balls[ballIndex].moveY = 3; - - } - //the ball is in one of the openings - else{ - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); - balls[ballIndex].moveX = 0; - balls[ballIndex].moveY = 3; - } - } - } + //balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); + balls[i].setPosition(0); + if(balls[i].moveX == 0) { + balls[i].moveX = generator.nextInt(15); + } + setBounds(i); + } - public void openGates(int priority) { - // TODO Auto-generated method stub - - gate[priority].setGateOpen(true); - - //set the height of all the canal panls depending on the state of the game - paintComponent(graphics2D); - } + private void setBounds(int ballIndex) { + // ball is in the server + if(balls[ballIndex].getPosition() == 0){ + balls[ballIndex].xBOUNDSUPPER = 100; + balls[ballIndex].xBOUNDSLOWER = 0; + balls[ballIndex].yBOUNDSUPPER = 100; + balls[ballIndex].yBOUNDSLOWER = 0; + //balls[ballIndex].moveX = generator.nextInt(6); + //balls[ballIndex].moveY = generator.nextInt(6); + //balls[ballIndex].moveX = 3; + //balls[ballIndex].moveY = 3; + } + else{ + if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) + || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ - public void closeGates(int priority) { - // TODO Auto-generated method stub - gate[priority].setGateOpen(false); - gate[priority].setx1(gate[priority].getdefaultx1()); - gate[priority].sety1(gate[priority].getdefaulty1()); - /*if(!(priority == 0)) - gate[priority].setHeight(gate[priority-1].getHeight());*/ - paintComponent(graphics2D); - } + balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); + balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); + balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; + balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getY(); + //balls[ballIndex].moveX = 3; + //balls[ballIndex].moveY = 3; - public void endRound() { - // TODO Auto-generated method stub - flagDownStream = false; - flagDownStream = false; + } + //the ball is in one of the openings + else{ + balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); + balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); + balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); + balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); + balls[ballIndex].moveX = 0; + balls[ballIndex].moveY = 3; + } + } + } - x2UpStream = 420; + public void openGates(int priority) { + gate[priority].setGateOpen(true); + // set the height of all the canal panels depending on the state of the game + repaint(); + } - y2UpStream = 100; + public void closeGates(int priority) { + gate[priority].setGateOpen(false); + gate[priority].setx1(gate[priority].getdefaultx1()); + gate[priority].sety1(gate[priority].getdefaulty1()); + /*if(!(priority == 0)) + gate[priority].setHeight(gate[priority-1].getHeight());*/ + repaint(); + } - y2DownStream = 100; - - x2DownStream = 950; - - initializexy(); - } + public void endRound() { + initializexy(); + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-15 00:12:05 UTC (rev 298) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-16 23:02:53 UTC (rev 299) @@ -1,45 +1,3 @@ - -/* =========================================================== - * JFreeChart : a free chart library for the Java(tm) platform - * =========================================================== - * - * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors. - * - * Project Info: http://www.jfree.org/jfreechart/index.html - * - * This library is free software; you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Foundation; - * either version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with this - * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * ----------------- - * XYSeriesDemo.java - * ----------------- - * (C) Copyright 2002-2004, by Object Refinery Limited and Contributors. - * - * Original Author: David Gilbert (for Object Refinery Limited); - * Contributor(s): -; - * - * $Id$ - * - * Changes - * ------- - * 08-Apr-2002 : Version 1 (DG); - * 11-Jun-2002 : Inserted value out of order to see that it works (DG); - * 11-Oct-2002 : Fixed issues reported by Checkstyle (DG); - * - */ - package edu.asu.commons.irrigation.client; import java.awt.CardLayout; @@ -57,140 +15,117 @@ import edu.asu.commons.irrigation.server.GroupDataModel; - /** - * A simple demo showing a dataset created using the {@link XYSeriesCollection} class. + * $Id$ + * * + * @author Sanket Joshi + * @version $Rev$ */ -//public class XYSeriesDemo extends ApplicationFrame { +public class ChartWindowPanelTokenBandwidth extends JPanel { - public class ChartWindowPanelTokenBandwidth extends JPanel { + private static final long serialVersionUID = 5555080117985336199L; - /** - * - */ - private static final long serialVersionUID = 5555080117985336199L; + private int numberofFilesDownloaded = 10; - private int numberofFilesDownloaded = 10; + private Dimension screenSize; - private Dimension screenSize; + private JPanel jPanel; - private JPanel jPanel; - - private IrrigationClient client; + private IrrigationClient client; - + /** * A demonstration application showing an XY series containing a null value. * * @param title the frame title. */ public ChartWindowPanelTokenBandwidth(IrrigationClient client) { - - //super(title); - this.client = client; - initialize(); + this.client = client; + initialize(); } - public void initialize() { - // TODO Auto-generated method stub - this.setLayout(new CardLayout()); - this.setSize(new Dimension(530/2, 326/2)); - //this.setSize(screenSize.width, screenSize.height); - this.add(getJPanel(), getJPanel().getName()); - repaint(); + public void initialize() { + this.setLayout(new CardLayout()); + this.setSize(new Dimension(530/2, 326/2)); + //this.setSize(screenSize.width, screenSize.height); + this.add(getJPanel(), getJPanel().getName()); + repaint(); - } + } - /** - * This method initializes jPanel - * - * @return javax.swing.JPanel - */ - private JPanel getJPanel() { - if (jPanel == null) { - jPanel = new JPanel(); - GridLayout gridLayout = new GridLayout(); - gridLayout.setColumns(2); - jPanel.setLayout(gridLayout); - jPanel.add(getChartPanel()); - //jPanel.add(getchartPanel1()); - jPanel.setName("jPanel"); - } - return jPanel; - } + /** + * This method initializes jPanel + * + * @return javax.swing.JPanel + */ + private JPanel getJPanel() { + if (jPanel == null) { + jPanel = new JPanel(); + GridLayout gridLayout = new GridLayout(); + gridLayout.setColumns(2); + jPanel.setLayout(gridLayout); + jPanel.add(getChartPanel()); + //jPanel.add(getchartPanel1()); + jPanel.setName("jPanel"); + } + return jPanel; + } - private ChartPanel getChartPanel() { - // TODO Auto-generated method stub - final XYSeries actualFlowCapacitySeries = new XYSeries("Actual"); - final XYSeries potentialFlowCapacitySeries = new XYSeries("Potential"); -// final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); - final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); - int x,y; - GroupDataModel group = client.getClientDataModel().getGroupDataModel(); - final int infrastructureEfficiency = group.getInfrastructureEfficiency(); - final int actualFlowCapacity = group.getFlowCapacity(); - for(y = 0; y <= actualFlowCapacity; y++) { - actualFlowCapacitySeries.add(infrastructureEfficiency, y); - } - for(x =0; x<=client.getRoundConfiguration().getMaximumInfrastructureEfficiency();x++){ - y = group.calculateFlowCapacity(x); - potentialFlowCapacitySeries.add(x,y); - } - final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); - final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); - for (y = 0; y <= initialFlowCapacity; y++) { - initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); - } + private ChartPanel getChartPanel() { + // TODO Auto-generated method stub + final XYSeries actualFlowCapacitySeries = new XYSeries("Actual"); + final XYSeries potentialFlowCapacitySeries = new XYSeries("Potential"); + // final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); + final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); + int x,y; + GroupDataModel group = client.getClientDataModel().getGroupDataModel(); + final int infrastructureEfficiency = group.getInfrastructureEfficiency(); + final int actualFlowCapacity = group.getFlowCapacity(); + for(y = 0; y <= actualFlowCapacity; y++) { + actualFlowCapacitySeries.add(infrastructureEfficiency, y); + } + for(x =0; x<=client.getRoundConfiguration().getMaximumInfrastructureEfficiency();x++){ + y = group.calculateFlowCapacity(x); + potentialFlowCapacitySeries.add(x,y); + } + final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); + final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); + for (y = 0; y <= initialFlowCapacity; y++) { + initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); + } -// for(y = 0; y <= actualFlowCapacity; y++) { -// actualFlowCapacitySeriesY.add(infrastructureEfficiency,y); -// } - repaint(); + // for(y = 0; y <= actualFlowCapacity; y++) { + // actualFlowCapacitySeriesY.add(infrastructureEfficiency,y); + // } - final XYSeriesCollection data = new XYSeriesCollection(); - data.addSeries(initialInfrastructureEfficiencySeries); - data.addSeries(actualFlowCapacitySeries); - data.addSeries(potentialFlowCapacitySeries); + final XYSeriesCollection data = new XYSeriesCollection(); + data.addSeries(initialInfrastructureEfficiencySeries); + data.addSeries(actualFlowCapacitySeries); + data.addSeries(potentialFlowCapacitySeries); -// data.addSeries(actualFlowCapacitySeriesY); + // data.addSeries(actualFlowCapacitySeriesY); - final JFreeChart chart = ChartFactory.createXYLineChart( - "Total Flow Capacity", - "Infrastructure Efficiency", - "Actual Flow Capacity", - data, - PlotOrientation.VERTICAL, - true, - true, - false - ); - final ChartPanel chartPanel = new ChartPanel(chart); - //chartPanel.chartProgress(arg0) - chartPanel.setLayout(new CardLayout()); - chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); - //setContentPane(chartPanel); - return chartPanel; - //y=4*x; - } - // **************************************************************************** - // * JFREECHART DEVELOPER GUIDE * - // * The JFreeChart Developer Guide, written by David Gilbert, is available * - // * to purchase from Object Refinery Limited: * - // * * - // * http://www.object-refinery.com/jfreechart/guide.html * - // * * - // * Sales are used to provide funding for the JFreeChart project - please * - // * support us so that we can continue developing free software. * - // **************************************************************************** - - /** - * Starting point for the demonstration application. - * - * @param args ignored. - */ - - } \ No newline at end of file + final JFreeChart chart = ChartFactory.createXYLineChart( + "Total Flow Capacity", + "Infrastructure Efficiency", + "Actual Flow Capacity", + data, + PlotOrientation.VERTICAL, + true, + true, + false + ); + final ChartPanel chartPanel = new ChartPanel(chart); + //chartPanel.chartProgress(arg0) + chartPanel.setLayout(new CardLayout()); + chartPanel.setPreferredSize(new Dimension(500, 270)); + repaint(); + //setContentPane(chartPanel); + return chartPanel; + //y=4*x; + } +} \ No newline at end of file Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-15 00:12:05 UTC (rev 298) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-16 23:02:53 UTC (rev 299) @@ -9,10 +9,11 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.lang.reflect.InvocationTargetException; import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Properties; @@ -58,7 +59,7 @@ private JPanel graphPanel; - private JTextField tokenEntryTextField; + private JTextField investedTokensTextField; private JButton submitTokensButton; @@ -72,7 +73,7 @@ private int totalContributedTokensPerGroup; - private JTextArea contributionStatusInformationjTextArea; + private JTextArea contributionInformationTextArea; private JButton nextButton; @@ -92,7 +93,7 @@ private int NUMBER_INSTRUCTIONS = 9; - private JLabel quizLabel; + private JLabel quizMessageLabel; private JLabel quizAnimationLabel = new JLabel(); @@ -112,26 +113,22 @@ private JScrollPane animationInstructionsScrollPane; - private JPanel chartPanel; + private JPanel pieChartPanel; private PieChart pieChart; - public ClientData clientData; - private CanalAnimationPanel canalAnimationPanel; private CardLayout cardLayout; private JLabel infrastructureEfficiencyLabel = new JLabel("Current infrastructure efficiency: "); - public ExperimentGameWindow(Dimension screenSize, IrrigationClient client) { + public ExperimentGameWindow(IrrigationClient client) { this.client = client; this.clientDataModel = client.getClientDataModel(); - // FIXME: set the actual screen size dimensions after this JPanel has - // been initialized... - // this.screenSize = getParent().getSize(); - // feed subject view the available screen size so that - // it can adjust appropriately when given a board size + } + + void initialize(Dimension screenSize) { initGuiComponents(screenSize); } @@ -150,7 +147,7 @@ addToCardLayout(getInstructionsPanel()); irrigationGamePanel = new IrrigationGamePanel(screenSize, client); addToCardLayout(irrigationGamePanel); - // add any other panels that need to be switched out. + // add any other panels that need to be switched to.. // FIXME: see if we can simplify the number of instructions panes that Sanket has created. // addToCardLayout(getInstructionsEditorPane()); } @@ -202,7 +199,7 @@ if (submitTokenPanel == null) { submitTokenPanel = new JPanel(); submitTokenPanel.setLayout(new BorderLayout()); - submitTokenPanel.add(getTokenEntryTextField(), BorderLayout.CENTER); + submitTokenPanel.add(getInvestedTokensTextField(), BorderLayout.CENTER); submitTokenPanel.add(getSubmitTokensButton(), BorderLayout.EAST); return submitTokenPanel; } @@ -218,52 +215,78 @@ instructionsPanel.add(getInstructionsNavigationPanel(), BorderLayout.PAGE_END); } return instructionsPanel; - } - + private JPanel getInstructionsNavigationPanel() { if (instructionsNavigationPanel == null) { instructionsNavigationPanel = new JPanel(); instructionsNavigationPanel.setLayout(new BorderLayout()); instructionsNavigationPanel.add(getPreviousButton(), BorderLayout.LINE_START); instructionsNavigationPanel.add(getNextButton(), BorderLayout.LINE_END); - // this is just to add spacing I think. - quizLabel = new JLabel(); - instructionsNavigationPanel.add(quizLabel, BorderLayout.CENTER); + // displays quiz messages (correct/incorrect answer). + quizMessageLabel = new JLabel(); + instructionsNavigationPanel.add(quizMessageLabel, BorderLayout.CENTER); } return instructionsNavigationPanel; } + private JButton getPreviousButton() { + if (previousButton == null) { + previousButton = new JButton(); + previousButton.setText("Previous"); + previousButton.setEnabled(false); + previousButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + quizMessageLabel.setText(""); + // getting the next instruction Number + if (instructionNumber > 1) { + instructionNumber--; + } + previousButton.setEnabled(instructionNumber > 1); + nextButton.setEnabled(true); + System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); + setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); + // FIXME: get rid of hardcoded animation on page 5. Should instead + // just be an animated gif or something like that. + // should be more like "if instructions.hasAnimation()" + if(instructionNumber == 5) { + getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); + } + else { + getInstructionsPanel().remove(getCanalAnimationPanel()); + } + validate(); + } + }); + } + return previousButton; + } + private JButton getNextButton() { if (nextButton == null) { nextButton = new JButton(); nextButton.setText("Next"); nextButton.setEnabled(false); - nextButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); - + nextButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + quizMessageLabel.setText(""); previousButton.setEnabled(true); - if(instructionNumber >= pagesTraversed){ + if (instructionNumber >= pagesTraversed){ nextButton.setEnabled(false); } // getting the next instruction Number - if (instructionNumber == NUMBER_INSTRUCTIONS) { - - } - else + if (instructionNumber < NUMBER_INSTRUCTIONS) { instructionNumber++; - System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); + } setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - if(instructionNumber == 5){ - quizAnimationLabel.setText(""); - addCenterComponent(getAnimationInstructionPane()); - //addCenterComponent(getTokenScreenPanel()); + if(instructionNumber == 5) { + getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); } else { - addCenterComponent(getInstructionsPanel()); + getInstructionsPanel().remove(getCanalAnimationPanel()); } + validate(); } }); @@ -272,14 +295,14 @@ return nextButton; } - private JPanel getAnimationInstructionPane() { + private JPanel getAnimationInstructionPanel() { if (animationInstructionPanel == null) { animationInstructionPanel = new JPanel(); animationInstructionPanel.setName("Animated instruction panel"); animationInstructionPanel.setLayout(new BorderLayout()); - animationInstructionPanel.add(getAnimationPane(), BorderLayout.CENTER); + animationInstructionPanel.add(getAnimationPanel(), BorderLayout.CENTER); - animationInstructionPanel.add(getNavigationAnimationPanel(), BorderLayout.SOUTH); + animationInstructionPanel.add(getNavigationAnimationPanel(), BorderLayout.PAGE_END); animationInstructionPanel.setBackground(Color.WHITE); return animationInstructionPanel; } @@ -291,8 +314,8 @@ private JPanel getNavigationAnimationPanel() { if (navigationAnimationPanel == null) { - navigationAnimationPanel = new JPanel(); + navigationAnimationPanel.setName("Navigation animation panel"); navigationAnimationPanel.setLayout(new BorderLayout()); navigationAnimationPanel.add(getNextAnimationButton(), BorderLayout.EAST); navigationAnimationPanel.add(getPreviousAnimationButton(), BorderLayout.WEST); @@ -310,7 +333,7 @@ previousAnimationButton.setEnabled(true); previousAnimationButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); + quizMessageLabel.setText(""); // getting the next instruction Number nextButton.setEnabled(true); if (instructionNumber > 1) { @@ -332,7 +355,7 @@ nextAnimationButton.setEnabled(false); nextAnimationButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - quizLabel.setText(""); + quizMessageLabel.setText(""); previousButton.setEnabled(true); if(instructionNumber >= pagesTraversed) nextButton.setEnabled(false); @@ -342,26 +365,36 @@ } System.out.println("instruction number : "+instructionNumber+" pages traversed"+pagesTraversed); setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed)); - if(instructionNumber == 5){ - addCenterComponent(getAnimationInstructionPane()); + // FIXME: horrifyingly hard coded + if(instructionNumber == 5) { //addCenterComponent(getTokenScreenPanel()); + getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START); } else { - addCenterComponent(getInstructionsPanel()); + getInstructionsPanel().remove(getCanalAnimationPanel()); +// addCenterComponent(getInstructionsPanel()); } + validate(); } }); } return nextAnimationButton; } + + private JPanel getCanalAnimationPanel() { + if (canalAnimationPanel == null) { + canalAnimationPanel = new CanalAnimationPanel(40); + } + return canalAnimationPanel; + } - private JPanel getAnimationPane() { + private JPanel getAnimationPanel() { if (animationPanel == null) { animationPanel = new JPanel(); + animationPanel.setName("Animation panel"); animationPanel.setLayout(new BorderLayout()); //FIXME: Here the animation panel needs to be decided on fly - //canalPanelAnimation = new CanalPanelAnimation(40); canalAnimationPanel = new CanalAnimationPanel(40); animationPanel.add(canalAnimationPanel,BorderLayout.CENTER); animationInstructionsEditorPane = createInstructionsEditorPane(); @@ -375,42 +408,10 @@ animationInstructionsEditorPane.setCaretPosition(0); animationInstructionsEditorPane.repaint(); animationPanel.setBackground(Color.WHITE); - return animationPanel; } - return animationPanel; } - private JButton getPreviousButton() { - if (previousButton == null) { - previousButton = new JButton(); - previousButton.setText("Previous"); - previousButton.setEnabled(false); - previousButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - quizLabel.setText(""); - // getting the next instruction Number - nextButton.setEnabled(true); - if (instructionNumber !=... [truncated message content] |
From: <al...@us...> - 2009-10-20 04:07:27
|
Revision: 307 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=307&view=rev Author: alllee Date: 2009-10-20 04:07:18 +0000 (Tue, 20 Oct 2009) Log Message: ----------- more refactoring of GUI components, getting rid of unnecessarily nested components and making it so that the GUI components can be initialized and added to the ExperimentGameWindow's CardLayout without generating NPEs. Getting rid of isPracticeRound() check in RoundConfiguration.isChatEnabled() method. Modified Paths: -------------- 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/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java Added Paths: ----------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java Removed Paths: ------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-20 02:36:40 UTC (rev 306) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java 2009-10-20 04:07:18 UTC (rev 307) @@ -1,131 +0,0 @@ -package edu.asu.commons.irrigation.client; - -import java.awt.CardLayout; -import java.awt.Dimension; -import java.awt.GridLayout; - -import javax.swing.JPanel; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; - -import edu.asu.commons.irrigation.server.GroupDataModel; - -/** - * $Id$ - * - * - * @author Sanket Joshi - * @version $Rev$ - */ -public class ChartWindowPanelTokenBandwidth extends JPanel { - - private static final long serialVersionUID = 5555080117985336199L; - - private int numberofFilesDownloaded = 10; - - private Dimension screenSize; - - private JPanel jPanel; - - private IrrigationClient client; - - - - /** - * A demonstration application showing an XY series containing a null value. - * - * @param title the frame title. - */ - public ChartWindowPanelTokenBandwidth(IrrigationClient client) { - this.client = client; - initialize(); - } - - - - public void initialize() { - this.setLayout(new CardLayout()); - this.setSize(new Dimension(530/2, 326/2)); - //this.setSize(screenSize.width, screenSize.height); - this.add(getJPanel(), getJPanel().getName()); - repaint(); - - } - - /** - * This method initializes jPanel - * - * @return javax.swing.JPanel - */ - private JPanel getJPanel() { - if (jPanel == null) { - jPanel = new JPanel(); - GridLayout gridLayout = new GridLayout(); - gridLayout.setColumns(2); - jPanel.setLayout(gridLayout); - jPanel.add(getChartPanel()); - //jPanel.add(getchartPanel1()); - jPanel.setName("jPanel"); - } - return jPanel; - } - - private ChartPanel getChartPanel() { - // TODO Auto-generated method stub - final XYSeries actualFlowCapacitySeries = new XYSeries("Actual"); - final XYSeries potentialFlowCapacitySeries = new XYSeries("Potential"); - // final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); - final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); - int x,y; - GroupDataModel group = client.getClientDataModel().getGroupDataModel(); - final int infrastructureEfficiency = group.getInfrastructureEfficiency(); - final int actualFlowCapacity = group.getFlowCapacity(); - for(y = 0; y <= actualFlowCapacity; y++) { - actualFlowCapacitySeries.add(infrastructureEfficiency, y); - } - for(x =0; x<=client.getRoundConfiguration().getMaximumInfrastructureEfficiency();x++){ - y = group.calculateFlowCapacity(x); - potentialFlowCapacitySeries.add(x,y); - } - final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); - final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); - for (y = 0; y <= initialFlowCapacity; y++) { - initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); - } - - // for(y = 0; y <= actualFlowCapacity; y++) { - // actualFlowCapacitySeriesY.add(infrastructureEfficiency,y); - // } - - final XYSeriesCollection data = new XYSeriesCollection(); - data.addSeries(initialInfrastructureEfficiencySeries); - data.addSeries(actualFlowCapacitySeries); - data.addSeries(potentialFlowCapacitySeries); - - // data.addSeries(actualFlowCapacitySeriesY); - - final JFreeChart chart = ChartFactory.createXYLineChart( - "Total Flow Capacity", - "Infrastructure Efficiency", - "Actual Flow Capacity", - data, - PlotOrientation.VERTICAL, - true, - true, - false - ); - final ChartPanel chartPanel = new ChartPanel(chart); - //chartPanel.chartProgress(arg0) - chartPanel.setLayout(new CardLayout()); - chartPanel.setPreferredSize(new Dimension(500, 270)); - repaint(); - //setContentPane(chartPanel); - return chartPanel; - //y=4*x; - } -} \ No newline at end of file Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-10-20 02:36:40 UTC (rev 306) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-10-20 04:07:18 UTC (rev 307) @@ -52,7 +52,6 @@ private IrrigationClient irrigationClient; - private Identifier clientId; private JScrollPane messageScrollPane; @@ -109,18 +108,13 @@ private void sendMessage() { String message = chatField.getText(); - // System.err.println("message: " + message); - if (message == null || "".equals(message)) { - return; + if (message != null && ! message.isEmpty() && targetIdentifier != null) { + chatField.setText(""); + irrigationClient.transmit(new ChatRequest(getClientId(), message, targetIdentifier)); + displayMessage( + String.format("%s -> %s", getChatHandle(getClientId()), getChatHandle(targetIdentifier)), + message); } - if (targetIdentifier == null) { - return; - } - chatField.setText(""); - irrigationClient.transmit(new ChatRequest(clientId, message, targetIdentifier)); - System.err.println("Sending a new chat request"); - displayMessage(getChatHandle(clientId) + " -> " - + getChatHandle(targetIdentifier), message); chatField.requestFocusInWindow(); } @@ -147,7 +141,7 @@ JFrame frame = new JFrame(); ChatPanel chatPanel = new ChatPanel(); Identifier selfId = new Identifier(){}; - chatPanel.setClientId(selfId); + chatPanel.clientId = selfId; chatPanel.initialize(Arrays.asList(new Identifier[] { new Identifier(){}, new Identifier(){}, new Identifier(){}, selfId })); @@ -229,13 +223,15 @@ chatHandles.put(participants.get(i), HANDLES[i]); } } - - public void setClientId(Identifier clientId) { - this.clientId = clientId; + + public Identifier getClientId() { + if (clientId == null) { + clientId = irrigationClient.getId(); + } + return clientId; } public void setIrrigationClient(IrrigationClient client) { - setClientId(client.getId()); this.irrigationClient = client; client.getEventChannel().add(this, new EventTypeProcessor<ChatEvent>(ChatEvent.class) { public void handle(final ChatEvent chatEvent) { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-20 02:36:40 UTC (rev 306) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-20 04:07:18 UTC (rev 307) @@ -67,7 +67,7 @@ private JButton submitTokensButton; - private ChartWindowPanelTokenBandwidth xySeriesDemo = null; + private InfrastructureEfficiencyChartPanel xySeriesDemo = null; private IrrigationClient client; @@ -625,7 +625,7 @@ private JPanel getPieChartPanel() { if (pieChartPanel == null) { pieChartPanel = new JPanel(); - xySeriesDemo = new ChartWindowPanelTokenBandwidth(client); + xySeriesDemo = new InfrastructureEfficiencyChartPanel(client); xySeriesDemo.setVisible(true); pieChart = new PieChart(); GridLayout gridLayout = new GridLayout(); @@ -654,7 +654,7 @@ System.err.println("Updating round instructions: " + roundConfiguration.getInstructions()); // if this is the first round, show the general instructions. if (roundConfiguration.isFirstRound()) { -// setInstructions(roundConfiguration.getParentConfiguration().getInitialInstructions()); + } else { instructionsBuilder.append(roundConfiguration.getInstructions()); Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java (from rev 306, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChartWindowPanelTokenBandwidth.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-10-20 04:07:18 UTC (rev 307) @@ -0,0 +1,89 @@ +package edu.asu.commons.irrigation.client; + +import java.awt.BorderLayout; +import java.awt.Dimension; + +import javax.swing.JPanel; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import edu.asu.commons.irrigation.server.GroupDataModel; + +/** + * $Id$ + * + * Presents a chart view of the infrastructure efficiency function. + * + * @author Allen Lee, Sanket Joshi + * @version $Rev$ + */ +public class InfrastructureEfficiencyChartPanel extends JPanel { + + private static final long serialVersionUID = 5555080117985336199L; + + private IrrigationClient client; + /** + * + * @param title the frame title. + */ + public InfrastructureEfficiencyChartPanel(IrrigationClient client) { + this.client = client; + setPreferredSize(new Dimension(530/2, 326/2)); + //this.setSize(screenSize.width, screenSize.height); + setName("infrastructure efficiency chart panel"); + setLayout(new BorderLayout()); + } + + public void initialize() { + add(createChartPanel(), BorderLayout.CENTER); + } + + private ChartPanel createChartPanel() { + final XYSeries actualFlowCapacitySeries = new XYSeries("Actual"); + final XYSeries potentialFlowCapacitySeries = new XYSeries("Potential"); + // final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); + final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); + int x,y; + GroupDataModel group = client.getClientDataModel().getGroupDataModel(); + final int infrastructureEfficiency = group.getInfrastructureEfficiency(); + final int actualFlowCapacity = group.getFlowCapacity(); + for (y = 0; y <= actualFlowCapacity; y++) { + actualFlowCapacitySeries.add(infrastructureEfficiency, y); + } + for(x =0; x<=client.getRoundConfiguration().getMaximumInfrastructureEfficiency();x++){ + y = group.calculateFlowCapacity(x); + potentialFlowCapacitySeries.add(x,y); + } + final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); + final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); + for (y = 0; y <= initialFlowCapacity; y++) { + initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); + } + + final XYSeriesCollection data = new XYSeriesCollection(); + data.addSeries(initialInfrastructureEfficiencySeries); + data.addSeries(actualFlowCapacitySeries); + data.addSeries(potentialFlowCapacitySeries); + + // data.addSeries(actualFlowCapacitySeriesY); + + final JFreeChart chart = ChartFactory.createXYLineChart( + "Total Flow Capacity", + "Infrastructure Efficiency", + "Actual Flow Capacity", + data, + PlotOrientation.VERTICAL, + true, + true, + false + ); + final ChartPanel chartPanel = new ChartPanel(chart); + chartPanel.setPreferredSize(new Dimension(500, 270)); + return chartPanel; + } +} \ No newline at end of file Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-20 02:36:40 UTC (rev 306) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-20 04:07:18 UTC (rev 307) @@ -71,14 +71,14 @@ this.channel = channel; setServerConfiguration(serverConfiguration); this.clientDispatcher = DispatcherFactory.getInstance().createClientDispatcher(channel); + initEventProcessors(); } private void initialize(Dimension screenSize) { clientDataModel = new ClientDataModel(channel, this); experimentGameWindow = new ExperimentGameWindow(this); experimentGameWindow.initialize(screenSize); - // clientGameState.setMainIrrigationGameWindow(irrigationGameWindow1); - initEventProcessors(); + connect(); } public void connect() { @@ -86,8 +86,8 @@ + " state: " + state); if (state != ClientState.UNCONNECTED) return; + id = clientDispatcher.connect(serverConfiguration.getServerAddress()); - System.err.println("Received id from server: " + id); if (id == null) { throw new RuntimeException("Null ID from Dispatcher. Server: <" + serverConfiguration.getServerAddress() + "> is probably down."); @@ -102,7 +102,6 @@ JFrame frame = new JFrame(); IrrigationClient client = new IrrigationClient(); client.initialize(defaultDimension); - client.connect(); frame.setTitle("Virtual Commons Experiment Client: " + client.id); frame.setSize(1130, 600); frame.getContentPane().add(client.getExperimentGameWindow()); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-20 02:36:40 UTC (rev 306) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-20 04:07:18 UTC (rev 307) @@ -130,14 +130,11 @@ /** * Returns true if the current round should have a communication session for - * getCommunicationDuration() seconds before the round begins. + * getChatDuration() seconds before the round begins. * * @return */ public boolean isChatEnabledBeforeRound() { - if (isPracticeRound()) { - return false; - } return getBooleanProperty("chat-enabled-before-round", true); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-20 04:41:39
|
Revision: 308 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=308&view=rev Author: alllee Date: 2009-10-20 04:41:30 +0000 (Tue, 20 Oct 2009) Log Message: ----------- infrastructure efficiency graph and pie chart are now properly displayed. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java Added Paths: ----------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java Removed Paths: ------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.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-10-20 04:07:18 UTC (rev 307) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-20 04:41:30 UTC (rev 308) @@ -18,6 +18,7 @@ import java.util.Map; import java.util.Properties; +import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; @@ -67,7 +68,7 @@ private JButton submitTokensButton; - private InfrastructureEfficiencyChartPanel xySeriesDemo = null; + private InfrastructureEfficiencyChartPanel infrastructureEfficiencyChartPanel = null; private IrrigationClient client; @@ -101,7 +102,7 @@ private JPanel pieChartPanel; - private PieChart pieChart; + private TokenInvestmentPieChartPanel pieChart; private CanalAnimationPanel canalAnimationPanel; @@ -356,8 +357,6 @@ } } - // /////////////////////////////////////////////////////////////////////////////////////////////////////////// - private HtmlEditorPane getInstructionsEditorPane() { if (instructionsEditorPane == null) { instructionsEditorPane = createInstructionsEditorPane(); @@ -595,15 +594,14 @@ - Runnable runnable = new Runnable() { + SwingUtilities.invokeLater(new Runnable() { public void run() { contributionInformationTextArea.setText(contributionInformation); + infrastructureEfficiencyChartPanel.initialize(); pieChart.setClientData(clientData); addCenterComponent(getGraphPanel()); } - }; - - SwingUtilities.invokeLater(runnable); + }); irrigationGamePanel.updateContributions(clientDataModel); } @@ -611,13 +609,11 @@ if (graphPanel == null) { graphPanel = new JPanel(); graphPanel.setName("Graph panel"); - GridLayout gridLayout = new GridLayout(); - gridLayout.setColumns(2); - graphPanel.setLayout(gridLayout); - graphPanel.add(getPieChartPanel(), null); + graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.X_AXIS)); + graphPanel.add(getPieChartPanel()); contributionInformationTextArea = new JTextArea(); contributionInformationTextArea.setEditable(false); - graphPanel.add(contributionInformationTextArea,null); + graphPanel.add(contributionInformationTextArea); } return graphPanel; } @@ -625,14 +621,13 @@ private JPanel getPieChartPanel() { if (pieChartPanel == null) { pieChartPanel = new JPanel(); - xySeriesDemo = new InfrastructureEfficiencyChartPanel(client); - xySeriesDemo.setVisible(true); - pieChart = new PieChart(); + infrastructureEfficiencyChartPanel = new InfrastructureEfficiencyChartPanel(client); + pieChart = new TokenInvestmentPieChartPanel(); GridLayout gridLayout = new GridLayout(); gridLayout.setRows(2); gridLayout.setColumns(1); pieChartPanel.setLayout(gridLayout); - pieChartPanel.add(xySeriesDemo); + pieChartPanel.add(infrastructureEfficiencyChartPanel); pieChartPanel.add(pieChart); } return pieChartPanel; Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-10-20 04:07:18 UTC (rev 307) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-10-20 04:41:30 UTC (rev 308) @@ -27,10 +27,9 @@ private static final long serialVersionUID = 5555080117985336199L; private IrrigationClient client; - /** - * - * @param title the frame title. - */ + + private ChartPanel chartPanel; + public InfrastructureEfficiencyChartPanel(IrrigationClient client) { this.client = client; setPreferredSize(new Dimension(530/2, 326/2)); @@ -40,7 +39,11 @@ } public void initialize() { - add(createChartPanel(), BorderLayout.CENTER); + if (chartPanel != null) { + remove(chartPanel); + } + chartPanel = createChartPanel(); + add(chartPanel, BorderLayout.CENTER); } private ChartPanel createChartPanel() { Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java 2009-10-20 04:07:18 UTC (rev 307) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java 2009-10-20 04:41:30 UTC (rev 308) @@ -1,105 +0,0 @@ -package edu.asu.commons.irrigation.client; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.util.Map; - -import javax.swing.JPanel; -import javax.swing.SwingUtilities; - -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartPanel; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.plot.PiePlot; -import org.jfree.data.general.DefaultPieDataset; -import org.jfree.data.general.PieDataset; - -import edu.asu.commons.irrigation.server.ClientData; -import edu.asu.commons.irrigation.server.GroupDataModel; -import edu.asu.commons.net.Identifier; - -/** - * Presents the group contributions as a pie chart. - */ -public class PieChart extends JPanel { - - private static final long serialVersionUID = -5382293105043214105L; - - private ChartPanel chartPanel; - - public void setClientData(final ClientData clientData) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - final PieDataset dataset = createDataset(clientData); - final JFreeChart chart = createChart(dataset); - remove(chartPanel); - chartPanel = new ChartPanel(chart); - chartPanel.setPreferredSize(new Dimension(500, 270)); - add(chartPanel); - setBounds(new Rectangle(0,0,500,270)); - } - }); - } - - /** - * Creates a pie dataset out of the client - * @return a sample dataset. - */ - private PieDataset createDataset(ClientData clientData) { - final DefaultPieDataset defaultPieDataset = new DefaultPieDataset(); - GroupDataModel groupDataModel = clientData.getGroupDataModel(); - Map<Identifier,ClientData>clientDataMap = groupDataModel.getClientDataMap(); - for (ClientData currentClientData : clientDataMap.values()) { - StringBuilder labelBuilder = new StringBuilder(); - if (currentClientData.getId().equals(clientData.getId())) { - labelBuilder.append("You"); - } - else { - labelBuilder.append(currentClientData.getPriorityAsString()); - } - labelBuilder.append(" invested ").append(currentClientData.getInvestedTokens()).append(" token(s)"); - defaultPieDataset.setValue(labelBuilder.toString(), currentClientData.getInvestedTokens()); - } - return defaultPieDataset; - } - - // **************************************************************************** - // * JFREECHART DEVELOPER GUIDE * - // * The JFreeChart Developer Guide, written by David Gilbert, is available * - // * to purchase from Object Refinery Limited: * - // * * - // * http://www.object-refinery.com/jfreechart/guide.html * - // * * - // * Sales are used to provide funding for the JFreeChart project - please * - // * support us so that we can continue developing free software. * - // **************************************************************************** - - /** - * Creates a chart. - * - * @param dataset the dataset. - * - * @return a chart. - */ - private JFreeChart createChart(final PieDataset dataset) { - - final JFreeChart chart = ChartFactory.createPieChart( - "Tokens Contributed", // chart title - dataset, // data - false, // include legend - true, - false - ); - - final PiePlot plot = (PiePlot) chart.getPlot(); - //plot.setLabelGenerator(new CustomLabelGenerator()); - plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); - plot.setNoDataMessage("No data available"); - plot.setCircular(false); - plot.setLabelGap(0.02); - return chart; - - } - -} Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java (from rev 306, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java) =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java 2009-10-20 04:41:30 UTC (rev 308) @@ -0,0 +1,104 @@ +package edu.asu.commons.irrigation.client; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.util.Map; + +import javax.swing.JPanel; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PiePlot; +import org.jfree.data.general.DefaultPieDataset; +import org.jfree.data.general.PieDataset; + +import edu.asu.commons.irrigation.server.ClientData; +import edu.asu.commons.irrigation.server.GroupDataModel; +import edu.asu.commons.net.Identifier; + +/** + * Presents the group contributions as a pie chart. + */ +public class TokenInvestmentPieChartPanel extends JPanel { + + private static final long serialVersionUID = -5382293105043214105L; + + private ChartPanel chartPanel; + + public TokenInvestmentPieChartPanel() { + setLayout(new BorderLayout()); + } + + public void setClientData(final ClientData clientData) { + final PieDataset dataset = createPieDataset(clientData); + final JFreeChart chart = createChart(dataset); + if (chartPanel != null) { + remove(chartPanel); + } + chartPanel = new ChartPanel(chart); + add(chartPanel, BorderLayout.CENTER); + revalidate(); + } + + /** + * Creates a pie dataset out of the client + * @return a sample dataset. + */ + private PieDataset createPieDataset(ClientData clientData) { + final DefaultPieDataset defaultPieDataset = new DefaultPieDataset(); + GroupDataModel groupDataModel = clientData.getGroupDataModel(); + Map<Identifier,ClientData>clientDataMap = groupDataModel.getClientDataMap(); + for (ClientData currentClientData : clientDataMap.values()) { + StringBuilder labelBuilder = new StringBuilder(); + if (currentClientData.getId().equals(clientData.getId())) { + labelBuilder.append("You"); + } + else { + labelBuilder.append(currentClientData.getPriorityAsString()); + } + labelBuilder.append(" invested ").append(currentClientData.getInvestedTokens()).append(" token(s)"); + defaultPieDataset.setValue(labelBuilder.toString(), currentClientData.getInvestedTokens()); + } + return defaultPieDataset; + } + + // **************************************************************************** + // * JFREECHART DEVELOPER GUIDE * + // * The JFreeChart Developer Guide, written by David Gilbert, is available * + // * to purchase from Object Refinery Limited: * + // * * + // * http://www.object-refinery.com/jfreechart/guide.html * + // * * + // * Sales are used to provide funding for the JFreeChart project - please * + // * support us so that we can continue developing free software. * + // **************************************************************************** + + /** + * Creates a chart. + * + * @param dataset the dataset. + * + * @return a chart. + */ + private JFreeChart createChart(final PieDataset dataset) { + + final JFreeChart chart = ChartFactory.createPieChart( + "Tokens Contributed", // chart title + dataset, // data + false, // include legend + true, + false + ); + + final PiePlot plot = (PiePlot) chart.getPlot(); + //plot.setLabelGenerator(new CustomLabelGenerator()); + plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); + plot.setNoDataMessage("No data available"); + plot.setCircular(false); + plot.setLabelGap(0.02); + return chart; + + } + +} Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-20 04:07:18 UTC (rev 307) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-20 04:41:30 UTC (rev 308) @@ -139,7 +139,7 @@ } public int getChatDuration() { - return getIntProperty("communication-duration", 40); + return getIntProperty("chat-duration", 40); } /** Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-20 04:07:18 UTC (rev 307) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-20 04:41:30 UTC (rev 308) @@ -8,7 +8,6 @@ import java.util.TreeSet; import javax.swing.BoxLayout; -import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-20 06:07:21
|
Revision: 309 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=309&view=rev Author: alllee Date: 2009-10-20 06:07:13 +0000 (Tue, 20 Oct 2009) Log Message: ----------- starting to refactor the game interface now. continuing to remove unnecessary nested JPanels (what were you thinking Sanket?!?). Next up is to continue merging all primary interface elements into IrrigationGamePanel. fixed a bug in RegistrationEvent where the facilitator would receive RegistrationEvents with a null RoundConfiguration. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RegistrationEvent.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-20 04:41:30 UTC (rev 308) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-20 06:07:13 UTC (rev 309) @@ -12,59 +12,35 @@ import javax.swing.Timer; /** - * @author Sanket - * + * $Id$ + * + * @author Allen Lee, Sanket Joshi */ public class CanalPanel extends JPanel { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = -6178860067928578812L; - /** - * This is the default constructor - */ - private int x1UpStream; +// private Graphics2D graphics2D; - private int y1UpStream; + //////////////////animation logic parameters////////////////////////////// + private Timer timer; - private int x2UpStream = 420; + private final static int DELAY = 20; - private int y2UpStream = 100; + private Ball balls[]; - private int y2DownStream = 100; + private final static int BALLCOUNT = 500; - private int x2DownStream = 950; + private Gate gate[] = new Gate[6]; - private int y1DownStream; - - private int x1DownStream; - - private Graphics2D graphics2D; - - private boolean flagDownStream = false; - - private boolean flagUpStream = false; - - //private IrrigationClientGameState clientGameState; - - //////////////////animation logic parameters////////////////////////////// - private Timer timer; - - private final int DELAY = 20; - - private Ball balls[]; - - private int BALLCOUNT = 500; - - private Gate gate[] = new Gate[6]; - private int gateHeight = 20; - + Random generator = new Random(); private boolean enableBallAnimation = true; private double totalContributedBandwidth; - + private ClientDataModel clientGameState; private int numberofGates = 6; @@ -87,7 +63,7 @@ if(totalContributedBandwidth == 1.0){ totalContributedBandwidth = 2.0; } - + initialize(); } @@ -105,67 +81,66 @@ gate[i] = new Gate(totalContributedBandwidth,i); //System.out.println("Gate "+i+"x : "+gate[i].getX()+"y : "+gate[i].getY()); } - - initializexy(); - - timer = new Timer(DELAY, new Rebound()); // setup the Timer to do an action - // every DELAY times. - timer.start(); // starts the timer. - - } + initializeBalls(); + + timer = new Timer(DELAY, new Rebound()); // setup the Timer to do an action + // every DELAY times. + timer.start(); // starts the timer. + + } + protected void paintComponent(Graphics graphics){ updateGUI(); super.paintComponent(graphics); // needed! - Graphics2D graphics2D = (Graphics2D)graphics; - this.graphics2D = graphics2D; - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(0,0,serverHeight,serverWidth); + Graphics2D graphics2D = (Graphics2D) graphics; + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(0,0,serverHeight,serverWidth); //draw the other gates for(int i=0;i<numberofGates-1;i++){ - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(gate[i].getX(), gate[i].getY(), gate[i].getWidth(),gate[i].getHeight()); } - + int numClients = clientGameState.getAllClientIdentifiers().size(); - for(int i=0;i<numClients;i++){ - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), + for(int i=0;i<numClients;i++) { + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(gate[i].getOpeningsX(), gate[i].getOpeningsY(),gate[i].getOpeningsWidth(), gate[i].getOpeningsHeight()); - this.graphics2D.setColor(Color.BLACK); - this.graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); + graphics2D.setColor(Color.BLACK); + graphics2D.drawLine(gate[i].getx1(),gate[i].gety1(),gate[i].getx2(),gate[i].gety2()); } - this.graphics2D.setColor(Color.BLUE); - this.graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); - + graphics2D.setColor(Color.BLUE); + graphics2D.fillRect(gate[5].getX(), gate[5].getY(),10,gate[5].getHeight()); + //////////////////////Animation Logic//////////////////////////// - if(enableBallAnimation == true) - { - 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) + if(enableBallAnimation == true) + { + 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{ - graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + if(balls[i].getPosition() != 0){ + if(gate[balls[i].getPosition() - 6].getHeight() != 0) + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } + else{ + graphics.fillOval(balls[i].x,balls[i].y,balls[i].getBallSize(), balls[i].getBallSize()); + } } } - } - } - + } + } - - - + + + private void updateGUI() { for(int i=1;i<6;i++){ if(gate[i-1].isOpenGate()){ @@ -179,19 +154,19 @@ } else{ gate[i].setHeight(gate[i-1].getHeight()); - + } //order matters here if(!(i == 5)){ gate[i].setOpeningsHeight((totalContributedBandwidth*bandWidthCanalHeightMapping) - gate[i].getHeight()); gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); - + //opening the lid logic if(gate[i].isOpenGate()){ gate[i].setx1(gate[i].getx2()); if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) - gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); + gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); else gate[i].sety1(gate[i].getOpeningsY()); } @@ -199,49 +174,47 @@ gate[i].setx1(gate[i].getdefaultx1()); gate[i].sety1(gate[i].getdefaulty1()); } - - if(gate[0].isOpenGate()){ - gate[0].setx1(gate[0].getx2()); - if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) - gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); - else - gate[0].sety1(gate[0].getY()); + + if(gate[0].isOpenGate()){ + gate[0].setx1(gate[0].getx2()); + if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) + gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); + else + gate[0].sety1(gate[0].getY()); + } + else{ + gate[0].setx1(gate[0].getdefaultx1()); + gate[0].sety1(gate[0].getdefaulty1()); + } + } - else{ - gate[0].setx1(gate[0].getdefaultx1()); - gate[0].sety1(gate[0].getdefaulty1()); - } - } - } } /* * initialize the Balls */ - private void initializexy() { - // TODO Auto-generated method stub + private void initializeBalls() { balls = new Ball[BALLCOUNT]; if(balls == null){ System.out.println("Ball is null"); } - + for(int i=0;i<BALLCOUNT;i++){ balls[i] = new Ball(generator); - + } } // this is the private class the Timer will look at every DELAY seconds private class Rebound implements ActionListener{ - Random generator = new Random(); public void actionPerformed(ActionEvent e) { for(int i=0;i<BALLCOUNT;i++){ - //updateGUI(); - balls[i].x += balls[i].moveX; - balls[i].y += balls[i].moveY; - process(i); - } + //updateGUI(); + balls[i].x += balls[i].moveX; + balls[i].y += balls[i].moveY; + process(i); + } repaint(); } } @@ -251,151 +224,151 @@ */ private void process(int i){ // TODO Auto-generated method stub - + switch(balls[i].getPosition()){ - + case 0: if((balls[i].x >= (serverWidth - gateBuffer ) && balls[i].x <= serverWidth) && (balls[i].y >= serverHeight-(int)(totalContributedBandwidth*bandWidthCanalHeightMapping) && balls[i].y <= serverHeight)){ - balls[i].setPosition(1); - setBounds(i); - } - //still in server - else{ - setBounds(i); - if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ - balls[i].moveX = balls[i].moveX * -1; - } - if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) - balls[i].moveY = balls[i].moveY * -1; - } - break; - + balls[i].setPosition(1); + setBounds(i); + } + //still in server + else{ + setBounds(i); + if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + balls[i].moveX = balls[i].moveX * -1; + } + if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + balls[i].moveY = balls[i].moveY * -1; + } + break; + case 1: if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+gateBuffer)) - && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ - balls[i].setPosition(7); - //directly pass in the information - setBounds(i); - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(2); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - - break; - + && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ + balls[i].setPosition(7); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(2); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + + break; + case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ - balls[i].setPosition(8); - //directly pass in the information - setBounds(i); - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(3); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - - + balls[i].setPosition(8); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(3); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + + case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ - balls[i].setPosition(9); - //directly pass in the information - setBounds(i); - /* balls[i].xBOUNDSUPPER = 420; + balls[i].setPosition(9); + //directly pass in the information + setBounds(i); + /* balls[i].xBOUNDSUPPER = 420; balls[i].xBOUNDSLOWER = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; balls[i].moveY = 3;*/ - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(4); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(4); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ - balls[i].setPosition(10); - //directly pass in the information - setBounds(i); - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(5); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - + balls[i].setPosition(10); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(5); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+gateBuffer)) - && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ - balls[i].setPosition(11); - //directly pass in the information - setBounds(i); - } - else{ - setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - balls[i].setPosition(6); - } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - } - break; - + && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ + balls[i].setPosition(11); + //directly pass in the information + setBounds(i); + } + else{ + setBounds(i); + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + balls[i].setPosition(6); + } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + } + break; + case 6: setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ - setBallinServer(i); - } - - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ - balls[i].moveY = balls[i].moveY*-1; - } - break; + if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + setBallinServer(i); } - - //set balls back to the server when they complete their flow in the gates - if((balls[i].getPosition() == 11) || (balls[i].getPosition() == 7) || (balls[i].getPosition() == 8) - || (balls[i].getPosition() == 9) || (balls[i].getPosition() == 10)){ - if(balls[i].getY() >= 150){ - setBallinServer(i); - } - else{ - setBounds(i); - } - } - } + if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + balls[i].moveY = balls[i].moveY*-1; + } + break; + } + //set balls back to the server when they complete their flow in the gates + if((balls[i].getPosition() == 11) || (balls[i].getPosition() == 7) || (balls[i].getPosition() == 8) + || (balls[i].getPosition() == 9) || (balls[i].getPosition() == 10)){ + if(balls[i].getY() >= 150){ + setBallinServer(i); + } + else{ + setBounds(i); + } + } + } + + private void setBallinServer(int i) { // TODO Auto-generated method stub - generator.setSeed(i*(i+1)); - balls[i].setX(generator.nextInt(serverWidth)); - balls[i].setY(generator.nextInt(serverHeight)); - balls[i].setPosition(0); - if(balls[i].moveX == 0) - balls[i].moveX = generator.nextInt(15); - setBounds(i); + generator.setSeed(i*(i+1)); + balls[i].setX(generator.nextInt(serverWidth)); + balls[i].setY(generator.nextInt(serverHeight)); + balls[i].setPosition(0); + if(balls[i].moveX == 0) + balls[i].moveX = generator.nextInt(15); + setBounds(i); } private void setBounds(int ballIndex) { @@ -414,7 +387,7 @@ else{ if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ - + balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; @@ -435,38 +408,23 @@ } public void openGates(int priority) { - // TODO Auto-generated method stub - gate[priority].setGateOpen(true); +// paintComponent(graphics2D); + repaint(); - //set the height of all the canal panls depending on the state of the game - paintComponent(graphics2D); } public void closeGates(int priority) { - // TODO Auto-generated method stub gate[priority].setGateOpen(false); gate[priority].setx1(gate[priority].getdefaultx1()); gate[priority].sety1(gate[priority].getdefaulty1()); /*if(!(priority == 0)) gate[priority].setHeight(gate[priority-1].getHeight());*/ - paintComponent(graphics2D); + repaint(); } public void endRound() { - // TODO Auto-generated method stub - flagDownStream = false; - flagDownStream = false; - - x2UpStream = 420; - - y2UpStream = 100; - - y2DownStream = 100; - - x2DownStream = 950; - - initializexy(); + initializeBalls(); } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-20 04:41:30 UTC (rev 308) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-20 06:07:13 UTC (rev 309) @@ -19,27 +19,28 @@ /** * $Id$ * - * Displays the canal animation and so on. + * The game interface screen shown during the round. * + * FIXME: needs refactoring, should merge IrrigationGameWindow functionality into this panel as well. + * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev$ */ public class IrrigationGamePanel extends JPanel { - private static final long serialVersionUID = -3878952269498777014L; + private static final long serialVersionUID = -3878952269498777014L; - public IrrigationGameWindow controlPanel; - - public CanalPanel upperPanel; - - private JPanel jPanelMain = null; + public IrrigationGameWindow irrigationGameWindow; + + public CanalPanel canalPanel; + //this contains the CanalPanel - private JPanel jPanelUpperWindow = null; + private JPanel upperPanel = null; //this contains the upstream and downstream Panel private JPanel jPanelUpStreamWindow = null; private JPanel jPanelDownStreamWindow = null; private JPanel downloadScreenPanel = null; - + private ScoreBoxPanel scoreBoxPanel; public IrrigationClient client; @@ -58,7 +59,7 @@ private JLabel maximumAvailableFlowCapacityLabel = null; - private ClientDataModel clientGameState; // @jve:decl-index=0: + private ClientDataModel clientDataModel; // @jve:decl-index=0: private MiddleWindowPanel middleWindowPanel; @@ -84,31 +85,17 @@ timeRemainingLabel.setText("Time Left"); timeRemainingTextField = new JTextField(); timeRemainingTextField.setEditable(false); -// timeRemainingTextField.setBounds(new Rectangle(620, 39, 61); + // timeRemainingTextField.setBounds(new Rectangle(620, 39, 61); timeRemainingTextField.setText("50 sec"); timeRemainingTextField.setBackground(Color.white); timeRemainingTextField.setFont(new Font("serif", Font.BOLD, 14)); timeRemainingTextField.setForeground(new Color(102, 204, 255)); timeRemainingTextField.setHorizontalAlignment(SwingConstants.CENTER); - this.setLayout(new BorderLayout(4,4)); - this.setPreferredSize(new Dimension(1130, 558)); - this.add(getJPanelMain(),null); - + setLayout(new BorderLayout()); + add(getDownloadScreenPanel(), BorderLayout.CENTER); } - private JPanel getJPanelMain() { - if(jPanelMain == null){ - jPanelMain = new JPanel(); - jPanelMain.setLayout(new BorderLayout(4,4)); - jPanelMain.setBackground(Color.WHITE); - jPanelMain.setForeground(Color.BLACK); - jPanelMain.add(getDownloadScreenPanel(), BorderLayout.CENTER); - return jPanelMain; - } - return jPanelMain; - } - private JPanel getDownloadScreenPanel() { if(downloadScreenPanel == null){ scoreBoardLabel = new JLabel(); @@ -132,7 +119,7 @@ downloadScreenPanel.setLayout(null); downloadScreenPanel.setName("downloadScreenPanel"); downloadScreenPanel.setBackground(Color.white); - downloadScreenPanel.add(getJPanelUpperWindow(),null); + downloadScreenPanel.add(getUpperPanel(),null); downloadScreenPanel.add(getTimeRemainingProgressBar(), null); downloadScreenPanel.add(timeRemainingLabel, null); downloadScreenPanel.add(timeRemainingTextField,null); @@ -145,26 +132,17 @@ return downloadScreenPanel; } - /** - * This method initializes jPanel - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelUpperWindow() { - if (jPanelUpperWindow == null) { - jPanelUpperWindow = new JPanel(); - jPanelUpperWindow.setLayout(null); - jPanelUpperWindow.setBounds(new Rectangle(13, 64, 1098, 123)); + private JPanel getUpperPanel() { + if (upperPanel == null) { + upperPanel = new JPanel(); + upperPanel.setLayout(new BorderLayout()); } - return jPanelUpperWindow; + return upperPanel; } - private JPanel getUpperPanel(ClientDataModel clientGameState) { - // TODO Auto-generated method stub - upperPanel = new CanalPanel(clientGameState); - upperPanel.setSize(new Dimension(1098, 123)); - - return upperPanel; + private JPanel getCanalPanel() { + canalPanel = new CanalPanel(clientDataModel); + return canalPanel; } /** @@ -184,12 +162,10 @@ } private IrrigationGameWindow getControlPanel() { - // TODO Auto-generated method stub - if(controlPanel == null){ - controlPanel = new IrrigationGameWindow(screenSize,client,this); - return controlPanel; + if(irrigationGameWindow == null) { + irrigationGameWindow = new IrrigationGameWindow(screenSize,client,this); } - return controlPanel; + return irrigationGameWindow; } /** * This method initializes jPanel3 @@ -202,22 +178,21 @@ jPanelDownStreamWindow.setLayout(null); jPanelDownStreamWindow.setBackground(new Color(186, 226, 237)); jPanelDownStreamWindow.setBounds(new Rectangle(582, 225 + 100+50, 530, 326)); - jPanelDownStreamWindow.add(getScoreBoxPanel(),null); + jPanelDownStreamWindow.add(getScoreBoxPanel(),null); } return jPanelDownStreamWindow; } private ScoreBoxPanel getScoreBoxPanel() { - // TODO Auto-generated method stub if(scoreBoxPanel == null){ scoreBoxPanel = new ScoreBoxPanel(client); - + return scoreBoxPanel; } return scoreBoxPanel; } - - + + /** * This method initializes TimeRemainingjProgressBar * @@ -236,48 +211,46 @@ /** * Shoudl be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. */ - public void updateClientStatus(final ClientDataModel clientGameState) { - ////////////new code//////////////////////////////////////////////////////////// - Runnable createGuiRunnable = new Runnable(){ - public void run() { - for(final ClientData clientData : clientGameState.getClientDataMap().values()){ - timeRemainingTextField.setText( clientGameState.getTimeLeft() +" second(s)" ); - timeRemainingProgressBar.setValue( (clientGameState.getTimeLeft() / 1000) ); - maximumAvailableFlowCapacityLabel.setText( - clientData.getGroupDataModel().getMaximumAvailableFlowCapacity() +" cubic feet per second (cfps)" - ); - middleWindowPanel.update(clientData); - if (clientGameState.getPriority() == clientData.getPriority()) { - controlPanel.update(clientData); - //per parameter score panel - scoreBoxPanel.update(clientData); - } - else{ - scoreBoxPanel.update(clientData); - } - if(clientData.isGateOpen()){ - upperPanel.openGates(clientData.getPriority()); + public void updateClientStatus(final ClientDataModel clientDataModel) { + ////////////new code//////////////////////////////////////////////////////////// + Runnable createGuiRunnable = new Runnable(){ + public void run() { + for(final ClientData clientData : clientDataModel.getClientDataMap().values()){ + timeRemainingTextField.setText( clientDataModel.getTimeLeft() +" second(s)" ); + timeRemainingProgressBar.setValue( (clientDataModel.getTimeLeft() / 1000) ); + maximumAvailableFlowCapacityLabel.setText( + clientData.getGroupDataModel().getMaximumAvailableFlowCapacity() +" cubic feet per second (cfps)" + ); + middleWindowPanel.update(clientData); + if (clientDataModel.getPriority() == clientData.getPriority()) { + irrigationGameWindow.update(clientData); + //per parameter score panel + scoreBoxPanel.update(clientData); + } + else{ + scoreBoxPanel.update(clientData); + } + if(clientData.isGateOpen()){ + canalPanel.openGates(clientData.getPriority()); - } - else if(clientData.isPaused()){ - upperPanel.closeGates(clientData.getPriority()); - } - if(clientData.isGateClosed()){ - upperPanel.closeGates(clientData.getPriority()); - } - } - } + } + else if(clientData.isPaused()){ + canalPanel.closeGates(clientData.getPriority()); + } + if(clientData.isGateClosed()){ + canalPanel.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(); } } @@ -293,87 +266,63 @@ public void endRound() { Runnable createGuiRunnable = new Runnable(){ public void run() { - //TODO Auto-generated method stub - //Refreshing the screen and preparing the main Irrigation Window for the next round - //provided we have already got the updatedClientDataMap - controlPanel.endRound(); - jPanelUpperWindow.removeAll(); - upperPanel.endRound(); + //Refreshing the screen and preparing the main Irrigation Window for the next round + //provided we have already got the updatedClientDataMap + irrigationGameWindow.endRound(); + upperPanel.removeAll(); + canalPanel.endRound(); } }; - - try { - SwingUtilities.invokeAndWait(createGuiRunnable); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + + try { + SwingUtilities.invokeAndWait(createGuiRunnable); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } /** * assigns the priority to the window and prepares the irrigationWindowMap */ - public void updateContributions(final ClientDataModel clientGameState) { - this.clientGameState = clientGameState; + public void updateContributions(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(clientGameState); - - //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 + //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. + fillPanels(); - //case 2 : irrigationWindowMap.put(new Integer(clientData.getPriority()), middleStreamWindow); - } - - - + } + + + /** * fills in the panels depending on the priority of the client */ - public void fillPanels(ClientDataModel clientDataModel) { - // TODO Auto-generated method stub - jPanelUpperWindow.add(getUpperPanel(clientDataModel)); - //switch(clientGameState.getPriority()){ - + private void fillPanels() { + upperPanel.add(getCanalPanel(), BorderLayout.CENTER); downloadScreenPanel.add(getJPanelUpStreamWindow(),null); - downloadScreenPanel.add(getJPanelDownStreamWindow(),null); + downloadScreenPanel.add(getJPanelDownStreamWindow(),null); //adding the in between Panel - downloadScreenPanel.add(getJPanelMiddleWindow(),null); - /*case 0 : downloadScreenPanel.add(getJPanelUpStreamWindow(0),null); - downloadScreenPanel.add(getJPanelDownStreamWindow(0),null); - //Assigning the Priorities on the Priority Label - break; + downloadScreenPanel.add(getJPanelMiddleWindow(),null); + } - case 1 : downloadScreenPanel.add(getJPanelUpStreamWindow(1),null); - downloadScreenPanel.add(getJPanelDownStreamWindow(1),null); - //Assigning the Priorities on the Priority Label - break; -*/ } - private JPanel getJPanelMiddleWindow() { - // TODO Auto-generated method stub if(middleWindowPanel == null){ - if(clientGameState != null){ + if(clientDataModel != null){ System.out.println("Main Irrigation Window clientGameState is not null"); } - middleWindowPanel = new MiddleWindowPanel(clientGameState); + middleWindowPanel = new MiddleWindowPanel(clientDataModel); } return middleWindowPanel; } - + public ClientDataModel getClientGameState() { - // TODO Auto-generated method stub - return clientGameState; + return clientDataModel; } } - // @jve:decl-index=0:visual-constraint="10,-43" +// @jve:decl-index=0:visual-constraint="10,-43" Modified: 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-10-20 04:41:30 UTC (rev 308) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 2009-10-20 06:07:13 UTC (rev 309) @@ -21,8 +21,8 @@ /** * $Id$ * - * Primary JPanel used to display the active interface for the experiment. - * Organizes and contains all other components. + * Contains the primary open gate button, etc. + * * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev$ @@ -72,7 +72,7 @@ private JLabel profitEarned = null; - public JTextField profitEarnedtxt = null; + public JTextField moneyEarnedTextField = null; private JLabel fileDownloadedtxt = null; @@ -125,7 +125,7 @@ * here the end code and debreifing logic should be written */ refreshButtons(); - profitEarnedtxt.setText("0"); + moneyEarnedTextField.setText("0"); } /** @@ -169,7 +169,7 @@ } public void updateProfitEarned(final int award) { - profitEarnedtxt.setText(new Integer(award).toString()); + moneyEarnedTextField.setText(new Integer(award).toString()); } @@ -541,16 +541,16 @@ * @return javax.swing.JTextField */ private JTextField getProfitEarnedTextField() { - if (profitEarnedtxt == null) { - profitEarnedtxt = new JTextField(); - profitEarnedtxt.setText(new Integer(mainIrrigationWindow + if (moneyEarnedTextField == null) { + moneyEarnedTextField = new JTextField(); + moneyEarnedTextField.setText(new Integer(mainIrrigationWindow .getClientGameState().getClientData().getTotalTokensEarned()) .toString()); - profitEarnedtxt.setBounds(new Rectangle(161, 17, 86, 21)); - profitEarnedtxt.setFont(new Font("Dialog", Font.PLAIN, 14)); - profitEarnedtxt.setEditable(false); + moneyEarnedTextField.setBounds(new Rectangle(161, 17, 86, 21)); + moneyEarnedTextField.setFont(new Font("Dialog", Font.PLAIN, 14)); + moneyEarnedTextField.setEditable(false); } - return profitEarnedtxt; + return moneyEarnedTextField; } /** @@ -639,7 +639,7 @@ // checks whether the file has been downlaoded if (clientData.isFileDownloaded()) { - profitEarnedtxt.setText(new Integer(clientData.getTotalTokensEarned()) + moneyEarnedTextField.setText(new Integer(clientData.getTotalTokensEarned()) .toString()); // StopDownload.setEnabled(false); pauseDownload.setEnabled(false); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-20 04:41:30 UTC (rev 308) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-20 06:07:13 UTC (rev 309) @@ -131,7 +131,6 @@ private JLabel getFilesDownLoadedText(int priority) { - // TODO Auto-generated method stub if(filesDownloadedText == null){ filesDownloadedText = new JLabel(); filesDownloadedText.setBounds(new Rectangle(5,50+32+10+20+10+20+10,30,20)); @@ -141,8 +140,6 @@ } public void update(ClientData clientData) { - // TODO Auto-generated method stub - this.clientData = clientData; if(clientData.getAvailableFlowCapacity() > 25){ @@ -154,9 +151,8 @@ filesDownloadedText.setText(new Integer(clientData.getCropsGrown()).toString()); tokensText.setText(new Integer(clientData.getTotalTokensEarned()).toString()); - if(clientData.isGateOpen() == true && clientData.getAvailableFlowCapacity() > 0) - fileLabel.setVisible(true); - else - fileLabel.setVisible(false); + if(clientData.isGateOpen() && clientData.getAvailableFlowCapacity() > 0) { + // show that client is actively irrigating + } } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RegistrationEvent.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RegistrationEvent.java 2009-10-20 04:41:30 UTC (rev 308) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/RegistrationEvent.java 2009-10-20 06:07:13 UTC (rev 309) @@ -30,11 +30,11 @@ public RegistrationEvent(Identifier id, RoundConfiguration roundConfiguration, ClientData clientData) { super(id, roundConfiguration.getInstructions()); this.clientData = clientData; + this.roundConfiguration = roundConfiguration; } public RegistrationEvent(ClientData clientData, RoundConfiguration roundConfiguration) { this(clientData.getId(), roundConfiguration, clientData); - this.roundConfiguration = roundConfiguration; } public RoundConfiguration getRoundConfiguration() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-20 09:58:38
|
Revision: 310 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=310&view=rev Author: alllee Date: 2009-10-20 09:58:30 +0000 (Tue, 20 Oct 2009) Log Message: ----------- irrigation game panel is almost complete. It's ugly as hell though, layout needs a lot of work. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 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 irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-20 09:58:30 UTC (rev 310) @@ -1,9 +1,9 @@ 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; @@ -73,8 +73,7 @@ * @return void */ private void initialize() { - this.setSize(1098,150); - this.setLayout(new GridBagLayout()); + this.setPreferredSize(new Dimension(1098,150)); this.setBackground(Color.white); //initializing the constructor for Gates for(int i=0;i<numberofGates ;i++){ 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-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-20 09:58:30 UTC (rev 310) @@ -1,6 +1,8 @@ package edu.asu.commons.irrigation.client; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -98,6 +100,17 @@ public Map<Identifier, ClientData> getClientDataMap() { return groupDataModel.getClientDataMap(); } + + public List<ClientData> getClientDataSortedByPriority() { + ArrayList<ClientData> clientDataList = new ArrayList<ClientData>(getGroupDataModel().getClientDataMap().values()); + // sort by position. + Collections.sort(clientDataList, new Comparator<ClientData>() { + public int compare(ClientData a, ClientData b) { + return new Integer(a.getPriority()).compareTo(b.getPriority()); + } + }); + return clientDataList; + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-20 09:58:30 UTC (rev 310) @@ -383,7 +383,7 @@ Runnable runnable = new Runnable() { public void run() { addCenterComponent(irrigationGamePanel); - requestFocusInWindow(); + irrigationGamePanel.startRound(); } }; SwingUtilities.invokeLater(runnable); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-20 09:58:30 UTC (rev 310) @@ -137,9 +137,8 @@ transmit(openGateEvent); } - public void closeGate(String fileNo) { + public void closeGate() { CloseGateEvent closeGateEvent = new CloseGateEvent(getId()); - closeGateEvent.setFileNumber(fileNo); transmit(closeGateEvent); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-20 09:58:30 UTC (rev 310) @@ -4,9 +4,14 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.GridLayout; import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException; +import javax.swing.BoxLayout; +import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JProgressBar; @@ -39,7 +44,7 @@ //this contains the upstream and downstream Panel private JPanel jPanelUpStreamWindow = null; private JPanel jPanelDownStreamWindow = null; - private JPanel downloadScreenPanel = null; + private JPanel mainIrrigationPanel = null; private ScoreBoxPanel scoreBoxPanel; @@ -47,26 +52,44 @@ public Dimension screenSize; - public JProgressBar timeRemainingProgressBar = null; + public JProgressBar timeRemainingProgressBar; - private JLabel timeRemainingLabel = null; + private JLabel timeRemainingLabel; private JTextField timeRemainingTextField; - private JLabel priorityjLabel = null; + private JButton gateSwitchButton; - private JLabel totalAvailableFlowCapacityLabel = null; + private JLabel irrigationCapacityLabel; - private JLabel maximumAvailableFlowCapacityLabel = null; + // private JLabel maximumAvailableFlowCapacityLabel = null; private ClientDataModel clientDataModel; // @jve:decl-index=0: private MiddleWindowPanel middleWindowPanel; - private JLabel dashBoardLabel = null; + // private JLabel dashBoardLabel = null; - private JLabel scoreBoardLabel = null; + // private JLabel scoreBoardLabel = null; + private JLabel totalTokensEarnedLabel; + + private JLabel tokensEarnedLabel; + + private JLabel tokensNotInvestedLabel; + + private JLabel waterUsedLabel; + + private JTextField waterUsedTextField; + + private JTextField tokensNotInvestedTextField; + + private JTextField tokensEarnedTextField; + + private JTextField totalTokensEarnedTextField; + + private boolean open; + public IrrigationGamePanel(Dimension screenSize, IrrigationClient client) { setName("Irrigation Game Panel"); this.screenSize = screenSize; @@ -78,68 +101,181 @@ * @return */ private void initGuiComponents() { - timeRemainingLabel = new JLabel(); - timeRemainingLabel.setBounds(new Rectangle(469, 39, 146, 23)); + + + JPanel topmostPanel = new JPanel(); + topmostPanel.setLayout(new BoxLayout(topmostPanel, BoxLayout.X_AXIS)); + topmostPanel.add(getIrrigationCapacityLabel()); + + JPanel timeRemainingPanel = new JPanel(); + timeRemainingPanel.setLayout(new BoxLayout(timeRemainingPanel, BoxLayout.Y_AXIS)); + timeRemainingPanel.add(getTimeRemainingProgressBar()); + timeRemainingPanel.add(getTimeRemainingPanel()); + + topmostPanel.add(timeRemainingPanel); + + + setLayout(new BorderLayout()); + add(topmostPanel, BorderLayout.PAGE_START); + add(getUpperPanel(), 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 GridLayout(4, 2)); + bottomPanel.add(getWaterUsedLabel()); + bottomPanel.add(getWaterUsedTextField()); + bottomPanel.add(getTokensNotInvestedLabel()); + bottomPanel.add(getTokensNotInvestedTextField()); + bottomPanel.add(getTokensEarnedLabel()); + bottomPanel.add(getTokensEarnedTextField()); + bottomPanel.add(getTotalTokensEarnedLabel()); + bottomPanel.add(getTotalTokensEarnedTextField()); + + panel.add(bottomPanel); + return panel; + } + + private JTextField getWaterUsedTextField() { + if (waterUsedTextField == null) { + waterUsedTextField = new JTextField(); + waterUsedTextField.setEditable(false); + } + return waterUsedTextField; + } + + private JLabel getWaterUsedLabel() { + if (waterUsedLabel == null) { + waterUsedLabel = new JLabel("Water units used: "); + } + return waterUsedLabel; + } + + private JTextField getTokensNotInvestedTextField() { + if (tokensNotInvestedTextField == null) { + tokensNotInvestedTextField = new JTextField(); + tokensNotInvestedTextField.setEditable(false); + } + return tokensNotInvestedTextField; + } + private JLabel getTokensNotInvestedLabel() { + if (tokensNotInvestedLabel == null) { + tokensNotInvestedLabel = new JLabel("Tokens not invested: "); + } + return tokensNotInvestedLabel; + } + + private JTextField getTokensEarnedTextField() { + if (tokensEarnedTextField == null) { + tokensEarnedTextField = new JTextField(); + tokensEarnedTextField.setEditable(false); + } + 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 = new JTextField(); + totalTokensEarnedTextField.setEditable(false); + } + return totalTokensEarnedTextField; + + } + + private JLabel getTotalTokensEarnedLabel() { + if (totalTokensEarnedLabel == null) { + totalTokensEarnedLabel = new JLabel("Total tokens earned this round: "); + } + return totalTokensEarnedLabel; + } + + private JPanel getTimeRemainingPanel() { + timeRemainingLabel = new JLabel("Time left: "); timeRemainingLabel.setHorizontalAlignment(SwingConstants.CENTER); timeRemainingLabel.setHorizontalTextPosition(SwingConstants.CENTER); - timeRemainingLabel.setText("Time Left"); - timeRemainingTextField = new JTextField(); + timeRemainingTextField = new JTextField("50 sec"); timeRemainingTextField.setEditable(false); - // timeRemainingTextField.setBounds(new Rectangle(620, 39, 61); - timeRemainingTextField.setText("50 sec"); timeRemainingTextField.setBackground(Color.white); timeRemainingTextField.setFont(new Font("serif", Font.BOLD, 14)); timeRemainingTextField.setForeground(new Color(102, 204, 255)); timeRemainingTextField.setHorizontalAlignment(SwingConstants.CENTER); - setLayout(new BorderLayout()); - add(getDownloadScreenPanel(), BorderLayout.CENTER); + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); + panel.add(timeRemainingLabel); + panel.add(timeRemainingTextField); + return panel; } - 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("SUMMARY SCOREBOARD FOR YOU AND OTHER PLAYERS"); - dashBoardLabel = new JLabel(); - dashBoardLabel.setBounds(new Rectangle(13,225+100+35,530,20)); - dashBoardLabel.setHorizontalAlignment(SwingConstants.CENTER); - dashBoardLabel.setText("YOUR DASHBOARD"); - maximumAvailableFlowCapacityLabel = new JLabel(); - maximumAvailableFlowCapacityLabel.setBounds(new Rectangle(200, 18, 55, 17)); - maximumAvailableFlowCapacityLabel.setText(""); - totalAvailableFlowCapacityLabel = new JLabel(); - totalAvailableFlowCapacityLabel.setBounds(new Rectangle(19, 17, 170, 16)); - totalAvailableFlowCapacityLabel.setText("Irrigation 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(getUpperPanel(),null); - downloadScreenPanel.add(getTimeRemainingProgressBar(), null); - downloadScreenPanel.add(timeRemainingLabel, null); - downloadScreenPanel.add(timeRemainingTextField,null); - - downloadScreenPanel.add(totalAvailableFlowCapacityLabel, null); - downloadScreenPanel.add(maximumAvailableFlowCapacityLabel, null); - downloadScreenPanel.add(dashBoardLabel, null); - downloadScreenPanel.add(scoreBoardLabel, null); + private JLabel getIrrigationCapacityLabel() { + if (irrigationCapacityLabel == null) { + irrigationCapacityLabel = new JLabel("Irrigation capacity: "); } - return downloadScreenPanel; + return irrigationCapacityLabel; } + // 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); } return upperPanel; } + + private JButton getGateSwitchButton() { + if (gateSwitchButton == null) { + gateSwitchButton = new JButton("Open Gate"); + gateSwitchButton.setPreferredSize(new Dimension(60, 60)); + 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 getCanalPanel() { canalPanel = new CanalPanel(clientDataModel); return canalPanel; @@ -185,9 +321,7 @@ private ScoreBoxPanel getScoreBoxPanel() { if(scoreBoxPanel == null){ - scoreBoxPanel = new ScoreBoxPanel(client); - - return scoreBoxPanel; + scoreBoxPanel = new ScoreBoxPanel(); } return scoreBoxPanel; } @@ -201,7 +335,6 @@ private JProgressBar getTimeRemainingProgressBar() { if (timeRemainingProgressBar == null) { timeRemainingProgressBar = new JProgressBar(0, 50); - timeRemainingProgressBar.setBounds(new Rectangle(360, 15, 370, 17)); timeRemainingProgressBar.setBackground(Color.white); timeRemainingProgressBar.setForeground(new Color(51, 153, 255)); } @@ -212,35 +345,32 @@ * Shoudl be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. */ public void updateClientStatus(final ClientDataModel clientDataModel) { - ////////////new code//////////////////////////////////////////////////////////// Runnable createGuiRunnable = new Runnable(){ public void run() { + int timeLeft = clientDataModel.getTimeLeft(); + int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + timeRemainingTextField.setText( timeLeft + " sec"); + timeRemainingProgressBar.setValue( timeLeft ); + irrigationCapacityLabel.setText( + String.format("Irrigation capacity: %d cubic feet per second (cfps)", + irrigationCapacity)); for(final ClientData clientData : clientDataModel.getClientDataMap().values()){ - timeRemainingTextField.setText( clientDataModel.getTimeLeft() +" second(s)" ); - timeRemainingProgressBar.setValue( (clientDataModel.getTimeLeft() / 1000) ); - maximumAvailableFlowCapacityLabel.setText( - clientData.getGroupDataModel().getMaximumAvailableFlowCapacity() +" cubic feet per second (cfps)" - ); - middleWindowPanel.update(clientData); - if (clientDataModel.getPriority() == clientData.getPriority()) { - irrigationGameWindow.update(clientData); - //per parameter score panel - scoreBoxPanel.update(clientData); - } - else{ - scoreBoxPanel.update(clientData); - } - if(clientData.isGateOpen()){ + if (clientData.isGateOpen()) { canalPanel.openGates(clientData.getPriority()); - } else if(clientData.isPaused()){ canalPanel.closeGates(clientData.getPriority()); } - if(clientData.isGateClosed()){ + else if(clientData.isGateClosed()){ canalPanel.closeGates(clientData.getPriority()); } } + ClientData clientData = clientDataModel.getClientData(); + waterUsedTextField.setText("" + clientData.getWaterUsed()); + tokensNotInvestedTextField.setText("" + clientData.getUninvestedTokens()); + tokensEarnedTextField.setText("" + clientData.waterToTokenFunction()); + totalTokensEarnedTextField.setText("" + clientData.getTotalTokensEarned()); + scoreBoxPanel.update(clientDataModel); } }; @@ -293,21 +423,21 @@ //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. - fillPanels(); - } - /** * fills in the panels depending on the priority of the client */ - private void fillPanels() { + public void startRound() { upperPanel.add(getCanalPanel(), BorderLayout.CENTER); - downloadScreenPanel.add(getJPanelUpStreamWindow(),null); - downloadScreenPanel.add(getJPanelDownStreamWindow(),null); + open = false; + scoreBoxPanel.initialize(clientDataModel); + revalidate(); + // mainIrrigationPanel.add(getJPanelUpStreamWindow(),null); + // mainIrrigationPanel.add(getJPanelDownStreamWindow(),null); //adding the in between Panel - downloadScreenPanel.add(getJPanelMiddleWindow(),null); + // mainIrrigationPanel.add(getJPanelMiddleWindow(),null); } private JPanel getJPanelMiddleWindow() { @@ -320,9 +450,8 @@ return middleWindowPanel; } - public ClientDataModel getClientGameState() { + public ClientDataModel getClientDataModel() { return clientDataModel; } } -// @jve:decl-index=0:visual-constraint="10,-43" Modified: 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-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 2009-10-20 09:58:30 UTC (rev 310) @@ -544,7 +544,7 @@ if (moneyEarnedTextField == null) { moneyEarnedTextField = new JTextField(); moneyEarnedTextField.setText(new Integer(mainIrrigationWindow - .getClientGameState().getClientData().getTotalTokensEarned()) + .getClientDataModel().getClientData().getTotalTokensEarned()) .toString()); moneyEarnedTextField.setBounds(new Rectangle(161, 17, 86, 21)); moneyEarnedTextField.setFont(new Font("Dialog", Font.PLAIN, 14)); @@ -635,8 +635,9 @@ * clientData.getAvailableBandwidth()).toString()); } */ - fileDownloadedProgressBar.setValue((int) clientData.getPercentFileDownload()); +// fileDownloadedProgressBar.setValue((int) clientData.getPercentFileDownload()); // checks whether the file has been downlaoded + /* if (clientData.isFileDownloaded()) { moneyEarnedTextField.setText(new Integer(clientData.getTotalTokensEarned()) Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-20 09:58:30 UTC (rev 310) @@ -148,7 +148,7 @@ else currentBandwidthText.setText(new Double(clientData.getAvailableFlowCapacity()).toString()); - filesDownloadedText.setText(new Integer(clientData.getCropsGrown()).toString()); + filesDownloadedText.setText(new Integer(clientData.getWaterUsed()).toString()); tokensText.setText(new Integer(clientData.getTotalTokensEarned()).toString()); if(clientData.isGateOpen() && clientData.getAvailableFlowCapacity() > 0) { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java 2009-10-20 09:58:30 UTC (rev 310) @@ -1,17 +1,19 @@ package edu.asu.commons.irrigation.client; -import java.awt.Dimension; import java.awt.GridLayout; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; +import javax.swing.JLabel; import javax.swing.JPanel; import edu.asu.commons.irrigation.server.ClientData; +import edu.asu.commons.irrigation.server.GroupDataModel; /** * $Id$ - * + * + * Panel displaying data for all participants. * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev$ @@ -19,42 +21,54 @@ public class ScoreBoxPanel extends JPanel { private static final long serialVersionUID = 4724679308719540371L; - //creating a Linked Hash Map for the activity Panel Screens - //Map<Integer, ActivitySummaryPanel>activitySummaryPanelMap = new LinkedHashMap<Integer, ActivitySummaryPanel>(); - Map<Integer, SummaryPanel>activitySummaryPanelMap = new LinkedHashMap<Integer, SummaryPanel>(); - - IrrigationClient client; - int NUMBER_PARAMETERS = 3; + private List<JLabel> availableWaterLabels = new ArrayList<JLabel>(); - public ScoreBoxPanel(IrrigationClient client){ - super(); - this.client = client; - initialize(); + private List<JLabel> waterUsedLabels = new ArrayList<JLabel>(); + + private void clear() { + availableWaterLabels.clear(); + waterUsedLabels.clear(); } - - private void initialize() { - // TODO Auto-generated method stub - GridLayout gridLayout = new GridLayout(); - gridLayout.setColumns(2); - gridLayout.setRows(2); - this.setSize(new Dimension(530,326)); - this.setLayout(gridLayout); - - //add the new activity panel that gives information per Parameter - for(int i=0;i<NUMBER_PARAMETERS;i++){ - //get the activity panels per parameter - SummaryPanel activitySummaryPanelNew = new SummaryPanel(i,client); - activitySummaryPanelMap.put(new Integer(i), activitySummaryPanelNew); - this.add(activitySummaryPanelNew); + + public void initialize(ClientDataModel clientDataModel) { + clear(); + // number of clients + 1 for the labels + GroupDataModel groupDataModel = clientDataModel.getGroupDataModel(); + int columns = groupDataModel.size() + 1; + GridLayout gridLayout = new GridLayout(3, columns); + setLayout(gridLayout); + + add(new JLabel("Position")); + List<ClientData> clientDataList = clientDataModel.getClientDataSortedByPriority(); + for (ClientData clientData : clientDataList) { + add(new JLabel(clientData.getPriorityAsString())); } + // available water per second + add(new JLabel("Available water per second")); + for (ClientData clientData: clientDataList) { + JLabel availableWaterLabel = new JLabel("" + clientData.getAvailableFlowCapacity()); + availableWaterLabels.add(availableWaterLabel); + add(availableWaterLabel); + } + // water used + add(new JLabel("Water used")); + for (ClientData clientData : clientDataList) { + JLabel waterUsedLabel = new JLabel("" + clientData.getWaterUsed()); + waterUsedLabels.add(waterUsedLabel); + add(waterUsedLabel); + } } - public void update(ClientData clientData){ - //update specific panel if activity Summary panel is being used, else update all the panels. - //activitySummaryPanelMap.get(new Integer(clientData.getPriority())).update(clientData); - for(int i=0;i<NUMBER_PARAMETERS;i++){ - activitySummaryPanelMap.get(new Integer(i)).update(clientData); + public void update(ClientDataModel clientDataModel) { + List<ClientData> clientDataList = clientDataModel.getClientDataSortedByPriority(); + for (int index = 0; index < clientDataList.size(); index++) { + ClientData clientData = clientDataList.get(index); + JLabel availableWaterLabel = availableWaterLabels.get(index); + availableWaterLabel.setText("" + clientData.getAvailableFlowCapacity()); + JLabel waterUsedLabel = waterUsedLabels.get(index); + waterUsedLabel.setText("" + clientData.getWaterUsed()); } + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-20 09:58:30 UTC (rev 310) @@ -63,10 +63,6 @@ return getIntProperty("max-infrastructure-efficiency", 100); } - public double getMaximumIndividualFlowCapacity() { - return getDoubleProperty("max-individual-flow-capacity", 20.0d); - } - public boolean isPracticeRound() { return getBooleanProperty("practice-round"); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-20 09:58:30 UTC (rev 310) @@ -30,27 +30,10 @@ private GroupDataModel groupDataModel; - private String fileNumber; - - private List<String> filesDownloadedList = new ArrayList<String>(); - - private boolean fileDownloaded = false; + private int waterUsed = 0; - private int fileSize; + private int availableFlowCapacity; - private double percentFileDownloaded = 0; - - private double downloadedFileSize = 0; - - private int cropsGrown = 0; - - // maximum available bandwidth - private double maximumIndividualFlowCapacity; - /** - * current download speed - */ - private double availableFlowCapacity = 25.0d; - private int investedTokens; private int assignedNumber; @@ -59,8 +42,6 @@ private int totalTokens; - private int tokensCollectedLastRound; - private boolean paused = false; private boolean gateOpen = false; @@ -80,29 +61,15 @@ public boolean isGateOpen(){ return gateOpen; } - - // cap on the size of the entire stream (e.g,. 50 kbps) - public double getMaximumAvailableBandwidth(){ - return groupDataModel.getMaximumAvailableFlowCapacity(); - } - // cap on the size of the stream that can be delivered to the client (e.g., 25 kbps) - public void setMaximumIndividualFlowCapacity(double deliveryBandwidth){ - this.maximumIndividualFlowCapacity = deliveryBandwidth; - } - - public double getMaximumIndividualFlowCapacity(){ - return maximumIndividualFlowCapacity; - } - /** * The actual bandwidth allocated to this client. */ - public void setAvailableFlowCapacity(double availableFlowCapacity){ + public void setAvailableFlowCapacity(int availableFlowCapacity) { this.availableFlowCapacity = availableFlowCapacity; } - public double getAvailableFlowCapacity(){ + public int getAvailableFlowCapacity(){ return availableFlowCapacity; } @@ -120,23 +87,7 @@ } return "Position not found"; } - - /** - * set and get the current file_no from the client.The corresponding file sizes and their numbers - * are listed down in the configuration file. Thus I can get their sizes. - * - */ - public void setFileNumber(String fileNumber){ - this.fileNumber = fileNumber; - } - public String getFileNumber() { - return fileNumber; - } - - public double getPercentFileDownload(){ - return percentFileDownloaded; - } /** * here the parameters isPaused, isStopped and isStartDownload would change. * The server every time would check the clients queue. It would be a queue of clients requests. @@ -149,7 +100,7 @@ paused = false; } - public void setPaused(){ + public void pause(){ paused = true; gateOpen = false; } @@ -197,17 +148,15 @@ * clearing the clientData at the end of each round * */ - public void reset() { - resetFileInformation(); + public void endRound() { closeGate(); investedTokens = 0; //adding number of files to be downloaded = 0 per round - cropsGrown = 0; - filesDownloadedList.clear(); + waterUsed = 0; } public void resetAllTokens() { - reset(); + endRound(); totalTokens = 0; } @@ -223,9 +172,6 @@ return totalTokens; } - public int getTokensCollectedLastRound() { - return tokensCollectedLastRound; - } public RoundConfiguration getRoundConfiguration(){ return roundConfiguration; @@ -234,21 +180,11 @@ * This would initialize the clientData before the start of each download. * */ - public void init(double availableFlowCapacity) { - resetFileInformation(); - maximumIndividualFlowCapacity = getRoundConfiguration().getMaximumIndividualFlowCapacity(); - //currentBandwidth = totalContributedBandwidth; - this.availableFlowCapacity = availableFlowCapacity; + public void init(int availableFlowCapacity) { + closeGate(); + setAvailableFlowCapacity(availableFlowCapacity); } - private void resetFileInformation() { - fileSize = 0; - fileNumber = ""; - downloadedFileSize = 0; - percentFileDownloaded = 0; - closeGate(); - } - public void award() { totalTokens += getTotalTokensEarned(); } @@ -258,102 +194,71 @@ * @return */ public int getTotalTokensEarned(){ - return calculateTokensEarned() + (getRoundConfiguration().getMaximumInvestedTokens() - investedTokens); + return waterToTokenFunction() + getUninvestedTokens(); } /** - * complex functions can be defined here + * Reward function table correlating water usage to tokens earned. + * * @param value * @return */ - - private int calculateTokensEarned() { - switch (cropsGrown) { - case 0: case 1: + public int waterToTokenFunction() { + if (waterUsed < 150) { return 0; - case 2: - return 6; - case 3: - return 22; - case 4: - return 28; - case 5: - return 30; - default: - throw new IllegalStateException("Should be a number between 0-5, was " + cropsGrown + " instead."); } -// double alpha,b,a,num,deno; -// /** -// * This would be taken by a proper configuration file -// */ -// alpha = getRoundConfiguration().getAlphaAward(); -// a = getRoundConfiguration().getA_award(); -// b = getRoundConfiguration().getB_award(); -// num = alpha * Math.pow((double)filesDownloaded,b); -// deno = Math.pow(a,b)+Math.pow(filesDownloaded,b); -// -// /** -// * until u get the final equation, you can go ahead with -// * these values.. -// */ -// return (int)(Math.round(num/deno)); - //return no_fileDownloaded; + else if (waterUsed < 200) { + return 1; + } + else if (waterUsed < 250) { + return 4; + } + else if (waterUsed < 300) { + return 10; + } + else if (waterUsed < 350) { + return 15; + } + else if (waterUsed < 400) { + return 18; + } + else if (waterUsed < 500) { + return 19; + } + else if (waterUsed < 550) { + return 20; + } + else if (waterUsed < 650) { + return 19; + } + else if (waterUsed < 700) { + return 18; + } + else if (waterUsed < 750) { + return 15; + } + else if (waterUsed < 800) { + return 10; + } + else if (waterUsed < 850) { + return 4; + } + else if (waterUsed < 900) { + return 1; + } + else { + return 0; + } } - /** - * calculates the percent of the file downloaded - * - */ - /** - *Here check whether the percentageFile > 100, then init the file download - *else simply increment the filesize. If we increment the file size and then - *check whether the filesize > 100 and then invoke completedownload, that information - *is not send to the client, as the sending file progress events are in the same loop - *as processDownload function - */ - public void allocateFlowCapacity(double availableBandwidth) { - assert gateOpen; - fileDownloaded = false; - incrementFileDownloadSize(); + + public void collectWater() { + waterUsed += availableFlowCapacity; } - private void completeFileDownload() { - cropsGrown++; - fileDownloaded = true; - filesDownloadedList.add(fileNumber); - groupDataModel.getEventChannel().handle(new FileDownloadedEvent(id, fileNumber)); - resetFileInformation(); - //init(availableBandwidth); + public int getWaterUsed(){ + return waterUsed; } - - /** - * This would increament the percentage of the file downloaded - * by Bi - * - */ - public void incrementFileDownloadSize(){ - downloadedFileSize += availableFlowCapacity; - percentFileDownloaded = (downloadedFileSize/fileSize)*100; - if (percentFileDownloaded >= 100) { - //filesDownloaded++; - percentFileDownloaded = 100; - completeFileDownload(); - } - - } - public int getCropsGrown(){ - return cropsGrown; - } - - public boolean isFileDownloaded() { - return fileDownloaded; - } - - public List<String> getDownloadListArray() { - return filesDownloadedList; - } - - } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-20 09:58:30 UTC (rev 310) @@ -70,6 +70,10 @@ clients.put(clientData.getId(), clientData); clientData.setAssignedNumber(clients.size()); } + + public int size() { + return clients.size(); + } public void removeClient(Identifier id) { clients.remove(id); @@ -99,14 +103,13 @@ return serverDataModel.getRoundConfiguration(); } - //get totalContributed tokens for this round public int getTotalContributedTokens() { return totalContributedTokens; } public void calculateTotalFlowCapacity() { // for practice round and first round, initialize to initial infrastructure efficiency - //setting the total contributed Bandwidth = 0 , so thatfor every round, + //setting the total contributed Bandwidth = 0 , so that for every round, // fresh totalContributed tokens are calculated totalContributedTokens = 0; for(ClientData clientData : getClientDataMap().values()) { @@ -194,16 +197,17 @@ } public void allocateFlowCapacity(ClientData clientData) { - if (currentlyAvailableFlowCapacity >= clientData.getMaximumIndividualFlowCapacity()) { - currentlyAvailableFlowCapacity -= clientData.getMaximumIndividualFlowCapacity(); -// setAvailableBandwidth(clientData.getTotalContributedBandwidth() - clientData.getDeliveryBandwidth()); - clientData.setAvailableFlowCapacity(clientData.getMaximumIndividualFlowCapacity()); + RoundConfiguration roundConfiguration = getRoundConfiguration(); + int maximumClientFlowCapacity = roundConfiguration.getMaximumClientFlowCapacity(); + if (currentlyAvailableFlowCapacity >= maximumClientFlowCapacity) { + currentlyAvailableFlowCapacity -= maximumClientFlowCapacity; + clientData.setAvailableFlowCapacity(maximumClientFlowCapacity); } else { clientData.setAvailableFlowCapacity(currentlyAvailableFlowCapacity); currentlyAvailableFlowCapacity = 0; } - clientData.allocateFlowCapacity(currentlyAvailableFlowCapacity); + clientData.collectWater(); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-20 06:07:13 UTC (rev 309) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-20 09:58:30 UTC (rev 310) @@ -259,7 +259,7 @@ }); addEventProcessor(new EventTypeProcessor<PauseRequest>(PauseRequest.class) { public void handle(PauseRequest event) { - clients.get(event.getId()).setPaused(); + clients.get(event.getId()).pause(); } }); } @@ -414,7 +414,7 @@ clientData.resetAllTokens(); } else { - clientData.reset(); + clientData.endRound(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-21 06:50:56
|
Revision: 312 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=312&view=rev Author: alllee Date: 2009-10-21 05:59:23 +0000 (Wed, 21 Oct 2009) Log Message: ----------- updated contribution text area and continuing to refine game interface layout. 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/ScoreBoxPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Removed Paths: ------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/SummaryPanel.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-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Ball.java 2009-10-21 05:59:23 UTC (rev 312) @@ -2,14 +2,8 @@ import java.util.Random; -public class Ball{ +public class Ball { - public boolean isInServer; - - public boolean isInFirstCanal; - - public boolean isInSecondCanal; - private int size = 2; public int x; @@ -19,10 +13,10 @@ public int moveX; public int moveY; - public int xBOUNDSUPPER; - public int xBOUNDSLOWER; - public int yBOUNDSUPPER; - public int yBOUNDSLOWER; + public int xUpperBound; + public int xLowerBound; + public int yUpperBound; + public int yLowerBound; //just one global variable speciying the ten potential positions of the balls private int position; @@ -31,10 +25,10 @@ this.x = generator.nextInt(100); this.y = generator.nextInt(100); - this.xBOUNDSUPPER = 100; - this.yBOUNDSUPPER = 100; - this.xBOUNDSLOWER = 0; - this.yBOUNDSLOWER = 0; + this.xUpperBound = 100; + this.yUpperBound = 100; + this.xLowerBound = 0; + this.yLowerBound = 0; this.moveX = generator.nextInt(15); this.moveY = generator.nextInt(10); /*this.moveX = 3; @@ -44,30 +38,13 @@ } public void setPosition(int position) { - // TODO Auto-generated method stub - - //System.out.println("Setting the position :"+position); - this.position = position; - } public int getBallSize(){ return size; } - public boolean getIsInServer(){ - return isInServer; - } - - public boolean getIsInFirstCanal(){ - return isInFirstCanal; - } - - public boolean getIsInSecondCanal(){ - return isInSecondCanal; - } - public void setX(int x){ this.x = x; } @@ -77,25 +54,14 @@ } public int getPosition() { - // TODO Auto-generated method stub return position; } public int getX() { - // TODO Auto-generated method stub return x; } - /* - * will set the upper and the lower bounds for a ball depending on its position - */ - /*public void setBounds(int position) { - // TODO Auto-generated method stub - - }*/ - public int getY() { - // TODO Auto-generated method stub return y; } 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-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-10-21 05:59:23 UTC (rev 312) @@ -264,10 +264,10 @@ //still in server else { setBounds(i); - if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + if(balls[i].x <= balls[i].xUpperBound || balls[i].x >= balls[i].xUpperBound-balls[i].getBallSize()){ balls[i].moveX = balls[i].moveX * -1; } - if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + if(balls[i].y <= balls[i].yLowerBound || balls[i].y >= balls[i].yUpperBound-balls[i].getBallSize()) balls[i].moveY = balls[i].moveY * -1; } break; @@ -280,9 +280,9 @@ //directly pass in the information setBounds(i); /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER - +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER);*/ + +" X Lower"+balls[i].xLowerBound+" X Upper"+balls[i].xBOUNDSUPPER);*/ /* balls[i].xBOUNDSUPPER = 420; - balls[i].xBOUNDSLOWER = 400; + balls[i].xLowerBound = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; @@ -291,12 +291,12 @@ else{ setBounds(i); /*System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER - +" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); + +" X Lower"+balls[i].xLowerBound+" X Upper"+balls[i].xBOUNDSUPPER); */ - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(2); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -309,7 +309,7 @@ //directly pass in the information setBounds(i); /* balls[i].xBOUNDSUPPER = 420; - balls[i].xBOUNDSLOWER = 400; + balls[i].xLowerBound = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; @@ -317,10 +317,10 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(3); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -333,7 +333,7 @@ //directly pass in the information setBounds(i); /* balls[i].xBOUNDSUPPER = 420; - balls[i].xBOUNDSLOWER = 400; + balls[i].xLowerBound = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; @@ -341,10 +341,10 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(4); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -356,7 +356,7 @@ //directly pass in the information setBounds(i); /* balls[i].xBOUNDSUPPER = 420; - balls[i].xBOUNDSLOWER = 400; + balls[i].xLowerBound = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; @@ -364,10 +364,10 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(5); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -379,7 +379,7 @@ //directly pass in the information setBounds(i); /* balls[i].xBOUNDSUPPER = 420; - balls[i].xBOUNDSLOWER = 400; + balls[i].xLowerBound = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; @@ -387,17 +387,17 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(6); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } break; case 6: setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ /*balls[i].setX(generator.nextInt(100)); balls[i].setY(100 - gate[0].getHeight()+ generator.nextInt(gate[0].getHeight())); balls[i].setPosition(0); @@ -405,7 +405,7 @@ setBallInTank(i); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } break; @@ -425,7 +425,7 @@ else{ setBounds(i); //System.out.println("X upper :"+balls[i].xBOUNDSUPPER+" Y Upper :"+balls[i].yBOUNDSUPPER - //+" X Lower"+balls[i].xBOUNDSLOWER+" X Upper"+balls[i].xBOUNDSUPPER); + //+" X Lower"+balls[i].xLowerBound+" X Upper"+balls[i].xBOUNDSUPPER); } } } @@ -448,10 +448,10 @@ private void setBounds(int ballIndex) { // ball is in the server if(balls[ballIndex].getPosition() == 0){ - balls[ballIndex].xBOUNDSUPPER = 100; - balls[ballIndex].xBOUNDSLOWER = 0; - balls[ballIndex].yBOUNDSUPPER = 100; - balls[ballIndex].yBOUNDSLOWER = 0; + balls[ballIndex].xUpperBound = 100; + balls[ballIndex].xLowerBound = 0; + balls[ballIndex].yUpperBound = 100; + balls[ballIndex].yLowerBound = 0; //balls[ballIndex].moveX = generator.nextInt(6); //balls[ballIndex].moveY = generator.nextInt(6); //balls[ballIndex].moveX = 3; @@ -461,20 +461,20 @@ if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getY(); + balls[ballIndex].xUpperBound = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); + balls[ballIndex].xLowerBound = gate[balls[ballIndex].getPosition() - 1].getX(); + balls[ballIndex].yUpperBound = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; + balls[ballIndex].yLowerBound = gate[balls[ballIndex].getPosition() - 1].getY(); //balls[ballIndex].moveX = 3; //balls[ballIndex].moveY = 3; } //the ball is in one of the openings else{ - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); + balls[ballIndex].xUpperBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); + balls[ballIndex].xLowerBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); + balls[ballIndex].yUpperBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); + balls[ballIndex].yLowerBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); balls[ballIndex].moveX = 0; balls[ballIndex].moveY = 3; } 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-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-21 05:59:23 UTC (rev 312) @@ -86,8 +86,8 @@ } protected void paintComponent(Graphics graphics){ + super.paintComponent(graphics); // needed! updateGUI(); - super.paintComponent(graphics); // needed! Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.setColor(Color.BLUE); graphics2D.fillRect(0,0,serverHeight,serverWidth); @@ -213,7 +213,7 @@ * This will process the balls according to their position */ private void process(int i){ - switch(balls[i].getPosition()){ + switch(balls[i].getPosition()) { case 0: if((balls[i].x >= (serverWidth - gateBuffer ) && balls[i].x <= serverWidth) && (balls[i].y >= serverHeight-(int)(maximumIrrigationCapacity*bandWidthCanalHeightMapping) && balls[i].y <= serverHeight)){ @@ -223,10 +223,10 @@ //still in server else{ setBounds(i); - if(balls[i].x <= balls[i].xBOUNDSLOWER || balls[i].x >= balls[i].xBOUNDSUPPER-balls[i].getBallSize()){ + if(balls[i].x <= balls[i].xLowerBound || balls[i].x >= balls[i].xUpperBound-balls[i].getBallSize()){ balls[i].moveX = balls[i].moveX * -1; } - if(balls[i].y <= balls[i].yBOUNDSLOWER || balls[i].y >= balls[i].yBOUNDSUPPER-balls[i].getBallSize()) + if(balls[i].y <= balls[i].yLowerBound || balls[i].y >= balls[i].yUpperBound-balls[i].getBallSize()) balls[i].moveY = balls[i].moveY * -1; } break; @@ -239,10 +239,10 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(2); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -257,10 +257,10 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(3); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -273,7 +273,7 @@ //directly pass in the information setBounds(i); /* balls[i].xBOUNDSUPPER = 420; - balls[i].xBOUNDSLOWER = 400; + balls[i].xLowerBound = 400; balls[i].yBOUNDSUPPER = 150; balls[i].yBOUNDSLOWER = 80; balls[i].moveX = 0; @@ -281,10 +281,10 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(4); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -298,10 +298,10 @@ } else{ setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(5); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } @@ -313,23 +313,23 @@ //directly pass in the information setBounds(i); } - else{ + else { setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ balls[i].setPosition(6); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } } break; case 6: setBounds(i); - if(balls[i].getX() > balls[i].xBOUNDSUPPER){ + if(balls[i].getX() > balls[i].xUpperBound){ setBallInServer(i); } - if(balls[i].getY() >= balls[i].yBOUNDSUPPER - balls[i].getBallSize() || balls[i].getY() <= balls[i].yBOUNDSLOWER){ + if(balls[i].getY() >= balls[i].yUpperBound - balls[i].getBallSize() || balls[i].getY() <= balls[i].yLowerBound){ balls[i].moveY = balls[i].moveY*-1; } break; @@ -362,10 +362,10 @@ // TODO Auto-generated method stub //ball is in the server if(balls[ballIndex].getPosition() == 0){ - balls[ballIndex].xBOUNDSUPPER = serverWidth; - balls[ballIndex].xBOUNDSLOWER = 0; - balls[ballIndex].yBOUNDSUPPER = serverHeight; - balls[ballIndex].yBOUNDSLOWER = 0; + balls[ballIndex].xUpperBound = serverWidth; + balls[ballIndex].xLowerBound = 0; + balls[ballIndex].yUpperBound = serverHeight; + balls[ballIndex].yLowerBound = 0; //balls[ballIndex].moveX = generator.nextInt(6); //balls[ballIndex].moveY = generator.nextInt(6); //balls[ballIndex].moveX = 3; @@ -375,17 +375,17 @@ if((balls[ballIndex].getPosition() == 1)||(balls[ballIndex].getPosition() == 2) || (balls[ballIndex].getPosition()==3) || (balls[ballIndex].getPosition() == 4) || (balls[ballIndex].getPosition() == 5)||(balls[ballIndex].getPosition() == 6)){ - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 1].getY(); + balls[ballIndex].xUpperBound = gate[balls[ballIndex].getPosition() - 1].getX()+gate[balls[ballIndex].getPosition() - 1].getWidth(); + balls[ballIndex].xLowerBound = gate[balls[ballIndex].getPosition() - 1].getX(); + balls[ballIndex].yUpperBound = gate[balls[ballIndex].getPosition() - 1].getY()/*+gate[balls[ballIndex].getPosition() - 1].getHeight()*/; + balls[ballIndex].yLowerBound = gate[balls[ballIndex].getPosition() - 1].getY(); } //the ball is in one of the openings else{ - balls[ballIndex].xBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); - balls[ballIndex].xBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); - balls[ballIndex].yBOUNDSUPPER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); - balls[ballIndex].yBOUNDSLOWER = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); + balls[ballIndex].xUpperBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsX()+gate[balls[ballIndex].getPosition() - 7].getGateWidth(); + balls[ballIndex].xLowerBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsX(); + balls[ballIndex].yUpperBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsY()+gate[balls[ballIndex].getPosition() - 7].getOpeningsHeight(); + balls[ballIndex].yLowerBound = gate[balls[ballIndex].getPosition() - 7].getOpeningsY(); //X change in motion balls[ballIndex].moveX = 0; //Y change in motion 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-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-21 05:59:23 UTC (rev 312) @@ -12,7 +12,6 @@ import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.lang.reflect.InvocationTargetException; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -76,8 +75,6 @@ private StringBuilder instructionsBuilder = new StringBuilder(); - private int totalContributedTokensPerGroup; - private JTextArea contributionInformationTextArea; private JButton nextButton; @@ -567,36 +564,34 @@ } - public void updateGraphDisplay(final ClientData clientData) { - totalContributedTokensPerGroup = clientData.getGroupDataModel().getTotalContributedTokens(); - DecimalFormat df = new DecimalFormat("#.##"); - final String contributionInformation = - "Initial infrastructure efficiency: " + clientData.getGroupDataModel().getInitialInfrastructureEfficiency() + "%" - + "\n\nInitial flow capacity: " + clientData.getGroupDataModel().getInitialFlowCapacity() + " cubic feet per second " - + "\n\nActual infrastructure efficiency: " + clientData.getGroupDataModel().getInfrastructureEfficiency() + "%" - + "\n\nActual total flow capacity: " - + df.format(clientData.getGroupDataModel().getMaximumAvailableFlowCapacity()) + " cubic feet per second \n\n" - + "\n\nMaximum tokens that could have been contributed: " - + clientDataModel.getRoundConfiguration().getMaximumTotalInvestedTokens() - + "\n\nTotal tokens contributed: " - + totalContributedTokensPerGroup - + "\n\nYour token contribution: " - + clientData.getInvestedTokens() - + "\n\nTotal flow capacity that could have been generated: " - + clientDataModel.getRoundConfiguration().getMaximumCanalFlowCapacity() - + " cubic feet per second"; - - - + public void displayTokenContributions(final ClientData clientData) { + GroupDataModel groupDataModel = clientData.getGroupDataModel(); + int totalContributedTokensPerGroup = groupDataModel.getTotalContributedTokens(); + final StringBuilder builder = new StringBuilder(); + builder.append("Infrastructure efficiency before investment: ") + .append(groupDataModel.getInitialInfrastructureEfficiency()) + .append("%\n"); + builder.append("Irrigation capacity before investment: ").append(groupDataModel.getInitialFlowCapacity()).append(" cubic feet per second\n\n"); + builder.append( + String.format( + "Your group invested a total of %d tokens, increasing the infrastructure efficiency to %d%%.\n", + groupDataModel.getTotalContributedTokens(), groupDataModel.getInfrastructureEfficiency())); + if (groupDataModel.getFlowCapacity() > groupDataModel.getInitialFlowCapacity()) { + builder.append("Your group's investment has increased the irrigation capacity to "); + } + else { + builder.append("Your group's irrigation capacity after investment is "); + } + builder.append(groupDataModel.getFlowCapacity()).append('.'); SwingUtilities.invokeLater(new Runnable() { public void run() { - contributionInformationTextArea.setText(contributionInformation); + contributionInformationTextArea.setText(builder.toString()); infrastructureEfficiencyChartPanel.initialize(); pieChart.setClientData(clientData); addCenterComponent(getGraphPanel()); } }); - irrigationGamePanel.updateContributions(clientDataModel); + irrigationGamePanel.setClientDataModel(clientDataModel); } public JPanel getGraphPanel() { @@ -607,6 +602,7 @@ graphPanel.add(getPieChartPanel()); contributionInformationTextArea = new JTextArea(); contributionInformationTextArea.setEditable(false); + graphPanel.add(contributionInformationTextArea); } return graphPanel; 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-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-21 05:59:23 UTC (rev 312) @@ -170,7 +170,7 @@ public void handle(InfrastructureUpdateEvent event) { System.err.println("Received group update event: " + event); clientDataModel.setGroupDataModel(event.getGroupDataModel()); - experimentGameWindow.updateGraphDisplay(event.getClientData()); + experimentGameWindow.displayTokenContributions(event.getClientData()); } }); channel.add(this, new EventTypeProcessor<RoundStartedEvent>(RoundStartedEvent.class) { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-21 05:59:23 UTC (rev 312) @@ -46,7 +46,7 @@ //this contains the upstream and downstream Panel private JPanel jPanelUpStreamWindow = null; private JPanel jPanelDownStreamWindow = null; - private JPanel mainIrrigationPanel = null; +// private JPanel mainIrrigationPanel = null; private ScoreBoxPanel scoreBoxPanel; @@ -186,7 +186,7 @@ private JLabel getWaterUsedLabel() { if (waterUsedLabel == null) { - waterUsedLabel = new JLabel("Water units used: "); + waterUsedLabel = new JLabel("Water units collected: "); } return waterUsedLabel; } @@ -293,8 +293,8 @@ private JButton getGateSwitchButton() { if (gateSwitchButton == null) { - gateSwitchButton = new JButton("Open Gate"); - gateSwitchButton.setPreferredSize(new Dimension(60, 60)); + gateSwitchButton = new JButton("Open gate"); + gateSwitchButton.setPreferredSize(new Dimension(100, 100)); gateSwitchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { open = !open; @@ -375,9 +375,9 @@ } return timeRemainingProgressBar; } - //this event gets called every second in the experiment. + /** - * Shoudl be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. + * Should be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. */ public void updateClientStatus(final ClientDataModel clientDataModel) { Runnable createGuiRunnable = new Runnable(){ @@ -442,6 +442,8 @@ canalPanel.endRound(); } }; + open = false; + gateSwitchButton.setText("Open gate"); try { SwingUtilities.invokeAndWait(createGuiRunnable); @@ -453,15 +455,8 @@ } - /** - * assigns the priority to the window and prepares the irrigationWindowMap - */ - public void updateContributions(final ClientDataModel clientDataModel) { + 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. } @@ -469,8 +464,8 @@ * fills in the panels depending on the priority of the client */ public void startRound() { - upperPanel.add(getCanalPanel(), BorderLayout.CENTER); open = false; + upperPanel.add(getCanalPanel(), BorderLayout.CENTER); getScoreBoxPanel().initialize(clientDataModel); getMiddleWindowPanel().initialize(clientDataModel); revalidate(); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java 2009-10-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java 2009-10-21 05:59:23 UTC (rev 312) @@ -29,6 +29,7 @@ private void clear() { availableWaterLabels.clear(); waterUsedLabels.clear(); + removeAll(); } public void initialize(ClientDataModel clientDataModel) { @@ -39,20 +40,20 @@ GridLayout gridLayout = new GridLayout(3, columns); setLayout(gridLayout); - add(new JLabel("Position")); + add(new JLabel("Position:")); List<ClientData> clientDataList = clientDataModel.getClientDataSortedByPriority(); for (ClientData clientData : clientDataList) { add(new JLabel(clientData.getPriorityAsString())); } // available water per second - add(new JLabel("Available water per second")); + add(new JLabel("Available water per second:")); for (ClientData clientData: clientDataList) { JLabel availableWaterLabel = new JLabel("" + clientData.getAvailableFlowCapacity()); availableWaterLabels.add(availableWaterLabel); add(availableWaterLabel); } // water used - add(new JLabel("Water used")); + add(new JLabel("Water collected:")); for (ClientData clientData : clientDataList) { JLabel waterUsedLabel = new JLabel("" + clientData.getWaterUsed()); waterUsedLabels.add(waterUsedLabel); Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/SummaryPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/SummaryPanel.java 2009-10-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/SummaryPanel.java 2009-10-21 05:59:23 UTC (rev 312) @@ -1,33 +0,0 @@ -package edu.asu.commons.irrigation.client; - -import javax.swing.JPanel; - -import edu.asu.commons.irrigation.server.ClientData; - - -/** - * $Id$ - * - * - * @author <a href='mailto:All...@as...'>Allen Lee</a> - * @version $Rev$ - */ -public class SummaryPanel extends JPanel { - - private static final long serialVersionUID = 2393688647176774993L; - - private IrrigationClient client; - - - public SummaryPanel(int parameterIndex, IrrigationClient client) { - super(); - this.client = client; - } - - - - public void update(ClientData clientData) { - - } - -} Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-21 05:59:23 UTC (rev 312) @@ -1,11 +1,8 @@ package edu.asu.commons.irrigation.server; import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; import edu.asu.commons.irrigation.conf.RoundConfiguration; -import edu.asu.commons.irrigation.events.FileDownloadedEvent; import edu.asu.commons.net.Identifier; /** @@ -18,7 +15,7 @@ * minus tokens subtracted by others * minus tokens subtracted by sanctioning others * - * @author <a href='ano...@gm...'>Allen Lee</a>, Deepali Bhagvat + * @author <a href='mailto:all...@as...'>Allen Lee</a>, Deepali Bhagvat * @version $Revision$ */ Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-21 05:59:23 UTC (rev 312) @@ -95,8 +95,8 @@ return Collections.unmodifiableMap(clients); } - public int getCurrentlyAvailableFlowCapacity(){ - return currentlyAvailableFlowCapacity; + public int getAvailableClientFlowCapacity(){ + return Math.min(currentlyAvailableFlowCapacity, getRoundConfiguration().getMaximumClientFlowCapacity()); } public RoundConfiguration getRoundConfiguration() { @@ -197,8 +197,7 @@ } public void allocateFlowCapacity(ClientData clientData) { - RoundConfiguration roundConfiguration = getRoundConfiguration(); - int maximumClientFlowCapacity = roundConfiguration.getMaximumClientFlowCapacity(); + int maximumClientFlowCapacity = getRoundConfiguration().getMaximumClientFlowCapacity(); if (currentlyAvailableFlowCapacity >= maximumClientFlowCapacity) { currentlyAvailableFlowCapacity -= maximumClientFlowCapacity; clientData.setAvailableFlowCapacity(maximumClientFlowCapacity); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-21 00:29:19 UTC (rev 311) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-21 05:59:23 UTC (rev 312) @@ -316,7 +316,7 @@ group.allocateFlowCapacity(clientData); } else if (clientData.isGateClosed()) { - clientData.init(group.getCurrentlyAvailableFlowCapacity()); + clientData.init(group.getAvailableClientFlowCapacity()); } // right now the clients cannot be paused. else if (clientData.isPaused()) { @@ -341,7 +341,7 @@ private IrrigationServerState state; - private long lastTime; +// private long lastTime; private Duration secondTick = Duration.create(1000L); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-21 07:35:07
|
Revision: 313 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=313&view=rev Author: alllee Date: 2009-10-21 07:35:00 +0000 (Wed, 21 Oct 2009) Log Message: ----------- fixed debriefing table for arbitrary numbers of clients instead of hard coded 5 clients by transposing it. 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 irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-21 07:35:00 UTC (rev 313) @@ -45,6 +45,11 @@ public ClientData getClientData() { return groupDataModel.getClientData( getId() ); } + + public String getPriorityString() { + return getClientData().getPriorityString(); + } + public Identifier getId() { return client.getId(); 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-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-21 07:35:00 UTC (rev 313) @@ -402,14 +402,14 @@ }; try { SwingUtilities.invokeAndWait(runnable); - } catch (InterruptedException e) { - // TODO Auto-generated catch block + } + catch (InterruptedException e) { e.printStackTrace(); - } catch (InvocationTargetException e) { - // TODO Auto-generated catch block + } + catch (InvocationTargetException e) { e.printStackTrace(); } - info("IrrigationGameWindow finished cleanup, ending round completed."); + info("ExperimentGameWindow finished cleanup, ending round completed."); } private void info(String message) { @@ -422,74 +422,85 @@ */ private void addDebriefingText(EndRoundEvent event) { instructionsBuilder.delete(0, instructionsBuilder.length()); - - Map<Identifier,ClientData> clientDataMap = event.getClientDataMap(); - - String positionString = "Your position is: " + event.getClientData().getPriorityAsString(); - ClientData[] allClientData = new ClientData[clientDataMap.size()]; - for(ClientData clientData : clientDataMap.values()) { - allClientData[clientData.getPriority()] = clientData; + instructionsBuilder.append("<b>You were in position " + clientDataModel.getPriorityString()); + instructionsBuilder.append( + "<table><thead><th>Position</th><th>Initial token endowment</th><th>Tokens invested</th><th>Tokens not invested</th>" + + "<th>Tokens earned from growing crops</th><th>Total tokens earned during this round</th>" + + "<th>Dollars earned during this round</th><th>Total dollars earned (including show-up bonus)</th></thead>" + + "<tbody>"); + double showUpBonus = clientDataModel.getServerConfiguration().getShowUpPayment(); + for(ClientData clientData : clientDataModel.getClientDataSortedByPriority()) { + instructionsBuilder.append( + String.format("<tr><td>%s</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>$%3.2f</td><td>$%3.2f</td></tr>", + clientData.getPriorityString(), + clientData.getMaximumTokenInvestment(), + clientData.getInvestedTokens(), + clientData.getUninvestedTokens(), + clientData.getAllTokensEarnedThisRound(), + clientData.getTokensEarnedFromWaterCollected(), + clientData.getAllTokensEarnedThisRound(), + clientData.getTotalDollarsEarnedThisRound(), + clientData.getTotalDollarsEarned() + showUpBonus + )); } - ClientData clientData = event.getClientData(); - RoundConfiguration roundConfiguration = clientData.getRoundConfiguration(); - double dollarsPerToken = roundConfiguration.getDollarsPerToken(); - // FIXME: wow - instructionsBuilder.append(String.format( - positionString + - "<table><thead><th></th><th></th><th>A</th><th></th><th>B</th><th></th><th>C</th><th></th><th>D</th><th></th><th>E</th></thead><tbody>"+ - "<tr><td>A Initial endowment</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td><td></td><td>10</td></tr>"+ - "<tr><td>B Infrastructure investment</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>C Kept endowment (A - B)</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>D Return from growing crops</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>E Total tokens earned in last round(D+C)</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td><td></td><td>%d</td></tr>"+ - "<tr><td>F Total dollars earned in this round (E*0.1$)</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td><td></td><td>%3.2f</td></tr>", - allClientData[0].getInvestedTokens(), - allClientData[1].getInvestedTokens(), - allClientData[2].getInvestedTokens(), - allClientData[3].getInvestedTokens(), - allClientData[4].getInvestedTokens(), - - allClientData[0].getUninvestedTokens(), - allClientData[1].getUninvestedTokens(), - allClientData[2].getUninvestedTokens(), - allClientData[3].getUninvestedTokens(), - allClientData[4].getUninvestedTokens(), + + ClientData clientData = clientDataModel.getClientData(); + RoundConfiguration configuration = clientDataModel.getRoundConfiguration(); - allClientData[0].getTotalTokensEarned() - allClientData[0].getUninvestedTokens(), - allClientData[1].getTotalTokensEarned() - allClientData[1].getUninvestedTokens(), - allClientData[2].getTotalTokensEarned() - allClientData[2].getUninvestedTokens(), - allClientData[3].getTotalTokensEarned() - allClientData[3].getUninvestedTokens(), - allClientData[4].getTotalTokensEarned() - allClientData[4].getUninvestedTokens(), - - allClientData[0].getTotalTokensEarned(), - allClientData[1].getTotalTokensEarned(), - allClientData[2].getTotalTokensEarned(), - allClientData[3].getTotalTokensEarned(), - 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(), - 10 - event.getClientData().getContributedTokens(),10 - otherClientData.getContributedTokens(), - event.getClientData().getAward()-(10 - event.getClientData().getContributedTokens()), - otherClientData.getAward()-(10 - otherClientData.getContributedTokens()), - event.getClientData().getAward(),otherClientData.getAward(), - (float)event.getClientData().getRoundConfiguration().getDollarsPerToken()*event.getClientData().getAward(), - (float)otherClientData.getRoundConfiguration().getDollarsPerToken()*otherClientData.getAward()*/ - )); - instructionsBuilder.append("</tbody></table><hr>"); - instructionsBuilder.append(String.format("Summary: You received $1.00 at the beginning of the round and had " + - "$%3.2f at the end of the round. Your earnings in the experiments so far are $%3.2f plus the $5.00 " + - "showup fee, for a grand total of $%3.2f", - (float)dollarsPerToken*clientData.getTotalTokensEarned(), - (float)dollarsPerToken*clientData.getTotalTokens(), - (float)dollarsPerToken*clientData.getTotalTokens() + getServerConfiguration().getShowUpPayment() - )); + instructionsBuilder.append("</tbody></table><hr/>"); + instructionsBuilder.append(String.format("<h3>You received $%3.2f this past round. Your total earnings are $%3.2f, including the $%3.2f show up bonus.</h3>", + clientData.getTotalDollarsEarnedThisRound(), clientData.getTotalDollarsEarned()+showUpBonus, showUpBonus)); + // FIXME: wow. change this. +// instructionsBuilder.append(String.format( +// positionString + +// +// allClientData[0].getInvestedTokens(), +// allClientData[1].getInvestedTokens(), +// allClientData[2].getInvestedTokens(), +// allClientData[3].getInvestedTokens(), +// allClientData[4].getInvestedTokens(), +// +// allClientData[0].getUninvestedTokens(), +// allClientData[1].getUninvestedTokens(), +// allClientData[2].getUninvestedTokens(), +// allClientData[3].getUninvestedTokens(), +// allClientData[4].getUninvestedTokens(), +// +// allClientData[0].getTotalTokensEarned() - allClientData[0].getUninvestedTokens(), +// allClientData[1].getTotalTokensEarned() - allClientData[1].getUninvestedTokens(), +// allClientData[2].getTotalTokensEarned() - allClientData[2].getUninvestedTokens(), +// allClientData[3].getTotalTokensEarned() - allClientData[3].getUninvestedTokens(), +// allClientData[4].getTotalTokensEarned() - allClientData[4].getUninvestedTokens(), +// +// allClientData[0].getTotalTokensEarned(), +// allClientData[1].getTotalTokensEarned(), +// allClientData[2].getTotalTokensEarned(), +// allClientData[3].getTotalTokensEarned(), +// 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(), +// 10 - event.getClientData().getContributedTokens(),10 - otherClientData.getContributedTokens(), +// event.getClientData().getAward()-(10 - event.getClientData().getContributedTokens()), +// otherClientData.getAward()-(10 - otherClientData.getContributedTokens()), +// event.getClientData().getAward(),otherClientData.getAward(), +// (float)event.getClientData().getRoundConfiguration().getDollarsPerToken()*event.getClientData().getAward(), +// (float)otherClientData.getRoundConfiguration().getDollarsPerToken()*otherClientData.getAward()*/ +// )); +// instructionsBuilder.append("</tbody></table><hr>"); +// instructionsBuilder.append(String.format("Summary: You received $1.00 at the beginning of the round and had " + +// "$%3.2f at the end of the round. Your earnings in the experiments so far are $%3.2f plus the $5.00 " + +// "showup fee, for a grand total of $%3.2f", +// (float)dollarsPerToken*clientData.getAllTokensEarnedThisRound(), +// (float)dollarsPerToken*clientData.getTotalTokens(), +// (float)dollarsPerToken*clientData.getTotalTokens() + getServerConfiguration().getShowUpPayment() +// )); //append the added practice round instructions if(clientDataModel.getRoundConfiguration().isPracticeRound()) { instructionsBuilder.append(" However, this is a practice round and the earnings mentioned are only for illustrative purposes " + 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-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-21 07:35:00 UTC (rev 313) @@ -181,6 +181,7 @@ }); channel.add(this, new EventTypeProcessor<EndRoundEvent>(EndRoundEvent.class) { public void handle(EndRoundEvent event) { + clientDataModel.setGroupDataModel(event.getClientData().getGroupDataModel()); experimentGameWindow.endRound(event); } }); 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-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-21 07:35:00 UTC (rev 313) @@ -177,12 +177,17 @@ private JTextField getWaterUsedTextField() { if (waterUsedTextField == null) { - waterUsedTextField = new JTextField(); - waterUsedTextField.setEditable(false); - waterUsedTextField.setBackground(Color.GRAY); + waterUsedTextField = createTextField(); } return waterUsedTextField; } + + private JTextField createTextField() { + JTextField textField = new JTextField(); + textField.setEditable(false); + textField.setBackground(Color.LIGHT_GRAY); + return textField; + } private JLabel getWaterUsedLabel() { if (waterUsedLabel == null) { @@ -193,8 +198,7 @@ private JTextField getTokensNotInvestedTextField() { if (tokensNotInvestedTextField == null) { - tokensNotInvestedTextField = new JTextField(); - tokensNotInvestedTextField.setEditable(false); + tokensNotInvestedTextField = createTextField(); } return tokensNotInvestedTextField; } @@ -207,8 +211,7 @@ private JTextField getTokensEarnedTextField() { if (tokensEarnedTextField == null) { - tokensEarnedTextField = new JTextField(); - tokensEarnedTextField.setEditable(false); + tokensEarnedTextField = createTextField(); } return tokensEarnedTextField; } @@ -221,8 +224,7 @@ private JTextField getTotalTokensEarnedTextField() { if (totalTokensEarnedTextField == null) { - totalTokensEarnedTextField = new JTextField(); - totalTokensEarnedTextField.setEditable(false); + totalTokensEarnedTextField = createTextField(); } return totalTokensEarnedTextField; @@ -404,8 +406,8 @@ ClientData clientData = clientDataModel.getClientData(); waterUsedTextField.setText("" + clientData.getWaterUsed()); tokensNotInvestedTextField.setText("" + clientData.getUninvestedTokens()); - tokensEarnedTextField.setText("" + clientData.waterToTokenFunction()); - totalTokensEarnedTextField.setText("" + clientData.getTotalTokensEarned()); + tokensEarnedTextField.setText("" + clientData.getTokensEarnedFromWaterCollected()); + totalTokensEarnedTextField.setText("" + clientData.getAllTokensEarnedThisRound()); getScoreBoxPanel().update(clientDataModel); // getMiddleWindowPanel().update(clientDataModel); @@ -434,22 +436,24 @@ public void endRound() { Runnable createGuiRunnable = new Runnable(){ public void run() { + gateSwitchButton.setText("Open gate"); if (canalPanel != null) { System.err.println("Removing canal panel"); upperPanel.remove(canalPanel); + canalPanel.endRound(); } System.err.println("ending round for canal panel"); - canalPanel.endRound(); + canalPanel = null; } }; open = false; - gateSwitchButton.setText("Open gate"); - try { SwingUtilities.invokeAndWait(createGuiRunnable); - } catch (InterruptedException e) { + } + catch (InterruptedException e) { e.printStackTrace(); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) { e.printStackTrace(); } Modified: 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-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGameWindow.java 2009-10-21 07:35:00 UTC (rev 313) @@ -544,7 +544,7 @@ if (moneyEarnedTextField == null) { moneyEarnedTextField = new JTextField(); moneyEarnedTextField.setText(new Integer(mainIrrigationWindow - .getClientDataModel().getClientData().getTotalTokensEarned()) + .getClientDataModel().getClientData().getAllTokensEarnedThisRound()) .toString()); moneyEarnedTextField.setBounds(new Rectangle(161, 17, 86, 21)); moneyEarnedTextField.setFont(new Font("Dialog", Font.PLAIN, 14)); 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-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-21 07:35:00 UTC (rev 313) @@ -72,7 +72,7 @@ private JLabel getPositionText() { if (positionText == null){ - positionText = new JLabel(clientData.getPriorityAsString()); + positionText = new JLabel(clientData.getPriorityString()); positionText.setBounds(new Rectangle(5,50+32+10,30,20)); } return positionText; @@ -91,7 +91,7 @@ this.clientData = clientData; currentBandwidthText.setText("" + clientData.getAvailableFlowCapacity()); waterUsedTextField.setText("" + clientData.getWaterUsed()); - totalTokensEarnedTextField.setText("" + clientData.getTotalTokensEarned()); + totalTokensEarnedTextField.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/ScoreBoxPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ScoreBoxPanel.java 2009-10-21 07:35:00 UTC (rev 313) @@ -43,7 +43,7 @@ add(new JLabel("Position:")); List<ClientData> clientDataList = clientDataModel.getClientDataSortedByPriority(); for (ClientData clientData : clientDataList) { - add(new JLabel(clientData.getPriorityAsString())); + add(new JLabel(clientData.getPriorityString())); } // available water per second add(new JLabel("Available water per second:")); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java 2009-10-21 07:35:00 UTC (rev 313) @@ -55,7 +55,7 @@ labelBuilder.append("You"); } else { - labelBuilder.append(currentClientData.getPriorityAsString()); + labelBuilder.append(currentClientData.getPriorityString()); } labelBuilder.append(" invested ").append(currentClientData.getInvestedTokens()).append(" token(s)"); defaultPieDataset.setValue(labelBuilder.toString(), currentClientData.getInvestedTokens()); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-21 07:35:00 UTC (rev 313) @@ -47,8 +47,8 @@ return getIntProperty("max-canal-flow-capacity", 40); } - public int getMaximumInvestedTokens() { - return getIntProperty("max-invested-tokens", 10); + public int getMaximumTokenInvestment() { + return getIntProperty("max-token-investment", 10); } /** @@ -56,7 +56,7 @@ * @return */ public int getMaximumTotalInvestedTokens() { - return getMaximumInvestedTokens() * getClientsPerGroup(); + return getMaximumTokenInvestment() * getClientsPerGroup(); } public int getMaximumInfrastructureEfficiency() { @@ -79,6 +79,8 @@ /** * Returns the dollars/token exchange rate. $1 = 1, 50 cents = $.50, 1 penny per token = .01, etc. * + * FIXME: this should be a ServerConfiguration parameter unless we change it so + * the client keeps track of total dollars earned per round instead of total tokens earned per round. * * @return */ Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-21 07:35:00 UTC (rev 313) @@ -186,8 +186,8 @@ "<td align='center'>$%3.2f</td>" + "<td align='center'>$%3.2f</td></tr>", clientId.toString(), - data.getTotalTokensEarned(), - data.getTotalTokensEarned() * model.getRoundConfiguration().getDollarsPerToken(), + data.getAllTokensEarnedThisRound(), + data.getAllTokensEarnedThisRound() * model.getRoundConfiguration().getDollarsPerToken(), data.getTotalTokens() * model.getRoundConfiguration().getDollarsPerToken()+ facilitator.getConfiguration().getShowUpPayment())); } builder.append("</tbody></table><hr>"); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-10-21 07:35:00 UTC (rev 313) @@ -27,7 +27,7 @@ private GroupDataModel groupDataModel; - private int waterUsed = 0; + private int waterCollected = 0; private int availableFlowCapacity; @@ -76,7 +76,7 @@ private final static String[] PRIORITY_STRINGS = { "A", "B", "C", "D", "E" }; - public String getPriorityAsString() { + public String getPriorityString() { // bounds check int priority = getPriority(); if (priority >= 0 && priority < PRIORITY_STRINGS.length) { @@ -125,7 +125,7 @@ } public int getUninvestedTokens() { - return roundConfiguration.getMaximumInvestedTokens() - investedTokens; + return roundConfiguration.getMaximumTokenInvestment() - investedTokens; } public GroupDataModel getGroupDataModel() { @@ -149,7 +149,7 @@ closeGate(); investedTokens = 0; //adding number of files to be downloaded = 0 per round - waterUsed = 0; + waterCollected = 0; } public void resetAllTokens() { @@ -182,17 +182,21 @@ setAvailableFlowCapacity(availableFlowCapacity); } - public void award() { - totalTokens += getTotalTokensEarned(); + public void addTokensEarnedThisRoundToTotal() { + totalTokens += getAllTokensEarnedThisRound(); } /** * Returns the current number of tokens given to this participant. * @return */ - public int getTotalTokensEarned(){ - return waterToTokenFunction() + getUninvestedTokens(); + public int getAllTokensEarnedThisRound(){ + return getTokensEarnedFromWaterCollected() + getUninvestedTokens(); } + + public double getTotalDollarsEarnedThisRound() { + return roundConfiguration.getDollarsPerToken() * getAllTokensEarnedThisRound(); + } /** * Reward function table correlating water usage to tokens earned. @@ -200,47 +204,47 @@ * @param value * @return */ - public int waterToTokenFunction() { - if (waterUsed < 150) { + public int getTokensEarnedFromWaterCollected() { + if (waterCollected < 150) { return 0; } - else if (waterUsed < 200) { + else if (waterCollected < 200) { return 1; } - else if (waterUsed < 250) { + else if (waterCollected < 250) { return 4; } - else if (waterUsed < 300) { + else if (waterCollected < 300) { return 10; } - else if (waterUsed < 350) { + else if (waterCollected < 350) { return 15; } - else if (waterUsed < 400) { + else if (waterCollected < 400) { return 18; } - else if (waterUsed < 500) { + else if (waterCollected < 500) { return 19; } - else if (waterUsed < 550) { + else if (waterCollected < 550) { return 20; } - else if (waterUsed < 650) { + else if (waterCollected < 650) { return 19; } - else if (waterUsed < 700) { + else if (waterCollected < 700) { return 18; } - else if (waterUsed < 750) { + else if (waterCollected < 750) { return 15; } - else if (waterUsed < 800) { + else if (waterCollected < 800) { return 10; } - else if (waterUsed < 850) { + else if (waterCollected < 850) { return 4; } - else if (waterUsed < 900) { + else if (waterCollected < 900) { return 1; } else { @@ -249,13 +253,21 @@ } public void collectWater() { - waterUsed += availableFlowCapacity; + waterCollected += availableFlowCapacity; } public int getWaterUsed(){ - return waterUsed; + return waterCollected; } + public int getMaximumTokenInvestment() { + return getRoundConfiguration().getMaximumTokenInvestment(); + } + + public double getTotalDollarsEarned() { + return roundConfiguration.getDollarsPerToken() * totalTokens; + } + } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-21 07:35:00 UTC (rev 313) @@ -63,7 +63,7 @@ throw new IllegalArgumentException( "no client state available for: " + id); } - return state.getTotalTokensEarned(); + return state.getAllTokensEarnedThisRound(); } public void addClient(ClientData clientData) { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-21 05:59:23 UTC (rev 312) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-21 07:35:00 UTC (rev 313) @@ -401,7 +401,7 @@ //Send the end round event to all the clients synchronized (clients) { for (ClientData data : clients.values()) { - data.award(); + data.addTokensEarnedThisRoundToTotal(); transmit(new EndRoundEvent(data.getId(), data.getGroupDataModel(), getConfiguration().isLastRound())); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <al...@us...> - 2009-10-22 07:00:45
|
Revision: 317 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=317&view=rev Author: alllee Date: 2009-10-22 07:00:32 +0000 (Thu, 22 Oct 2009) Log Message: ----------- client interface is pretty much finalized, next up is testing round configurations and server interaction / persistence. Modified Paths: -------------- 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/MainIrrigationGameWindow.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/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.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-10-22 06:25:19 UTC (rev 316) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-22 07:00:32 UTC (rev 317) @@ -555,7 +555,7 @@ graphPanel.setName("Graph panel"); graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS)); graphPanel.add(getPieChartPanel()); - graphPanel.add(Box.createVerticalStrut(10)); + graphPanel.add(Box.createVerticalStrut(15)); contributionInformationTextArea = new JTextArea(); contributionInformationTextArea.setEditable(false); 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 06:25:19 UTC (rev 316) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-22 07:00:32 UTC (rev 317) @@ -109,7 +109,7 @@ IrrigationClient client = new IrrigationClient(); client.initialize(); frame.setTitle("Virtual Commons Experiment Client: " + client.id); - frame.setPreferredSize(new Dimension(1024, 768)); + frame.setPreferredSize(new Dimension(1100, 800)); // frame.setResizable(false); frame.getContentPane().add(client.getExperimentGameWindow()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 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 06:25:19 UTC (rev 316) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-22 07:00:32 UTC (rev 317) @@ -231,15 +231,17 @@ } 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 JButton getGateSwitchButton() { if (gateSwitchButton == null) { - gateSwitchButton = new JButton("Open gate"); + 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" : "Open gate"); + gateSwitchButton.setText( open ? CLOSE_GATE_LABEL : OPEN_GATE_LABEL ); if (open) { client.openGate(); } @@ -499,7 +501,7 @@ // controlPanel.endRound(); centerPanel.removeAll(); canalPanel.endRound(); - gateSwitchButton.setText("Open gate"); + gateSwitchButton.setText(OPEN_GATE_LABEL); } }); 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 06:25:19 UTC (rev 316) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-10-22 07:00:32 UTC (rev 317) @@ -23,11 +23,14 @@ private JLabel positionText; - private JLabel availableFlowCapacityLabel; + private JLabel availableWaterLabel; private JLabel waterCollectedLabel; - private JLabel tokensCollectedLabel; + private JLabel tokensEarnedLabel; + + private JLabel tokensNotInvestedLabel; + private JLabel totalTokensEarnedLabel; private int priority; @@ -46,34 +49,48 @@ this.setPreferredSize(new Dimension(60,200)); this.add(getPositionLabel(),null); this.add(getWaterCollectedLabel(),null); - this.add(getAvailableFlowCapacityLabel(),null); - this.add(getTokensCollectedLabel(),null); - - + this.add(getAvailableWaterLabel(),null); + this.add(getTokensEarnedLabel(),null); +// this.add(getTokensNotInvestedLabel(),null); +// this.add(getTotalTokensEarnedLabel(),null); } + + private JLabel getTotalTokensEarnedLabel() { + if (totalTokensEarnedLabel == null) { + totalTokensEarnedLabel = new JLabel(); + totalTokensEarnedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10+20+10+30+30,30,20)); + } + return totalTokensEarnedLabel; + } + + private JLabel getTokensNotInvestedLabel() { + if (tokensNotInvestedLabel == null) { + tokensNotInvestedLabel = new JLabel(String.valueOf(clientData.getUninvestedTokens())); + tokensNotInvestedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10+20+10+30,30,20)); + } + return tokensNotInvestedLabel; + } - 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(""); + private JLabel getTokensEarnedLabel() { + if(tokensEarnedLabel == null){ + tokensEarnedLabel = new JLabel(); + tokensEarnedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10+20+10,30,20)); } - return tokensCollectedLabel; + return tokensEarnedLabel; } - private JLabel getAvailableFlowCapacityLabel() { - if(availableFlowCapacityLabel == null){ - availableFlowCapacityLabel = new JLabel(); - availableFlowCapacityLabel.setBounds(new Rectangle(5,50+32+10+20+10,30,20)); - availableFlowCapacityLabel.setText(""); + private JLabel getAvailableWaterLabel() { + if(availableWaterLabel == null){ + availableWaterLabel = new JLabel(); + availableWaterLabel.setBounds(new Rectangle(5,10+32+10+20+10,30,20)); } - return availableFlowCapacityLabel; + return availableWaterLabel; } private JLabel getPositionLabel() { if (positionText == null){ positionText = new JLabel(clientData.getPriorityString()); - positionText.setBounds(new Rectangle(5,50+32+10,30,20)); + positionText.setBounds(new Rectangle(5,10+32+10,30,20)); } return positionText; } @@ -82,16 +99,16 @@ private JLabel getWaterCollectedLabel() { if(waterCollectedLabel == null){ waterCollectedLabel = new JLabel("0"); - waterCollectedLabel.setBounds(new Rectangle(5,50+32+10+20+10+20+10,30,20)); + waterCollectedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10,30,20)); } return waterCollectedLabel; } public void update(ClientData clientData) { this.clientData = clientData; - availableFlowCapacityLabel.setText("" + clientData.getAvailableFlowCapacity()); + availableWaterLabel.setText("" + clientData.getAvailableFlowCapacity()); waterCollectedLabel.setText("" + clientData.getWaterCollected()); - tokensCollectedLabel.setText("" + clientData.getAllTokensEarnedThisRound()); + tokensEarnedLabel.setText("" + clientData.getTokensEarnedFromWaterCollected()); 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 06:25:19 UTC (rev 316) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java 2009-10-22 07:00:32 UTC (rev 317) @@ -36,21 +36,21 @@ this.setBounds(new Rectangle(13,100 + 100 - 50,1093,100+50+50)); this.setSize(new Dimension(1093,200)); - positionLabel = new JLabel(); - positionLabel.setBounds(new Rectangle(30,50+32+10,150,20)); + positionLabel = new JLabel("Position"); + positionLabel.setBounds(new Rectangle(30,10+32+10,200,20)); positionLabel.setText("Position"); - availableWaterLabel = new JLabel(); - availableWaterLabel.setBounds(new Rectangle(30,50+32+10+20+10,200,20)); - availableWaterLabel.setText("Available water per second"); + availableWaterLabel = new JLabel("Available water per second"); + availableWaterLabel.setBounds(new Rectangle(30,10+32+10+20+10,200,20)); - waterCollectedLabel = new JLabel(); - waterCollectedLabel.setBounds(new Rectangle(30,50+32+10+20+10+20+10, 150,20)); - waterCollectedLabel.setText("Water collected"); + waterCollectedLabel = new JLabel("Water collected"); + waterCollectedLabel.setBounds(new Rectangle(30,10+32+10+20+10+20+10, 150,20)); - tokensEarnedLabel = new JLabel(); - tokensEarnedLabel.setBounds(new Rectangle(30,50+32+10+20+10+20+10+20+10, 200,20)); - tokensEarnedLabel.setText("Tokens earned "); + tokensEarnedLabel = new JLabel("Tokens earned"); + tokensEarnedLabel.setBounds(new Rectangle(30,10+32+10+20+10+20+10+20+10, 200,20)); + + totalTokensEarnedLabel = new JLabel("Total tokens earned"); + totalTokensEarnedLabel.setBounds(new Rectangle(30,10+32+10+20+10+20+10+20+10+30, 200,20)); this.add(positionLabel, null); this.add(availableWaterLabel, null); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-22 06:25:19 UTC (rev 316) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-22 07:00:32 UTC (rev 317) @@ -99,6 +99,10 @@ public void report() { getProperties().list(System.err); } + + public boolean shouldResetInfrastructureEfficiency() { + return getBooleanProperty("reset-infrastructure-efficiency", false); + } public String getInstructions() { return getStringProperty("instructions", Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-22 06:25:19 UTC (rev 316) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-22 07:00:32 UTC (rev 317) @@ -128,7 +128,7 @@ // initialize infrastructure efficiency System.err.println("current round number: " + currentRoundNumber); System.err.println("initial infrastructure efficiency: " + infrastructureEfficiency); - if (roundConfiguration.isPracticeRound() || roundConfiguration.isFirstRound()) { + if ( roundConfiguration.shouldResetInfrastructureEfficiency() ) { System.err.println("initializing infrastructure efficiency to default initial value: " + roundConfiguration.getInitialInfrastructureEfficiency()); infrastructureEfficiency = roundConfiguration.getInitialInfrastructureEfficiency(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-23 18:18:44
|
Revision: 330 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=330&view=rev Author: alllee Date: 2009-10-23 18:18:35 +0000 (Fri, 23 Oct 2009) Log Message: ----------- adding water supply capacity instructions to label Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.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-10-23 16:44:30 UTC (rev 329) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-23 18:18:35 UTC (rev 330) @@ -578,9 +578,11 @@ addCenterComponent(getInvestTokensPanel()); 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>", + String.format( + "<h2>The current infrastructure efficiency is %d%%. The irrigation capacity is %d cubic feet per second and the water supply is %d cubic feet per second.</h2>", infrastructureEfficiency, - group.calculateFlowCapacity(infrastructureEfficiency) + group.calculateFlowCapacity(infrastructureEfficiency), + roundConfiguration.getWaterSupplyCapacity() )); builder.append(getServerConfiguration().getInvestmentInstructions()); tokenInstructionsEditorPane.setText(builder.toString()); @@ -607,11 +609,11 @@ else { instructionsBuilder.append( String.format("<p>The current infrastructure efficiency is %d%% but will be degraded by %d%% during this round." + - "The current irrigation capacity is %d cfps with a maximum canal capacity is %d cfps.</p><hr/>", + "The current irrigation capacity is %d cfps and the available water supply is %d cfps.</p><hr/>", clientDataModel.getGroupDataModel().getInfrastructureEfficiency(), roundConfiguration.getInfrastructureDegradationFactor(), irrigationCapacity, - roundConfiguration.getMaximumCanalFlowCapacity() + roundConfiguration.getWaterSupplyCapacity() )); } setInstructions(instructionsBuilder.toString()); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-23 16:44:30 UTC (rev 329) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-10-23 18:18:35 UTC (rev 330) @@ -43,7 +43,7 @@ return getIntProperty("infrastructure-degradation-factor", 25); } - public int getMaximumCanalFlowCapacity() { + public int getWaterSupplyCapacity() { return getIntProperty("max-canal-flow-capacity", 30); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-23 16:44:30 UTC (rev 329) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-23 18:18:35 UTC (rev 330) @@ -156,11 +156,11 @@ } public int getInitialFlowCapacity() { - return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getMaximumCanalFlowCapacity()); + return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); } public int getFlowCapacity() { - return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getMaximumCanalFlowCapacity()); + return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); } public void resetCurrentlyAvailableFlowCapacity() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-24 21:34:20
|
Revision: 333 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=333&view=rev Author: alllee Date: 2009-10-24 21:34:10 +0000 (Sat, 24 Oct 2009) Log Message: ----------- changing == to >= for token submission round notification Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-24 21:19:51 UTC (rev 332) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-24 21:34:10 UTC (rev 333) @@ -138,7 +138,7 @@ SwingUtilities.invokeLater(createGuiRunnable); } - void sendBeginExperimentRequest(){ + void sendStartRoundOverride(){ transmit(new BeginExperimentRequest(id)); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-24 21:19:51 UTC (rev 332) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-24 21:34:10 UTC (rev 333) @@ -72,7 +72,7 @@ buttonPanel.add(getBeginChatButton()); buttonPanel.add(getDisplayInvestmentButton()); buttonPanel.add(getStartRoundButton()); - buttonPanel.add(getBeginExperimentButton()); + buttonPanel.add(getStartRoundOverrideButton()); add(buttonPanel, BorderLayout.NORTH); editorPane = new HtmlEditorPane(); editorPane.setEditable(false); @@ -116,14 +116,13 @@ return beginChatButton; } - private JButton getBeginExperimentButton() { + private JButton getStartRoundOverrideButton() { if (beginExperimentButton == null) { - beginExperimentButton = new JButton("Begin experiment"); + beginExperimentButton = new JButton("Override"); beginExperimentButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { - facilitator.sendBeginExperimentRequest(); + facilitator.sendStartRoundOverride(); } - }); } return beginExperimentButton; Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-24 21:19:51 UTC (rev 332) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-24 21:34:10 UTC (rev 333) @@ -108,6 +108,7 @@ addEventProcessor(new EventTypeProcessor<BeginExperimentRequest>(BeginExperimentRequest.class) { @Override public void handle(BeginExperimentRequest event) { + // sends override and immediately starts the round. synchronized (roundSignal) { roundSignal.notifyAll(); } @@ -122,14 +123,9 @@ return; } // ignore the request if not every group has submit their tokens. - if (submittedClients == clients.size()) { - synchronized (roundSignal) { - roundSignal.notifyAll(); - } - } - else { - System.err.println("clients still haven't submitted their tokens: " + submittedClients + " - # clients: " + clients.size()); - } + synchronized (roundSignal) { + roundSignal.notifyAll(); + } } }); addEventProcessor(new EventTypeProcessor<EndRoundRequest>(EndRoundRequest.class) { @@ -234,7 +230,7 @@ ClientData clientData = clients.get(event.getId()); clientData.setInvestedTokens(event.getInvestedTokens()); submittedClients++; - if (submittedClients == clients.size()) { + if (submittedClients >= clients.size()) { // everyone's submitted their tokens so we can calculate the available bandwidth and // notify each client initializeInfrastructureEfficiency(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-27 02:20:14
|
Revision: 335 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=335&view=rev Author: alllee Date: 2009-10-27 02:20:01 +0000 (Tue, 27 Oct 2009) Log Message: ----------- refactoring code in an attempt to clearly disambiguate between the irrigation capacity (theoretical maximum) and water supply (actual amount of water available to flow through the irrigation canal). Fixed bug where chat logs were not being persisted properly. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 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/InfrastructureEfficiencyChartPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -68,7 +68,7 @@ if (timer != null) { timer.stop(); } - this.maximumIrrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + this.maximumIrrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableWaterFlow(); this.clientDataModel = clientDataModel; initialize(); } 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-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -117,5 +117,13 @@ return clientDataList; } + public int getWaterSupplyCapacity() { + return roundConfiguration.getWaterSupplyCapacity(); + } + public int getIrrigationCapacity() { + return groupDataModel.getIrrigationCapacity(); + } + + } 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-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-27 02:20:01 UTC (rev 335) @@ -507,20 +507,21 @@ int totalContributedTokens = groupDataModel.getTotalContributedTokens(); final StringBuilder builder = new StringBuilder(); builder.append("Infrastructure efficiency before investment: ") - .append(groupDataModel.getInitialInfrastructureEfficiency()) + .append(groupDataModel.getInfrastructureEfficiencyBeforeInvestment()) .append("%\n"); - builder.append("Irrigation capacity before investment: ").append(groupDataModel.getInitialFlowCapacity()).append(" cubic feet per second\n\n"); + builder.append("Irrigation capacity before investment: ").append(groupDataModel.getIrrigationCapacityBeforeInvestment()).append(" cubic feet per second\n\n"); builder.append( String.format( "Your group invested a total of %d tokens, increasing the infrastructure efficiency to %d%%.\n", totalContributedTokens, groupDataModel.getInfrastructureEfficiency())); - if (groupDataModel.getFlowCapacity() > groupDataModel.getInitialFlowCapacity()) { + if (groupDataModel.getIrrigationCapacity() > groupDataModel.getIrrigationCapacityBeforeInvestment()) { builder.append("Your group's investment has increased the irrigation capacity to "); } else { builder.append("Your group's investment was not enough to increase the irrigation capacity. Your group's irrigation capacity is still "); } - builder.append(groupDataModel.getFlowCapacity()).append(" cubic feet of water per second."); + builder.append(groupDataModel.getIrrigationCapacity()).append(" cubic feet of water per second. The amount of water available to pass through your irrigation canal is ") + .append(groupDataModel.getActualFlowCapacity()); SwingUtilities.invokeLater(new Runnable() { public void run() { contributionInformationTextArea.setText(builder.toString()); @@ -601,7 +602,7 @@ else { instructionsBuilder.append(roundConfiguration.getInstructions()); instructionsBuilder.append("<hr/>"); - int irrigationCapacity = clientDataModel.getGroupDataModel().getFlowCapacity(); + int irrigationCapacity = clientDataModel.getGroupDataModel().getIrrigationCapacity(); int clientCapacity = roundConfiguration.getMaximumClientFlowCapacity(); if (roundConfiguration.shouldResetInfrastructureEfficiency()) { instructionsBuilder.append("The irrigation infrastructure efficiency is currently 75%."); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -54,7 +54,7 @@ int x,y; GroupDataModel group = client.getClientDataModel().getGroupDataModel(); final int infrastructureEfficiency = group.getInfrastructureEfficiency(); - final int actualFlowCapacity = group.getFlowCapacity(); + final int actualFlowCapacity = group.getIrrigationCapacity(); for (y = 0; y <= actualFlowCapacity; y++) { actualFlowCapacitySeries.add(infrastructureEfficiency, y); } @@ -62,10 +62,10 @@ y = group.calculateFlowCapacity(x); potentialFlowCapacitySeries.add(x,y); } - final int initialInfrastructureEfficiency = group.getInitialInfrastructureEfficiency(); - final int initialFlowCapacity = group.calculateFlowCapacity(initialInfrastructureEfficiency); - for (y = 0; y <= initialFlowCapacity; y++) { - initialInfrastructureEfficiencySeries.add(initialInfrastructureEfficiency, y); + final int infrastructureEfficiencyBeforeInvestment = group.getInfrastructureEfficiencyBeforeInvestment(); + final int irrigationCapacityBeforeInvestment = group.getIrrigationCapacityBeforeInvestment(); + for (y = 0; y <= irrigationCapacityBeforeInvestment; y++) { + initialInfrastructureEfficiencySeries.add(infrastructureEfficiencyBeforeInvestment, y); } final XYSeriesCollection data = new XYSeriesCollection(); 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-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -443,7 +443,7 @@ // getWaterCollectedToTokensTable().setText(clientDataModel.getServerConfiguration().getWaterCollectedToTokensTable()); // getScoreBoxPanel().initialize(clientDataModel); getMiddleWindowPanel().initialize(clientDataModel); - int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableWaterFlow(); irrigationCapacityLabel.setText( String.format("Irrigation capacity: %d cubic feet per second (cfps)", irrigationCapacity)); 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-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-10-27 02:20:01 UTC (rev 335) @@ -8,6 +8,7 @@ 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; @@ -22,21 +23,22 @@ import edu.asu.commons.irrigation.server.ClientData; import edu.asu.commons.util.HtmlEditorPane; - - - +/** + * $Id$ + * + * Primary game interface window for the irrigation game. + * + * @author <a href='mailto:All...@as...'>Allen Lee</a>, Sanket Joshi + * @version $Rev$ + */ public class MainIrrigationGameWindow extends JPanel { - //public ChartWindowPanelTokenBandwidth xySeriesDemo; + private static final long serialVersionUID = 5900368694556557132L; - public IrrigationGameWindow controlPanel; + public IrrigationGameWindow controlPanel; - //public ActivitySummaryPanel activitySummaryWindow; + private CanalPanel canalPanel; - public CanalPanel canalPanel; - - private static final long serialVersionUID = 1L; - private JPanel jPanelMain = null; //this contains the CanalPanel private JPanel centerPanel = null; @@ -88,8 +90,10 @@ private JLabel totalTokensEarnedLabel; private JLabel irrigationCapacityLabel; + private JLabel waterSupplyLabel; private JTextField irrigationCapacityTextField; + private JTextField waterSupplyTextField; private HtmlEditorPane waterCollectedToTokensTable; @@ -135,7 +139,11 @@ jPanelMain.setLayout(new BorderLayout(4,4)); jPanelMain.setBackground(Color.WHITE); jPanelMain.setForeground(Color.BLACK); - jPanelMain.add(getIrrigationCapacityLabel(), BorderLayout.NORTH); + JPanel upperPanel = new JPanel(); + upperPanel.setLayout(new BoxLayout(upperPanel, BoxLayout.X_AXIS)); + upperPanel.add(getIrrigationCapacityLabel()); + upperPanel.add(getWaterSupplyLabel()); + jPanelMain.add(upperPanel, BorderLayout.NORTH); jPanelMain.add(getDownloadScreenPanel(), BorderLayout.CENTER); return jPanelMain; } @@ -345,7 +353,7 @@ } return totalTokensEarnedLabel; } - + private JLabel getIrrigationCapacityLabel() { if (irrigationCapacityLabel == null) { irrigationCapacityLabel = new JLabel(); @@ -361,6 +369,21 @@ } return irrigationCapacityTextField; } + + private JLabel getWaterSupplyLabel() { + if (waterSupplyLabel == null) { + waterSupplyLabel = new JLabel("Water supply: "); + waterSupplyLabel.setLabelFor(getWaterSupplyTextField()); + waterSupplyLabel.setFont(new Font("sansserif", Font.BOLD, 16)); + } + return waterSupplyLabel; + } + private JTextField getWaterSupplyTextField() { + if (waterSupplyTextField == null) { + waterSupplyTextField = createTextField(); + } + return waterSupplyTextField; + } /** * This method initializes jPanel3 * summary scoreboard @@ -388,16 +411,6 @@ return waterCollectedToTokensScrollPane; } - private void setProgressBarColor(int timeLeft) { - if (timeLeft < 10) { -// timeLeftProgressBar.setForeground( Color.RED ); -// timeLeftProgressBar.setBackground( Color.RED ); -// return Color.RED; - } - else { -// timeLeftProgressBar.setBackground( Color.GREEN ); - } - } /** * Should be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. */ @@ -408,6 +421,7 @@ String timeLeftString = String.format("%d sec", timeLeft); timeLeftProgressBar.setValue( timeLeft ); timeLeftProgressBar.setString(timeLeftString); + // FIXME: figure out how to reliably set the progress bar colors regardless of OS. // setProgressBarColor(timeLeft); for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { if (clientData.isGateOpen()) { @@ -520,10 +534,14 @@ public void startRound() { open = false; getMiddleWindowPanel().initialize(clientDataModel); - int irrigationCapacity = clientDataModel.getGroupDataModel().getMaximumAvailableFlowCapacity(); + int irrigationCapacity = clientDataModel.getIrrigationCapacity(); + int waterSupply = clientDataModel.getWaterSupplyCapacity(); irrigationCapacityLabel.setText( String.format("Irrigation capacity: %d cubic feet per second (cfps)", irrigationCapacity)); + waterSupplyLabel.setText( + String.format("Water supply: %d cubic feet per second (cfps)", + waterSupply)); revalidate(); // mainIrrigationPanel.add(getJPanelUpStreamWindow(),null); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-10-27 02:20:01 UTC (rev 335) @@ -30,11 +30,11 @@ private transient Logger logger = Logger.getLogger(GroupDataModel.class.getName()); private int currentlyAvailableFlowCapacity = 0; - private int maximumAvailableFlowCapacity = 0; + private int maximumAvailableWaterFlow = 0; private int infrastructureEfficiency; // infrastructure efficiency before investment (but post decline) - private int initialInfrastructureEfficiency; + private int infrastructureEfficiencyBeforeInvestment; private int totalContributedTokens = 0; @@ -87,7 +87,7 @@ return totalContributedTokens; } - public void calculateTotalFlowCapacity() { + public void initializeInfrastructure() { // for practice round and first round, initialize to initial infrastructure efficiency //setting the total contributed Bandwidth = 0 , so that for every round, // fresh totalContributed tokens are calculated @@ -96,7 +96,7 @@ totalContributedTokens += clientData.getInvestedTokens(); } updateInfrastructureEfficiency(totalContributedTokens); - currentlyAvailableFlowCapacity = maximumAvailableFlowCapacity = getFlowCapacity(); + currentlyAvailableFlowCapacity = maximumAvailableWaterFlow = getActualFlowCapacity(); } private void updateInfrastructureEfficiency(int totalContributedTokens) { @@ -111,7 +111,7 @@ } // set original infrastructure efficiency before token contributions getLogger().info("initial infrastructure efficiency: " + infrastructureEfficiency); - initialInfrastructureEfficiency = infrastructureEfficiency; + infrastructureEfficiencyBeforeInvestment = infrastructureEfficiency; // add total invested tokens to infrastructure efficiency, clamp at // 100 infrastructureEfficiency = Math.min(100, totalContributedTokens + infrastructureEfficiency); @@ -155,19 +155,34 @@ return 40; } - public int getInitialFlowCapacity() { - return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); + public int getIrrigationCapacityBeforeInvestment() { +// return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); + return calculateFlowCapacity(infrastructureEfficiencyBeforeInvestment); } - public int getFlowCapacity() { - return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); + /** + * Returns the theoretical maximum amount of water that the infrastructure can handle. + * This is independent of the actual water supply. + */ + public int getIrrigationCapacity() { + return calculateFlowCapacity(infrastructureEfficiency); +// return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); } + + /** + * Returns the actual maximum amount of water that can pass through the canal, which is the minimum + * of the irrigation capacity and the water supply. + * @return + */ + public int getActualFlowCapacity() { + return Math.min(getIrrigationCapacity(), getRoundConfiguration().getWaterSupplyCapacity()); + } public void resetCurrentlyAvailableFlowCapacity() { - currentlyAvailableFlowCapacity = maximumAvailableFlowCapacity; + currentlyAvailableFlowCapacity = maximumAvailableWaterFlow; } - public void allocateFlowCapacity(ClientData clientData) { + public void allocateWater(ClientData clientData) { int maximumClientFlowCapacity = getRoundConfiguration().getMaximumClientFlowCapacity(); if (currentlyAvailableFlowCapacity >= maximumClientFlowCapacity) { currentlyAvailableFlowCapacity -= maximumClientFlowCapacity; @@ -180,17 +195,16 @@ clientData.collectWater(); } - - public int getMaximumAvailableFlowCapacity() { - return maximumAvailableFlowCapacity; + public int getMaximumAvailableWaterFlow() { + return maximumAvailableWaterFlow; } public int getInfrastructureEfficiency() { return infrastructureEfficiency; } - public int getInitialInfrastructureEfficiency() { - return initialInfrastructureEfficiency; + public int getInfrastructureEfficiencyBeforeInvestment() { + return infrastructureEfficiencyBeforeInvestment; } public Logger getLogger() { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-26 21:07:55 UTC (rev 334) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-27 02:20:01 UTC (rev 335) @@ -138,6 +138,7 @@ addEventProcessor(new EventTypeProcessor<BeginChatRoundRequest>(BeginChatRoundRequest.class) { @Override public void handle(BeginChatRoundRequest request) { + persister.clearChatData(); // pass it on to all the clients synchronized (clients) { for (Identifier id: clients.keySet()) { @@ -222,6 +223,7 @@ ChatEvent chatEvent = new ChatEvent(request.getTarget(), request.toString(), request.getSource()); transmit(chatEvent); } + persister.store(request); } }); addEventProcessor(new EventTypeProcessor<InvestedTokensEvent>(InvestedTokensEvent.class) { @@ -274,7 +276,7 @@ // post round cleanup ///////////////////////////////////////////////////////////////////////////////// for(GroupDataModel group : serverDataModel.getAllGroupDataModels()){ - group.calculateTotalFlowCapacity(); + group.initializeInfrastructure(); // iterate through all groups and send back their contribution status for (Identifier id : group.getClientDataMap().keySet()) { InfrastructureUpdateEvent infrastructureUpdateEvent = new InfrastructureUpdateEvent(id, group); @@ -309,7 +311,7 @@ // clientData.init(group.getCurrentlyAvailableFlowCapacity()); // } if (clientData.isGateOpen()) { - group.allocateFlowCapacity(clientData); + group.allocateWater(clientData); } else if (clientData.isGateClosed()) { clientData.init(group.getAvailableClientFlowCapacity()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-13 06:56:52
|
Revision: 361 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=361&view=rev Author: alllee Date: 2009-11-13 06:56:43 +0000 (Fri, 13 Nov 2009) Log Message: ----------- - adding JFreeChart to bottom right hand corner for dynamic display of tokens earned - shuffling participants in the first round when chat begins - extracted tokens earned function to static method in RoundConfiguration for the time being Modified Paths: -------------- 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/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 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-11-13 05:32:07 UTC (rev 360) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-11-13 06:56:43 UTC (rev 361) @@ -49,8 +49,6 @@ private IrrigationClient irrigationClient; - private Identifier clientId; - private JScrollPane messageScrollPane; private JTextPane messageWindow; @@ -61,13 +59,8 @@ private JTextField chatField; - - public ChatPanel() { - initGuiComponents(); - } - public ChatPanel(IrrigationClient irrigationClient) { - this(); + initGuiComponents(); setIrrigationClient(irrigationClient); } @@ -106,7 +99,7 @@ private void sendMessage() { String message = chatField.getText(); if (message != null && ! message.isEmpty() && targetIdentifier != null) { - displayMessage(String.format("%s -> %s", getChatHandle(getClientId()), getChatHandle(targetIdentifier)), + displayMessage(String.format("%s -> %s : ", getChatHandle(getClientId()), getChatHandle(targetIdentifier)), message); chatField.setText(""); irrigationClient.transmit(new ChatRequest(getClientId(), message, targetIdentifier)); @@ -129,20 +122,6 @@ private Map<Identifier, String> chatHandles = new HashMap<Identifier, String>(); - public static void main(String[] args) { - JFrame frame = new JFrame(); - ChatPanel chatPanel = new ChatPanel(); - Identifier selfId = new Identifier(){}; - chatPanel.clientId = selfId; - chatPanel.initialize(Arrays.asList(new Identifier[] { - new Identifier(){}, new Identifier(){}, - new Identifier(){}, selfId })); - frame.add(chatPanel); - frame.setSize(new Dimension(400, 400)); - frame.setVisible(true); - } - - private void addStylesToMessageWindow() { StyledDocument styledDocument = messageWindow.getStyledDocument(); // and why not have something like... StyleContext.getDefaultStyle() to @@ -152,10 +131,8 @@ // Style regularStyle = styledDocument.addStyle("regular", // defaultStyle); StyleConstants.setFontFamily(defaultStyle, "Helvetica"); - StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), - true); - StyleConstants.setItalic(styledDocument - .addStyle("italic", defaultStyle), true); + StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), true); + StyleConstants.setItalic(styledDocument.addStyle("italic", defaultStyle), true); } public void setTimeLeft(long timeLeft) { @@ -189,11 +166,10 @@ private void displayMessage(String chatHandle, String message) { // String chatHandle = getChatHandle(source); - StyledDocument document = messageWindow.getStyledDocument(); + final StyledDocument document = messageWindow.getStyledDocument(); try { - document.insertString(document.getLength(), chatHandle + " : ", - document.getStyle("bold")); - document.insertString(document.getLength(), message + "\n", null); + document.insertString(document.getLength(), chatHandle, document.getStyle("bold")); + document.insertString(document.getLength(), message + "\n", document.getStyle("italic")); messageWindow.setCaretPosition(document.getLength()); } catch (BadLocationException e) { @@ -215,10 +191,7 @@ } public Identifier getClientId() { - if (clientId == null) { - clientId = irrigationClient.getId(); - } - return clientId; + return irrigationClient.getId(); } public void setIrrigationClient(IrrigationClient client) { @@ -228,7 +201,7 @@ public void handle(final ChatEvent chatEvent) { SwingUtilities.invokeLater(new Runnable() { public void run() { - displayMessage(String.format("%s -> %s", getChatHandle(chatEvent.getSource()), getChatHandle(chatEvent.getTarget())), + displayMessage(String.format("%s -> %s : ", getChatHandle(chatEvent.getSource()), getChatHandle(chatEvent.getTarget())), chatEvent.toString()); } }); 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-13 05:32:07 UTC (rev 360) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-11-13 06:56:43 UTC (rev 361) @@ -463,10 +463,17 @@ builder.append(quizAnswers.get( "explanation" + number )).append("</p>"); } } + if (incorrectAnswers.isEmpty()) { + builder.append("<p>Congratulations, you got all of the questions correct.</p>"); + } + else { + builder.append(String.format("<p>You answered %d questions incorrectly. Please review the correct answers to make sure you understand.</p>", incorrectAnswers.size())); + } + builder.append("<p><b>Please click the 'Next' button at the bottom right of the screen to continue.</b></p>"); quizPageResponses.put(currentQuizPageNumber, builder.toString()); // no matter what we move on to the next question page // tell them what was right and what was wrong. - if (currentQuizPageNumber < numberOfQuestionPages) { + if (currentQuizPageNumber <= numberOfQuestionPages) { nextButton.setEnabled(true); } quizzesAnswered++; 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-13 05:32:07 UTC (rev 360) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-11-13 06:56:43 UTC (rev 361) @@ -11,7 +11,6 @@ import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.GroupLayout; -import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; @@ -22,6 +21,14 @@ import javax.swing.GroupLayout.Alignment; import javax.swing.GroupLayout.ParallelGroup; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.xy.XYSeries; +import org.jfree.data.xy.XYSeriesCollection; + +import edu.asu.commons.irrigation.conf.RoundConfiguration; import edu.asu.commons.irrigation.server.ClientData; /** * $Id$ @@ -355,9 +362,32 @@ } return jPanelDownStreamWindow; } + + private XYSeries currentWaterAppliedSeries = new XYSeries("Current water applied"); - private JLabel getWaterCollectedToTokensTable() { - return new JLabel(new ImageIcon("images/payoff-structure.jpg")); + private ChartPanel getWaterCollectedToTokensTable() { + final XYSeries tokensEarnedSeries = new XYSeries("Tokens earned from water applied"); + + for (int waterApplied = 0; waterApplied < 1000; waterApplied++) { + int tokensEarned = RoundConfiguration.getTokensEarned(waterApplied); + tokensEarnedSeries.add(waterApplied, tokensEarned); + } + + + XYSeriesCollection data = new XYSeriesCollection(); + data.addSeries(tokensEarnedSeries); + data.addSeries(currentWaterAppliedSeries); + JFreeChart chart = ChartFactory.createXYLineChart( + "Water applied to tokens earned", + "Cubic feet of water applied to your field", + "Tokens earned", + data, + PlotOrientation.VERTICAL, + true, + true, + false + ); + return new ChartPanel(chart); } /** @@ -389,7 +419,11 @@ getTokensEarnedTextField().setText("" + clientData.getTokensEarnedFromWaterCollected()); getTotalTokensEarnedTextField().setText("" + clientData.getAllTokensEarnedThisRound()); getMiddleWindowPanel().update(clientDataModel); - + + currentWaterAppliedSeries.clear(); + for (int i = 0; i <= clientData.getTokensEarnedFromWaterCollected(); i++) { + currentWaterAppliedSeries.add(clientData.getWaterCollected(), i); + } } }); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-11-13 05:32:07 UTC (rev 360) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/RoundConfiguration.java 2009-11-13 06:56:43 UTC (rev 361) @@ -27,6 +27,56 @@ super(); } + public static int getTokensEarned(int waterCollected) { + if (waterCollected < 150) { + return 0; + } + else if (waterCollected < 200) { + return 1; + } + else if (waterCollected < 250) { + return 4; + } + else if (waterCollected < 300) { + return 10; + } + else if (waterCollected < 350) { + return 15; + } + else if (waterCollected < 400) { + return 18; + } + else if (waterCollected < 500) { + return 19; + } + else if (waterCollected < 550) { + return 20; + } + else if (waterCollected < 650) { + return 19; + } + else if (waterCollected < 700) { + return 18; + } + else if (waterCollected < 750) { + return 15; + } + else if (waterCollected < 800) { + return 10; + } + else if (waterCollected < 850) { + return 4; + } + else if (waterCollected < 900) { + return 1; + } + else { + return 0; + } + } + + + public RoundConfiguration(String resource) { super(resource); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-11-13 05:32:07 UTC (rev 360) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2009-11-13 06:56:43 UTC (rev 361) @@ -206,53 +206,10 @@ * @return */ public int getTokensEarnedFromWaterCollected() { - if (waterCollected < 150) { - return 0; - } - else if (waterCollected < 200) { - return 1; - } - else if (waterCollected < 250) { - return 4; - } - else if (waterCollected < 300) { - return 10; - } - else if (waterCollected < 350) { - return 15; - } - else if (waterCollected < 400) { - return 18; - } - else if (waterCollected < 500) { - return 19; - } - else if (waterCollected < 550) { - return 20; - } - else if (waterCollected < 650) { - return 19; - } - else if (waterCollected < 700) { - return 18; - } - else if (waterCollected < 750) { - return 15; - } - else if (waterCollected < 800) { - return 10; - } - else if (waterCollected < 850) { - return 4; - } - else if (waterCollected < 900) { - return 1; - } - else { - return 0; - } + return RoundConfiguration.getTokensEarned(waterCollected); } + public void collectWater() { waterCollected += availableFlowCapacity; } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-11-13 05:32:07 UTC (rev 360) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-11-13 06:56:43 UTC (rev 361) @@ -160,6 +160,9 @@ addEventProcessor(new EventTypeProcessor<BeginChatRoundRequest>(BeginChatRoundRequest.class) { @Override public void handle(BeginChatRoundRequest request) { + if (getRoundConfiguration().isFirstRound()) { + shuffleParticipants(); + } persister.clearChatData(); // pass it on to all the clients synchronized (clients) { @@ -355,6 +358,18 @@ server.repl(); } + private void shuffleParticipants() { + serverDataModel.clear(); + List<ClientData> clientDataList = new ArrayList<ClientData>(clients.values()); + // randomize the client data list + Collections.shuffle(clientDataList); + // re-add each the clients to the server data model + for (ClientData data: clientDataList) { + serverDataModel.addClient(data); + } + } + + enum IrrigationServerState { WAITING, ROUND_IN_PROGRESS }; private class IrrigationServerStateMachine implements StateMachine { @@ -448,6 +463,8 @@ submittedClients = 0; persister.clear(); } + + private void advanceToNextRound() { if (getConfiguration().isLastRound()) { state = IrrigationServerState.WAITING; @@ -458,14 +475,8 @@ // set up the next round synchronized (clients) { if (nextRoundConfiguration.shouldRandomizeGroup()) { - serverDataModel.clear(); - List<ClientData> clientDataList = new ArrayList<ClientData>(clients.values()); - // randomize the client data list - Collections.shuffle(clientDataList); - // re-add each the clients to the server data model - for (ClientData data: clientDataList) { - serverDataModel.addClient(data); - } + shuffleParticipants(); + } // send registration events to all participants. for (ClientData data: clients.values()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-13 15:14:51
|
Revision: 362 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=362&view=rev Author: alllee Date: 2009-11-13 15:14:42 +0000 (Fri, 13 Nov 2009) Log Message: ----------- minor code hygiene, removing unused code etc. 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/Gate.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-11-13 06:56:43 UTC (rev 361) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalAnimationPanel.java 2009-11-13 15:14:42 UTC (rev 362) @@ -139,7 +139,7 @@ //get the position information of the ball. and then recheck the condition for height. if((balls[i].getPosition() == 1)||(balls[i].getPosition() == 2) || (balls[i].getPosition()==3) || (balls[i].getPosition() == 4) || (balls[i].getPosition() == 5)){ - if(!((!gate[balls[i].getPosition()-1].isOpenGate())&& balls[i].getY() >= (gate[balls[i].getPosition()-1].getY()+gate[balls[i].getPosition()-1].getHeight()))) + if(!((!gate[balls[i].getPosition()-1].isGateOpen())&& 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 { @@ -161,7 +161,7 @@ private void updateGUI() { for(int i=1;i<6;i++){ - if(gate[i-1].isOpenGate()){ + if(gate[i-1].isGateOpen()){ if(!(gate[i-1].getHeight() - gateHeight < 0)){ gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); @@ -181,7 +181,7 @@ gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); //opening the lid logic - if(gate[i].isOpenGate()){ + if(gate[i].isGateOpen()){ gate[i].setx1(gate[i].getx2()); if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); @@ -193,7 +193,7 @@ gate[i].sety1(gate[i].getdefaulty1()); } - if(gate[0].isOpenGate()){ + if(gate[0].isGateOpen()){ gate[0].setx1(gate[0].getx2()); if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); @@ -280,7 +280,7 @@ case 1: /*if(gate[0].isOpenGate() && (balls[i].x >= 400 && balls[i].x <= 420) && (balls[i].y >= 80 && balls[i].y <= 100)){ - */ if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+20)) + */ if(gate[0].isGateOpen() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+20)) && (balls[i].y >= 80 && balls[i].y <= 100)){ balls[i].setPosition(7); //directly pass in the information @@ -309,7 +309,7 @@ break; - case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+20)) + case 2: if(gate[1].isGateOpen() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+20)) && (balls[i].y >= 80 && balls[i].y <= 100)){ balls[i].setPosition(8); //directly pass in the information @@ -333,7 +333,7 @@ break; - case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+20)) + case 3: if(gate[2].isGateOpen() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+20)) && (balls[i].y >= 80 && balls[i].y <= 100)){ balls[i].setPosition(9); //directly pass in the information @@ -356,7 +356,7 @@ } break; - case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+20)) + case 4: if(gate[3].isGateOpen() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+20)) && (balls[i].y >= 80 && balls[i].y <= 100)){ balls[i].setPosition(10); //directly pass in the information @@ -379,7 +379,7 @@ } break; - case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+20)) + case 5: if(gate[4].isGateOpen() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+20)) && (balls[i].y >= 80 && balls[i].y <= 100)){ balls[i].setPosition(11); //directly pass in the information 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-11-13 06:56:43 UTC (rev 361) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java 2009-11-13 15:14:42 UTC (rev 362) @@ -40,8 +40,6 @@ private Random generator = new Random(); - private final static boolean enableBallAnimation = true; - private int maximumIrrigationCapacity; private ClientDataModel clientDataModel; @@ -124,7 +122,7 @@ 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()))) + if(!((!gate[balls[i].getPosition()-1].isGateOpen())&& 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{ @@ -144,7 +142,7 @@ private void updateGUI() { for(int i=1;i<6;i++){ - if(gate[i-1].isOpenGate()){ + if(gate[i-1].isGateOpen()){ if(!(gate[i-1].getHeight() - gateHeight < 0)){ gate[i].setHeight(gate[i-1].getHeight() - gateHeight ); @@ -164,7 +162,7 @@ gate[i].setOpeningsY(gate[i].getOpeningsHeight() - 50); //opening the lid logic - if(gate[i].isOpenGate()){ + if(gate[i].isGateOpen()){ gate[i].setx1(gate[i].getx2()); if(!(gate[i].gety2()- gate[i].getGateWidth() < gate[i].getY())) gate[i].sety1(gate[i].gety2()- gate[i].getGateWidth()); @@ -176,7 +174,7 @@ gate[i].sety1(gate[i].getdefaulty1()); } - if(gate[0].isOpenGate()){ + if(gate[0].isGateOpen()){ gate[0].setx1(gate[0].getx2()); if(!(gate[0].gety2()- gate[0].getGateWidth() < gate[0].getY())) gate[0].sety1(gate[0].gety2()- gate[0].getGateWidth()); @@ -237,7 +235,7 @@ } break; - case 1: if(gate[0].isOpenGate() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+gateBuffer)) + case 1: if(gate[0].isGateOpen() && (balls[i].x >= gate[0].getOpeningsX() && balls[i].x <= (gate[0].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ balls[i].setPosition(7); //directly pass in the information @@ -255,7 +253,7 @@ break; - case 2: if(gate[1].isOpenGate() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+gateBuffer)) + case 2: if(gate[1].isGateOpen() && (balls[i].x >= gate[1].getOpeningsX() && balls[i].x <= (gate[1].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ balls[i].setPosition(8); //directly pass in the information @@ -273,7 +271,7 @@ break; - case 3: if(gate[2].isOpenGate() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+gateBuffer)) + case 3: if(gate[2].isGateOpen() && (balls[i].x >= gate[2].getOpeningsX() && balls[i].x <= (gate[2].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ balls[i].setPosition(9); //directly pass in the information @@ -296,7 +294,7 @@ } break; - case 4: if(gate[3].isOpenGate() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+gateBuffer)) + case 4: if(gate[3].isGateOpen() && (balls[i].x >= gate[3].getOpeningsX() && balls[i].x <= (gate[3].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ balls[i].setPosition(10); //directly pass in the information @@ -313,7 +311,7 @@ } break; - case 5: if(gate[4].isOpenGate() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+gateBuffer)) + case 5: if(gate[4].isGateOpen() && (balls[i].x >= gate[4].getOpeningsX() && balls[i].x <= (gate[4].getOpeningsX()+gateBuffer)) && (balls[i].y >= serverHeight - gateBuffer && balls[i].y <= serverHeight)){ balls[i].setPosition(11); //directly pass in the information 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-11-13 06:56:43 UTC (rev 361) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-11-13 15:14:42 UTC (rev 362) @@ -1,19 +1,16 @@ package edu.asu.commons.irrigation.client; import java.awt.BorderLayout; -import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.swing.JButton; import javax.swing.JEditorPane; -import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JProgressBar; import javax.swing.JScrollPane; Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Gate.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Gate.java 2009-11-13 06:56:43 UTC (rev 361) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/Gate.java 2009-11-13 15:14:42 UTC (rev 362) @@ -6,7 +6,7 @@ */ public class Gate { - private boolean openGate = false; + private boolean gateOpen = false; private int height; @@ -40,13 +40,7 @@ private int y2; - private int priority; - - private double totalContributedBandwidth; - public Gate(double totalContributedBandwidth, int priority){ - this.totalContributedBandwidth = totalContributedBandwidth; - this.priority = priority; setWidth(198); setHeight(totalContributedBandwidth*0.8); setOpeningsWidth(gateWidth); @@ -62,7 +56,6 @@ } public void setOpeningsY(int openingsY) { - // TODO Auto-generated method stub this.openingsy = 100 - openingsY; this.y1 = 100 - openingsY; this.y2 = 100 - openingsY; @@ -70,22 +63,18 @@ } public void setOpeningsWidth(int gateWidth) { - // TODO Auto-generated method stub openingsWidth = gateWidth; } public void setOpeningsHeight(double gateHeight) { - // TODO Auto-generated method stub openingsHeight = (int)(gateHeight)+this.gateHeight; } public void setY(int y) { - // TODO Auto-generated method stub this.y = y; } public void setWidth(int width) { - // TODO Auto-generated method stub this.width = width; } @@ -132,106 +121,84 @@ } public int getHeight() { - // TODO Auto-generated method stub return height; } public int getWidth() { - // TODO Auto-generated method stub return width; } public int getY() { - // TODO Auto-generated method stub + return y; } public int getX() { - // TODO Auto-generated method stub return x; } - public boolean isOpenGate(){ - if(openGate == true) - return true; - else - return false; + public boolean isGateOpen(){ + return gateOpen; } - public void setGateOpen(boolean openGate) { - // TODO Auto-generated method stub - this.openGate = openGate; + public void setGateOpen(boolean gateOpen) { + this.gateOpen = gateOpen; } public int getOpeningsHeight() { - // TODO Auto-generated method stub return openingsHeight; } public int getOpeningsX() { - // TODO Auto-generated method stub return openingsx; } public int getOpeningsY() { - // TODO Auto-generated method stub return openingsy; } public int getOpeningsWidth() { - // TODO Auto-generated method stub return openingsWidth; } public int gety2() { - // TODO Auto-generated method stub return y2; } public int gety1() { - // TODO Auto-generated method stub return y1; } public int getx1() { - // TODO Auto-generated method stub return x1; } public int getx2() { - // TODO Auto-generated method stub return x2; } public void setx1(int x1) { - // TODO Auto-generated method stub this.x1 = x1; } public int getGateWidth() { - // TODO Auto-generated method stub return gateWidth; } public void sety1(int y1) { - // TODO Auto-generated method stub this.y1 = y1; } public int getdefaultx1() { - // TODO Auto-generated method stub return defaultx1; } public int getdefaulty1() { - // TODO Auto-generated method stub return defaulty1; } public void sety2(int y2) { - // TODO Auto-generated method stub this.y2 = y2; } - } 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-11-13 06:56:43 UTC (rev 361) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleScorePanel.java 2009-11-13 15:14:42 UTC (rev 362) @@ -29,8 +29,8 @@ private JLabel tokensEarnedLabel; - private JLabel tokensNotInvestedLabel; - private JLabel totalTokensEarnedLabel; +// private JLabel tokensNotInvestedLabel; +// private JLabel totalTokensEarnedLabel; private int priority; @@ -55,21 +55,21 @@ // this.add(getTotalTokensEarnedLabel(),null); } - private JLabel getTotalTokensEarnedLabel() { - if (totalTokensEarnedLabel == null) { - totalTokensEarnedLabel = new JLabel(); - totalTokensEarnedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10+20+10+30+30,30,20)); - } - return totalTokensEarnedLabel; - } +// private JLabel getTotalTokensEarnedLabel() { +// if (totalTokensEarnedLabel == null) { +// totalTokensEarnedLabel = new JLabel(); +// totalTokensEarnedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10+20+10+30+30,30,20)); +// } +// return totalTokensEarnedLabel; +// } - private JLabel getTokensNotInvestedLabel() { - if (tokensNotInvestedLabel == null) { - tokensNotInvestedLabel = new JLabel(String.valueOf(clientData.getUninvestedTokens())); - tokensNotInvestedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10+20+10+30,30,20)); - } - return tokensNotInvestedLabel; - } +// private JLabel getTokensNotInvestedLabel() { +// if (tokensNotInvestedLabel == null) { +// tokensNotInvestedLabel = new JLabel(String.valueOf(clientData.getUninvestedTokens())); +// tokensNotInvestedLabel.setBounds(new Rectangle(5,10+32+10+20+10+20+10+20+10+30,30,20)); +// } +// return tokensNotInvestedLabel; +// } private JLabel getTokensEarnedLabel() { if(tokensEarnedLabel == null){ @@ -106,12 +106,12 @@ public void update(ClientData clientData) { this.clientData = clientData; - availableWaterLabel.setText("" + clientData.getAvailableFlowCapacity()); - waterCollectedLabel.setText("" + clientData.getWaterCollected()); - tokensEarnedLabel.setText("" + clientData.getTokensEarnedFromWaterCollected()); + availableWaterLabel.setText(clientData.getAvailableFlowCapacity() + " cfps"); + waterCollectedLabel.setText(clientData.getWaterCollected() + " cf"); + tokensEarnedLabel.setText(String.valueOf(clientData.getTokensEarnedFromWaterCollected())); if(clientData.isGateOpen() && clientData.getAvailableFlowCapacity() > 0) { - // show that client is actively irrigating + // animation displaying active crop growing? } } 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-11-13 06:56:43 UTC (rev 361) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MiddleWindowPanel.java 2009-11-13 15:14:42 UTC (rev 362) @@ -1,6 +1,5 @@ package edu.asu.commons.irrigation.client; - import java.awt.Dimension; import java.awt.Rectangle; import java.util.ArrayList; @@ -27,7 +26,7 @@ private JLabel availableWaterLabel; private JLabel waterCollectedLabel; private JLabel tokensEarnedLabel; - private JLabel tokensNotInvestedLabel; +// private JLabel tokensNotInvestedLabel; private JLabel totalTokensEarnedLabel; Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-11-13 06:56:43 UTC (rev 361) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-11-13 15:14:42 UTC (rev 362) @@ -14,11 +14,11 @@ import javax.swing.SwingUtilities; import edu.asu.commons.irrigation.events.BeginChatRoundRequest; +import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; import edu.asu.commons.irrigation.events.ShowGameScreenshotRequest; +import edu.asu.commons.irrigation.events.ShowInstructionsRequest; import edu.asu.commons.irrigation.events.ShowQuizRequest; import edu.asu.commons.irrigation.events.ShowTokenInvestmentScreenRequest; -import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent; -import edu.asu.commons.irrigation.events.ShowInstructionsRequest; import edu.asu.commons.irrigation.server.ClientData; import edu.asu.commons.irrigation.server.GroupDataModel; import edu.asu.commons.irrigation.server.ServerDataModel; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-19 03:43:00
|
Revision: 368 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=368&view=rev Author: alllee Date: 2009-11-19 03:42:52 +0000 (Thu, 19 Nov 2009) Log Message: ----------- minor hygiene / refactoring, renaming Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 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/InfrastructureEfficiencyChartPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 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-11-18 07:15:06 UTC (rev 367) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-11-19 03:42:52 UTC (rev 368) @@ -177,7 +177,7 @@ } public void initialize(List<Identifier> participants) { - System.err.println("Setting participants: " + participants); + displayMessage("", " ---- chat round starting ---- "); if (HANDLES != null) { return; } @@ -187,7 +187,6 @@ HANDLES[i] = " " + HANDLE_STRING.charAt(i) + " "; chatHandles.put(participants.get(i), HANDLES[i]); } - displayMessage("", " ---- chat round starting ---- "); } public Identifier getClientId() { 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-11-18 07:15:06 UTC (rev 367) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2009-11-19 03:42:52 UTC (rev 368) @@ -122,7 +122,7 @@ } public int getIrrigationCapacity() { - return groupDataModel.getIrrigationCapacity(); + return groupDataModel.getWaterDeliveryCapacity(); } 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-18 07:15:06 UTC (rev 367) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-11-19 03:42:52 UTC (rev 368) @@ -207,6 +207,7 @@ else { setInstructions(instructionsBuilder.toString()); nextButton.setEnabled(false); + disableQuiz(); } } }); @@ -390,7 +391,7 @@ private void setInstructions(String instructions, boolean caretToEnd) { instructionsEditorPane.setText(instructions); - instructionsEditorPane.setCaretPosition(caretToEnd ? instructions.length() : 0); + instructionsEditorPane.setCaretPosition(caretToEnd ? instructions.length() - 1 : 0); } private void displayInstructions(final String instructions) { @@ -473,19 +474,19 @@ builder.append("<ul><li>Infrastructure efficiency before investment: ") .append(groupDataModel.getInfrastructureEfficiencyBeforeInvestment()) .append("%</li>"); - builder.append("<li>Irrigation capacity before investment: ").append(groupDataModel.getIrrigationCapacityBeforeInvestment()).append(" cubic feet per second</li>"); + builder.append("<li>Water delivery capacity before investment: ").append(groupDataModel.getIrrigationCapacityBeforeInvestment()).append(" cubic feet per second</li>"); builder.append( String.format( "<li>Total group investment: %d tokens, increasing the infrastructure efficiency to %d%%</li>", totalContributedTokens, groupDataModel.getInfrastructureEfficiency())); - if (groupDataModel.getIrrigationCapacity() > groupDataModel.getIrrigationCapacityBeforeInvestment()) { - builder.append("<li><b>Your group's investment has increased the irrigation capacity to "); + if (groupDataModel.getWaterDeliveryCapacity() > groupDataModel.getIrrigationCapacityBeforeInvestment()) { + builder.append("<li><b>Your group's investment has increased the water delivery capacity to "); } else { - builder.append("<li>Your group's investment was not enough to increase the irrigation capacity. Your group's irrigation capacity is still "); + builder.append("<li>Your group's investment was not enough to increase the water delivery capacity. Your group's water delivery capacity is still "); } - builder.append(groupDataModel.getIrrigationCapacity()).append(" cubic feet of water per second.</li><li>The amount of water available to pass through your irrigation canal is ") - .append(groupDataModel.getActualFlowCapacity()).append(" cubic feet per second</li>"); + builder.append(groupDataModel.getWaterDeliveryCapacity()).append(" cubic feet of water per second.</li><li>The amount of water available to pass through your irrigation canal is ") + .append(groupDataModel.getActualWaterDeliveryCapacity()).append(" cubic feet per second</li>"); SwingUtilities.invokeLater(new Runnable() { public void run() { contributionInformationEditorPane.setText(builder.toString()); @@ -538,17 +539,17 @@ infrastructureEfficiency = roundConfiguration.getInitialInfrastructureEfficiency(); } else { - infrastructureEfficiency = group.getInfrastructureEfficiency() - roundConfiguration.getInfrastructureDegradationFactor(); + infrastructureEfficiency = Math.max(0, group.getInfrastructureEfficiency() - roundConfiguration.getInfrastructureDegradationFactor()); } addCenterComponent(getTokenInvestmentPanel()); StringBuilder builder = new StringBuilder(); builder.append( String.format( "<h2>Current infrastructure efficiency: %d%%</h2>" + - "<h2>Current irrigation capacity: %d cubic feet per second</h2>" + + "<h2>Current water delivery capacity: %d cubic feet per second</h2>" + "<h2>Available water supply: %d cubic feet per second</h2>", infrastructureEfficiency, - group.calculateFlowCapacity(infrastructureEfficiency), + group.calculateWaterDeliveryCapacity(infrastructureEfficiency), roundConfiguration.getWaterSupplyCapacity() )); builder.append(getServerConfiguration().getInvestmentInstructions()); @@ -563,18 +564,18 @@ if (! roundConfiguration.isFirstRound()) { instructionsBuilder.append(roundConfiguration.getInstructions()); instructionsBuilder.append("<hr/>"); - int irrigationCapacity = clientDataModel.getGroupDataModel().getIrrigationCapacity(); + int irrigationCapacity = clientDataModel.getGroupDataModel().getWaterDeliveryCapacity(); // int clientCapacity = roundConfiguration.getMaximumClientFlowCapacity(); if (roundConfiguration.shouldResetInfrastructureEfficiency()) { - instructionsBuilder.append("The irrigation infrastructure efficiency is currently 75%."); + instructionsBuilder.append("The irrigation infrastructure efficiency is currently 75% (water delivery capacity of 35 cfps)."); } else { instructionsBuilder.append( - String.format("<p>The <b>current infrastructure efficiency is %d%%</b> but will <b>decline by %d%%</b> during this round." + - "The <b>current irrigation capacity is %d cfps</b> and the <b>available water supply is %d cfps</b>.</p><hr/>", + String.format("<p>The <b>irrigation infrastructure efficiency is %d%% (water delivery capacity of %d cfps)</b> but will <b>decline by %d%%</b> during this round." + + "The <b>available water supply is %d cfps</b>.</p><br/><hr/>", clientDataModel.getGroupDataModel().getInfrastructureEfficiency(), + irrigationCapacity, roundConfiguration.getInfrastructureDegradationFactor(), - irrigationCapacity, roundConfiguration.getWaterSupplyCapacity() )); } @@ -637,15 +638,11 @@ /** * Should only be invoked when the instructions navigation panel is done. - * How do we know when it's done? When the user adds a new + * How do we know when it's done? */ - public void disableQuiz() { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - getInstructionsPanel().remove(getQuizNavigationPanel()); - getInstructionsPanel().revalidate(); - } - }); + private void disableQuiz() { + getInstructionsPanel().remove(getQuizNavigationPanel()); + getInstructionsPanel().revalidate(); } public void showGameScreenshot() { Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-11-18 07:15:06 UTC (rev 367) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-11-19 03:42:52 UTC (rev 368) @@ -55,15 +55,15 @@ final XYSeries waterSupplySeries = new XYSeries("Available water supply"); GroupDataModel group = client.getClientDataModel().getGroupDataModel(); final int actualInfrastructureEfficiency = group.getInfrastructureEfficiency(); - final int actualFlowCapacity = group.getIrrigationCapacity(); + final int actualFlowCapacity = group.getWaterDeliveryCapacity(); for (int y = 0; y <= actualFlowCapacity; y++) { actualFlowCapacitySeries.add(actualInfrastructureEfficiency, y); } RoundConfiguration roundConfiguration = client.getRoundConfiguration(); int maximumInfrastructureEfficiency = roundConfiguration.getMaximumInfrastructureEfficiency(); int waterSupplyCapacity = roundConfiguration.getWaterSupplyCapacity(); - for(int x = 0; x <= maximumInfrastructureEfficiency; x++){ - int flowCapacity = group.calculateFlowCapacity(x); + for (int x = 0; x <= maximumInfrastructureEfficiency; x++) { + int flowCapacity = group.calculateWaterDeliveryCapacity(x); potentialFlowCapacitySeries.add(x,flowCapacity); waterSupplySeries.add(x, waterSupplyCapacity); } @@ -76,14 +76,15 @@ final XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(initialInfrastructureEfficiencySeries); + // the second series gets turned blue. + data.addSeries(waterSupplySeries); data.addSeries(actualFlowCapacitySeries); data.addSeries(potentialFlowCapacitySeries); - data.addSeries(waterSupplySeries); final JFreeChart chart = ChartFactory.createXYLineChart( "Water Delivery Capacity vs. Infrastructure Efficiency", - "Infrastructure Efficiency", - "Water Delivery Capacity", + "Infrastructure Efficiency (%)", + "Water Delivery Capacity (cfps)", data, PlotOrientation.VERTICAL, true, 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-18 07:15:06 UTC (rev 367) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-11-19 03:42:52 UTC (rev 368) @@ -124,10 +124,10 @@ private JPanel getMainInterfacePanel() { if(mainInterfacePanel == null){ - scoreBoardLabel = new JLabel("EARNINGS GRAPH"); + scoreBoardLabel = new JLabel(""); scoreBoardLabel.setBounds(new Rectangle(582,225+100+35,530,20)); scoreBoardLabel.setHorizontalAlignment(SwingConstants.CENTER); - gateSwitchLabel = new JLabel("DASHBOARD"); + gateSwitchLabel = new JLabel(""); gateSwitchLabel.setBounds(new Rectangle(13,225+100+35,530,20)); gateSwitchLabel.setHorizontalAlignment(SwingConstants.CENTER); mainInterfacePanel = new JPanel(); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-11-18 07:15:06 UTC (rev 367) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-11-19 03:42:52 UTC (rev 368) @@ -18,7 +18,6 @@ import edu.asu.commons.irrigation.events.ShowGameScreenshotRequest; import edu.asu.commons.irrigation.events.ShowInstructionsRequest; import edu.asu.commons.irrigation.events.ShowQuizRequest; -import edu.asu.commons.irrigation.events.ShowTokenInvestmentScreenRequest; import edu.asu.commons.irrigation.server.ClientData; import edu.asu.commons.irrigation.server.GroupDataModel; import edu.asu.commons.irrigation.server.ServerDataModel; @@ -52,32 +51,28 @@ private JButton showScreenshotButton; - private JButton displayInvestmentButton; +// private JButton displayInvestmentButton; private StringBuilder builder = new StringBuilder(); - private JButton beginExperimentButton; + private JButton overrideButton; /** * This is the default constructor */ public FacilitatorWindow(Facilitator facilitator) { this.facilitator = facilitator; - initGuiComponents(); + initialize(); } - /** - * - * @return void - */ - private void initGuiComponents() { + private void initialize() { setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.add(getShowInstructionsButton()); - buttonPanel.add(getBeginChatButton()); - buttonPanel.add(getDisplayInvestmentButton()); buttonPanel.add(getShowScreenshotButton()); + buttonPanel.add(getBeginChatButton()); +// buttonPanel.add(getDisplayInvestmentButton()); buttonPanel.add(getStartRoundButton()); buttonPanel.add(getShowQuizButton()); buttonPanel.add(getStartRoundOverrideButton()); @@ -125,28 +120,28 @@ } private JButton getStartRoundOverrideButton() { - if (beginExperimentButton == null) { - beginExperimentButton = new JButton("Override"); - beginExperimentButton.addActionListener(new ActionListener() { + if (overrideButton == null) { + overrideButton = new JButton("Override"); + overrideButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { facilitator.sendStartRoundOverride(); } }); } - return beginExperimentButton; + return overrideButton; } - private JButton getDisplayInvestmentButton() { - if (displayInvestmentButton == null) { - displayInvestmentButton = new JButton("Show Investment Screen"); - displayInvestmentButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - facilitator.transmit(new ShowTokenInvestmentScreenRequest(facilitator.getId())); - } - }); - } - return displayInvestmentButton; - } +// private JButton getDisplayInvestmentButton() { +// if (displayInvestmentButton == null) { +// displayInvestmentButton = new JButton("Show Investment Screen"); +// displayInvestmentButton.addActionListener(new ActionListener() { +// public void actionPerformed(ActionEvent event) { +// facilitator.transmit(new ShowTokenInvestmentScreenRequest(facilitator.getId())); +// } +// }); +// } +// return displayInvestmentButton; +// } public Facilitator getFacilitator() { return facilitator; Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-11-18 07:15:06 UTC (rev 367) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2009-11-19 03:42:52 UTC (rev 368) @@ -96,7 +96,7 @@ totalContributedTokens += clientData.getInvestedTokens(); } updateInfrastructureEfficiency(totalContributedTokens); - currentlyAvailableFlowCapacity = maximumAvailableWaterFlow = getActualFlowCapacity(); + currentlyAvailableFlowCapacity = maximumAvailableWaterFlow = getActualWaterDeliveryCapacity(); } private void updateInfrastructureEfficiency(int totalContributedTokens) { @@ -124,7 +124,7 @@ * @param totalTokens * @return */ - public int calculateFlowCapacity(final int infrastructureEfficiency) { + public int calculateWaterDeliveryCapacity(final int infrastructureEfficiency) { if (infrastructureEfficiency <= 45) { return 0; } @@ -157,15 +157,15 @@ public int getIrrigationCapacityBeforeInvestment() { // return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); - return calculateFlowCapacity(infrastructureEfficiencyBeforeInvestment); + return calculateWaterDeliveryCapacity(infrastructureEfficiencyBeforeInvestment); } /** * Returns the theoretical maximum amount of water that the infrastructure can handle. * This is independent of the actual water supply. */ - public int getIrrigationCapacity() { - return calculateFlowCapacity(infrastructureEfficiency); + public int getWaterDeliveryCapacity() { + return calculateWaterDeliveryCapacity(infrastructureEfficiency); // return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); } @@ -174,8 +174,8 @@ * of the irrigation capacity and the water supply. * @return */ - public int getActualFlowCapacity() { - return Math.min(getIrrigationCapacity(), getRoundConfiguration().getWaterSupplyCapacity()); + public int getActualWaterDeliveryCapacity() { + return Math.min(getWaterDeliveryCapacity(), getRoundConfiguration().getWaterSupplyCapacity()); } public void resetCurrentlyAvailableFlowCapacity() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2010-01-16 00:08:32
|
Revision: 441 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=441&view=rev Author: alllee Date: 2010-01-16 00:08:20 +0000 (Sat, 16 Jan 2010) Log Message: ----------- first cut at an irrigation save file converter. still need to verify all persisted data. 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/InfrastructureEfficiencyChartPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java Added Paths: ----------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.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 2010-01-15 23:46:54 UTC (rev 440) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java 2010-01-16 00:08:20 UTC (rev 441) @@ -122,7 +122,7 @@ } public int getIrrigationCapacity() { - return groupDataModel.getWaterDeliveryCapacity(); + return groupDataModel.getIrrigationCapacity(); } 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 2010-01-15 23:46:54 UTC (rev 440) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2010-01-16 00:08:20 UTC (rev 441) @@ -479,13 +479,13 @@ String.format( "<li>Total group investment: %d tokens, increasing the infrastructure efficiency to %d%%</li>", totalContributedTokens, groupDataModel.getInfrastructureEfficiency())); - if (groupDataModel.getWaterDeliveryCapacity() > groupDataModel.getIrrigationCapacityBeforeInvestment()) { + if (groupDataModel.getIrrigationCapacity() > groupDataModel.getIrrigationCapacityBeforeInvestment()) { builder.append("<li><b>Your group's investment has increased the water delivery capacity to "); } else { builder.append("<li>Your group's investment was not enough to increase the water delivery capacity. Your group's water delivery capacity is still "); } - builder.append(groupDataModel.getWaterDeliveryCapacity()).append(" cubic feet of water per second.</li><li>The amount of water available to pass through your irrigation canal is ") + builder.append(groupDataModel.getIrrigationCapacity()).append(" cubic feet of water per second.</li><li>The amount of water available to pass through your irrigation canal is ") .append(groupDataModel.getActualWaterDeliveryCapacity()).append(" cubic feet per second</li>"); SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -549,7 +549,7 @@ "<h2>Current water delivery capacity: %d cubic feet per second</h2>" + "<h2>Available water supply: %d cubic feet per second</h2>", infrastructureEfficiency, - group.calculateWaterDeliveryCapacity(infrastructureEfficiency), + group.calculateIrrigationCapacity(infrastructureEfficiency), roundConfiguration.getWaterSupplyCapacity() )); builder.append(getServerConfiguration().getInvestmentInstructions()); @@ -564,7 +564,7 @@ if (! roundConfiguration.isFirstRound()) { instructionsBuilder.append(roundConfiguration.getInstructions()); instructionsBuilder.append("<hr/>"); - int irrigationCapacity = clientDataModel.getGroupDataModel().getWaterDeliveryCapacity(); + int irrigationCapacity = clientDataModel.getGroupDataModel().getIrrigationCapacity(); // int clientCapacity = roundConfiguration.getMaximumClientFlowCapacity(); if (roundConfiguration.shouldResetInfrastructureEfficiency()) { instructionsBuilder.append("The irrigation infrastructure efficiency is currently 75% (water delivery capacity of 35 cfps)."); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2010-01-15 23:46:54 UTC (rev 440) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2010-01-16 00:08:20 UTC (rev 441) @@ -54,7 +54,7 @@ final XYSeries waterSupplySeries = new XYSeries("Available water supply"); GroupDataModel group = client.getClientDataModel().getGroupDataModel(); final int actualInfrastructureEfficiency = group.getInfrastructureEfficiency(); - final int actualFlowCapacity = group.getWaterDeliveryCapacity(); + final int actualFlowCapacity = group.getIrrigationCapacity(); for (int y = 0; y <= actualFlowCapacity; y++) { postInvestmentInfrastructureEfficiencySeries.add(actualInfrastructureEfficiency, y); } @@ -62,7 +62,7 @@ int maximumInfrastructureEfficiency = roundConfiguration.getMaximumInfrastructureEfficiency(); int waterSupplyCapacity = roundConfiguration.getWaterSupplyCapacity(); for (int x = 0; x <= maximumInfrastructureEfficiency; x++) { - int flowCapacity = group.calculateWaterDeliveryCapacity(x); + int flowCapacity = group.calculateIrrigationCapacity(x); potentialInfrastructureEfficiencySeries.add(x,flowCapacity); waterSupplySeries.add(x, waterSupplyCapacity); } Added: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java (rev 0) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java 2010-01-16 00:08:20 UTC (rev 441) @@ -0,0 +1,172 @@ +package edu.asu.commons.irrigation.data; + +import java.io.File; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.concurrent.TimeUnit; + +import edu.asu.commons.event.ChatRequest; +import edu.asu.commons.event.PersistableEvent; +import edu.asu.commons.experiment.Persister; +import edu.asu.commons.experiment.SaveFileProcessor; +import edu.asu.commons.experiment.SavedRoundData; +import edu.asu.commons.irrigation.conf.RoundConfiguration; +import edu.asu.commons.irrigation.server.ClientData; +import edu.asu.commons.irrigation.server.GroupDataModel; +import edu.asu.commons.irrigation.server.ServerDataModel; +import edu.asu.commons.net.Identifier; + +/** + * $Id$ + * + * + * @author <a href='mailto:All...@as...'>Allen Lee</a> + * @version $Rev$ + */ +public class IrrigationSaveFileConverter { + + public static boolean convert(String saveDataDirectory) { + File allSaveFilesDirectory = new File(saveDataDirectory); + if (allSaveFilesDirectory.exists() && allSaveFilesDirectory.isDirectory()) { + List<SaveFileProcessor> processors = new ArrayList<SaveFileProcessor>(); + processors.addAll(Arrays.asList( + new ClientTokensProcessor(), + new AllDataProcessor(), + new SummaryProcessor() + )); + Persister.processSaveFiles(allSaveFilesDirectory, processors); + return true; + } + return false; + } + + public static void main(String[] args) { + if (args.length == 0) { + System.err.println("Usage: java " + IrrigationSaveFileConverter.class + " <save-data-directory>"); + System.exit(0); + } + if (convert(args[0])) { + System.err.println("Successfully converted files in " + args[0]); + } + else { + System.err.println(args[0] + " doesn't appear to be a valid save file directory."); + } + } + + private static class AllDataProcessor extends SaveFileProcessor.Base { + + @Override + public void process(SavedRoundData savedRoundData, PrintWriter writer) { + writer.println("Group #, Identifier, Event"); + ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); + ArrayList<GroupDataModel> groups = new ArrayList<GroupDataModel>(serverDataModel.getAllGroupDataModels()); + for (PersistableEvent persistableEvent: savedRoundData.getActions()) { + Identifier id = persistableEvent.getId(); + GroupDataModel group = serverDataModel.getGroupDataModel(id); + writer.println(String.format("%s, %s, %s", groups.indexOf(group), id, persistableEvent)); + } + } + + @Override + public String getOutputFileExtension() { + return "-all-data.txt"; + } + + } + + private static class SummaryProcessor extends SaveFileProcessor.Base { + + @Override + public void process(SavedRoundData savedRoundData, PrintWriter writer) { + ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); + RoundConfiguration roundConfiguration = (RoundConfiguration) savedRoundData.getRoundParameters(); + ArrayList<GroupDataModel> groups = new ArrayList<GroupDataModel>(serverDataModel.getAllGroupDataModels()); + writer.println("Group, Total group tokens earned, Water availability, Water supply, Tokens invested"); + for (GroupDataModel group: groups) { + int totalGroupTokensEarned = 0; + int totalGroupTokenInvestment = 0; + for (ClientData data : group.getClientDataMap().values()) { + totalGroupTokensEarned += data.getAllTokensEarnedThisRound(); + totalGroupTokenInvestment += data.getInvestedTokens(); + } + writer.println(String.format("%s, %d, %d, %d, %d", + groups.indexOf(group), + totalGroupTokensEarned, + group.getIrrigationCapacity(), + roundConfiguration.getWaterSupplyCapacity(), + totalGroupTokenInvestment)); + } + Map<GroupDataModel, SortedSet<ChatRequest>> chatRequestMap = new HashMap<GroupDataModel, SortedSet<ChatRequest>>(); + SortedSet<ChatRequest> allChatRequests = savedRoundData.getChatRequests(); + if (! allChatRequests.isEmpty()) { + ChatRequest first = allChatRequests.first(); + for (ChatRequest request: savedRoundData.getChatRequests()) { + GroupDataModel group = serverDataModel.getGroupDataModel(request.getSource()); + if (chatRequestMap.containsKey(group)) { + chatRequestMap.get(group).add(request); + } + else { + TreeSet<ChatRequest> chatRequests = new TreeSet<ChatRequest>(); + chatRequests.add(request); + chatRequestMap.put(group, chatRequests); + } + } + // FIXME: hack to deal with rolling chat logs + // set last creation time to the last chat request that occurred so in the next chat round + // we'll know if we repeated a chat request. + // ChatRequest last = allChatRequests.last(); + // lastCreationTime = last.getCreationTime(); + // System.err.println("last creation time: " + lastCreationTime + " - " + last); + for (GroupDataModel group: groups) { + SortedSet<ChatRequest> chatRequests = chatRequestMap.get(group); + if (chatRequests != null) { + writer.println("Group #" + groups.indexOf(group) + " chats"); + for (ChatRequest request: chatRequests) { + writer.println( + String.format("%s: %s (%s s)", + request.getSource(), + request.toString(), + TimeUnit.SECONDS.convert(request.getCreationTime() - first.getCreationTime(), TimeUnit.NANOSECONDS))); + } + } + } + } + } + + @Override + public String getOutputFileExtension() { + return "-summary.txt"; + } + + } + + private static class ClientTokensProcessor extends SaveFileProcessor.Base { + + public void process(SavedRoundData savedRoundData, PrintWriter writer) { + ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); + ArrayList<GroupDataModel> groups = new ArrayList<GroupDataModel>(serverDataModel.getAllGroupDataModels()); + writer.println("Group #, Identifier, Position, Tokens Earned From Water Collected, Uninvested Tokens"); + for (GroupDataModel group: groups) { + for (ClientData data : group.getClientDataMap().values()) { + writer.println(String.format("%s, %s, %s, %s, %s", + groups.indexOf(group), data.getId(), data.getPriorityString(), data.getTokensEarnedFromWaterCollected(), data.getUninvestedTokens())); + } + } + + + } + + @Override + public String getOutputFileExtension() { + return "-tokens.txt"; + } + + } + +} Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2010-01-15 23:46:54 UTC (rev 440) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2010-01-16 00:08:20 UTC (rev 441) @@ -124,7 +124,7 @@ * @param totalTokens * @return */ - public int calculateWaterDeliveryCapacity(final int infrastructureEfficiency) { + public int calculateIrrigationCapacity(final int infrastructureEfficiency) { if (infrastructureEfficiency <= 45) { return 0; } @@ -157,15 +157,15 @@ public int getIrrigationCapacityBeforeInvestment() { // return Math.min(calculateFlowCapacity(initialInfrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); - return calculateWaterDeliveryCapacity(infrastructureEfficiencyBeforeInvestment); + return calculateIrrigationCapacity(infrastructureEfficiencyBeforeInvestment); } /** * Returns the theoretical maximum amount of water that the infrastructure can handle. * This is independent of the actual water supply. */ - public int getWaterDeliveryCapacity() { - return calculateWaterDeliveryCapacity(infrastructureEfficiency); + public int getIrrigationCapacity() { + return calculateIrrigationCapacity(infrastructureEfficiency); // return Math.min(calculateFlowCapacity(infrastructureEfficiency), getRoundConfiguration().getWaterSupplyCapacity()); } @@ -175,7 +175,7 @@ * @return */ public int getActualWaterDeliveryCapacity() { - return Math.min(getWaterDeliveryCapacity(), getRoundConfiguration().getWaterSupplyCapacity()); + return Math.min(getIrrigationCapacity(), getRoundConfiguration().getWaterSupplyCapacity()); } public void resetCurrentlyAvailableFlowCapacity() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2010-02-04 06:10:27
|
Revision: 459 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=459&view=rev Author: alllee Date: 2010-02-04 05:35:48 +0000 (Thu, 04 Feb 2010) Log Message: ----------- improved toStrings() for a few events to make it easier to emit them directly to the converted save files, starting to investigate how to get the proper client side host name over to the server. Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InvestedTokensEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.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 2010-02-04 05:28:04 UTC (rev 458) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2010-02-04 05:35:48 UTC (rev 459) @@ -10,6 +10,7 @@ import edu.asu.commons.event.EventChannel; import edu.asu.commons.event.EventChannelFactory; import edu.asu.commons.event.EventTypeProcessor; +import edu.asu.commons.event.SocketIdentifierUpdateRequest; import edu.asu.commons.irrigation.conf.RoundConfiguration; import edu.asu.commons.irrigation.conf.ServerConfiguration; import edu.asu.commons.irrigation.events.BeginChatRoundRequest; @@ -28,6 +29,7 @@ import edu.asu.commons.net.ClientDispatcher; import edu.asu.commons.net.DispatcherFactory; import edu.asu.commons.net.Identifier; +import edu.asu.commons.net.SocketIdentifier; /** * $Id$ @@ -85,6 +87,8 @@ "Null ID from Dispatcher. Server: <" + serverConfiguration.getServerAddress() + "> is probably down."); } + // send back id + transmit(new SocketIdentifierUpdateRequest((SocketIdentifier) id)); state = ClientState.CONNECTED; } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java 2010-02-04 05:28:04 UTC (rev 458) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java 2010-02-04 05:35:48 UTC (rev 459) @@ -63,13 +63,14 @@ @Override public void process(SavedRoundData savedRoundData, PrintWriter writer) { - writer.println("Group #, Identifier, Event"); + writer.println("Time, Group #, Identifier, Event"); ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); ArrayList<GroupDataModel> groups = new ArrayList<GroupDataModel>(serverDataModel.getAllGroupDataModels()); for (PersistableEvent persistableEvent: savedRoundData.getActions()) { + long elapsedTime = savedRoundData.getElapsedTimeInSeconds(persistableEvent); Identifier id = persistableEvent.getId(); GroupDataModel group = serverDataModel.getGroupDataModel(id); - writer.println(String.format("%s, %s, %s", groups.indexOf(group), id, persistableEvent)); + writer.println(String.format("%d, %s, %s, %s", elapsedTime, groups.indexOf(group), id, persistableEvent)); } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java 2010-02-04 05:28:04 UTC (rev 458) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/CloseGateEvent.java 2010-02-04 05:35:48 UTC (rev 459) @@ -18,4 +18,8 @@ super(id); } + public String toString() { + return id + " closed gate"; + } + } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InvestedTokensEvent.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InvestedTokensEvent.java 2010-02-04 05:28:04 UTC (rev 458) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InvestedTokensEvent.java 2010-02-04 05:35:48 UTC (rev 459) @@ -22,10 +22,9 @@ public int getInvestedTokens(){ return investedTokens; } - + public String toString() { + return String.format("%s invested %d tokens", id, investedTokens); + } - - - } 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 2010-02-04 05:28:04 UTC (rev 458) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/OpenGateEvent.java 2010-02-04 05:35:48 UTC (rev 459) @@ -18,5 +18,9 @@ public OpenGateEvent(Identifier id) { super(id); } + + public String toString() { + return id + " opened gate"; + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2010-02-04 05:28:04 UTC (rev 458) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/ClientData.java 2010-02-04 05:35:48 UTC (rev 459) @@ -23,7 +23,7 @@ private static final long serialVersionUID = 5281922601551921005L; - private final Identifier id; + private Identifier id; private GroupDataModel groupDataModel; @@ -200,6 +200,10 @@ public double getTotalDollarsEarned() { return roundConfiguration.getDollarsPerToken() * totalTokens; } + + public void setId(Identifier id) { + this.id = id; + } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2010-02-04 05:28:04 UTC (rev 458) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2010-02-04 05:35:48 UTC (rev 459) @@ -14,6 +14,8 @@ import edu.asu.commons.event.EndRoundRequest; import edu.asu.commons.event.EventTypeProcessor; import edu.asu.commons.event.FacilitatorRegistrationRequest; +import edu.asu.commons.event.RoundStartedMarkerEvent; +import edu.asu.commons.event.SocketIdentifierUpdateRequest; import edu.asu.commons.experiment.AbstractExperiment; import edu.asu.commons.experiment.StateMachine; import edu.asu.commons.irrigation.conf.RoundConfiguration; @@ -35,6 +37,7 @@ import edu.asu.commons.irrigation.events.ShowTokenInvestmentScreenRequest; import edu.asu.commons.net.Dispatcher; import edu.asu.commons.net.Identifier; +import edu.asu.commons.net.SocketIdentifier; import edu.asu.commons.net.event.ConnectionEvent; import edu.asu.commons.net.event.DisconnectionRequest; import edu.asu.commons.util.Duration; @@ -195,9 +198,21 @@ } }); } - + + /** + * Registers client handling EventTypeProcessors. + * Each EventTypeProcessor encapsulates the handling of a specific kind of message event. + */ private void initializeClientHandlers() { - // client handlers + addEventProcessor(new EventTypeProcessor<SocketIdentifierUpdateRequest>(SocketIdentifierUpdateRequest.class) { + @Override + public void handle(SocketIdentifierUpdateRequest request) { + SocketIdentifier socketId = request.getSocketIdentifier(); + System.err.println("socket id from client: " + socketId); + ClientData clientData = clients.get(socketId); + System.err.println("client data: " + clientData); + } + }); addEventProcessor(new EventTypeProcessor<ConnectionEvent>(ConnectionEvent.class) { @Override public void handle(ConnectionEvent event) { @@ -394,6 +409,7 @@ currentRoundDuration.start(); state = IrrigationServerState.ROUND_IN_PROGRESS; secondTick.start(); + persister.store(new RoundStartedMarkerEvent()); // lastTime = System.currentTimeMillis(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2010-02-10 06:38:53
|
Revision: 469 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=469&view=rev Author: alllee Date: 2010-02-10 06:38:47 +0000 (Wed, 10 Feb 2010) Log Message: ----------- updated save file converter to include additional group summary stats Modified Paths: -------------- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java 2010-02-09 00:53:10 UTC (rev 468) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/data/IrrigationSaveFileConverter.java 2010-02-10 06:38:47 UTC (rev 469) @@ -89,7 +89,7 @@ ServerDataModel serverDataModel = (ServerDataModel) savedRoundData.getDataModel(); RoundConfiguration roundConfiguration = (RoundConfiguration) savedRoundData.getRoundParameters(); ArrayList<GroupDataModel> groups = new ArrayList<GroupDataModel>(serverDataModel.getAllGroupDataModels()); - writer.println("Group, Total group tokens earned, Water availability, Water supply, Tokens invested"); + writer.println("Group, Total group tokens earned, Water availability, Water supply, Tokens invested, Infrastructure before investment, Total infrastructure efficiency, % infrastructure decline"); for (GroupDataModel group: groups) { int totalGroupTokensEarned = 0; int totalGroupTokenInvestment = 0; @@ -97,12 +97,16 @@ totalGroupTokensEarned += data.getAllTokensEarnedThisRound(); totalGroupTokenInvestment += data.getInvestedTokens(); } - writer.println(String.format("%s, %d, %d, %d, %d", + writer.println(String.format("%s, %d, %d, %d, %d, %d, %d, %d", groups.indexOf(group), totalGroupTokensEarned, group.getIrrigationCapacity(), roundConfiguration.getWaterSupplyCapacity(), - totalGroupTokenInvestment)); + totalGroupTokenInvestment, + group.getInfrastructureEfficiencyBeforeInvestment(), + group.getInfrastructureEfficiency(), + roundConfiguration.getInfrastructureDegradationFactor() + )); } Map<GroupDataModel, SortedSet<ChatRequest>> chatRequestMap = new HashMap<GroupDataModel, SortedSet<ChatRequest>>(); SortedSet<ChatRequest> allChatRequests = savedRoundData.getChatRequests(); Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2010-02-09 00:53:10 UTC (rev 468) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/GroupDataModel.java 2010-02-10 06:38:47 UTC (rev 469) @@ -199,25 +199,25 @@ return maximumAvailableWaterFlow; } - public int getInfrastructureEfficiency() { - return infrastructureEfficiency; - } + public int getInfrastructureEfficiency() { + return infrastructureEfficiency; + } - public int getInfrastructureEfficiencyBeforeInvestment() { - return infrastructureEfficiencyBeforeInvestment; - } - - public Logger getLogger() { - if (logger == null) { - logger = Logger.getLogger(getClass().getName()); - } - return logger; - } - - + public int getInfrastructureEfficiencyBeforeInvestment() { + return infrastructureEfficiencyBeforeInvestment; + } + + public Logger getLogger() { + if (logger == null) { + logger = Logger.getLogger(getClass().getName()); + } + return logger; + } + + public void setRoundConfiguration(RoundConfiguration roundConfiguration) { - this.roundConfiguration = roundConfiguration; - } + this.roundConfiguration = roundConfiguration; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |