virtualcommons-svn Mailing List for Virtual Commons Experiment Software (Page 57)
Status: Beta
Brought to you by:
alllee
You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(21) |
Aug
(31) |
Sep
(6) |
Oct
(15) |
Nov
(2) |
Dec
(9) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(4) |
Feb
(6) |
Mar
(12) |
Apr
(52) |
May
(14) |
Jun
(19) |
Jul
(81) |
Aug
(115) |
Sep
(36) |
Oct
(88) |
Nov
(46) |
Dec
(58) |
2010 |
Jan
(52) |
Feb
(55) |
Mar
(48) |
Apr
(15) |
May
(5) |
Jun
(38) |
Jul
(27) |
Aug
(24) |
Sep
(28) |
Oct
(1) |
Nov
(2) |
Dec
(29) |
2011 |
Jan
(87) |
Feb
(39) |
Mar
(63) |
Apr
(42) |
May
(26) |
Jun
(53) |
Jul
(23) |
Aug
(43) |
Sep
(37) |
Oct
(25) |
Nov
(4) |
Dec
(7) |
2012 |
Jan
(73) |
Feb
(79) |
Mar
(62) |
Apr
(28) |
May
(12) |
Jun
(2) |
Jul
(9) |
Aug
(1) |
Sep
(8) |
Oct
|
Nov
(3) |
Dec
(3) |
2013 |
Jan
(8) |
Feb
(16) |
Mar
(38) |
Apr
(74) |
May
(62) |
Jun
(15) |
Jul
(49) |
Aug
(19) |
Sep
(9) |
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(25) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <al...@us...> - 2009-12-04 17:05:40
|
Revision: 407 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=407&view=rev Author: alllee Date: 2009-12-04 17:05:29 +0000 (Fri, 04 Dec 2009) Log Message: ----------- latest update of code so deepak can help debug the RegulationPanel and EnforcementPanel voting (selecting any vote clears the entire screen). Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java 2009-12-04 16:16:38 UTC (rev 406) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java 2009-12-04 17:05:29 UTC (rev 407) @@ -250,13 +250,12 @@ chatInstructionsPane.setContentType("text/html"); chatInstructionsPane.setEditorKit(new HTMLEditorKit()); chatInstructionsPane.setEditable(false); + chatInstructionsPane.setBackground(Color.WHITE); JScrollPane chatInstructionsScrollPane = new JScrollPane(chatInstructionsPane); chatInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getChatInstructions()); add(chatInstructionsScrollPane, BorderLayout.NORTH); add(messageScrollPane, BorderLayout.CENTER); - // if (client.getDataModel().getRoundConfiguration().shouldD - // add(participantButtonPanel, BorderLayout.EAST); add(textEntryPanel, BorderLayout.SOUTH); textEntryPanel.setChatFieldFocus(); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 16:16:38 UTC (rev 406) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 17:05:29 UTC (rev 407) @@ -20,6 +20,7 @@ import javax.swing.ScrollPaneConstants; import edu.asu.commons.foraging.event.EnforcementRankingRequest; +import edu.asu.commons.foraging.model.EnforcementMechanism; import edu.asu.commons.net.Identifier; /** @@ -38,12 +39,13 @@ private String[] votes = { "1", "2", "3","4"}; - private String[] enforcementOptions = { - "No Enforcement - Click here for more info ", - "Everyone sanctions - Click here for more info ", - "Randomly picked monitering - Click here for more info", - "Random sanctioning - Click here for more info " - }; + private EnforcementMechanism[] enforcementOptions = EnforcementMechanism.values(); + // private String[] enforcementOptions = { + // "No Enforcement - Click here for more info ", + // "Everyone sanctions - Click here for more info ", + // "Randomly picked monitering - Click here for more info", + // "Random sanctioning - Click here for more info " + // }; private String[] enforcementText = { "Everybody can harvest. Nobody can subtract tokens<br>" + @@ -79,61 +81,61 @@ private JPanel instructionsPanel; private SixChoicePanel[] newPanel; - private int noOfEnforcements; + private int noOfEnforcements = EnforcementMechanism.values().length; private int currentRankingInformation[]; private JPanel buttonPanel; - public EnforcementPanel () - { - newPanel = new SixChoicePanel[4]; - } + public EnforcementPanel () + { + newPanel = new SixChoicePanel[4]; + } public String getVotedEnforcementOptions(int index){ return this.enforcementText[index]; } - private JPanel getInstructionPanel() - { - JPanel instructionPanel = new JPanel(); - - //instructionPanel.setBackground(color); - instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); - instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); - - //create Text area and JSCroll pane for it - String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); + private JPanel getInstructionPanel() + { + JPanel instructionPanel = new JPanel(); - JTextArea instructionText = new JTextArea(instructions,3,50); - JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - instructionPanel.add(scrollForRegulationText); - - return instructionPanel; + //instructionPanel.setBackground(color); + instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); + instructionPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Instructions")); - } + //create Text area and JSCroll pane for it + String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); - private Color getColor(int i) - { - Color color = null; - if(i==0) color = new Color(153,153,204); - if(i==1) color = new Color(204,153,153); - if(i==2) color = new Color(153,204,102); - if(i==3) color = new Color(204,204,102); - if(i==4) color = new Color(255,255,153); - return color; - } + JTextArea instructionText = new JTextArea(instructions,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(instructionText); + instructionPanel.add(scrollForRegulationText); - // FIXME: this is extremely inefficient, reimplement later + return instructionPanel; + + } + + private Color getColor(int i) + { + Color color = null; + if(i==0) color = new Color(153,153,204); + if(i==1) color = new Color(204,153,153); + if(i==2) color = new Color(153,204,102); + if(i==3) color = new Color(204,204,102); + if(i==4) color = new Color(255,255,153); + return color; + } + + // FIXME: this is extremely inefficient, reimplement later private void updateVotingPanel(int currentActive){ int r,c,i; SixChoicePanel temp = null; boolean enableSendButton = true; - + for(r = 0; r < noOfEnforcements; r++) { - + if(newPanel[r].currentRanking == -1)enableSendButton = false; if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) @@ -167,27 +169,27 @@ // System.out.print(newPanel[c].getCurrentRanking() +" "); } - votingPanel.setVisible(false); - remove(votingPanel); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setVisible(false); + remove(votingPanel); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.add(getInstructionPanel()); + votingPanel.add(getInstructionPanel()); - for(i=0; i < noOfEnforcements; i++) { - votingPanel.add(newPanel[i].enforcementPanel); - } + for(i=0; i < noOfEnforcements; i++) { + votingPanel.add(newPanel[i].enforcementPanel); + } - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } - revalidate(); + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + revalidate(); } private String getVoteString(){ @@ -221,18 +223,18 @@ setBackground(Color.lightGray); setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - //add the instruction panel as the first panel in voting panel. - instructionsPanel = getInstructionPanel(); - votingPanel.add(instructionsPanel); + //add the instruction panel as the first panel in voting panel. + instructionsPanel = getInstructionPanel(); + votingPanel.add(instructionsPanel); for(int i=0; i<noOfEnforcements; i++) { - + //newPanel[i] = new SixChoicePanel(s, votes, enforcementData.getEnforcementID(), getColor(i)); //newPanel[i] = new SixChoicePanel(s, votes, client.getEnforcementID(), getColor(i)); newPanel[i] = new SixChoicePanel(enforcementOptions[i], votes, i, getColor(i)); @@ -288,20 +290,23 @@ public void initialize() { initGuiComponents(); } - private class SixChoicePanel implements ActionListener{ - String title; - String [] buttonLabels; - int enforcementID; - int currentRanking; - JPanel enforcementPanel; - JPanel rankPanel; - ButtonGroup group; - JRadioButton option []; - Color color; + + private class SixChoicePanel implements ActionListener{ + String title; + String description; + String [] buttonLabels; + int enforcementID; + int currentRanking; + JPanel enforcementPanel; + JPanel rankPanel; + ButtonGroup group; + JRadioButton option []; + Color color; - public SixChoicePanel(String title, String[] buttonLabels, int enforcementID, Color color ) { - this.title = title; + public SixChoicePanel(EnforcementMechanism enforcementMechanism, String[] buttonLabels, int enforcementID, Color color ) { + this.title = enforcementMechanism.getTitle(); + this.description = enforcementMechanism.getDescription(); this.buttonLabels = buttonLabels; this.enforcementID = enforcementID; this.color = color; @@ -313,46 +318,47 @@ } public void actionPerformed(ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - System.out.println("ACTION Choice Selected: " + choice); - System.out.println("Bno: " + buttonNo); - System.out.println("CurrentActive : "+this.enforcementID); - this.currentRanking = buttonNo; - updateVotingPanel(this.enforcementID); - } + String choice = group.getSelection().getActionCommand(); + int buttonNo = Integer.parseInt(choice); + System.out.println("ACTION Choice Selected: " + choice); + System.out.println("Bno: " + buttonNo); + System.out.println("CurrentActive : "+this.enforcementID); + this.currentRanking = buttonNo; + updateVotingPanel(this.enforcementID); + } - - public JPanel getEnforcementPanel(int i){ - enforcementPanel = new JPanel(); - enforcementPanel.setBackground(color); - enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); - enforcementPanel.setBorder(BorderFactory.createTitledBorder("Enforcement "+(i+1))); - //create Text area and JSCroll pane for it + public JPanel getEnforcementPanel(int i){ + enforcementPanel = new JPanel(); + enforcementPanel.setBackground(color); + enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); + enforcementPanel.setBorder(BorderFactory.createTitledBorder(title)); - JTextArea regulationText = new JTextArea(title,3,50); - JScrollPane scrollForRegulationText = new JScrollPane(regulationText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - enforcementPanel.add(scrollForRegulationText); + //create Text area and JSCroll pane for it - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length + JTextArea regulationText = new JTextArea(title,3,50); + regulationText.setText(description); + JScrollPane scrollForRegulationText = new JScrollPane(regulationText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + enforcementPanel.add(scrollForRegulationText); - for(int j=0; j<length; j++) { - option[j] = new JRadioButton(buttonLabels[j]); - option[j].setActionCommand(buttonLabels[j]); - group.add(option[j]); - option[j].addActionListener(this); - rankPanel.add(option[j]); - } - enforcementPanel.add(rankPanel); - return enforcementPanel; - } + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length - } + for(int j=0; j<length; j++) { + option[j] = new JRadioButton(buttonLabels[j]); + option[j].setActionCommand(buttonLabels[j]); + group.add(option[j]); + option[j].addActionListener(this); + rankPanel.add(option[j]); + } + enforcementPanel.add(rankPanel); + return enforcementPanel; + } + } + } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 16:16:38 UTC (rev 406) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 17:05:29 UTC (rev 407) @@ -146,6 +146,7 @@ .addStyle("italic", defaultStyle), true); } + // FIXME: extremely inefficient, refactor after experiment. private void updateVotingPanel(int currentActive){ int r,c,i; SixChoicePanel temp = null; @@ -190,11 +191,6 @@ } } - for(c = 0; c < noOfRegulations; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } - votingPanel.setVisible(false); remove(votingPanel); votingPanel = new JPanel(); @@ -357,10 +353,8 @@ instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); - - //create Text area and JSCroll pane for it - - JTextArea instructionText = new JTextArea(instructions,3,50); + JTextArea instructionText = new JTextArea(instructions); + instructionText.setWrapStyleWord(true); JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); instructionPanel.add(scrollForRegulationText); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 16:16:38 UTC (rev 406) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 17:05:29 UTC (rev 407) @@ -243,7 +243,7 @@ } public String getVotingInstructions() { - return getProperty("voting-instructions", "You may rank the below options from 1 to 5, where 1 is the most favorable and 5 is the least favorable. When you rank a given option it will be sorted automatically."); + return getProperty("voting-instructions", "You may rank the options below from 1 to 5, where 1 is the most favorable and 5 is the least favorable. When you rank a given option it will be sorted automatically."); } public String getLastRoundDebriefing() { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 16:16:38 UTC (rev 406) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 17:05:29 UTC (rev 407) @@ -152,6 +152,7 @@ logger.info("client: " + clientData.getId() + " ranked regulations: "+ regulationRankings); for (int index = 0; index < numberOfRegulations; index++) { regulationVotingTally[index] += rankToValue(regulationRankings[index]); + submittedRegulations.get(index).setRank(regulationVotingTally[index]); if (regulationVotingTally[index] > maxRankingValue) { maxRankingValue = regulationVotingTally[index]; maxRankingIndex = index; @@ -171,12 +172,13 @@ this.activeRegulation = activeRegulation; } + // FIXME: this algorithm is very similar to generateRegulationRankings, extract to other method. public EnforcementMechanism generateEnforcementRankings() { resetEnforcementRankingCount(); // FIXME: change to round config parameter instead? double[] enforcementVotingTally = new double[EnforcementMechanism.values().length]; Arrays.fill(enforcementVotingTally, 0.0d); - int maxRankingEnforcementIndex = 0; + int maxRankingIndex = 0; double maxRankingValue = 0.0d; for (ClientData clientData: clients.values()) { int[] enforcementRankings = clientData.getEnforcementRankings(); @@ -185,12 +187,12 @@ // keep a tally of the max index so we don't have to make another pass. if (enforcementVotingTally[index] > maxRankingValue) { maxRankingValue = enforcementVotingTally[index]; - maxRankingEnforcementIndex = index; + maxRankingIndex = index; } } } - activeEnforcementMechanism = EnforcementMechanism.get(maxRankingEnforcementIndex); - logger.info("Active enforcement mechanism: " + activeEnforcementMechanism + " with index " + maxRankingEnforcementIndex); + activeEnforcementMechanism = EnforcementMechanism.get(maxRankingIndex); + logger.info("Active enforcement mechanism: " + activeEnforcementMechanism + " with rank " + maxRankingValue); if (activeEnforcementMechanism.hasMonitor()) { // pick a random person from the clients ArrayList<ClientData> clientDataList = new ArrayList<ClientData>(clients.values()); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java 2009-12-04 16:16:38 UTC (rev 406) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java 2009-12-04 17:05:29 UTC (rev 407) @@ -20,7 +20,7 @@ private Identifier id; private String text; - private int rank; + private double rank; private int index; public RegulationData(Identifier id, String text) { @@ -49,11 +49,11 @@ return text; } - public int getRank() { + public double getRank() { return rank; } - public void setRank(int rank) { + public void setRank(double rank) { this.rank = rank; } @@ -67,7 +67,7 @@ } public int hashCode() { - return text.hashCode() ^ id.hashCode() * (rank + 34); + return text.hashCode() ^ id.hashCode() * ((int) rank + 34); } public String toString() { @@ -75,7 +75,7 @@ } public int compareTo(RegulationData regulationData) { - int comparison = Integer.valueOf(rank).compareTo(regulationData.rank); + int comparison = Double.valueOf(rank).compareTo(regulationData.rank); if (comparison == 0) { if (equals(regulationData)) { return comparison; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-04 16:16:48
|
Revision: 406 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=406&view=rev Author: alllee Date: 2009-12-04 16:16:38 +0000 (Fri, 04 Dec 2009) Log Message: ----------- setting group data model on enforcement mechanism update event. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 15:33:49 UTC (rev 405) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 16:16:38 UTC (rev 406) @@ -66,12 +66,6 @@ return groupDataModel.getActiveMonitor().getId(); } - private List<RegulationData> submittedRegulations; - - public void setSubmittedRegulations(List<RegulationData> regulations) { - this.submittedRegulations = regulations; - } - public boolean isSanctioningAllowed() { return getClientData().isSanctioningAllowed() || isSanctioningEnabled(); } @@ -290,4 +284,12 @@ public Set<Resource> getRemovedResources() { return groupDataModel.getRemovedResources(); } + + public void setActiveRegulation(RegulationData regulationData) { + groupDataModel.setActiveRegulation(regulationData); + } + + public RegulationData getActiveRegulation() { + return groupDataModel.getActiveRegulation(); + } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 15:33:49 UTC (rev 405) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 16:16:38 UTC (rev 406) @@ -30,6 +30,7 @@ import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; import edu.asu.commons.foraging.event.RegulationSubmissionUpdateEvent; +import edu.asu.commons.foraging.event.RegulationUpdateEvent; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; @@ -231,7 +232,8 @@ }); addEventProcessor(new EventTypeProcessor<EnforcementMechanismUpdateEvent>(EnforcementMechanismUpdateEvent.class) { public void handle(final EnforcementMechanismUpdateEvent event) { - gameWindow2D.displayActiveEnforcementMechanism(event.getActiveEnforcementMechanism()); + dataModel.setGroupDataModel(event.getGroupDataModel()); + gameWindow2D.displayActiveEnforcementMechanism(); } }); addEventProcessor(new EventTypeProcessor<RegulationSubmissionUpdateEvent>(RegulationSubmissionUpdateEvent.class) { @@ -240,6 +242,12 @@ gameWindow2D.initializeRegulationVotingPanel(); } }); + addEventProcessor(new EventTypeProcessor<RegulationUpdateEvent>(RegulationUpdateEvent.class) { + public void handle(final RegulationUpdateEvent event) { + dataModel.setActiveRegulation(event.getRegulationData()); + gameWindow2D.displayActiveRegulation(); + } + }); } public boolean canPerformRealTimeSanction() { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 15:33:49 UTC (rev 405) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 16:16:38 UTC (rev 406) @@ -51,8 +51,6 @@ import edu.asu.commons.foraging.event.SubmitRegulationRequest; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.Direction; -import edu.asu.commons.foraging.model.EnforcementMechanism; -import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; import edu.asu.commons.util.HtmlEditorPane; @@ -93,8 +91,6 @@ // FIXME: this shouldn't be public public static Duration duration; - private RegulationData votedRegulation; - private ChatPanel chatPanel; public final static String[] roleDescription = { @@ -771,10 +767,11 @@ addCenterComponent(instructionsScrollPane); } - public void displayActiveEnforcementMechanism(final EnforcementMechanism enforcementMechanism) { + public void displayActiveEnforcementMechanism() { SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsBuilder.append("<hr/><h2>Active enforcement mechanism</h2><hr/><p>").append(enforcementMechanism.getDescription()).append("</p>"); + instructionsBuilder.append("<hr/><h2>Active regulation</h2><hr/><p>").append(dataModel.getActiveRegulation()).append("</p>"); + instructionsBuilder.append("<hr/><h2>Active enforcement mechanism</h2><hr/><p>").append(dataModel.getActiveEnforcementMechanism().getDescription()).append("</p>"); setInstructions(instructionsBuilder.toString()); addCenterComponent(instructionsScrollPane); } @@ -786,12 +783,11 @@ addCenterComponent(instructionsScrollPane); } - public void displayVotedRegulation() { - //new code - // System.out.println("*****Inside display voting regulation"); + public void displayActiveRegulation() { SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getText()+".</b>"); + setInstructions( + "<h3>The following regulation received the most votes:</h3><pre>" + dataModel.getActiveRegulation() + "</pre>"); addCenterComponent(instructionsScrollPane); startRegulationDisplayTimer(); } @@ -841,8 +837,7 @@ } public void initializeEnforcementVotingPanel() { - //new code - // System.out.println("*****Inside initialize enforcement()"); + // TODO: revisit SwingUtilities.invokeLater(new Runnable() { public void run() { EnforcementPanel enforcementPanel = getEnforcementPanel(); @@ -857,8 +852,6 @@ public void initializeRegulationVotingPanel() { SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code - //System.out.println("*****Inside thread initialize votingPanel()"); RegulationPanel regulationPanel = updateRegulationVotingPanel(); addCenterComponent( regulationPanel ); //sanctioningPanel.startTimer(); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java 2009-12-04 15:33:49 UTC (rev 405) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java 2009-12-04 16:16:38 UTC (rev 406) @@ -2,7 +2,7 @@ package edu.asu.commons.foraging.event; import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.EnforcementMechanism; +import edu.asu.commons.foraging.model.GroupDataModel; import edu.asu.commons.net.Identifier; @@ -20,14 +20,16 @@ private static final long serialVersionUID = 5373346980670885924L; // FIXME: just send the entire group data model instead? - private EnforcementMechanism activeEnforcementMechanism; + private GroupDataModel groupDataModel; - public EnforcementMechanismUpdateEvent(Identifier id, EnforcementMechanism activeEnforcementMechanism) { - this.activeEnforcementMechanism = activeEnforcementMechanism; + public EnforcementMechanismUpdateEvent(Identifier id, GroupDataModel groupDataModel) { + super(id); + this.groupDataModel = groupDataModel; } - public EnforcementMechanism getActiveEnforcementMechanism() { - return activeEnforcementMechanism; - } + public GroupDataModel getGroupDataModel() { + return groupDataModel; + } + } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 15:33:49 UTC (rev 405) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 16:16:38 UTC (rev 406) @@ -142,13 +142,15 @@ public RegulationData generateRegulationRankings() { resetRegulationRankingCount(); - double[] regulationVotingTally = new double[submittedRegulations.size()]; + int numberOfRegulations = submittedRegulations.size(); + double[] regulationVotingTally = new double[numberOfRegulations]; Arrays.fill(regulationVotingTally, 0.0d); int maxRankingIndex = 0; double maxRankingValue = 0.0d; for (ClientData clientData : clients.values()) { int[] regulationRankings = clientData.getRegulationRankings(); - for (int index = 0; index < regulationRankings.length; index++) { + logger.info("client: " + clientData.getId() + " ranked regulations: "+ regulationRankings); + for (int index = 0; index < numberOfRegulations; index++) { regulationVotingTally[index] += rankToValue(regulationRankings[index]); if (regulationVotingTally[index] > maxRankingValue) { maxRankingValue = regulationVotingTally[index]; @@ -157,11 +159,19 @@ } } activeRegulation = submittedRegulations.get(maxRankingIndex); - logger.info("active regulation: " + activeRegulation.getText()); + logger.info("active regulation: " + activeRegulation.getText() + " max ranking value: " + maxRankingValue); return activeRegulation; } - public EnforcementMechanism generateEnforcementRankings() { + public RegulationData getActiveRegulation() { + return activeRegulation; + } + + public void setActiveRegulation(RegulationData activeRegulation) { + this.activeRegulation = activeRegulation; + } + + public EnforcementMechanism generateEnforcementRankings() { resetEnforcementRankingCount(); // FIXME: change to round config parameter instead? double[] enforcementVotingTally = new double[EnforcementMechanism.values().length]; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 15:33:49 UTC (rev 405) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 16:16:38 UTC (rev 406) @@ -447,7 +447,6 @@ for (Identifier id: group.getClientIdentifiers()) { transmit(new RegulationSubmissionUpdateEvent(id, group)); } - } private void sendRegulationRankingUpdate(GroupDataModel group) { @@ -460,7 +459,7 @@ private void sendEnforcementUpdate(GroupDataModel group) { EnforcementMechanism enforcementMechanism = group.generateEnforcementRankings(); for (Identifier id: group.getClientIdentifiers()) { - transmit(new EnforcementMechanismUpdateEvent(id, enforcementMechanism)); + transmit(new EnforcementMechanismUpdateEvent(id, group)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-04 15:33:59
|
Revision: 405 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=405&view=rev Author: alllee Date: 2009-12-04 15:33:49 +0000 (Fri, 04 Dec 2009) Log Message: ----------- adding voting instructions to enforcement and regulation panels Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 15:27:11 UTC (rev 404) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 15:33:49 UTC (rev 405) @@ -94,14 +94,16 @@ return this.enforcementText[index]; } - private JPanel getInstructionPanel(String instructions) + private JPanel getInstructionPanel() { JPanel instructionPanel = new JPanel(); + //instructionPanel.setBackground(color); instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); //create Text area and JSCroll pane for it + String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); JTextArea instructionText = new JTextArea(instructions,3,50); JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); @@ -121,7 +123,8 @@ if(i==4) color = new Color(255,255,153); return color; } - + + // FIXME: this is extremely inefficient, reimplement later private void updateVotingPanel(int currentActive){ int r,c,i; SixChoicePanel temp = null; @@ -169,7 +172,7 @@ votingPanel = new JPanel(); votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.add(getInstructionPanel("This is instruction panel")); + votingPanel.add(getInstructionPanel()); for(i=0; i < noOfEnforcements; i++) { @@ -222,7 +225,7 @@ votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); //add the instruction panel as the first panel in voting panel. - instructionsPanel = getInstructionPanel("This is instruction panel"); + instructionsPanel = getInstructionPanel(); votingPanel.add(instructionsPanel); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 15:27:11 UTC (rev 404) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 15:33:49 UTC (rev 405) @@ -200,7 +200,7 @@ votingPanel = new JPanel(); votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.add(getInstructionPanel("This is instruction panel")); + votingPanel.add(getInstructionPanel()); for(i=0; i < noOfRegulations; i++) { @@ -275,7 +275,7 @@ votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); //add the instruction panel as the first panel in voting panel. - instructionsPanel = getInstructionPanel("This is instruction panel"); + instructionsPanel = getInstructionPanel(); votingPanel.add(instructionsPanel); // this is for dummy regulation data for testing @@ -349,12 +349,14 @@ add(buttonPanel, BorderLayout.SOUTH); } - private JPanel getInstructionPanel(String instructions) + private JPanel getInstructionPanel() { JPanel instructionPanel = new JPanel(); //instructionPanel.setBackground(color); instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); + + String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); //create Text area and JSCroll pane for it Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 15:27:11 UTC (rev 404) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 15:33:49 UTC (rev 405) @@ -83,6 +83,7 @@ return ( isPracticeRound() && isPrivateProperty() ) || getBooleanProperty("randomize-group", false); } + /** * Returns the number of seconds that the flashing visualization of * sanctioning should occur. @@ -241,6 +242,10 @@ return getProperty("regulation-instructions"); } + public String getVotingInstructions() { + return getProperty("voting-instructions", "You may rank the below options from 1 to 5, where 1 is the most favorable and 5 is the least favorable. When you rank a given option it will be sorted automatically."); + } + public String getLastRoundDebriefing() { return getProperty("last-round-debriefing"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
Revision: 404 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=404&view=rev Author: alllee Date: 2009-12-04 15:27:11 +0000 (Fri, 04 Dec 2009) Log Message: ----------- improving instructions Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml 2009-12-04 10:08:41 UTC (rev 403) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml 2009-12-04 15:27:11 UTC (rev 404) @@ -81,21 +81,19 @@ <h3>Regulation Instructions</h3> <hr> <p> -Below you can provide your regulation that you want to be conducted during the -next round. Please type in your regulation in the text box provided below. +You may now propose a regulation that you wish to have in place during the +round. After all participants in your group have submitted a regulation you +will be able to vote for a regulation by ranking it from 1 to 5, where 1 is +the most favorable and 5 is the least favorable. </p> -<p> -Once you propose your regulation and submit it, you will be able to see all the -regulations proposed by the other participants and vote them. -</p> <ul> -<li>Proposing the regulation is mandatory. -<li>You have 60 seconds to propose your regulation. -<li>You can write your regulation and submit it before time. -<li>Your regulation will be submitted automatically once the time ends. +<li>You have 60 seconds to propose a regulation.</li> +<li>Enter your regulation in the text area below. It will be submitted +automatically once the time ends.</li> </ul> ]]> </entry> + <entry key="chat-instructions"> <![CDATA[ <p> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml 2009-12-04 10:08:41 UTC (rev 403) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml 2009-12-04 15:27:11 UTC (rev 404) @@ -39,21 +39,19 @@ <h3>Regulation Instructions</h3> <hr> <p> -Below you can provide your regulation that you want to be conducted during the -next round. Please type in your regulation in the text box provided below. +You may now propose a regulation that you wish to have in place during the +round. After all participants in your group have submitted a regulation you +will be able to vote for a regulation by ranking it from 1 to 5, where 1 is +the most favorable and 5 is the least favorable. </p> -<p> -Once you propose your regulation and submit it, you will be able to see all the -regulations proposed by the other participants and vote them. -</p> <ul> -<li>Proposing the regulation is mandatory. -<li>You have 60 seconds to propose your regulation. -<li>You can write your regulation and submit it before time. -<li>Your regulation will be submitted automatically once the time ends. +<li>You have 60 seconds to propose a regulation.</li> +<li>Enter your regulation in the text area below. It will be submitted +automatically once the time ends.</li> </ul> ]]> </entry> + <entry key="chat-instructions"> <![CDATA[ <p> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml 2009-12-04 10:08:41 UTC (rev 403) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml 2009-12-04 15:27:11 UTC (rev 404) @@ -33,51 +33,8 @@ <h3>Round 4 Instructions</h3> <hr> <p> -This round is the same as the previous round with two exceptions: +This round is the same as previous rounds. </p> -<ol> -<li> -Before the next round starts you can anonymously communicate by text messages -for four minutes with the other participants in your group. You can use this -opportunity to discuss the experiment and coordinate your actions to improve -your earnings. You may not promise side-payments after the experiment is -completed or make any threats. You are also not allowed to reveal your real -identity. We are monitoring the chat traffic while you chat. -</li> -<li> -During the next round you will have the option to reduce the earnings of another -participant at a cost to your own earnings with constraints depending on the type -of enforcement mechanism used. Below are the 4 types of enforcement mechanisms that -you have to vote later in the round. -<ol> -<li><b> Everyone can harvest but no sanctioning </b> -<p>In this type all players can harvest but no can sanction or reduce any other -player's tokens</p> -<li><b> Everyone can harvest as well as sanction </b> -<p>Each time you press the numeric keys between 1-5 the number of tokens of the -corresponding participant is reduced by <b>2</b> with a penalty of <b>1</b> to -yourself.</p> -<p>When you reduce the number of tokens of another participant, they will -receive a message stating that you have reduced their tokens. Likewise, if -another participant reduces your number of tokens, you will also receive a -message. These messages will be displayed on the bottom of your screen.</p> - -<li><b> Randomly picked monitor </b> -<p>Randomly one of the participants is selected to be the monitoring agent -This participant can not harvest, but can force another participant to pay -<b>1</b> token to the monitoring participant by pressing the responding -numeric key</p> -<p>At the end of the round each participant who could harvest pays 25% of -the earning to the monitoring participant.</p> - -<li><b> Round Robin monitoring </b> -<p>One participant is assigned the role of the monitor for a period of 48 secs -and others can only harvest. So same rules apply as for the mechanism two. </p> -<p> This continues with each participant getting the chance to be a monitor for -48 secs </p> -</ol> -</li> -</ol> ]]> </entry> @@ -86,22 +43,20 @@ <h3>Regulation Instructions</h3> <hr> <p> -Below you can provide your regulation that you want to be conducted during the -next round. Please type in your regulation in the text box provided below. +You may now propose a regulation that you wish to have in place during the +round. After all participants in your group have submitted a regulation you +will be able to vote for a regulation by ranking from from 1 to 5, where 1 is +the most favorable and 5 is the least favorable. </p> -<p> -Once you propose your regulation and submit it, you will be able to see all the -regulations proposed by the other participants and vote them. -</p> <ul> -<li>Proposing the regulation is mandatory. -<li>You have 60 seconds to propose your regulation. -<li>You can write your regulation and submit it before time. -<li>Your regulation will be submitted automatically once the time ends. +<li>You have 60 seconds to propose a regulation.</li> +<li>Enter your regulation in the text area below. It will be submitted +automatically once the time ends.</li> </ul> ]]> </entry> + <entry key="chat-instructions"> <![CDATA[ <p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
Revision: 403 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=403&view=rev Author: alllee Date: 2009-12-04 10:08:41 +0000 (Fri, 04 Dec 2009) Log Message: ----------- fixing some speling errors in the configuration instructions Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml 2009-12-04 10:07:58 UTC (rev 402) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml 2009-12-04 10:08:41 UTC (rev 403) @@ -25,12 +25,96 @@ <h3>Round 2 Instructions</h3> <hr> <p> -Round 2 is the same as round 1. +This round is the same as the previous round with two exceptions: </p> +<ol> +<li> +Before the next round starts you can anonymously communicate by text messages +for four minutes with the other participants in your group. You can use this +opportunity to discuss the experiment and coordinate your actions to improve +your earnings. You may not promise side-payments after the experiment is +completed or make any threats. You are also not allowed to reveal your real +identity. We are monitoring the chat traffic while you chat. +</li> +<li> +During the next round you will have the option to reduce the earnings of another +participant at a cost to your own earnings with constraints depending on the type +of enforcement mechanism used. Below are the 4 types of enforcement mechanisms that +you have to vote later in the round. +<ol> +<li><b> Everyone can harvest but no sanctioning </b> +<p>In this type all players can harvest but no can sanction or reduce any other +player's tokens</p> +<li><b> Everyone can harvest as well as sanction </b> +<p>Each time you press the numeric keys between 1-5 the number of tokens of the +corresponding participant is reduced by <b>2</b> with a penalty of <b>1</b> to +yourself.</p> +<p>When you reduce the number of tokens of another participant, they will +receive a message stating that you have reduced their tokens. Likewise, if +another participant reduces your number of tokens, you will also receive a +message. These messages will be displayed on the bottom of your screen.</p> + +<li><b> Randomly picked monitoring </b> +<p>Randomly one of the participants is selected to be the monitoring agent +This participant can not harvest, but can force another participant to pay +<b>1</b> token to the monitoring participant by pressing the responding +numeric key</p> +<p>At the end of the round each participant who could harvest pays 25% of +the earning to the monitoring participant.</p> + +<li><b> Round Robin monitoring </b> +<p>One participant is assigned the role of the monitor for a period of 48 secs +and others can only harvest. So same rules apply as for the mechanism two. </p> +<p> This continues with each participant getting the chance to be a monitor for +48 secs </p> +</ol> +</li> +</ol> <p> If you have any questions please raise your hand. <b>Do you have any questions so far?</b> </p> ]]> </entry> +<entry key="regulation-instructions"> +<![CDATA[ +<h3>Regulation Instructions</h3> +<hr> +<p> +Below you can provide your regulation that you want to be conducted during the +next round. Please type in your regulation in the text box provided below. +</p> +<p> +Once you propose your regulation and submit it, you will be able to see all the +regulations proposed by the other participants and vote them. +</p> +<ul> +<li>Proposing the regulation is mandatory. +<li>You have 60 seconds to propose your regulation. +<li>You can write your regulation and submit it before time. +<li>Your regulation will be submitted automatically once the time ends. +</ul> +]]> +</entry> +<entry key="chat-instructions"> +<![CDATA[ +<p> +You can now chat with the other participants in your group for 4 minutes +total. During the chat round, you may communicate about any aspect of the +experiment that you would like to discuss with other participants with whom +you have been matched. You may not promise them side-payments after the +experiment is completed or threaten them with any consequence after the +experiment is finished. We are monitoring the chat traffic while you chat. If +we see that somebody reveals his or her identity, we have to stop the +experiment and remove the whole group from which this person is a member out +of this room. +</p> +<p> +You will see other participants labeled as "1", "2","3", "4", or "5" in the +chat box. You can send a chat message by typing into the textfield at the +bottom of the screen and clicking the "send" button with your mouse or +pressing the "enter" key on your keyboard. +</p> +]]> +</entry> </properties> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml 2009-12-04 10:07:58 UTC (rev 402) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml 2009-12-04 10:08:41 UTC (rev 403) @@ -34,4 +34,46 @@ </p> ]]> </entry> +<entry key="regulation-instructions"> +<![CDATA[ +<h3>Regulation Instructions</h3> +<hr> +<p> +Below you can provide your regulation that you want to be conducted during the +next round. Please type in your regulation in the text box provided below. +</p> +<p> +Once you propose your regulation and submit it, you will be able to see all the +regulations proposed by the other participants and vote them. +</p> +<ul> +<li>Proposing the regulation is mandatory. +<li>You have 60 seconds to propose your regulation. +<li>You can write your regulation and submit it before time. +<li>Your regulation will be submitted automatically once the time ends. +</ul> +]]> +</entry> +<entry key="chat-instructions"> +<![CDATA[ +<p> +You can now chat with the other participants in your group for 4 minutes +total. During the chat round, you may communicate about any aspect of the +experiment that you would like to discuss with other participants with whom +you have been matched. You may not promise them side-payments after the +experiment is completed or threaten them with any consequence after the +experiment is finished. We are monitoring the chat traffic while you chat. If +we see that somebody reveals his or her identity, we have to stop the +experiment and remove the whole group from which this person is a member out +of this room. +</p> +<p> +You will see other participants labeled as "1", "2","3", "4", or "5" in the +chat box. You can send a chat message by typing into the textfield at the +bottom of the screen and clicking the "send" button with your mouse or +pressing the "enter" key on your keyboard. +</p> +]]> +</entry> + </properties> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml 2009-12-04 10:07:58 UTC (rev 402) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml 2009-12-04 10:08:41 UTC (rev 403) @@ -33,23 +33,23 @@ <h3>Round 4 Instructions</h3> <hr> <p> -Round 4 is the same as the previous two rounds with two exceptions. +This round is the same as the previous round with two exceptions: </p> -<p> +<ol> +<li> Before the next round starts you can anonymously communicate by text messages for four minutes with the other participants in your group. You can use this opportunity to discuss the experiment and coordinate your actions to improve your earnings. You may not promise side-payments after the experiment is completed or make any threats. You are also not allowed to reveal your real identity. We are monitoring the chat traffic while you chat. -</p> -<p> +</li> +<li> During the next round you will have the option to reduce the earnings of another participant at a cost to your own earnings with constraints depending on the type of enforcement mechanism used. Below are the 4 types of enforcement mechanisms that you have to vote later in the round. -</p> -<ul> +<ol> <li><b> Everyone can harvest but no sanctioning </b> <p>In this type all players can harvest but no can sanction or reduce any other player's tokens</p> @@ -62,7 +62,7 @@ another participant reduces your number of tokens, you will also receive a message. These messages will be displayed on the bottom of your screen.</p> -<li><b> Randomly picked monitering </b> +<li><b> Randomly picked monitor </b> <p>Randomly one of the participants is selected to be the monitoring agent This participant can not harvest, but can force another participant to pay <b>1</b> token to the monitoring participant by pressing the responding @@ -70,12 +70,14 @@ <p>At the end of the round each participant who could harvest pays 25% of the earning to the monitoring participant.</p> -<li><b> Round Robin monitering </b> -<p>One participant is assigned the role of the moniter for a period of 48 secs +<li><b> Round Robin monitoring </b> +<p>One participant is assigned the role of the monitor for a period of 48 secs and others can only harvest. So same rules apply as for the mechanism two. </p> -<p> This continues with each participant getting the chance to be a moniter for +<p> This continues with each participant getting the chance to be a monitor for 48 secs </p> -</ul> +</ol> +</li> +</ol> ]]> </entry> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-04 10:08:07
|
Revision: 402 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=402&view=rev Author: alllee Date: 2009-12-04 10:07:58 +0000 (Fri, 04 Dec 2009) Log Message: ----------- regulation rankings are now kind of showing up, still buggy. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java 2009-12-04 10:07:58 UTC (rev 402) @@ -102,7 +102,7 @@ add(targetHandlePanel, BorderLayout.NORTH); add(chatField, BorderLayout.CENTER); - add(sendButton, BorderLayout.SOUTH); +// add(sendButton, BorderLayout.SOUTH); setChatFieldFocus(); } @@ -199,6 +199,7 @@ setName("Chat panel"); messageWindow = new JTextPane(); messageWindow.setEditable(false); + messageWindow.setBackground(Color.WHITE); messageScrollPane = new JScrollPane(messageWindow); addStylesToMessageWindow(); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 10:07:58 UTC (rev 402) @@ -66,8 +66,10 @@ return groupDataModel.getActiveMonitor().getId(); } - public void setRegulation(String regulation) { - + private List<RegulationData> submittedRegulations; + + public void setSubmittedRegulations(List<RegulationData> regulations) { + this.submittedRegulations = regulations; } public boolean isSanctioningAllowed() { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 10:07:58 UTC (rev 402) @@ -166,23 +166,6 @@ state = ClientState.RUNNING; } }); - -// addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { -// public void handle(NewClientRole event) { -// Identifier receivedClientId = event.getRoleObj().getClientId(); -// //System.out.println("Broadcast ID : "+receivedClientId); -// if(dataModel.getId().equals(receivedClientId)) { -// int[] roles = event.getRoleObj().getClientRoles(); -// //System.out.println("Setting my role"); -// dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); -// dataModel.setMonitorId(event.getRoleObj().getMoniterId()); -// //System.out.println("New role for the client : "+dataModel.getMyRole()); -// gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); -// -// // Utils.notify(GameWindow2D.clientRoleSignal); -// } -// } -// }); addEventProcessor(new EventTypeProcessor<EndRoundEvent>(EndRoundEvent.class) { public void handle(final EndRoundEvent event) { @@ -247,23 +230,14 @@ } }); addEventProcessor(new EventTypeProcessor<EnforcementMechanismUpdateEvent>(EnforcementMechanismUpdateEvent.class) { - public void handle(final EnforcementMechanismUpdateEvent enforcementEvent) { -// -// enforcements = enforcementEvent.getAllEnforcements(); -// System.out.println("Enforcement received : "+enforcements.size()); -// noOfEnforcements = enforcements.size(); -// for (Identifier targetId : enforcements.keySet()) { -// votedEnforcement = enforcements.get(targetId); -// } -// displayVotedEnforcement(); - // FIXME: implement me. - gameWindow2D.displayVotedEnforcement(); + public void handle(final EnforcementMechanismUpdateEvent event) { + gameWindow2D.displayActiveEnforcementMechanism(event.getActiveEnforcementMechanism()); } }); addEventProcessor(new EventTypeProcessor<RegulationSubmissionUpdateEvent>(RegulationSubmissionUpdateEvent.class) { - public void handle(final RegulationSubmissionUpdateEvent regulationEvent) { + public void handle(final RegulationSubmissionUpdateEvent event) { + dataModel.setGroupDataModel(event.getGroupDataModel()); gameWindow2D.initializeRegulationVotingPanel(); - } }); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 10:07:58 UTC (rev 402) @@ -22,16 +22,16 @@ import java.util.Map; import java.util.Properties; +import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; -import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.JTextPane; import javax.swing.SwingUtilities; import javax.swing.Timer; -import javax.swing.UIManager; import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; @@ -48,8 +48,10 @@ import edu.asu.commons.foraging.event.QuizCompletedEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; +import edu.asu.commons.foraging.event.SubmitRegulationRequest; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.Direction; +import edu.asu.commons.foraging.model.EnforcementMechanism; import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; @@ -78,7 +80,7 @@ private Component currentCenterComponent; - private JScrollPane instructionsScrollPane; + private JScrollPane instructionsScrollPane; private HtmlEditorPane instructionsEditorPane; @@ -86,18 +88,17 @@ private JScrollPane errorMessageScrollPane; private JTextPane errorMessageTextPane; - private JPanel regulationVotingPane; - private JPanel labelPanel; + // FIXME: this shouldn't be public public static Duration duration; private RegulationData votedRegulation; private ChatPanel chatPanel; - public static String roleDescription [] = { - "Moniter: You cannot harvest but can sanction other participants\n" + + public final static String[] roleDescription = { + "Monitor: You cannot harvest but can sanction other participants\n" + "To sanction press numbers from 1-5. At the end of the round you\n" + "will receive 25% tokens from every other participant", "Harvest: You can collect tokens as in earlier rounds. But you \n" + @@ -116,8 +117,6 @@ private JPanel subjectWindow; - private JEditorPane regulationVotingIntructions; - private ForagingClient client; private SubjectView subjectView; @@ -239,53 +238,15 @@ subjectView.collectToken(position); } - private void startEnforcementDisplayTimer(){ - - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementDisplayDuration()); - - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - if (duration.hasExpired()) { - timeLeftLabel.setText("Round begins now."); - - //new code - //Need to add the enforcementVotingPane over here - //instead of the instructionsScrollPane - timer.stop(); - timer = null; - remove(enforcementPanel); - // System.out.println("Enforcement Panel removed : New Pane added"); - addCenterComponent(instructionsScrollPane); - - } - else { - timeLeftLabel.setText( String.format("Voting for the enforcement mechanism will start in %d seconds.", duration.getTimeLeft() / 1000L) ); - } - } - }); - timer.start(); - } - } - private void startRegulationDisplayTimer(){ if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationDisplayDuration()); - timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { - timeLeftLabel.setText("Enforcement Voting begins now."); - - //new code - //Need to add the enforcementVotingPane over here - //instead of the instructionsScrollPane + timeLeftLabel.setText("Regulation voting will start soon."); timer.stop(); timer = null; - //remove(sanctioningPanel); - // System.out.println("New Pane added"); initializeEnforcementVotingPanel(); } else { @@ -301,36 +262,15 @@ if (timer == null) { //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementVotingDuration()); - + duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementVotingDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { - timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); - - //new code - //Need to add the enforcementVotingPane over here - //instead of the instructionsScrollPane + timeLeftLabel.setText("Voting is now disabled."); timer.stop(); timer = null; - //remove(sanctioningPanel); - //getEnforcementPanel().stopTimer(); - getEnforcementPanel().sendEnforcementVotes(); - //displayEnforcementWaitMessage(); - - System.out.println("Enforcement voting sent"); - -// Utils.waitOn(enforcementVotesSignal); - -// System.out.println("Voted enforcement received"); - - //Utils.waitOn(clientRoleSignal); - - // System.out.println("Client Role received"); - - - - // System.out.println("New Pane added"); + getEnforcementPanel().sendEnforcementVotes(); + displayVotingWaitMessage(); } else { timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -345,7 +285,6 @@ private void startRegulationVotingTimer() { if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingtDuration()); timer = new Timer(1000, new ActionListener() { @@ -360,15 +299,8 @@ timer = null; //remove(sanctioningPanel); //getSanctioningPanel().stopTimer(); - getRegulationPanel().sendRegulationVotes(); - System.out.println("Regulation voting sent"); - //displayRegulationWaitMessage(); -// Utils.waitOn(regulationVotesSignal); -// System.out.println("Voted regulation received"); - - - - //System.out.println("New Pane added"); + getRegulationPanel().sendRegulationVotes(); + displayVotingWaitMessage(); } else { timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -382,27 +314,19 @@ private void startRegulationSubmissionTimer() { if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationSubmissionDuration()); + duration = Duration.create(dataModel.getRoundConfiguration().getRegulationSubmissionDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { - timeLeftLabel.setText("Your time to write the regulation is finished. Next round begins shortly."); - //new code - //FIXME: - //Need to add the regulationVotingPane over here - //instead of the instructionsScrollPane - //Need to create new client request to send the sanction information - //client.transmit(); - //addCenterComponent(instructionsScrollPane); - //addCenterComponent(regulationVotingPane); + timeLeftLabel.setText("Time's up."); timer.stop(); timer = null; - getRegulationPanel().sendRegulation(); -// Utils.waitOn(regulationSignal); + String regulation = regulationTextArea.getText(); + client.transmit(new SubmitRegulationRequest(client.getId(), regulation)); + displayVotingWaitMessage(); } else { - timeLeftLabel.setText( String.format("You have %d seconds left to write your regualtion", duration.getTimeLeft() / 1000L) ); + timeLeftLabel.setText( String.format("You have %d second(s) left to write your regulation.", duration.getTimeLeft() / 1000L) ); } } }); @@ -413,21 +337,13 @@ if (timer == null) { // final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); - timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { - timeLeftLabel.setText("Chat is now disabled. Next round begins shortly."); - - //new code - //Need to add the regulationVotingPane over here - //instead of the instructionsScrollPane - //addCenterComponent(instructionsScrollPane); + timeLeftLabel.setText("Chat is now disabled."); timer.stop(); timer = null; - initializeRegulationPanel(); - } else { timeLeftLabel.setText( String.format("Chat will end in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -484,16 +400,10 @@ final HtmlEditorPane htmlPane = new HtmlEditorPane(); htmlPane.setPreferredSize(new Dimension(400, 400)); htmlPane.setEditable(false); + htmlPane.setBackground(Color.WHITE); htmlPane.setFont(new Font("sansserif", Font.PLAIN, 12)); return htmlPane; } - public static void setNativeLookAndFeel() { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch(Exception e) { - // System.out.println("Error setting native LAF: " + e); - } - } private RegulationPanel updateRegulationVotingPanel(){ RegulationPanel regulationPanel = getRegulationPanel(); @@ -552,6 +462,7 @@ errorMessageTextPane = new JTextPane(); errorMessageTextPane.setEditable(false); errorMessageTextPane.setFont(new Font("arial", Font.BOLD, 12)); + errorMessageTextPane.setBackground(Color.WHITE); addStyles(errorMessageTextPane.getStyledDocument()); @@ -600,6 +511,7 @@ public void keyReleased(KeyEvent keyEvent) { keyReleased = true; } + // FIXME: refactor this method if possible. @Override public void keyPressed(KeyEvent keyEvent) { int keyChar = (int) keyEvent.getKeyChar(); @@ -615,9 +527,9 @@ if(dataModel.isHarvestingAllowed()) { event = new CollectTokenRequest(client.getId()); } - else - displayErrorMessage("You are either a Moniter or Sanctioner : You cannot harvest ", 1); - + else { + displayErrorMessage("You cannot harvest at this time.", 1); + } break; // real-time sanctioning keycode handling case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: @@ -644,8 +556,9 @@ // below function must be used for enforcement type4 dataModel.sanction(dataModel.getId(), sanctionee); } - else{ + else { displayErrorMessage("The participant is out of range ", 1); + return; } } break; @@ -858,46 +771,21 @@ addCenterComponent(instructionsScrollPane); } - public void displayVotedEnforcement(){ - // TODO: reimplement - SwingUtilities.invokeLater(new Runnable() { + public void displayActiveEnforcementMechanism(final EnforcementMechanism enforcementMechanism) { + SwingUtilities.invokeLater(new Runnable() { public void run() { + instructionsBuilder.append("<hr/><h2>Active enforcement mechanism</h2><hr/><p>").append(enforcementMechanism.getDescription()).append("</p>"); + setInstructions(instructionsBuilder.toString()); addCenterComponent(instructionsScrollPane); - startEnforcementDisplayTimer(); } }); } - public void displayRegulationWaitMessage(){ - //new code - // System.out.println("*****Inside reg wait mesg"); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - instructionsEditorPane.setText("Message from the System:<br><br>" + - "<b>Please wait until the System receives votes from all players.System<br>"+ - "will calculate the result of the voting and display it in a moment</b>"); - remove(regulationPanel); - addCenterComponent(instructionsScrollPane); - } - }); + private void displayVotingWaitMessage() { + setInstructions("<h3>Please wait while we finish collecting information from all the participants.</h3>"); + addCenterComponent(instructionsScrollPane); } - public void displayEnforcementWaitMessage(){ - //new code - System.out.println("*****Inside enfr wait message"); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - instructionsEditorPane.setText("Message from the System:<br><br>" + - "<b>Please wait until the System receives votes from all players.System<br>"+ - "will calculate the result of the voting and display it in a moment</b>"); - remove(enforcementPanel); - addCenterComponent(instructionsScrollPane); - } - }); - } - - - public void displayVotedRegulation() { //new code // System.out.println("*****Inside display voting regulation"); @@ -967,8 +855,6 @@ public void initializeRegulationVotingPanel() { - //new code - // System.out.println("*****Inside initialize regulation votingPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { //new code @@ -982,17 +868,27 @@ } public void initializeRegulationPanel() { - //new code - SwingUtilities.invokeLater(new Runnable() { - public void run() { - getRegulationPanel().initialize(); - // System.out.println("Initialization done"); - //remove( messagePanel ); - addCenterComponent(getRegulationPanel()); - startRegulationSubmissionTimer(); - } - }); +// getRegulationPanel().initialize(); + // System.out.println("Initialization done"); + addCenterComponent(getSubmitRegulationPanel()); + startRegulationSubmissionTimer(); } + + private JPanel submitRegulationPanel; + private JTextArea regulationTextArea; + private JPanel getSubmitRegulationPanel() { + if (submitRegulationPanel == null) { + submitRegulationPanel = new JPanel(new BorderLayout()); + regulationTextArea = new JTextArea(); + submitRegulationPanel.add(regulationTextArea, BorderLayout.CENTER); + regulationTextArea.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); + HtmlEditorPane editorPane = createInstructionsEditorPane(); + JScrollPane scrollPane = new JScrollPane(editorPane); + editorPane.setText(dataModel.getRoundConfiguration().getRegulationInstructions()); + submitRegulationPanel.add(scrollPane, BorderLayout.PAGE_START); + } + return submitRegulationPanel; + } public void initializeChatPanel() { //new code Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 10:07:58 UTC (rev 402) @@ -39,6 +39,8 @@ * * Sanctioning panel is used to create regulations and * enforcement mechanism + * + * FIXME: split this functionality out into two different panels, one for submission and the other for voting. * * @author dbarge * @version $Revision: 45 $ @@ -91,7 +93,7 @@ private int[] currentRankingInformation; - private SixChoicePanel newPanel[]; + private SixChoicePanel[] newPanel; private JPanel votingPanel; private JPanel instructionsPanel; @@ -231,21 +233,6 @@ this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); } - /* - for(i=0 ; i<5 ; i++) - { - System.out.println(currentRankingInformation[i]); - } - */ - -// RegulationData regulationData = new RegulationData(); -// regulationData.setCurrentRankingInformation(this.currentRankingInformation); -// regulationData.setRegulationText(message); -// regulationData.setVotingFlag(true); -// -// // System.out.println("ID:"+client.getRegulationID()); -// regulationData.setRegulationID(client.getRegulationID()); - client.transmit(new RegulationRankingRequest(client.getId(), currentRankingInformation)); } @@ -273,8 +260,12 @@ public void initRegulationVotingComponents(){ - remove(regulationsInstructionsScrollPane); - remove(messageScrollPane); + if (regulationsInstructionsScrollPane != null) { + remove(regulationsInstructionsScrollPane); + } + if (messageScrollPane != null) { + remove(messageScrollPane); + } this.currentRankingInformation = new int[5]; this.newPanel = new SixChoicePanel[5]; setBackground(Color.lightGray); @@ -310,7 +301,7 @@ // String s = sb.toString(); newPanel[i] = new SixChoicePanel(regulationData.getText(), votes, regulationData.getIndex(), getColor(i)); // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); - votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); + votingPanel.add(newPanel[i].getRegulationPanel(i,regulationData.getText())); i++; } @@ -374,7 +365,8 @@ return instructionPanel; } - private void initGuiComponents() { + + public void initialize() { setLayout(new BorderLayout(4, 4)); messageWindow = new JTextPane(); messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); @@ -395,9 +387,9 @@ //dummy regulation instructions are //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); - regulationsInstructionsPane.setText("Test regulation instructions...."); - //add(regulationsInstructionsScrollPane, BorderLayout.NORTH); - //add(messageScrollPane, BorderLayout.CENTER); + regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); + add(regulationsInstructionsScrollPane, BorderLayout.NORTH); + add(messageScrollPane, BorderLayout.CENTER); } @@ -405,10 +397,6 @@ participants.clear(); } - public void initialize() { - // System.out.println("Calling init GUI components"); - initGuiComponents(); - } private class SixChoicePanel implements ActionListener{ //String title; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 10:07:58 UTC (rev 402) @@ -274,7 +274,7 @@ } public int getChatDuration() { - return getIntProperty("chat-duration", 30); + return getIntProperty("chat-duration", 10); } public int getRegulationSubmissionDuration() { @@ -294,7 +294,7 @@ } public int getEnforcementDisplayDuration() { - return getIntProperty("enforcement-display-duration", 60); + return getIntProperty("enforcement-display-duration", 30); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java 2009-12-04 10:07:58 UTC (rev 402) @@ -1,10 +1,8 @@ //package edu.asu.commons.event; package edu.asu.commons.foraging.event; -import java.util.List; - import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.RegulationData; +import edu.asu.commons.foraging.model.GroupDataModel; import edu.asu.commons.net.Identifier; @@ -21,15 +19,15 @@ private static final long serialVersionUID = 475300882222383637L; - private List<RegulationData> submittedRegulations; + private GroupDataModel groupDataModel; - public RegulationSubmissionUpdateEvent(Identifier id, List<RegulationData> submittedRegulations) { + public RegulationSubmissionUpdateEvent(Identifier id, GroupDataModel groupDataModel) { super(id); - this.submittedRegulations = submittedRegulations; + this.groupDataModel = groupDataModel; } - public List<RegulationData> getSubmittedRegulations() { - return submittedRegulations; + public GroupDataModel getGroupDataModel() { + return groupDataModel; } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 08:56:49 UTC (rev 401) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 10:07:58 UTC (rev 402) @@ -445,7 +445,7 @@ private void sendRegulationUpdate(GroupDataModel group) { for (Identifier id: group.getClientIdentifiers()) { - transmit(new RegulationSubmissionUpdateEvent(id, group.getSubmittedRegulations())); + transmit(new RegulationSubmissionUpdateEvent(id, group)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-04 08:56:59
|
Revision: 401 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=401&view=rev Author: alllee Date: 2009-12-04 08:56:49 +0000 (Fri, 04 Dec 2009) Log Message: ----------- removing defunct EnforcementData Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java Removed Paths: ------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementData.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 08:31:29 UTC (rev 400) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 08:56:49 UTC (rev 401) @@ -71,7 +71,7 @@ } public boolean isSanctioningAllowed() { - return getClientData().isSanctioningAllowed(); + return getClientData().isSanctioningAllowed() || isSanctioningEnabled(); } public boolean isHarvestingAllowed() { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 08:31:29 UTC (rev 400) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 08:56:49 UTC (rev 401) @@ -20,7 +20,6 @@ import javax.swing.ScrollPaneConstants; import edu.asu.commons.foraging.event.EnforcementRankingRequest; -import edu.asu.commons.foraging.model.EnforcementData; import edu.asu.commons.net.Identifier; /** @@ -86,12 +85,6 @@ private JPanel buttonPanel; - private EnforcementData votedEnforcement; - - - public EnforcementData getVotedEnforcement(){ - return this.votedEnforcement; - } public EnforcementPanel () { newPanel = new SixChoicePanel[4]; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 08:31:29 UTC (rev 400) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 08:56:49 UTC (rev 401) @@ -34,7 +34,6 @@ import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; -import edu.asu.commons.foraging.model.EnforcementData; import edu.asu.commons.util.Duration; import edu.asu.commons.util.Utils; @@ -269,22 +268,11 @@ }); } - public boolean canPerformRealTimeSanction(EnforcementData votedEnforcement) { - //System.out.println("Result index"+votedEnforcement.getResultIndex()); - if(votedEnforcement.getResultIndex() == 2 || votedEnforcement.getResultIndex() == 3) - return dataModel.getRoundConfiguration().isRealTimeSanctioningEnabled() && dataModel.getCurrentTokens() >= 0; - else - return dataModel.getRoundConfiguration().isRealTimeSanctioningEnabled() && dataModel.getCurrentTokens() > 0; + public boolean canPerformRealTimeSanction() { + return dataModel.isMonitor() + || (dataModel.isSanctioningAllowed() && dataModel.getCurrentTokens() > 0); } - public boolean isSanctioningAllowed() { - return dataModel.isSanctioningAllowed(); - } - - public boolean isHarvestingAllowed(){ - return dataModel.isHarvestingAllowed(); - } - public void transmit(PostRoundSanctionRequest request) { if (state == ClientState.WAITING) { //System.out.println("Sending post round sanction request"); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 08:31:29 UTC (rev 400) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 08:56:49 UTC (rev 401) @@ -612,7 +612,7 @@ switch (keyCode) { // token request handling case KeyEvent.VK_SPACE: - if(client.isHarvestingAllowed()) { + if(dataModel.isHarvestingAllowed()) { event = new CollectTokenRequest(client.getId()); } else @@ -623,17 +623,12 @@ case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: - - // System.out.println("Key pressed : "+(keyChar-48)); - //if(dataModel.getRoundConfiguration().isChatEnabled() == false) { - //return; - //} - if(dataModel.getRoundConfiguration().isSanctioningEnabled() == false) { + if (! dataModel.isSanctioningAllowed()) { + // get rid of magic constants + displayErrorMessage("You aren't allowed to reduce other participants tokens at this time.", 1); return; } - - - if (client.isSanctioningAllowed() && client.canPerformRealTimeSanction(getEnforcementPanel().getVotedEnforcement())) { + if (client.canPerformRealTimeSanction()) { //System.out.println("Can do sanctioning"); int assignedNumber = keyChar - 48; Identifier sanctionee = dataModel.getClientId(assignedNumber); @@ -650,16 +645,9 @@ dataModel.sanction(dataModel.getId(), sanctionee); } else{ - displayErrorMessage("Sanctionee is out of range ", 1); + displayErrorMessage("The participant is out of range ", 1); } } - else - { - if(client.isSanctioningAllowed()==false){ - displayErrorMessage("You don't have the privilege to sanction",1); - } - return; - } break; // reset token distribution request handling case KeyEvent.VK_R: Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-04 08:31:29 UTC (rev 400) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-04 08:56:49 UTC (rev 401) @@ -199,14 +199,7 @@ } } else { - if (id.equals(dataModel.getMonitorId()) && dataModel.isSanctioningEnabled()) { - //System.out.println("Is a moniter image"); - graphics2D.drawImage(scaledMoniterImage, x, y, this); - } - else { - //System.out.println("Is a other image"); - graphics2D.drawImage(scaledOtherSubjectImage, x, y, this); - } + graphics2D.drawImage(scaledOtherSubjectImage, x, y, this); } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 08:31:29 UTC (rev 400) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 08:56:49 UTC (rev 401) @@ -30,7 +30,6 @@ private GroupDataModel groupDataModel; private RegulationData regulationData; - private EnforcementData enforcementData; private int[] regulationRankings; private int[] enforcementRankings; @@ -336,16 +335,6 @@ this.regulationData = regulationData; } - public EnforcementData getEnforcementData() { - return enforcementData; - } - - public void setEnforcementData(EnforcementData enforcementData) { - // if(!(this.regulationData.getRegulationText().isEmpty())) - // regulationData.setRegulationText(this.regulationData.getRegulationText()); - this.enforcementData = enforcementData; - } - // FIXME: generalize for arbitrary clients per group. public Point3D generate3DPosition() { // float x = assignedNumber * getGroupDataModel().getCurrentConfiguration().getWorldWidth() / getGroupDataModel().getNumberOfClients() + 1; Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementData.java 2009-12-04 08:31:29 UTC (rev 400) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementData.java 2009-12-04 08:56:49 UTC (rev 401) @@ -1,87 +0,0 @@ -package edu.asu.commons.foraging.model; - -import java.io.Serializable; - -/** - * - * $Id: RegulationData.java 117 2009-04-21 17:26:20Z dbarge $ - * - * - * @author <a href='mailto:db...@as...'>dbarge</a> - * @version $Revision: 117 $ - */ - -public class EnforcementData implements Serializable { - - private static final long serialVersionUID = 5281922601551921005L; - - //private Identifier ClientID; - - private int enforcementID; - - private int resultIndex; - - private String enforcementText; - - private int[] currentRankingInformation; - - // private String enforcementInstructions; - - // private int enforcementMechanism; - -// private int enforcementMethod; - - /* - public String getEnforcementInstructions(){ - return enforcementInstructions; - } - - public int getEnforcementMechanism(){ - return enforcementMechanism; - } - - public void setEnforcementMechanism(int enforcementMechanism){ - this.enforcementMechanism = enforcementMechanism; - }*/ - -// private int enforcementMethod; - - - public EnforcementData () {this.enforcementText = "";} - - public void setCurrentRankingInformation(int currentRankingInformation[]) - { - this.currentRankingInformation = currentRankingInformation; - } - public int [] getCurrentRankingInformation() - { - return this.currentRankingInformation; - } - - public String getEnforcementText(){ - return enforcementText; - } - - - public void setEnforcementText(String enforcementText){ - this.enforcementText = enforcementText; - } - - public int getEnforcementID(){ - return enforcementID; - } - - public void setEnforcementID(int enforcementID){ - this.enforcementID = enforcementID; - } - - - public int getResultIndex(){ - return resultIndex; - } - - public void setResultIndex(int resultIndex){ - this.resultIndex = resultIndex; - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-04 08:31:43
|
Revision: 400 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=400&view=rev Author: alllee Date: 2009-12-04 08:31:29 +0000 (Fri, 04 Dec 2009) Log Message: ----------- first cut at field of vision. the gray circle is still not 100% accurately centered on the participant. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/Circle.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java Removed Paths: ------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/Circle.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/Circle.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/Circle.java 2009-12-04 08:31:29 UTC (rev 400) @@ -16,6 +16,8 @@ private static final long serialVersionUID = 6400834001276229287L; + private static final double FUDGE_FACTOR = 0.1d; + private Point center; private final double radius; @@ -28,7 +30,7 @@ if (point == null) { throw new IllegalArgumentException("Null point passed to Circle.contains()"); } - return center.distance(point) <= radius; + return center.distance(point) <= (radius + FUDGE_FACTOR); } public void setCenter(Point center) { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 08:31:29 UTC (rev 400) @@ -14,8 +14,10 @@ import edu.asu.commons.foraging.event.RealTimeSanctionRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.model.ClientData; +import edu.asu.commons.foraging.model.EnforcementMechanism; import edu.asu.commons.foraging.model.ForagingDataModel; import edu.asu.commons.foraging.model.GroupDataModel; +import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.foraging.model.Resource; import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; @@ -40,8 +42,6 @@ // FIXME: can obtain tokensConsumed from the clientDataMap now. private int currentTokens; - private Identifier monitorId; - // these are the subjects whom we have sanctioned private Map<Identifier, Duration> sanctioned = new HashMap<Identifier, Duration>(); @@ -62,12 +62,8 @@ client.transmit(new ExplicitCollectionModeRequest(client.getId(), explicitCollectionMode)); } - public void setMonitorId (Identifier moniterId) { - this.monitorId = moniterId; - } - public Identifier getMonitorId() { - return this.monitorId; + return groupDataModel.getActiveMonitor().getId(); } public void setRegulation(String regulation) { @@ -126,7 +122,17 @@ groupDataModel = null; } } - + + public List<RegulationData> getSubmittedRegulations() { + return groupDataModel.getSubmittedRegulations(); + } + + public EnforcementMechanism getActiveEnforcementMechanism() { + return groupDataModel.getActiveEnforcementMechanism(); + } + + + public void initialize(GroupDataModel groupDataModel) { clear(); this.groupDataModel = groupDataModel; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 08:31:29 UTC (rev 400) @@ -7,34 +7,26 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.Map; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.JButton; -import javax.swing.JEditorPane; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.ScrollPaneConstants; -import javax.swing.Timer; import edu.asu.commons.foraging.event.EnforcementRankingRequest; import edu.asu.commons.foraging.model.EnforcementData; import edu.asu.commons.net.Identifier; - - - /** * $Id: EnforcementPanel.java 45 2008-08-21 00:47:39Z dbarge $ * - * Enforcement panel is used to vote - * enforcement mechanism + * Enforcement panel is used to vote enforcement mechanism * * @author dbarge * @version $Revision: 45 $ @@ -45,15 +37,7 @@ private ForagingClient client; - private Map<Identifier, EnforcementData> enforcements; - public EnforcementPanel (ForagingClient client) { - this.noOfEnforcements = 4; - this.client = client; - this.clientId = client.getId(); - - } - private String[] votes = { "1", "2", "3","4"}; private String[] enforcementOptions = { "No Enforcement - Click here for more info ", @@ -84,6 +68,10 @@ "of 48 seconds randomly assigned by the computer.<br>" }; + public EnforcementPanel (ForagingClient client) { + this.client = client; + this.clientId = client.getId(); + } private Identifier clientId; private JPanel votingPanel; @@ -106,9 +94,7 @@ } public EnforcementPanel () { - enforcements = new HashMap<Identifier, EnforcementData>(); newPanel = new SixChoicePanel[4]; - noOfEnforcements = 4; } public String getVotedEnforcementOptions(int index){ Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 08:31:29 UTC (rev 400) @@ -263,7 +263,8 @@ }); addEventProcessor(new EventTypeProcessor<RegulationSubmissionUpdateEvent>(RegulationSubmissionUpdateEvent.class) { public void handle(final RegulationSubmissionUpdateEvent regulationEvent) { - dataModel.setRegulation(regulationEvent.getMessage()); + gameWindow2D.initializeRegulationVotingPanel(); + } }); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 08:31:29 UTC (rev 400) @@ -22,7 +22,6 @@ import java.util.Map; import java.util.Properties; -import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JEditorPane; @@ -38,7 +37,6 @@ import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import javax.swing.text.StyledDocument; -import javax.swing.text.html.HTMLEditorKit; import edu.asu.commons.event.Event; import edu.asu.commons.event.EventChannel; @@ -52,12 +50,10 @@ import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.Direction; -import edu.asu.commons.foraging.model.EnforcementData; import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; import edu.asu.commons.util.HtmlEditorPane; -import edu.asu.commons.util.Utils; @@ -89,7 +85,7 @@ private JPanel messagePanel; private JScrollPane errorMessageScrollPane; private JTextPane errorMessageTextPane; - private JScrollPane regulationVotingIntructionsScrollPane; + private JPanel regulationVotingPane; private JPanel labelPanel; @@ -98,8 +94,6 @@ private RegulationData votedRegulation; - private EnforcementData votedEnforcement; - private ChatPanel chatPanel; public static String roleDescription [] = { @@ -112,7 +106,7 @@ "Harvest and Sanction: You can collect tokens and at the same & \n" + "at the same time sanction other participants"}; - private SanctioningPanel sanctioningPanel; + private RegulationPanel regulationPanel; private EnforcementPanel enforcementPanel; @@ -142,7 +136,6 @@ private EventChannel channel; - private Map<Identifier, RegulationData> regulations; private CardLayout cardLayout; @@ -367,7 +360,7 @@ timer = null; //remove(sanctioningPanel); //getSanctioningPanel().stopTimer(); - getSanctioningPanel().sendRegulationVotes(); + getRegulationPanel().sendRegulationVotes(); System.out.println("Regulation voting sent"); //displayRegulationWaitMessage(); // Utils.waitOn(regulationVotesSignal); @@ -387,11 +380,10 @@ } - private void startSanctioningTimer() { + private void startRegulationSubmissionTimer() { if (timer == null) { //FIXME: Need to fetch this value from the round4.xml final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationSubmissionDuration()); - timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -406,9 +398,8 @@ //addCenterComponent(regulationVotingPane); timer.stop(); timer = null; - getSanctioningPanel().sendRegulation(); - Utils.waitOn(regulationSignal); - initializeRegulationVotingPanel(); + getRegulationPanel().sendRegulation(); +// Utils.waitOn(regulationSignal); } else { timeLeftLabel.setText( String.format("You have %d seconds left to write your regualtion", duration.getTimeLeft() / 1000L) ); @@ -435,7 +426,7 @@ timer.stop(); timer = null; - initializeSanctioningPanel(); + initializeRegulationPanel(); } else { @@ -504,18 +495,10 @@ } } - private SanctioningPanel updateRegulationVotingPanel(){ - // System.out.println("Inside update regulation"); - - SanctioningPanel sanctioningPanel = getSanctioningPanel(); - sanctioningPanel.initRegulationVotingCompontents(); - - regulations = getSanctioningPanel().getAllRegulations(); - // System.out.println("Fetched all the regulations from the server : "+regulations.size()); - // setNativeLookAndFeel(); - //regulationVotingPane.add(votingArea, BorderLayout.SOUTH); - //regulationVotingPane.add(regulationVotingIntructionsScrollPane,BorderLayout.NORTH); - return sanctioningPanel; + private RegulationPanel updateRegulationVotingPanel(){ + RegulationPanel regulationPanel = getRegulationPanel(); + regulationPanel.initRegulationVotingComponents(); + return regulationPanel; } private void initGuiComponents() { @@ -532,6 +515,7 @@ subjectWindow.setBackground(Color.WHITE); subjectWindow.setForeground(Color.BLACK); subjectWindow.add(subjectView, BorderLayout.CENTER); +// setBackground(SubjectView.FIELD_OF_VISION_COLOR); setBackground(Color.WHITE); // replace with progress bar. timeLeftLabel = new JLabel("Connecting ..."); @@ -542,17 +526,17 @@ // getSanctioningPanel().initializeVotingPaneWithRegulations(); - regulationVotingPane = new JPanel(); - //regulationVotingPane.setLayout(new BoxLayout(regulationVotingPane, BoxLayout.LINE_AXIS)); - regulationVotingPane.setLayout(new BorderLayout(4,4)); +// regulationVotingPane = new JPanel(); +// //regulationVotingPane.setLayout(new BoxLayout(regulationVotingPane, BoxLayout.LINE_AXIS)); +// regulationVotingPane.setLayout(new BorderLayout(4,4)); +// +// regulationVotingIntructions = new JEditorPane(); +// regulationVotingIntructions.setContentType("text/html"); +// regulationVotingIntructions.setEditorKit(new HTMLEditorKit()); +// regulationVotingIntructions.setEditable(false); +// regulationVotingIntructions.setBorder(BorderFactory.createTitledBorder("Regulation voting instructions")); +// regulationVotingIntructionsScrollPane = new JScrollPane(regulationVotingIntructions); - regulationVotingIntructions = new JEditorPane(); - regulationVotingIntructions.setContentType("text/html"); - regulationVotingIntructions.setEditorKit(new HTMLEditorKit()); - regulationVotingIntructions.setEditable(false); - regulationVotingIntructions.setBorder(BorderFactory.createTitledBorder("Regulation voting instructions")); - regulationVotingIntructionsScrollPane = new JScrollPane(regulationVotingIntructions); - labelPanel = new JPanel(); labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.LINE_AXIS)); labelPanel.setBackground(Color.WHITE); @@ -587,6 +571,7 @@ } }); + // resize listener addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent event) { Component component = event.getComponent(); @@ -594,7 +579,8 @@ Dimension size = new Dimension(component.getWidth(), subjectViewHeight); subjectView.setScreenSize(size); subjectView.setImageSizes(); - repaint(); + GameWindow2D.this.revalidate(); + GameWindow2D.this.repaint(); } }); // add component listeners, chat panel, and sanctioning window IF chat/sanctioning are enabled, and after the end of the round... @@ -727,7 +713,6 @@ } currentCenterComponent = newCenterComponent; revalidate(); - // currentCenterComponent.repaint(); } public void startRound() { @@ -736,7 +721,6 @@ timer.stop(); timer = null; } - // currentExperimentConfiguration = configuration; Runnable runnable = new Runnable() { public void run() { @@ -748,7 +732,6 @@ // has begun. update(configuration.getRoundDuration().getTimeLeft()); add(messagePanel, BorderLayout.SOUTH); - addCenterComponent(subjectWindow); requestFocusInWindow(); } @@ -852,12 +835,12 @@ } return chatPanel; } - private SanctioningPanel getSanctioningPanel() { - if (sanctioningPanel == null) { + private RegulationPanel getRegulationPanel() { + if (regulationPanel == null) { //System.out.println("Sanc panel is null"); - sanctioningPanel = new SanctioningPanel(client); + regulationPanel = new RegulationPanel(client); } - return sanctioningPanel; + return regulationPanel; } private EnforcementPanel getEnforcementPanel() { if (enforcementPanel == null) { @@ -905,7 +888,7 @@ instructionsEditorPane.setText("Message from the System:<br><br>" + "<b>Please wait until the System receives votes from all players.System<br>"+ "will calculate the result of the voting and display it in a moment</b>"); - remove(sanctioningPanel); + remove(regulationPanel); addCenterComponent(instructionsScrollPane); } }); @@ -927,13 +910,12 @@ - public void displayVotedRegulation(){ + public void displayVotedRegulation() { //new code // System.out.println("*****Inside display voting regulation"); SwingUtilities.invokeLater(new Runnable() { public void run() { instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getText()+".</b>"); - remove(sanctioningPanel); addCenterComponent(instructionsScrollPane); startRegulationDisplayTimer(); } @@ -943,7 +925,6 @@ public void updateDebriefing(final PostRoundSanctionUpdateEvent event) { Runnable runnable = new Runnable() { public void run() { - System.err.println("updating debriefing text"); postSanctionDebriefingText(event); addCenterComponent(instructionsScrollPane); } @@ -952,15 +933,8 @@ } public void resetPanels() { - //System.out.println("Reseting the panels"); - // if(sanctioningPanel != null) - // sanctioningPanel.resetHandles(); - // if(enforcementPanel != null) - // enforcementPanel.resetHandles(); - - sanctioningPanel = null; + regulationPanel = null; enforcementPanel = null; - // chatPanel = null; } @@ -995,13 +969,9 @@ // System.out.println("*****Inside initialize enforcement()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code - System.out.println("*****Inside thread initialize sanctioningPanel()"); EnforcementPanel enforcementPanel = getEnforcementPanel(); enforcementPanel.initialize(); - remove(instructionsScrollPane); addCenterComponent(enforcementPanel); - // enforcementPanel.startTimer(); startEnforcementVotingTimer(); } }); @@ -1015,28 +985,23 @@ public void run() { //new code //System.out.println("*****Inside thread initialize votingPanel()"); - remove(sanctioningPanel); - SanctioningPanel sanctioningPanel = updateRegulationVotingPanel(); - addCenterComponent( sanctioningPanel ); + RegulationPanel regulationPanel = updateRegulationVotingPanel(); + addCenterComponent( regulationPanel ); //sanctioningPanel.startTimer(); startRegulationVotingTimer(); } }); } - public void initializeSanctioningPanel() { + public void initializeRegulationPanel() { //new code - // System.out.println("*****Inside initialize sanctioningPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code - // System.out.println("*****Inside thread initialize sanctioningPanel()"); - SanctioningPanel sanctioningPanel = getSanctioningPanel(); - sanctioningPanel.initialize(); + getRegulationPanel().initialize(); // System.out.println("Initialization done"); //remove( messagePanel ); - addCenterComponent( sanctioningPanel ); - startSanctioningTimer(); + addCenterComponent(getRegulationPanel()); + startRegulationSubmissionTimer(); } }); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-04 08:31:29 UTC (rev 400) @@ -114,8 +114,7 @@ private void setBoardSize(Dimension boardSize) { this.boardSize = boardSize; setBackground(Color.BLACK); - setForeground(Color.WHITE); - repaint(); +// setForeground(Color.WHITE); } /** Copied: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java (from rev 399, foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java) =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 08:31:29 UTC (rev 400) @@ -0,0 +1,481 @@ +package edu.asu.commons.foraging.client; + + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JEditorPane; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyleContext; +import javax.swing.text.StyledDocument; +import javax.swing.text.html.HTMLEditorKit; + +import edu.asu.commons.foraging.event.RegulationRankingRequest; +import edu.asu.commons.foraging.event.SubmitRegulationRequest; +import edu.asu.commons.foraging.model.RegulationData; +import edu.asu.commons.net.Identifier; + + + +/** + * $Id: Sanctioning.java 45 2008-08-21 00:47:39Z dbarge $ + * + * Sanctioning panel is used to create regulations and + * enforcement mechanism + * + * @author dbarge + * @version $Revision: 45 $ + */ + +@SuppressWarnings("serial") +public class RegulationPanel extends JPanel { + + private ForagingClient client; + + public RegulationPanel (ForagingClient client) { + this.client = client; +// client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { +// public void handle(final RegulationEvent regulationEvent) { +// boolean votingFlag=false; +// RegulationData regulationData = null; +// regulations = regulationEvent.getAllRegulations(); +// // System.out.println("Regulation received : "+regulations.size()); +// noOfRegulations = regulations.size(); +// for (Identifier targetId : regulations.keySet()) { +// regulationData = regulations.get(targetId); +// if(regulationData.isVoting())votingFlag = true; +// break; +// } +// if(votingFlag) +// { +// votedRegulation = regulationData; +// Utils.notify(GameWindow2D.regulationVotesSignal); +// } +// else +// { +// //System.out.println("Finding my ID"); +// findAndSetMyRegulationID(); +// Utils.notify(GameWindow2D.regulationSignal); +// } +// } +// }); + } + + public RegulationPanel () + { +// regulations = new ArrayList<RegulationData>(); + newPanel = new SixChoicePanel[5]; + noOfRegulations = 5; + } + + private RegulationData votedRegulation; + + private int noOfRegulations; + + private int[] currentRankingInformation; + + private SixChoicePanel newPanel[]; + + private JPanel votingPanel; + private JPanel instructionsPanel; + private JPanel buttonPanel; + private JButton sendMyVotes; + private JButton reset; + + private String[] votes = { "1", "2", "3","4", "5"}; + + private JScrollPane messageScrollPane; + + private JScrollPane regulationsInstructionsScrollPane; + + private JTextPane messageWindow; + + private List<Identifier> participants; + + private JEditorPane regulationsInstructionsPane; + +// private void findAndSetMyRegulationID() +// { +// for (Identifier targetId : regulations.keySet()) { +// if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ +// client.setRegulationID(regulations.get(targetId).getRegulationID()); +// //client.setEnforcementID(regulations.get(targetId).getToken()); +// client.setToken(regulations.get(targetId).getToken()); +// //System.out.println("My RegID:"+client.getRegulationID()); +// //System.out.println("Token:"+client.getEnforcementID()); +// return; +// } +// } +// } + + public RegulationData getVotedRegulation(){ + return this.votedRegulation; + } + + private void addStylesToMessageWindow() { + StyledDocument styledDocument = messageWindow.getStyledDocument(); + // and why not have something like... StyleContext.getDefaultStyle() to + // replace this junk + Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( + StyleContext.DEFAULT_STYLE); + // Style regularStyle = styledDocument.addStyle("regular", + // defaultStyle); + StyleConstants.setFontFamily(defaultStyle, "Helvetica"); + StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), + true); + StyleConstants.setItalic(styledDocument + .addStyle("italic", defaultStyle), true); + } + + private void updateVotingPanel(int currentActive){ + int r,c,i; + SixChoicePanel temp = null; + boolean enableSendButton = true; + + // System.out.println("Active panel: "+SixChoicePanel.currentActive); + // The below for loop is used to clear off radio button of the panel whose ranking conflicts + // with the new panel's radio button + + + for(r = 0; r < noOfRegulations; r++) + { + System.out.print(newPanel[r].currentRanking+" "); + if(newPanel[r].currentRanking == -1)enableSendButton = false; + + if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) + { + newPanel[r].currentRanking = -1; + newPanel[r].group.clearSelection(); + } + } + + //The below for loops are used for sorting the panels when the ranks are + //changed + + for(r = 0; r < noOfRegulations-1; r++) + { + for(c = 0; c < noOfRegulations-1; c++) + { + if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + } + } + + for(c = 0; c < noOfRegulations; c++) + { + // System.out.print(newPanel[c].getCurrentRanking() +" "); + } + + votingPanel.setVisible(false); + remove(votingPanel); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + + votingPanel.add(getInstructionPanel("This is instruction panel")); + + + for(i=0; i < noOfRegulations; i++) { + votingPanel.add(newPanel[i].regulationPanel); + } + + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); + + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + revalidate(); + } + + public void sendRegulation() { + client.transmit(new SubmitRegulationRequest(client.getId(), messageWindow.getText())); + } + + public void sendRegulationVotes() { + System.out.println("Regulation votes ready to be sent"); + // System.err.println("message: " + message); + int i; + for(i=0; i < noOfRegulations; i++) { + if(newPanel[i].currentRanking == -1) + this.currentRankingInformation[i] = -1; + else + this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); + } + + /* + for(i=0 ; i<5 ; i++) + { + System.out.println(currentRankingInformation[i]); + } + */ + +// RegulationData regulationData = new RegulationData(); +// regulationData.setCurrentRankingInformation(this.currentRankingInformation); +// regulationData.setRegulationText(message); +// regulationData.setVotingFlag(true); +// +// // System.out.println("ID:"+client.getRegulationID()); +// regulationData.setRegulationID(client.getRegulationID()); + + client.transmit(new RegulationRankingRequest(client.getId(), currentRankingInformation)); + } + + private Color getColor(int i) + { + Color color = null; + if(i==0) color = new Color(153,153,204); + if(i==1) color = new Color(204,153,153); + if(i==2) color = new Color(153,204,102); + if(i==3) color = new Color(204,204,102); + if(i==4) color = new Color(255,255,153); + return color; + } + + private String getVoteString(){ + + StringBuilder sb = new StringBuilder(); + + for(int c = 0; c < noOfRegulations; c++) + { + sb.append("\nRegulation "+(newPanel[c].getCurrentRanking()+1)); + } + return(sb.toString()); + } + + public void initRegulationVotingComponents(){ + + remove(regulationsInstructionsScrollPane); + remove(messageScrollPane); + this.currentRankingInformation = new int[5]; + this.newPanel = new SixChoicePanel[5]; + setBackground(Color.lightGray); + setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + + //add the instruction panel as the first panel in voting panel. + instructionsPanel = getInstructionPanel("This is instruction panel"); + votingPanel.add(instructionsPanel); + + // this is for dummy regulation data for testing + // start +// for(int i=0; i<5; i++) { +// RegulationData regulationData1 = new RegulationData(); +// regulationData1.setRegulationID(i); +// regulationData1.setRegulationText("Test Regulation " + i); +// Identifier temp = new Identifier.Base (){}; +// System.out.println("Idn : " + temp); +// regulations.put(temp, regulationData1); +// } +// System.out.println(regulations.size()); + // end + + //for(int i=0; i<5; i++) { + int i = 0; + for (RegulationData regulationData : client.getDataModel().getSubmittedRegulations()) { + // FIXME: are you aware that this code is completely unnecessary? You're creating a StringBuilder for no reason at all - + // regulationData.getText() is already a String! +// StringBuilder sb = new StringBuilder(); +// sb.append(regulationData.getText()); +// String s = sb.toString(); + newPanel[i] = new SixChoicePanel(regulationData.getText(), votes, regulationData.getIndex(), getColor(i)); + // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); + votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); + i++; + } + + add(votingPanel, BorderLayout.CENTER); + reset = new JButton("Reset All Ranks"); + reset.setAlignmentX(Component.CENTER_ALIGNMENT); + reset.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + for(int i=0; i<noOfRegulations; i++) { + for(int j=0; j<noOfRegulations; j++) { + newPanel[i].option[j].setEnabled(true); + newPanel[i].group.clearSelection(); + newPanel[i].currentRanking = -1; + } + } + } + }); + sendMyVotes = new JButton("Send votes"); + sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); + sendMyVotes.setEnabled(false); + sendMyVotes.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + int n = JOptionPane.showConfirmDialog( + null, "Are you sure to submit your votes ?"+ + "\nBelow is order of your voting" + + getVoteString(), + "Confirm and send votes", + JOptionPane.YES_NO_OPTION); + + if (n == JOptionPane.YES_OPTION) { + GameWindow2D.duration.expire(); + } + if (n == JOptionPane.NO_OPTION) { + + } + + } + }); + buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridLayout(1,2)); + buttonPanel.add(reset); + buttonPanel.add(sendMyVotes); + + add(buttonPanel, BorderLayout.SOUTH); + } + + private JPanel getInstructionPanel(String instructions) + { + JPanel instructionPanel = new JPanel(); + //instructionPanel.setBackground(color); + instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); + instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); + + //create Text area and JSCroll pane for it + + JTextArea instructionText = new JTextArea(instructions,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + instructionPanel.add(scrollForRegulationText); + + return instructionPanel; + + } + private void initGuiComponents() { + setLayout(new BorderLayout(4, 4)); + messageWindow = new JTextPane(); + messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); + messageWindow.requestFocusInWindow(); + messageScrollPane = new JScrollPane(messageWindow); + addStylesToMessageWindow(); + + // orient the components in true lazyman fashion. + + regulationsInstructionsPane = new JEditorPane(); + regulationsInstructionsPane.setContentType("text/html"); + regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); + regulationsInstructionsPane.setEditable(false); + regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation details")); + regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); + + //FIXME: Need to fetch the regulation instructions over here + //dummy regulation instructions are + + //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); + regulationsInstructionsPane.setText("Test regulation instructions...."); + //add(regulationsInstructionsScrollPane, BorderLayout.NORTH); + //add(messageScrollPane, BorderLayout.CENTER); + + } + + public void clear() { + participants.clear(); + } + + public void initialize() { + // System.out.println("Calling init GUI components"); + initGuiComponents(); + } + + private class SixChoicePanel implements ActionListener{ + //String title; + String [] buttonLabels; + // the index of the regulation that is being rendered in this panel + int regulationID; + int currentRanking; + JPanel regulationPanel; + JPanel rankPanel; + ButtonGroup group; + JRadioButton option []; + Color color; + + public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { + //this.title = title; + this.buttonLabels = buttonLabels; + this.regulationID = regulationID; + this.color = color; + this.currentRanking = -1; + this.option = new JRadioButton[5]; + } + + public int getCurrentRanking(){ + return regulationID; + } + + public void actionPerformed(ActionEvent e) { + String choice = group.getSelection().getActionCommand(); + int buttonNo = Integer.parseInt(choice); + System.out.println("ACTION Choice Selected: " + choice); + System.out.println("Bno: " + buttonNo); + System.out.println("CurrentActive : "+this.regulationID); + this.currentRanking = buttonNo; + updateVotingPanel(this.regulationID); + } + + + public JPanel getRegulationPanel(int i, String information){ + regulationPanel = new JPanel(); + regulationPanel.setBackground(color); + regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); + regulationPanel.setBorder(BorderFactory.createTitledBorder("Regulation "+(i+1))); + + //create Text area and JSCroll pane for it + + JTextArea regulationText = new JTextArea(information,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(regulationText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + regulationPanel.add(scrollForRegulationText); + + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length + + for(int j=0; j<length; j++) { + option[j] = new JRadioButton(buttonLabels[j]); + option[j].setActionCommand(buttonLabels[j]); + group.add(option[j]); + option[j].addActionListener(this); + rankPanel.add(option[j]); + } + regulationPanel.add(rankPanel); + return regulationPanel; + } + + } + +} Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-04 08:31:29 UTC (rev 400) @@ -1,495 +0,0 @@ -package edu.asu.commons.foraging.client; - - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JEditorPane; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextPane; -import javax.swing.ScrollPaneConstants; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import javax.swing.text.StyledDocument; -import javax.swing.text.html.HTMLEditorKit; - -import edu.asu.commons.foraging.event.RegulationRankingRequest; -import edu.asu.commons.foraging.event.SubmitRegulationRequest; -import edu.asu.commons.foraging.model.RegulationData; -import edu.asu.commons.net.Identifier; - - - -/** - * $Id: Sanctioning.java 45 2008-08-21 00:47:39Z dbarge $ - * - * Sanctioning panel is used to create regulations and - * enforcement mechanism - * - * @author dbarge - * @version $Revision: 45 $ - */ - -@SuppressWarnings("serial") -public class SanctioningPanel extends JPanel { - - private ForagingClient client; - - private Map<Identifier, RegulationData> regulations; - - public SanctioningPanel (ForagingClient client) { - this.client = client; - this.clientId = client.getId(); -// client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { -// public void handle(final RegulationEvent regulationEvent) { -// boolean votingFlag=false; -// RegulationData regulationData = null; -// regulations = regulationEvent.getAllRegulations(); -// // System.out.println("Regulation received : "+regulations.size()); -// noOfRegulations = regulations.size(); -// for (Identifier targetId : regulations.keySet()) { -// regulationData = regulations.get(targetId); -// if(regulationData.isVoting())votingFlag = true; -// break; -// } -// if(votingFlag) -// { -// votedRegulation = regulationData; -// Utils.notify(GameWindow2D.regulationVotesSignal); -// } -// else -// { -// //System.out.println("Finding my ID"); -// findAndSetMyRegulationID(); -// Utils.notify(GameWindow2D.regulationSignal); -// } -// } -// }); - } - - public SanctioningPanel () - { - regulations = new HashMap<Identifier, RegulationData>(); - newPanel = new SixChoicePanel[5]; - noOfRegulations = 5; - } - - private Identifier clientId; - - private String message; - - private RegulationData votedRegulation; - - private int noOfRegulations; - - private int currentRankingInformation[]; - - private SixChoicePanel newPanel[]; - - private JPanel votingPanel; - private JPanel instructionsPanel; - private JPanel buttonPanel; - private JButton sendMyVotes; - private JButton reset; - - private String[] votes = { "1", "2", "3","4", "5"}; - - private JScrollPane messageScrollPane; - - private JScrollPane regulationsInstructionsScrollPane; - - private JTextPane messageWindow; - - private List<Identifier> participants; - - private JEditorPane regulationsInstructionsPane; - - public Map<Identifier, RegulationData> getAllRegulations() { - return regulations; - } - -// private void findAndSetMyRegulationID() -// { -// for (Identifier targetId : regulations.keySet()) { -// if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ -// client.setRegulationID(regulations.get(targetId).getRegulationID()); -// //client.setEnforcementID(regulations.get(targetId).getToken()); -// client.setToken(regulations.get(targetId).getToken()); -// //System.out.println("My RegID:"+client.getRegulationID()); -// //System.out.println("Token:"+client.getEnforcementID()); -// return; -// } -// } -// } - - public RegulationData getVotedRegulation(){ - return this.votedRegulation; - } - - private void addStylesToMessageWindow() { - StyledDocument styledDocument = messageWindow.getStyledDocument(); - // and why not have something like... StyleContext.getDefaultStyle() to - // replace this junk - Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( - StyleContext.DEFAULT_STYLE); - // Style regularStyle = styledDocument.addStyle("regular", - // defaultStyle); - StyleConstants.setFontFamily(defaultStyle, "Helvetica"); - StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), - true); - StyleConstants.setItalic(styledDocument - .addStyle("italic", defaultStyle), true); - } - - private void updateVotingPanel(int currentActive){ - int r,c,i; - SixChoicePanel temp = null; - boolean enableSendButton = true; - - // System.out.println("Active panel: "+SixChoicePanel.currentActive); - // The below for loop is used to clear off radio button of the panel whose ranking conflicts - // with the new panel's radio button - - - for(r = 0; r < noOfRegulations; r++) - { - System.out.print(newPanel[r].currentRanking+" "); - if(newPanel[r].currentRanking == -1)enableSendButton = false; - - if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) - { - newPanel[r].currentRanking = -1; - newPanel[r].group.clearSelection(); - } - } - - //The below for loops are used for sorting the panels when the ranks are - //changed - - for(r = 0; r < noOfRegulations-1; r++) - { - for(c = 0; c < noOfRegulations-1; c++) - { - if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - } - } - - for(c = 0; c < noOfRegulations; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } - - votingPanel.setVisible(false); - remove(votingPanel); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - - votingPanel.add(getInstructionPanel("This is instruction panel")); - - - for(i=0; i < noOfRegulations; i++) { - votingPanel.add(newPanel[i].regulationPanel); - } - - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); - - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } - revalidate(); - } - - public void sendRegulation() { - client.transmit(new SubmitRegulationRequest(clientId, messageWindow.getText())); - } - - public void sendRegulationVotes() { - System.out.println("Regulation votes ready to be sent"); - // System.err.println("message: " + message); - int i; - for(i=0; i < noOfRegulations; i++) { - if(newPanel[i].currentRanking == -1) - this.currentRankingInformation[i] = -1; - else - this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); - } - - /* - for(i=0 ; i<5 ; i++) - { - System.out.println(currentRankingInformation[i]); - } - */ - -// RegulationData regulationData = new RegulationData(); -// regulationData.setCurrentRankingInformation(this.currentRankingInformation); -// regulationData.setRegulationText(message); -// regulationData.setVotingFlag(true); -// -// // System.out.println("ID:"+client.getRegulationID()); -// regulationData.setRegulationID(client.getRegulationID()); - - client.transmit(new RegulationRankingRequest(clientId, currentRankingInformation)); - } - - private Color getColor(int i) - { - Color color = null; - if(i==0) color = new Color(153,153,204); - if(i==1) color = new Color(204,153,153); - if(i==2) color = new Color(153,204,102); - if(i==3) color = new Color(204,204,102); - if(i==4) color = new Color(255,255,153); - return color; - } - - private String getVoteString(){ - - StringBuilder sb = new StringBuilder(); - - for(int c = 0; c < noOfRegulations; c++) - { - sb.append("\nRegulation "+(newPanel[c].getCurrentRanking()+1)); - } - return(sb.toString()); - } - - public void initRegulationVotingCompontents(){ - - remove(regulationsInstructionsScrollPane); - remove(messageScrollPane); - this.currentRankingInformation = new int[5]; - this.newPanel = new SixChoicePanel[5]; - setBackground(Color.lightGray); - setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - - //add the instruction panel as the first panel in voting panel. - instructionsPanel = getInstructionPanel("This is instruction panel"); - votingPanel.add(instructionsPanel); - - RegulationData regulationData; - - // this is for dummy regulation data for testing - // start -// for(int i=0; i<5; i++) { -// RegulationData regulationData1 = new RegulationData(); -// regulationData1.setRegulationID(i); -// regulationData1.setRegulationText("Test Regulation " + i); -// Identifier temp = new Identifier.Base (){}; -// System.out.println("Idn : " + temp); -// regulations.put(temp, regulationData1); -// } -// System.out.println(regulations.size()); - // end - - //for(int i=0; i<5; i++) { - int i = 0; - for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - StringBuilder sb = new StringBuilder(); - sb.append(regulationData.getText()); - String s = sb.toString(); - newPanel[i] = new SixChoicePanel(s, votes, regulationData.getIndex(), getColor(i)); - // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); - votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); - i++; - } - - add(votingPanel, BorderLayout.CENTER); - reset = new JButton("Reset All Ranks"); - reset.setAlignmentX(Component.CENTER_ALIGNMENT); - reset.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - for(int i=0; i<noOfRegulations; i++) { - for(int j=0; j<noOfRegulations; j++) { - newPanel[i].option[j].setEnabled(true); - newPanel[i].group.clearSelection(); - newPanel[i].currentRanking = -1; - } - } - } - }); - sendMyVotes = new JButton("Send votes"); - sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); - sendMyVotes.setEnabled(false); - sendMyVotes.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - - int n = JOptionPane.showConfirmDialog( - null, "Are you sure to submit your votes ?"+ - "\nBelow is order of your voting" + - getVoteString(), - "Confirm and send votes", - JOptionPane.YES_NO_OPTION); - - if (n == JOptionPane.YES_OPTION) { - GameWindow2D.duration.expire(); - } - if (n == JOptionPane.NO_OPTION) { - - } - - } - }); - buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(1,2)); - buttonPanel.add(reset); - buttonPanel.add(sendMyVotes); - - add(buttonPanel, BorderLayout.SOUTH); - } - - private JPanel getInstructionPanel(String instructions) - { - JPanel instructionPanel = new JPanel(); - //instructionPanel.setBackground(color); - instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); - instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); - - //create Text area and JSCroll pane for it - - JTextArea instructionText = new JTextArea(instructions,3,50); - JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - instructionPanel.add(scrollForRegulationText); - - return instructionPanel; - - } - private void initGuiComponents() { - setLayout(new BorderLayout(4, 4)); - messageWindow = new JTextPane(); - messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); - messageWindow.requestFocusInWindow(); - messageScrollPane = new JScrollPane(messageWindow); - addStylesToMessageWindow(); - - // orient the components in true lazyman fashion. - - regulationsInstructionsPane = new JEditorPane(); - regulationsInstructionsPane.setContentType("text/html"); - regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); - regulationsInstructionsPane.setEditable(false); - regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation details")); - regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); - - //FIXME: Need to fetch the regulation instructions over here - //dummy regulation instructions are - - //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); - regulationsInstructionsPane.setText("Test regulation instructions...."); - //add(regulationsInstructionsScrollPane, BorderLayout.NORTH); - //add(messageScrollPane, BorderLayout.CENTER); - - } - - public void clear() { - participants.clear(); - } - - public void initialize() { - // System.out.println("Calling init GUI components"); - initGuiComponents(); - } - - private class SixChoicePanel implements ActionListener{ - //String title; - String [] buttonLabels; - // the index of the regulation that is being rendered in this panel - int regulationID; - int currentRanking; - JPanel regulationPanel; - JPanel rankPanel; - ButtonGroup group; - JRadioButton option []; - Color color; - - public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { - //this.title = title; - this.buttonLabels = buttonLabels; - this.regulationID = regulationID; - this.color = color; - this.currentRanking = -1; - this.option = new JRadioButton[5]; - } - - public int getCurrentRanking(){ - return regulationID; - } - - public void actionPerformed(ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - System.out.println("ACTION Choice Selected: " + choice); - System.out.println("Bno: " + buttonNo); - System.out.println("CurrentActive : "+this.regulationID); - this.currentRanking = buttonNo; - updateVotingPanel(this.regulationID); - } - - - public JPanel getRegulationPanel(int i, String information){ - regulationPanel = new JPanel(); - regulationPanel.setBackground(color); - regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); - regulationPanel.setBorder(BorderFactory.createTitledBorder("Regulation "+(i+1))); - - //create Text area and JSCroll pane for it - - JTextArea regulationText = new JTextArea(information,3,50); - JScrollPane scrollForRegulationText = new JScrollPane(regulationText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - regulationPanel.add(scrollForRegulationText); - - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length - - for(int j=0; j<length; j++) { - option[j] = new JRadioButton(buttonLabels[j]); - option[j].setActionCommand(buttonLabels[j]); - group.add(option[j]); - option[j].addActionListener(this); - rankPanel.add(option[j]); - } - regulationPanel.add(rankPanel); - return regulationPanel; - } - - } - -} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-04 08:31:29 UTC (rev 400) @@ -4,7 +4,9 @@ import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics2D; +import java.awt.Paint; import java.awt.Point; +import java.awt.geom.Ellipse2D; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -18,10 +20,15 @@ /** * $Id$ - * + * <p> * This class encapsulates the client's view of the game board. Used by the * ForagerGameWindow to render the current state of the game. * + * <br/> + * FIXME: refactor field of vision + * </p> + * + * * @author Allen Lee * @version $Revision$ * @@ -31,6 +38,8 @@ private static final long serialVersionUID = 8215577330876498459L; private final ClientDataModel dataModel; + + public final static Color FIELD_OF_VISION_COLOR = new Color(192, 192, 192, 30); // associates a Duration with a piece of token consumed at the given Point - // the duration is used to render the token as shrinking. @@ -120,13 +129,16 @@ double radius = roundConfiguration.getViewSubjectsRadius(); fieldOfVision = new Circle(currentPosition, radius); // paint field of vision -// Paint originalPaint = graphics2D.getPaint(); -// graphics2D.setPaint(new Color(192, 192, 192, 30)); -// Point topLeftCorner = new Point(currentPosition.x - (int) radius, currentPosition.y - (int) radius); -// int x = scaleX(topLeftCorner.x); -// int y = scaleY(topLeftCorner.y); -// graphics2D.fillOval(x, y, scaleX(radius), scaleY(radius)); -// graphics2D.setPaint(originalPaint); + Paint originalPaint = graphics2D.getPaint(); + graphics2D.setPaint(FIELD_OF_VISION_COLOR); + Point topLeftCorner = new Point(currentPosition.x - (int) radius, currentPosition.y - (int) radius); + int x = scaleX(topLeftCorner.x); + int y = scaleY(topLeftCorner.y); + int diameter = (int) radius * 2; + diameter = Math.min(scaleX(diameter), scaleY(diameter)); + Ellipse2D.Double circle = new Ellipse2D.Double(x, y, diameter, diameter); + graphics2D.fill(circle); + graphics2D.setPaint(originalPaint); } for (Map.Entry<Identifier, ClientData> entry : positions.entrySet()) { Identifier id = entry.getKey(); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 08:31:29 UTC (rev 400) @@ -278,24 +278,26 @@ } public int getRegulationSubmissionDuration() { - return getIntProperty("regulation-duration", 60); + return getIntProperty("regulation-submission-duration", 60); } public int getRegulationDisplayDuration() { - return getIntProperty("regulation-display-duration", 15); + return getIntProperty("regulation-display-duration", 60); } + public int getRegulationVotingtDuration() { + return getIntProperty("regulation-voting-duration", 60); + } + public int getEnforcementVotingDuration() { - return getIntProperty("enforcement-voting-duration", 30); + return getIntProperty("enforcement-voting-duration", 60); } public int getEnforcementDisplayDuration() { - return getIntProperty("enforcement-display-duration", 15); + return getIntProperty("enforcement-display-duration", 60); } - public int getRegulationVotingtDuration() { - return getIntProperty("regulation-voting-duration", 30); - } + public String getSanctionInstructions() { return getProperty("sanction-instructions"); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java 2009-12-04 06:54:23 UTC (rev 399) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java 2009-12-04 08:31:29 UTC (rev 400) @@ -9,7 +9,7 @@ /** * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ * - * Sent... [truncated message content] |
From: <al...@us...> - 2009-12-04 06:54:31
|
Revision: 399 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=399&view=rev Author: alllee Date: 2009-12-04 06:54:23 +0000 (Fri, 04 Dec 2009) Log Message: ----------- starting refactoring on client side, server-side is nearly complete. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java Removed Paths: ------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 06:54:23 UTC (rev 399) @@ -40,15 +40,8 @@ // FIXME: can obtain tokensConsumed from the clientDataMap now. private int currentTokens; - private int role; - private Identifier monitorId; - private static final int MONITOR = 0; - private static final int HARVEST = 1; - private static final int SANCTION = 2; - private static final int HARVESTANDSANCTION = 3; - // these are the subjects whom we have sanctioned private Map<Identifier, Duration> sanctioned = new HashMap<Identifier, Duration>(); @@ -62,23 +55,13 @@ public ClientDataModel(ForagingClient client) { super(client.getEventChannel()); this.client = client; - this.role = HARVEST; } public void toggleExplicitCollectionMode() { explicitCollectionMode = !explicitCollectionMode; - client.transmit(new ExplicitCollectionModeRequest(client.getId(), - explicitCollectionMode)); + client.transmit(new ExplicitCollectionModeRequest(client.getId(), explicitCollectionMode)); } - public void setMyRole(int role){ - this.role = role; - } - - public int getMyRole() { - return this.role; - } - public void setMonitorId (Identifier moniterId) { this.monitorId = moniterId; } @@ -91,42 +74,18 @@ } - public boolean isSanctioningAllowed(){ - System.out.println("My Role : "+getMyRole()); - /* - boolean result = false; - switch(getMyRole()) { - case MONITER: - case SANCTION: - case HARVESTANDSANCTION: - result = true; - break; - } - return result;*/ - - if(getMyRole() == MONITOR || getMyRole() == SANCTION || getMyRole() == HARVESTANDSANCTION)return true; - else return false; - + public boolean isSanctioningAllowed() { + return getClientData().isSanctioningAllowed(); } - public boolean isHarvestingAllowed(){ - if(getMyRole() == HARVEST || getMyRole() == HARVESTANDSANCTION)return true; - else return false; + public boolean isHarvestingAllowed() { + return getClientData().isHarvestingAllowed(); } public boolean isMonitor() { - return role == MONITOR; + return getClientData().getForagingRole().isMonitor(); } - - public boolean canHarvest() { - return role == HARVEST || role == HARVESTANDSANCTION; - } - - public boolean canSanction() { - return role == SANCTION || role == HARVESTANDSANCTION || role == MONITOR; - - } - + /* * public Map<Identifier, Duration> getSanctioned() { return sanctioned; } */ Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-04 06:54:23 UTC (rev 399) @@ -26,17 +26,15 @@ import edu.asu.commons.foraging.event.EndRoundEvent; import edu.asu.commons.foraging.event.EnforcementMechanismUpdateEvent; import edu.asu.commons.foraging.event.LockResourceEvent; -import edu.asu.commons.foraging.event.NewClientRole; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; -import edu.asu.commons.foraging.event.RegulationEvent; +import edu.asu.commons.foraging.event.RegulationSubmissionUpdateEvent; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.model.EnforcementData; -import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; import edu.asu.commons.util.Utils; @@ -70,15 +68,10 @@ private ClientDataModel dataModel; - private int regulationID; - - private int enforcementID; - - private int token; - private MessageQueue messageQueue; - private JPanel panel = new JPanel(); + private JPanel clientPanel = new JPanel(); + public ForagingClient(ServerConfiguration configuration) { this(configuration, new Dimension(800, 600)); } @@ -89,12 +82,11 @@ if (configuration.shouldInitialize2D()) { gameWindow2D = new GameWindow2D(this, screenSize); } - if (configuration.shouldInitialize3D()) { + else if (configuration.shouldInitialize3D()) { gameWindow3D = new GameWindow3D(this); } - panel.setLayout(new BorderLayout()); - panel.add(configuration.getCurrentParameters().is2dExperiment() - ? gameWindow2D : gameWindow3D.getPanel(), + clientPanel.setLayout(new BorderLayout()); + clientPanel.add(configuration.getCurrentParameters().is2dExperiment() ? gameWindow2D : gameWindow3D.getPanel(), BorderLayout.CENTER); } @@ -120,18 +112,7 @@ return gameWindow3D; } } - public void setRegulationID(int ID){this.regulationID = ID;} - - public int getRegulationID(){return this.regulationID;} - - public void setEnforcementID(int ID){this.enforcementID = ID;} - - public int getEnforcementID(){return this.enforcementID;} - - public void setToken(int token){this.token = token;} - - public int getToken(){return this.token;} - + public void sendAvatarInfo(boolean male, Color hairColor, Color skinColor, Color shirtColor, Color trouserColor, Color shoesColor) { transmit(new AgentInfoRequest(getId(), male, hairColor, skinColor, shirtColor, trouserColor, shoesColor)); gameWindow3D.removeAgentDesigner(); @@ -151,19 +132,19 @@ dataModel.setRoundConfiguration(configuration); SwingUtilities.invokeLater(new Runnable() { public void run() { - panel.removeAll(); - panel.invalidate(); + clientPanel.removeAll(); + clientPanel.invalidate(); if (dataModel.is2dExperiment()) { - panel.add(gameWindow2D, BorderLayout.CENTER); + clientPanel.add(gameWindow2D, BorderLayout.CENTER); if (gameWindow3D != null) { gameWindow3D.dispose(); } } else { - panel.add(gameWindow3D.getPanel(), BorderLayout.CENTER); + clientPanel.add(gameWindow3D.getPanel(), BorderLayout.CENTER); } - panel.validate(); - panel.repaint(); + clientPanel.validate(); + clientPanel.repaint(); getGameWindow().init(); } }); @@ -187,23 +168,23 @@ } }); - addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { - public void handle(NewClientRole event) { - Identifier receivedClientId = event.getRoleObj().getClientId(); - //System.out.println("Broadcast ID : "+receivedClientId); - if(dataModel.getId().equals(receivedClientId)) { - int[] roles = event.getRoleObj().getClientRoles(); - //System.out.println("Setting my role"); - dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); - dataModel.setMonitorId(event.getRoleObj().getMoniterId()); - //System.out.println("New role for the client : "+dataModel.getMyRole()); - gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); +// addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { +// public void handle(NewClientRole event) { +// Identifier receivedClientId = event.getRoleObj().getClientId(); +// //System.out.println("Broadcast ID : "+receivedClientId); +// if(dataModel.getId().equals(receivedClientId)) { +// int[] roles = event.getRoleObj().getClientRoles(); +// //System.out.println("Setting my role"); +// dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); +// dataModel.setMonitorId(event.getRoleObj().getMoniterId()); +// //System.out.println("New role for the client : "+dataModel.getMyRole()); +// gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); +// +// // Utils.notify(GameWindow2D.clientRoleSignal); +// } +// } +// }); - // Utils.notify(GameWindow2D.clientRoleSignal); - } - } - }); - addEventProcessor(new EventTypeProcessor<EndRoundEvent>(EndRoundEvent.class) { public void handle(final EndRoundEvent event) { if (state == ClientState.RUNNING) { @@ -280,8 +261,8 @@ gameWindow2D.displayVotedEnforcement(); } }); - addEventProcessor(new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { - public void handle(final RegulationEvent regulationEvent) { + addEventProcessor(new EventTypeProcessor<RegulationSubmissionUpdateEvent>(RegulationSubmissionUpdateEvent.class) { + public void handle(final RegulationSubmissionUpdateEvent regulationEvent) { dataModel.setRegulation(regulationEvent.getMessage()); } }); @@ -470,7 +451,7 @@ client.connect(); frame.setTitle("Client Window: " + client.getId()); frame.setSize(defaultDimension); - frame.add(client.panel); + frame.add(client.clientPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 06:54:23 UTC (rev 399) @@ -747,12 +747,6 @@ // by the server no new clients can connect because the round // has begun. update(configuration.getRoundDuration().getTimeLeft()); - - //if(configuration.isChatEnabled()){ - if(configuration.isSanctioningEnabled()){ - displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); - - } add(messagePanel, BorderLayout.SOUTH); addCenterComponent(subjectWindow); @@ -894,14 +888,9 @@ } public void displayVotedEnforcement(){ - //new code - // System.out.println("*****Inside display voting enforcement"); + // TODO: reimplement SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below enforcement has been voted from the voting conducting earlier<br><br>" + - "<b>"+getEnforcementPanel().getVotedEnforcementOptions(votedEnforcement.getResultIndex())+ - "</b><br><br>This is your role for the next round <br><br><b>"+roleDescription[client.getDataModel().getMyRole()]+"</b>"); - remove(enforcementPanel); addCenterComponent(instructionsScrollPane); startEnforcementDisplayTimer(); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 06:54:23 UTC (rev 399) @@ -185,11 +185,6 @@ return getSanctionCost() * getSanctionMultiplier(); } - public int getSanctionPenalty(int option) { - if (option == 1) return getSanctionCost() * getSanctionMultiplier(); - else return (getSanctionCost() * 1); - } - public SanctionType getSanctionType() { return SanctionType.find(getProperty("sanction-type", "none")); } Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/MonitorTaxEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -0,0 +1,29 @@ +package edu.asu.commons.foraging.event; + +import java.util.Map; + +import edu.asu.commons.event.AbstractPersistableEvent; +import edu.asu.commons.net.Identifier; + +public class MonitorTaxEvent extends AbstractPersistableEvent { + + private static final long serialVersionUID = -3191310440517697158L; + + private Map<Identifier, Integer> monitorTaxes; + private int totalMonitorTax; + + public MonitorTaxEvent(Identifier id, Map<Identifier, Integer> monitorTaxes, int totalMonitorTax) { + super(id); + this.monitorTaxes = monitorTaxes; + this.totalMonitorTax = totalMonitorTax; + } + + public Map<Identifier, Integer> getMonitorTaxes() { + return monitorTaxes; + } + + public int getTotalMonitorTax() { + return totalMonitorTax; + } + +} Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java 2009-12-04 06:54:23 UTC (rev 399) @@ -1,35 +0,0 @@ -//package edu.asu.commons.event; -package edu.asu.commons.foraging.event; - -import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.ClientRole; -import edu.asu.commons.net.Identifier; - - -/** - * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ - * - * Sent from the server to all clients about the - * updated vote stats - * @author <a href='db...@as...'>Deepak Barge</a> - * @version $Revision: 49 $ - */ - -public class NewClientRole extends AbstractEvent { - - private static final long serialVersionUID = 475300882222383637L; - - private ClientRole clientRole; - - public NewClientRole(Identifier id) { - super(id); - } - - public void setRoleObj(ClientRole clientRole) { - this.clientRole = clientRole; - } - - public ClientRole getRoleObj() { - return this.clientRole; - } -} Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -1,28 +0,0 @@ -//package edu.asu.commons.event; -package edu.asu.commons.foraging.event; - -import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.RegulationData; -import edu.asu.commons.net.Identifier; - - -/** - * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ - * - * Sent from the server to all clients about the updated vote stats. - * - * @author <a href='db...@as...'>Deepak Barge</a> - * @version $Revision: 49 $ - */ - -public class RegulationEvent extends AbstractEvent { - - private static final long serialVersionUID = 475300882222383637L; - - public RegulationEvent(Identifier id, RegulationData[] regulations) { - super(id); - - } - - -} Copied: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java (from rev 398, foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java) =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationSubmissionUpdateEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -0,0 +1,35 @@ +//package edu.asu.commons.event; +package edu.asu.commons.foraging.event; + +import java.util.List; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.model.RegulationData; +import edu.asu.commons.net.Identifier; + + +/** + * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ + * + * Sent from the server to all clients about the updated vote stats. + * + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 49 $ + */ + +public class RegulationSubmissionUpdateEvent extends AbstractEvent { + + private static final long serialVersionUID = 475300882222383637L; + + private List<RegulationData> submittedRegulations; + + public RegulationSubmissionUpdateEvent(Identifier id, List<RegulationData> submittedRegulations) { + super(id); + this.submittedRegulations = submittedRegulations; + } + + public List<RegulationData> getSubmittedRegulations() { + return submittedRegulations; + } + +} Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationUpdateEvent.java 2009-12-04 06:54:23 UTC (rev 399) @@ -0,0 +1,33 @@ +//package edu.asu.commons.event; +package edu.asu.commons.foraging.event; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.model.RegulationData; +import edu.asu.commons.net.Identifier; + + +/** + * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ + * + * Sent from the server to all clients about the selected regulation data. + * + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 49 $ + */ + +public class RegulationUpdateEvent extends AbstractEvent { + + private static final long serialVersionUID = 475300882222383637L; + + private RegulationData regulationData; + + public RegulationUpdateEvent(Identifier id, RegulationData regulationData) { + super(id); + this.regulationData = regulationData; + } + + public RegulationData getRegulationData() { + return regulationData; + } + +} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 06:54:23 UTC (rev 399) @@ -37,8 +37,6 @@ private ForagingRole foragingRole = ForagingRole.HARVEST; - private ClientRole clientRole; - private double totalIncome; private int totalTokens; private int currentTokens; @@ -60,7 +58,11 @@ private double viewSubjectsRadius; private double viewTokensRadius; - // this is only used in the Rotating Monitor enforcement mechanism. + // only needed if this client has already received a tax. + private boolean taxReceived = false; + + + // this is only used in the Rotating Monitor enforcement mechanism. private int tokensCollectedDuringInterval = 0; public ClientData(Identifier id) { @@ -116,6 +118,14 @@ } } + public boolean isSanctioningAllowed() { + return foragingRole != null && foragingRole.isSanctioningAllowed(); + } + + public boolean isHarvestingAllowed() { + return foragingRole != null && foragingRole.isHarvestingAllowed(); + } + public boolean isSubjectInFieldOfVision(Point subjectPosition) { Circle circle = getSubjectsFieldOfVision(); if (circle == null) { @@ -179,24 +189,10 @@ subtractTokens(sanctionPenalty); } else if (sanctionAction.equals("freeze")) { - freeze( roundConfiguration.getSanctionPenalty(1) ); + freeze( roundConfiguration.getSanctionPenalty() ); } } - public void sanctionPenalty(int option) { - RoundConfiguration roundConfiguration = getGroupDataModel().getRoundConfiguration(); - String sanctionAction = roundConfiguration.getSanctionAction(); - if (sanctionAction.equals("fine")) { - final int sanctionPenalty = roundConfiguration.getSanctionPenalty(option); - sanctionPenalties += sanctionPenalty; - subtractTokens(sanctionPenalty); - } - else if (sanctionAction.equals("freeze")) { - freeze( roundConfiguration.getSanctionPenalty(option) ); - } - - } - /** * If this ClientData is already frozen, this method returns false and does nothing. * If not, sets or resets the freeze duration for this ClientData and returns true. @@ -290,6 +286,8 @@ public void reset() { resetCurrentTokens(); resetLatestSanctions(); + foragingRole = ForagingRole.HARVEST; + taxReceived = false; } public void resetLatestSanctions() { @@ -348,14 +346,6 @@ this.enforcementData = enforcementData; } - public void setClientRole(ClientRole clientRole){ - this.clientRole = clientRole; - } - - public ClientRole getClientRole(){ - return clientRole; - } - // FIXME: generalize for arbitrary clients per group. public Point3D generate3DPosition() { // float x = assignedNumber * getGroupDataModel().getCurrentConfiguration().getWorldWidth() / getGroupDataModel().getNumberOfClients() + 1; @@ -563,4 +553,13 @@ public void setEnforcementRankings(int[] enforcementRankings) { this.enforcementRankings = enforcementRankings; } + + public boolean isTaxReceived() { + return taxReceived; + } + + public void setTaxReceived() { + this.taxReceived = true; + } + } Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-04 06:54:23 UTC (rev 399) @@ -1,63 +0,0 @@ -package edu.asu.commons.foraging.model; - -import java.io.Serializable; - -import edu.asu.commons.net.Identifier; - -/** - * - * $Id: RegulationData.java 117 2009-04-21 17:26:20Z dbarge $ - * - * - * @author <a href='mailto:db...@as...'>dbarge</a> - * @version $Revision: 117 $ - */ - -public class ClientRole implements Serializable { - - private static final long serialVersionUID = 5281922601551921005L; - - private int roles[]; - - private Identifier id; - - private Identifier moniterId; - - private int roleNo; - - public ClientRole() {} - - public int[] getClientRoles(){ - return roles; - } - - public void setClientRoles(int roles[]){ - this.roles = roles; - } - - public Identifier getClientId(){ - return id; - } - - public void setClientId(Identifier id){ - this.id = id; - } - - public Identifier getMoniterId(){ - return moniterId; - } - - public void setMoniterId(Identifier moniterId){ - this.moniterId = moniterId; - } - - - public int getRoleNo(){ - return roleNo; - } - - public void setRoleNo(int roleNo){ - this.roleNo = roleNo; - } - -} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java 2009-12-04 06:54:23 UTC (rev 399) @@ -24,8 +24,12 @@ return this == MONITOR; } - public boolean canSanction() { + public boolean isSanctioningAllowed() { return this != HARVEST; } + + public boolean isHarvestingAllowed() { + return this != MONITOR; + } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 06:54:23 UTC (rev 399) @@ -19,6 +19,7 @@ import edu.asu.commons.foraging.event.ClientPositionUpdateEvent; import edu.asu.commons.foraging.event.EnforcementRankingRequest; import edu.asu.commons.foraging.event.LockResourceRequest; +import edu.asu.commons.foraging.event.MonitorTaxEvent; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.RegulationRankingRequest; import edu.asu.commons.foraging.event.SubmitRegulationRequest; @@ -64,9 +65,12 @@ private volatile int receivedRegulationRankings = 0; private EnforcementMechanism activeEnforcementMechanism = EnforcementMechanism.NONE; + private RegulationData activeRegulation; private List<ClientData> waitingMonitors; + private ClientData activeMonitor; + private int tokensCollectedDuringInterval = 0; private ArrayList<RegulationData> submittedRegulations = new ArrayList<RegulationData>(); @@ -118,18 +122,44 @@ return clients.size(); } - public void rotateMonitor() { + public boolean rotateMonitorIfNecessary() { if (activeEnforcementMechanism.isRotatingMonitor() && ! waitingMonitors.isEmpty()) { - for (ClientData clientData: clients.values()) { - if (clientData.isMonitor()) { - // this is the active monitor, give them 25% of the take. - } - clientData.setForagingRole(ForagingRole.HARVEST); - } - ClientData nextMonitor = waitingMonitors.remove(0); - nextMonitor.setForagingRole(ForagingRole.MONITOR); + applyMonitorTax(); + // set active monitor back to harvest + activeMonitor.setForagingRole(ForagingRole.HARVEST); + if (waitingMonitors.isEmpty()) { + logger.warning("no waiting monitors left but still trying to rotate: " + activeMonitor); + return false; + } + else { + activeMonitor = waitingMonitors.remove(0); + activeMonitor.setForagingRole(ForagingRole.MONITOR); + return true; + } } + return false; } + + public RegulationData generateRegulationRankings() { + resetRegulationRankingCount(); + double[] regulationVotingTally = new double[submittedRegulations.size()]; + Arrays.fill(regulationVotingTally, 0.0d); + int maxRankingIndex = 0; + double maxRankingValue = 0.0d; + for (ClientData clientData : clients.values()) { + int[] regulationRankings = clientData.getRegulationRankings(); + for (int index = 0; index < regulationRankings.length; index++) { + regulationVotingTally[index] += rankToValue(regulationRankings[index]); + if (regulationVotingTally[index] > maxRankingValue) { + maxRankingValue = regulationVotingTally[index]; + maxRankingIndex = index; + } + } + } + activeRegulation = submittedRegulations.get(maxRankingIndex); + logger.info("active regulation: " + activeRegulation.getText()); + return activeRegulation; + } public EnforcementMechanism generateEnforcementRankings() { resetEnforcementRankingCount(); @@ -156,8 +186,8 @@ ArrayList<ClientData> clientDataList = new ArrayList<ClientData>(clients.values()); Collections.shuffle(clientDataList); // pick the first client from the shuffled list and set their role to MONITOR - ClientData monitor = clientDataList.remove(0); - monitor.setForagingRole(ForagingRole.MONITOR); + activeMonitor = clientDataList.remove(0); + activeMonitor.setForagingRole(ForagingRole.MONITOR); // set the rest of the clients to the HARVEST role for (ClientData clientData : clientDataList) { clientData.setForagingRole(ForagingRole.HARVEST); @@ -178,6 +208,10 @@ receivedEnforcementRankings = 0; } + private void resetRegulationRankingCount() { + receivedRegulationRankings = 0; + } + public boolean hasReceivedAllEnforcementRankings() { return receivedEnforcementRankings >= clients.size(); } @@ -215,6 +249,7 @@ tokensCollectedDuringInterval = 0; activeEnforcementMechanism = EnforcementMechanism.NONE; submittedRegulations.clear(); + activeMonitor = null; } public void clearResourceDistribution() { @@ -579,6 +614,7 @@ public String toString() { return "Group #" + groupId; } + @Override public int compareTo(GroupDataModel other) { return Long.valueOf(groupId).compareTo(other.groupId); @@ -595,8 +631,13 @@ } public void submitRegulationRanking(RegulationRankingRequest request) { - + clients.get(request.getId()).setRegulationRankings(request.getRankings()); + receivedRegulationRankings++; } + + public boolean isRotatingMonitor() { + return activeEnforcementMechanism != null && activeEnforcementMechanism.isRotatingMonitor(); + } public boolean hasReceivedAllRegulationRankings() { return receivedRegulationRankings >= clients.size(); @@ -605,5 +646,30 @@ public List<RegulationData> getSubmittedRegulations() { return submittedRegulations; } + + public void applyMonitorTax() { + if (activeMonitor == null) { + logger.severe("Trying to apply monitor tax for null monitor."); + return; + } + if (activeMonitor.isTaxReceived()) { + logger.severe("active monitor: " + activeMonitor + " already received tax."); + return; + } + ArrayList<ClientData> clientDataList = new ArrayList<ClientData>(clients.values()); + clientDataList.remove(activeMonitor); + Map<Identifier, Integer> monitorTaxes = new HashMap<Identifier, Integer>(); + int totalTax = 0; + for (ClientData clientData : clientDataList) { + int monitorTax = clientData.applyMonitorTax(); + totalTax += monitorTax; + activeMonitor.addTokens(monitorTax); + monitorTaxes.put(clientData.getId(), monitorTax); + } + logger.info("active monitor: " + activeMonitor + " received tax: " + totalTax); + activeMonitor.setTaxReceived(); + // persist monitor tax + serverDataModel.getEventChannel().handle(new MonitorTaxEvent(activeMonitor.getId(), monitorTaxes, totalTax)); + } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java 2009-12-04 06:54:23 UTC (rev 399) @@ -70,6 +70,10 @@ return text.hashCode() ^ id.hashCode() * (rank + 34); } + public String toString() { + return text; + } + public int compareTo(RegulationData regulationData) { int comparison = Integer.valueOf(rank).compareTo(regulationData.rank); if (comparison == 0) { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 02:28:43 UTC (rev 398) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 06:54:23 UTC (rev 399) @@ -42,12 +42,13 @@ import edu.asu.commons.foraging.event.HarvestResourceRequest; import edu.asu.commons.foraging.event.LockResourceEvent; import edu.asu.commons.foraging.event.LockResourceRequest; -import edu.asu.commons.foraging.event.NewClientRole; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.QuizCompletedEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; import edu.asu.commons.foraging.event.RegulationRankingRequest; +import edu.asu.commons.foraging.event.RegulationSubmissionUpdateEvent; +import edu.asu.commons.foraging.event.RegulationUpdateEvent; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; @@ -55,10 +56,10 @@ import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.event.UnlockResourceRequest; import edu.asu.commons.foraging.model.ClientData; -import edu.asu.commons.foraging.model.ClientRole; import edu.asu.commons.foraging.model.Direction; import edu.asu.commons.foraging.model.EnforcementMechanism; import edu.asu.commons.foraging.model.GroupDataModel; +import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.foraging.model.ResourceDispenser; import edu.asu.commons.foraging.model.ServerDataModel; import edu.asu.commons.foraging.util.ForagingSaveFileConverter; @@ -116,7 +117,8 @@ private volatile int numberOfCompletedQuizzes; private volatile int numberOfCompletedSanctions; private volatile int numberOfCompletedAgentDesigns; - private volatile int clientToken; + + private int monitorRotationInterval; private Duration currentRoundDuration; // private Duration chatDuration; @@ -295,6 +297,7 @@ } } }); + addEventProcessor(new EventTypeProcessor<SubmitRegulationRequest>(SubmitRegulationRequest.class) { public void handle(final SubmitRegulationRequest request) { GroupDataModel group = serverDataModel.getGroup(request.getId()); @@ -389,9 +392,6 @@ addEventProcessor(new EventTypeProcessor<RealTimeSanctionRequest>(RealTimeSanctionRequest.class) { @Override public void handleInExperimentThread(final RealTimeSanctionRequest request) { - System.out.println("received sanctioning request"); - ClientData targetClient = clients.get(request.getTarget()); - ClientData sourceClient = clients.get(request.getSource()); // validate request // a user can sanction iff the following hold: // 1. sanctioning is enabled or they are the monitor @@ -444,13 +444,16 @@ } private void sendRegulationUpdate(GroupDataModel group) { - // TODO: implement me + for (Identifier id: group.getClientIdentifiers()) { + transmit(new RegulationSubmissionUpdateEvent(id, group.getSubmittedRegulations())); + } } + private void sendRegulationRankingUpdate(GroupDataModel group) { - EnforcementMechanism enforcementMechanism = group.generateEnforcementRankings(); + RegulationData regulationData = group.generateRegulationRankings(); for (Identifier id: group.getClientIdentifiers()) { - transmit(new EnforcementMechanismUpdateEvent(id, enforcementMechanism)); + transmit(new RegulationUpdateEvent(id, regulationData)); } } @@ -464,84 +467,115 @@ private void handleEnforcementSanctionRequest(RealTimeSanctionRequest request) { ClientData sourceClient = clients.get(request.getSource()); ClientData targetClient = clients.get(request.getTarget()); - if (sourceClient.isMonitor()) { - // monitor can always sanction regardless of if they have enough tokens. - if (targetClient.getCurrentTokens() == 0) { - // nothing to take, so sanctioning has no effect. - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Ignoring token reduction request: # %d does not have any tokens to reduce.", targetClient.getAssignedNumber()))); - return; + + GroupDataModel group = sourceClient.getGroupDataModel(); + if (! group.equals(targetClient.getGroupDataModel())) { + logger.severe("source client and target client groups are different: " + sourceClient + targetClient); + return; + } + EnforcementMechanism enforcementMechanism = group.getActiveEnforcementMechanism(); + switch (enforcementMechanism) { + case EVERYONE_CAN_SANCTION: + handleRealTimeSanctionRequest(request); + break; + case RANDOM_MONITOR: + case ROTATING_MONITOR: + if (sourceClient.isMonitor()) { + // monitor can always sanction regardless of if they have enough tokens. + if (targetClient.getCurrentTokens() == 0) { + // nothing to take, so sanctioning has no effect. + transmit(new ClientMessageEvent(sourceClient.getId(), + String.format("Ignoring token reduction request: # %d does not have any tokens to reduce.", targetClient.getAssignedNumber()))); + return; + } + // monitors don't get any sanction costs. + targetClient.sanctionPenalty(); + // add sanction request to the target client so they can figure out who just sanctioned them + targetClient.getLatestSanctions().add(request); + transmit(new ClientMessageEvent(sourceClient.getId(), + String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , + getCurrentRoundConfiguration().getSanctionPenalty(), + targetClient.getAssignedNumber()))); + transmit(new ClientMessageEvent(targetClient.getId(), + String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty()))); } - + break; + case NONE: + default: + logger.severe("tried to sanction with EnforcementMechanism.NONE"); } - int srcEnforcementType = sourceClient.getEnforcementData().getResultIndex(); - int tgtEnforcementType = targetClient.getEnforcementData().getResultIndex(); - if(srcEnforcementType == tgtEnforcementType) { - System.out.println("This condition should be always true"); - switch(srcEnforcementType) { - /* - * No sanctioning just harvest - */ case NO_SANCTIONS: - System.out.println("This code should never be reached"); - - break; - - /* - * Harvest and sanction - * Reduce other by 2 but also own by 1 - */ - case HARVEST_WITH_SANCTION: - sourceClient.sanctionCost(); - targetClient.sanctionPenalty(1); - // add sanction request to the target client so they can figure out who just sanctioned them - targetClient.getLatestSanctions().add(request); - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Subtracting %d tokens from # %d at the cost of %d to yourself." , - getCurrentRoundConfiguration().getSanctionPenalty(1), - targetClient.getAssignedNumber(), - getCurrentRoundConfiguration().getSanctionCost()))); - transmit(new ClientMessageEvent(targetClient.getId(), - String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(1)))); - break; - - - /* - * One participant is a moniter who sanctions but cannot harvest - * Moniter can give penalty by subtract 1 from sanctionee - * Nothing taken from Moniter but receives 25% tokens from each - */ case RANDOM_SANCTIONER: - //sourceClient.sanctionCost(); - targetClient.sanctionPenalty(0); - // add sanction request to the target client so they can figure out who just sanctioned them - targetClient.getLatestSanctions().add(request); - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , - getCurrentRoundConfiguration().getSanctionPenalty(0), - targetClient.getAssignedNumber()))); - transmit(new ClientMessageEvent(targetClient.getId(), - String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(0)))); - break; - - /* - * Harvest and sanction for 48 secs in sequence - * One participant is a moniter who sanctions but cannot harvest - * Moniter can give penalty by subtract 1 from sanctionee - * Nothing taken from Moniter but receives 25% tokens from each - */ case CIRCULAR_MONITERING: - //sourceClient.sanctionCost(); - targetClient.sanctionPenalty(0); - // add sanction request to the target client so they can figure out who just sanctioned them - targetClient.getLatestSanctions().add(request); - transmit(new ClientMessageEvent(sourceClient.getId(), - String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , - getCurrentRoundConfiguration().getSanctionPenalty(0), - targetClient.getAssignedNumber()))); - transmit(new ClientMessageEvent(targetClient.getId(), - String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(0)))); - break; - } - } + // TODO: reimplement +// +// +// int srcEnforcementType = sourceClient.getEnforcementData().getResultIndex(); +// int tgtEnforcementType = targetClient.getEnforcementData().getResultIndex(); +// +// if(srcEnforcementType == tgtEnforcementType) { +// System.out.println("This condition should be always true"); +// switch(srcEnforcementType) { +// /* +// * No sanctioning just harvest +// */ case NO_SANCTIONS: +// System.out.println("This code should never be reached"); +// +// break; +// +// /* +// * Harvest and sanction +// * Reduce other by 2 but also own by 1 +// */ +// case HARVEST_WITH_SANCTION: +// sourceClient.sanctionCost(); +// targetClient.monitorSanctionPenalty(1); +// // add sanction request to the target client so they can figure out who just sanctioned them +// targetClient.getLatestSanctions().add(request); +// transmit(new ClientMessageEvent(sourceClient.getId(), +// String.format("Subtracting %d tokens from # %d at the cost of %d to yourself." , +// getCurrentRoundConfiguration().getSanctionPenalty(1), +// targetClient.getAssignedNumber(), +// getCurrentRoundConfiguration().getSanctionCost()))); +// transmit(new ClientMessageEvent(targetClient.getId(), +// String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(1)))); +// break; +// +// +// /* +// * One participant is a moniter who sanctions but cannot harvest +// * Moniter can give penalty by subtract 1 from sanctionee +// * Nothing taken from Moniter but receives 25% tokens from each +// */ case RANDOM_SANCTIONER: +// //sourceClient.sanctionCost(); +// targetClient.monitorSanctionPenalty(0); +// // add sanction request to the target client so they can figure out who just sanctioned them +// targetClient.getLatestSanctions().add(request); +// transmit(new ClientMessageEvent(sourceClient.getId(), +// String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , +// getCurrentRoundConfiguration().getSanctionPenalty(0), +// targetClient.getAssignedNumber()))); +// transmit(new ClientMessageEvent(targetClient.getId(), +// String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty(0)))); +// break; +// +// /* +// * Harvest and sanction for 48 secs in sequence +// * One participant is a moniter who sanctions but cannot harvest +// * Moniter can give penalty by subtract 1 from sanctionee +// * Nothing taken from Moniter but receives 25% tokens from each +// */ case CIRCULAR_MONITERING: +// //sourceClient.sanctionCost(); +// targetClient.monitorSanctionPenalty(0); +// // add sanction request to the target client so they can figure out who just sanctioned them +// targetClient.getLatestSanctions().add(request); +// transmit(new ClientMessageEvent(sourceClient.getId(), +// String.format("Subtracting %d tokens from # %d at the cost of 0 to yourself." , +// getCurrentRoundConfiguration().getSanctionPenalty(), +// targetClient.getAssignedNumber()))); +// transmit(new ClientMessageEvent(targetClient.getId(), +// String.format("# %d subtracted %d tokens from you.", sourceClient.getAssignedNumber(), getCurrentRoundConfiguration().getSanctionPenalty()))); +// break; +// } +// } } private void handleRealTimeSanctionRequest(RealTimeSanctionRequest request) { @@ -653,50 +687,49 @@ // FIXME: handle reconfiguration requests from facilitator } - private double getRank(int rankNo) { - double actualRank = 0; - if (rankNo == 0) actualRank=1; - if (rankNo == 1) actualRank=0.5; - if (rankNo == 2) actualRank=0.33; - if (rankNo == 3) actualRank=0.25; - if (rankNo == 4) actualRank=0.2; - return actualRank; - } +// private double getRank(int rankNo) { +// double actualRank = 0; +// if (rankNo == 0) actualRank=1; +// if (rankNo == 1) actualRank=0.5; +// if (rankNo == 2) actualRank=0.33; +// if (rankNo == 3) actualRank=0.25; +// if (rankNo == 4) actualRank=0.2; +// return actualRank; +// } +// +// private int findMax(double voteArray[], int loopCount) +// { +// double max = voteArray[0]; +// int i=0; +// int index=0; +// for(i=0 ; i < loopCount ; i++) +// { +// if(voteArray[i] > max) +// { +// index = i; +// max = voteArray[i]; +// } +// } +// return index; +// } - private int findMax(double voteArray[], int loopCount) - { - double max = voteArray[0]; - int i=0; - int index=0; - for(i=0 ; i < loopCount ; i++) - { - if(voteArray[i] > max) - { - index = i; - max = voteArray[i]; - } - } - return index; - } +// private void sendNewRolesToClients(Identifier id, int roles[]) { +// ClientRole clientRole = new ClientRole(); +// clientRole.setClientRoles(roles); +// int i = 0; +// for (Identifier targetId : clients.get(id).getGroupDataModel().getClientIdentifiers()) { +// NewClientRole newClientRole = new NewClientRole(targetId); +// clientRole.setClientId(targetId); +// clientRole.setRoleNo(i); +// if(roles[i] == MONITER)clientRole.setMoniterId(targetId); +// clients.get(targetId).setClientRole(clientRole); +// newClientRole.setRoleObj(clientRole); +// transmit(newClientRole); +// getLogger().info("transmitted timesliced client roles"); +// i++; +// } +// } - // FIXME: refactor later - private void sendNewRolesToClients(Identifier id, int roles[]) { - ClientRole clientRole = new ClientRole(); - clientRole.setClientRoles(roles); - int i = 0; - for (Identifier targetId : clients.get(id).getGroupDataModel().getClientIdentifiers()) { - NewClientRole newClientRole = new NewClientRole(targetId); - clientRole.setClientId(targetId); - clientRole.setRoleNo(i); - if(roles[i] == MONITER)clientRole.setMoniterId(targetId); - clients.get(targetId).setClientRole(clientRole); - newClientRole.setRoleObj(clientRole); - transmit(newClientRole); - getLogger().info("transmitted timesliced client roles"); - i++; - } - } - // private int [] findClientRoles(GroupDataModel group, int index) { // int roles [] = new int [MAX_CLIENTS_PER_GROUP]; // int i; @@ -824,7 +857,7 @@ // perform token adjustment if needed. for (GroupDataModel group: serverDataModel.getGroups()) { if (group.getActiveEnforcementMechanism().hasMonitor()) { - // check for monitor status + group.applyMonitorTax(); } } stopRound(); @@ -916,10 +949,22 @@ } serverDataModel.clearDiffLists(); } - + private void processRound2d() { boolean secondHasPassed = secondTick.hasExpired(); if (secondHasPassed) { + if (currentRoundDuration.getElapsedTimeInSeconds() % monitorRotationInterval == 0) { + for (GroupDataModel group: serverDataModel.getGroups()) { + boolean rotated = group.rotateMonitorIfNecessary(); + if (rotated) { + // send new roles to all clients + for (ClientData clientData : group.getClientDataMap().values()) { + transmit(new SynchronizeClientEvent(clientData, currentRoundDuration.getTimeLeft())); + } + } + + } + } resourceDispenser.generateResources(); secondTick.restart(); } @@ -928,9 +973,6 @@ // ask each client if it wants to grab a token, wherever it is. clientData.collectToken(); } - if (getCurrentRoundConfiguration().isVotingAndRegulationEnabled() && group.getActiveEnforcementMechanism().isRotatingMonitor()) { - - } } for (ClientData clientData : clients.values()) { @@ -1089,6 +1131,10 @@ // start timers currentRoundDuration = roundConfiguration.getRoundDuration(); + if (roundConfiguration.isVotingAndRegulationEnabled()) { + monitorRotationInterval = currentRoundDuration.getElapsedTimeInSeconds() / roundConfiguration.getClientsPerGroup(); + logger.info("monitor rotation interval: " + monitorRotationInterval); + } currentRoundDuration.start(); transmit(new FacilitatorUpdateEvent(facilitatorId, serverDataModel, currentRoundDuration.getTimeLeft())); ... [truncated message content] |
From: <al...@us...> - 2009-12-04 02:28:50
|
Revision: 398 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=398&view=rev Author: alllee Date: 2009-12-04 02:28:43 +0000 (Fri, 04 Dec 2009) Log Message: ----------- getting rid of mobile resource-generator from configuration more refactoring on server side, still incomplete. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ServerDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-04 02:28:43 UTC (rev 398) @@ -427,6 +427,7 @@ private class SixChoicePanel implements ActionListener{ //String title; String [] buttonLabels; + // the index of the regulation that is being rendered in this panel int regulationID; int currentRanking; JPanel regulationPanel; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java 2009-12-04 02:28:43 UTC (rev 398) @@ -338,15 +338,15 @@ public void displayDebriefing(FacilitatorEndRoundEvent event) { Map<Identifier, ClientData> clientDataMap = event.getClientDataMap(); - StringBuilder buffer = new StringBuilder(); - buffer.append(String.format("<h3>Round %d Results</h3>", facilitator.getCurrentRoundConfiguration().getRoundNumber())); - buffer.append("<table><thead><th>Participant</th><th>Current tokens</th><th>Current Income</th><th>Total Income</th></thead><tbody>"); + StringBuilder builder = new StringBuilder(); + builder.append(String.format("<h3>Round %d Results</h3>", facilitator.getCurrentRoundConfiguration().getRoundNumber())); + builder.append("<table><thead><th>Participant</th><th>Current tokens</th><th>Current Income</th><th>Total Income</th></thead><tbody>"); TreeSet<Identifier> orderedSet = new TreeSet<Identifier>(clientDataMap.keySet()); for (Identifier clientId : orderedSet) { ClientData data = clientDataMap.get(clientId); // FIXME: hack... inject the configuration into the client data so that getIncome() will return something appropriate. // should just refactor getIncome or remove it from ClientData entirely. - buffer.append(String.format( + builder.append(String.format( "<tr><td>%s</td>" + "<td align='center'>%d</td>" + "<td align='center'>$%3.2f</td>" + @@ -356,11 +356,11 @@ getIncome(data.getCurrentTokens()), data.getTotalIncome() + facilitator.getServerConfiguration().getShowUpFee())); } - buffer.append("</tbody></table><hr>"); + builder.append("</tbody></table><hr>"); if (event.isLastRound()) { - buffer.append("<h2><font color='blue'>The experiment is over. Please prepare payments.</font></h2>"); + builder.append("<h2><font color='blue'>The experiment is over. Please prepare payments.</font></h2>"); } - informationEditorPane.setText(buffer.toString()); + informationEditorPane.setText(builder.toString()); // switchCenterComponent(viewPane, informationPanel); //startRoundMenuItem.setEnabled(true); showInstructionsMenuItem.setEnabled(true); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 02:28:43 UTC (rev 398) @@ -60,6 +60,8 @@ private double viewSubjectsRadius; private double viewTokensRadius; + // this is only used in the Rotating Monitor enforcement mechanism. + private int tokensCollectedDuringInterval = 0; public ClientData(Identifier id) { this.id = id; @@ -92,7 +94,7 @@ */ public int getCurrentTokens() { return currentTokens; - } + } public void addTokens(int tokens) { currentTokens += tokens; @@ -102,6 +104,7 @@ totalTokens += tokens; totalIncome += (tokens * configuration.getDollarsPerToken()); } + tokensCollectedDuringInterval += tokens; } public Circle getSubjectsFieldOfVision() { @@ -137,6 +140,12 @@ addTokens(1); } + public int applyMonitorTax() { + int monitorTax = tokensCollectedDuringInterval / 4; + subtractTokens(monitorTax); + return monitorTax; + } + // used for post round sanctioning public synchronized void postRoundSanctionCost(int cost) { sanctionCosts += Math.abs(cost); @@ -280,13 +289,13 @@ */ public void reset() { resetCurrentTokens(); - if (getGroupDataModel().getRoundConfiguration().isRealTimeSanctioningEnabled()) { - resetLatestSanctions(); - } + resetLatestSanctions(); } public void resetLatestSanctions() { - latestSanctions.clear(); + if (latestSanctions != null) { + latestSanctions.clear(); + } } private void resetCurrentTokens() { @@ -294,7 +303,12 @@ sanctionBonuses = 0; sanctionPenalties = 0; sanctionCosts = 0; + tokensCollectedDuringInterval = 0; } + + public void resetTokensCollectedDuringInterval() { + tokensCollectedDuringInterval = 0; + } public int getAssignedNumber() { return assignedNumber; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java 2009-12-04 02:28:43 UTC (rev 398) @@ -5,6 +5,8 @@ NONE("No enforcement", "Everybody can harvest. Nobody can subtract tokens from others"), EVERYONE_CAN_SANCTION("Everybody can reduce", "Every participant can reduce the tokens of other participants by pressing the number key associated with that participant."), RANDOM_MONITOR("Random monitor", "Randomly, one of the participants is selected to be the monitoring participant. This participant cannot harvest but can subtract tokens from other participants by pressing the number key associated with that participant. At the end of the round each harvesting participant pays 25% of their earned tokens to the monitoring participant."), + // after (round duration / # of clients) seconds + // each monitor receives 25% of the tokens collected during their monitoring time. ROTATING_MONITOR("Rotating monitor", "Each participant is given an equal amount of time to be a monitor, with the ability to reduce the tokens of other participants by pressing the number key associated with that participant."); private final String title; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 02:28:43 UTC (rev 398) @@ -17,8 +17,11 @@ import edu.asu.commons.experiment.DataModel; import edu.asu.commons.foraging.conf.RoundConfiguration; import edu.asu.commons.foraging.event.ClientPositionUpdateEvent; +import edu.asu.commons.foraging.event.EnforcementRankingRequest; import edu.asu.commons.foraging.event.LockResourceRequest; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; +import edu.asu.commons.foraging.event.RegulationRankingRequest; +import edu.asu.commons.foraging.event.SubmitRegulationRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.foraging.event.TokenCollectedEvent; import edu.asu.commons.foraging.event.UnlockResourceRequest; @@ -58,16 +61,16 @@ private volatile static long nextGroupId = 0; private volatile int receivedEnforcementRankings = 0; - private volatile int numberOfReceivedRegulations = 0; + private volatile int receivedRegulationRankings = 0; private EnforcementMechanism activeEnforcementMechanism = EnforcementMechanism.NONE; private List<ClientData> waitingMonitors; + + private int tokensCollectedDuringInterval = 0; -// private List<Regulation> regulationSubmissions; + private ArrayList<RegulationData> submittedRegulations = new ArrayList<RegulationData>(); -// private transient float averageTokens = -1; - public GroupDataModel(ServerDataModel serverDataModel) { this(serverDataModel, nextGroupId++); } @@ -118,6 +121,9 @@ public void rotateMonitor() { if (activeEnforcementMechanism.isRotatingMonitor() && ! waitingMonitors.isEmpty()) { for (ClientData clientData: clients.values()) { + if (clientData.isMonitor()) { + // this is the active monitor, give them 25% of the take. + } clientData.setForagingRole(ForagingRole.HARVEST); } ClientData nextMonitor = waitingMonitors.remove(0); @@ -168,10 +174,6 @@ return activeEnforcementMechanism; } - public int addEnforcementRanking() { - return receivedEnforcementRankings++; - } - private void resetEnforcementRankingCount() { receivedEnforcementRankings = 0; } @@ -179,15 +181,19 @@ public boolean hasReceivedAllEnforcementRankings() { return receivedEnforcementRankings >= clients.size(); } - - public int incrRegulationCount() { - return numberOfReceivedRegulations++; + + public void submitRegulationRequest(SubmitRegulationRequest request) { + Identifier id = request.getId(); + ClientData clientData = clients.get(id); + RegulationData submittedRegulation = new RegulationData(id, request.getMessage()); + clientData.setRegulationData(submittedRegulation); + submittedRegulations.add(submittedRegulation); } - public void resetRegulationCount() { - numberOfReceivedRegulations = 0; + public boolean hasReceivedAllRegulations() { + return submittedRegulations.size() >= clients.size(); } - + /** * Used to reset the food distribution for a client during a practice * round. @@ -201,6 +207,16 @@ resourceDistribution.clear(); } + /** + * Perform all cleanup. + */ + public void cleanupRound() { + clearResourceDistribution(); + tokensCollectedDuringInterval = 0; + activeEnforcementMechanism = EnforcementMechanism.NONE; + submittedRegulations.clear(); + } + public void clearResourceDistribution() { resourceDistribution.clear(); clearDiffLists(); @@ -367,6 +383,7 @@ Point position = clientData.getPoint(); if (resourceDistribution.containsKey(position)) { getRemovedResources().add( resourceDistribution.remove(position) ); + tokensCollectedDuringInterval++; clientData.addToken(); serverDataModel.getEventChannel().handle(new TokenCollectedEvent(clientData.getId(), position)); } @@ -398,7 +415,7 @@ public void clear() { clients.clear(); - clearResourceDistribution(); + cleanupRound(); } public boolean isResourceDistributionEmpty() { @@ -571,4 +588,22 @@ return activeEnforcementMechanism; } + public void submitEnforcementRanking(EnforcementRankingRequest request) { + ClientData clientData = clients.get(request.getId()); + clientData.setEnforcementRankings(request.getRankings()); + receivedEnforcementRankings++; + } + + public void submitRegulationRanking(RegulationRankingRequest request) { + + } + + public boolean hasReceivedAllRegulationRankings() { + return receivedRegulationRankings >= clients.size(); + } + + public List<RegulationData> getSubmittedRegulations() { + return submittedRegulations; + } + } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ServerDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ServerDataModel.java 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ServerDataModel.java 2009-12-04 02:28:43 UTC (rev 398) @@ -166,9 +166,9 @@ } - public void clearResourceDistribution() { + public void cleanupRound() { for (GroupDataModel group: clientsToGroups.values()) { - group.clearResourceDistribution(); + group.cleanupRound(); } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 02:28:43 UTC (rev 398) @@ -278,28 +278,30 @@ // FIXME: start new implementation here. addEventProcessor(new EventTypeProcessor<EnforcementRankingRequest>(EnforcementRankingRequest.class) { public void handle(final EnforcementRankingRequest request) { - ClientData clientData = clients.get(request.getId()); - GroupDataModel groupDataModel = clientData.getGroupDataModel(); - clientData.setEnforcementRankings(request.getRankings()); - groupDataModel.addEnforcementRanking(); - if (groupDataModel.hasReceivedAllEnforcementRankings()) { - EnforcementMechanism enforcementMechanism = groupDataModel.generateEnforcementRankings(); - for (Identifier id: groupDataModel.getClientIdentifiers()) { - transmit(new EnforcementMechanismUpdateEvent(id, enforcementMechanism)); - } + GroupDataModel group = serverDataModel.getGroup(request.getId()); + group.submitEnforcementRanking(request); + if (group.hasReceivedAllEnforcementRankings()) { + sendEnforcementUpdate(group); } - } }); + addEventProcessor(new EventTypeProcessor<RegulationRankingRequest>(RegulationRankingRequest.class) { public void handle(final RegulationRankingRequest request) { - - + GroupDataModel group = serverDataModel.getGroup(request.getId()); + group.submitRegulationRanking(request); + if (group.hasReceivedAllRegulationRankings()) { + sendRegulationRankingUpdate(group); + } } }); addEventProcessor(new EventTypeProcessor<SubmitRegulationRequest>(SubmitRegulationRequest.class) { public void handle(final SubmitRegulationRequest request) { - + GroupDataModel group = serverDataModel.getGroup(request.getId()); + group.submitRegulationRequest(request); + if (group.hasReceivedAllRegulations()) { + sendRegulationUpdate(group); + } } }); @@ -441,6 +443,24 @@ }); } + private void sendRegulationUpdate(GroupDataModel group) { + // TODO: implement me + + } + private void sendRegulationRankingUpdate(GroupDataModel group) { + EnforcementMechanism enforcementMechanism = group.generateEnforcementRankings(); + for (Identifier id: group.getClientIdentifiers()) { + transmit(new EnforcementMechanismUpdateEvent(id, enforcementMechanism)); + } + } + + private void sendEnforcementUpdate(GroupDataModel group) { + EnforcementMechanism enforcementMechanism = group.generateEnforcementRankings(); + for (Identifier id: group.getClientIdentifiers()) { + transmit(new EnforcementMechanismUpdateEvent(id, enforcementMechanism)); + } + } + private void handleEnforcementSanctionRequest(RealTimeSanctionRequest request) { ClientData sourceClient = clients.get(request.getSource()); ClientData targetClient = clients.get(request.getTarget()); @@ -803,15 +823,14 @@ if (currentRoundDuration.hasExpired()) { // perform token adjustment if needed. for (GroupDataModel group: serverDataModel.getGroups()) { - if (group.getActiveEnforcementMechanism().isRandomMonitor()) { - // this is + if (group.getActiveEnforcementMechanism().hasMonitor()) { + // check for monitor status } } stopRound(); break; } - - + roundProcessor.execute(); Utils.sleep(SERVER_SLEEP_INTERVAL); break; @@ -979,7 +998,7 @@ } private void cleanupRound() { - serverDataModel.clearResourceDistribution(); + serverDataModel.cleanupRound(); for (ClientData clientData: clients.values()) { clientData.reset(); } Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml 2009-12-04 02:28:43 UTC (rev 398) @@ -8,7 +8,6 @@ <entry key="private-property">true</entry> <entry key="duration">240</entry> -<entry key='resource-generator'>mobile</entry> <entry key='tokens-field-of-vision'>true</entry> <entry key='subjects-field-of-vision'>true</entry> @@ -16,12 +15,12 @@ <entry key='initial-distribution'>.25</entry> <entry key='always-explicit'>true</entry> -<entry key='enforcement-option1'>Everybody can harvest</entry> - <entry key="quiz">true</entry> <entry key="q1">C</entry> <entry key="q2">B</entry> + + <entry key="instructions"> <![CDATA[ <h3>General Instructions</h3> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml 2009-12-04 02:28:43 UTC (rev 398) @@ -8,7 +8,6 @@ <entry key="resource-depth">29</entry> <entry key="resource-width">29</entry> -<entry key='resource-generator'>mobile</entry> <entry key='tokens-field-of-vision'>true</entry> <entry key='subjects-field-of-vision'>true</entry> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml 2009-12-04 02:28:43 UTC (rev 398) @@ -8,7 +8,6 @@ <entry key="resource-depth">29</entry> <entry key="resource-width">29</entry> -<entry key='resource-generator'>mobile</entry> <entry key='tokens-field-of-vision'>true</entry> <entry key='subjects-field-of-vision'>true</entry> @@ -18,6 +17,9 @@ <entry key="initial-distribution">.25</entry> <entry key="regrowth-rate">0.01</entry> +<entry key="chat-enabled">true</entry> +<entry key='voting-and-regulation-enabled'>true</entry> + <entry key="instructions"> <![CDATA[ <h3>Round 2 Instructions</h3> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml 2009-12-04 02:28:43 UTC (rev 398) @@ -8,7 +8,6 @@ <entry key="resource-depth">29</entry> <entry key="resource-width">29</entry> -<entry key='resource-generator'>mobile</entry> <entry key='tokens-field-of-vision'>true</entry> <entry key='subjects-field-of-vision'>true</entry> @@ -19,13 +18,8 @@ <entry key="initial-distribution">.25</entry> <entry key="regrowth-rate">0.01</entry> -<!-- -<entry key="patchy">true</entry> -<entry key="top-initial-distribution">0.50</entry> -<entry key="top-rate">0.02</entry> -<entry key="bottom-initial-distribution">0.25</entry> -<entry key="bottom-rate">0.01</entry> ---> +<entry key="chat-enabled">true</entry> +<entry key='voting-and-regulation-enabled'>true</entry> <entry key="instructions"> <![CDATA[ Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml 2009-12-04 02:28:43 UTC (rev 398) @@ -8,7 +8,6 @@ <entry key="resource-width">29</entry> <entry key="duration">240</entry> -<entry key='resource-generator'>mobile</entry> <entry key='tokens-field-of-vision'>true</entry> <entry key='subjects-field-of-vision'>true</entry> @@ -17,6 +16,7 @@ <!-- before this round begins, we have a chat session --> <entry key="chat-enabled">true</entry> +<entry key='voting-and-regulation-enabled'>true</entry> <!-- enable sanctioning --> <entry key="sanction-type">real-time</entry> Modified: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml 2009-12-04 01:07:37 UTC (rev 397) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml 2009-12-04 02:28:43 UTC (rev 398) @@ -8,8 +8,6 @@ <entry key="resource-width">29</entry> <entry key="duration">240</entry> -<!-- enable mobile offspring-generating resource --> -<entry key='resource-generator'>mobile</entry> <!-- enable field of vision for tokens and subjects --> <entry key='tokens-field-of-vision'>true</entry> <entry key='subjects-field-of-vision'>true</entry> @@ -27,6 +25,7 @@ <!-- before this round begins, we have a chat session --> <entry key="chat-enabled">true</entry> +<entry key='voting-and-regulation-enabled'>true</entry> <entry key="instructions"> <![CDATA[ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <db...@us...> - 2009-12-04 01:07:49
|
Revision: 397 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=397&view=rev Author: dbarge Date: 2009-12-04 01:07:37 +0000 (Fri, 04 Dec 2009) Log Message: ----------- Made changes in the EnforcementPanel.java to get rid of the timers to update the GUI (enforcement panel) Changed the look of the enforcement panel with more meaning GUI components with the help from Seema Changed the use of colors for the panels. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/TestEnforcement.java Added: foraging/branches/deepak-branch-fall-09/src/main/java/TestEnforcement.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/TestEnforcement.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/TestEnforcement.java 2009-12-04 01:07:37 UTC (rev 397) @@ -0,0 +1,33 @@ +import java.awt.Color; +import java.awt.Container; +import java.awt.FlowLayout; + +import javax.swing.JFrame; + +import edu.asu.commons.foraging.client.EnforcementPanel; + + +public class TestEnforcement { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + //ForagingClient client = new ForagingClient(); + + EnforcementPanel testEnforcement = new EnforcementPanel(); + testEnforcement.initialize(); + JFrame f = new JFrame("This is a test"); + f.setSize(1000, 1000); + Container content = f.getContentPane(); + content.setBackground(Color.white); + content.setLayout(new FlowLayout()); + content.add(testEnforcement); + //f.setDefaultCloseOperation(0); + f.setVisible(true); + + + } + +} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-03 22:06:12 UTC (rev 396) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 01:07:37 UTC (rev 397) @@ -7,8 +7,7 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; +import java.util.HashMap; import java.util.Map; import javax.swing.BorderFactory; @@ -16,13 +15,13 @@ import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JEditorPane; -import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.ScrollPaneConstants; import javax.swing.Timer; -import javax.swing.text.html.HTMLEditorKit; import edu.asu.commons.foraging.event.EnforcementRankingRequest; import edu.asu.commons.foraging.model.EnforcementData; @@ -55,11 +54,6 @@ } - public static int currentActive; - - public static int currentLabel; - - private static String[] HANDLES; private String[] votes = { "1", "2", "3","4"}; private String[] enforcementOptions = { "No Enforcement - Click here for more info ", @@ -93,60 +87,71 @@ private Identifier clientId; private JPanel votingPanel; - private JPanel informationPanel; - private JLabel label; private JButton reset; private JButton sendMyVotes; private JPanel instructionsPanel; - private Timer timer; private SixChoicePanel[] newPanel; private int noOfEnforcements; - private String message; - private int currentRankingInformation[]; private JPanel buttonPanel; private EnforcementData votedEnforcement; - private JScrollPane enforcementInstructionsScrollPane; - - private JEditorPane enforcementInstructionsPane; - public EnforcementData getVotedEnforcement(){ return this.votedEnforcement; } + public EnforcementPanel () + { + enforcements = new HashMap<Identifier, EnforcementData>(); + newPanel = new SixChoicePanel[4]; + noOfEnforcements = 4; + } public String getVotedEnforcementOptions(int index){ return this.enforcementText[index]; } - private void updateInstructionPanel(){ - enforcementInstructionsPane.setText(enforcementText[currentLabel]); - invalidate(); - validate(); - instructionsPanel.repaint(); - repaint(); - //pack(); - // setVisible(true); - } + private JPanel getInstructionPanel(String instructions) + { + JPanel instructionPanel = new JPanel(); + //instructionPanel.setBackground(color); + instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); + instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); + + //create Text area and JSCroll pane for it - private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; + JTextArea instructionText = new JTextArea(instructions,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + instructionPanel.add(scrollForRegulationText); + + return instructionPanel; + + } + + private Color getColor(int i) + { + Color color = null; + if(i==0) color = new Color(153,153,204); + if(i==1) color = new Color(204,153,153); + if(i==2) color = new Color(153,204,102); + if(i==3) color = new Color(204,204,102); + if(i==4) color = new Color(255,255,153); + return color; + } + + private void updateVotingPanel(int currentActive){ + int r,c,i; SixChoicePanel temp = null; boolean enableSendButton = true; - // System.out.println("No of enfrments: "+noOfEnforcements); - // System.out.println("Current active :"+currentActive); - + for(r = 0; r < noOfEnforcements; r++) { - // System.out.print(newPanel[r].currentRanking+" "); - + if(newPanel[r].currentRanking == -1)enableSendButton = false; if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) @@ -180,65 +185,29 @@ // System.out.print(newPanel[c].getCurrentRanking() +" "); } - // votingPanel.setVisible(false); - // remove(votingPanel); + votingPanel.setVisible(false); + remove(votingPanel); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + votingPanel.add(getInstructionPanel("This is instruction panel")); - for(i=0; i < noOfEnforcements; i++) { - votingPanel.add(newPanel[i].enforcementPanel); - votingPanel.add(newPanel[i].rankPanel); - } - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); + for(i=0; i < noOfEnforcements; i++) { + votingPanel.add(newPanel[i].enforcementPanel); + } - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); - revalidate(); + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + revalidate(); } - public void stopTimer(){ - timer.stop(); - } - - public void startTimer(){ - if (timer == null) { - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } - }); - timer.start(); - } - } - - private Color getColor(int i) { - switch (i) { - case 0: - return Color.GREEN; - case 1: - return Color.LIGHT_GRAY; - case 2: - return Color.orange; - case 3: - return Color.red; - case 4: - return Color.cyan; - default: - return Color.MAGENTA; - } - } - private String getVoteString(){ StringBuilder sb = new StringBuilder(); @@ -266,37 +235,26 @@ // remove(enforcementInstructionsScrollPane); // remove(messageScrollPane); this.currentRankingInformation = new int[4]; - this.timer=null; this.newPanel = new SixChoicePanel[4]; setBackground(Color.lightGray); setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - informationPanel = new JPanel(); - informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); - informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); - label = new JLabel("You have 30 seconds left to vote the enforcements"); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - informationPanel.add(label); + //add the instruction panel as the first panel in voting panel. + instructionsPanel = getInstructionPanel("This is instruction panel"); + votingPanel.add(instructionsPanel); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Information")); - // EnforcementData enforcementData; - // System.out.println("No of enfrments: "+noOfEnforcements); for(int i=0; i<noOfEnforcements; i++) { - //System.out.println("Added : "+(i+1)); - StringBuilder sb = new StringBuilder(); - sb.append(enforcementOptions[i]); - String s = sb.toString(); - + //newPanel[i] = new SixChoicePanel(s, votes, enforcementData.getEnforcementID(), getColor(i)); //newPanel[i] = new SixChoicePanel(s, votes, client.getEnforcementID(), getColor(i)); - newPanel[i] = new SixChoicePanel(s, votes, i, getColor(i)); + newPanel[i] = new SixChoicePanel(enforcementOptions[i], votes, i, getColor(i)); votingPanel.add(newPanel[i].getEnforcementPanel(i)); - votingPanel.add(newPanel[i].getRankPanel(i)); } add(votingPanel, BorderLayout.CENTER); @@ -343,43 +301,23 @@ buttonPanel.setVisible(true); buttonPanel.repaint(); add(buttonPanel, BorderLayout.SOUTH); - - instructionsPanel = new JPanel(); - instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); - instructionsPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Instructions")); - - enforcementInstructionsPane = new JEditorPane(); - enforcementInstructionsPane.setContentType("text/html"); - enforcementInstructionsPane.setEditorKit(new HTMLEditorKit()); - enforcementInstructionsPane.setEditable(false); - // regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); - enforcementInstructionsScrollPane = new JScrollPane(enforcementInstructionsPane); - - //FIXME: Need to fetch the regulation instructions over here - //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getChatInstructions()); - enforcementInstructionsPane.setText("This is the place of enforcement detailed information"); - instructionsPanel.add(enforcementInstructionsScrollPane); - - // add(instructionsPanel, BorderLayout.CENTER); - add(instructionsPanel, BorderLayout.EAST); } public void initialize() { initGuiComponents(); } - private class SixChoicePanel implements ActionListener, MouseListener{ - String title; - String [] buttonLabels; - int enforcementID; - int currentRanking; - JPanel enforcementPanel; - JPanel rankPanel; - JLabel enforcementLabel; - ButtonGroup group; - JRadioButton option []; - Color color; - // static int currentActive; + private class SixChoicePanel implements ActionListener{ + String title; + String [] buttonLabels; + int enforcementID; + int currentRanking; + JPanel enforcementPanel; + JPanel rankPanel; + ButtonGroup group; + JRadioButton option []; + Color color; + public SixChoicePanel(String title, String[] buttonLabels, int enforcementID, Color color ) { this.title = title; this.buttonLabels = buttonLabels; @@ -392,56 +330,47 @@ return enforcementID; } - public void mouseClicked(MouseEvent arg0) { } + public void actionPerformed(ActionEvent e) { + String choice = group.getSelection().getActionCommand(); + int buttonNo = Integer.parseInt(choice); + System.out.println("ACTION Choice Selected: " + choice); + System.out.println("Bno: " + buttonNo); + System.out.println("CurrentActive : "+this.enforcementID); + this.currentRanking = buttonNo; + updateVotingPanel(this.enforcementID); + } - public void mouseEntered(MouseEvent arg0) { } + + public JPanel getEnforcementPanel(int i){ + enforcementPanel = new JPanel(); + enforcementPanel.setBackground(color); + enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); + enforcementPanel.setBorder(BorderFactory.createTitledBorder("Enforcement "+(i+1))); - public void mouseExited(MouseEvent arg0) { } + //create Text area and JSCroll pane for it - public void mousePressed(MouseEvent arg0) { - currentLabel = this.enforcementID; - // System.out.println("Label No:"+currentLabel); - } + JTextArea regulationText = new JTextArea(title,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(regulationText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + enforcementPanel.add(scrollForRegulationText); - public void mouseReleased(MouseEvent arg0){ } + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length - public void actionPerformed(ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - // System.out.println("ACTION Choice Selected: " + choice); - // System.out.println("Bno: " + buttonNo); - this.currentRanking = buttonNo; - EnforcementPanel.currentActive = this.enforcementID; - } + for(int j=0; j<length; j++) { + option[j] = new JRadioButton(buttonLabels[j]); + option[j].setActionCommand(buttonLabels[j]); + group.add(option[j]); + option[j].addActionListener(this); + rankPanel.add(option[j]); + } + enforcementPanel.add(rankPanel); + return enforcementPanel; + } - public JPanel getRankPanel(int clientNo){ - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length - for(int i=0; i<length; i++) { - option[i] = new JRadioButton(buttonLabels[i]); - option[i].setActionCommand(buttonLabels[i]); - group.add(option[i]); - option[i].addActionListener(this); - rankPanel.add(option[i]); - } + } - return rankPanel; - } - public JPanel getEnforcementPanel(int i){ - enforcementPanel = new JPanel(); - enforcementPanel.setBackground(color); - enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); - enforcementPanel.setBorder(BorderFactory.createTitledBorder("Enforcement "+(i+1))); - enforcementLabel = new JLabel(title); - enforcementLabel.addMouseListener(this); - enforcementPanel.add(enforcementLabel); - return enforcementPanel; - } - - } - } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 22:06:12 UTC (rev 396) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 01:07:37 UTC (rev 397) @@ -321,7 +321,7 @@ timer.stop(); timer = null; //remove(sanctioningPanel); - getEnforcementPanel().stopTimer(); + //getEnforcementPanel().stopTimer(); getEnforcementPanel().sendEnforcementVotes(); //displayEnforcementWaitMessage(); @@ -1012,7 +1012,7 @@ enforcementPanel.initialize(); remove(instructionsScrollPane); addCenterComponent(enforcementPanel); - enforcementPanel.startTimer(); + // enforcementPanel.startTimer(); startEnforcementVotingTimer(); } }); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 22:06:12 UTC (rev 396) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-04 01:07:37 UTC (rev 397) @@ -205,6 +205,7 @@ { // System.out.print(newPanel[c].getCurrentRanking() +" "); } + votingPanel.setVisible(false); remove(votingPanel); votingPanel = new JPanel(); @@ -264,9 +265,7 @@ private Color getColor(int i) { Color color = null; - //if(i==0) color = Color.lightGray; if(i==0) color = new Color(153,153,204); - //if(i==1) color=Color.green; if(i==1) color = new Color(204,153,153); if(i==2) color = new Color(153,204,102); if(i==3) color = new Color(204,204,102); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-03 22:06:33
|
Revision: 396 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=396&view=rev Author: alllee Date: 2009-12-03 22:06:12 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Heavily refactoring the way regulations and enforcement information is managed on the server side and passed back and forth to the client side. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EmbeddedChatPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java Removed Paths: ------------- foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRequest.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationRequest.java Property Changed: ---------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java 2009-12-03 22:06:12 UTC (rev 396) @@ -1,36 +0,0 @@ -import java.awt.Color; -import java.awt.Container; -import java.awt.FlowLayout; - -import javax.swing.JFrame; - -import edu.asu.commons.foraging.client.ForagingClient; -import edu.asu.commons.foraging.client.SanctioningPanel; - - -public class TestSanction { - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - //ForagingClient client = new ForagingClient(); - - SanctioningPanel testsanctioning = new SanctioningPanel(); - testsanctioning.initialize(); - //testsanctioning.getdata(); - testsanctioning.initRegulationVotingCompontents(); - JFrame f = new JFrame("This is a test"); - f.setSize(1000, 1000); - Container content = f.getContentPane(); - content.setBackground(Color.white); - content.setLayout(new FlowLayout()); - content.add(testsanctioning); - //f.setDefaultCloseOperation(0); - f.setVisible(true); - - - } - -} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-03 22:06:12 UTC (rev 396) @@ -42,7 +42,7 @@ private int role; - private Identifier moniterId; + private Identifier monitorId; private static final int MONITOR = 0; private static final int HARVEST = 1; @@ -79,14 +79,18 @@ return this.role; } - public void setMoniterId (Identifier moniterId) { - this.moniterId = moniterId; + public void setMonitorId (Identifier moniterId) { + this.monitorId = moniterId; } - public Identifier getMoniterId() { - return this.moniterId; + public Identifier getMonitorId() { + return this.monitorId; } + public void setRegulation(String regulation) { + + } + public boolean isSanctioningAllowed(){ System.out.println("My Role : "+getMyRole()); /* Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EmbeddedChatPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EmbeddedChatPanel.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EmbeddedChatPanel.java 2009-12-03 22:06:12 UTC (rev 396) @@ -34,7 +34,7 @@ /** * $Id$ * - * Chat panel used to communicate with other players. + * Chat panel used to communicate with other players within the 3D foraging visualization. * * FIXME: randomize mappings from handle (e.g., A -> 1, B -> 2, C -> 3 ...) so that it's * not linear. Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-03 22:06:12 UTC (rev 396) @@ -9,9 +9,6 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import java.util.Map; import javax.swing.BorderFactory; @@ -24,22 +21,12 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; -import javax.swing.JTextPane; import javax.swing.Timer; -import javax.swing.UIManager; -import javax.swing.text.BadLocationException; -import javax.swing.text.Style; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyleContext; -import javax.swing.text.StyledDocument; import javax.swing.text.html.HTMLEditorKit; -import edu.asu.commons.event.EventTypeProcessor; -import edu.asu.commons.foraging.event.EnforcementEvent; -import edu.asu.commons.foraging.event.EnforcementRequest; +import edu.asu.commons.foraging.event.EnforcementRankingRequest; import edu.asu.commons.foraging.model.EnforcementData; import edu.asu.commons.net.Identifier; -import edu.asu.commons.util.Utils; @@ -58,63 +45,52 @@ public class EnforcementPanel extends JPanel { private ForagingClient client; - + private Map<Identifier, EnforcementData> enforcements; - + public EnforcementPanel (ForagingClient client) { - this.noOfEnforcements = 4; + this.noOfEnforcements = 4; this.client = client; this.clientId = client.getId(); - client.getEventChannel().add(this, new EventTypeProcessor<EnforcementEvent>(EnforcementEvent.class) { - public void handle(final EnforcementEvent enforcementEvent) { - enforcements = enforcementEvent.getAllEnforcements(); - System.out.println("Enforcement received : "+enforcements.size()); - noOfEnforcements = enforcements.size(); - for (Identifier targetId : enforcements.keySet()) { - votedEnforcement = enforcements.get(targetId); - } - Utils.notify(GameWindow2D.enforcementVotesSignal); - } - }); + } - private Identifier targetIdentifier = Identifier.ALL; - - private final static String HANDLE_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - public static int currentActive; - + public static int currentLabel; private static String[] HANDLES; private String[] votes = { "1", "2", "3","4"}; private String[] enforcementOptions = { - "No Enforcement - Click here for more info ", - "Everyone sanctions - Click here for more info ", - "Randomly picked monitering - Click here for more info", - "Random sanctioning - Click here for more info " - }; + "No Enforcement - Click here for more info ", + "Everyone sanctions - Click here for more info ", + "Randomly picked monitering - Click here for more info", + "Random sanctioning - Click here for more info " + }; private String[] enforcementText = { - "Everybody can harvest. Nobody can subtract tokens<br>" + - "from others<br>", - "Each participant can reduce the token amount of<br>" + - "another participant by two tokens at a cost of <br>" + - "one by pressing the numeric key that identifies<br>" + - "the other participant.<br>", - "Randomly one of the participants is selected to<br>" + - "be the monitoring participant. This participant<br>" + - "can not harvest, but can force another particip<br>" + - "ant to pay a token to the monitoring participan<br>" + - "by pressing the responding numeric key. At the <br>" + - "end of the round each participant who could har<br>" + - "vest pays 25% of the earning to the monitoring <br>" + - "participant.<br>", - "Same as two, but now each participant takes turns<br>" + - "of 48 seconds randomly assigned by the computer.<br>" - }; + "Everybody can harvest. Nobody can subtract tokens<br>" + + "from others<br>", - + "Each participant can reduce the token amount of<br>" + + "another participant by two tokens at a cost of <br>" + + "one by pressing the numeric key that identifies<br>" + + "the other participant.<br>", + + "Randomly one of the participants is selected to<br>" + + "be the monitoring participant. This participant<br>" + + "can not harvest, but can force another particip<br>" + + "ant to pay a token to the monitoring participan<br>" + + "by pressing the responding numeric key. At the <br>" + + "end of the round each participant who could har<br>" + + "vest pays 25% of the earning to the monitoring <br>" + + "participant.<br>", + + "Same as two, but now each participant takes turns<br>" + + "of 48 seconds randomly assigned by the computer.<br>" + }; + + private Identifier clientId; private JPanel votingPanel; private JPanel informationPanel; @@ -126,274 +102,215 @@ private SixChoicePanel[] newPanel; private int noOfEnforcements; - + private String message; - + private int currentRankingInformation[]; - private JScrollPane messageScrollPane; - private JPanel buttonPanel; - + private EnforcementData votedEnforcement; private JScrollPane enforcementInstructionsScrollPane; - private JTextPane messageWindow; - private List<Identifier> participants; - private JEditorPane enforcementInstructionsPane; - - private void addStylesToMessageWindow() { - StyledDocument styledDocument = messageWindow.getStyledDocument(); - // and why not have something like... StyleContext.getDefaultStyle() to - // replace this junk - Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( - StyleContext.DEFAULT_STYLE); - // Style regularStyle = styledDocument.addStyle("regular", - // defaultStyle); - StyleConstants.setFontFamily(defaultStyle, "Helvetica"); - StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), - true); - StyleConstants.setItalic(styledDocument - .addStyle("italic", defaultStyle), true); - } - public EnforcementData getVotedEnforcement(){ - return this.votedEnforcement; + return this.votedEnforcement; } public String getVotedEnforcementOptions(int index){ - return this.enforcementText[index]; + return this.enforcementText[index]; } - + private void updateInstructionPanel(){ - enforcementInstructionsPane.setText(enforcementText[currentLabel]); + enforcementInstructionsPane.setText(enforcementText[currentLabel]); invalidate(); validate(); instructionsPanel.repaint(); repaint(); - //pack(); - // setVisible(true); + //pack(); + // setVisible(true); } - + private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; - SixChoicePanel temp = null; - boolean enableSendButton = true; - - // System.out.println("No of enfrments: "+noOfEnforcements); - // System.out.println("Current active :"+currentActive); + int r,c,i,j; + int currentRanking; + SixChoicePanel temp = null; + boolean enableSendButton = true; - for(r = 0; r < noOfEnforcements; r++) - { - // System.out.print(newPanel[r].currentRanking+" "); - - if(newPanel[r].currentRanking == -1)enableSendButton = false; - - if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) - { - newPanel[r].currentRanking = -1; - newPanel[r].group.clearSelection(); - } - } - - - for(r = 0; r < noOfEnforcements-1; r++) - { - for(c = 0; c < noOfEnforcements-1; c++) - { - if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - } - } - for(c = 0; c < noOfEnforcements; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } - - // votingPanel.setVisible(false); - // remove(votingPanel); + // System.out.println("No of enfrments: "+noOfEnforcements); + // System.out.println("Current active :"+currentActive); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + for(r = 0; r < noOfEnforcements; r++) + { + // System.out.print(newPanel[r].currentRanking+" "); - - for(i=0; i < noOfEnforcements; i++) { - votingPanel.add(newPanel[i].enforcementPanel); - votingPanel.add(newPanel[i].rankPanel); - } - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); + if(newPanel[r].currentRanking == -1)enableSendButton = false; - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } - - invalidate(); - validate(); - votingPanel.repaint(); - buttonPanel.repaint(); - repaint(); - } - + if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) + { + newPanel[r].currentRanking = -1; + newPanel[r].group.clearSelection(); + } + } + + + for(r = 0; r < noOfEnforcements-1; r++) + { + for(c = 0; c < noOfEnforcements-1; c++) + { + if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + } + } + for(c = 0; c < noOfEnforcements; c++) + { + // System.out.print(newPanel[c].getCurrentRanking() +" "); + } + + // votingPanel.setVisible(false); + // remove(votingPanel); + + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + + + for(i=0; i < noOfEnforcements; i++) { + votingPanel.add(newPanel[i].enforcementPanel); + votingPanel.add(newPanel[i].rankPanel); + } + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); + + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + + revalidate(); + } + public void stopTimer(){ - timer.stop(); + timer.stop(); } - + public void startTimer(){ - if (timer == null) { + if (timer == null) { timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } + //timer.stop(); + //timer = null; + // System.out.println("Timer called to update the voting panel:"); + updateVotingPanel(); + updateInstructionPanel(); + } }); timer.start(); - } + } } - private Color getColor(int i) - { - Color color = null; - if(i==0) color=Color.green; - if(i==1) color=Color.lightGray; - if(i==2) color=Color.blue; - if(i==3) color=Color.red; - if(i==4) color=Color.cyan; - return color; + private Color getColor(int i) { + switch (i) { + case 0: + return Color.GREEN; + case 1: + return Color.LIGHT_GRAY; + case 2: + return Color.orange; + case 3: + return Color.red; + case 4: + return Color.cyan; + default: + return Color.MAGENTA; + } } - + private String getVoteString(){ - - StringBuilder sb = new StringBuilder(); - for(int c = 0; c < noOfEnforcements; c++) - { - sb.append("\nEnforcement "+(newPanel[c].getCurrentRanking()+1)); - } - return(sb.toString()); - } + StringBuilder sb = new StringBuilder(); - public void sendEnforcementVotes() { - - System.out.println("Enforcement Votes ready to be sent"); - // System.err.println("message: " + message); - int i; - for(i=0; i < noOfEnforcements; i++) { - if(newPanel[i].currentRanking == -1) - this.currentRankingInformation[i] = -1; - else - this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); - } - - /* - for(i=0 ; i<5 ; i++) - { - System.out.println(currentRankingInformation[i]); - } - */ - - EnforcementData enforcementData = new EnforcementData(); - enforcementData.setCurrentRankingInformation(this.currentRankingInformation); - //enforcementData.setenforcementText(message); - - // System.out.println("ID:"+client.getEnforcementID()); - //enforcementData.setEnforcementID(client.getEnforcementID()); - enforcementData.setEnforcementID(client.getToken()); - - client.transmit(new EnforcementRequest(clientId, message, enforcementData)); - // displayMessage(getEnforcementHandle(clientId) + " -> " - // + getEnforcementHandle(targetIdentifier), message); - - + for(int c = 0; c < noOfEnforcements; c++) + { + sb.append("\nEnforcement "+(newPanel[c].getCurrentRanking()+1)); + } + return(sb.toString()); } - - public void resetHandles() { - HANDLES = null; - } - private String getEnforcementHandle(Identifier source) { - if (source.equals(Identifier.ALL)) { - return "all"; + public void sendEnforcementVotes() { + int i; + for(i=0; i < noOfEnforcements; i++) { + if(newPanel[i].currentRanking == -1) + this.currentRankingInformation[i] = -1; + else + this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); } - else { - String enforcementHandle = HANDLES[participants.indexOf(source)]; - if (source.equals(clientId)) { - return enforcementHandle.concat(" (you)"); - } - return enforcementHandle; - } + client.transmit(new EnforcementRankingRequest(clientId, currentRankingInformation)); } + public void initGuiComponents(){ - // remove(enforcementInstructionsScrollPane); - // remove(messageScrollPane); + // remove(enforcementInstructionsScrollPane); + // remove(messageScrollPane); this.currentRankingInformation = new int[4]; this.timer=null; this.newPanel = new SixChoicePanel[4]; - new WindowUtilities().setNativeLookAndFeel(); setBackground(Color.lightGray); setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - + informationPanel = new JPanel(); informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); label = new JLabel("You have 30 seconds left to vote the enforcements"); informationPanel.add(label); - + votingPanel = new JPanel(); votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); votingPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Information")); - - - // EnforcementData enforcementData; - // System.out.println("No of enfrments: "+noOfEnforcements); + + // EnforcementData enforcementData; + // System.out.println("No of enfrments: "+noOfEnforcements); + for(int i=0; i<noOfEnforcements; i++) { - //System.out.println("Added : "+(i+1)); - StringBuilder sb = new StringBuilder(); - sb.append(enforcementOptions[i]); - String s = sb.toString(); - - //newPanel[i] = new SixChoicePanel(s, votes, enforcementData.getEnforcementID(), getColor(i)); - //newPanel[i] = new SixChoicePanel(s, votes, client.getEnforcementID(), getColor(i)); - newPanel[i] = new SixChoicePanel(s, votes, i, getColor(i)); - votingPanel.add(newPanel[i].getEnforcementPanel(i)); - votingPanel.add(newPanel[i].getRankPanel(i)); - } + //System.out.println("Added : "+(i+1)); + StringBuilder sb = new StringBuilder(); + sb.append(enforcementOptions[i]); + String s = sb.toString(); + //newPanel[i] = new SixChoicePanel(s, votes, enforcementData.getEnforcementID(), getColor(i)); + //newPanel[i] = new SixChoicePanel(s, votes, client.getEnforcementID(), getColor(i)); + newPanel[i] = new SixChoicePanel(s, votes, i, getColor(i)); + votingPanel.add(newPanel[i].getEnforcementPanel(i)); + votingPanel.add(newPanel[i].getRankPanel(i)); + } + add(votingPanel, BorderLayout.CENTER); reset = new JButton("Reset All Ranks"); reset.setAlignmentX(Component.CENTER_ALIGNMENT); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - for(int i=0; i<noOfEnforcements; i++) { - for(int j=0; j<noOfEnforcements; j++) { - newPanel[i].option[j].setEnabled(true); - newPanel[i].group.clearSelection(); - newPanel[i].currentRanking = -1; - } - } + for(int i=0; i<noOfEnforcements; i++) { + for(int j=0; j<noOfEnforcements; j++) { + newPanel[i].option[j].setEnabled(true); + newPanel[i].group.clearSelection(); + newPanel[i].currentRanking = -1; + } + } } }); sendMyVotes = new JButton("Send votes"); @@ -401,19 +318,19 @@ sendMyVotes.setEnabled(false); sendMyVotes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - + int n = JOptionPane.showConfirmDialog( null, "Are you sure to submit your votes ?"+ "\nBelow is order of your voting" + getVoteString(), "Confirm and send votes", JOptionPane.YES_NO_OPTION); - + if (n == JOptionPane.YES_OPTION) { - GameWindow2D.duration.expire(); + GameWindow2D.duration.expire(); } if (n == JOptionPane.NO_OPTION) { - + } } @@ -426,7 +343,7 @@ buttonPanel.setVisible(true); buttonPanel.repaint(); add(buttonPanel, BorderLayout.SOUTH); - + instructionsPanel = new JPanel(); instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); instructionsPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Instructions")); @@ -435,141 +352,96 @@ enforcementInstructionsPane.setContentType("text/html"); enforcementInstructionsPane.setEditorKit(new HTMLEditorKit()); enforcementInstructionsPane.setEditable(false); -// regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); + // regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); enforcementInstructionsScrollPane = new JScrollPane(enforcementInstructionsPane); //FIXME: Need to fetch the regulation instructions over here //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getChatInstructions()); enforcementInstructionsPane.setText("This is the place of enforcement detailed information"); instructionsPanel.add(enforcementInstructionsScrollPane); - - // add(instructionsPanel, BorderLayout.CENTER); + + // add(instructionsPanel, BorderLayout.CENTER); add(instructionsPanel, BorderLayout.EAST); } - private void displayMessage(String sanctionHandle, String message) { - // String chatHandle = getChatHandle(source); - StyledDocument document = messageWindow.getStyledDocument(); - try { - document.insertString(document.getLength(), sanctionHandle + " : ", - document.getStyle("bold")); - document.insertString(document.getLength(), message + "\n", null); - messageWindow.setCaretPosition(document.getLength()); - } catch (BadLocationException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } - public void initialize() { - - if (HANDLES != null) { - // displayMessage("System message", " --- Round ended --- "); - return; - } - this.participants = client.getDataModel().getAllClientIdentifiers(); - HANDLES = new String[participants.size()]; - List<String> handles = new ArrayList<String>(); - if (client.getDataModel().getRoundConfiguration().isChatAnonymized()) { - for (int i = HANDLES.length; --i >= 0;) { - handles.add(HANDLE_STRING.charAt(i) + ""); - } - Collections.shuffle(handles); - for (int i = 0; i < HANDLES.length; i++) { - HANDLES[i] = handles.get(i); - } - } - else { - for (int i = 0; i < HANDLES.length; i++) { - HANDLES[i] = client.getDataModel().getAssignedNumber(participants.get(i)) + ""; - } - } initGuiComponents(); } private class SixChoicePanel implements ActionListener, MouseListener{ - String title; - String [] buttonLabels; - int enforcementID; - int currentRanking; - JPanel enforcementPanel; - JPanel rankPanel; - JLabel enforcementLabel; - ButtonGroup group; - JRadioButton option []; - Color color; - // static int currentActive; - - public SixChoicePanel(String title, String[] buttonLabels, int enforcementID, Color color ) { - this.title = title; - this.buttonLabels = buttonLabels; - this.enforcementID = enforcementID; - this.color = color; - this.currentRanking = -1; - this.option = new JRadioButton[4]; - } - public int getCurrentRanking(){ - return enforcementID; - } - - public void mouseClicked(MouseEvent arg0) { } + String title; + String [] buttonLabels; + int enforcementID; + int currentRanking; + JPanel enforcementPanel; + JPanel rankPanel; + JLabel enforcementLabel; + ButtonGroup group; + JRadioButton option []; + Color color; + // static int currentActive; - public void mouseEntered(MouseEvent arg0) { } + public SixChoicePanel(String title, String[] buttonLabels, int enforcementID, Color color ) { + this.title = title; + this.buttonLabels = buttonLabels; + this.enforcementID = enforcementID; + this.color = color; + this.currentRanking = -1; + this.option = new JRadioButton[4]; + } + public int getCurrentRanking(){ + return enforcementID; + } - public void mouseExited(MouseEvent arg0) { } + public void mouseClicked(MouseEvent arg0) { } - public void mousePressed(MouseEvent arg0) { - currentLabel = this.enforcementID; - // System.out.println("Label No:"+currentLabel); - } + public void mouseEntered(MouseEvent arg0) { } - public void mouseReleased(MouseEvent arg0){ } + public void mouseExited(MouseEvent arg0) { } - public void actionPerformed(ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - // System.out.println("ACTION Choice Selected: " + choice); - // System.out.println("Bno: " + buttonNo); - this.currentRanking = buttonNo; - EnforcementPanel.currentActive = this.enforcementID; - } + public void mousePressed(MouseEvent arg0) { + currentLabel = this.enforcementID; + // System.out.println("Label No:"+currentLabel); + } - public JPanel getRankPanel(int clientNo){ - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length - for(int i=0; i<length; i++) { - option[i] = new JRadioButton(buttonLabels[i]); - option[i].setActionCommand(buttonLabels[i]); - group.add(option[i]); - option[i].addActionListener(this); - rankPanel.add(option[i]); - } + public void mouseReleased(MouseEvent arg0){ } - return rankPanel; - } - public JPanel getEnforcementPanel(int i){ - enforcementPanel = new JPanel(); - enforcementPanel.setBackground(color); - enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); - enforcementPanel.setBorder(BorderFactory.createTitledBorder("Enforcement "+(i+1))); - enforcementLabel = new JLabel(title); - enforcementLabel.addMouseListener(this); - enforcementPanel.add(enforcementLabel); - return enforcementPanel; - } + public void actionPerformed(ActionEvent e) { + String choice = group.getSelection().getActionCommand(); + int buttonNo = Integer.parseInt(choice); + // System.out.println("ACTION Choice Selected: " + choice); + // System.out.println("Bno: " + buttonNo); + this.currentRanking = buttonNo; + EnforcementPanel.currentActive = this.enforcementID; + } - } - private class WindowUtilities { - public void setNativeLookAndFeel() { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch(Exception e) { - System.out.println("Error setting native LAF: " + e); - } - } - } + public JPanel getRankPanel(int clientNo){ + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length + for(int i=0; i<length; i++) { + option[i] = new JRadioButton(buttonLabels[i]); + option[i].setActionCommand(buttonLabels[i]); + group.add(option[i]); + option[i].addActionListener(this); + rankPanel.add(option[i]); + } + return rankPanel; + } + public JPanel getEnforcementPanel(int i){ + enforcementPanel = new JPanel(); + enforcementPanel.setBackground(color); + enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); + enforcementPanel.setBorder(BorderFactory.createTitledBorder("Enforcement "+(i+1))); + enforcementLabel = new JLabel(title); + enforcementLabel.addMouseListener(this); + enforcementPanel.add(enforcementLabel); + return enforcementPanel; + } + + } + } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-03 22:06:12 UTC (rev 396) @@ -24,11 +24,13 @@ import edu.asu.commons.foraging.event.ClientPositionUpdateEvent; import edu.asu.commons.foraging.event.CollectTokenRequest; import edu.asu.commons.foraging.event.EndRoundEvent; +import edu.asu.commons.foraging.event.EnforcementMechanismUpdateEvent; import edu.asu.commons.foraging.event.LockResourceEvent; import edu.asu.commons.foraging.event.NewClientRole; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; +import edu.asu.commons.foraging.event.RegulationEvent; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; @@ -190,10 +192,10 @@ Identifier receivedClientId = event.getRoleObj().getClientId(); //System.out.println("Broadcast ID : "+receivedClientId); if(dataModel.getId().equals(receivedClientId)) { - int roles [] = event.getRoleObj().getClientRoles(); + int[] roles = event.getRoleObj().getClientRoles(); //System.out.println("Setting my role"); dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); - dataModel.setMoniterId(event.getRoleObj().getMoniterId()); + dataModel.setMonitorId(event.getRoleObj().getMoniterId()); //System.out.println("New role for the client : "+dataModel.getMyRole()); gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); @@ -264,6 +266,25 @@ gameWindow2D.displayErrorMessage(event.toString(),0); } }); + addEventProcessor(new EventTypeProcessor<EnforcementMechanismUpdateEvent>(EnforcementMechanismUpdateEvent.class) { + public void handle(final EnforcementMechanismUpdateEvent enforcementEvent) { +// +// enforcements = enforcementEvent.getAllEnforcements(); +// System.out.println("Enforcement received : "+enforcements.size()); +// noOfEnforcements = enforcements.size(); +// for (Identifier targetId : enforcements.keySet()) { +// votedEnforcement = enforcements.get(targetId); +// } +// displayVotedEnforcement(); + // FIXME: implement me. + gameWindow2D.displayVotedEnforcement(); + } + }); + addEventProcessor(new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { + public void handle(final RegulationEvent regulationEvent) { + dataModel.setRegulation(regulationEvent.getMessage()); + } + }); } public boolean canPerformRealTimeSanction(EnforcementData votedEnforcement) { @@ -308,7 +329,7 @@ private int messagesSent; // samples are collected over 3 seconds. - private final static int SAMPLE_TIME = 3; +// private final static int SAMPLE_TIME = 3; private int totalMessagesPerSample; private int averageMessagesPerSecond; @@ -357,10 +378,6 @@ System.err.println("Discarding event: " + request + " - already sent " + messagesSent); } } - - public void clear() { - stop(); - } public void start() { running = true; @@ -399,10 +416,6 @@ // } // } - public int size() { - return actions.size(); - } - private void tick() { if (secondTick.hasExpired()) { secondTick.restart(); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 22:06:12 UTC (rev 396) @@ -327,17 +327,15 @@ System.out.println("Enforcement voting sent"); - Utils.waitOn(enforcementVotesSignal); +// Utils.waitOn(enforcementVotesSignal); - System.out.println("Voted enforcement received"); +// System.out.println("Voted enforcement received"); //Utils.waitOn(clientRoleSignal); // System.out.println("Client Role received"); - votedEnforcement = getEnforcementPanel().getVotedEnforcement(); - displayVotedEnforcement(); // System.out.println("New Pane added"); } @@ -372,12 +370,11 @@ getSanctioningPanel().sendRegulationVotes(); System.out.println("Regulation voting sent"); //displayRegulationWaitMessage(); - Utils.waitOn(regulationVotesSignal); - System.out.println("Voted regulation received"); +// Utils.waitOn(regulationVotesSignal); +// System.out.println("Voted regulation received"); - votedRegulation = getSanctioningPanel().getVotedRegulation(); - displayVotedRegulation(); + //System.out.println("New Pane added"); } else { @@ -637,9 +634,9 @@ break; // real-time sanctioning keycode handling - case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: - case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: - case KeyEvent.VK_9: + case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: + case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: + case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: // System.out.println("Key pressed : "+(keyChar-48)); //if(dataModel.getRoundConfiguration().isChatEnabled() == false) { @@ -946,7 +943,7 @@ // System.out.println("*****Inside display voting regulation"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getRegulationText()+".</b>"); + instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getText()+".</b>"); remove(sanctioningPanel); addCenterComponent(instructionsScrollPane); startRegulationDisplayTimer(); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 22:06:12 UTC (rev 396) @@ -5,11 +5,8 @@ import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; -import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,7 +16,6 @@ import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JEditorPane; -import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; @@ -27,19 +23,16 @@ import javax.swing.JTextArea; import javax.swing.JTextPane; import javax.swing.ScrollPaneConstants; -import javax.swing.Timer; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import javax.swing.text.StyledDocument; import javax.swing.text.html.HTMLEditorKit; -import edu.asu.commons.event.EventTypeProcessor; -import edu.asu.commons.foraging.event.RegulationEvent; -import edu.asu.commons.foraging.event.RegulationRequest; +import edu.asu.commons.foraging.event.RegulationRankingRequest; +import edu.asu.commons.foraging.event.SubmitRegulationRequest; import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.net.Identifier; -import edu.asu.commons.util.Utils; @@ -63,31 +56,31 @@ public SanctioningPanel (ForagingClient client) { this.client = client; this.clientId = client.getId(); - client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { - public void handle(final RegulationEvent regulationEvent) { - boolean votingFlag=false; - RegulationData regulationData = null; - regulations = regulationEvent.getAllRegulations(); - // System.out.println("Regulation received : "+regulations.size()); - noOfRegulations = regulations.size(); - for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - if(regulationData.isVoting())votingFlag = true; - break; - } - if(votingFlag) - { - votedRegulation = regulationData; - Utils.notify(GameWindow2D.regulationVotesSignal); - } - else - { - //System.out.println("Finding my ID"); - findAndSetMyRegulationID(); - Utils.notify(GameWindow2D.regulationSignal); - } - } - }); +// client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { +// public void handle(final RegulationEvent regulationEvent) { +// boolean votingFlag=false; +// RegulationData regulationData = null; +// regulations = regulationEvent.getAllRegulations(); +// // System.out.println("Regulation received : "+regulations.size()); +// noOfRegulations = regulations.size(); +// for (Identifier targetId : regulations.keySet()) { +// regulationData = regulations.get(targetId); +// if(regulationData.isVoting())votingFlag = true; +// break; +// } +// if(votingFlag) +// { +// votedRegulation = regulationData; +// Utils.notify(GameWindow2D.regulationVotesSignal); +// } +// else +// { +// //System.out.println("Finding my ID"); +// findAndSetMyRegulationID(); +// Utils.notify(GameWindow2D.regulationSignal); +// } +// } +// }); } public SanctioningPanel () @@ -131,19 +124,19 @@ return regulations; } - private void findAndSetMyRegulationID() - { - for (Identifier targetId : regulations.keySet()) { - if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ - client.setRegulationID(regulations.get(targetId).getRegulationID()); - //client.setEnforcementID(regulations.get(targetId).getToken()); - client.setToken(regulations.get(targetId).getToken()); - //System.out.println("My RegID:"+client.getRegulationID()); - //System.out.println("Token:"+client.getEnforcementID()); - return; - } - } - } +// private void findAndSetMyRegulationID() +// { +// for (Identifier targetId : regulations.keySet()) { +// if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ +// client.setRegulationID(regulations.get(targetId).getRegulationID()); +// //client.setEnforcementID(regulations.get(targetId).getToken()); +// client.setToken(regulations.get(targetId).getToken()); +// //System.out.println("My RegID:"+client.getRegulationID()); +// //System.out.println("Token:"+client.getEnforcementID()); +// return; +// } +// } +// } public RegulationData getVotedRegulation(){ return this.votedRegulation; @@ -236,18 +229,7 @@ } public void sendRegulation() { - System.out.println("Regulation sent"); - message = messageWindow.getText(); - // System.err.println("message: " + message); - - RegulationData regulationData = new RegulationData(); - regulationData.setRegulationText(message); - regulationData.setVotingFlag(false); - //FIXME:All the clients have to send some regulation - // if (message == null || "".equals(message) || targetIdentifier == null) { - // return; - // } - client.transmit(new RegulationRequest(clientId, message, regulationData)); + client.transmit(new SubmitRegulationRequest(clientId, messageWindow.getText())); } public void sendRegulationVotes() { @@ -268,15 +250,15 @@ } */ - RegulationData regulationData = new RegulationData(); - regulationData.setCurrentRankingInformation(this.currentRankingInformation); - regulationData.setRegulationText(message); - regulationData.setVotingFlag(true); +// RegulationData regulationData = new RegulationData(); +// regulationData.setCurrentRankingInformation(this.currentRankingInformation); +// regulationData.setRegulationText(message); +// regulationData.setVotingFlag(true); +// +// // System.out.println("ID:"+client.getRegulationID()); +// regulationData.setRegulationID(client.getRegulationID()); - // System.out.println("ID:"+client.getRegulationID()); - regulationData.setRegulationID(client.getRegulationID()); - - client.transmit(new RegulationRequest(clientId, message, regulationData)); + client.transmit(new RegulationRankingRequest(clientId, currentRankingInformation)); } private Color getColor(int i) @@ -323,15 +305,15 @@ // this is for dummy regulation data for testing // start - for(int i=0; i<5; i++) { - RegulationData regulationData1 = new RegulationData(); - regulationData1.setRegulationID(i); - regulationData1.setRegulationText("Test Regulation " + i); - Identifier temp = new Identifier.Base (){}; - System.out.println("Idn : " + temp); - regulations.put(temp, regulationData1); - } - System.out.println(regulations.size()); +// for(int i=0; i<5; i++) { +// RegulationData regulationData1 = new RegulationData(); +// regulationData1.setRegulationID(i); +// regulationData1.setRegulationText("Test Regulation " + i); +// Identifier temp = new Identifier.Base (){}; +// System.out.println("Idn : " + temp); +// regulations.put(temp, regulationData1); +// } +// System.out.println(regulations.size()); // end //for(int i=0; i<5; i++) { @@ -339,9 +321,9 @@ for (Identifier targetId : regulations.keySet()) { regulationData = regulations.get(targetId); StringBuilder sb = new StringBuilder(); - sb.append(regulationData.getRegulationText()); + sb.append(regulationData.getText()); String s = sb.toString(); - newPanel[i] = new SixChoicePanel(s, votes, regulationData.getRegulationID(), getColor(i)); + newPanel[i] = new SixChoicePanel(s, votes, regulationData.getIndex(), getColor(i)); // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); i++; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-03 22:06:12 UTC (rev 396) @@ -187,7 +187,7 @@ } } else { - if (id.equals(dataModel.getMoniterId()) && dataModel.isSanctioningEnabled()) { + if (id.equals(dataModel.getMonitorId()) && dataModel.isSanctioningEnabled()) { //System.out.println("Is a moniter image"); graphics2D.drawImage(scaledMoniterImage, x, y, this); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-03 22:06:12 UTC (rev 396) @@ -8,6 +8,7 @@ import edu.asu.commons.conf.ExperimentRoundParameters; import edu.asu.commons.foraging.graphics.Point3D; +import edu.asu.commons.foraging.model.EnforcementMechanism; public class RoundConfiguration extends ExperimentRoundParameters.Base<ServerConfiguration> { @@ -180,8 +181,12 @@ return getIntProperty("sanction-multiplier", 1); } + public int getSanctionPenalty() { + return getSanctionCost() * getSanctionMultiplier(); + } + public int getSanctionPenalty(int option) { - if (option == 1)return getSanctionCost() * getSanctionMultiplier(); + if (option == 1) return getSanctionCost() * getSanctionMultiplier(); else return (getSanctionCost() * 1); } @@ -350,10 +355,6 @@ return getBooleanProperty("voting-enabled", false); } - public String getEnforcementMechanisms() { - return getProperty("enforcement-mechanisms", "single, rotation"); - } - public int getMaximumResourceAge() { return getIntProperty("maximum-resource-age", 10); } @@ -372,7 +373,7 @@ return new Point3D(-xExtend, 0, -zExtend); } - public int calculateTokens(int resourceAge) { + public int ageToTokens(int resourceAge) { switch (resourceAge) { case 0: return 0; @@ -420,4 +421,12 @@ return getStringProperty("welcome-instructions", "Please wait quietly and do not open or close any programs on this computer."); } + public EnforcementMechanism[] getEnforcementMechanisms() { + return EnforcementMechanism.values(); + } + + public boolean isVotingAndRegulationEnabled() { + return getBooleanProperty("voting-and-regulation-enabled", false); + } + } Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementEvent.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementEvent.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementEvent.java 2009-12-03 22:06:12 UTC (rev 396) @@ -1,33 +0,0 @@ -//package edu.asu.commons.event; -package edu.asu.commons.foraging.event; - -import java.util.Map; - -import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.EnforcementData; -import edu.asu.commons.net.Identifier; - - -/** - * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ - * - * Sent from the server to all clients about the - * updated vote stats - * @author <a href='db...@as...'>Deepak Barge</a> - * @version $Revision: 49 $ - */ - -public class EnforcementEvent extends AbstractEvent { - - private static final long serialVersionUID = 475300882222383637L; - - private final Map<Identifier, EnforcementData> enforcements; - - public EnforcementEvent(Map<Identifier, EnforcementData> enforcements) { - this.enforcements = enforcements; - } - - public Map<Identifier, EnforcementData> getAllEnforcements() { - return enforcements; - } -} Copied: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java (from rev 395, foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementEvent.java) =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementMechanismUpdateEvent.java 2009-12-03 22:06:12 UTC (rev 396) @@ -0,0 +1,33 @@ +//package edu.asu.commons.event; +package edu.asu.commons.foraging.event; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.model.EnforcementMechanism; +import edu.asu.commons.net.Identifier; + + +/** + * $Id: VoteEvent.java 49 2008-09-04 16:57:40Z dbarge $ + * + * Sent from the server to all clients about the + * updated vote stats + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 49 $ + */ + +public class EnforcementMechanismUpdateEvent extends AbstractEvent { + + private static final long serialVersionUID = 5373346980670885924L; + + // FIXME: just send the entire group data model instead? + private EnforcementMechanism activeEnforcementMechanism; + + public EnforcementMechanismUpdateEvent(Identifier id, EnforcementMechanism activeEnforcementMechanism) { + this.activeEnforcementMechanism = activeEnforcementMechanism; + } + + public EnforcementMechanism getActiveEnforcementMechanism() { + return activeEnforcementMechanism; + } + +} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java 2009-12-03 22:06:12 UTC (rev 396) @@ -1,7 +1,7 @@ package edu.asu.commons.foraging.event; -import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.event.AbstractPersistableEvent; import edu.asu.commons.net.Identifier; /** @@ -14,7 +14,7 @@ * @version $Revision: 1 $ */ -public class EnforcementRankingRequest extends AbstractEvent { +public class EnforcementRankingRequest extends AbstractPersistableEvent { private static final long serialVersionUID = 475300882222383637L; Deleted: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRequest.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRequest.java 2009-12-03 20:57:59 UTC (rev 395) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRequest.java 2009-12-03 22:06:12 UTC (rev 396) @@ -1,53 +0,0 @@ -package edu.asu.commons.foraging.event; - - -import edu.asu.commons.event.AbstractEvent; -import edu.asu.commons.foraging.model.EnforcementData; -import edu.asu.commons.net.Identifier; - -/** - * $Id: Regulation... [truncated message content] |
From: <db...@us...> - 2009-12-03 20:58:10
|
Revision: 395 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=395&view=rev Author: dbarge Date: 2009-12-03 20:57:59 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Made changes in the SanctioningPanel.java to get rid of the timers to update the GUI (sanctioning panel) Changed the look of the sanctioning panel with more meaning GUI components with the help from Seema Changed the use of colors for the panels. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 18:16:22 UTC (rev 394) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 20:57:59 UTC (rev 395) @@ -368,7 +368,7 @@ timer.stop(); timer = null; //remove(sanctioningPanel); - getSanctioningPanel().stopTimer(); + //getSanctioningPanel().stopTimer(); getSanctioningPanel().sendRegulationVotes(); System.out.println("Regulation voting sent"); //displayRegulationWaitMessage(); @@ -1032,7 +1032,7 @@ remove(sanctioningPanel); SanctioningPanel sanctioningPanel = updateRegulationVotingPanel(); addCenterComponent( sanctioningPanel ); - sanctioningPanel.startTimer(); + //sanctioningPanel.startTimer(); startRegulationVotingTimer(); } }); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 18:16:22 UTC (rev 394) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 20:57:59 UTC (rev 395) @@ -94,15 +94,9 @@ { regulations = new HashMap<Identifier, RegulationData>(); newPanel = new SixChoicePanel[5]; - + noOfRegulations = 5; } - public static int currentActive; - - public static int currentLabel; - - public static String regulationString = ""; - private Identifier clientId; private String message; @@ -113,12 +107,9 @@ private int currentRankingInformation[]; - private Timer timer; private SixChoicePanel newPanel[]; private JPanel votingPanel; - private JPanel informationPanel; - private JLabel label; private JPanel instructionsPanel; private JPanel buttonPanel; private JButton sendMyVotes; @@ -173,33 +164,19 @@ .addStyle("italic", defaultStyle), true); } - private void updateInstructionPanel(){ - // System.out.println("RegulationString:"+regulationString); - - if(regulationString.equals("")) - regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); - else - regulationsInstructionsPane.setText(regulationString); - - revalidate(); - instructionsPanel.repaint(); - repaint(); - //pack(); - // setVisible(true); - } - - - private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; + private void updateVotingPanel(int currentActive){ + int r,c,i; SixChoicePanel temp = null; boolean enableSendButton = true; // System.out.println("Active panel: "+SixChoicePanel.currentActive); - + // The below for loop is used to clear off radio button of the panel whose ranking conflicts + // with the new panel's radio button + + for(r = 0; r < noOfRegulations; r++) { - // System.out.print(newPanel[r].currentRanking+" "); + System.out.print(newPanel[r].currentRanking+" "); if(newPanel[r].currentRanking == -1)enableSendButton = false; if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) @@ -209,6 +186,8 @@ } } + //The below for loops are used for sorting the panels when the ranks are + //changed for(r = 0; r < noOfRegulations-1; r++) { @@ -228,23 +207,23 @@ } } } + for(c = 0; c < noOfRegulations; c++) { // System.out.print(newPanel[c].getCurrentRanking() +" "); } - votingPanel.setVisible(false); remove(votingPanel); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - //votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setLayout(new GridLayout(5,2)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + votingPanel.add(getInstructionPanel("This is instruction panel")); for(i=0; i < noOfRegulations; i++) { votingPanel.add(newPanel[i].regulationPanel); - votingPanel.add(newPanel[i].rankPanel); } + votingPanel.setVisible(true); add(votingPanel, BorderLayout.CENTER); @@ -256,25 +235,6 @@ revalidate(); } - public void stopTimer(){ - timer.stop(); - } - - public void startTimer(){ - if (timer == null) { - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } - }); - timer.start(); - } - } - public void sendRegulation() { System.out.println("Regulation sent"); message = messageWindow.getText(); @@ -322,11 +282,13 @@ private Color getColor(int i) { Color color = null; - if(i==0) color=Color.lightGray; - if(i==1) color=Color.green; - if(i==2) color=Color.blue; - if(i==3) color=Color.red; - if(i==4) color=Color.cyan; + //if(i==0) color = Color.lightGray; + if(i==0) color = new Color(153,153,204); + //if(i==1) color=Color.green; + if(i==1) color = new Color(204,153,153); + if(i==2) color = new Color(153,204,102); + if(i==3) color = new Color(204,204,102); + if(i==4) color = new Color(255,255,153); return color; } @@ -346,26 +308,16 @@ remove(regulationsInstructionsScrollPane); remove(messageScrollPane); this.currentRankingInformation = new int[5]; - this.timer=null; this.newPanel = new SixChoicePanel[5]; setBackground(Color.lightGray); setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - informationPanel = new JPanel(); - informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); - informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); - label = new JLabel("You have 30 seconds left to vote the regulations"); - - informationPanel.add(label); - // add(informationPanel, BorderLayout.NORTH); - votingPanel = new JPanel(); votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - //votingPanel.setLayout(new GridLayout(5,2)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); //add the instruction panel as the first panel in voting panel. - votingPanel.add(getInstructionPanel("this is instruction panel")); + instructionsPanel = getInstructionPanel("This is instruction panel"); + votingPanel.add(instructionsPanel); RegulationData regulationData; @@ -391,9 +343,7 @@ String s = sb.toString(); newPanel[i] = new SixChoicePanel(s, votes, regulationData.getRegulationID(), getColor(i)); // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); - votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); - //votingPanel.add(newPanel[i].getRankPanel(i)); - + votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); i++; } @@ -434,32 +384,11 @@ } }); buttonPanel = new JPanel(); - //buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.setLayout(new GridLayout(1,2)); buttonPanel.add(reset); buttonPanel.add(sendMyVotes); add(buttonPanel, BorderLayout.SOUTH); - - /*instructionsPanel = new JPanel(); - instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); - instructionsPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); -*/ - /*regulationsInstructionsPane = new JEditorPane(); - regulationsInstructionsPane.setContentType("text/html"); - regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); - regulationsInstructionsPane.setEditable(false); - // regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); - regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); - - //FIXME: Need to fetch the regulation instructions over here - //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getChatInstructions()); - regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); - instructionsPanel.add(regulationsInstructionsScrollPane); - */ - // add(instructionsPanel, BorderLayout.CENTER); -// add(instructionsPanel, BorderLayout.EAST); - } private JPanel getInstructionPanel(String instructions) @@ -468,10 +397,7 @@ //instructionPanel.setBackground(color); instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); - //regulationLabel = new JLabel(title); - //regulationLabel = new JLabel("Click here to get more information on right hand side"); - - + //create Text area and JSCroll pane for it JTextArea instructionText = new JTextArea(instructions,3,50); @@ -482,7 +408,6 @@ } private void initGuiComponents() { - //System.out.println("Intializing GUI components"); setLayout(new BorderLayout(4, 4)); messageWindow = new JTextPane(); messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); @@ -514,29 +439,23 @@ } public void initialize() { - - - // Collections.shuffle(Arrays.asList(HANDLES)); - // System.err.println("handles: " + HANDLES);*/ // System.out.println("Calling init GUI components"); initGuiComponents(); } - private class SixChoicePanel implements ActionListener, MouseListener{ - String title; + private class SixChoicePanel implements ActionListener{ + //String title; String [] buttonLabels; int regulationID; int currentRanking; JPanel regulationPanel; JPanel rankPanel; - JLabel regulationLabel; ButtonGroup group; JRadioButton option []; Color color; - // static int currentActive; public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { - this.title = title; + //this.title = title; this.buttonLabels = buttonLabels; this.regulationID = regulationID; this.color = color; @@ -547,56 +466,24 @@ public int getCurrentRanking(){ return regulationID; } - public void mouseClicked(MouseEvent arg0) { } - public void mouseEntered(MouseEvent arg0) { } - - public void mouseExited(MouseEvent arg0) { } - - public void mousePressed(MouseEvent arg0) { - currentLabel = this.regulationID; - regulationString = this.title; - // System.out.println("Label No:"+currentLabel); - } - - public void mouseReleased(MouseEvent arg0){ } - public void actionPerformed(ActionEvent e) { String choice = group.getSelection().getActionCommand(); int buttonNo = Integer.parseInt(choice); System.out.println("ACTION Choice Selected: " + choice); System.out.println("Bno: " + buttonNo); + System.out.println("CurrentActive : "+this.regulationID); this.currentRanking = buttonNo; - SanctioningPanel.currentActive = this.regulationID; - updateVotingPanel(); + updateVotingPanel(this.regulationID); } - public JPanel getRankPanel(int clientNo){ - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length - for(int i=0; i<length; i++) { - option[i] = new JRadioButton(buttonLabels[i]); - option[i].setActionCommand(buttonLabels[i]); - group.add(option[i]); - option[i].addActionListener(this); - rankPanel.add(option[i]); - } - - return rankPanel; - } + public JPanel getRegulationPanel(int i, String information){ regulationPanel = new JPanel(); regulationPanel.setBackground(color); regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); regulationPanel.setBorder(BorderFactory.createTitledBorder("Regulation "+(i+1))); - //regulationLabel = new JLabel(title); - //regulationLabel = new JLabel("Click here to get more information on right hand side"); - //create Text area and JSCroll pane for it JTextArea regulationText = new JTextArea(information,3,50); @@ -617,8 +504,6 @@ option[j].addActionListener(this); rankPanel.add(option[j]); } - - //regulationLabel.addMouseListener(this); regulationPanel.add(rankPanel); return regulationPanel; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-03 18:16:29
|
Revision: 394 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=394&view=rev Author: alllee Date: 2009-12-03 18:16:22 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Requests to rank regulation and enforcement mechanisms as well as submit a regulation. Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationRankingRequest.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/SubmitRegulationRequest.java Copied: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java (from rev 392, foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRequest.java) =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRankingRequest.java 2009-12-03 18:16:22 UTC (rev 394) @@ -0,0 +1,31 @@ +package edu.asu.commons.foraging.event; + + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.net.Identifier; + +/** + * $Id: RegulationRequest.java 1 2008-07-23 22:15:18Z dbarge $ + * + * Sent from a client to the server signaling that the client + * has updated the votes to the given options + * + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 1 $ + */ + +public class EnforcementRankingRequest extends AbstractEvent { + + private static final long serialVersionUID = 475300882222383637L; + + private int[] rankings; + + public EnforcementRankingRequest(Identifier id, int[] ranking) { + super(id); + this.rankings = ranking; + } + + public int[] getRankings() { + return rankings; + } +} Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationRankingRequest.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationRankingRequest.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationRankingRequest.java 2009-12-03 18:16:22 UTC (rev 394) @@ -0,0 +1,51 @@ +package edu.asu.commons.foraging.event; + + +import java.util.SortedSet; + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.foraging.model.RegulationData; +import edu.asu.commons.net.Identifier; + +/** + * $Id: RegulationRequest.java 1 2008-07-23 22:15:18Z dbarge $ + * + * + * + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 1 $ + */ + +public class RegulationRankingRequest extends AbstractEvent { + + private static final long serialVersionUID = 475300882222383637L; + + private SortedSet<RegulationData> rankedRegulationData; + + private int[] rankings; + + /** + * Constructs a ranking request with the appropriate ranking. + * @param id + * @param ranking + */ + public RegulationRankingRequest(Identifier id, int[] ranking) { + super(id); + this.rankings = ranking; +// this.rankedRegulationData = rankedRegulationData; + } + + public RegulationRankingRequest(Identifier id, SortedSet<RegulationData> rankedRegulationData) { + super(id); + this.rankedRegulationData = rankedRegulationData; + } + + public SortedSet<RegulationData> getRankedRegulationData() { + return rankedRegulationData; + } + + public int[] getRankings() { + return rankings; + } + +} Copied: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/SubmitRegulationRequest.java (from rev 393, foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationRequest.java) =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/SubmitRegulationRequest.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/SubmitRegulationRequest.java 2009-12-03 18:16:22 UTC (rev 394) @@ -0,0 +1,34 @@ +package edu.asu.commons.foraging.event; + + +import edu.asu.commons.event.AbstractEvent; +import edu.asu.commons.net.Identifier; + +/** + * $Id: RegulationRequest.java 1 2008-07-23 22:15:18Z dbarge $ + * + * + * + * @author <a href='db...@as...'>Deepak Barge</a> + * @version $Revision: 1 $ + */ + +public class SubmitRegulationRequest extends AbstractEvent { + + private static final long serialVersionUID = 475300882222383637L; + + /** + * A communication event with a target of Identifier.ALL is broadcast to all group participants. + * @param source + * @param message + */ + public SubmitRegulationRequest(Identifier id, String regulation) { + super(id, regulation); + } + + public String getRegulation() { + return message; + } + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <see...@us...> - 2009-12-03 03:06:21
|
Revision: 393 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=393&view=rev Author: seematalele Date: 2009-12-03 03:06:15 +0000 (Thu, 03 Dec 2009) Log Message: ----------- 1) Created Interface for Regulation. 2) Created the dummy information. So, during the actual experiment, remove the dummy information. 3) Created TestSanction to test the SanctioningPanel class. Bugs- 1) Trying to reduce the height of the TextArea, written settings for it, but due to some reason, it is not reflecting in the GUI. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java Added: foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java 2009-12-03 03:06:15 UTC (rev 393) @@ -0,0 +1,36 @@ +import java.awt.Color; +import java.awt.Container; +import java.awt.FlowLayout; + +import javax.swing.JFrame; + +import edu.asu.commons.foraging.client.ForagingClient; +import edu.asu.commons.foraging.client.SanctioningPanel; + + +public class TestSanction { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + //ForagingClient client = new ForagingClient(); + + SanctioningPanel testsanctioning = new SanctioningPanel(); + testsanctioning.initialize(); + //testsanctioning.getdata(); + testsanctioning.initRegulationVotingCompontents(); + JFrame f = new JFrame("This is a test"); + f.setSize(1000, 1000); + Container content = f.getContentPane(); + content.setBackground(Color.white); + content.setLayout(new FlowLayout()); + content.add(testsanctioning); + //f.setDefaultCloseOperation(0); + f.setVisible(true); + + + } + +} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 01:15:41 UTC (rev 392) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 03:06:15 UTC (rev 393) @@ -5,10 +5,12 @@ import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; +import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,7 +24,9 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.JTextPane; +import javax.swing.ScrollPaneConstants; import javax.swing.Timer; import javax.swing.text.Style; import javax.swing.text.StyleConstants; @@ -52,370 +56,396 @@ @SuppressWarnings("serial") public class SanctioningPanel extends JPanel { - private ForagingClient client; + private ForagingClient client; - private Map<Identifier, RegulationData> regulations; + private Map<Identifier, RegulationData> regulations; - public SanctioningPanel (ForagingClient client) { - this.client = client; - this.clientId = client.getId(); - client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { - public void handle(final RegulationEvent regulationEvent) { - boolean votingFlag=false; - RegulationData regulationData = null; - regulations = regulationEvent.getAllRegulations(); - // System.out.println("Regulation received : "+regulations.size()); - noOfRegulations = regulations.size(); - for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - if(regulationData.isVoting())votingFlag = true; - break; - } - if(votingFlag) - { - votedRegulation = regulationData; - Utils.notify(GameWindow2D.regulationVotesSignal); - } - else - { - //System.out.println("Finding my ID"); - findAndSetMyRegulationID(); - Utils.notify(GameWindow2D.regulationSignal); - } - } - }); - } + public SanctioningPanel (ForagingClient client) { + this.client = client; + this.clientId = client.getId(); + client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { + public void handle(final RegulationEvent regulationEvent) { + boolean votingFlag=false; + RegulationData regulationData = null; + regulations = regulationEvent.getAllRegulations(); + // System.out.println("Regulation received : "+regulations.size()); + noOfRegulations = regulations.size(); + for (Identifier targetId : regulations.keySet()) { + regulationData = regulations.get(targetId); + if(regulationData.isVoting())votingFlag = true; + break; + } + if(votingFlag) + { + votedRegulation = regulationData; + Utils.notify(GameWindow2D.regulationVotesSignal); + } + else + { + //System.out.println("Finding my ID"); + findAndSetMyRegulationID(); + Utils.notify(GameWindow2D.regulationSignal); + } + } + }); + } - public static int currentActive; + public SanctioningPanel () + { + regulations = new HashMap<Identifier, RegulationData>(); + newPanel = new SixChoicePanel[5]; - public static int currentLabel; + } - public static String regulationString = ""; + public static int currentActive; - private Identifier clientId; + public static int currentLabel; - private String message; + public static String regulationString = ""; - private RegulationData votedRegulation; + private Identifier clientId; - private int noOfRegulations; + private String message; - private int currentRankingInformation[]; + private RegulationData votedRegulation; - private Timer timer; - private SixChoicePanel newPanel[]; + private int noOfRegulations; - private JPanel votingPanel; - private JPanel informationPanel; - private JLabel label; - private JPanel instructionsPanel; - private JPanel buttonPanel; - private JButton sendMyVotes; - private JButton reset; + private int currentRankingInformation[]; - private String[] votes = { "1", "2", "3","4", "5"}; + private Timer timer; + private SixChoicePanel newPanel[]; - private JScrollPane messageScrollPane; + private JPanel votingPanel; + private JPanel informationPanel; + private JLabel label; + private JPanel instructionsPanel; + private JPanel buttonPanel; + private JButton sendMyVotes; + private JButton reset; - private JScrollPane regulationsInstructionsScrollPane; + private String[] votes = { "1", "2", "3","4", "5"}; - private JTextPane messageWindow; + private JScrollPane messageScrollPane; - private List<Identifier> participants; + private JScrollPane regulationsInstructionsScrollPane; - private JEditorPane regulationsInstructionsPane; + private JTextPane messageWindow; - public Map<Identifier, RegulationData> getAllRegulations() { - return regulations; - } + private List<Identifier> participants; - private void findAndSetMyRegulationID() - { - for (Identifier targetId : regulations.keySet()) { - if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ - client.setRegulationID(regulations.get(targetId).getRegulationID()); - //client.setEnforcementID(regulations.get(targetId).getToken()); - client.setToken(regulations.get(targetId).getToken()); - //System.out.println("My RegID:"+client.getRegulationID()); - //System.out.println("Token:"+client.getEnforcementID()); - return; - } - } - } + private JEditorPane regulationsInstructionsPane; - public RegulationData getVotedRegulation(){ - return this.votedRegulation; - } + public Map<Identifier, RegulationData> getAllRegulations() { + return regulations; + } - private void addStylesToMessageWindow() { - StyledDocument styledDocument = messageWindow.getStyledDocument(); - // and why not have something like... StyleContext.getDefaultStyle() to - // replace this junk - Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( - StyleContext.DEFAULT_STYLE); - // Style regularStyle = styledDocument.addStyle("regular", - // defaultStyle); - StyleConstants.setFontFamily(defaultStyle, "Helvetica"); - StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), - true); - StyleConstants.setItalic(styledDocument - .addStyle("italic", defaultStyle), true); - } + private void findAndSetMyRegulationID() + { + for (Identifier targetId : regulations.keySet()) { + if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ + client.setRegulationID(regulations.get(targetId).getRegulationID()); + //client.setEnforcementID(regulations.get(targetId).getToken()); + client.setToken(regulations.get(targetId).getToken()); + //System.out.println("My RegID:"+client.getRegulationID()); + //System.out.println("Token:"+client.getEnforcementID()); + return; + } + } + } - private void updateInstructionPanel(){ - // System.out.println("RegulationString:"+regulationString); + public RegulationData getVotedRegulation(){ + return this.votedRegulation; + } - if(regulationString.equals("")) - regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); - else - regulationsInstructionsPane.setText(regulationString); + private void addStylesToMessageWindow() { + StyledDocument styledDocument = messageWindow.getStyledDocument(); + // and why not have something like... StyleContext.getDefaultStyle() to + // replace this junk + Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( + StyleContext.DEFAULT_STYLE); + // Style regularStyle = styledDocument.addStyle("regular", + // defaultStyle); + StyleConstants.setFontFamily(defaultStyle, "Helvetica"); + StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), + true); + StyleConstants.setItalic(styledDocument + .addStyle("italic", defaultStyle), true); + } - revalidate(); - instructionsPanel.repaint(); - repaint(); - //pack(); - // setVisible(true); - } + private void updateInstructionPanel(){ + // System.out.println("RegulationString:"+regulationString); + if(regulationString.equals("")) + regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); + else + regulationsInstructionsPane.setText(regulationString); - private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; - SixChoicePanel temp = null; - boolean enableSendButton = true; + revalidate(); + instructionsPanel.repaint(); + repaint(); + //pack(); + // setVisible(true); + } - // System.out.println("Active panel: "+SixChoicePanel.currentActive); - for(r = 0; r < noOfRegulations; r++) - { - // System.out.print(newPanel[r].currentRanking+" "); - if(newPanel[r].currentRanking == -1)enableSendButton = false; + private void updateVotingPanel(){ + int r,c,i,j; + int currentRanking; + SixChoicePanel temp = null; + boolean enableSendButton = true; - if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) - { - newPanel[r].currentRanking = -1; - newPanel[r].group.clearSelection(); - } - } + // System.out.println("Active panel: "+SixChoicePanel.currentActive); + for(r = 0; r < noOfRegulations; r++) + { + // System.out.print(newPanel[r].currentRanking+" "); + if(newPanel[r].currentRanking == -1)enableSendButton = false; - for(r = 0; r < noOfRegulations-1; r++) - { - for(c = 0; c < noOfRegulations-1; c++) - { - if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - } - } - for(c = 0; c < noOfRegulations; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } + if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) + { + newPanel[r].currentRanking = -1; + newPanel[r].group.clearSelection(); + } + } - votingPanel.setVisible(false); - remove(votingPanel); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + for(r = 0; r < noOfRegulations-1; r++) + { + for(c = 0; c < noOfRegulations-1; c++) + { + if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + } + } + for(c = 0; c < noOfRegulations; c++) + { + // System.out.print(newPanel[c].getCurrentRanking() +" "); + } + votingPanel.setVisible(false); + remove(votingPanel); - for(i=0; i < noOfRegulations; i++) { - votingPanel.add(newPanel[i].regulationPanel); - votingPanel.add(newPanel[i].rankPanel); - } - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); + //votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setLayout(new GridLayout(5,2)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } - revalidate(); - } - public void stopTimer(){ - timer.stop(); - } + for(i=0; i < noOfRegulations; i++) { + votingPanel.add(newPanel[i].regulationPanel); + votingPanel.add(newPanel[i].rankPanel); + } + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); - public void startTimer(){ - if (timer == null) { - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } - }); - timer.start(); - } - } + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + revalidate(); + } - public void sendRegulation() { - System.out.println("Regulation sent"); - message = messageWindow.getText(); - // System.err.println("message: " + message); + public void stopTimer(){ + timer.stop(); + } - RegulationData regulationData = new RegulationData(); - regulationData.setRegulationText(message); - regulationData.setVotingFlag(false); - //FIXME:All the clients have to send some regulation - // if (message == null || "".equals(message) || targetIdentifier == null) { - // return; - // } - client.transmit(new RegulationRequest(clientId, message, regulationData)); - } - - public void sendRegulationVotes() { - System.out.println("Regulation votes ready to be sent"); - // System.err.println("message: " + message); - int i; - for(i=0; i < noOfRegulations; i++) { - if(newPanel[i].currentRanking == -1) - this.currentRankingInformation[i] = -1; - else - this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); - } + public void startTimer(){ + if (timer == null) { + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + //timer.stop(); + //timer = null; + // System.out.println("Timer called to update the voting panel:"); + updateVotingPanel(); + updateInstructionPanel(); + } + }); + timer.start(); + } + } - /* + public void sendRegulation() { + System.out.println("Regulation sent"); + message = messageWindow.getText(); + // System.err.println("message: " + message); + + RegulationData regulationData = new RegulationData(); + regulationData.setRegulationText(message); + regulationData.setVotingFlag(false); + //FIXME:All the clients have to send some regulation + // if (message == null || "".equals(message) || targetIdentifier == null) { + // return; + // } + client.transmit(new RegulationRequest(clientId, message, regulationData)); + } + + public void sendRegulationVotes() { + System.out.println("Regulation votes ready to be sent"); + // System.err.println("message: " + message); + int i; + for(i=0; i < noOfRegulations; i++) { + if(newPanel[i].currentRanking == -1) + this.currentRankingInformation[i] = -1; + else + this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); + } + + /* for(i=0 ; i<5 ; i++) { System.out.println(currentRankingInformation[i]); } - */ + */ - RegulationData regulationData = new RegulationData(); - regulationData.setCurrentRankingInformation(this.currentRankingInformation); - regulationData.setRegulationText(message); - regulationData.setVotingFlag(true); + RegulationData regulationData = new RegulationData(); + regulationData.setCurrentRankingInformation(this.currentRankingInformation); + regulationData.setRegulationText(message); + regulationData.setVotingFlag(true); - // System.out.println("ID:"+client.getRegulationID()); - regulationData.setRegulationID(client.getRegulationID()); + // System.out.println("ID:"+client.getRegulationID()); + regulationData.setRegulationID(client.getRegulationID()); - client.transmit(new RegulationRequest(clientId, message, regulationData)); - } + client.transmit(new RegulationRequest(clientId, message, regulationData)); + } - private Color getColor(int i) - { - Color color = null; - if(i==0) color=Color.green; - if(i==1) color=Color.lightGray; - if(i==2) color=Color.blue; - if(i==3) color=Color.red; - if(i==4) color=Color.cyan; - return color; - } + private Color getColor(int i) + { + Color color = null; + if(i==0) color=Color.lightGray; + if(i==1) color=Color.green; + if(i==2) color=Color.blue; + if(i==3) color=Color.red; + if(i==4) color=Color.cyan; + return color; + } - private String getVoteString(){ + private String getVoteString(){ - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - for(int c = 0; c < noOfRegulations; c++) - { - sb.append("\nRegulation "+(newPanel[c].getCurrentRanking()+1)); - } - return(sb.toString()); - } + for(int c = 0; c < noOfRegulations; c++) + { + sb.append("\nRegulation "+(newPanel[c].getCurrentRanking()+1)); + } + return(sb.toString()); + } - public void initRegulationVotingCompontents(){ + public void initRegulationVotingCompontents(){ - remove(regulationsInstructionsScrollPane); - remove(messageScrollPane); - this.currentRankingInformation = new int[5]; - this.timer=null; - this.newPanel = new SixChoicePanel[5]; - setBackground(Color.lightGray); - setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + remove(regulationsInstructionsScrollPane); + remove(messageScrollPane); + this.currentRankingInformation = new int[5]; + this.timer=null; + this.newPanel = new SixChoicePanel[5]; + setBackground(Color.lightGray); + setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - informationPanel = new JPanel(); - informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); - informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); - label = new JLabel("You have 30 seconds left to vote the regulations"); + informationPanel = new JPanel(); + informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); + informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); + label = new JLabel("You have 30 seconds left to vote the regulations"); - informationPanel.add(label); - // add(informationPanel, BorderLayout.NORTH); + informationPanel.add(label); + // add(informationPanel, BorderLayout.NORTH); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + //votingPanel.setLayout(new GridLayout(5,2)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + //add the instruction panel as the first panel in voting panel. + votingPanel.add(getInstructionPanel("this is instruction panel")); - RegulationData regulationData; + RegulationData regulationData; - //for(int i=0; i<5; i++) { - int i = 0; - for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - StringBuilder sb = new StringBuilder(); - sb.append(regulationData.getRegulationText()); - String s = sb.toString(); - newPanel[i] = new SixChoicePanel(s, votes, regulationData.getRegulationID(), getColor(i)); - votingPanel.add(newPanel[i].getRegulationPanel(i)); - votingPanel.add(newPanel[i].getRankPanel(i)); - i++; - } + // this is for dummy regulation data for testing + // start + for(int i=0; i<5; i++) { + RegulationData regulationData1 = new RegulationData(); + regulationData1.setRegulationID(i); + regulationData1.setRegulationText("Test Regulation " + i); + Identifier temp = new Identifier.Base (){}; + System.out.println("Idn : " + temp); + regulations.put(temp, regulationData1); + } + System.out.println(regulations.size()); + // end - add(votingPanel, BorderLayout.CENTER); - reset = new JButton("Reset All Ranks"); - reset.setAlignmentX(Component.CENTER_ALIGNMENT); - reset.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - for(int i=0; i<noOfRegulations; i++) { - for(int j=0; j<noOfRegulations; j++) { - newPanel[i].option[j].setEnabled(true); - newPanel[i].group.clearSelection(); - newPanel[i].currentRanking = -1; - } - } - } - }); - sendMyVotes = new JButton("Send votes"); - sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); - sendMyVotes.setEnabled(false); - sendMyVotes.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + //for(int i=0; i<5; i++) { + int i = 0; + for (Identifier targetId : regulations.keySet()) { + regulationData = regulations.get(targetId); + StringBuilder sb = new StringBuilder(); + sb.append(regulationData.getRegulationText()); + String s = sb.toString(); + newPanel[i] = new SixChoicePanel(s, votes, regulationData.getRegulationID(), getColor(i)); + // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); + votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); + //votingPanel.add(newPanel[i].getRankPanel(i)); + + i++; + } - int n = JOptionPane.showConfirmDialog( - null, "Are you sure to submit your votes ?"+ - "\nBelow is order of your voting" + - getVoteString(), - "Confirm and send votes", - JOptionPane.YES_NO_OPTION); + add(votingPanel, BorderLayout.CENTER); + reset = new JButton("Reset All Ranks"); + reset.setAlignmentX(Component.CENTER_ALIGNMENT); + reset.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + for(int i=0; i<noOfRegulations; i++) { + for(int j=0; j<noOfRegulations; j++) { + newPanel[i].option[j].setEnabled(true); + newPanel[i].group.clearSelection(); + newPanel[i].currentRanking = -1; + } + } + } + }); + sendMyVotes = new JButton("Send votes"); + sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); + sendMyVotes.setEnabled(false); + sendMyVotes.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { - if (n == JOptionPane.YES_OPTION) { - GameWindow2D.duration.expire(); - } - if (n == JOptionPane.NO_OPTION) { + int n = JOptionPane.showConfirmDialog( + null, "Are you sure to submit your votes ?"+ + "\nBelow is order of your voting" + + getVoteString(), + "Confirm and send votes", + JOptionPane.YES_NO_OPTION); - } + if (n == JOptionPane.YES_OPTION) { + GameWindow2D.duration.expire(); + } + if (n == JOptionPane.NO_OPTION) { - } - }); - buttonPanel = new JPanel(); - //buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); - buttonPanel.setLayout(new GridLayout(1,2)); - buttonPanel.add(reset); - buttonPanel.add(sendMyVotes); + } - add(buttonPanel, BorderLayout.SOUTH); + } + }); + buttonPanel = new JPanel(); + //buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + buttonPanel.setLayout(new GridLayout(1,2)); + buttonPanel.add(reset); + buttonPanel.add(sendMyVotes); - instructionsPanel = new JPanel(); - instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); - instructionsPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); + add(buttonPanel, BorderLayout.SOUTH); - regulationsInstructionsPane = new JEditorPane(); + /*instructionsPanel = new JPanel(); + instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); + instructionsPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); +*/ + /*regulationsInstructionsPane = new JEditorPane(); regulationsInstructionsPane.setContentType("text/html"); regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); regulationsInstructionsPane.setEditable(false); @@ -426,128 +456,173 @@ //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getChatInstructions()); regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); instructionsPanel.add(regulationsInstructionsScrollPane); + */ + // add(instructionsPanel, BorderLayout.CENTER); +// add(instructionsPanel, BorderLayout.EAST); - // add(instructionsPanel, BorderLayout.CENTER); - add(instructionsPanel, BorderLayout.EAST); + } - } - private void initGuiComponents() { - //System.out.println("Intializing GUI components"); - setLayout(new BorderLayout(4, 4)); - messageWindow = new JTextPane(); - messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); - messageWindow.requestFocusInWindow(); - messageScrollPane = new JScrollPane(messageWindow); - addStylesToMessageWindow(); + private JPanel getInstructionPanel(String instructions) + { + JPanel instructionPanel = new JPanel(); + //instructionPanel.setBackground(color); + instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); + instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); + //regulationLabel = new JLabel(title); + //regulationLabel = new JLabel("Click here to get more information on right hand side"); - // orient the components in true lazyman fashion. - regulationsInstructionsPane = new JEditorPane(); - regulationsInstructionsPane.setContentType("text/html"); - regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); - regulationsInstructionsPane.setEditable(false); - regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation details")); - regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); + //create Text area and JSCroll pane for it - //FIXME: Need to fetch the regulation instructions over here - regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); + JTextArea instructionText = new JTextArea(instructions,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + instructionPanel.add(scrollForRegulationText); + + return instructionPanel; - add(regulationsInstructionsScrollPane, BorderLayout.NORTH); - add(messageScrollPane, BorderLayout.CENTER); + } + private void initGuiComponents() { + //System.out.println("Intializing GUI components"); + setLayout(new BorderLayout(4, 4)); + messageWindow = new JTextPane(); + messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); + messageWindow.requestFocusInWindow(); + messageScrollPane = new JScrollPane(messageWindow); + addStylesToMessageWindow(); - } + // orient the components in true lazyman fashion. - public void clear() { - participants.clear(); - } + regulationsInstructionsPane = new JEditorPane(); + regulationsInstructionsPane.setContentType("text/html"); + regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); + regulationsInstructionsPane.setEditable(false); + regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation details")); + regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); - public void initialize() { + //FIXME: Need to fetch the regulation instructions over here + //dummy regulation instructions are + //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); + regulationsInstructionsPane.setText("Test regulation instructions...."); + //add(regulationsInstructionsScrollPane, BorderLayout.NORTH); + //add(messageScrollPane, BorderLayout.CENTER); - // Collections.shuffle(Arrays.asList(HANDLES)); - // System.err.println("handles: " + HANDLES);*/ - // System.out.println("Calling init GUI components"); - initGuiComponents(); - } + } - private class SixChoicePanel implements ActionListener, MouseListener{ - String title; - String [] buttonLabels; - int regulationID; - int currentRanking; - JPanel regulationPanel; - JPanel rankPanel; - JLabel regulationLabel; - ButtonGroup group; - JRadioButton option []; - Color color; - // static int currentActive; + public void clear() { + participants.clear(); + } - public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { - this.title = title; - this.buttonLabels = buttonLabels; - this.regulationID = regulationID; - this.color = color; - this.currentRanking = -1; - this.option = new JRadioButton[5]; - } + public void initialize() { - public int getCurrentRanking(){ - return regulationID; - } - public void mouseClicked(MouseEvent arg0) { } - public void mouseEntered(MouseEvent arg0) { } + // Collections.shuffle(Arrays.asList(HANDLES)); + // System.err.println("handles: " + HANDLES);*/ + // System.out.println("Calling init GUI components"); + initGuiComponents(); + } - public void mouseExited(MouseEvent arg0) { } + private class SixChoicePanel implements ActionListener, MouseListener{ + String title; + String [] buttonLabels; + int regulationID; + int currentRanking; + JPanel regulationPanel; + JPanel rankPanel; + JLabel regulationLabel; + ButtonGroup group; + JRadioButton option []; + Color color; + // static int currentActive; - public void mousePressed(MouseEvent arg0) { - currentLabel = this.regulationID; - regulationString = this.title; - // System.out.println("Label No:"+currentLabel); - } + public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { + this.title = title; + this.buttonLabels = buttonLabels; + this.regulationID = regulationID; + this.color = color; + this.currentRanking = -1; + this.option = new JRadioButton[5]; + } - public void mouseReleased(MouseEvent arg0){ } + public int getCurrentRanking(){ + return regulationID; + } + public void mouseClicked(MouseEvent arg0) { } - public void actionPerformed(ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - //System.out.println("ACTION Choice Selected: " + choice); - // System.out.println("Bno: " + buttonNo); - this.currentRanking = buttonNo; - SanctioningPanel.currentActive = this.regulationID; - } + public void mouseEntered(MouseEvent arg0) { } - public JPanel getRankPanel(int clientNo){ - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length - for(int i=0; i<length; i++) { - option[i] = new JRadioButton(buttonLabels[i]); - option[i].setActionCommand(buttonLabels[i]); - group.add(option[i]); - option[i].addActionListener(this); - rankPanel.add(option[i]); - } + public void mouseExited(MouseEvent arg0) { } - return rankPanel; - } - public JPanel getRegulationPanel(int i){ - regulationPanel = new JPanel(); - regulationPanel.setBackground(color); - regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); - regulationPanel.setBorder(BorderFactory.createTitledBorder("Regulation "+(i+1))); - //regulationLabel = new JLabel(title); - regulationLabel = new JLabel("Click here to get more information on right hand side"); - regulationLabel.addMouseListener(this); - regulationPanel.add(regulationLabel); - return regulationPanel; - } + public void mousePressed(MouseEvent arg0) { + currentLabel = this.regulationID; + regulationString = this.title; + // System.out.println("Label No:"+currentLabel); + } - } + public void mouseReleased(MouseEvent arg0){ } + public void actionPerformed(ActionEvent e) { + String choice = group.getSelection().getActionCommand(); + int buttonNo = Integer.parseInt(choice); + System.out.println("ACTION Choice Selected: " + choice); + System.out.println("Bno: " + buttonNo); + this.currentRanking = buttonNo; + SanctioningPanel.currentActive = this.regulationID; + updateVotingPanel(); + } + public JPanel getRankPanel(int clientNo){ + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length + for(int i=0; i<length; i++) { + option[i] = new JRadioButton(buttonLabels[i]); + option[i].setActionCommand(buttonLabels[i]); + group.add(option[i]); + option[i].addActionListener(this); + rankPanel.add(option[i]); + } + + return rankPanel; + } + public JPanel getRegulationPanel(int i, String information){ + regulationPanel = new JPanel(); + regulationPanel.setBackground(color); + regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); + regulationPanel.setBorder(BorderFactory.createTitledBorder("Regulation "+(i+1))); + //regulationLabel = new JLabel(title); + //regulationLabel = new JLabel("Click here to get more information on right hand side"); + + + //create Text area and JSCroll pane for it + + JTextArea regulationText = new JTextArea(information,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(regulationText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + regulationPanel.add(scrollForRegulationText); + + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length + + for(int j=0; j<length; j++) { + option[j] = new JRadioButton(buttonLabels[j]); + option[j].setActionCommand(buttonLabels[j]); + group.add(option[j]); + option[j].addActionListener(this); + rankPanel.add(option[j]); + } + + //regulationLabel.addMouseListener(this); + regulationPanel.add(rankPanel); + return regulationPanel; + } + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-03 01:15:49
|
Revision: 392 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=392&view=rev Author: alllee Date: 2009-12-03 01:15:41 +0000 (Thu, 03 Dec 2009) Log Message: ----------- new enums representing an enforcement mechanism and a foraging role, might rethink how these are represented later Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementMechanism.java 2009-12-03 01:15:41 UTC (rev 392) @@ -0,0 +1,28 @@ +package edu.asu.commons.foraging.model; + +public enum EnforcementMechanism { + + NONE("No enforcement", "Everybody can harvest. Nobody can subtract tokens from others"), + EVERYONE_CAN_SANCTION("Everybody can reduce", "Every participant can reduce the tokens of other participants by pressing the number key associated with that participant."), + RANDOM_MONITOR("Random monitor", "Randomly, one of the participants is selected to be the monitoring participant. This participant cannot harvest but can subtract tokens from other participants by pressing the number key associated with that participant. At the end of the round each harvesting participant pays 25% of their earned tokens to the monitoring participant."), + ROTATING_MONITOR("Rotating monitor", "Each participant is given an equal amount of time to be a monitor, with the ability to reduce the tokens of other participants by pressing the number key associated with that participant."); + + private final String title; + private final String description; + + EnforcementMechanism(String title, String description) { + this.title = title; + this.description = description; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + + +} Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ForagingRole.java 2009-12-03 01:15:41 UTC (rev 392) @@ -0,0 +1,30 @@ +package edu.asu.commons.foraging.model; + +public enum ForagingRole { + + HARVEST("Harvest"), MONITOR("Monitor"), + SANCTION("Sanction"), SANCTION_AND_HARVEST("Sanction and harvest"); + + private final String label; + + ForagingRole(String label) { + this.label = label; + } + + public String toString() { + return label; + } + + public String getLabel() { + return label; + } + + public boolean isMonitor() { + return this == MONITOR; + } + + public boolean canSanction() { + return this == SANCTION || this == SANCTION_AND_HARVEST; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <db...@us...> - 2009-12-03 00:48:44
|
Revision: 391 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=391&view=rev Author: dbarge Date: 2009-12-03 00:48:31 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Added some code for getting parameters for the timers on the client side Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-03 00:48:31 UTC (rev 391) @@ -41,6 +41,8 @@ private int currentTokens; private int role; + + private Identifier moniterId; private static final int MONITOR = 0; private static final int HARVEST = 1; @@ -77,6 +79,14 @@ return this.role; } + public void setMoniterId (Identifier moniterId) { + this.moniterId = moniterId; + } + + public Identifier getMoniterId() { + return this.moniterId; + } + public boolean isSanctioningAllowed(){ System.out.println("My Role : "+getMyRole()); /* Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-03 00:48:31 UTC (rev 391) @@ -188,11 +188,13 @@ addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { public void handle(NewClientRole event) { Identifier receivedClientId = event.getRoleObj().getClientId(); - System.out.println("Broadcast ID : "+receivedClientId); + //System.out.println("Broadcast ID : "+receivedClientId); if(dataModel.getId().equals(receivedClientId)) { int roles [] = event.getRoleObj().getClientRoles(); + //System.out.println("Setting my role"); dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); - System.out.println("New role for the client : "+dataModel.getMyRole()); + dataModel.setMoniterId(event.getRoleObj().getMoniterId()); + //System.out.println("New role for the client : "+dataModel.getMyRole()); gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); // Utils.notify(GameWindow2D.clientRoleSignal); @@ -265,6 +267,7 @@ } public boolean canPerformRealTimeSanction(EnforcementData votedEnforcement) { + //System.out.println("Result index"+votedEnforcement.getResultIndex()); if(votedEnforcement.getResultIndex() == 2 || votedEnforcement.getResultIndex() == 3) return dataModel.getRoundConfiguration().isRealTimeSanctioningEnabled() && dataModel.getCurrentTokens() >= 0; else @@ -281,7 +284,7 @@ public void transmit(PostRoundSanctionRequest request) { if (state == ClientState.WAITING) { - System.out.println("Sending post round sanction request"); + //System.out.println("Sending post round sanction request"); gameWindow2D.switchInstructionsPane(); super.transmit(request); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 00:48:31 UTC (rev 391) @@ -78,7 +78,7 @@ // the data model private final ClientDataModel dataModel; - // instructions components. + // instructions components. private Component currentCenterComponent; @@ -247,9 +247,11 @@ } private void startEnforcementDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(10); + + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementDisplayDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -275,9 +277,10 @@ } private void startRegulationDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(15); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationDisplayDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -302,9 +305,11 @@ } private void startEnforcementVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementVotingDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -347,9 +352,11 @@ private void startRegulationVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingtDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -382,10 +389,12 @@ } } - private void startRegulationSubmissionTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + + private void startSanctioningTimer() { + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationSubmissionDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -413,8 +422,10 @@ } } private void startChatTimer() { - if (timer == null) { - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + if (timer == null) { + // final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -629,10 +640,16 @@ case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: - // System.out.println("Key pressed : "+(keyChar-48)); - if(dataModel.getRoundConfiguration().isChatEnabled() == false) { - return; - } + + // System.out.println("Key pressed : "+(keyChar-48)); + //if(dataModel.getRoundConfiguration().isChatEnabled() == false) { + //return; + //} + if(dataModel.getRoundConfiguration().isSanctioningEnabled() == false) { + return; + } + + if (client.isSanctioningAllowed() && client.canPerformRealTimeSanction(getEnforcementPanel().getVotedEnforcement())) { //System.out.println("Can do sanctioning"); int assignedNumber = keyChar - 48; @@ -733,8 +750,11 @@ // by the server no new clients can connect because the round // has begun. update(configuration.getRoundDuration().getTimeLeft()); - if(configuration.isChatEnabled()){ - displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); + + //if(configuration.isChatEnabled()){ + if(configuration.isSanctioningEnabled()){ + displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); + } add(messagePanel, BorderLayout.SOUTH); @@ -1030,7 +1050,7 @@ // System.out.println("Initialization done"); //remove( messagePanel ); addCenterComponent( sanctioningPanel ); - startRegulationSubmissionTimer(); + startSanctioningTimer(); } }); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-03 00:48:31 UTC (rev 391) @@ -34,7 +34,7 @@ protected Image tokenImage, otherSubjectImage, selfImage, selfExplicitCollectionModeImage, beingSanctionedImage, sanctioningImage, monitorImage; protected Image scaledTokenImage, scaledOtherSubjectImage, scaledSelfImage, - scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMonitorImage; + scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMoniterImage; /** * Use these for the dimensions when drawing. @@ -93,7 +93,7 @@ scaledSelfExplicitCollectionModeImage = selfExplicitCollectionModeImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledBeingSanctionedImage = beingSanctionedImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledSanctioningImage = sanctioningImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); - scaledMonitorImage = monitorImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); + scaledMoniterImage = monitorImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); } /** Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-03 00:48:31 UTC (rev 391) @@ -169,7 +169,7 @@ graphics2D.drawImage(scaledBeingSanctionedImage, x, y, this); } else if (dataModel.isMonitor()) { - graphics2D.drawImage(scaledMonitorImage, x, y, this); + graphics2D.drawImage(scaledMoniterImage, x, y, this); } else if (dataModel.isSanctioning(id)) { graphics2D.setColor(Color.WHITE); @@ -182,11 +182,19 @@ graphics2D.drawImage(scaledSelfExplicitCollectionModeImage, x, y, this); } else { + //System.out.println("Is a self image"); graphics2D.drawImage(scaledSelfImage, x, y, this); } } else { - graphics2D.drawImage(scaledOtherSubjectImage, x, y, this); + if (id.equals(dataModel.getMoniterId()) && dataModel.isSanctioningEnabled()) { + //System.out.println("Is a moniter image"); + graphics2D.drawImage(scaledMoniterImage, x, y, this); + } + else { + //System.out.println("Is a other image"); + graphics2D.drawImage(scaledOtherSubjectImage, x, y, this); + } } } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-03 00:48:31 UTC (rev 391) @@ -274,9 +274,29 @@ } public int getChatDuration() { - return getIntProperty("chat-duration", 5); + return getIntProperty("chat-duration", 30); } - + + public int getRegulationSubmissionDuration() { + return getIntProperty("regulation-duration", 60); + } + + public int getRegulationDisplayDuration() { + return getIntProperty("regulation-display-duration", 15); + } + + public int getEnforcementVotingDuration() { + return getIntProperty("enforcement-voting-duration", 30); + } + + public int getEnforcementDisplayDuration() { + return getIntProperty("enforcement-display-duration", 15); + } + + public int getRegulationVotingtDuration() { + return getIntProperty("regulation-voting-duration", 30); + } + public String getSanctionInstructions() { return getProperty("sanction-instructions"); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java 2009-12-03 00:48:31 UTC (rev 391) @@ -21,6 +21,8 @@ private Identifier id; + private Identifier moniterId; + private int roleNo; public ClientRole() {} @@ -41,6 +43,15 @@ this.id = id; } + public Identifier getMoniterId(){ + return moniterId; + } + + public void setMoniterId(Identifier moniterId){ + this.moniterId = moniterId; + } + + public int getRoleNo(){ return roleNo; } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-02 23:47:09 UTC (rev 390) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-03 00:48:31 UTC (rev 391) @@ -101,6 +101,11 @@ public static final int SANCTION = 2; public static final int HARVESTANDSANCTION = 3; + public static final int NO_SANCTIONS = 0; + public static final int HARVEST_WITH_SANCTION = 1; + public static final int RANDOM_SANCTIONER = 2; + public static final int CIRCULAR_MONITERING = 3; + public final static int SYNCHRONIZATION_FREQUENCY = 60; public final static int SERVER_SLEEP_INTERVAL = 100; @@ -264,7 +269,7 @@ Identifier newClientIdentifier = event.getId(); // Identifier newClientIdentifier = (Identifier)t1.toString(); - System.out.println("Client ID : "+newClientIdentifier); + System.out.println("New Client ID : "+newClientIdentifier); synchronized (clients) { clients.put(newClientIdentifier, new ClientData(newClientIdentifier)); @@ -439,7 +444,7 @@ switch(srcEnforcementType) { /* * No sanctioning just harvest - */ case 0: + */ case NO_SANCTIONS: System.out.println("This code should never be reached"); break; @@ -447,7 +452,7 @@ /* * Harvest and sanction * Reduce other by 2 but also own by 1 - */ case 1: + */ case HARVEST_WITH_SANCTION: sourceClient.sanctionCost(); targetClient.sanctionPenalty(1); // add sanction request to the target client so they can figure out who just sanctioned them @@ -466,7 +471,7 @@ * One participant is a moniter who sanctions but cannot harvest * Moniter can give penalty by subtract 1 from sanctionee * Nothing taken from Moniter but receives 25% tokens from each - */ case 2: + */ case RANDOM_SANCTIONER: //sourceClient.sanctionCost(); targetClient.sanctionPenalty(0); // add sanction request to the target client so they can figure out who just sanctioned them @@ -485,7 +490,7 @@ * One participant is a moniter who sanctions but cannot harvest * Moniter can give penalty by subtract 1 from sanctionee * Nothing taken from Moniter but receives 25% tokens from each - */ case 3: + */ case CIRCULAR_MONITERING: //sourceClient.sanctionCost(); targetClient.sanctionPenalty(0); // add sanction request to the target client so they can figure out who just sanctioned them @@ -660,6 +665,7 @@ NewClientRole newClientRole = new NewClientRole(targetId); clientRole.setClientId(targetId); clientRole.setRoleNo(i); + if(roles[i] == MONITER)clientRole.setMoniterId(targetId); clients.get(targetId).setClientRole(clientRole); newClientRole.setRoleObj(clientRole); transmit(newClientRole); @@ -706,6 +712,7 @@ // update all clients with the roles roles = findClientRoles(group, 3); + roles = findClientRoles(group, 3); for(Identifier targetId: group.getClientIdentifiers()) { sendNewRolesToClients(targetId, roles); } @@ -724,26 +731,26 @@ int i; System.out.println("Finding roles for mechanism : "+index); switch(index){ - case 0: + case NO_SANCTIONS: for(i=0; i<MAX_CLIENTS_PER_GROUP; i++){ roles[i] = HARVEST; } break; - case 1: + case HARVEST_WITH_SANCTION: for(i=0; i<MAX_CLIENTS_PER_GROUP; i++){ roles[i] = HARVESTANDSANCTION; } break; - case 2: + case RANDOM_SANCTIONER: roles[0] = MONITER; for(i=1; i<MAX_CLIENTS_PER_GROUP; i++){ roles[i] = HARVEST; } break; - case 3: + case CIRCULAR_MONITERING: // first client is given the chance to sanction int moniter = group.getRandomMoniterCount(); group.incrRandomMoniterCount(); @@ -811,6 +818,7 @@ NewClientRole newClientRole = new NewClientRole(targetId); clientRole.setClientId(targetId); clientRole.setRoleNo(i); + if(roles[i] == MONITER)clientRole.setMoniterId(targetId); clients.get(targetId).setClientRole(clientRole); newClientRole.setRoleObj(clientRole); transmit(newClientRole); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <see...@us...> - 2009-12-02 23:47:22
|
Revision: 390 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=390&view=rev Author: seematalele Date: 2009-12-02 23:47:09 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Some fields were missing in BlockInformationWindow.as, InformationWindow.as and CategoricalOption.as. Added those so that it is consistent with entities at server side. Modified Paths: -------------- mentalmodels/trunk/flex/src/actionscript/BlockInformationWindow.as mentalmodels/trunk/flex/src/actionscript/InformationWindow.as mentalmodels/trunk/flex/src/actionscript/questions/CategoricalOption.as Modified: mentalmodels/trunk/flex/src/actionscript/BlockInformationWindow.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/BlockInformationWindow.as 2009-12-02 00:32:41 UTC (rev 389) +++ mentalmodels/trunk/flex/src/actionscript/BlockInformationWindow.as 2009-12-02 23:47:09 UTC (rev 390) @@ -8,5 +8,6 @@ public var id:Number; public var sequenceNo:int; public var infoWindow:InformationWindow; + public var block:Block; } } \ No newline at end of file Modified: mentalmodels/trunk/flex/src/actionscript/InformationWindow.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/InformationWindow.as 2009-12-02 00:32:41 UTC (rev 389) +++ mentalmodels/trunk/flex/src/actionscript/InformationWindow.as 2009-12-02 23:47:09 UTC (rev 390) @@ -1,5 +1,7 @@ package actionscript { + import mx.collections.ArrayCollection; + [Bindable] [RemoteClass(alias="edu.asu.commons.mme.entity.InformationWindow")] public class InformationWindow @@ -7,5 +9,6 @@ public var id:int; public var indexID:int; public var title:String; + public var blockInfoWindows:ArrayCollection; } } \ No newline at end of file Modified: mentalmodels/trunk/flex/src/actionscript/questions/CategoricalOption.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/questions/CategoricalOption.as 2009-12-02 00:32:41 UTC (rev 389) +++ mentalmodels/trunk/flex/src/actionscript/questions/CategoricalOption.as 2009-12-02 23:47:09 UTC (rev 390) @@ -9,6 +9,6 @@ public var optionKey:String; public var choices:ArrayCollection = new ArrayCollection(); - + public var id:Number; } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <see...@us...> - 2009-12-02 00:32:52
|
Revision: 389 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=389&view=rev Author: seematalele Date: 2009-12-02 00:32:41 +0000 (Wed, 02 Dec 2009) Log Message: ----------- 1)Created CommunicationService.java 2)Expose this as a remoting service in applicationContext file 3)Re factored the entire database. Removed the forecasting, editing strategy. Kept Strategy design as it is. Needs to convert strategy design into day by day decision. 4)Changed the communication component so that it will invoke CommunicationService. Some of the things are hard coded. for example, student and subtopic, because do not know how to find student object. Bugs- 1) Communication component is not displaying at all for the communication round. Next Tasks - 1) Test 10 sec timer, written code in MessageHandler. 2) Test communication once component is available. Modified Paths: -------------- mentalmodels/trunk/flex/src/custom/Communication.mxml mentalmodels/trunk/src/main/db/init-mme.sql mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/DayByDayDecisionsService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/GameService.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/utility/MessageHandler.java mentalmodels/trunk/src/main/webapp/WEB-INF/applicationContext.xml Added Paths: ----------- mentalmodels/trunk/src/main/java/edu/asu/commons/mme/dao/HibernateCommunicationDao.java mentalmodels/trunk/src/main/java/edu/asu/commons/mme/service/CommunicationService.java Modified: mentalmodels/trunk/flex/src/custom/Communication.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/Communication.mxml 2009-12-01 23:22:11 UTC (rev 388) +++ mentalmodels/trunk/flex/src/custom/Communication.mxml 2009-12-02 00:32:41 UTC (rev 389) @@ -1,38 +1,82 @@ <?xml version="1.0" encoding="utf-8"?> -<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" defaultButton="{btnSend}"> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" defaultButton="{btnSelfComm}" creationComplete="init()"> + + <mx:Consumer id="consumer" destination="mme" message="messageHandler(event.message)" fault="faultMsgHandler(event)" channelSet="{cs}" /> + <mx:ChannelSet id="cs"> + <!-- <mx:StreamingAMFChannel url="http://localhost:8080/messagebroker/streamingamf"/> --> + <mx:AMFChannel url="http://localhost:8080/mme/messagebroker/amflongpolling"/> + <mx:AMFChannel url="http://localhost:8080/mme/messagebroker/amfpolling"/> + </mx:ChannelSet> + <mx:Producer id="producer" destination="mme" channelSet="{cs}"/> + <mx:RemoteObject id="comunication" destination="communicationService" fault="faultHandler(event)"> + <mx:method name="saveCommunication"/> + </mx:RemoteObject> <mx:Script> <![CDATA[ - import mx.rpc.events.ResultEvent; - import mx.rpc.events.FaultEvent; + import actionscript.Group; import actionscript.Communication; import actionscript.Student; import mx.controls.Label; import mx.controls.Text; - - public var student:Student = null; - - public function faultHandler(event:FaultEvent):void + import mx.messaging.messages.IMessage; + import mx.messaging.events.MessageAckEvent; + import mx.messaging.events.MessageFaultEvent; + import mx.messaging.events.MessageEvent; + import mx.messaging.events.MessageFaultEvent; + import mx.messaging.events.MessageFaultEvent; + import mx.controls.Alert; + import mx.messaging.messages.AsyncMessage; + + import mx.messaging.Producer; + import mx.messaging.Consumer; + + import mx.rpc.events.FaultEvent; + + public var student:actionscript.Student; + public var testDBD:TestDayByDayDecisions = new TestDayByDayDecisions(); + public function init():void { - // Silent Failure + /* var testDBD:TestDayByDayDecisions = new TestDayByDayDecisions(); + student = testDBD.studentObject; + var group:actionscript.Group = testDBD.getGroup(); + var subTopic:String = student.gameCode + group.id.toString() + student.id.toString();*/ + + consumer.subtopic = "test1.1"; + consumer.subscribe(); + + producer.subtopic = "test1.1"; + } - public function messageHandler(event:ResultEvent):void + public function faultMsgHandler(msgevent:MessageFaultEvent):void { - if(event.message.body is actionscript.Communication) - { - commReceived(event.message.body as actionscript.Communication); - } + Alert.show("Error in getting message: " + msgevent.faultString); } + private function faultHandler(event:FaultEvent):void + { + Alert.show("Fault:\n"+event.fault.message + "\n" + event.fault.getStackTrace()); + } public function btnSend_click():void { - var tempCommunication:actionscript.Communication = new actionscript.Communication(); - tempCommunication.date = new Date(); - tempCommunication.message = txtMessage.text; - tempCommunication.student = this.student; + var message:IMessage = new AsyncMessage(); + var comm:actionscript.Communication = new actionscript.Communication(); + comm.message = txtMessage.text; + comm.date = new Date(); + comm.student = new actionscript.Student(); + comm.student.birthYear = 1982; + comm.student.gender = "F"; + comm.student.major = "CSE" + comm.student.semester = "1"; + comm.student.gameCode = "test1" + comm.student.id = 1; + + message.body = comm; + //producer.send(message); + txtMessage.text = ""; - - //<service>.<method>(tempCommunication); + //<service>.<method>(txtMessage.text); + comunication.saveCommunication(comm); } public function btnSelfComm_click():void { @@ -41,7 +85,6 @@ comm.date = new Date(); comm.student = new actionscript.Student(); comm.student.id = 1; txtMessage.text = ""; - commReceived(comm); } @@ -51,7 +94,11 @@ vbxMessages.addChild(commToText(comm)); vbxMessages.verticalScrollPosition = vbxMessages.maxVerticalScrollPosition; } - + + private function messageHandler(message:IMessage):void + { + commReceived(message.body as actionscript.Communication); + } private function strToText(str:String):Text { var newText:Text = new Text(); @@ -68,10 +115,7 @@ ]]> </mx:Script> - <mx:RemoteObject id="communicationService" destination="communicationService" fault="faultHandler(event)"> - <mx:method name="sendCommunication" result="resultHandler(event)"/> - </mx:RemoteObject> - + <mx:VBox id="vbxMessages" width="500" height="300" verticalScrollPolicy="on"/> <mx:HBox> <mx:TextInput id="txtMessage" width="500"/> @@ -79,4 +123,5 @@ <mx:Button id="btnSelfComm" label="SelfComm" click="btnSelfComm_click()" visible="false"/> </mx:HBox> + </mx:VBox> Modified: mentalmodels/trunk/src/main/db/init-mme.sql =================================================================== --- mentalmodels/trunk/src/main/db/init-mme.sql 2009-12-01 23:22:11 UTC (rev 388) +++ mentalmodels/trunk/src/main/db/init-mme.sql 2009-12-02 00:32:41 UTC (rev 389) @@ -4,6 +4,10 @@ -- ------------------------------------------------------ -- Server version 5.1.33-community +-- This file contains the refactored MME database. Foolowing records have been removed : + -- Forecasting questions + -- Blocks with "Editing strategy" description and their corresponding question groups, infromation windows and questions + /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; @@ -40,7 +44,7 @@ LOCK TABLES `block` WRITE; /*!40000 ALTER TABLE `block` DISABLE KEYS */; -INSERT INTO `block` VALUES (1,'Introduction',1080,1,1),(2,'Design Strategy',1080,1,2),(3,'Characterizing own strategy',1020,2,2),(4,'Editing strategy',300,3,2),(5,'Day-by-day decisions game',360,4,2),(6,'Evaluation of Outcomes',660,5,2),(7,'Communication',360,1,3),(8,'Design Strategy',300,1,4),(9,'Characterizing own strategy',540,2,4),(10,'Editing strategy',180,3,4),(11,'Day-by-day decisions game',360,4,4),(12,'Evaluation of Outcomes',360,5,4),(13,'Final data gathering',120,1,5),(14,'Debriefing',120,2,5),(15,'Communication - Questions',480,2,3),(16,'Day-by-day decisions game',345,2,1); +INSERT INTO `block` VALUES (1,'Introduction',1080,1,1),(2,'Design Strategy',1080,1,2),(3,'Characterizing own strategy',1020,2,2),(5,'Day-by-day decisions game',360,4,2),(6,'Evaluation of Outcomes',660,5,2),(7,'Communication',360,1,3),(8,'Design Strategy',300,1,4),(9,'Characterizing own strategy',540,2,4),(11,'Day-by-day decisions game',360,4,4),(12,'Evaluation of Outcomes',360,5,4),(13,'Final data gathering',120,1,5),(14,'Debriefing',120,2,5),(15,'Communication - Questions',480,2,3),(16,'Day-by-day decisions game',345,2,1); /*!40000 ALTER TABLE `block` ENABLE KEYS */; UNLOCK TABLES; @@ -70,7 +74,7 @@ LOCK TABLES `block_information_window` WRITE; /*!40000 ALTER TABLE `block_information_window` DISABLE KEYS */; -INSERT INTO `block_information_window` VALUES (4,1,1,1),(5,2,1,2),(6,3,1,3),(7,4,1,4),(8,1,2,1),(9,2,2,3),(10,3,2,4),(11,4,2,5),(12,1,3,1),(13,2,3,3),(14,3,3,4),(15,4,3,6),(16,1,4,1),(17,2,4,3),(18,3,4,4),(19,4,4,6),(20,5,4,5),(21,6,4,7),(22,7,4,8),(23,1,5,1),(24,2,5,3),(25,3,5,4),(26,4,5,6),(27,1,6,1),(28,2,6,3),(29,3,6,4),(30,4,6,6),(31,5,6,7),(32,6,6,8),(33,7,6,9),(34,8,6,10),(35,1,7,1),(36,2,7,3),(37,3,7,4),(38,4,7,6),(39,1,8,1),(40,2,8,3),(41,3,8,4),(42,4,8,6),(43,5,8,5),(44,6,8,8),(45,7,8,9),(46,8,8,10),(47,9,8,11),(48,10,8,12),(49,1,9,1),(50,2,9,3),(51,3,9,4),(52,4,9,6),(53,5,9,8),(54,6,9,9),(55,7,9,10),(56,8,9,11),(57,9,9,12),(58,1,10,1),(59,2,10,3),(60,3,10,4),(61,4,10,5),(62,5,10,6),(63,6,10,7),(64,7,10,8),(65,8,10,9),(66,9,10,10),(67,10,10,11),(68,11,10,12),(69,1,12,1),(70,2,12,3),(71,3,12,4),(72,4,12,5),(73,5,12,6),(74,6,12,7),(75,7,12,8),(76,8,12,9),(77,9,12,10),(78,10,12,11),(79,11,12,12),(80,1,13,1),(81,2,13,3),(82,3,13,4),(83,4,13,6),(84,5,13,9),(85,6,13,10),(86,1,14,1),(87,2,14,3),(88,3,14,4),(89,4,14,6),(90,5,14,9),(91,6,14,10); +INSERT INTO `block_information_window` VALUES (4,1,1,1),(5,2,1,2),(6,3,1,3),(7,4,1,4),(8,1,2,1),(9,2,2,3),(10,3,2,4),(12,1,3,1),(13,2,3,3),(14,3,3,4),(23,1,5,1),(24,2,5,3),(25,3,5,4),(27,1,6,1),(28,2,6,3),(29,3,6,4),(31,5,6,7),(33,7,6,9),(34,8,6,10),(35,1,7,1),(36,2,7,3),(37,3,7,4),(39,1,8,1),(40,2,8,3),(41,3,8,4),(45,7,8,9),(46,8,8,10),(47,9,8,11),(48,10,8,12),(49,1,9,1),(50,2,9,3),(51,3,9,4),(54,6,9,9),(55,7,9,10),(56,8,9,11),(57,9,9,12),(69,1,12,1),(70,2,12,3),(71,3,12,4),(74,6,12,7),(76,8,12,9),(77,9,12,10),(78,10,12,11),(79,11,12,12),(80,1,13,1),(81,2,13,3),(82,3,13,4),(84,5,13,9),(85,6,13,10),(86,1,14,1),(87,2,14,3),(88,3,14,4),(90,5,14,9),(91,6,14,10); /*!40000 ALTER TABLE `block_information_window` ENABLE KEYS */; UNLOCK TABLES; @@ -267,6 +271,35 @@ UNLOCK TABLES; -- +-- Table structure for table `day_group_location` +-- + +DROP TABLE IF EXISTS `day_group_location`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `day_group_location` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `current_population` double DEFAULT NULL, + `dayNumber` int(11) DEFAULT NULL, + `fish_leaving` double DEFAULT NULL, + `fish_return` double DEFAULT NULL, + `groupLocation_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FK1FAF7878A77DC681` (`groupLocation_id`), + CONSTRAINT `FK1FAF7878A77DC681` FOREIGN KEY (`groupLocation_id`) REFERENCES `group_location` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `day_group_location` +-- + +LOCK TABLES `day_group_location` WRITE; +/*!40000 ALTER TABLE `day_group_location` DISABLE KEYS */; +/*!40000 ALTER TABLE `day_group_location` ENABLE KEYS */; +UNLOCK TABLES; + +-- -- Table structure for table `forecasting_question` -- @@ -389,8 +422,33 @@ -- Table structure for table `group_location` -- +DROP TABLE IF EXISTS `group_location`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `group_location` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `initial_population` double NOT NULL, + `max_capacity` double NOT NULL, + `group_id` bigint(20) NOT NULL, + `location_id` bigint(20) NOT NULL, + PRIMARY KEY (`id`), + KEY `FKCFF7B975224FD013` (`location_id`), + KEY `FKCFF7B97565663181` (`group_id`), + CONSTRAINT `FKCFF7B97565663181` FOREIGN KEY (`group_id`) REFERENCES `grp` (`id`), + CONSTRAINT `FKCFF7B975224FD013` FOREIGN KEY (`location_id`) REFERENCES `location` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; -- +-- Dumping data for table `group_location` +-- + +LOCK TABLES `group_location` WRITE; +/*!40000 ALTER TABLE `group_location` DISABLE KEYS */; +/*!40000 ALTER TABLE `group_location` ENABLE KEYS */; +UNLOCK TABLES; + +-- -- Table structure for table `grp` -- @@ -597,7 +655,7 @@ LOCK TABLES `question` WRITE; /*!40000 ALTER TABLE `question` DISABLE KEYS */; -INSERT INTO `question` VALUES (1,0,'Most important goal:',1,'categorical',10),(2,0,'Second most important goal:',2,'categorical',10),(3,0,'Third most important goal:',4,'categorical',10),(4,0,'Compared to the most important goal, this goal is',3,'psychometric',10),(7,0,'An example of a scale would be',1,'psychometric',11),(8,0,'<ul>\r<li>Why did you design the strategy the way you did? What did you consider and why do you think your strategy is an adequate solution?</li>\r<li>What actions do you expect from the other fishermen in your group? Why do you think, they might act this way?</li>\r<li>How do you think your strategy will work? Will the fish population grow or shrink in the different bays? What earnings do you expect?</li>\r</ul>\r',1,'text',12),(9,0,'Compared to the most important goal, this goal is',5,'psychometric',10),(10,0,'<b>Most important goal:</b>',1,'categorical',13),(11,0,'<b>Second most important goal:</b>',2,'categorical',13),(12,0,'Compared to the most important goal, this goal is',3,'psychometric',13),(13,0,'<b>Third most important goal:</b>',4,'categorical',13),(14,0,'Compared to the most important goal, this goal is',5,'psychometric',13),(15,0,'Over all, how much do like your group (i.e. the other players)?',1,'psychometric',14),(16,0,'How important is it for you what the others think about you and your behavior (i.e. your reputation in the group)?',2,'psychometric',14),(17,0,'How important is it for you that the others can reach their goals (i.e. the outcomes are fair)?',3,'psychometric',14),(18,0,'What do you think, how important is it for the others that you can reach your goals (i.e. the outcomes are fair)?',4,'psychometric',14),(19,0,'Do you perceive the group as a team or as competing players?',5,'psychometric',14),(20,0,'How much do you trust the others in your group?',1,'psychometric',15),(21,0,'How important is it for you that the others in your group can and do trust you?',2,'psychometric',15),(22,0,'How much do you think your group trying to coordinate their actions to reach better outcomes for all?',3,'psychometric',15),(23,1,'How much are you trying to follow rules or agreements that emerged from the communication?',4,'psychometric',15),(24,1,'How much do you think <i>the others</i> are trying to follow rules or agreements that emerged from the communica-tion?',5,'psychometric',15),(25,0,'Do you feel a sense of ‘commitment’ to act in the way you specified in your strategy?',1,'psychometric',16),(26,0,'Would you feel any discomfort or tension if you would act differently than you specified in your strategy?',2,'psychometric',16),(27,0,'Do you feel any sort of ‘social pressure’ to act in the way you specified in your strategy?',3,'psychometric',16),(28,0,'Would you feel guilt or shame if you had acted differently than you specified in your strategy?',4,'psychometric',16),(29,0,'Are you afraid of some sort of ‘punishment’ if you had acted differently as specified in your strategy?',5,'psychometric',16),(30,0,'How well did you understand the dynamics of the fish population?',1,'psychometric',17),(31,0,'Did the others in your group understand the dynamics better or worse than you?',2,'psychometric',17),(32,0,'How confident are you in having developed a strategy that leads to ‘good’ outcomes regarding your goals?',3,'psychometric',17),(33,0,'How much does your strategy depend on how the others in the group will act to reach the desired outcomes?',4,'psychometric',17),(34,0,'Would you classify your strategy as ‘safe’ in the sense of having acceptable but suboptimal results for sure, or rather as ‘risky’ in the sense of having the optimal results if everything runs like expected or very poor results otherwise?',5,'psychometric',17),(35,0,'',1,'forecastingfishermen',18),(36,0,'',1,'forecastingfish',19),(37,0,'',1,'strategydesign',9),(38,0,'',1,'strategydesign',22),(39,0,'',1,'daybydaydecisions',24),(40,0,'',1,'psychometric',27),(41,0,'… better understand the dynamics of the fish population.',1,'psychometric',29),(42,0,'… better understand the other fishermen in my group.',2,'psychometric',29),(43,0,'… better understand how to design the strategy.',3,'psychometric',29),(44,0,'… feel a ‘team spirit’ in the group.',4,'psychometric',29),(45,0,'… appraise the other fishermen in my group differently. Now I think about the others…',5,'psychometric',29),(46,0,'… better understand the dynamics of the fish population.',1,'psychometric',30),(47,0,'… better understand the other fishermen.',2,'psychometric',30),(48,0,'… better understand how to design the strategy.',3,'psychometric',30),(49,0,'… feel a ‘team spirit’ in the group.',4,'psychometric',30),(50,0,'… appraise the other fishermen in my group differently. Now I think about the others …',5,'psychometric',30),(51,0,'Did the communication have any form of reference to how to fish or design the strategy?',1,'categorical',31),(54,0,'',1,'psychometric',32),(55,0,'',2,'psychometric',32),(56,0,'',3,'psychometric',32),(57,0,'',4,'psychometric',32),(58,0,'',5,'psychometric',32),(59,0,'How clear is it to you, that you have to fish conforming to this rule, agreement or coordination attempt?',1,'psychometric',33),(60,0,'Do you think the other fishermen understood how they have to act according to this rule?<br>I think the others… ',2,'psychometric',33),(61,0,'Will you follow the rule, agreement, or coordination attempt that emerged from communication?<br>I will follow the rule…',3,'psychometric',33),(62,0,'Do you think, the other fishermen in you group will follow the rule, agreement, or coordination attempt?<br>\rI think, the others will… ',4,'psychometric',33),(63,0,'Considering the effects you expect for following the rule and your expectations of how the group will follow the rule, do you think the group will do better or worse due to the rule?',5,'psychometric',33),(64,0,'New understanding of fish dynamics',1,'text',34),(65,0,'New Expectations on how the others of the group will act',2,'text',34),(66,0,'Ideas for improving your strategy',3,'text',34),(67,0,'How interesting was the experiment for you?',1,'psychometric',35),(68,0,'How would you rate the effort you invested to design your strategy?',2,'psychometric',35),(69,0,'How difficult was it to understand the problem?',3,'psychometric',35),(70,0,'How difficult was it to find a good strategy?',4,'psychometric',35),(71,0,'How clear was it what you had to do?',5,'psychometric',35),(72,0,'How many times have you participated in problem solving experiments similar to this one?',1,'text',36),(73,0,'If you already participated in such experiments, when was the last time?',2,'categorical',36),(74,0,'Comments and Feedback',1,'text',37),(75,0,'',1,'strategydesign',40),(76,0,'',1,'strategydesign',53),(77,0,'',1,'daybydaydecisions',55),(78,0,'',1,'psychometric',58),(79,0,'',2,'psychometric',27),(80,0,'I feel the outcomes are:',3,'psychometric',27),(81,0,'',1,'psychometric',59),(82,0,'',2,'psychometric',59),(83,0,'',3,'psychometric',59),(84,0,'',4,'psychometric',59),(85,0,'',5,'psychometric',59),(86,0,'I did not understand the dynamics of the fish population well enough.',1,'psychometric',60),(87,0,'Some of the other fishermen did not understand the dynamics of the fish population well enough.',2,'psychometric',60),(88,0,'The actions of the others in my group did not help my strategy work well.',3,'psychometric',60),(89,0,'Some of the other fishermen acted too reluctantly (harvested too few).',4,'psychometric',60),(90,0,'Some of the other fishermen acted too aggressively (harvested too much).',5,'psychometric',60),(91,0,'The group was too uncoordinated',6,'psychometric',60),(92,0,'The group did not follow the rules or agreements that emerged from the communication enough.',7,'psychometric',60),(93,0,'The rules or agreements that emerged from the communication did not work out well.',8,'psychometric',60),(94,0,'What were the most important reasons for you to deviate from your strategy during the day-by-day decisions?<br>\rIf you did not deviate from your strategy then please write something like \"No difference\" in the text field.',1,'text',61),(95,0,'New understanding of fish dynamics',1,'text',62),(96,0,'New expectations on how the others of the group will act',2,'text',62),(97,0,'Ideas for improving your strategy',3,'text',62),(98,0,'',2,'psychometric',58),(99,0,'I feel the outcomes are:',3,'psychometric',58),(100,0,'',1,'psychometric',63),(101,0,'',2,'psychometric',63),(102,0,'',3,'psychometric',63),(103,0,'',4,'psychometric',63),(104,0,'',5,'psychometric',63),(105,0,'I did not understand the dynamics of the fish population well enough.',1,'psychometric',64),(106,0,'Some of the other fishermen did not understand the dynamics of the fish population well enough',2,'psychometric',64),(107,0,'The actions of the others in my group did not help my strategy work well.',3,'psychometric',64),(108,0,'Some of the other fishermen acted too reluctantly (harvested too few).',4,'psychometric',64),(109,0,'Some of the other fishermen acted too aggressively (harvested too much).',5,'psychometric',64),(110,0,'The group was too uncoordinated',6,'psychometric',64),(111,0,'The group did not follow the rules or agreements that emerged from the communication enough.',7,'psychometric',64),(112,0,'The rules or agreements that emerged from the communication did not work out well.',8,'psychometric',64),(113,0,'What were the most important reasons for you to deviate from your strategy during the day-by-day decisions?<br>\rIf you did not deviate from your strategy then please write something like \"No difference\" in the text field.',1,'text',65),(114,0,'New understanding of fish dynamics',1,'text',66),(115,0,'New expectations on how the others of the group will act',2,'text',66),(116,0,'Ideas for improving your strategy',3,'text',66),(117,0,'Describe in your own words what the rule, agreement, or other coordination attempt states. Describe how you and the others should act and what would happen if one does not act in this way.<br>\rIf you cannot identify any sort of coordination attempt in the communication, write \"no coordination\" in the field below.<br>\r(The information you write in this field will be available the next time you edit your strategy.)',2,'text',31),(118,0,'How often do you play strategy games (i.e. any games where you have to anticipate the moves of other players and plan your own moves ahead, like computer games, card games, board games, etc)?',3,'categorical',36),(120,0,'<ul>\r<li>Why did you design the strategy the way you did? What did you consider and why do you think your strategy is an adequate solution?</li>\r<li>What actions do you expect from the other fishermen in your group? Why do you think, they might act this way?</li>\r<li>How do you think your strategy will work? Will the fish population grow or shrink in the different bays? What earnings do you expect?</li>\r</ul>\r',1,'text',42),(121,0,'Most important goal:',1,'categorical',43),(122,0,'Second most important goal:',2,'categorical',43),(123,0,'Compared to the most important goal, this goal is',3,'psychometric',43),(124,0,'Third most important goal:',4,'categorical',43),(125,0,'Compared to the most important goal, this goal is',5,'psychometric',43),(126,0,'<b>Most important goal:</b>',1,'categorical',44),(127,0,'<b>Second most important goal:</b>',2,'categorical',44),(128,0,'Compared to the most important goal, this goal is',3,'psychometric',44),(129,0,'<b>Third most important goal:</b>',4,'categorical',44),(130,0,'Compared to the most important goal, this goal is',5,'psychometric',44),(131,0,'Over all, how much do like your group (i.e. the other players)?',1,'psychometric',45),(132,0,'How important is it for you what the others think about you and your behavior (i.e. your reputation in the group)?',2,'psychometric',45),(133,0,'How important is it for you that the others can reach their goals (i.e. the outcomes are fair)?',3,'psychometric',45),(134,0,'What do you think, how important is it for the others that you can reach your goals (i.e. the outcomes are fair)?',4,'psychometric',45),(135,0,'Do you perceive the group as a team or as competing players?',5,'psychometric',45),(136,0,'How much do you trust the others in your group?',1,'psychometric',46),(137,0,'How important is it for you that the others in your group can and do trust you?',2,'psychometric',46),(138,0,'How much do you think your group trying to coordinate their actions to reach better outcomes for all?',3,'psychometric',46),(139,0,'How much are you trying to follow rules or agreements that emerged from the communication?',4,'psychometric',46),(140,0,'How much do you think <i>the others</i> are trying to follow rules or agreements that emerged from the communica-tion?',5,'psychometric',46),(141,0,'Do you feel a sense of ‘commitment’ to act in the way you specified in your strategy?',1,'psychometric',47),(142,0,'Would you feel any discomfort or tension if you would act differently than you specified in your strategy?',2,'psychometric',47),(143,0,'Do you feel any sort of ‘social pressure’ to act in the way you specified in your strategy?',3,'psychometric',47),(144,0,'Would you feel guilt or shame if you had acted differently than you specified in your strategy?',4,'psychometric',47),(145,0,'Are you afraid of some sort of ‘punishment’ if you had acted differently as specified in your strategy?',5,'psychometric',47),(146,0,'How well did you understand the dynamics of the fish population?',1,'psychometric',48),(147,0,'Did the others in your group understand the dynamics better or worse than you?',2,'psychometric',48),(148,0,'How confident are you in having developed a strategy that leads to ‘good’ outcomes regarding your goals?',3,'psychometric',48),(149,0,'How much does your strategy depend on how the others in the group will act to reach the desired outcomes?',4,'psychometric',48),(150,0,'Would you classify your strategy as ‘safe’ in the sense of having acceptable but suboptimal results for sure, or rather as ‘risky’ in the sense of having the optimal results if everything runs like expected or very poor results otherwise?',5,'psychometric',48),(151,0,'',1,'forecastingfishermen',49),(152,0,'',1,'forecastingfish',50),(153,0,'',1,'daybydaydecisions',67); +INSERT INTO `question` VALUES (1,0,'Most important goal:',1,'categorical',10),(2,0,'Second most important goal:',2,'categorical',10),(3,0,'Third most important goal:',4,'categorical',10),(4,0,'Compared to the most important goal, this goal is',3,'psychometric',10),(7,0,'An example of a scale would be',1,'psychometric',11),(8,0,'<ul>\r<li>Why did you design the strategy the way you did? What did you consider and why do you think your strategy is an adequate solution?</li>\r<li>What actions do you expect from the other fishermen in your group? Why do you think, they might act this way?</li>\r<li>How do you think your strategy will work? Will the fish population grow or shrink in the different bays? What earnings do you expect?</li>\r</ul>\r',1,'text',12),(9,0,'Compared to the most important goal, this goal is',5,'psychometric',10),(10,0,'<b>Most important goal:</b>',1,'categorical',13),(11,0,'<b>Second most important goal:</b>',2,'categorical',13),(12,0,'Compared to the most important goal, this goal is',3,'psychometric',13),(13,0,'<b>Third most important goal:</b>',4,'categorical',13),(14,0,'Compared to the most important goal, this goal is',5,'psychometric',13),(15,0,'Over all, how much do like your group (i.e. the other players)?',1,'psychometric',14),(16,0,'How important is it for you what the others think about you and your behavior (i.e. your reputation in the group)?',2,'psychometric',14),(17,0,'How important is it for you that the others can reach their goals (i.e. the outcomes are fair)?',3,'psychometric',14),(18,0,'What do you think, how important is it for the others that you can reach your goals (i.e. the outcomes are fair)?',4,'psychometric',14),(19,0,'Do you perceive the group as a team or as competing players?',5,'psychometric',14),(20,0,'How much do you trust the others in your group?',1,'psychometric',15),(21,0,'How important is it for you that the others in your group can and do trust you?',2,'psychometric',15),(22,0,'How much do you think your group trying to coordinate their actions to reach better outcomes for all?',3,'psychometric',15),(23,1,'How much are you trying to follow rules or agreements that emerged from the communication?',4,'psychometric',15),(24,1,'How much do you think <i>the others</i> are trying to follow rules or agreements that emerged from the communica-tion?',5,'psychometric',15),(25,0,'Do you feel a sense of ‘commitment’ to act in the way you specified in your strategy?',1,'psychometric',16),(26,0,'Would you feel any discomfort or tension if you would act differently than you specified in your strategy?',2,'psychometric',16),(27,0,'Do you feel any sort of ‘social pressure’ to act in the way you specified in your strategy?',3,'psychometric',16),(28,0,'Would you feel guilt or shame if you had acted differently than you specified in your strategy?',4,'psychometric',16),(29,0,'Are you afraid of some sort of ‘punishment’ if you had acted differently as specified in your strategy?',5,'psychometric',16),(30,0,'How well did you understand the dynamics of the fish population?',1,'psychometric',17),(31,0,'Did the others in your group understand the dynamics better or worse than you?',2,'psychometric',17),(32,0,'How confident are you in having developed a strategy that leads to ‘good’ outcomes regarding your goals?',3,'psychometric',17),(33,0,'How much does your strategy depend on how the others in the group will act to reach the desired outcomes?',4,'psychometric',17),(34,0,'Would you classify your strategy as ‘safe’ in the sense of having acceptable but suboptimal results for sure, or rather as ‘risky’ in the sense of having the optimal results if everything runs like expected or very poor results otherwise?',5,'psychometric',17),(37,0,'',1,'strategydesign',9),(39,0,'',1,'daybydaydecisions',24),(40,0,'',1,'psychometric',27),(41,0,'… better understand the dynamics of the fish population.',1,'psychometric',29),(42,0,'… better understand the other fishermen in my group.',2,'psychometric',29),(43,0,'… better understand how to design the strategy.',3,'psychometric',29),(44,0,'… feel a ‘team spirit’ in the group.',4,'psychometric',29),(45,0,'… appraise the other fishermen in my group differently. Now I think about the others…',5,'psychometric',29),(46,0,'… better understand the dynamics of the fish population.',1,'psychometric',30),(47,0,'… better understand the other fishermen.',2,'psychometric',30),(48,0,'… better understand how to design the strategy.',3,'psychometric',30),(49,0,'… feel a ‘team spirit’ in the group.',4,'psychometric',30),(50,0,'… appraise the other fishermen in my group differently. Now I think about the others …',5,'psychometric',30),(51,0,'Did the communication have any form of reference to how to fish or design the strategy?',1,'categorical',31),(54,0,'',1,'psychometric',32),(55,0,'',2,'psychometric',32),(56,0,'',3,'psychometric',32),(57,0,'',4,'psychometric',32),(58,0,'',5,'psychometric',32),(59,0,'How clear is it to you, that you have to fish conforming to this rule, agreement or coordination attempt?',1,'psychometric',33),(60,0,'Do you think the other fishermen understood how they have to act according to this rule?<br>I think the others… ',2,'psychometric',33),(61,0,'Will you follow the rule, agreement, or coordination attempt that emerged from communication?<br>I will follow the rule…',3,'psychometric',33),(62,0,'Do you think, the other fishermen in you group will follow the rule, agreement, or coordination attempt?<br>\rI think, the others will… ',4,'psychometric',33),(63,0,'Considering the effects you expect for following the rule and your expectations of how the group will follow the rule, do you think the group will do better or worse due to the rule?',5,'psychometric',33),(64,0,'New understanding of fish dynamics',1,'text',34),(65,0,'New Expectations on how the others of the group will act',2,'text',34),(66,0,'Ideas for improving your strategy',3,'text',34),(67,0,'How interesting was the experiment for you?',1,'psychometric',35),(68,0,'How would you rate the effort you invested to design your strategy?',2,'psychometric',35),(69,0,'How difficult was it to understand the problem?',3,'psychometric',35),(70,0,'How difficult was it to find a good strategy?',4,'psychometric',35),(71,0,'How clear was it what you had to do?',5,'psychometric',35),(72,0,'How many times have you participated in problem solving experiments similar to this one?',1,'text',36),(73,0,'If you already participated in such experiments, when was the last time?',2,'categorical',36),(74,0,'Comments and Feedback',1,'text',37),(75,0,'',1,'strategydesign',40),(77,0,'',1,'daybydaydecisions',55),(78,0,'',1,'psychometric',58),(79,0,'',2,'psychometric',27),(80,0,'I feel the outcomes are:',3,'psychometric',27),(81,0,'',1,'psychometric',59),(82,0,'',2,'psychometric',59),(83,0,'',3,'psychometric',59),(84,0,'',4,'psychometric',59),(85,0,'',5,'psychometric',59),(86,0,'I did not understand the dynamics of the fish population well enough.',1,'psychometric',60),(87,0,'Some of the other fishermen did not understand the dynamics of the fish population well enough.',2,'psychometric',60),(88,0,'The actions of the others in my group did not help my strategy work well.',3,'psychometric',60),(89,0,'Some of the other fishermen acted too reluctantly (harvested too few).',4,'psychometric',60),(90,0,'Some of the other fishermen acted too aggressively (harvested too much).',5,'psychometric',60),(91,0,'The group was too uncoordinated',6,'psychometric',60),(92,0,'The group did not follow the rules or agreements that emerged from the communication enough.',7,'psychometric',60),(93,0,'The rules or agreements that emerged from the communication did not work out well.',8,'psychometric',60),(94,0,'What were the most important reasons for you to deviate from your strategy during the day-by-day decisions?<br>\rIf you did not deviate from your strategy then please write something like \"No difference\" in the text field.',1,'text',61),(95,0,'New understanding of fish dynamics',1,'text',62),(96,0,'New expectations on how the others of the group will act',2,'text',62),(97,0,'Ideas for improving your strategy',3,'text',62),(98,0,'',2,'psychometric',58),(99,0,'I feel the outcomes are:',3,'psychometric',58),(100,0,'',1,'psychometric',63),(101,0,'',2,'psychometric',63),(102,0,'',3,'psychometric',63),(103,0,'',4,'psychometric',63),(104,0,'',5,'psychometric',63),(105,0,'I did not understand the dynamics of the fish population well enough.',1,'psychometric',64),(106,0,'Some of the other fishermen did not understand the dynamics of the fish population well enough',2,'psychometric',64),(107,0,'The actions of the others in my group did not help my strategy work well.',3,'psychometric',64),(108,0,'Some of the other fishermen acted too reluctantly (harvested too few).',4,'psychometric',64),(109,0,'Some of the other fishermen acted too aggressively (harvested too much).',5,'psychometric',64),(110,0,'The group was too uncoordinated',6,'psychometric',64),(111,0,'The group did not follow the rules or agreements that emerged from the communication enough.',7,'psychometric',64),(112,0,'The rules or agreements that emerged from the communication did not work out well.',8,'psychometric',64),(113,0,'What were the most important reasons for you to deviate from your strategy during the day-by-day decisions?<br>\rIf you did not deviate from your strategy then please write something like \"No difference\" in the text field.',1,'text',65),(114,0,'New understanding of fish dynamics',1,'text',66),(115,0,'New expectations on how the others of the group will act',2,'text',66),(116,0,'Ideas for improving your strategy',3,'text',66),(117,0,'Describe in your own words what the rule, agreement, or other coordination attempt states. Describe how you and the others should act and what would happen if one does not act in this way.<br>\rIf you cannot identify any sort of coordination attempt in the communication, write \"no coordination\" in the field below.<br>\r(The information you write in this field will be available the next time you edit your strategy.)',2,'text',31),(118,0,'How often do you play strategy games (i.e. any games where you have to anticipate the moves of other players and plan your own moves ahead, like computer games, card games, board games, etc)?',3,'categorical',36),(120,0,'<ul>\r<li>Why did you design the strategy the way you did? What did you consider and why do you think your strategy is an adequate solution?</li>\r<li>What actions do you expect from the other fishermen in your group? Why do you think, they might act this way?</li>\r<li>How do you think your strategy will work? Will the fish population grow or shrink in the different bays? What earnings do you expect?</li>\r</ul>\r',1,'text',42),(121,0,'Most important goal:',1,'categorical',43),(122,0,'Second most important goal:',2,'categorical',43),(123,0,'Compared to the most important goal, this goal is',3,'psychometric',43),(124,0,'Third most important goal:',4,'categorical',43),(125,0,'Compared to the most important goal, this goal is',5,'psychometric',43),(126,0,'<b>Most important goal:</b>',1,'categorical',44),(127,0,'<b>Second most important goal:</b>',2,'categorical',44),(128,0,'Compared to the most important goal, this goal is',3,'psychometric',44),(129,0,'<b>Third most important goal:</b>',4,'categorical',44),(130,0,'Compared to the most important goal, this goal is',5,'psychometric',44),(131,0,'Over all, how much do like your group (i.e. the other players)?',1,'psychometric',45),(132,0,'How important is it for you what the others think about you and your behavior (i.e. your reputation in the group)?',2,'psychometric',45),(133,0,'How important is it for you that the others can reach their goals (i.e. the outcomes are fair)?',3,'psychometric',45),(134,0,'What do you think, how important is it for the others that you can reach your goals (i.e. the outcomes are fair)?',4,'psychometric',45),(135,0,'Do you perceive the group as a team or as competing players?',5,'psychometric',45),(136,0,'How much do you trust the others in your group?',1,'psychometric',46),(137,0,'How important is it for you that the others in your group can and do trust you?',2,'psychometric',46),(138,0,'How much do you think your group trying to coordinate their actions to reach better outcomes for all?',3,'psychometric',46),(139,0,'How much are you trying to follow rules or agreements that emerged from the communication?',4,'psychometric',46),(140,0,'How much do you think <i>the others</i> are trying to follow rules or agreements that emerged from the communica-tion?',5,'psychometric',46),(141,0,'Do you feel a sense of ‘commitment’ to act in the way you specified in your strategy?',1,'psychometric',47),(142,0,'Would you feel any discomfort or tension if you would act differently than you specified in your strategy?',2,'psychometric',47),(143,0,'Do you feel any sort of ‘social pressure’ to act in the way you specified in your strategy?',3,'psychometric',47),(144,0,'Would you feel guilt or shame if you had acted differently than you specified in your strategy?',4,'psychometric',47),(145,0,'Are you afraid of some sort of ‘punishment’ if you had acted differently as specified in your strategy?',5,'psychometric',47),(146,0,'How well did you understand the dynamics of the fish population?',1,'psychometric',48),(147,0,'Did the others in your group understand the dynamics better or worse than you?',2,'psychometric',48),(148,0,'How confident are you in having developed a strategy that leads to ‘good’ outcomes regarding your goals?',3,'psychometric',48),(149,0,'How much does your strategy depend on how the others in the group will act to reach the desired outcomes?',4,'psychometric',48),(150,0,'Would you classify your strategy as ‘safe’ in the sense of having acceptable but suboptimal results for sure, or rather as ‘risky’ in the sense of having the optimal results if everything runs like expected or very poor results otherwise?',5,'psychometric',48),(153,0,'',1,'daybydaydecisions',67); /*!40000 ALTER TABLE `question` ENABLE KEYS */; UNLOCK TABLES; @@ -627,7 +685,7 @@ LOCK TABLES `question_group` WRITE; /*!40000 ALTER TABLE `question_group` DISABLE KEYS */; -INSERT INTO `question_group` VALUES (1,'In this experiment you will design a strategy to fish in an abstract fishing ground together with three other persons. As we are mainly interested in the reasons <i>why</i> you choose a certain strategy, we will ask you a number of questions. For the same reason, there are no correct or wrong strategies and no correct or wrong answers. However, since for each pound of fish you get during the experiment you will receive $1.00 US, you might be interested in finding a strategy that fits your goals well. For this, you will need to understand the dynamics of the (simulated) fish population and anticipate well the behavior of the other persons of your group.',30,'<b>Welcome to the E-Fishery Experiment</b>',1,1),(2,'<p>The experiment will run as follows:</p> <ul> <li><b>Introduction</b>: We will explain the interface and how the dynamics of the fish population are modeled. We will also ask you some questions about you and you will have the opportunity to make your decisions on how to fish on a (simulated) day-by-day basis to get a feeling for the dynamics of the fish population. </li> <li><b>Strategy design 1</b>: You will design a fishing strategy that will be simulated together with the strategies of the other persons in your group, and we ask you a larger amount of questions to understand your decisions and to help you reflect on those decisions. </li> <li><b>Fishing and evaluation 1</b>: Besides simulating the strategies you will decide on how to fish on a (simulated) day-by-day basis. Then, we will ask you some questions on your evaluation of the results. </li> <li><b>Communication</b>:You will have the opportunity to chat with the other persons in your group. After the chat we will ask some questions to asses your evaluation of the communication. </li> <li><b>Strategy design, fishing and evaluation 2</b>: The strategy design, fishing and evaluation are repeated as described above. </li> <li><b>Finishing the experiment</b>: The experiment closes with some final questions and more information on the experiment, and you will have the opportunity to give a feedback if you wish to do so. </li> </ul> <p> In the <b>information bar above the main window</b> you can see which part of the experiment you are in, your progress and how you are doing with the time. </p>',30,'<b>Experimental procedure</b>',2,1),(3,'<p>The <b>information window "Fishing Ground"</b> gives you an overview that will be explained here.</p> <p> Imagine you are living on an island and your only income is from a species of fish that only survives in the shallow bays formed by the island. The fish can leave crowed bays and move to less crowded bays, but they cannot survive in the ocean. Nor can new fish arrive from the ocean. </p> <p> The fish population grows at a constant rate. Thus, the more fish are in a bay the faster the population grows. However, the population a bay can sustain is limited and fish leave crowed bays to find less crowded bays. The more crowded a bay, the more fish leave and the less fish enter the bay (the movement is directly proportional to the percentage to which a bay is filled up). The number of fish leaving the bay is proportional to the rate of growth, and the number of fish entering the bay is also proportional to the amount of fish leaving the three bays (i.e. fish in the ocean). </p> <p> The equations of these dynamics are given in the information windows. It is, however, not necessary to know them for designing a strategy. For this, you only have to <b>understand the following five principles</b>: </p> <ul> <li>If all bays are <b>filled up</b> with fish, then the total growth is highest, but all additional lbs of fish are lost to the ocean and the amount of fish in the bays stops growing.</li> <li>If the bays are <b>half filled</b>, then the amount of fish in the bays grows fastest.</li> <li>If the bays are <b>nearly empty</b>, the population grows very slowly.</li> <li>If there is <b>no fish</b> in any of the bays, there will be never any fish again.</li> <li>If there are both <b>crowded and empty</b> bays, a lot of fish move from the crowded to the empty bays.</li> </ul> ',120,'<b>How the dynamics of the fish population are modeled</b>',3,1),(4,'<p>The three bays are different in size and characteristics leading to different growth rates and capacities (i.e. the maximal amount of fish the bay can sustain). At the start of the simulation each bay is half filled.</p> <table> <thead> <th></th><th>Bay 1</th><th>Bay 2</th><th>Bay 3</th> </thead> <tbody> <tr> <td>Capacity:</td><td>10 lb</td><td>20 lb</td><td>30 lb</td> </tr> <tr> <td>Starts with:</td><td>5 lb</td><td>10 lb</td><td>15 lb</td> </tr> <tr> <td>Growth rate:</td><td>50% per day</td><td>15% per day</td><td>5% per day</td> </tr> </tbody> </table> <p> <b>How much fish</b> you take out in a day is <b>directly proportional with the extent that the bay is filled up with fish</b>. Your fishing gear allows you to harvest a maximum of 5 lbs. Thus, if the bay is completely filled up you get 5 lb of fish. If the bay is half filled, you get 2.5 lb of fish. If the bay is filled up only to 20 % you will get 1 lb, etc. The fish population is diminished by the same amount. If several persons fish the same bay and together would get more fish than the bay holds, then all the fish in the bay are distributed equally among these fishermen. </p> <p>However, you can <b>stay in the harbor</b> instead of fishing. This way, you do not get anything and the fish population is not diminished. </p> <p> Your task is to design a strategy of how to fish this fishing ground for 30 days together with three other persons (thus, with you the group compromises 4 persons). You will define the number of days that you stay in each bay or in the harbor. Please note that this is not an exam! We do not expect you to find the mathematically optimal solution to this problem. We want to know how you come up with a solution that sufficiently fulfills your goals. As long as we can understand why you choose a certain strategy you can come up with whatever you like. </p> ',120,'<b>Differences of bays and effects of fishing</b>',4,1),(5,'<p>Before designing the strategy, you have the opportunity to make your decisions on a day-by-day basis for the simulation. You will interact with the actual model of the fishing ground together with the other persons of your group. Thus, the problems and possibilities you will experience in this warm-up are relevant for the design of your strategy. </p> <p> The <b>interface</b> you will encounter on the next page has the following elements: <ul> <li>Information on the day of the simulation</li> <li>Buttons for your decision. If you want to fish in Bay 1, for example, click on Button "Bay 1". </li> <li>Time remaining. You have 10 seconds for each decision. If you do not press any button within these 10 seconds then you will stay in the harbor for this day. However, you can change your decision within these 10 seconds (i.e. if you clicked on "Bay 1" after 4 seconds and after another 4 seconds on "Bay 3", you will go to Bay 3). </li> <li>Table of past results. Your previous locations from past days are highlighted. The table shows you how much you fished and who else was in the same location as you. You do not have any information of locations where you not have been. </li> ',60,'<b>A warm-up</b>',5,1),(7,'<p>In what we refer to as a \'strategy\' you predefine your decisions of where to go each day of the simulation.\r Al-though only 30 days will be simulated, your strategy should represent your decisions for an indefinite period. Therefore you define a <b>set of decisions that will be repeated</b> until the end of the simulation. The set can contain as many decisions as you want but try to use as few as possible. Remember: Often simple strategies are more effective!</p> <p>It might be that you want to base your set of repeated decisions on another state of the fish population. In this case you can define a set of not repeated decisions that are applied at the beginning of the simulation. For example, you might first stay in the harbor to let the fish population increase or first fish all the bays to reduce the fish population before you start the repeated sequence of decisions.</p> <p>In this strategy you define how many days you stay at a certain location and to which other location you will move on.\r If, for example, you define to repeat the sequence \"2 days in harbor - 3 days in Bay 1 - 2 days in Bay 2\" you will not fish for two days, then fish in Bay 1 for three days, then fish in Bay 2 for two days, then not fish for two days, then fish in Bay 1 for three days, etc.</p> ',480,'<b>Designing your Strategy</b>',1,2),(8,'<p>Your strategy is mainly based on the number of days you stay at a certain location. However, things might run differently than you expected and you might wish to leave a bay earlier than the days you specified because you get too few fish out of that bay. For doing so you can specify a threshold of income. If you fish less then this threshold, the next day you will not fish this bay anymore but move on to the next location specified in your strategy.</p> <p>Note: Thresholds refer to the quantity of fish you get during one day fishing in a bay and not, for example, to the quantity of fish in the bay, fish fished by others, sum of fish already fished, etc.</p> <p>The final option you have is to stop repeating your strategy and stay in the harbor for some days. This op-tion can be used to prevent the total destruction of the fish population. For this you define a threshold and a number of days. If during one repetition of your decision set you never fished the amount defined by the threshold, then you stay in the harbor for the specified number of days before you start the next repetition.</p> <p>Note: Intentionally we do not allow designing \'intelligent\' strategies that search for solutions during the game. You have to think about what would be the best solution for you and express it with the options explained above.</p> ',90,'<b>Some special features of the strategy design</b>',2,2),(9,'<p>Design your strategy by clicking on <b>\'New\'</b> and <b>\'Delete\'</b>. You have to specify at least one repeated decision! If you are not sure about the meaning of the concepts used, refer to the information window \'Help for strategy design\'. </br>\rWhen you are done, click on <b>\'Next\'</b> </p>',480,'<b>Design your strategy</b>',3,2),(10,'<p>Please specify three goals that most influenced the design of your strategy. You can select from 18 different goals grouped in three categories (foci). </p><p>First select the focus of the goal (earnings, fish population or the other fishermen). Based on this selection, the list on the right hand sight will be filled and you can select one of these goals. For the second and third most important goal, also state, how much less important they are in relation to the most important goal.</p><p> The information you write into these fields will be available the next time you edit your strategy.</p>',30,'<b>What goals did you follow when designing your strategy?</b>',3,3),(11,'<p>We will ask you a number of questions on the strategy you just designed. This will help us to better understand how you came up with your strategy and it might help you reflect on certain aspects to improve your strategy.</p>\r<p>Besides <b>large fields</b> to write text and <b>small fields</b> to write numbers, you will encounter drop-down lists for selecting predefined values and scales. </p>\r<p>To give an answer on a scale, click on the location between the labels that comes closest to your opinion. By clicking on the scale, a slider appears that marks the value you selected. You can change the value by clicking on another position on the scale. By clicking on the reset button, the sliders of all scales on a page are removed and you can start selecting values again.</p>\r<p>Please try to answer all questions even if you are not sure. We are not testing your abilities but rather want to understand how you came up with your strategy.</p>\r',30,'<b>Introduction to questionnaire</b>',1,3),(12,'<p>Please explain your strategy with a few sentences. Particularly consider the following aspects:</p>',300,'<b>Explain the strategy in your own words</b>',2,3),(13,'<p>Specify the three goals that you think most influenced the design of the strategy of the other fishermen in your group. You can select from 18 different goals grouped in three categories (foci).</p>\r<p>First select the focus of the goal (earnings, fish population or the other fishermen). Based on this selection, the list on the right hand sight will be filled and you can select one of these goals. For the second and third most important goal, also state, how much less important they are in relation to the most important goal</p>\r',30,'<b>What goals do you think the others follow?</b>',4,3),(14,'',30,'<b>How do you perceive your group?</b>',5,3),(15,'',30,'<b>How much do you count on others and how much can they count on you?</b>',6,3),(16,'',30,'<b>What else influenced your strategy design?</b>',7,3),(17,'',60,'<b>How confident are you in reaching the outcomes you are expecting?</b>',8,3),(18,'<p>Fill in the following table your expectations of the others’ actions (i.e. the number of fishermen in each bay) for the first 15 days. Please note that we ask only for the expectations of where the others will go. </p>',180,'<b>What are you expecting the others will do?</b>',9,3),(19,'<p>Please enter in the table below your expectations of how the fish population develops within the first six days. Note that by clicking on “Update” the earnings and fish remaining in the bays is calculated, using your expecta-tions of the other’s actions and your strategy. Thus, you only have to think about how the fish population changes from one day to the next due to growth and movement of the fish. These estimations can be really rough. We do not expect you do perform detailed calculations.</p>\r<b>Note: You can only change the entries of one day at a time. To calculate the values and activate the next day for entries click on “Update”. You cannot return to previous days!</b>\r',180,'<b>What are you expecting how the fish population will develop?</b>',10,3),(20,'By clicking on “Accept” you will leave this part of the questionnaire and return to the strategy design. <b>You can-not return to this or previous pages!</b> However, important information for the design of your strategy will be available in information windows.',30,'<b>Leaving questionnaire on your strategy</b>',11,3),(21,'<p>The previous questions may have lead to some reflections on your strategy and you may wish to change some elements of it. Among the information windows you will find your previous strategy, your goals and your fore-cast.</p>\r<p>The time for editing your strategy depends on how fast you finished the questionnaire. For the next simulation we have to synchronize the group again. If you have been rather fast, you can think now more deeply about your strategy. If you are rather behind the time suggestion, you have to make your changes quickly.</p>\r<p>The interface for designing your strategy will not be explained again. If you are not sure about some elements, please refer to the information window “Help on strategy design”.</p>\r',30,'<b>Edit your strategy</b>',1,4),(22,'<p>Design your strategy by clicking on <b>\'New\'</b> and <b>\'Delete\'</b>. You have to specify at least one repeated decision! If you are not sure about the meaning of the concepts used, refer to the information window \'Help for strategy design\'. </br>\rWhen you are done, click on <b>\'Next\'</b> </p>',240,'<b>Design your strategy</b>',2,4),(23,'<p>Before we present the results of your strategy, we would like to see again how you make your decisions day-by-day. On the next page you will find the same interface as you already used to decide on how to fish the modeled fishing grounds.</p>',15,'<b>Applying your strategy in day-by-day decisions</b>',1,5),(24,'',345,'<b>Day-by-day-decisions</b>',2,5),(25,'<p>We will now present you the results of your strategy. By clicking on “Accept” you cannot return to this or any previous page, but the results of your day-by-day decisions (and also of your strategy) will be available in an information window.</p>',15,'<b>Leaving day-bay-day decisions</b>',3,5),(26,'',60,'<b>Your strategy resulted in the following actions</b>',1,6),(27,'<p>First we want to know your emotional reactions to the results:</p>',30,'<b>What are your emotional reactions to the outcome?</b>',2,6),(28,'You can now chat for 5 minutes with the other fishermen in your group. You can talk about whatever you want as long as you…\r<ul><li>…do not reveal your identity.</li>\r<li>…do not threaten others with any consequence after the experiment is finished.</li>\r<li>…do not promise others side-payments after the experiment is completed.</li></ul>\rThe interface works like a text messenger. In the text box at the bottom you write your text and by clicking on “Send” you send this text to all other group members. In the large box in the center of the window you see all messages that have been sent during the communication.<br>\rAfter five minutes the “Send” button will be deactivated and the “Next” button activated. Please click then on “Next” to answer some questions about the communication. You can return to this page to see the communication protocol again.\r',360,'<b>Chat with the other fishermen in your group</b>',1,7),(29,'Due to the conversation, I now…',30,'<b>Did the communication have any effect on you?</b>',1,15),(30,'Due to the conversation, the other fishermen in my group…',30,'<b>What do you think were the effects of the communication on the others?</b>',2,15),(31,'',60,'<b>Did the communication lead to some sort of coordination of the fishing?</b>',3,15),(32,'The rule, agreement, or coordination attempt is… ',30,'<b>What is your opinion about the rule(s) that emerged from communication?</b>',4,15),(33,'',30,'<b>What will be the effects of the rule?</b>',5,15),(34,'In the fields below note what you have learned from the communication to improve your strategy.<br>\rThink about your understanding of the dynamics of the fish population, your expectations about the behavior of the other fishermen in your group and possibilities to improve your strategy. For each of these aspects a separate field is offered. This information will be available in the next round of designing your strategy.<br>\rIf you have no entry for one of the fields below, write “none” in the respective field.<br>\rThe information you write into these fields will be available the next time you edit your strategy.',300,'<b>Lessons learned<b>',6,15),(35,'Congratulations! You finished the actual experiment. We wan... [truncated message content] |
From: <al...@us...> - 2009-12-01 23:22:28
|
Revision: 388 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=388&view=rev Author: alllee Date: 2009-12-01 23:22:11 +0000 (Tue, 01 Dec 2009) Log Message: ----------- minor refactoring Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-01 23:22:11 UTC (rev 388) @@ -42,7 +42,7 @@ private int role; - private static final int MONITER = 0; + private static final int MONITOR = 0; private static final int HARVEST = 1; private static final int SANCTION = 2; private static final int HARVESTANDSANCTION = 3; @@ -90,7 +90,7 @@ } return result;*/ - if(getMyRole() == MONITER || getMyRole() == SANCTION || getMyRole() == HARVESTANDSANCTION)return true; + if(getMyRole() == MONITOR || getMyRole() == SANCTION || getMyRole() == HARVESTANDSANCTION)return true; else return false; } @@ -100,6 +100,19 @@ else return false; } + public boolean isMonitor() { + return role == MONITOR; + } + + public boolean canHarvest() { + return role == HARVEST || role == HARVESTANDSANCTION; + } + + public boolean canSanction() { + return role == SANCTION || role == HARVESTANDSANCTION || role == MONITOR; + + } + /* * public Map<Identifier, Duration> getSanctioned() { return sanctioned; } */ Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-01 23:22:11 UTC (rev 388) @@ -123,7 +123,7 @@ private JButton sendMyVotes; private JPanel instructionsPanel; private Timer timer; - private SixChoicePanel newPanel[]; + private SixChoicePanel[] newPanel; private int noOfEnforcements; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-01 23:22:11 UTC (rev 388) @@ -8,6 +8,7 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; import edu.asu.commons.client.BaseClient; import edu.asu.commons.event.ClientMessageEvent; @@ -440,6 +441,13 @@ public void run() { //System.out.println("inside client"); //Dimension defaultDimension = new Dimension(600, 600); + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch(Exception e) { + e.printStackTrace(); + System.err.println("Couldn't set native look and feel: "+ e); + } Dimension defaultDimension = new Dimension(600, 600); JFrame frame = new JFrame(); ForagingClient client = new ForagingClient(new ServerConfiguration(), defaultDimension); @@ -449,6 +457,7 @@ frame.add(client.panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); + } }; SwingUtilities.invokeLater(createGuiRunnable); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 23:22:11 UTC (rev 388) @@ -79,41 +79,41 @@ private final ClientDataModel dataModel; // instructions components. - + private Component currentCenterComponent; - + private JScrollPane instructionsScrollPane; private HtmlEditorPane instructionsEditorPane; - + private JPanel messagePanel; private JScrollPane errorMessageScrollPane; private JTextPane errorMessageTextPane; private JScrollPane regulationVotingIntructionsScrollPane; private JPanel regulationVotingPane; - + private JPanel labelPanel; - + public static Duration duration; - + private RegulationData votedRegulation; - + private EnforcementData votedEnforcement; - + private ChatPanel chatPanel; - + public static String roleDescription [] = { - "Moniter: You cannot harvest but can sanction other participants\n" + - "To sanction press numbers from 1-5. At the end of the round you\n" + - "will receive 25% tokens from every other participant", - "Harvest: You can collect tokens as in earlier rounds. But you \n" + - "cannot sanction", - "Sanction: You cannot harvest but only sanction \n", - "Harvest and Sanction: You can collect tokens and at the same & \n" + - "at the same time sanction other participants"}; - + "Moniter: You cannot harvest but can sanction other participants\n" + + "To sanction press numbers from 1-5. At the end of the round you\n" + + "will receive 25% tokens from every other participant", + "Harvest: You can collect tokens as in earlier rounds. But you \n" + + "cannot sanction", + "Sanction: You cannot harvest but only sanction \n", + "Harvest and Sanction: You can collect tokens and at the same & \n" + + "at the same time sanction other participants"}; + private SanctioningPanel sanctioningPanel; - + private EnforcementPanel enforcementPanel; private JLabel informationLabel; @@ -121,25 +121,25 @@ private JLabel timeLeftLabel; private JPanel subjectWindow; - + private JEditorPane regulationVotingIntructions; private ForagingClient client; - + private SubjectView subjectView; public Timer timer; - + public static final Object regulationSignal = new Object(); - + public static final Object enforcementVotesSignal = new Object(); - + public static final Object regulationVotesSignal = new Object(); - + public static final Object clientRoleSignal = new Object(); private final StringBuilder instructionsBuilder = new StringBuilder(); - + private EventChannel channel; private Map<Identifier, RegulationData> regulations; @@ -158,7 +158,7 @@ Dimension subjectViewSize = new Dimension((int) Math.floor(size.getWidth()), (int) Math.floor(size.getHeight() * 0.85)); subjectView = new SubjectView(subjectViewSize, dataModel); -// subjectView.addKeyListener(this); + // subjectView.addKeyListener(this); initGuiComponents(); } @@ -181,7 +181,7 @@ } - + /** * In certain cases, init() _can_ be called before endRound() is finished. Need to lock * access! @@ -194,22 +194,22 @@ } // don't display next round time, instead wait for the // facilitator signal. - + timeLeftLabel.setText("Waiting for facilitator's signal."); informationLabel.setText("Waiting for facilitator's signal."); // add the next round instructions to the existing debriefing text set by the previous // EndRoundEvent. } - - - + + + private ActionListener createQuizListener(final RoundConfiguration configuration) { return new ActionListener() { public void actionPerformed(ActionEvent e) { // System.err.println("In action performed with event: " + e); HtmlEditorPane.FormActionEvent formEvent = (HtmlEditorPane.FormActionEvent) e; Properties actualAnswers = formEvent.getData(); -// actualAnswers.list(System.err); + // actualAnswers.list(System.err); List<String> incorrectAnswers = new ArrayList<String>(); // iterate through expected answers for (Map.Entry<String, String> entry : configuration.getQuizAnswers().entrySet()) { @@ -245,25 +245,25 @@ public void collectToken(Point position) { subjectView.collectToken(position); } - + private void startEnforcementDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(15); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(10); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Round begins now."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; remove(enforcementPanel); - // System.out.println("Enforcement Panel removed : New Pane added"); + // System.out.println("Enforcement Panel removed : New Pane added"); addCenterComponent(instructionsScrollPane); - + } else { timeLeftLabel.setText( String.format("Voting for the enforcement mechanism will start in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -271,25 +271,25 @@ } }); timer.start(); - } + } } - + private void startRegulationDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(15); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(15); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Enforcement Voting begins now."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; //remove(sanctioningPanel); - // System.out.println("New Pane added"); + // System.out.println("New Pane added"); initializeEnforcementVotingPanel(); } else { @@ -298,43 +298,43 @@ } }); timer.start(); - } + } } - + private void startEnforcementVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(30); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; //remove(sanctioningPanel); getEnforcementPanel().stopTimer(); getEnforcementPanel().sendEnforcementVotes(); //displayEnforcementWaitMessage(); - + System.out.println("Enforcement voting sent"); Utils.waitOn(enforcementVotesSignal); - + System.out.println("Voted enforcement received"); - + //Utils.waitOn(clientRoleSignal); - - // System.out.println("Client Role received"); - + + // System.out.println("Client Role received"); + votedEnforcement = getEnforcementPanel().getVotedEnforcement(); - + displayVotedEnforcement(); - - // System.out.println("New Pane added"); + + // System.out.println("New Pane added"); } else { timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -342,23 +342,23 @@ } }); timer.start(); - } + } } - + private void startRegulationVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(30); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; //remove(sanctioningPanel); getSanctioningPanel().stopTimer(); @@ -367,10 +367,10 @@ //displayRegulationWaitMessage(); Utils.waitOn(regulationVotesSignal); System.out.println("Voted regulation received"); - + votedRegulation = getSanctioningPanel().getVotedRegulation(); displayVotedRegulation(); - + //System.out.println("New Pane added"); } else { @@ -379,17 +379,17 @@ } }); timer.start(); - } + } } - - private void startSanctioningTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(30); + + private void startRegulationSubmissionTimer() { + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { - timeLeftLabel.setText("Your time to write the regualtion is finished. Next round begins shortly."); + timeLeftLabel.setText("Your time to write the regulation is finished. Next round begins shortly."); //new code //FIXME: //Need to add the regulationVotingPane over here @@ -398,7 +398,7 @@ //client.transmit(); //addCenterComponent(instructionsScrollPane); //addCenterComponent(regulationVotingPane); - timer.stop(); + timer.stop(); timer = null; getSanctioningPanel().sendRegulation(); Utils.waitOn(regulationSignal); @@ -410,24 +410,23 @@ } }); timer.start(); - } + } } private void startChatTimer() { - if (timer == null) { - // final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); - final Duration duration = Duration.create(30); + if (timer == null) { + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Chat is now disabled. Next round begins shortly."); - + //new code //Need to add the regulationVotingPane over here //instead of the instructionsScrollPane //addCenterComponent(instructionsScrollPane); - timer.stop(); + timer.stop(); timer = null; - + initializeSanctioningPanel(); } @@ -437,7 +436,7 @@ } }); timer.start(); - } + } } private String getInformationLabelText() { @@ -470,7 +469,7 @@ long secondsLeft = roundTimeLeft / 1000L; return "Time left: " + secondsLeft + " second(s)"; } - + private void setInstructions(String s) { instructionsEditorPane.setText(s); instructionsEditorPane.setCaretPosition(0); @@ -482,7 +481,7 @@ private HtmlEditorPane createInstructionsEditorPane() { // JEditorPane pane = new JEditorPane("text/html", - // "Costly Sanctioning Experiment"); + // "Costly Sanctioning Experiment"); final HtmlEditorPane htmlPane = new HtmlEditorPane(); htmlPane.setPreferredSize(new Dimension(400, 400)); htmlPane.setEditable(false); @@ -491,30 +490,30 @@ } public static void setNativeLookAndFeel() { try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { - // System.out.println("Error setting native LAF: " + e); + // System.out.println("Error setting native LAF: " + e); } - } + } private SanctioningPanel updateRegulationVotingPanel(){ - // System.out.println("Inside update regulation"); - - SanctioningPanel sanctioningPanel = getSanctioningPanel(); + // System.out.println("Inside update regulation"); + + SanctioningPanel sanctioningPanel = getSanctioningPanel(); sanctioningPanel.initRegulationVotingCompontents(); regulations = getSanctioningPanel().getAllRegulations(); - // System.out.println("Fetched all the regulations from the server : "+regulations.size()); - // setNativeLookAndFeel(); - //regulationVotingPane.add(votingArea, BorderLayout.SOUTH); + // System.out.println("Fetched all the regulations from the server : "+regulations.size()); + // setNativeLookAndFeel(); + //regulationVotingPane.add(votingArea, BorderLayout.SOUTH); //regulationVotingPane.add(regulationVotingIntructionsScrollPane,BorderLayout.NORTH); return sanctioningPanel; } - + private void initGuiComponents() { // FIXME: replace with CardLayout for easier switching between panels -// cardLayout = new CardLayout(); - + // cardLayout = new CardLayout(); + setLayout(new BorderLayout(4, 4)); instructionsEditorPane = createInstructionsEditorPane(); instructionsScrollPane = new JScrollPane(instructionsEditorPane); @@ -532,9 +531,9 @@ // latencyLabel = new JLabel("Latency: 0"); informationLabel.setBackground(Color.YELLOW); informationLabel.setForeground(Color.BLUE); - -// getSanctioningPanel().initializeVotingPaneWithRegulations(); - + + // getSanctioningPanel().initializeVotingPaneWithRegulations(); + regulationVotingPane = new JPanel(); //regulationVotingPane.setLayout(new BoxLayout(regulationVotingPane, BoxLayout.LINE_AXIS)); regulationVotingPane.setLayout(new BorderLayout(4,4)); @@ -553,16 +552,16 @@ labelPanel.add(Box.createHorizontalGlue()); labelPanel.add(informationLabel); add(labelPanel, BorderLayout.NORTH); - + // add message window. messagePanel = new JPanel(new BorderLayout()); -// messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS)); + // messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS)); messagePanel.add(new JLabel("System Messages"), BorderLayout.NORTH); errorMessageTextPane = new JTextPane(); errorMessageTextPane.setEditable(false); errorMessageTextPane.setFont(new Font("arial", Font.BOLD, 12)); - + addStyles(errorMessageTextPane.getStyledDocument()); errorMessageScrollPane = new JScrollPane(errorMessageTextPane); Dimension scrollPaneSize = new Dimension(getPreferredSize().width, 50); @@ -571,15 +570,15 @@ errorMessageScrollPane.setMaximumSize(scrollPaneSize); messagePanel.add(errorMessageScrollPane, BorderLayout.CENTER); add(messagePanel, BorderLayout.SOUTH); - - + + addKeyListener( createGameWindowKeyListener() ); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { requestFocusInWindow(); } }); - + addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent event) { Component component = event.getComponent(); @@ -592,7 +591,7 @@ }); // add component listeners, chat panel, and sanctioning window IF chat/sanctioning are enabled, and after the end of the round... } - + /** * IMPORTANT: this method handles client keyboard inputs within the game. * @return @@ -619,23 +618,23 @@ switch (keyCode) { // token request handling case KeyEvent.VK_SPACE: - if(client.isHarvestingAllowed()) { - event = new CollectTokenRequest(client.getId()); - } - else - displayErrorMessage("You are either a Moniter or Sanctioner : You cannot harvest ", 1); - + if(client.isHarvestingAllowed()) { + event = new CollectTokenRequest(client.getId()); + } + else + displayErrorMessage("You are either a Moniter or Sanctioner : You cannot harvest ", 1); + break; // real-time sanctioning keycode handling case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: - // System.out.println("Key pressed : "+(keyChar-48)); - if(dataModel.getRoundConfiguration().isChatEnabled() == false) { - return; - } + // System.out.println("Key pressed : "+(keyChar-48)); + if(dataModel.getRoundConfiguration().isChatEnabled() == false) { + return; + } if (client.isSanctioningAllowed() && client.canPerformRealTimeSanction(getEnforcementPanel().getVotedEnforcement())) { - //System.out.println("Can do sanctioning"); + //System.out.println("Can do sanctioning"); int assignedNumber = keyChar - 48; Identifier sanctionee = dataModel.getClientId(assignedNumber); if (sanctionee == null || sanctionee.equals(dataModel.getId())) { @@ -645,21 +644,21 @@ // only allow sanctions for subjects within this subject's field of vision Point subjectPosition = dataModel.getClientDataMap().get(sanctionee).getPoint(); if (dataModel.getClientData().isSubjectInFieldOfVision(subjectPosition)) { - // System.out.println("sanctioning event sent"); + // System.out.println("sanctioning event sent"); event = new RealTimeSanctionRequest(dataModel.getId(), sanctionee); // below function must be used for enforcement type4 dataModel.sanction(dataModel.getId(), sanctionee); } else{ - displayErrorMessage("Sanctionee is out of range ", 1); - } + displayErrorMessage("Sanctionee is out of range ", 1); + } } else { - if(client.isSanctioningAllowed()==false){ - displayErrorMessage("You don't have the privilege to sanction",1); - } - return; + if(client.isSanctioningAllowed()==false){ + displayErrorMessage("You don't have the privilege to sanction",1); + } + return; } break; // reset token distribution request handling @@ -687,11 +686,11 @@ dataModel.getClientData().setPosition(newPosition); subjectView.repaint(); } - */ + */ } if (keyReleased) { // FIXME: have client directly render these requests? Would - // make the app more "responsive" and less tied to server latency. + // make the app more "responsive" and less tied to server latency. channel.handle(event); keyReleased = false; } @@ -699,7 +698,7 @@ }; } - + private boolean canResetTokenDistribution() { RoundConfiguration configuration = dataModel.getRoundConfiguration(); return configuration.isPracticeRound() && configuration.isPrivateProperty(); @@ -711,19 +710,19 @@ remove(currentCenterComponent); add(newCenterComponent, BorderLayout.CENTER); newCenterComponent.setVisible(true); - revalidate(); } currentCenterComponent = newCenterComponent; - // currentCenterComponent.repaint(); + revalidate(); + // currentCenterComponent.repaint(); } public void startRound() { final RoundConfiguration configuration = dataModel.getRoundConfiguration(); - if (timer != null) { - timer.stop(); - timer = null; - } - + if (timer != null) { + timer.stop(); + timer = null; + } + // currentExperimentConfiguration = configuration; Runnable runnable = new Runnable() { public void run() { @@ -735,22 +734,22 @@ // has begun. update(configuration.getRoundDuration().getTimeLeft()); if(configuration.isChatEnabled()){ - displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); + displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); } add(messagePanel, BorderLayout.SOUTH); - + addCenterComponent(subjectWindow); requestFocusInWindow(); } }; SwingUtilities.invokeLater(runnable); } - + public void displayErrorMessage(String errorMessage, int par) { // String chatHandle = getChatHandle(source); - if(par==1)errorMessageTextPane.setForeground(Color.RED); - else errorMessageTextPane.setForeground(Color.BLACK); - + if(par==1)errorMessageTextPane.setForeground(Color.RED); + else errorMessageTextPane.setForeground(Color.BLACK); + StyledDocument document = errorMessageTextPane.getStyledDocument(); try { document.insertString(document.getLength(), errorMessage + "\n", document.getStyle("bold")); @@ -761,7 +760,7 @@ throw new RuntimeException(e); } } - + // FIXME: add to some common GUI package? private void addStyles(StyledDocument styledDocument) { // and why not have something like... StyleContext.getDefaultStyle() to @@ -776,26 +775,26 @@ StyleConstants.setItalic(styledDocument .addStyle("italic", defaultStyle), true); } - - + + private double getIncome(float numTokens) { if (dataModel.getRoundConfiguration().isPracticeRound()) { return 0.0f; } return dataModel.getRoundConfiguration().getDollarsPerToken() * numTokens; } - + private void addDebriefingText(EndRoundEvent event) { instructionsBuilder.delete(0, instructionsBuilder.length()); instructionsBuilder.append( String.format("<h3>Your stats in this round:</h3>" + - "<ul>" + - "<li>Tokens collected: %d</li>" + - "<li>Income: $%3.2f</li>" + + "<ul>" + + "<li>Tokens collected: %d</li>" + + "<li>Income: $%3.2f</li>" + "</ul>", event.getCurrentTokens(), getIncome(event.getCurrentTokens())) - ); + ); double showUpFee = dataModel.getRoundConfiguration().getParentConfiguration().getShowUpFee(); instructionsBuilder.append(String.format("Your <b>total income</b> so far (including a $%3.2f bonus for showing up) is : $%3.2f<hr>", showUpFee, dataModel.getTotalIncome() + showUpFee)); @@ -805,7 +804,7 @@ } setInstructions(instructionsBuilder.toString()); } - + private void postSanctionDebriefingText(final PostRoundSanctionUpdateEvent event) { instructionsBuilder.delete(0, instructionsBuilder.length()); ClientData clientData = event.getClientData(); @@ -825,7 +824,7 @@ clientData.getSanctionCosts(), clientData.getCurrentTokens(), getIncome(clientData.getCurrentTokens())) - ); + ); instructionsBuilder.append(String.format("Your <b>total income</b> so far is: $%3.2f<hr>", getIncome(clientData.getTotalTokens()))); if (event.isLastRound()) { @@ -834,25 +833,25 @@ setInstructions(instructionsBuilder.toString()); } - + private ChatPanel getChatPanel() { if (chatPanel == null) { - //System.out.println("Chat panel is null"); + //System.out.println("Chat panel is null"); chatPanel = new ChatPanel(client); } return chatPanel; } private SanctioningPanel getSanctioningPanel() { if (sanctioningPanel == null) { - //System.out.println("Sanc panel is null"); - sanctioningPanel = new SanctioningPanel(client); + //System.out.println("Sanc panel is null"); + sanctioningPanel = new SanctioningPanel(client); } return sanctioningPanel; } private EnforcementPanel getEnforcementPanel() { if (enforcementPanel == null) { - //System.out.println("enf panel is null"); - enforcementPanel = new EnforcementPanel(client); + //System.out.println("enf panel is null"); + enforcementPanel = new EnforcementPanel(client); } return enforcementPanel; } @@ -876,65 +875,65 @@ instructionsEditorPane.setText("<b>Please wait while we compute your new token totals.</b>"); addCenterComponent(instructionsScrollPane); } - + public void displayVotedEnforcement(){ - //new code - // System.out.println("*****Inside display voting enforcement"); + //new code + // System.out.println("*****Inside display voting enforcement"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below enforcement has been voted from the voting conducting earlier<br><br>" + - "<b>"+getEnforcementPanel().getVotedEnforcementOptions(votedEnforcement.getResultIndex())+ - "</b><br><br>This is your role for the next round <br><br><b>"+roleDescription[client.getDataModel().getMyRole()]+"</b>"); + instructionsEditorPane.setText("Below enforcement has been voted from the voting conducting earlier<br><br>" + + "<b>"+getEnforcementPanel().getVotedEnforcementOptions(votedEnforcement.getResultIndex())+ + "</b><br><br>This is your role for the next round <br><br><b>"+roleDescription[client.getDataModel().getMyRole()]+"</b>"); remove(enforcementPanel); addCenterComponent(instructionsScrollPane); startEnforcementDisplayTimer(); } }); } - + public void displayRegulationWaitMessage(){ - //new code - // System.out.println("*****Inside reg wait mesg"); + //new code + // System.out.println("*****Inside reg wait mesg"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Message from the System:<br><br>" + - "<b>Please wait until the System receives votes from all players.System<br>"+ - "will calculate the result of the voting and display it in a moment</b>"); - remove(sanctioningPanel); + instructionsEditorPane.setText("Message from the System:<br><br>" + + "<b>Please wait until the System receives votes from all players.System<br>"+ + "will calculate the result of the voting and display it in a moment</b>"); + remove(sanctioningPanel); addCenterComponent(instructionsScrollPane); } }); } - + public void displayEnforcementWaitMessage(){ - //new code + //new code System.out.println("*****Inside enfr wait message"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Message from the System:<br><br>" + - "<b>Please wait until the System receives votes from all players.System<br>"+ - "will calculate the result of the voting and display it in a moment</b>"); - remove(enforcementPanel); + instructionsEditorPane.setText("Message from the System:<br><br>" + + "<b>Please wait until the System receives votes from all players.System<br>"+ + "will calculate the result of the voting and display it in a moment</b>"); + remove(enforcementPanel); addCenterComponent(instructionsScrollPane); } }); } - - + + public void displayVotedRegulation(){ - //new code - // System.out.println("*****Inside display voting regulation"); + //new code + // System.out.println("*****Inside display voting regulation"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getRegulationText()+".</b>"); + instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getRegulationText()+".</b>"); remove(sanctioningPanel); addCenterComponent(instructionsScrollPane); startRegulationDisplayTimer(); } }); } - + public void updateDebriefing(final PostRoundSanctionUpdateEvent event) { Runnable runnable = new Runnable() { public void run() { @@ -945,20 +944,20 @@ }; SwingUtilities.invokeLater(runnable); } - + public void resetPanels() { - //System.out.println("Reseting the panels"); - if(sanctioningPanel != null) - sanctioningPanel.resetHandles(); - if(enforcementPanel != null) - enforcementPanel.resetHandles(); - - sanctioningPanel = null; - enforcementPanel = null; - // chatPanel = null; + //System.out.println("Reseting the panels"); + // if(sanctioningPanel != null) + // sanctioningPanel.resetHandles(); + // if(enforcementPanel != null) + // enforcementPanel.resetHandles(); + + sanctioningPanel = null; + enforcementPanel = null; + // chatPanel = null; } - + public void endRound(final EndRoundEvent event) { Runnable runnable = new Runnable() { public void run() { @@ -986,11 +985,11 @@ } public void initializeEnforcementVotingPanel() { - //new code - // System.out.println("*****Inside initialize enforcement()"); + //new code + // System.out.println("*****Inside initialize enforcement()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code + //new code System.out.println("*****Inside thread initialize sanctioningPanel()"); EnforcementPanel enforcementPanel = getEnforcementPanel(); enforcementPanel.initialize(); @@ -1002,13 +1001,13 @@ }); } - + public void initializeRegulationVotingPanel() { - //new code - // System.out.println("*****Inside initialize regulation votingPanel()"); + //new code + // System.out.println("*****Inside initialize regulation votingPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code + //new code //System.out.println("*****Inside thread initialize votingPanel()"); remove(sanctioningPanel); SanctioningPanel sanctioningPanel = updateRegulationVotingPanel(); @@ -1018,32 +1017,31 @@ } }); } - + public void initializeSanctioningPanel() { - //new code - // System.out.println("*****Inside initialize sanctioningPanel()"); + //new code + // System.out.println("*****Inside initialize sanctioningPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code - // System.out.println("*****Inside thread initialize sanctioningPanel()"); + //new code + // System.out.println("*****Inside thread initialize sanctioningPanel()"); SanctioningPanel sanctioningPanel = getSanctioningPanel(); sanctioningPanel.initialize(); - // System.out.println("Initialization done"); + // System.out.println("Initialization done"); //remove( messagePanel ); - remove(chatPanel); addCenterComponent( sanctioningPanel ); - startSanctioningTimer(); + startRegulationSubmissionTimer(); } }); } public void initializeChatPanel() { - //new code - // System.out.println("*****Inside initialize chatPanel()"); + //new code + // System.out.println("*****Inside initialize chatPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code - // System.out.println("*****Inside thread initialize chatPanel()"); + //new code + // System.out.println("*****Inside thread initialize chatPanel()"); ChatPanel chatPanel = getChatPanel(); chatPanel.initialize(); remove( messagePanel ); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-01 23:22:11 UTC (rev 388) @@ -31,9 +31,10 @@ * If the parameters call for a background, this object is created so that * the scaling calculation does not have to be performed for each paint. */ - protected Image tokenImage, otherSubjectImage, selfImage, selfExplicitCollectionModeImage, beingSanctionedImage, sanctioningImage; + protected Image tokenImage, otherSubjectImage, selfImage, selfExplicitCollectionModeImage, beingSanctionedImage, sanctioningImage, monitorImage; - protected Image scaledTokenImage, scaledOtherSubjectImage, scaledSelfImage, scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage; + protected Image scaledTokenImage, scaledOtherSubjectImage, scaledSelfImage, + scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMonitorImage; /** * Use these for the dimensions when drawing. @@ -92,6 +93,7 @@ scaledSelfExplicitCollectionModeImage = selfExplicitCollectionModeImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledBeingSanctionedImage = beingSanctionedImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledSanctioningImage = sanctioningImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); + scaledMonitorImage = monitorImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); } /** @@ -142,6 +144,10 @@ if (sanctioningImage == null) { sanctioningImage = loadImage("images/gem-purple.gif"); } + // FIXME: generate a new image for the monitor, for now just use the explicit-mode image. + if (monitorImage == null) { + monitorImage = loadImage("images/gem-self-explicit.gif"); + } } private Image loadImage(String path) { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-01 23:22:11 UTC (rev 388) @@ -9,8 +9,6 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -26,8 +24,6 @@ import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.Timer; -import javax.swing.UIManager; -import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; @@ -57,61 +53,55 @@ public class SanctioningPanel extends JPanel { private ForagingClient client; - + private Map<Identifier, RegulationData> regulations; - + public SanctioningPanel (ForagingClient client) { this.client = client; this.clientId = client.getId(); client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { public void handle(final RegulationEvent regulationEvent) { - boolean votingFlag=false; - RegulationData regulationData = null; - regulations = regulationEvent.getAllRegulations(); - // System.out.println("Regulation received : "+regulations.size()); - noOfRegulations = regulations.size(); + boolean votingFlag=false; + RegulationData regulationData = null; + regulations = regulationEvent.getAllRegulations(); + // System.out.println("Regulation received : "+regulations.size()); + noOfRegulations = regulations.size(); for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - if(regulationData.isVoting())votingFlag = true; - break; + regulationData = regulations.get(targetId); + if(regulationData.isVoting())votingFlag = true; + break; } if(votingFlag) { - votedRegulation = regulationData; - Utils.notify(GameWindow2D.regulationVotesSignal); + votedRegulation = regulationData; + Utils.notify(GameWindow2D.regulationVotesSignal); } else { - //System.out.println("Finding my ID"); - findAndSetMyRegulationID(); - Utils.notify(GameWindow2D.regulationSignal); + //System.out.println("Finding my ID"); + findAndSetMyRegulationID(); + Utils.notify(GameWindow2D.regulationSignal); } } }); } public static int currentActive; - + public static int currentLabel; - - public static String regulationString = new String(""); - - private Identifier targetIdentifier = Identifier.ALL; - - private final static String HANDLE_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - private static String[] HANDLES; + public static String regulationString = ""; + private Identifier clientId; - + private String message; - + private RegulationData votedRegulation; private int noOfRegulations; - + private int currentRankingInformation[]; - + private Timer timer; private SixChoicePanel newPanel[]; @@ -126,41 +116,37 @@ private String[] votes = { "1", "2", "3","4", "5"}; private JScrollPane messageScrollPane; - + private JScrollPane regulationsInstructionsScrollPane; private JTextPane messageWindow; private List<Identifier> participants; - + private JEditorPane regulationsInstructionsPane; - public Map<Identifier, RegulationData> getAllRegulations() { - return regulations; - } - + public Map<Identifier, RegulationData> getAllRegulations() { + return regulations; + } + private void findAndSetMyRegulationID() { for (Identifier targetId : regulations.keySet()) { - if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ - client.setRegulationID(regulations.get(targetId).getRegulationID()); - //client.setEnforcementID(regulations.get(targetId).getToken()); - client.setToken(regulations.get(targetId).getToken()); - //System.out.println("My RegID:"+client.getRegulationID()); - //System.out.println("Token:"+client.getEnforcementID()); - return; - } + if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ + client.setRegulationID(regulations.get(targetId).getRegulationID()); + //client.setEnforcementID(regulations.get(targetId).getToken()); + client.setToken(regulations.get(targetId).getToken()); + //System.out.println("My RegID:"+client.getRegulationID()); + //System.out.println("Token:"+client.getEnforcementID()); + return; + } } } - - public void resetHandles() { - HANDLES = null; - } - + public RegulationData getVotedRegulation(){ - return this.votedRegulation; + return this.votedRegulation; } - + private void addStylesToMessageWindow() { StyledDocument styledDocument = messageWindow.getStyledDocument(); // and why not have something like... StyleContext.getDefaultStyle() to @@ -175,195 +161,174 @@ StyleConstants.setItalic(styledDocument .addStyle("italic", defaultStyle), true); } - + private void updateInstructionPanel(){ - // System.out.println("RegulationString:"+regulationString); + // System.out.println("RegulationString:"+regulationString); - if(regulationString.equals("")) - regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); - else - regulationsInstructionsPane.setText(regulationString); - - invalidate(); - validate(); + if(regulationString.equals("")) + regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); + else + regulationsInstructionsPane.setText(regulationString); + + revalidate(); instructionsPanel.repaint(); repaint(); - //pack(); - // setVisible(true); + //pack(); + // setVisible(true); } - + private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; - SixChoicePanel temp = null; - boolean enableSendButton = true; + int r,c,i,j; + int currentRanking; + SixChoicePanel temp = null; + boolean enableSendButton = true; -// System.out.println("Active panel: "+SixChoicePanel.currentActive); - - for(r = 0; r < noOfRegulations; r++) - { - // System.out.print(newPanel[r].currentRanking+" "); - if(newPanel[r].currentRanking == -1)enableSendButton = false; + // System.out.println("Active panel: "+SixChoicePanel.currentActive); - if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) - { - newPanel[r].currentRanking = -1; - newPanel[r].group.clearSelection(); - } - } - - - for(r = 0; r < noOfRegulations-1; r++) - { - for(c = 0; c < noOfRegulations-1; c++) - { - if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - } - } - for(c = 0; c < noOfRegulations; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } - - votingPanel.setVisible(false); - remove(votingPanel); + for(r = 0; r < noOfRegulations; r++) + { + // System.out.print(newPanel[r].currentRanking+" "); + if(newPanel[r].currentRanking == -1)enableSendButton = false; - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) + { + newPanel[r].currentRanking = -1; + newPanel[r].group.clearSelection(); + } + } - - for(i=0; i < noOfRegulations; i++) { - votingPanel.add(newPanel[i].regulationPanel); - votingPanel.add(newPanel[i].rankPanel); - } - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } - invalidate(); - validate(); - votingPanel.repaint(); - repaint(); + for(r = 0; r < noOfRegulations-1; r++) + { + for(c = 0; c < noOfRegulations-1; c++) + { + if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + } + } + for(c = 0; c < noOfRegulations; c++) + { + // System.out.print(newPanel[c].getCurrentRanking() +" "); + } + + votingPanel.setVisible(false); + remove(votingPanel); + + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + + + for(i=0; i < noOfRegulations; i++) { + votingPanel.add(newPanel[i].regulationPanel); + votingPanel.add(newPanel[i].rankPanel); + } + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); + + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + revalidate(); } - + public void stopTimer(){ - timer.stop(); + timer.stop(); } - + public void startTimer(){ - if (timer == null) { + if (timer == null) { timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } + //timer.stop(); + //timer = null; + // System.out.println("Timer called to update the voting panel:"); + updateVotingPanel(); + updateInstructionPanel(); + } }); timer.start(); - } + } } public void sendRegulation() { - System.out.println("Regulation sent"); + System.out.println("Regulation sent"); message = messageWindow.getText(); // System.err.println("message: " + message); - + RegulationData regulationData = new RegulationData(); regulationData.setRegulationText(message); regulationData.setVotingFlag(false); //FIXME:All the clients have to send some regulation - if (message == null || "".equals(message) || targetIdentifier == null) { - return; - } + // i... [truncated message content] |
From: <al...@us...> - 2009-12-01 22:28:57
|
Revision: 387 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=387&view=rev Author: alllee Date: 2009-12-01 22:28:49 +0000 (Tue, 01 Dec 2009) Log Message: ----------- voting + regulation + enforcement foraging configuration Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/server.xml Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,127 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="resource-width">13</entry> +<entry key="resource-depth">13</entry> +<entry key="practice-round">true</entry> +<entry key="private-property">true</entry> +<entry key="duration">240</entry> + +<entry key='resource-generator'>mobile</entry> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='view-tokens-radius'>3.0</entry> +<entry key='subjects-field-of-vision'>true</entry> + +<entry key='regrowth-rate'>.01</entry> +<entry key='initial-distribution'>.25</entry> +<entry key='always-explicit'>true</entry> + +<entry key="quiz">true</entry> +<entry key="q1">C</entry> +<entry key="q2">B</entry> + +<entry key="instructions"> +<![CDATA[ +<h3>General Instructions</h3> +<p> +You will appear on the screen as a yellow dot <img +src="http://localhost:8080/foraging/images/gem-self.gif">, You can move by pressing the four arrow +keys on your keyboard. You can move either up, down, left, or right. You have to +press a key for each and every move of your yellow dot. In this experiment you can +collect green diamond shaped tokens +<img src="http://localhost:8080/foraging/images/gem-token.gif"> and you will +earn two cents for each collected token. To collect a token, simply move your +yellow dot over a green token and press the <b>space bar</b>. If you move +over a token without pressing the <b>space bar</> you will NOT collect that +token. +</p> + +<p> +The tokens that you collect have the potential to regenerate. After you have +collected a green token, a new token can once again appear on that empty cell. +However, the rate at which new tokens will appear depends on the number of +adjacent cells that still have tokens. The more tokens in the 8 cells around +an empty cell, the faster a new token will appear on that empty cell. Existing +tokens can generate new tokens. Thus the middle cell in Image 1 denoted with X will +be regenerated at a faster rate than the middle cell in Image 2. When all +neighboring cells are empty, there is no renewal. + +<table width="100%"> +<tr> +<td align="center"><b>Image 1</b></td> +<td align="center"><b>Image 2</b></td> +</tr> +<tr> +<td align="center"> +<img src="http://localhost:8080/foraging/images/8neighbors.jpg" alt="image 1"> +</td> +<td align="center"> +<img src="http://localhost:8080/foraging/images/5neighbors.jpg" alt="image 2"> +</td> +</tr> +</table> +<hr> +<h3>Practice Round Instructions</h3> +<hr> +<p> +You will now have four minutes to practice with the experimental environment. +The decisions you make in this round will NOT influence your earnings. At the +At the beginning of the practice round half of the cells are occupied +with green tokens. The environment is a 13 x 13 grid of cells. +</p> +<p> +When you push the <b>R</b> key you will reset the distribution of +the tokens to randomly occupying half of the cells with green tokens. +</p> + +<p><center><b>Please do not communicate with any other participant.</b></center></p> +<p>If you have any questions please raise your hand. <b>Do you have any +questions so far?</b></p> +]]> +</entry> + +<entry key="quiz-instructions"> +<![CDATA[ +<p> +Before we begin the practice round you need to answer the following questions +correctly. You can only continue when you have answered all questions +correctly. If an error is made you will need to answer the questions again. +</p> +<br> +<form> +Which of the statements is incorrect? <br> +<input type="radio" name="q1" value="A">Your decisions of where to collect tokens affects the regeneration of tokens.<br> +<input type="radio" name="q1" value="B">When you have collected all tokens on +the screen, no new tokens will appear.<br> +<input type="radio" name="q1" value="C">Tokens grow from the middle of the +screen.<br> +<input type="radio" name="q1" value="D">In order to collect a token you need +to press the space bar while your avatar is on a cell with a token.<br> +<br><br> + +Which sequence of situations is not possible? <br> +<img src="http://localhost:8080/foraging/images/question2.jpg"><br> +<input type="radio" name="q2" value="A">A<br> +<input type="radio" name="q2" value="B">B<br> +<input type="radio" name="q2" value="C">C<br> +<br> +<input type="submit" name="submit" value="Submit"> +</form> +]]> +</entry> +<entry key="welcome-instructions"> +<![CDATA[ +<h3>Welcome</h3> +<p> +Welcome. You have already earned 5 dollars for showing up at this experiment. +You can earn more, up to a maximum of 40 dollars, by participating in this +experiment, which will take about an hour. The amount of money you earn +depends on your decisions as well as the decisions of your group members +during the four rounds of the experiment. Please be patient while the rest of the +participants are seated, the experiment will begin shortly. +</p> +]]> +</entry> + +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round1.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="display-group-tokens">true</entry> +<entry key="clients-per-group">5</entry> +<entry key="duration">240</entry> +<entry key="resource-depth">29</entry> +<entry key="resource-width">29</entry> + +<entry key='resource-generator'>mobile</entry> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='subjects-field-of-vision'>true</entry> + +<entry key='always-explicit'>true</entry> +<entry key='max-cell-occupancy'>1</entry> + +<entry key="initial-distribution">.25</entry> +<entry key="regrowth-rate">0.01</entry> + + +<entry key="instructions"> +<![CDATA[ +<h3>Round 1 Instructions</h3> +<hr> +<p> +This is the first round of the experiment. The length of the round is 4 +minutes. Like in the practice round you can collect green tokens. This time +you earn <b>two cents</b> for each token collected. This time you +<b>cannot</b> reset the distribution of green tokens. +</p> +<p> +In this round the renewable resource will become five times bigger. You +will share this larger environment with four other players in this room. +Each of you has been randomly assigned to one of several equal-sized +groups. Each of the groups is collecting tokens from an identical, but +separate resource. +</p> +<p> +Each of you has been assigned a number from 1 to 5. The other four players +will appear on the screen as blue dots +<img src="http://localhost:8080/foraging/images/gem-other.gif"> with a white +number embedded in the dot. On the top right corner of the screen you can see +how many tokens each player has collected. +</p> +<p> +If you have any questions please raise your hand. <b>Do you have any +questions so far?</b> +</p> +]]> +</entry> +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round2.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="display-group-tokens">true</entry> +<entry key="clients-per-group">5</entry> +<entry key="duration">240</entry> +<entry key="resource-depth">29</entry> +<entry key="resource-width">29</entry> + +<entry key='resource-generator'>mobile</entry> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='subjects-field-of-vision'>true</entry> + +<entry key='always-explicit'>true</entry> +<entry key='max-cell-occupancy'>1</entry> + +<entry key="initial-distribution">.25</entry> +<entry key="regrowth-rate">0.01</entry> + +<entry key="instructions"> +<![CDATA[ +<h3>Round 2 Instructions</h3> +<hr> +<p> +Round 2 is the same as round 1. +</p> +<p> +If you have any questions please raise your hand. <b>Do you have any +questions so far?</b> +</p> +]]> +</entry> +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round3.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="display-group-tokens">true</entry> +<entry key="clients-per-group">5</entry> +<entry key="duration">240</entry> +<entry key="resource-depth">29</entry> +<entry key="resource-width">29</entry> + +<entry key='resource-generator'>mobile</entry> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='subjects-field-of-vision'>true</entry> + +<entry key='always-explicit'>true</entry> +<entry key='max-cell-occupancy'>1</entry> + +<!-- resource regrowth parameters --> +<entry key="initial-distribution">.25</entry> +<entry key="regrowth-rate">0.01</entry> + +<!-- +<entry key="patchy">true</entry> +<entry key="top-initial-distribution">0.50</entry> +<entry key="top-rate">0.02</entry> +<entry key="bottom-initial-distribution">0.25</entry> +<entry key="bottom-rate">0.01</entry> +--> + +<entry key="instructions"> +<![CDATA[ +<h3>Round 3 Instructions</h3> +<hr> +<p> +Round 3 is the same as round 2. +</p> +<p> +If you have any questions please raise your hand. <b>Do you have any +questions so far?</b> +</p> +]]> +</entry> +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,178 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="display-group-tokens">true</entry> +<entry key="clients-per-group">5</entry> +<entry key="resource-depth">29</entry> +<entry key="resource-width">29</entry> +<entry key="duration">240</entry> + +<entry key='resource-generator'>mobile</entry> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='subjects-field-of-vision'>true</entry> + +<entry key='always-explicit'>true</entry> +<entry key='max-cell-occupancy'>1</entry> + +<!-- before this round begins, we have a chat session --> +<entry key="chat-enabled">true</entry> +<entry key="chat-duration">240</entry> + +<!-- enable sanctioning --> +<entry key="sanction-type">real-time</entry> +<entry key="sanction-cost">1</entry> +<entry key="sanction-multiplier">2</entry> + + +<entry key="initial-distribution">.25</entry> +<entry key="regrowth-rate">0.01</entry> + +<!-- enable quiz --> +<entry key='quiz'>true</entry> +<entry key='q1'>1</entry> +<entry key='q2'>2</entry> +<entry key='q3'>1</entry> +<entry key='q4'>1</entry> + +<entry key="instructions"> +<![CDATA[ +<h3>Round 4 Instructions</h3> +<hr> +<p> +Round 4 is the same as the previous two rounds with two exceptions. +</p> +<p> +Before the next round starts you can anonymously communicate by text messages +for four minutes with the other participants in your group. You can use this +opportunity to discuss the experiment and coordinate your actions to improve +your earnings. You may not promise side-payments after the experiment is +completed or make any threats. You are also not allowed to reveal your real +identity. We are monitoring the chat traffic while you chat. +</p> +<p> +During the next round you will have the option to reduce the earnings of another +participant at a cost to your own earnings with constraints depending on the type +of enforcement mechanism used. Below are the 4 types of enforcement mechanisms that +you have to vote later in the round. +</p> +<ul> +<li><b> Everyone can harvest but no sanctioning </b> +<p>In this type all players can harvest but no can sanction or reduce any other +player's tokens</p> +<li><b> Everyone can harvest as well as sanction </b> +<p>Each time you press the numeric keys between 1-5 the number of tokens of the +corresponding participant is reduced by <b>2</b> with a penalty of <b>1</b> to +yourself.</p> +<p>When you reduce the number of tokens of another participant, they will +receive a message stating that you have reduced their tokens. Likewise, if +another participant reduces your number of tokens, you will also receive a +message. These messages will be displayed on the bottom of your screen.</p> + +<li><b> Randomly picked monitering </b> +<p>Randomly one of the participants is selected to be the monitoring agent +This participant can not harvest, but can force another participant to pay +<b>1</b> token to the monitoring participant by pressing the responding +numeric key</p> +<p>At the end of the round each participant who could harvest pays 25% of +the earning to the monitoring participant.</p> + +<li><b> Round Robin monitering </b> +<p>One participant is assigned the role of the moniter for a period of 48 secs +and others can only harvest. So same rules apply as for the mechanism two. </p> +<p> This continues with each participant getting the chance to be a moniter for +48 secs </p> +</ul> +]]> +</entry> + +<entry key="regulation-instructions"> +<![CDATA[ +<h3>Regulation Instructions</h3> +<hr> +<p> +Below you can provide your regulation that you want to be conducted during the +next round. Please type in your regulation in the text box provided below. +</p> +<p> +Once you propose your regulation and submit it, you will be able to see all the +regulations proposed by the other participants and vote them. +</p> +<ul> +<li>Proposing the regulation is mandatory. +<li>You have 60 seconds to propose your regulation. +<li>You can write your regulation and submit it before time. +<li>Your regulation will be submitted automatically once the time ends. +</ul> +]]> +</entry> + +<entry key="chat-instructions"> +<![CDATA[ +<p> +You can now chat with the other participants in your group for 4 minutes +total. During the chat round, you may communicate about any aspect of the +experiment that you would like to discuss with other participants with whom +you have been matched. You may not promise them side-payments after the +experiment is completed or threaten them with any consequence after the +experiment is finished. We are monitoring the chat traffic while you chat. If +we see that somebody reveals his or her identity, we have to stop the +experiment and remove the whole group from which this person is a member out +of this room. +</p> +<p> +You will see other participants labeled as "1", "2","3", "4", or "5" in the +chat box. You can send a chat message by typing into the textfield at the +bottom of the screen and clicking the "send" button with your mouse or +pressing the "enter" key on your keyboard. +</p> +]]> +</entry> +<entry key="quiz-instructions"> +<![CDATA[ +<p>Before the next round begins you must complete the quiz below. You can +only continue when you have answered all questions correctly. If an error is +made you will need to answer the questions again. +</p> + +<form> +Each time I press the numeric keys between 1-5 my tokens will be reduced +by:<br> +<input type="radio" name="q1" value="0">0 tokens<br> +<input type="radio" name="q1" value="1">1 token<br> +<input type="radio" name="q1" value="2">2 tokens<br> +<input type="radio" name="q1" value="4">4 tokens<br> +<br><br> + +Each time I press the numeric keys between 1-5 the number of tokens of the +corresponding participant is reduced by:<br> +<input type="radio" name="q2" value="0">0 tokens<br> +<input type="radio" name="q2" value="1">1 token<br> +<input type="radio" name="q2" value="2">2 tokens<br> +<input type="radio" name="q2" value="4">4 tokens<br> +<br><br> + +The background of your avatar turns blue. What does this represent?<br> +<input type="radio" name="q3" value="0">You collected a token<br> +<input type="radio" name="q3" value="1">Another participant is subtracting two +tokens from you<br> +<input type="radio" name="q3" value="2">You are subtracting two tokens from another +participant<br> +<input type="radio" name="q3" value="3">You are moving too fast<br> +<br><br> + +Every time I press the numeric keys between 1-5:<br> +<input type="radio" name="q4" value="0">Two tokens are subtracted from my tokens +collected this round<br> +<input type="radio" name="q4" value="1">One token is subtracted from my tokens +collected this round<br> +<input type="radio" name="q4" value="2">The background of my avatar turns blue +momentarily<br> +<input type="radio" name="q4" value="3">My avatar is paused for two seconds<br> + +<input type="submit" name="submit" value="Submit"> +</form> +]]> +</entry> + +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="display-group-tokens">true</entry> +<entry key="clients-per-group">5</entry> +<entry key="resource-depth">29</entry> +<entry key="resource-width">29</entry> +<entry key="duration">240</entry> + +<!-- enable mobile offspring-generating resource --> +<entry key='resource-generator'>mobile</entry> +<!-- enable field of vision for tokens and subjects --> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='subjects-field-of-vision'>true</entry> + +<!-- enable sanctioning --> +<entry key="sanction-type">real-time</entry> +<entry key="sanction-cost">1</entry> +<entry key="sanction-multiplier">2</entry> + +<entry key="initial-distribution">.25</entry> +<entry key="regrowth-rate">0.01</entry> + +<entry key='always-explicit'>true</entry> +<entry key='max-cell-occupancy'>1</entry> + +<!-- before this round begins, we have a chat session --> +<entry key="chat-enabled">true</entry> +<entry key="chat-duration">240</entry> + +<entry key="instructions"> +<![CDATA[ +<h3>Round 5 Instructions</h3> +<hr> +<p> +Round 5 is the same as round 4.</p> +<p> +The length of this round is again four minutes. +</p> +<p> +If you have any questions please raise your hand. <b>Do you have any +questions so far?</b> +</p> +]]> +</entry> + +<entry key="regulation-instructions"> +<![CDATA[ +<h3>Regulation Instructions</h3> +<hr> +<p> +Same instructions apply to the regulations as in the previos round. +</p> +]]> +</entry> + +<entry key="chat-instructions"> +<![CDATA[ +<p> +You can now chat with the other participants in your group for 4 minutes +total. During the chat round, you may communicate about any aspect of the +experiment that you would like to discuss with other participants with whom +you have been matched. You may not promise them side-payments after the +experiment is completed or threaten them with any consequence after the +experiment is finished. We are monitoring the chat traffic while you chat. If +we see that somebody reveals his or her identity, we have to stop the +experiment and remove the whole group from which this person is a member out +of this room. +</p> +<p> +You will see other participants labeled as "1", "2","3", "4", or "5" in the +chat box. You can send a chat message by typing into the textfield at the +bottom of the screen and clicking the "send" button with your mouse or +pressing the "enter" key on your keyboard. +</p> +]]> +</entry> + +<entry key='private-chat-instructions'> +<![CDATA[ +You may send private messages to a specific participant by clicking on the +appropriately labeled button (1, 2, 3, 4, or 5) before typing your message in +the chat box and sending it. By default you are communicating with all +members of your group. +]]> +</entry> + +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="display-group-tokens">true</entry> +<entry key="clients-per-group">5</entry> +<entry key="resource-depth">29</entry> +<entry key="resource-width">29</entry> +<entry key="duration">240</entry> + +<!-- enable mobile offspring-generating resource --> +<entry key='resource-generator'>mobile</entry> +<!-- enable field of vision for tokens and subjects --> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='subjects-field-of-vision'>true</entry> + +<!-- enable sanctioning --> +<entry key="sanction-type">real-time</entry> +<entry key="sanction-cost">1</entry> +<entry key="sanction-multiplier">2</entry> + +<entry key="initial-distribution">.25</entry> +<entry key="regrowth-rate">0.01</entry> + +<entry key='always-explicit'>true</entry> +<entry key='max-cell-occupancy'>1</entry> + +<!-- before this round begins, we have a chat session --> +<entry key="chat-enabled">true</entry> +<entry key="chat-duration">240</entry> + +<entry key="instructions"> +<![CDATA[ +<h3>Round 5 Instructions</h3> +<hr> +<p> +Round 5 is the same as round 4.</p> +<p> +The length of this round is again four minutes. +</p> +<p> +If you have any questions please raise your hand. <b>Do you have any +questions so far?</b> +</p> +]]> +</entry> + +<entry key="regulation-instructions"> +<![CDATA[ +<h3>Regulation Instructions</h3> +<hr> +<p> +Same instructions apply to the regulations as in the previos round. +</p> +]]> +</entry> + +<entry key="chat-instructions"> +<![CDATA[ +<p> +You can now chat with the other participants in your group for 4 minutes +total. During the chat round, you may communicate about any aspect of the +experiment that you would like to discuss with other participants with whom +you have been matched. You may not promise them side-payments after the +experiment is completed or threaten them with any consequence after the +experiment is finished. We are monitoring the chat traffic while you chat. If +we see that somebody reveals his or her identity, we have to stop the +experiment and remove the whole group from which this person is a member out +of this room. +</p> +<p> +You will see other participants labeled as "1", "2","3", "4", or "5" in the +chat box. You can send a chat message by typing into the textfield at the +bottom of the screen and clicking the "send" button with your mouse or +pressing the "enter" key on your keyboard. +</p> +]]> +</entry> + +<entry key='private-chat-instructions'> +<![CDATA[ +You may send private messages to a specific participant by clicking on the +appropriately labeled button (1, 2, 3, 4, or 5) before typing your message in +the chat box and sending it. By default you are communicating with all +members of your group. +]]> +</entry> + +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Foraging XML-ized experiment round configuration</comment> +<entry key="display-group-tokens">true</entry> +<entry key="clients-per-group">5</entry> +<entry key="resource-depth">29</entry> +<entry key="resource-width">29</entry> +<entry key="duration">240</entry> + +<entry key='resource-generator'>mobile</entry> +<entry key='tokens-field-of-vision'>true</entry> +<entry key='subjects-field-of-vision'>true</entry> +<!-- enable sanctioning --> +<entry key="sanction-type">real-time</entry> +<entry key="sanction-cost">1</entry> +<entry key="sanction-multiplier">2</entry> + +<entry key="initial-distribution">.25</entry> +<entry key="regrowth-rate">0.01</entry> + +<entry key='always-explicit'>true</entry> +<entry key='max-cell-occupancy'>1</entry> + +<!-- before this round begins, we have a chat session --> +<entry key="chat-enabled">true</entry> +<entry key="chat-duration">240</entry> + +<entry key="instructions"> +<![CDATA[ +<h3>Round 6 Instructions</h3> +<hr> +<p> +Round 6 is the same as round 5.</p> +<p> +The length of this round is again four minutes. +</p> +<p> +If you have any questions please raise your hand. <b>Do you have any +questions so far?</b> +</p> +]]> +</entry> + +<entry key="regulation-instructions"> +<![CDATA[ +<h3>Regulation Instructions</h3> +<hr> +<p> +Same instructions apply to the regulations as in the previos round. +</p> +]]> +</entry> + +<entry key="last-round-debriefing"> +<![CDATA[ +<p> +This was the last round, but not the end of the experiment. We will now +determine your payments. While we are doing this, we request that you +carefully fill out a brief survey. +</p> +<p> +When we are ready we will call you one by one to the room next door. We will +pay you there in private. Please wait until your computer number is called, +and then proceed to the room next door to turn in your computer number and +your survey. +</p> +<p> +Please answer the survey carefully and thank you for participating. +</p> +]]> +</entry> + +<entry key="chat-instructions"> +<![CDATA[ +<p> +You can now chat with the other participants in your group for 4 minutes +total. During the chat round, you may communicate about any aspect of the +experiment that you would like to discuss with other participants with whom +you have been matched. You may not promise them side-payments after the +experiment is completed or threaten them with any consequence after the +experiment is finished. We are monitoring the chat traffic while you chat. If +we detect that somebody has revealed their identity, we will have to stop the +experiment and remove that person's entire group from the experiment. +</p> +<p> +You will see other participants labeled as "1", "2","3", "4", or "5" in the +chat box. You can send a chat message by typing into the textfield at the +bottom of the screen and clicking the "send" button with your mouse or +pressing the "enter" key on your keyboard. </p> +]]> +</entry> +</properties> Added: foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/server.xml =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/server.xml (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/server.xml 2009-12-01 22:28:49 UTC (rev 387) @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> +<properties> +<comment>Costly Sanctioning XML-ized experiment round configuration</comment> +<entry key="hostname">localhost</entry> +<entry key="port">16001</entry> +<entry key="round0">round0.xml</entry> +<entry key="round1">round1.xml</entry> +<entry key="round2">round2.xml</entry> +<entry key="round3">round3.xml</entry> +<entry key="round4">round4.xml</entry> +<entry key="round5">round5.xml</entry> +<entry key="round6">round6.xml</entry> +<entry key="wait-for-participants">true</entry> +<entry key="number-of-rounds">7</entry> +<entry key="facilitator-instructions"> +<![CDATA[ +<h3>Facilitator Instructions</h3> +<p> +Welcome to the facilitator interface. This interface allows you to control +the experiment. You may only modify configuration parameters <b>before</b> +you start the experiment by selecting the Configuration menu. When all the +participants are ready to begin the experiment, you can start the experiment +by selecting Experiment -> Start. After a round has been completed you +will be able to view the statistics for all of the participants. You can +begin the next round by selecting Round -> Start. +</p> +]]> +</entry> +</properties> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-01 21:52:11
|
Revision: 386 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=386&view=rev Author: alllee Date: 2009-12-01 21:51:57 +0000 (Tue, 01 Dec 2009) Log Message: ----------- deepak's changes to implement voting + regulation functionality to the foraging game Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow3D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/util/ForagingSaveFileConverter.java Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/EnforcementRequest.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationEvent.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/RegulationRequest.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/EnforcementData.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-01 21:40:53 UTC (rev 385) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-01 21:51:57 UTC (rev 386) @@ -39,7 +39,14 @@ // FIXME: can obtain tokensConsumed from the clientDataMap now. private int currentTokens; + + private int role; + private static final int MONITER = 0; + private static final int HARVEST = 1; + private static final int SANCTION = 2; + private static final int HARVESTANDSANCTION = 3; + // these are the subjects whom we have sanctioned private Map<Identifier, Duration> sanctioned = new HashMap<Identifier, Duration>(); @@ -53,6 +60,7 @@ public ClientDataModel(ForagingClient client) { super(client.getEventChannel()); this.client = client; + this.role = HARVEST; } public void toggleExplicitCollectionMode() { @@ -60,7 +68,38 @@ client.transmit(new ExplicitCollectionModeRequest(client.getId(), explicitCollectionMode)); } + + public void setMyRole(int role){ + this.role = role; + } + + public int getMyRole() { + return this.role; + } + + public boolean isSanctioningAllowed(){ + System.out.println("My Role : "+getMyRole()); + /* + boolean result = false; + switch(getMyRole()) { + case MONITER: + case SANCTION: + case HARVESTANDSANCTION: + result = true; + break; + } + return result;*/ + + if(getMyRole() == MONITER || getMyRole() == SANCTION || getMyRole() == HARVESTANDSANCTION)return true; + else return false; + } + + public boolean isHarvestingAllowed(){ + if(getMyRole() == HARVEST || getMyRole() == HARVESTANDSANCTION)return true; + else return false; + } + /* * public Map<Identifier, Duration> getSanctioned() { return sanctioned; } */ Added: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-01 21:51:57 UTC (rev 386) @@ -0,0 +1,575 @@ +package edu.asu.commons.foraging.client; + + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTextPane; +import javax.swing.Timer; +import javax.swing.UIManager; +import javax.swing.text.BadLocationException; +import javax.swing.text.Style; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyleContext; +import javax.swing.text.StyledDocument; +import javax.swing.text.html.HTMLEditorKit; + +import edu.asu.commons.event.EventTypeProcessor; +import edu.asu.commons.foraging.event.EnforcementEvent; +import edu.asu.commons.foraging.event.EnforcementRequest; +import edu.asu.commons.foraging.model.EnforcementData; +import edu.asu.commons.net.Identifier; +import edu.asu.commons.util.Utils; + + + + +/** + * $Id: EnforcementPanel.java 45 2008-08-21 00:47:39Z dbarge $ + * + * Enforcement panel is used to vote + * enforcement mechanism + * + * @author dbarge + * @version $Revision: 45 $ + */ + +@SuppressWarnings("serial") +public class EnforcementPanel extends JPanel { + + private ForagingClient client; + + private Map<Identifier, EnforcementData> enforcements; + + public EnforcementPanel (ForagingClient client) { + this.noOfEnforcements = 4; + this.client = client; + this.clientId = client.getId(); + client.getEventChannel().add(this, new EventTypeProcessor<EnforcementEvent>(EnforcementEvent.class) { + public void handle(final EnforcementEvent enforcementEvent) { + enforcements = enforcementEvent.getAllEnforcements(); + System.out.println("Enforcement received : "+enforcements.size()); + noOfEnforcements = enforcements.size(); + for (Identifier targetId : enforcements.keySet()) { + votedEnforcement = enforcements.get(targetId); + } + Utils.notify(GameWindow2D.enforcementVotesSignal); + } + }); + } + + private Identifier targetIdentifier = Identifier.ALL; + + private final static String HANDLE_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + public static int currentActive; + + public static int currentLabel; + + private static String[] HANDLES; + private String[] votes = { "1", "2", "3","4"}; + private String[] enforcementOptions = { + "No Enforcement - Click here for more info ", + "Everyone sanctions - Click here for more info ", + "Randomly picked monitering - Click here for more info", + "Random sanctioning - Click here for more info " + }; + + private String[] enforcementText = { + "Everybody can harvest. Nobody can subtract tokens<br>" + + "from others<br>", + "Each participant can reduce the token amount of<br>" + + "another participant by two tokens at a cost of <br>" + + "one by pressing the numeric key that identifies<br>" + + "the other participant.<br>", + "Randomly one of the participants is selected to<br>" + + "be the monitoring participant. This participant<br>" + + "can not harvest, but can force another particip<br>" + + "ant to pay a token to the monitoring participan<br>" + + "by pressing the responding numeric key. At the <br>" + + "end of the round each participant who could har<br>" + + "vest pays 25% of the earning to the monitoring <br>" + + "participant.<br>", + "Same as two, but now each participant takes turns<br>" + + "of 48 seconds randomly assigned by the computer.<br>" + }; + + + private Identifier clientId; + private JPanel votingPanel; + private JPanel informationPanel; + private JLabel label; + private JButton reset; + private JButton sendMyVotes; + private JPanel instructionsPanel; + private Timer timer; + private SixChoicePanel newPanel[]; + + private int noOfEnforcements; + + private String message; + + private int currentRankingInformation[]; + + private JScrollPane messageScrollPane; + + private JPanel buttonPanel; + + private EnforcementData votedEnforcement; + + private JScrollPane enforcementInstructionsScrollPane; + + private JTextPane messageWindow; + + private List<Identifier> participants; + + private JEditorPane enforcementInstructionsPane; + + + private void addStylesToMessageWindow() { + StyledDocument styledDocument = messageWindow.getStyledDocument(); + // and why not have something like... StyleContext.getDefaultStyle() to + // replace this junk + Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( + StyleContext.DEFAULT_STYLE); + // Style regularStyle = styledDocument.addStyle("regular", + // defaultStyle); + StyleConstants.setFontFamily(defaultStyle, "Helvetica"); + StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), + true); + StyleConstants.setItalic(styledDocument + .addStyle("italic", defaultStyle), true); + } + + public EnforcementData getVotedEnforcement(){ + return this.votedEnforcement; + } + + public String getVotedEnforcementOptions(int index){ + return this.enforcementText[index]; + } + + private void updateInstructionPanel(){ + enforcementInstructionsPane.setText(enforcementText[currentLabel]); + invalidate(); + validate(); + instructionsPanel.repaint(); + repaint(); + //pack(); + // setVisible(true); + } + + private void updateVotingPanel(){ + int r,c,i,j; + int currentRanking; + SixChoicePanel temp = null; + boolean enableSendButton = true; + + // System.out.println("No of enfrments: "+noOfEnforcements); + // System.out.println("Current active :"+currentActive); + + for(r = 0; r < noOfEnforcements; r++) + { + // System.out.print(newPanel[r].currentRanking+" "); + + if(newPanel[r].currentRanking == -1)enableSendButton = false; + + if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) + { + newPanel[r].currentRanking = -1; + newPanel[r].group.clearSelection(); + } + } + + + for(r = 0; r < noOfEnforcements-1; r++) + { + for(c = 0; c < noOfEnforcements-1; c++) + { + if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + } + } + for(c = 0; c < noOfEnforcements; c++) + { + // System.out.print(newPanel[c].getCurrentRanking() +" "); + } + + // votingPanel.setVisible(false); + // remove(votingPanel); + + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + + + for(i=0; i < noOfEnforcements; i++) { + votingPanel.add(newPanel[i].enforcementPanel); + votingPanel.add(newPanel[i].rankPanel); + } + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); + + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + + invalidate(); + validate(); + votingPanel.repaint(); + buttonPanel.repaint(); + repaint(); + } + + public void stopTimer(){ + timer.stop(); + } + + public void startTimer(){ + if (timer == null) { + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + //timer.stop(); + //timer = null; + // System.out.println("Timer called to update the voting panel:"); + updateVotingPanel(); + updateInstructionPanel(); + } + }); + timer.start(); + } + } + + private Color getColor(int i) + { + Color color = null; + if(i==0) color=Color.green; + if(i==1) color=Color.lightGray; + if(i==2) color=Color.blue; + if(i==3) color=Color.red; + if(i==4) color=Color.cyan; + return color; + } + + private String getVoteString(){ + + StringBuilder sb = new StringBuilder(); + + for(int c = 0; c < noOfEnforcements; c++) + { + sb.append("\nEnforcement "+(newPanel[c].getCurrentRanking()+1)); + } + return(sb.toString()); + } + + public void sendEnforcementVotes() { + + System.out.println("Enforcement Votes ready to be sent"); + // System.err.println("message: " + message); + int i; + for(i=0; i < noOfEnforcements; i++) { + if(newPanel[i].currentRanking == -1) + this.currentRankingInformation[i] = -1; + else + this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); + } + + /* + for(i=0 ; i<5 ; i++) + { + System.out.println(currentRankingInformation[i]); + } + */ + + EnforcementData enforcementData = new EnforcementData(); + enforcementData.setCurrentRankingInformation(this.currentRankingInformation); + //enforcementData.setenforcementText(message); + + // System.out.println("ID:"+client.getEnforcementID()); + //enforcementData.setEnforcementID(client.getEnforcementID()); + enforcementData.setEnforcementID(client.getToken()); + + client.transmit(new EnforcementRequest(clientId, message, enforcementData)); + // displayMessage(getEnforcementHandle(clientId) + " -> " + // + getEnforcementHandle(targetIdentifier), message); + + + } + + public void resetHandles() { + HANDLES = null; + } + + private String getEnforcementHandle(Identifier source) { + if (source.equals(Identifier.ALL)) { + return "all"; + } + else { + String enforcementHandle = HANDLES[participants.indexOf(source)]; + if (source.equals(clientId)) { + return enforcementHandle.concat(" (you)"); + } + return enforcementHandle; + } + } + public void initGuiComponents(){ + + // remove(enforcementInstructionsScrollPane); + // remove(messageScrollPane); + this.currentRankingInformation = new int[4]; + this.timer=null; + this.newPanel = new SixChoicePanel[4]; + new WindowUtilities().setNativeLookAndFeel(); + setBackground(Color.lightGray); + setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + + informationPanel = new JPanel(); + informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); + informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); + label = new JLabel("You have 30 seconds left to vote the enforcements"); + + informationPanel.add(label); + + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Information")); + + + // EnforcementData enforcementData; + // System.out.println("No of enfrments: "+noOfEnforcements); + + for(int i=0; i<noOfEnforcements; i++) { + //System.out.println("Added : "+(i+1)); + StringBuilder sb = new StringBuilder(); + sb.append(enforcementOptions[i]); + String s = sb.toString(); + + //newPanel[i] = new SixChoicePanel(s, votes, enforcementData.getEnforcementID(), getColor(i)); + //newPanel[i] = new SixChoicePanel(s, votes, client.getEnforcementID(), getColor(i)); + newPanel[i] = new SixChoicePanel(s, votes, i, getColor(i)); + votingPanel.add(newPanel[i].getEnforcementPanel(i)); + votingPanel.add(newPanel[i].getRankPanel(i)); + } + + add(votingPanel, BorderLayout.CENTER); + reset = new JButton("Reset All Ranks"); + reset.setAlignmentX(Component.CENTER_ALIGNMENT); + reset.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + for(int i=0; i<noOfEnforcements; i++) { + for(int j=0; j<noOfEnforcements; j++) { + newPanel[i].option[j].setEnabled(true); + newPanel[i].group.clearSelection(); + newPanel[i].currentRanking = -1; + } + } + } + }); + sendMyVotes = new JButton("Send votes"); + sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); + sendMyVotes.setEnabled(false); + sendMyVotes.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + + int n = JOptionPane.showConfirmDialog( + null, "Are you sure to submit your votes ?"+ + "\nBelow is order of your voting" + + getVoteString(), + "Confirm and send votes", + JOptionPane.YES_NO_OPTION); + + if (n == JOptionPane.YES_OPTION) { + GameWindow2D.duration.expire(); + } + if (n == JOptionPane.NO_OPTION) { + + } + + } + }); + buttonPanel = new JPanel(); + //buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + buttonPanel.setLayout(new GridLayout(1,2)); + buttonPanel.add(reset); + buttonPanel.add(sendMyVotes); + buttonPanel.setVisible(true); + buttonPanel.repaint(); + add(buttonPanel, BorderLayout.SOUTH); + + instructionsPanel = new JPanel(); + instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); + instructionsPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Instructions")); + + enforcementInstructionsPane = new JEditorPane(); + enforcementInstructionsPane.setContentType("text/html"); + enforcementInstructionsPane.setEditorKit(new HTMLEditorKit()); + enforcementInstructionsPane.setEditable(false); +// regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); + enforcementInstructionsScrollPane = new JScrollPane(enforcementInstructionsPane); + + //FIXME: Need to fetch the regulation instructions over here + //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getChatInstructions()); + enforcementInstructionsPane.setText("This is the place of enforcement detailed information"); + instructionsPanel.add(enforcementInstructionsScrollPane); + + // add(instructionsPanel, BorderLayout.CENTER); + add(instructionsPanel, BorderLayout.EAST); + } + + private void displayMessage(String sanctionHandle, String message) { + // String chatHandle = getChatHandle(source); + StyledDocument document = messageWindow.getStyledDocument(); + try { + document.insertString(document.getLength(), sanctionHandle + " : ", + document.getStyle("bold")); + document.insertString(document.getLength(), message + "\n", null); + messageWindow.setCaretPosition(document.getLength()); + } catch (BadLocationException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } + + public void initialize() { + + if (HANDLES != null) { + // displayMessage("System message", " --- Round ended --- "); + return; + } + this.participants = client.getDataModel().getAllClientIdentifiers(); + HANDLES = new String[participants.size()]; + List<String> handles = new ArrayList<String>(); + if (client.getDataModel().getRoundConfiguration().isChatAnonymized()) { + for (int i = HANDLES.length; --i >= 0;) { + handles.add(HANDLE_STRING.charAt(i) + ""); + } + Collections.shuffle(handles); + for (int i = 0; i < HANDLES.length; i++) { + HANDLES[i] = handles.get(i); + } + } + else { + for (int i = 0; i < HANDLES.length; i++) { + HANDLES[i] = client.getDataModel().getAssignedNumber(participants.get(i)) + ""; + } + } + initGuiComponents(); + } + private class SixChoicePanel implements ActionListener, MouseListener{ + String title; + String [] buttonLabels; + int enforcementID; + int currentRanking; + JPanel enforcementPanel; + JPanel rankPanel; + JLabel enforcementLabel; + ButtonGroup group; + JRadioButton option []; + Color color; + // static int currentActive; + + public SixChoicePanel(String title, String[] buttonLabels, int enforcementID, Color color ) { + this.title = title; + this.buttonLabels = buttonLabels; + this.enforcementID = enforcementID; + this.color = color; + this.currentRanking = -1; + this.option = new JRadioButton[4]; + } + public int getCurrentRanking(){ + return enforcementID; + } + + public void mouseClicked(MouseEvent arg0) { } + + public void mouseEntered(MouseEvent arg0) { } + + public void mouseExited(MouseEvent arg0) { } + + public void mousePressed(MouseEvent arg0) { + currentLabel = this.enforcementID; + // System.out.println("Label No:"+currentLabel); + } + + public void mouseReleased(MouseEvent arg0){ } + + public void actionPerformed(ActionEvent e) { + String choice = group.getSelection().getActionCommand(); + int buttonNo = Integer.parseInt(choice); + // System.out.println("ACTION Choice Selected: " + choice); + // System.out.println("Bno: " + buttonNo); + this.currentRanking = buttonNo; + EnforcementPanel.currentActive = this.enforcementID; + } + + public JPanel getRankPanel(int clientNo){ + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length + for(int i=0; i<length; i++) { + option[i] = new JRadioButton(buttonLabels[i]); + option[i].setActionCommand(buttonLabels[i]); + group.add(option[i]); + option[i].addActionListener(this); + rankPanel.add(option[i]); + } + + return rankPanel; + } + public JPanel getEnforcementPanel(int i){ + enforcementPanel = new JPanel(); + enforcementPanel.setBackground(color); + enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); + enforcementPanel.setBorder(BorderFactory.createTitledBorder("Enforcement "+(i+1))); + enforcementLabel = new JLabel(title); + enforcementLabel.addMouseListener(this); + enforcementPanel.add(enforcementLabel); + return enforcementPanel; + } + + } + private class WindowUtilities { + public void setNativeLookAndFeel() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch(Exception e) { + System.out.println("Error setting native LAF: " + e); + } + } + } + +} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-01 21:40:53 UTC (rev 385) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-01 21:51:57 UTC (rev 386) @@ -24,6 +24,7 @@ import edu.asu.commons.foraging.event.CollectTokenRequest; import edu.asu.commons.foraging.event.EndRoundEvent; import edu.asu.commons.foraging.event.LockResourceEvent; +import edu.asu.commons.foraging.event.NewClientRole; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; @@ -31,6 +32,8 @@ import edu.asu.commons.foraging.event.RoundStartedEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; +import edu.asu.commons.foraging.model.EnforcementData; +import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; import edu.asu.commons.util.Utils; @@ -64,6 +67,12 @@ private ClientDataModel dataModel; + private int regulationID; + + private int enforcementID; + + private int token; + private MessageQueue messageQueue; private JPanel panel = new JPanel(); @@ -108,7 +117,18 @@ return gameWindow3D; } } + public void setRegulationID(int ID){this.regulationID = ID;} + public int getRegulationID(){return this.regulationID;} + + public void setEnforcementID(int ID){this.enforcementID = ID;} + + public int getEnforcementID(){return this.enforcementID;} + + public void setToken(int token){this.token = token;} + + public int getToken(){return this.token;} + public void sendAvatarInfo(boolean male, Color hairColor, Color skinColor, Color shirtColor, Color trouserColor, Color shoesColor) { transmit(new AgentInfoRequest(getId(), male, hairColor, skinColor, shirtColor, trouserColor, shoesColor)); gameWindow3D.removeAgentDesigner(); @@ -163,11 +183,28 @@ state = ClientState.RUNNING; } }); + + addEventProcessor(new EventTypeProcessor<NewClientRole>(NewClientRole.class) { + public void handle(NewClientRole event) { + Identifier receivedClientId = event.getRoleObj().getClientId(); + System.out.println("Broadcast ID : "+receivedClientId); + if(dataModel.getId().equals(receivedClientId)) { + int roles [] = event.getRoleObj().getClientRoles(); + dataModel.setMyRole(roles[event.getRoleObj().getRoleNo()]); + System.out.println("New role for the client : "+dataModel.getMyRole()); + gameWindow2D.displayErrorMessage(GameWindow2D.roleDescription[getDataModel().getMyRole()],1); + + // Utils.notify(GameWindow2D.clientRoleSignal); + } + } + }); + addEventProcessor(new EventTypeProcessor<EndRoundEvent>(EndRoundEvent.class) { public void handle(final EndRoundEvent event) { if (state == ClientState.RUNNING) { dataModel.setGroupDataModel(event.getGroupDataModel()); getGameWindow().endRound(event); + getGameWindow().resetPanels(); if (dataModel.is2dExperiment()) { messageQueue.stop(); } @@ -221,17 +258,29 @@ addEventProcessor(new EventTypeProcessor<ClientMessageEvent>(ClientMessageEvent.class) { public void handle(ClientMessageEvent event) { - gameWindow2D.displayErrorMessage(event.toString()); + gameWindow2D.displayErrorMessage(event.toString(),0); } }); } - public boolean canPerformRealTimeSanction() { - return dataModel.getRoundConfiguration().isRealTimeSanctioningEnabled() && dataModel.getCurrentTokens() > 0; + public boolean canPerformRealTimeSanction(EnforcementData votedEnforcement) { + if(votedEnforcement.getResultIndex() == 2 || votedEnforcement.getResultIndex() == 3) + return dataModel.getRoundConfiguration().isRealTimeSanctioningEnabled() && dataModel.getCurrentTokens() >= 0; + else + return dataModel.getRoundConfiguration().isRealTimeSanctioningEnabled() && dataModel.getCurrentTokens() > 0; } + public boolean isSanctioningAllowed() { + return dataModel.isSanctioningAllowed(); + } + + public boolean isHarvestingAllowed(){ + return dataModel.isHarvestingAllowed(); + } + public void transmit(PostRoundSanctionRequest request) { if (state == ClientState.WAITING) { + System.out.println("Sending post round sanction request"); gameWindow2D.switchInstructionsPane(); super.transmit(request); } @@ -389,8 +438,10 @@ public static void main(String[] args) { Runnable createGuiRunnable = new Runnable() { public void run() { - Dimension defaultDimension = new Dimension(800, 600); - JFrame frame = new JFrame(); + //System.out.println("inside client"); + //Dimension defaultDimension = new Dimension(600, 600); + Dimension defaultDimension = new Dimension(600, 600); + JFrame frame = new JFrame(); ForagingClient client = new ForagingClient(new ServerConfiguration(), defaultDimension); client.connect(); frame.setTitle("Client Window: " + client.getId()); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow.java 2009-12-01 21:40:53 UTC (rev 385) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow.java 2009-12-01 21:51:57 UTC (rev 386) @@ -17,5 +17,6 @@ public void init(); public void update(long millisecondsLeft); public void showInstructions(); + public void resetPanels(); } Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 21:40:53 UTC (rev 385) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 21:51:57 UTC (rev 386) @@ -1,5 +1,6 @@ package edu.asu.commons.foraging.client; + import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; @@ -21,19 +22,23 @@ import java.util.Map; import java.util.Properties; +import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.SwingUtilities; import javax.swing.Timer; +import javax.swing.UIManager; import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; import javax.swing.text.StyledDocument; +import javax.swing.text.html.HTMLEditorKit; import edu.asu.commons.event.Event; import edu.asu.commons.event.EventChannel; @@ -47,9 +52,12 @@ import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.Direction; +import edu.asu.commons.foraging.model.EnforcementData; +import edu.asu.commons.foraging.model.RegulationData; import edu.asu.commons.net.Identifier; import edu.asu.commons.util.Duration; import edu.asu.commons.util.HtmlEditorPane; +import edu.asu.commons.util.Utils; @@ -71,38 +79,73 @@ private final ClientDataModel dataModel; // instructions components. - + private Component currentCenterComponent; - private JScrollPane instructionsScrollPane; + private JScrollPane instructionsScrollPane; - private HtmlEditorPane instructionsEditorPane; + private HtmlEditorPane instructionsEditorPane; private JPanel messagePanel; private JScrollPane errorMessageScrollPane; private JTextPane errorMessageTextPane; - + private JScrollPane regulationVotingIntructionsScrollPane; + private JPanel regulationVotingPane; + private JPanel labelPanel; + + public static Duration duration; + + private RegulationData votedRegulation; + + private EnforcementData votedEnforcement; + private ChatPanel chatPanel; + + public static String roleDescription [] = { + "Moniter: You cannot harvest but can sanction other participants\n" + + "To sanction press numbers from 1-5. At the end of the round you\n" + + "will receive 25% tokens from every other participant", + "Harvest: You can collect tokens as in earlier rounds. But you \n" + + "cannot sanction", + "Sanction: You cannot harvest but only sanction \n", + "Harvest and Sanction: You can collect tokens and at the same & \n" + + "at the same time sanction other participants"}; + + private SanctioningPanel sanctioningPanel; + + private EnforcementPanel enforcementPanel; private JLabel informationLabel; private JLabel timeLeftLabel; private JPanel subjectWindow; + + private JEditorPane regulationVotingIntructions; private ForagingClient client; private SubjectView subjectView; - private Timer timer; + public Timer timer; + + public static final Object regulationSignal = new Object(); + + public static final Object enforcementVotesSignal = new Object(); + + public static final Object regulationVotesSignal = new Object(); + + public static final Object clientRoleSignal = new Object(); private final StringBuilder instructionsBuilder = new StringBuilder(); private EventChannel channel; - + + private Map<Identifier, RegulationData> regulations; + private CardLayout cardLayout; - + // private EnergyLevel energyLevel; public GameWindow2D(ForagingClient client, Dimension size) { @@ -110,11 +153,12 @@ this.dataModel = client.getDataModel(); // FIXME: set the actual screen size dimensions after this JPanel has been initialized... this.channel = client.getEventChannel(); - // feed subject view the avaiable screen size so that + // feed subject view the available screen size so that // it can adjust appropriately when given a board size Dimension subjectViewSize = new Dimension((int) Math.floor(size.getWidth()), (int) Math.floor(size.getHeight() * 0.85)); subjectView = new SubjectView(subjectViewSize, dataModel); +// subjectView.addKeyListener(this); initGuiComponents(); } @@ -136,6 +180,8 @@ }); } + + /** * In certain cases, init() _can_ be called before endRound() is finished. Need to lock * access! @@ -199,17 +245,191 @@ public void collectToken(Point position) { subjectView.collectToken(position); } + + private void startEnforcementDisplayTimer(){ + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(15); + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + if (duration.hasExpired()) { + timeLeftLabel.setText("Round begins now."); + + //new code + //Need to add the enforcementVotingPane over here + //instead of the instructionsScrollPane + timer.stop(); + timer = null; + remove(enforcementPanel); + // System.out.println("Enforcement Panel removed : New Pane added"); + addCenterComponent(instructionsScrollPane); + + } + else { + timeLeftLabel.setText( String.format("Voting for the enforcement mechanism will start in %d seconds.", duration.getTimeLeft() / 1000L) ); + } + } + }); + timer.start(); + } + } + + private void startRegulationDisplayTimer(){ + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(15); + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + if (duration.hasExpired()) { + timeLeftLabel.setText("Enforcement Voting begins now."); + + //new code + //Need to add the enforcementVotingPane over here + //instead of the instructionsScrollPane + timer.stop(); + timer = null; + //remove(sanctioningPanel); + // System.out.println("New Pane added"); + initializeEnforcementVotingPanel(); + } + else { + timeLeftLabel.setText( String.format("Voting for the enforcement mechanism will start in %d seconds.", duration.getTimeLeft() / 1000L) ); + } + } + }); + timer.start(); + } + } + + private void startEnforcementVotingTimer() { + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(30); + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + if (duration.hasExpired()) { + timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); + + //new code + //Need to add the enforcementVotingPane over here + //instead of the instructionsScrollPane + timer.stop(); + timer = null; + //remove(sanctioningPanel); + getEnforcementPanel().stopTimer(); + getEnforcementPanel().sendEnforcementVotes(); + //displayEnforcementWaitMessage(); + + System.out.println("Enforcement voting sent"); + Utils.waitOn(enforcementVotesSignal); + + System.out.println("Voted enforcement received"); + + //Utils.waitOn(clientRoleSignal); + + // System.out.println("Client Role received"); + + votedEnforcement = getEnforcementPanel().getVotedEnforcement(); + + displayVotedEnforcement(); + + // System.out.println("New Pane added"); + } + else { + timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); + } + } + }); + timer.start(); + } + } + + + private void startRegulationVotingTimer() { + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(30); + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + if (duration.hasExpired()) { + timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); + + //new code + //Need to add the enforcementVotingPane over here + //instead of the instructionsScrollPane + timer.stop(); + timer = null; + //remove(sanctioningPanel); + getSanctioningPanel().stopTimer(); + getSanctioningPanel().sendRegulationVotes(); + System.out.println("Regulation voting sent"); + //displayRegulationWaitMessage(); + Utils.waitOn(regulationVotesSignal); + System.out.println("Voted regulation received"); + + votedRegulation = getSanctioningPanel().getVotedRegulation(); + displayVotedRegulation(); + + //System.out.println("New Pane added"); + } + else { + timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); + } + } + }); + timer.start(); + } + } + + private void startSanctioningTimer() { + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(30); + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + if (duration.hasExpired()) { + timeLeftLabel.setText("Your time to write the regualtion is finished. Next round begins shortly."); + //new code + //FIXME: + //Need to add the regulationVotingPane over here + //instead of the instructionsScrollPane + //Need to create new client request to send the sanction information + //client.transmit(); + //addCenterComponent(instructionsScrollPane); + //addCenterComponent(regulationVotingPane); + timer.stop(); + timer = null; + getSanctioningPanel().sendRegulation(); + Utils.waitOn(regulationSignal); + initializeRegulationVotingPanel(); + } + else { + timeLeftLabel.setText( String.format("You have %d seconds left to write your regualtion", duration.getTimeLeft() / 1000L) ); + } + } + }); + timer.start(); + } + } private void startChatTimer() { if (timer == null) { - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + // final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); + final Duration duration = Duration.create(30); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { - timeLeftLabel.setText("Chat is now disabled. The next round will begin shortly."); - addCenterComponent(instructionsScrollPane); + timeLeftLabel.setText("Chat is now disabled. Next round begins shortly."); + + //new code + //Need to add the regulationVotingPane over here + //instead of the instructionsScrollPane + //addCenterComponent(instructionsScrollPane); timer.stop(); timer = null; + + initializeSanctioningPanel(); + } else { timeLeftLabel.setText( String.format("Chat will end in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -269,7 +489,28 @@ htmlPane.setFont(new Font("sansserif", Font.PLAIN, 12)); return htmlPane; } + public static void setNativeLookAndFeel() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch(Exception e) { + // System.out.println("Error setting native LAF: " + e); + } + } + private SanctioningPanel updateRegulationVotingPanel(){ + // System.out.println("Inside update regulation"); + + SanctioningPanel sanctioningPanel = getSanctioningPanel(); + sanctioningPanel.initRegulationVotingCompontents(); + + regulations = getSanctioningPanel().getAllRegulations(); + // System.out.println("Fetched all the regulations from the server : "+regulations.size()); + // setNativeLookAndFeel(); + //regulationVotingPane.add(votingArea, BorderLayout.SOUTH); + //regulationVotingPane.add(regulationVotingIntructionsScrollPane,BorderLayout.NORTH); + return sanctioningPanel; + } + private void initGuiComponents() { // FIXME: replace with CardLayout for easier switching between panels // cardLayout = new CardLayout(); @@ -292,6 +533,19 @@ informationLabel.setBackground(Color.YELLOW); informationLabel.setForeground(Color.BLUE); +// getSanctioningPanel().initializeVotingPaneWithRegulations(); + + regulationVotingPane = new JPanel(); + //regulationVotingPane.setLayout(new BoxLayout(regulationVotingPane, BoxLayout.LINE_AXIS)); + regulationVotingPane.setLayout(new BorderLayout(4,4)); + + regulationVotingIntructions = new JEditorPane(); + regulationVotingIntructions.setContentType("text/html"); + regulationVotingIntructions.setEditorKit(new HTMLEditorKit()); + regulationVotingIntructions.setEditable(false); + regulationVotingIntructions.setBorder(BorderFactory.createTitledBorder("Regulation voting instructions")); + regulationVotingIntructionsScrollPane = new JScrollPane(regulationVotingIntructions); + labelPanel = new JPanel(); labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.LINE_AXIS)); labelPanel.setBackground(Color.WHITE); @@ -307,6 +561,8 @@ errorMessageTextPane = new JTextPane(); errorMessageTextPane.setEditable(false); errorMessageTextPane.setFont(new Font("arial", Font.BOLD, 12)); + + addStyles(errorMessageTextPane.getStyledDocument()); errorMessageScrollPane = new JScrollPane(errorMessageTextPane); Dimension scrollPaneSize = new Dimension(getPreferredSize().width, 50); @@ -363,13 +619,23 @@ switch (keyCode) { // token request handling case KeyEvent.VK_SPACE: - event = new CollectTokenRequest(client.getId()); + if(client.isHarvestingAllowed()) { + event = new CollectTokenRequest(client.getId()); + } + else + displayErrorMessage("You are either a Moniter or Sanctioner : You cannot harvest ", 1); + break; // real-time sanctioning keycode handling case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: - if (client.canPerformRealTimeSanction()) { + // System.out.println("Key pressed : "+(keyChar-48)); + if(dataModel.getRoundConfiguration().isChatEnabled() == false) { + return; + } + if (client.isSanctioningAllowed() && client.canPerformRealTimeSanction(getEnforcementPanel().getVotedEnforcement())) { + //System.out.println("Can do sanctioning"); int assignedNumber = keyChar - 48; Identifier sanctionee = dataModel.getClientId(assignedNumber); if (sanctionee == null || sanctionee.equals(dataModel.getId())) { @@ -379,11 +645,22 @@ // only allow sanctions for subjects within this subject's field of vision Point subjectPosition = dataModel.getClientDataMap().get(sanctionee).getPoint(); if (dataModel.getClientData().isSubjectInFieldOfVision(subjectPosition)) { + // System.out.println("sanctioning event sent"); event = new RealTimeSanctionRequest(dataModel.getId(), sanctionee); + // below function must be used for enforcement type4 dataModel.sanction(dataModel.getId(), sanctionee); - } + } + else{ + displayErrorMessage("Sanctionee is out of range ", 1); + } } - else return; + else + { + if(client.isSanctioningAllowed()==false){ + displayErrorMessage("You don't have the privilege to sanction",1); + } + return; + } break; // reset token distribution request handling case KeyEvent.VK_R: @@ -437,6 +714,7 @@ revalidate(); } currentCenterComponent = newCenterComponent; + // currentCenterComponent.repaint(); } public void startRound() { @@ -445,6 +723,7 @@ timer.stop(); timer = null; } + // currentExperimentConfiguration = configuration; Runnable runnable = new Runnable() { public void run() { @@ -455,7 +734,11 @@ // by the server no new clients can connect because the round // has begun. update(configuration.getRoundDuration().getTimeLeft()); + if(configuration.isChatEnabled()){ + displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); + } add(messagePanel, BorderLayout.SOUTH); + addCenterComponent(subjectWindow); requestFocusInWindow(); } @@ -463,10 +746,13 @@ SwingUtilities.invokeLater(runnable); } - public void displayErrorMessage(String errorMessage) { + public void displayErrorMessage(String errorMessage, int par) { // String chatHandle = getChatHandle(source); + if(par==1)errorMessageTextPane.setForeground(Color.RED); + else errorMessageTextPane.setForeground(Color.BLACK); + StyledDocument document = errorMessageTextPane.getStyledDocument(); - try { + try { document.insertString(document.getLength(), errorMessage + "\n", document.getStyle("bold")); errorMessageTextPane.setCaretPosition(document.getLength()); } @@ -491,6 +777,7 @@ .addStyle("italic", defaultStyle), true); } + private double getIncome(float numTokens) { if (dataModel.getRoundConfiguration().isPracticeRound()) { return 0.0f; @@ -550,11 +837,25 @@ private ChatPanel getChatPanel() { if (chatPanel == null) { + //System.out.println("Chat panel is null"); chatPanel = new ChatPanel(client); } return chatPanel; } - + private SanctioningPanel getSanctioningPanel() { + if (sanctioningPanel == null) { + //System.out.println("Sanc panel is null"); + sanctioningPanel = new SanctioningPanel(client); + } + return sanctioningPanel; + } + private EnforcementPanel getEnforcementPanel() { + if (enforcementPanel == null) { + //System.out.println("enf panel is null"); + enforcementPanel = new EnforcementPanel(client); + } + return enforcementPanel; + } public void showInstructions() { RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); instructionsBuilder.delete(0, instructionsBuilder.length()); @@ -576,6 +877,64 @@ addCenterComponent(instructionsScrollPane); } + public void displayVotedEnforcement(){ + //new code + // System.out.println("*****Inside display voting enforcement"); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + instructionsEditorPane.setText("Below enforcement has been voted from the voting conducting earlier<br><br>" + + "<b>"+getEnforcementPanel().getVotedEnforcementOptions(votedEnforcement.getResultIndex())+ + "</b><br><br>This is your role for the next round <br><br><b>"+roleDescription[client.getDataModel().getMyRole()]+"</b>"); + remove(enforcementPanel); + addCenterComponent(instructionsScrollPane); + startEnforcementDisplayTimer(); + } + }); + } + + public void displayRegulationWaitMessage(){ + //new code + // System.out.println("*****Inside reg wait mesg"); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + instructionsEditorPane.setText("Message from the System:<br><br>" + + "<b>Please wait until the System receives votes from all players.System<br>"+ + "will calculate the result of the voting and display it in a moment</b>"); + remove(sanctioningPanel); + addCenterComponent(instructionsScrollPane); + } + }); + } + + public void displayEnforcementWaitMessage(){ + //new code + System.out.println("*****Inside enfr wait message"); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + instructionsEditorPane.setText("Message from the System:<br><br>" + + "<b>Please wait until the System receives votes from all players.System<br>"+ + "will calculate the result of the voting and display it in a moment</b>"); + remove(enforcementPanel); + addCenterComponent(instructionsScrollPane); + } + }); + } + + + + public void displayVotedRegulation(){ + //new code + // System.out.println("*****Inside display voting regulation"); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getRegulationText()+".</b>"); + remove(sanctioningPanel); + addCenterComponent(instructionsScrollPane); + startRegulationDisplayTimer(); + } + }); + } + public void updateDebriefing(final PostRoundSanctionUpdateEvent event) { Runnable runnable = new Runnable() { public void run() { @@ -587,6 +946,19 @@ SwingUtilities.invokeLater(runnable); } + public void resetPanels() { + //System.out.println("Reseting the panels"); + if(sanctioningPanel != null) + sanctioningPanel.resetHandles(); + if(enforcementPanel != null) + enforcementPanel.resetHandles(); + + sanctioningPanel = null; + enforcementPanel = null; + // chatPanel = null; + } + + public void endRound(final EndRoundEvent event) { Runnable runnable = new Runnable() { public void run() { @@ -613,11 +985,65 @@ } } + public void initializeEnforcementVotingPanel() { + //new code + // System.out.println("*****Inside initialize enforcement()"); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + //new code + System.out.println("*****Inside thread initialize sanctioningPanel()"); + EnforcementPanel enforcementPanel = getEnforcementPanel(); + enforcementPanel.initialize(); + remove(instructionsScrollPane); + addCenterComponent(enforcementPanel); + enforcementPanel.startTimer(); + startEnforcementVotingTimer(); + } + }); + } + + public void initializeRegulationVotingPanel() { + //new code + // System.out.println("*****Inside initialize regulation vot... [truncated message content] |
From: <al...@us...> - 2009-12-01 21:40:59
|
Revision: 385 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=385&view=rev Author: alllee Date: 2009-12-01 21:40:53 +0000 (Tue, 01 Dec 2009) Log Message: ----------- creating new branch for deepak's work on the regulation and voting in the foraging game Added Paths: ----------- foraging/branches/deepak-branch-fall-09/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-01 21:23:45
|
Revision: 384 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=384&view=rev Author: alllee Date: 2009-12-01 21:23:20 +0000 (Tue, 01 Dec 2009) Log Message: ----------- fixing ivy settings for artifacts, minor refactoring + documentation hygiene for foraging server starting to implement field of vision in subject view, will finish on deepak's branch. Modified Paths: -------------- foraging/trunk/ivysettings.xml foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GridView.java foraging/trunk/src/main/java/edu/asu/commons/foraging/client/PostRoundSanctioningPanel.java foraging/trunk/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ReplayControlPanel.java foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/RoundConfigurationDialog.java foraging/trunk/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java Modified: foraging/trunk/ivysettings.xml =================================================================== --- foraging/trunk/ivysettings.xml 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/ivysettings.xml 2009-12-01 21:23:20 UTC (rev 384) @@ -4,15 +4,15 @@ --> <ivysettings> <settings defaultResolver="chain-resolver" /> - <property name='local-m2-pattern' - value='${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision]'/> + <property name='local-m2-pattern' value='${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision]'/> <resolvers> <chain name='chain-resolver' returnFirst='true'> <filesystem name='m2' m2compatible='true'> <ivy pattern='${local-m2-pattern}.pom' /> <artifact pattern='${local-m2-pattern}.[ext]'/> </filesystem> - <ibiblio name='commons-archiva' m2compatible='true' root='http://dev.commons.asu.edu/archiva/repository/internal'/> + <ibiblio name='commons.snapshots' m2compatible='true' root='http://dev.commons.asu.edu/archiva/repository/snapshots'/> + <ibiblio name='commons.internal' m2compatible='true' root='http://dev.commons.asu.edu/archiva/repository/internal'/> <ibiblio name='tdar-archiva' m2compatible='true' root='http://dev.tdar.org/archiva/repository/internal'/> </chain> </resolvers> Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/client/ChatPanel.java 2009-12-01 21:23:20 UTC (rev 384) @@ -196,6 +196,7 @@ private void initGuiComponents() { setLayout(new BorderLayout(4, 4)); + setName("Chat panel"); messageWindow = new JTextPane(); messageWindow.setEditable(false); messageScrollPane = new JScrollPane(messageWindow); Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 21:23:20 UTC (rev 384) @@ -1,6 +1,7 @@ package edu.asu.commons.foraging.client; import java.awt.BorderLayout; +import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -100,6 +101,8 @@ private EventChannel channel; + private CardLayout cardLayout; + // private EnergyLevel energyLevel; public GameWindow2D(ForagingClient client, Dimension size) { @@ -245,8 +248,7 @@ private String getTimeLeftLabelText(long roundTimeLeft) { long secondsLeft = roundTimeLeft / 1000L; - String secondsText = (secondsLeft > 1) ? " seconds" : " second"; - return "Time left: " + secondsLeft + secondsText; + return "Time left: " + secondsLeft + " second(s)"; } private void setInstructions(String s) { @@ -264,11 +266,14 @@ final HtmlEditorPane htmlPane = new HtmlEditorPane(); htmlPane.setPreferredSize(new Dimension(400, 400)); htmlPane.setEditable(false); - htmlPane.setFont(new Font("helvetica", Font.PLAIN, 12)); + htmlPane.setFont(new Font("sansserif", Font.PLAIN, 12)); return htmlPane; } private void initGuiComponents() { + // FIXME: replace with CardLayout for easier switching between panels +// cardLayout = new CardLayout(); + setLayout(new BorderLayout(4, 4)); instructionsEditorPane = createInstructionsEditorPane(); instructionsScrollPane = new JScrollPane(instructionsEditorPane); @@ -280,6 +285,7 @@ subjectWindow.setForeground(Color.BLACK); subjectWindow.add(subjectView, BorderLayout.CENTER); setBackground(Color.WHITE); + // replace with progress bar. timeLeftLabel = new JLabel("Connecting ..."); informationLabel = new JLabel("Tokens collected: 0 "); // latencyLabel = new JLabel("Latency: 0"); @@ -331,6 +337,10 @@ // add component listeners, chat panel, and sanctioning window IF chat/sanctioning are enabled, and after the end of the round... } + /** + * IMPORTANT: this method handles client keyboard inputs within the game. + * @return + */ private KeyAdapter createGameWindowKeyListener() { return new KeyAdapter() { private volatile boolean keyReleased; @@ -424,10 +434,7 @@ remove(currentCenterComponent); add(newCenterComponent, BorderLayout.CENTER); newCenterComponent.setVisible(true); - invalidate(); - validate(); - newCenterComponent.repaint(); - repaint(); + revalidate(); } currentCenterComponent = newCenterComponent; } Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GridView.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-01 21:23:20 UTC (rev 384) @@ -51,7 +51,7 @@ // how big the entire screen is. protected Dimension screenSize; - // how big the game board is. + // the size of the actual resource board. protected Dimension boardSize; public GridView(Dimension screenSize) { @@ -78,7 +78,7 @@ yoffset = (int) Math.floor((availableHeight - (dh * boardSize.getHeight())) / 2); fontSize = (int)(0.85 * dh); - font = new Font("Serif", Font.BOLD, fontSize); + font = new Font("sansserif", Font.BOLD, fontSize); // make sure we've got enough room setSize(availableWidth, availableHeight); @@ -157,9 +157,9 @@ // Could just update the parts that have changed (tokens removed, subjects moved) // paint the background paintBackground(graphics2D); - // render the food particles in my mouth and on my shirt + // paint resources paintTokens(graphics2D); - // render the subjects on the graphics object. + // paint subjects last (covering up tokens as needed) paintSubjects(graphics2D); } Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/client/PostRoundSanctioningPanel.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/PostRoundSanctioningPanel.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/client/PostRoundSanctioningPanel.java 2009-12-01 21:23:20 UTC (rev 384) @@ -97,6 +97,7 @@ // centerPanel.add(getSanctionTableScrollPane()); add(centerPanel, BorderLayout.CENTER); add(getSubmitButton(), BorderLayout.SOUTH); + setName("Post round sanctioning panel"); } private JButton getSubmitButton() { Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/client/SubjectView.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-01 21:23:20 UTC (rev 384) @@ -41,6 +41,10 @@ this.dataModel = dataModel; } + /** + * FIXME: use dataModel.getRoundConfiguration() instead, but need to ensure it is updated properly + * prior to invocation of this method. + */ public void setup(RoundConfiguration configuration) { synchronized (collectedTokens) { collectedTokens.clear(); @@ -61,6 +65,7 @@ Point location = dataModel.getCurrentPosition(); Circle viewTokensField = new Circle(location, dataModel.getRoundConfiguration().getViewTokensRadius()); paintCollection(dataModel.getResourcePositions(), graphics2D, scaledTokenImage, this, viewTokensField); + } else { paintCollection(dataModel.getResourcePositions(), graphics2D, scaledTokenImage); @@ -109,8 +114,19 @@ int characterHeight = fontMetrics.getAscent(); int verticalCharacterSpacing = (int) ( (dh - characterHeight) / 2); Circle fieldOfVision = null; - if (dataModel.getRoundConfiguration().isSubjectsFieldOfVisionEnabled()) { - fieldOfVision = new Circle(dataModel.getCurrentPosition(), dataModel.getRoundConfiguration().getViewSubjectsRadius()); + Point currentPosition = dataModel.getCurrentPosition(); + RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); + if (roundConfiguration.isSubjectsFieldOfVisionEnabled()) { + double radius = roundConfiguration.getViewSubjectsRadius(); + fieldOfVision = new Circle(currentPosition, radius); + // paint field of vision +// Paint originalPaint = graphics2D.getPaint(); +// graphics2D.setPaint(new Color(192, 192, 192, 30)); +// Point topLeftCorner = new Point(currentPosition.x - (int) radius, currentPosition.y - (int) radius); +// int x = scaleX(topLeftCorner.x); +// int y = scaleY(topLeftCorner.y); +// graphics2D.fillOval(x, y, scaleX(radius), scaleY(radius)); +// graphics2D.setPaint(originalPaint); } for (Map.Entry<Identifier, ClientData> entry : positions.entrySet()) { Identifier id = entry.getKey(); Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/FacilitatorWindow.java 2009-12-01 21:23:20 UTC (rev 384) @@ -2,14 +2,11 @@ import java.awt.BorderLayout; import java.awt.Color; -import java.awt.Component; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; -import java.io.File; -import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -17,7 +14,6 @@ import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JEditorPane; -import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -27,7 +23,6 @@ import javax.swing.ScrollPaneConstants; import edu.asu.commons.foraging.conf.RoundConfiguration; -import edu.asu.commons.foraging.conf.ServerConfiguration; import edu.asu.commons.foraging.event.FacilitatorEndRoundEvent; import edu.asu.commons.foraging.event.FacilitatorSanctionUpdateEvent; import edu.asu.commons.foraging.model.ClientData; @@ -73,19 +68,12 @@ private JMenuItem loadExperimentMenuItem = null; - private ReplayControlPanel replayControlPanel; - - private File saveDirectory; - private JMenuBar menuBar; private int completedQuizzes; private JMenuItem startChatMenuItem; - /* - * Constructor - */ public FacilitatorWindow(Dimension dimension, Facilitator facilitator) { this.facilitator = facilitator; windowDimension = dimension; @@ -96,13 +84,21 @@ // centerOnScreen(); // frame.setVisible(true); } + + public void initializeReplay() { + throw new UnsupportedOperationException("Replay currently unimplemented."); + } + + public void initializeReplayRound() { + throw new UnsupportedOperationException("Replay currently unimplemented."); + } /* * This method gets called after the end of each round */ public void displayInstructions() { - - repaint(); + +// repaint(); } /* @@ -120,11 +116,9 @@ } private JMenuBar createMenu() { - JMenu menu = null; + JMenu menu = new JMenu("Experiment"); menuBar = new JMenuBar(); - //Experiment menu - menu = new JMenu("Experiment"); menu.setMnemonic(KeyEvent.VK_E); startExperimentMenuItem = new JMenuItem("Start"); @@ -210,59 +204,12 @@ menuBar.add(menu); - //Replay menu - menu = new JMenu("Replay"); - menu.setMnemonic(KeyEvent.VK_R); - loadExperimentMenuItem = new JMenuItem("Load Experiment"); - loadExperimentMenuItem.setMnemonic(KeyEvent.VK_L); - ActionListener loadExperimentActionListener = new ActionListener() { - public void actionPerformed(ActionEvent e) { - JFileChooser fileChooser = new JFileChooser(); - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - int returnVal = fileChooser.showOpenDialog(null); - if (returnVal == JFileChooser.APPROVE_OPTION) { - saveDirectory = fileChooser.getSelectedFile(); - // FIXME: implement Persister.restoreConfiguration. -// getFacilitator().setConfiguration( -// ForagerPersister.restoreServerConfiguration(saveDirectory)); - initializeReplay(); - replayControlPanel.setVisible(true); - } - } - }; - loadExperimentMenuItem.addActionListener(loadExperimentActionListener); - loadExperimentMenuItem.setEnabled(false); - menu.add(loadExperimentMenuItem); - menuBar.add(menu); return menuBar; } public JMenuBar getMenuBar() { return menuBar; } - - // FIXME: better names please - public void initializeReplay() { - viewPane.getViewport().removeAll(); - ServerConfiguration configuration = getFacilitator().getServerConfiguration(); -// FIXME: add restore() method to Persister as well and then uncomment these lines of code. -// ForagerPersister persister = ForagerPersister.restore(saveDirectory, -// configuration.getCurrentRoundNumber()); -// RoundConfiguration currentRoundConfiguration = -// persister.getRoundConfiguration(); -// getFacilitator().setServerGameState( -// new ForagerServerGameState(currentRoundConfiguration)); - // initialize currentRoundConfiguration on every ClientData object? -// replayControlPanel.init(saveDirectory, persister); - repaint(); - } - - public void initializeReplayRound() { - // switchCenterComponent(informationPanel, viewPane); - // initViewPanel(); - // repaint(); - } - private void initGuiComponents() { setLayout(new BorderLayout(4, 4)); // setBackground(Color.WHITE); @@ -286,12 +233,6 @@ viewPane = new JScrollPane(); add(informationPanel, BorderLayout.CENTER); - // set up replay control panel - if (facilitator.isReplaying()) { - replayControlPanel = new ReplayControlPanel(FacilitatorWindow.this); - replayControlPanel.setVisible(false); - add(replayControlPanel, BorderLayout.NORTH); - } } public void initViewPanel() { @@ -325,11 +266,6 @@ int groupCounter = 1; for (GroupDataModel group : groups) { JPanel groupPanel = new JPanel(new BorderLayout(4, 4)); - - //FIXME: This is not a very elegant code. Try to make it. - Set<Identifier> clientIds = group.getClientIdentifiers(); - Iterator<Identifier> iter = clientIds.iterator(); - Identifier clientId = iter.next(); GroupView groupView = new GroupView(groupViewDimension, group); groupView.setup(roundConfiguration); @@ -367,23 +303,6 @@ viewPane.getViewport().add(viewPanel); } - private void switchCenterComponent(Component out, Component in) { - switchComponent(out, in, BorderLayout.CENTER); - } - - private void switchComponent(Component out, Component in, String location) { - out.setVisible(false); - remove(out); - // XXX: assumes that we're using BorderLayout as the LayoutManager - // for the game window - add(in, location); - in.setVisible(true); - invalidate(); - validate(); - //in.repaint(); - repaint(); - } - private void setInstructions(String contents) { informationEditorPane.setText(contents); informationEditorPane.setCaretPosition(0); Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ReplayControlPanel.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ReplayControlPanel.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/ReplayControlPanel.java 2009-12-01 21:23:20 UTC (rev 384) @@ -4,11 +4,9 @@ import java.awt.event.ActionListener; import java.io.File; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ListIterator; -import java.util.Map; import javax.swing.Box; import javax.swing.BoxLayout; @@ -31,7 +29,6 @@ import edu.asu.commons.foraging.model.ClientData; import edu.asu.commons.foraging.model.GroupDataModel; import edu.asu.commons.foraging.model.ServerDataModel; -import edu.asu.commons.net.Identifier; /** @@ -237,7 +234,6 @@ private static final int DEFAULT_STEP_SIZE = 100; private final List<PersistableEvent> actions; private final ServerDataModel serverDataModel; - private Persister<ServerConfiguration, RoundConfiguration> persister; private Thread saveGameViewerThread; private ListIterator<PersistableEvent> actionsIterator; private volatile boolean playing; @@ -250,7 +246,6 @@ public ReplayRoundThread(Persister<ServerConfiguration, RoundConfiguration> persister) { this.actions = new ArrayList<PersistableEvent>(persister.getActions()); - this.persister = persister; // FIXME: provide data model restore functionality in persister // this.serverDataModel = persister.restoreInitialGameState(); this.serverDataModel = new ServerDataModel(EventChannelFactory.create()); @@ -273,6 +268,7 @@ haltThread(); // facilitatorWindow.getFacilitator().getServerConfiguration().resetExperimentRoundConfiguration(); serverDataModel.clear(); + actions.clear(); facilitatorWindow.initializeReplay(); } @@ -309,11 +305,6 @@ startSaveGameViewerThread(); } - public void dispose() { - stop(); - actions.clear(); - } - private void step(int duration) { long timeLeft = 0; if (currentPersistableEvent == null) { @@ -487,24 +478,13 @@ saveGameViewerThread.start(); } - private Map<Identifier, ClientData> getClientDataMap() { +// private Map<Identifier, ClientData> getClientDataMap() { // Map<Identifier, ClientData> clientDataMap = new HashMap<Identifier, ClientData>(); -// Map<Identifier, Persister<ServerConfiguration>.ParticipantTokens> tokens = persister.getParticipantTokensMap(); -// for (Group group: gameState.getGroups()) { -// for (Identifier id: group.getClientIdentifiers()) { -// ClientData clientData = group.getClientData(id); -// clientData.setCurrentTokens(tokens.get(id).currentTokens); -// clientData.setTotalTokens(tokens.get(id).totalTokens); -// clientDataMap.put(id, group.getClientData(id)); -// } +// for (GroupDataModel group: serverDataModel.getGroups()) { +// clientDataMap.putAll(group.getClientDataMap()); // } // return clientDataMap; - Map<Identifier, ClientData> clientDataMap = new HashMap<Identifier, ClientData>(); - for (GroupDataModel group: serverDataModel.getGroups()) { - clientDataMap.putAll(group.getClientDataMap()); - } - return clientDataMap; - } +// } private long getTimeOffset(PersistableEvent event) { // grab the creation time of the very first persistable event to Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/RoundConfigurationDialog.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/RoundConfigurationDialog.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/facilitator/RoundConfigurationDialog.java 2009-12-01 21:23:20 UTC (rev 384) @@ -25,8 +25,6 @@ private JTextField foodRate = null; private JCheckBox privateProperty = null; private JCheckBox practiceRound = null; - private JCheckBox displayOtherClients = null; - private JCheckBox displayFood = null; private JCheckBox displayGroupTokens = null; private JTextField boardWidth = null; private JTextField boardHeight = null; @@ -103,8 +101,6 @@ checkBoxPanel.add(this.getPrivateProperty()); checkBoxPanel.add(this.getPracticeRound()); -// checkBoxPanel.add(this.getDisplayFood()); -// checkBoxPanel.add(this.getDisplayOtherClients()); checkBoxPanel.add(this.getDisplayGroupTokens()); return checkBoxPanel; @@ -189,21 +185,7 @@ } return practiceRound; } -// public JCheckBox getDisplayFood() { -// if (displayFood == null) { -// displayFood = new JCheckBox("Display Food", roundConfiguration.getFoodVisibility().isFullVisibility()); -// displayFood.setEnabled(!readOnly); -// } -// return displayFood; -// } -// public JCheckBox getDisplayOtherClients() { -// if (displayOtherClients == null) { -// displayOtherClients = new JCheckBox("Display Other Clients", roundConfiguration.getSubjectVisibility().isFullVisibility()); -// displayOtherClients.setEnabled(!readOnly); -// } -// return displayOtherClients; -// } - + public JCheckBox getDisplayGroupTokens() { if (displayGroupTokens == null) { displayGroupTokens = new JCheckBox("Display Group Tokens", roundConfiguration.shouldDisplayGroupTokens()); Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-01 21:23:20 UTC (rev 384) @@ -54,6 +54,8 @@ private final long groupId; private volatile static long nextGroupId = 0; +// private List<Regulation> regulationSubmissions; + // private transient float averageTokens = -1; public GroupDataModel(ServerDataModel serverDataModel) { Modified: foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java =================================================================== --- foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-01 19:06:46 UTC (rev 383) +++ foraging/trunk/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-01 21:23:20 UTC (rev 384) @@ -74,7 +74,6 @@ private final Logger logger = Logger.getLogger(getClass().getName()); - private final Map<Identifier, ClientData> clients = new HashMap<Identifier, ClientData>(); public final static int SYNCHRONIZATION_FREQUENCY = 60; @@ -87,7 +86,7 @@ private final Object quizSignal = new Object(); private final Object postRoundSanctioningSignal = new Object(); private final Object agentDesignSignal = new Object(); -// FIXME: these latches don't quite do what we want... +// FIXME: these latches don't quite do what we want. We need a way to reset them at each round. // private CountDownLatch postRoundSanctionLatch; private StateMachine stateMachine = new ForagingStateMachine(); @@ -632,7 +631,6 @@ } } - private void advanceToNextRound() { if (getConfiguration().isLastRound()) { // stop the experiment. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Kalin J. <kj...@as...> - 2009-12-01 19:09:34
|
I am checking out for now at 12:00noon (2hrs) I have finished adding the actionscript methods that will work with consumer etc to make the component work, but it just needs to be connected to server, which I have to leave up to seema, as I don't quite know how to implement consumer etc. I will be leaving for the day unless I get an email before 2pm, as I have class/plans after that. On Tue, Dec 1, 2009 at 10:03 AM, Kalin Jonas <kj...@as...> wrote: > I came in to work today at 10:00 am > I will work on the communication component: adding the mxml for the service > that it will use. > > > On Sun, Nov 29, 2009 at 3:11 PM, Kalin Jonas <kj...@as...> wrote: > >> Checking out at 3:00pm >> I have completed the Communication interface as listed below. >> It needs to have a service to connect to the server, and code needs to be >> written to push the communication objects to all clients connected, but the >> interface is done. >> >> >> On Sun, Nov 29, 2009 at 12:18 PM, Kalin Jonas <kj...@as...> wrote: >> >>> Checking in from home today at 12:00 noon >>> I will be working on a communications interface with the following >>> design: >>> >>> - Large Box for messages received/sent >>> - Small Box for typing a message >>> - Button for sending a message (Enter key should also send) >>> >>> I am going to try to give it the following functionality: >>> >>> - Client concatenates user number & sends a message to server when >>> Enter/Button pressed (Server should assign timestamp and push the message to >>> all clients) >>> - Client receives a message from the server (does not matter who it >>> is from) and puts it in the Large Box. >>> >>> >> > |