[virtualcommons-svn] SF.net SVN: virtualcommons:[306] irrigation/trunk
Status: Beta
Brought to you by:
alllee
|
From: <al...@us...> - 2009-10-20 02:36:51
|
Revision: 306
http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=306&view=rev
Author: alllee
Date: 2009-10-20 02:36:40 +0000 (Tue, 20 Oct 2009)
Log Message:
-----------
continuing to refactor GUI components. Updated the pie chart displaying token
investments and the chat panel.
Modified Paths:
--------------
irrigation/trunk/build.xml
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/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/ServerConfiguration.java
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
irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml
Added Paths:
-----------
irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InfrastructureUpdateEvent.java
Removed Paths:
-------------
irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GroupUpdateEvent.java
Modified: irrigation/trunk/build.xml
===================================================================
--- irrigation/trunk/build.xml 2009-10-20 00:15:43 UTC (rev 305)
+++ irrigation/trunk/build.xml 2009-10-20 02:36:40 UTC (rev 306)
@@ -73,7 +73,7 @@
<property name='server.class' value='edu.asu.commons.irrigation.server.IrrigationServer'/>
<property name='framework.jar' value='csidex.jar'/>
- <property name='dist.dir' value='dist' />
+ <property name='dist.dir' value='.' />
<property name='resources.dir' value='src/main/resources'/>
<property name='conf.dir' value='${resources.dir}/configuration'/>
@@ -136,7 +136,7 @@
<include name='facilitator.jar'/>
</fileset>
<fileset dir='${lib.dir}'>
- <include name='${framework.jar}'/>
+ <include name='*.jar'/>
</fileset>
<fileset dir='${resources.dir}/web'>
<include name='index.html'/>
@@ -195,7 +195,6 @@
<param name='main.class' value='${server.class}'/>
<param name='jar.name' value='server.jar'/>
</antcall>
- <move file='${dist.dir}/server.jar' tofile='server.jar'/>
</target>
<target name='build-jar'>
@@ -229,10 +228,10 @@
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${test.build.dir}"/>
- <delete dir='${dist.dir}'/>
<delete dir='${lib.dir}'/>
<delete file='server.jar'/>
-
+ <delete file='client.jar'/>
+ <delete file='facilitator.jar'/>
</target>
<!-- Compile project source files -->
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 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -2,18 +2,17 @@
import java.awt.BorderLayout;
import java.awt.Color;
-import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
-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.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
-import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JEditorPane;
@@ -33,7 +32,6 @@
import edu.asu.commons.event.ChatEvent;
import edu.asu.commons.event.ChatRequest;
-import edu.asu.commons.event.EventChannel;
import edu.asu.commons.event.EventTypeProcessor;
import edu.asu.commons.net.Identifier;
@@ -52,58 +50,65 @@
@SuppressWarnings("serial")
public class ChatPanel extends JPanel {
- private IrrigationClient client;
+ private IrrigationClient irrigationClient;
- private JTextField textField;
- public JTextField getJTextField(){
- if (textField == null) {
- textField = new JTextField();
- }
- return textField;
+ private Identifier clientId;
+
+ private JScrollPane messageScrollPane;
+
+ private JTextPane messageWindow;
+
+ private TextEntryPanel textEntryPanel;
+
+ private JEditorPane chatInstructionsPane;
+
+ public ChatPanel() {
+ initGuiComponents();
}
+
+ public ChatPanel(IrrigationClient irrigationClient) {
+ this();
+ setIrrigationClient(irrigationClient);
+ }
private class TextEntryPanel extends JPanel {
private JLabel timeLeftLabel;
-
+ private JTextField chatField;
private Identifier targetIdentifier = Identifier.ALL;
public TextEntryPanel() {
super();
setLayout(new BorderLayout(3, 3));
-
- textField.addKeyListener(new KeyAdapter() {
+ chatField = new JTextField();
+ chatField.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
- // System.err.println("event keycode is: " +
- // event.getKeyCode());
- // System.err.println("vk_enter: " + KeyEvent.VK_ENTER);
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
- sendMessage(textField);
+ sendMessage();
}
}
});
final JButton sendButton = new JButton("Send");
sendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
- sendMessage(textField);
+ sendMessage();
}
});
JPanel timeLeftPanel = new JPanel();
- timeLeftPanel.setLayout(new BoxLayout(timeLeftPanel,
- BoxLayout.LINE_AXIS));
- timeLeftLabel = new JLabel(" 50");
+ timeLeftPanel.setLayout(new BoxLayout(timeLeftPanel, BoxLayout.LINE_AXIS));
+ timeLeftLabel = new JLabel("40");
timeLeftLabel.setFont(new Font("Arial", Font.BOLD, 14));
timeLeftLabel.setForeground(new Color(0x0000dd));
timeLeftPanel.add(new JLabel(" Time left: "));
timeLeftPanel.add(timeLeftLabel);
- add(timeLeftPanel, BorderLayout.NORTH);
- add(textField, BorderLayout.CENTER);
- add(sendButton, BorderLayout.SOUTH);
+ add(timeLeftPanel, BorderLayout.PAGE_START);
+ add(chatField, BorderLayout.CENTER);
+ add(sendButton, BorderLayout.PAGE_END);
}
- private void sendMessage(JTextField textField) {
- String message = textField.getText();
+ private void sendMessage() {
+ String message = chatField.getText();
// System.err.println("message: " + message);
if (message == null || "".equals(message)) {
return;
@@ -111,26 +116,18 @@
if (targetIdentifier == null) {
return;
}
- textField.setText("");
- client.transmit(new ChatRequest(clientId, message, targetIdentifier));
+ chatField.setText("");
+ irrigationClient.transmit(new ChatRequest(clientId, message, targetIdentifier));
System.err.println("Sending a new chat request");
displayMessage(getChatHandle(clientId) + " -> "
+ getChatHandle(targetIdentifier), message);
- textField.requestFocusInWindow();
+ chatField.requestFocusInWindow();
}
private void setTimeRemaining(long timeRemaining) {
timeLeftLabel.setText(String.format(" %d s", timeRemaining / 1000L));
}
- private void setTargetHandle(Identifier targetIdentifier) {
- // this.targetIdentifier = targetIdentifier;
- // if (targetIdentifier == Identifier.ALL) {
- // timeLeftLabel.setText("everyone");
- // } else {
- // timeLeftLabel.setText(getChatHandle(targetIdentifier));
- // }
- }
}
private final static String HANDLE_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -143,6 +140,8 @@
"The time left for the discussion is displayed above the text field at the bottom of the screen.</p>";
private static String[] HANDLES;
+
+ private Map<Identifier, String> chatHandles = new HashMap<Identifier, String>();
public static void main(String[] args) {
JFrame frame = new JFrame();
@@ -157,25 +156,7 @@
frame.setVisible(true);
}
- private long timeRemaining;
- private Identifier clientId;
-
- private JScrollPane messageScrollPane;
-
- private JTextPane messageWindow;
-
- private EventChannel channel;
-
- // used by the participant to select which participant to send a message to.
- private JPanel participantButtonPanel;
-
- private List<Identifier> participants;
-
- private TextEntryPanel textEntryPanel;
-
- private JEditorPane chatInstructionsPane;
-
private void addStylesToMessageWindow() {
StyledDocument styledDocument = messageWindow.getStyledDocument();
// and why not have something like... StyleContext.getDefaultStyle() to
@@ -195,17 +176,11 @@
textEntryPanel.setTimeRemaining(timeRemaining);
}
- private String getChatHandle(Identifier source) {
- if (source.equals(Identifier.ALL)) {
+ private String getChatHandle(Identifier identifier) {
+ if (identifier.equals(Identifier.ALL)) {
return " all ";
- } else {
- int index = participants.indexOf(source);
- if (source.equals(clientId)) {
- return HANDLES[index] + "(you)";
- }
- return " " + HANDLES[index] + " ";
}
-
+ return chatHandles.get(identifier);
}
private void initGuiComponents() {
@@ -214,71 +189,19 @@
messageWindow.setEditable(false);
messageScrollPane = new JScrollPane(messageWindow);
addStylesToMessageWindow();
-
- // set up the participant panel
- participantButtonPanel = new JPanel();
- // participantButtonPanel.setLayout(new
- // BoxLayout(participantButtonPanel,
- // BoxLayout.PAGE_AXIS));
- participantButtonPanel.setLayout(new GridLayout(0, 1));
- participantButtonPanel.setBackground(Color.GRAY);
- // JLabel selfLabel = new JLabel(getChatHandle(clientId));
- // selfLabel.setForeground(Color.ORANGE);
- // selfLabel.setBackground(Color.ORANGE);
- // selfLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
- JButton selfButton = new JButton(getChatHandle(clientId));
- selfButton.setEnabled(false);
- selfButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- participantButtonPanel.add(selfButton);
- participantButtonPanel.add(Box.createRigidArea(new Dimension(0, 15)));
- for (int i = 0; i < HANDLES.length; i++) {
- final Identifier targetId = participants.get(i);
- if (targetId.equals(clientId)) {
- continue;
- }
- String handle = HANDLES[i];
- JButton button = new JButton(handle);
- button.setAlignmentX(Component.CENTER_ALIGNMENT);
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- // change stuff in the messageEntryPanel
- textEntryPanel.setTargetHandle(targetId);
- }
- });
- participantButtonPanel.add(button);
- }
- // special case to send a message to everyone
- JButton sendAllButton = new JButton(" all ");
- sendAllButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- sendAllButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textEntryPanel.setTargetHandle(Identifier.ALL);
- }
- });
- participantButtonPanel.add(sendAllButton);
-
textEntryPanel = new TextEntryPanel();
- // orient the components in true lazyman fashion.
-
chatInstructionsPane = new JEditorPane();
chatInstructionsPane.setContentType("text/html");
chatInstructionsPane.setEditorKit(new HTMLEditorKit());
chatInstructionsPane.setEditable(false);
JScrollPane chatInstructionsScrollPane = new JScrollPane(chatInstructionsPane);
chatInstructionsPane.setText(CHAT_INSTRUCTIONS);
-
-
- add(chatInstructionsScrollPane, BorderLayout.NORTH);
+ add(chatInstructionsScrollPane, BorderLayout.PAGE_START);
add(messageScrollPane, BorderLayout.CENTER);
- add(participantButtonPanel, BorderLayout.EAST);
- add(textEntryPanel, BorderLayout.SOUTH);
-
+// add(participantButtonPanel, BorderLayout.EAST);
+ add(textEntryPanel, BorderLayout.PAGE_END);
}
- public void clear() {
- participants.clear();
- }
-
private void displayMessage(String chatHandle, String message) {
// String chatHandle = getChatHandle(source);
StyledDocument document = messageWindow.getStyledDocument();
@@ -287,7 +210,8 @@
document.getStyle("bold"));
document.insertString(document.getLength(), message + "\n", null);
messageWindow.setCaretPosition(document.getLength());
- } catch (BadLocationException e) {
+ }
+ catch (BadLocationException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
@@ -298,36 +222,32 @@
if (HANDLES != null) {
return;
}
- this.participants = participants;
HANDLES = new String[participants.size()];
+ // FIXME: shuffle handles?
for (int i = HANDLES.length; --i >= 0;) {
HANDLES[i] = " " + HANDLE_STRING.charAt(i) + " ";
+ chatHandles.put(participants.get(i), HANDLES[i]);
}
- // Collections.shuffle(Arrays.asList(HANDLES));
- // System.err.println("handles: " + HANDLES);
+ }
- channel.add(this, new EventTypeProcessor<ChatEvent>(ChatEvent.class) {
+ public void setClientId(Identifier clientId) {
+ this.clientId = 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) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
displayMessage(getChatHandle(chatEvent.getSource()) + " -> "
- // FIXME: either "all" or "you".
+ getChatHandle(chatEvent.getTarget()), chatEvent.toString());
}
});
}
});
- initGuiComponents();
}
- public void setClientId(Identifier clientId) {
- this.clientId = clientId;
- }
-
- public void setClient(IrrigationClient client) {
- setClientId(client.getId());
- this.client = client;
- }
-
}
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 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -95,8 +95,6 @@
private JScrollPane tokenInstructionsScrollPane;
- private int NUMBER_INSTRUCTIONS = 9;
-
private JLabel quizMessageLabel;
private int pagesTraversed = 0;
@@ -108,12 +106,15 @@
private CanalAnimationPanel canalAnimationPanel;
private CardLayout cardLayout;
+
+ private int numberOfGeneralInstructionPages;
private JLabel infrastructureEfficiencyLabel = new JLabel("Current infrastructure efficiency: ");
public ExperimentGameWindow(IrrigationClient client) {
this.client = client;
this.clientDataModel = client.getClientDataModel();
+ this.numberOfGeneralInstructionPages = getServerConfiguration().getNumberOfGeneralInstructionPages();
}
void initialize(Dimension screenSize) {
@@ -128,7 +129,7 @@
instructionsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
instructionsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
// create a quiz listener and then initialize the instructions.
- instructionsEditorPane.setActionListener(createQuizListener(clientDataModel.getServerConfiguration()));
+ instructionsEditorPane.setActionListener(createQuizListener(getServerConfiguration()));
instructionsEditorPane.setCaretPosition(0);
setInstructions(getGeneralInstructions(0));
@@ -136,6 +137,8 @@
irrigationGamePanel = new IrrigationGamePanel(screenSize, client);
addToCardLayout(irrigationGamePanel);
addToCardLayout(getInvestTokensPanel());
+ addToCardLayout(getChatPanel());
+ addToCardLayout(getGraphPanel());
}
private void addToCardLayout(Component component) {
@@ -150,14 +153,13 @@
tokenInstructionsEditorPane = createInstructionsEditorPane();
tokenInstructionsScrollPane = new JScrollPane(tokenInstructionsEditorPane);
investTokensPanel.add(tokenInstructionsScrollPane, BorderLayout.CENTER);
- tokenInstructionsEditorPane.setText(clientDataModel.getServerConfiguration().getInvestmentInstructions());
+ tokenInstructionsEditorPane.setText(getServerConfiguration().getInvestmentInstructions());
tokenInstructionsEditorPane.setCaretPosition(0);
tokenInstructionsEditorPane.repaint();
investTokensPanel.add(getSubmitTokenPanel(), BorderLayout.SOUTH);
investTokensPanel.add(infrastructureEfficiencyLabel, BorderLayout.NORTH);
investTokensPanel.setBackground(Color.WHITE);
}
- updateInfrastructureEfficiencyLabel();
return investTokensPanel;
}
@@ -173,7 +175,6 @@
infrastructureEfficiency = group.getInfrastructureEfficiency() - roundConfiguration.getInfrastructureDegradationFactor();
}
infrastructureEfficiencyLabel.setText("Current infrastructure efficiency: " + infrastructureEfficiency);
- infrastructureEfficiencyLabel.repaint();
}
private JPanel getSubmitTokenPanel() {
@@ -206,6 +207,7 @@
instructionsNavigationPanel.add(getNextButton(), BorderLayout.LINE_END);
// displays quiz messages (correct/incorrect answer).
quizMessageLabel = new JLabel();
+ quizMessageLabel.setHorizontalAlignment(JLabel.CENTER);
instructionsNavigationPanel.add(quizMessageLabel, BorderLayout.CENTER);
}
return instructionsNavigationPanel;
@@ -225,7 +227,6 @@
}
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.
@@ -236,7 +237,7 @@
else {
getInstructionsPanel().remove(getCanalAnimationPanel());
}
- validate();
+ getInstructionsPanel().revalidate();
}
});
}
@@ -255,21 +256,21 @@
if (instructionNumber >= pagesTraversed){
nextButton.setEnabled(false);
}
-
- // getting the next instruction Number
- if (instructionNumber < NUMBER_INSTRUCTIONS) {
+ if (instructionNumber < numberOfGeneralInstructionPages) {
instructionNumber++;
+ setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed));
}
- setInstructions(getGeneralInstructions(instructionNumber,pagesTraversed));
+// else {
+// setInstructions(clientDataModel.getRoundConfiguration().getInstructions());
+// }
if(instructionNumber == 5) {
getInstructionsPanel().add(getCanalAnimationPanel(), BorderLayout.PAGE_START);
}
else {
getInstructionsPanel().remove(getCanalAnimationPanel());
}
- validate();
+ getInstructionsPanel().revalidate();
}
-
});
}
@@ -291,21 +292,22 @@
* @return
*/
private String getGeneralInstructions(int pageNumber, int pagesTraversed) {
- return clientDataModel.getServerConfiguration().getGeneralInstructions(pageNumber, pagesTraversed, clientDataModel.getPriority());
+ return getServerConfiguration().getGeneralInstructions(pageNumber, pagesTraversed, clientDataModel.getPriority());
}
private String getGeneralInstructions(int pageNumber) {
- return clientDataModel.getServerConfiguration().getGeneralInstructions(pageNumber);
+ return getServerConfiguration().getGeneralInstructions(pageNumber);
}
+
+ private ServerConfiguration getServerConfiguration() {
+ return clientDataModel.getServerConfiguration();
+ }
private JTextField getInvestedTokensTextField() {
if (investedTokensTextField == null) {
investedTokensTextField = new JTextField();
investedTokensTextField.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event) {
- // System.err.println("event keycode is: " +
- // event.getKeyCode());
- // System.err.println("vk_enter: " + KeyEvent.VK_ENTER);
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
submitInvestedTokens();
}
@@ -322,7 +324,6 @@
submitTokensButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submitInvestedTokens();
-
}
});
}
@@ -342,7 +343,7 @@
investedTokensTextField.setText("");
instructionsBuilder.delete(0, instructionsBuilder.length());
instructionsBuilder.append("\nPlease enter your tokens within the range 0 - 10");
- instructionsBuilder.append(clientDataModel.getServerConfiguration().getInvestmentInstructions());
+ instructionsBuilder.append(getServerConfiguration().getInvestmentInstructions());
tokenInstructionsEditorPane.setText(instructionsBuilder.toString());
}
}
@@ -350,7 +351,7 @@
investedTokensTextField.setText("");
instructionsBuilder.delete(0, instructionsBuilder.length());
instructionsBuilder.append("\nYou only have between 0 and 10 to invest. Please choose a number between 0 and 10 and try again.");
- instructionsBuilder.append(clientDataModel.getServerConfiguration().getInvestmentInstructions());
+ instructionsBuilder.append(getServerConfiguration().getInvestmentInstructions());
tokenInstructionsEditorPane.setText(instructionsBuilder.toString());
}
}
@@ -375,42 +376,20 @@
private void addCenterComponent(Component 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;
revalidate();
repaint();
}
public void startRound(final RoundConfiguration configuration) {
-
- // currentExperimentConfiguration = configuration;
Runnable runnable = new Runnable() {
public void run() {
-// addCenterComponent(subjectWindow);
+ addCenterComponent(irrigationGamePanel);
requestFocusInWindow();
-
}
};
SwingUtilities.invokeLater(runnable);
}
- /*
- * This method could be merged somehow with the startRoundEvent. We can get
- * rid of the sendContributionStatus then
- */
- public void updateContributions() {
- irrigationGamePanel.updateContributions(clientDataModel);
- }
-
public void update() {
irrigationGamePanel.updateClientStatus(clientDataModel);
}
@@ -447,6 +426,10 @@
System.err.println(message);
}
+ /**
+ * FIXME: needs serious refactoring
+ * @param event
+ */
private void addDebriefingText(EndRoundEvent event) {
instructionsBuilder.delete(0, instructionsBuilder.length());
@@ -515,7 +498,7 @@
"showup fee, for a grand total of $%3.2f",
(float)dollarsPerToken*clientData.getTotalTokensEarned(),
(float)dollarsPerToken*clientData.getTotalTokens(),
- (float)dollarsPerToken*clientData.getTotalTokens() + clientDataModel.getServerConfiguration().getShowUpPayment()
+ (float)dollarsPerToken*clientData.getTotalTokens() + getServerConfiguration().getShowUpPayment()
));
//append the added practice round instructions
if(clientDataModel.getRoundConfiguration().isPracticeRound()) {
@@ -523,7 +506,7 @@
"and will not count towards your actual payments");
}
else if (event.isLastRound()) {
- instructionsBuilder.append(clientDataModel.getServerConfiguration().getFinalInstructions());
+ instructionsBuilder.append(getServerConfiguration().getFinalInstructions());
}
setInstructions(instructionsBuilder.toString());
}
@@ -559,63 +542,6 @@
}
}
}
-//
-//
-// // iterate through expected answers
-// for (Map.Entry<String, String> entry : configuration.getQuizAnswers().entrySet()) {
-// // just check those questions that come in those instructions
-// String questionNumber = entry.getKey();
-// String expectedAnswer = entry.getValue();
-//
-// switch(instructionNumber){
-// case 1:
-// if(questionNumber.equalsIgnoreCase("q1")) {
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// }
-// break;
-// case 2:
-// if(questionNumber.equalsIgnoreCase("q2")){
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// }
-// break;
-// case 3:
-// if(questionNumber.equalsIgnoreCase("q3") || questionNumber.equalsIgnoreCase("q4") ) {
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// }
-// break;
-// case 4:
-// if(questionNumber.equalsIgnoreCase("q5")) {
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// }
-// break;
-//
-// case 5: if(questionNumber.equalsIgnoreCase("q6") || questionNumber.equalsIgnoreCase("q7") ){
-// //System.out.println("Entering the string equal");
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// }
-// break;
-//
-// case 6: if(questionNumber.equalsIgnoreCase("q8")){
-// //System.out.println("Entering the string equal");
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// }
-// break;
-// case 7: if(questionNumber.equalsIgnoreCase("q9") || questionNumber.equalsIgnoreCase("q10") ){
-// //System.out.println("Entering the string equal");
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// }
-// break;
-//
-// case 8: if(questionNumber.equalsIgnoreCase("q10")){
-// //System.out.println("Entering the string equal");
-// incorrectAnswers = addIncorrectAnswerList(expectedAnswer,responses,questionNumber, incorrectAnswers);
-// System.out.println("Expected question"+questionNumber);
-// System.out.println("Expected Answer"+expectedAnswer);
-// }
-// break;
-// }
-//
-// }
printIncorrectAnswerList(incorrectAnswers);
if (incorrectAnswers.isEmpty()) {
nextButton.setEnabled(true);
@@ -650,8 +576,6 @@
public void updateGraphDisplay(final ClientData clientData) {
totalContributedTokensPerGroup = clientData.getGroupDataModel().getTotalContributedTokens();
- contributionInformationTextArea = new JTextArea();
- contributionInformationTextArea.setEditable(false);
DecimalFormat df = new DecimalFormat("#.##");
final String contributionInformation =
"Initial infrastructure efficiency: " + clientData.getGroupDataModel().getInitialInfrastructureEfficiency() + "%"
@@ -674,33 +598,36 @@
Runnable runnable = new Runnable() {
public void run() {
contributionInformationTextArea.setText(contributionInformation);
+ pieChart.setClientData(clientData);
+ addCenterComponent(getGraphPanel());
}
};
SwingUtilities.invokeLater(runnable);
+ irrigationGamePanel.updateContributions(clientDataModel);
}
public JPanel getGraphPanel() {
if (graphPanel == null) {
graphPanel = new JPanel();
+ graphPanel.setName("Graph panel");
GridLayout gridLayout = new GridLayout();
gridLayout.setColumns(2);
graphPanel.setLayout(gridLayout);
graphPanel.add(getPieChartPanel(), null);
+ contributionInformationTextArea = new JTextArea();
+ contributionInformationTextArea.setEditable(false);
graphPanel.add(contributionInformationTextArea,null);
- addCenterComponent(graphPanel);
- requestFocusInWindow();
}
return graphPanel;
}
private JPanel getPieChartPanel() {
if (pieChartPanel == null) {
- ClientData clientData = clientDataModel.getClientData();
pieChartPanel = new JPanel();
xySeriesDemo = new ChartWindowPanelTokenBandwidth(client);
xySeriesDemo.setVisible(true);
- pieChart = new PieChart(clientData.getGroupDataModel(),client);
+ pieChart = new PieChart();
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(2);
gridLayout.setColumns(1);
@@ -715,15 +642,8 @@
public void updateSubmitTokenScreenDisplay() {
Runnable runnable = new Runnable() {
public void run() {
- //mainIrrigationWindow.setup(configuration);
- // reset the amount of time left in the round on food eaten
- // label to the value from the configuration file.
- // this is NOT dynamic; once the StartRoundEvent is fired off
- // by the server no new clients can connect because the round
- // has begun.
- /*roundEndsOn = (configuration.getRoundTime() * 1000L) + System.currentTimeMillis();
- update();*/
addCenterComponent(getInvestTokensPanel());
+ updateInfrastructureEfficiencyLabel();
getInvestedTokensTextField().requestFocusInWindow();
}
};
@@ -745,8 +665,8 @@
private ChatPanel getChatPanel() {
if (chatPanel == null) {
- chatPanel = new ChatPanel();
- chatPanel.setClient(client);
+ chatPanel = new ChatPanel(client);
+ chatPanel.setName("Chat panel");
}
return chatPanel;
}
@@ -759,10 +679,6 @@
ChatPanel chatPanel = getChatPanel();
chatPanel.initialize(clientDataModel.getAllClientIdentifiers());
addCenterComponent( chatPanel );
- chatPanel.getJTextField().requestFocus();
- System.err.println("Done adding chat panel...");
- //stop the animation in the instructions
-
}
});
}
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 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationClient.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -18,7 +18,7 @@
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.GroupUpdateEvent;
+import edu.asu.commons.irrigation.events.InfrastructureUpdateEvent;
import edu.asu.commons.irrigation.events.InvestedTokensEvent;
import edu.asu.commons.irrigation.events.OpenGateEvent;
import edu.asu.commons.irrigation.events.PauseRequest;
@@ -168,12 +168,11 @@
experimentGameWindow.updateRoundInstructions(configuration);
}
});
- channel.add(this, new EventTypeProcessor<GroupUpdateEvent>(GroupUpdateEvent.class) {
- public void handle(GroupUpdateEvent event) {
+ channel.add(this, new EventTypeProcessor<InfrastructureUpdateEvent>(InfrastructureUpdateEvent.class) {
+ public void handle(InfrastructureUpdateEvent event) {
System.err.println("Received group update event: " + event);
clientDataModel.setGroupDataModel(event.getGroupDataModel());
- experimentGameWindow.updateGraphDisplay(event.getClientDataMap().get(event.getId()));
- experimentGameWindow.updateContributions();
+ experimentGameWindow.updateGraphDisplay(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-20 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/IrrigationGamePanel.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -339,9 +339,9 @@
/**
* fills in the panels depending on the priority of the client
*/
- public void fillPanels(ClientDataModel clientGameState) {
+ public void fillPanels(ClientDataModel clientDataModel) {
// TODO Auto-generated method stub
- jPanelUpperWindow.add(getUpperPanel(clientGameState));
+ jPanelUpperWindow.add(getUpperPanel(clientDataModel));
//switch(clientGameState.getPriority()){
downloadScreenPanel.add(getJPanelUpStreamWindow(),null);
Modified: 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 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/PieChart.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -1,20 +1,16 @@
-/**
- *
- */
package edu.asu.commons.irrigation.client;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
-import java.text.AttributedString;
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.labels.PieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
@@ -24,67 +20,48 @@
import edu.asu.commons.net.Identifier;
/**
- * A pie chart with a custom label generator.
+ * Presents the group contributions as a pie chart.
*/
public class PieChart extends JPanel {
private static final long serialVersionUID = -5382293105043214105L;
- private GroupDataModel groupDataModel;
-
- private IrrigationClient client;
+ private ChartPanel chartPanel;
- public PieChart(GroupDataModel groupDataModel,IrrigationClient client) {
- this.groupDataModel = groupDataModel;
- this.client = client;
- final PieDataset dataset = createDataset();
- final JFreeChart chart = createChart(dataset);
- final ChartPanel chartPanel = new ChartPanel(chart);
- chartPanel.setPreferredSize(new Dimension(500, 270));
- this.add(chartPanel);
- this.setBounds(new Rectangle(0,0,500,270));
+ 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 sample dataset.
- *
+ * Creates a pie dataset out of the client
* @return a sample dataset.
*/
- private PieDataset createDataset() {
- final DefaultPieDataset dataset = new DefaultPieDataset();
+ private PieDataset createDataset(ClientData clientData) {
+ final DefaultPieDataset defaultPieDataset = new DefaultPieDataset();
+ GroupDataModel groupDataModel = clientData.getGroupDataModel();
Map<Identifier,ClientData>clientDataMap = groupDataModel.getClientDataMap();
- for(ClientData clientData : clientDataMap.values()){
- String clientPieLabel =null;
- switch(clientData.getPriority()){
- case 0 : clientPieLabel = "A = ";
- break;
-
- case 1 : clientPieLabel = "B = ";
- break;
-
- case 2 : clientPieLabel = "C = ";
- break;
-
- case 3 : clientPieLabel = "D = ";
- break;
-
- case 4 : clientPieLabel = "E = ";
- break;
- }
- if(client.getClientDataModel().getPriority() == clientData.getPriority()){
- clientPieLabel = "YOU = ";
- }
- clientPieLabel = clientPieLabel+new Integer(clientData.getInvestedTokens()).toString();
- dataset.setValue(clientPieLabel,new Double(clientData.getInvestedTokens()));
+ 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());
}
- /*dataset.setValue("One", new Double(43.2));
- dataset.setValue("Two", new Double(10.0));
- dataset.setValue("Three", new Double(27.5));
- dataset.setValue("Four", new Double(17.5));
- dataset.setValue("Five", new Double(11.0));
- dataset.setValue("Six", new Double(19.4));
- */
- return dataset;
+ return defaultPieDataset;
}
// ****************************************************************************
@@ -125,40 +102,4 @@
}
- /**
- * Starting point for the demonstration application.
- *
- * @param args ignored.
- */
-
-
- /**
- * A custom label generator (returns null for one item as a test).
- */
- static class CustomLabelGenerator implements PieSectionLabelGenerator {
-
- /**
- * Generates a label for a pie section.
- *
- * @param dataset the dataset (<code>null</code> not permitted).
- * @param key the section key (<code>null</code> not permitted).
- *
- * @return the label (possibly <code>null</code>).
- */
- public String generateSectionLabel(final PieDataset dataset, final Comparable key) {
- String result = null;
- if (dataset != null) {
- if (!key.equals("Two")) {
- result = key.toString();
- }
- }
- return result;
- }
-
- public AttributedString generateAttributedSectionLabel(PieDataset arg0, Comparable arg1) {
- return 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-20 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/conf/ServerConfiguration.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -153,5 +153,9 @@
public String getInvestmentInstructions() {
return assistant.getProperty("investment-instructions");
}
+
+ public int getNumberOfGeneralInstructionPages() {
+ return assistant.getIntProperty("general-instruction-pages", 8);
+ }
}
Deleted: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GroupUpdateEvent.java
===================================================================
--- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GroupUpdateEvent.java 2009-10-20 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GroupUpdateEvent.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -1,38 +0,0 @@
-package edu.asu.commons.irrigation.events;
-
-import java.util.Map;
-
-import edu.asu.commons.event.AbstractEvent;
-import edu.asu.commons.event.ExperimentUpdateEvent;
-import edu.asu.commons.irrigation.server.ClientData;
-import edu.asu.commons.irrigation.server.GroupDataModel;
-import edu.asu.commons.net.Identifier;
-
-/**
- * $Id$
- *
- * Event carrying the GroupDataModel and the time remaining to be sent to all participants each second.
- *
- * @author <a href='mailto:All...@as...'>Allen Lee</a>
- * @version $Rev$
- */
-public class GroupUpdateEvent extends AbstractEvent implements ExperimentUpdateEvent {
-
- private static final long serialVersionUID = -8522536860601018690L;
-
- private final GroupDataModel groupDataModel;
-
- public GroupUpdateEvent(Identifier id, GroupDataModel groupDataModel) {
- super(id);
- this.groupDataModel = groupDataModel;
- }
-
- public GroupDataModel getGroupDataModel() {
- return groupDataModel;
- }
-
- public Map<Identifier,ClientData> getClientDataMap(){
- return groupDataModel.getClientDataMap();
- }
-
-}
Copied: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InfrastructureUpdateEvent.java (from rev 298, irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/GroupUpdateEvent.java)
===================================================================
--- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InfrastructureUpdateEvent.java (rev 0)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/events/InfrastructureUpdateEvent.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -0,0 +1,42 @@
+package edu.asu.commons.irrigation.events;
+
+import java.util.Map;
+
+import edu.asu.commons.event.AbstractEvent;
+import edu.asu.commons.event.ExperimentUpdateEvent;
+import edu.asu.commons.irrigation.server.ClientData;
+import edu.asu.commons.irrigation.server.GroupDataModel;
+import edu.asu.commons.net.Identifier;
+
+/**
+ * $Id$
+ *
+ * Event carrying the GroupDataModel and the time remaining to be sent to all participants each second.
+ *
+ * @author <a href='mailto:All...@as...'>Allen Lee</a>
+ * @version $Rev$
+ */
+public class InfrastructureUpdateEvent extends AbstractEvent implements ExperimentUpdateEvent {
+
+ private static final long serialVersionUID = -8522536860601018690L;
+
+ private final GroupDataModel groupDataModel;
+
+ public InfrastructureUpdateEvent(Identifier id, GroupDataModel groupDataModel) {
+ super(id);
+ this.groupDataModel = groupDataModel;
+ }
+
+ public GroupDataModel getGroupDataModel() {
+ return groupDataModel;
+ }
+
+ public Map<Identifier,ClientData> getClientDataMap(){
+ return groupDataModel.getClientDataMap();
+ }
+
+ public ClientData getClientData() {
+ return groupDataModel.getClientData(id);
+ }
+
+}
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-20 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/Facilitator.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -8,7 +8,6 @@
import edu.asu.commons.event.BeginExperimentRequest;
import edu.asu.commons.event.BeginRoundRequest;
-import edu.asu.commons.event.ConfigurationEvent;
import edu.asu.commons.event.EndRoundRequest;
import edu.asu.commons.event.Event;
import edu.asu.commons.event.EventChannel;
@@ -18,6 +17,7 @@
import edu.asu.commons.irrigation.conf.RoundConfiguration;
import edu.asu.commons.irrigation.conf.ServerConfiguration;
import edu.asu.commons.irrigation.events.FacilitatorEndRoundEvent;
+import edu.asu.commons.irrigation.events.RegistrationEvent;
import edu.asu.commons.irrigation.server.ServerDataModel;
import edu.asu.commons.net.ClientDispatcher;
import edu.asu.commons.net.DispatcherFactory;
@@ -42,7 +42,7 @@
private ServerDataModel serverGameState; // @jve:decl-index=0:
- private FacilitatorWindow irrigationFacilitatorWindow;
+ private FacilitatorWindow facilitatorWindow;
private boolean experimentRunning = false;
@@ -55,19 +55,17 @@
public Facilitator(ServerConfiguration configuration) {
dispatcher = DispatcherFactory.getInstance().createClientDispatcher(channel);
setConfiguration(configuration);
- initializeEventProcessors();
}
-
- @SuppressWarnings("unchecked")
+
private void initializeEventProcessors() {
- channel.add(this, new EventTypeProcessor<ConfigurationEvent>(ConfigurationEvent.class) {
- public void handle(ConfigurationEvent configurationEvent) {
- setConfiguration((ServerConfiguration) configurationEvent.getConfiguration());
+ channel.add(this, new EventTypeProcessor<RegistrationEvent>(RegistrationEvent.class) {
+ public void handle(RegistrationEvent registrationEvent) {
+ facilitatorWindow.setText(registrationEvent.getRoundConfiguration().getInstructions());
}
});
channel.add(this, new EventTypeProcessor<FacilitatorEndRoundEvent>(FacilitatorEndRoundEvent.class) {
public void handle(FacilitatorEndRoundEvent event) {
- irrigationFacilitatorWindow.endRound(event);
+ facilitatorWindow.endRound(event);
configuration.nextRound();
}
});
@@ -107,8 +105,10 @@
transmit(new FacilitatorRegistrationRequest(id));
}
- void createFacilitatorWindow(Dimension dimension) {
- irrigationFacilitatorWindow = new FacilitatorWindow(dimension, this);
+ void initialize() {
+ facilitatorWindow = new FacilitatorWindow(this);
+ facilitatorWindow.setText(configuration.getFacilitatorInstructions());
+ initializeEventProcessors();
}
/*
@@ -121,24 +121,23 @@
public static void main(String[] args) {
Runnable createGuiRunnable = new Runnable() {
public void run() {
- Dimension dimension = new Dimension(500, 600);
+ Dimension dimension = new Dimension(600, 600);
Facilitator facilitator = Facilitator.getInstance();
+ facilitator.initialize();
facilitator.connect();
JFrame frame = new JFrame();
frame.setTitle("Facilitator window: " + facilitator.id);
- frame.setSize((int) dimension.getWidth(), (int) dimension.getHeight());
- facilitator.createFacilitatorWindow(dimension);
+ frame.setPreferredSize(dimension);
+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(facilitator.getFacilitatorWindow());
+ frame.pack();
frame.setVisible(true);
}
};
SwingUtilities.invokeLater(createGuiRunnable);
}
- /*
- * Send a request to server to start an experiment
- */
void sendBeginExperimentRequest(){
transmit(new BeginExperimentRequest(id));
}
@@ -155,7 +154,7 @@
}
public FacilitatorWindow getFacilitatorWindow() {
- return irrigationFacilitatorWindow;
+ return facilitatorWindow;
}
public Identifier getId(){
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 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/facilitator/FacilitatorWindow.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -1,8 +1,6 @@
package edu.asu.commons.irrigation.facilitator;
import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
@@ -10,9 +8,11 @@
import java.util.TreeSet;
import javax.swing.BoxLayout;
+import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
import edu.asu.commons.irrigation.events.BeginChatRoundRequest;
import edu.asu.commons.irrigation.events.DisplaySubmitTokenRequest;
@@ -25,8 +25,12 @@
import edu.asu.commons.util.HtmlEditorPane;
/**
- * @author Sanket
+ * $Id$
+ *
+ * Basic facilitator interface for driving the experiment.
*
+ * @author <a href='mailto:All...@as...'>Allen Lee</a>
+ * @version $Rev$
*/
public class FacilitatorWindow extends JPanel {
@@ -34,8 +38,6 @@
private Facilitator facilitator;
- private Dimension windowDimension;
-
private JButton startRoundButton = null;
private JButton beginChatButton;
@@ -44,34 +46,36 @@
private JScrollPane scrollPane;
private JButton showInstructionsButton;
+
+ private JButton displayInvestmentButton;
/**
* This is the default constructor
*/
- public FacilitatorWindow(Dimension dimension, Facilitator facilitator) {
- windowDimension = dimension;
+ public FacilitatorWindow(Facilitator facilitator) {
this.facilitator = facilitator;
- initialize();
+ initGuiComponents();
}
/**
*
* @return void
*/
- private void initialize() {
- setSize(windowDimension);
+ private void initGuiComponents() {
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(getStartRoundButton());
- buttonPanel.add(getBeginChatButton());
- buttonPanel.add(getShowInstructionsButton());
add(buttonPanel, BorderLayout.NORTH);
- JPanel informationPanel = new JPanel();
editorPane = new HtmlEditorPane();
+ editorPane.setEditable(false);
scrollPane = new JScrollPane(editorPane);
- informationPanel.add(scrollPane);
- add(informationPanel, BorderLayout.CENTER);
+ scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+ scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ add(scrollPane, BorderLayout.CENTER);
}
private JButton getShowInstructionsButton() {
@@ -102,14 +106,23 @@
if (facilitator.getCurrentRoundConfiguration().isChatEnabledBeforeRound()) {
facilitator.transmit(new BeginChatRoundRequest(facilitator.getId()));
}
- else {
- facilitator.transmit(new DisplaySubmitTokenRequest(facilitator.getId()));
- }
}
});
}
return beginChatButton;
}
+
+ private JButton getDisplayInvestmentButton() {
+ if (displayInvestmentButton == null) {
+ displayInvestmentButton = new JButton("Show Investment Screen");
+ displayInvestmentButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent event) {
+ facilitator.transmit(new DisplaySubmitTokenRequest(facilitator.getId()));
+ }
+ });
+ }
+ return displayInvestmentButton;
+ }
public Facilitator getFacilitator() {
return facilitator;
@@ -128,7 +141,6 @@
private JButton getStartRoundButton() {
if (startRoundButton == null) {
startRoundButton = new JButton();
- startRoundButton.setBounds(new Rectangle(180, 16, 136, 24));
startRoundButton.setText("Start Round");
startRoundButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -138,14 +150,21 @@
}
return startRoundButton;
}
+
+ public void setText(final String text) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ editorPane.setText(text);
+ scrollPane.revalidate();
+ }
+ });
+ }
/**
* This method initializes Stop_Round_Button1
*
* @return javax.swing.JButton
*/
-
-
public void endRound(FacilitatorEndRoundEvent event) {
ServerDataModel model = event.getServerDataModel();
StringBuilder builder = new StringBuilder();
@@ -175,8 +194,7 @@
if (event.isLastRound()) {
builder.append("<h2><font color='blue'>The experiment is over. Please prepare payments.</font></h2>");
}
- editorPane.setText(builder.toString());
- repaint();
+ setText(builder.toString());
}
-} // @jve:decl-index=0:visual-constraint="48,19"
+}
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 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/server/IrrigationServer.java 2009-10-20 02:36:40 UTC (rev 306)
@@ -24,7 +24,7 @@
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.GroupUpdateEvent;
+import edu.asu.commons.irrigation.events.InfrastructureUpdateEvent;
import edu.asu.commons.irrigation.events.InvestedTokensEvent;
import edu.asu.commons.irrigation.events.OpenGateEvent;
import edu.asu.commons.irrigation.events.PauseRequest;
@@ -276,8 +276,8 @@
group.calculateTotalFlowCapacity();
// iterate through all groups and send back their contribution status
for (Identifier id : group.getClientDataMap().keySet()) {
- GroupUpdateEvent groupUpdateEvent = new GroupUpdateEvent(id, group);
- transmit(groupUpdateEvent);
+ InfrastructureUpdateEvent infrastructureUpdateEvent = new InfrastructureUpdateEvent(id, group);
+ transmit(infrastructureUpdateEvent);
}
}
}
Modified: irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml
===================================================================
--- irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 2009-10-20 00:15:43 UTC (rev 305)
+++ irrigation/trunk/src/main/resources/configuration/asu-fall-2009/irrigation.xml 2009-10-20 02:36:40 UTC (rev 306)
@@ -595,7 +595,7 @@
]]>
</entry>
-<entry key="general-instructionsq9">
+<entry key="general-instructions8">
<![CDATA[
<p>
We will now start with two practice rounds. This practice round will not contribute to your earnings –
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|