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