[virtualcommons-svn] SF.net SVN: virtualcommons:[361] irrigation/trunk/src/main/java/edu/asu/ commo
Status: Beta
Brought to you by:
alllee
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. |