Thread: [virtualcommons-svn] SF.net SVN: virtualcommons:[386] foraging/branches/deepak-branch-fall-09/ src
Status: Beta
Brought to you by:
alllee
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: <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: <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 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 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 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. |
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 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 18:24:31
|
Revision: 408 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=408&view=rev Author: alllee Date: 2009-12-04 18:24:23 +0000 (Fri, 04 Dec 2009) Log Message: ----------- latest revision 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/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 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/EnforcementPanel.java =================================================================== --- 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) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-04 18:24:23 UTC (rev 408) @@ -3,16 +3,12 @@ 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 javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; @@ -70,14 +66,15 @@ }; public EnforcementPanel (ForagingClient client) { + this(); this.client = client; this.clientId = client.getId(); } private Identifier clientId; private JPanel votingPanel; - private JButton reset; - private JButton sendMyVotes; +// private JButton reset; +// private JButton sendMyVotes; private JPanel instructionsPanel; private SixChoicePanel[] newPanel; @@ -108,6 +105,7 @@ String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); JTextArea instructionText = new JTextArea(instructions,3,50); + instructionText.setWrapStyleWord(true); JScrollPane scrollForRegulationText = new JScrollPane(instructionText); instructionPanel.add(scrollForRegulationText); @@ -130,13 +128,13 @@ private void updateVotingPanel(int currentActive){ int r,c,i; SixChoicePanel temp = null; - boolean enableSendButton = true; +// boolean enableSendButton = true; for(r = 0; r < noOfEnforcements; r++) { - if(newPanel[r].currentRanking == -1)enableSendButton = false; +// if(newPanel[r].currentRanking == -1)enableSendButton = false; if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) { @@ -184,11 +182,11 @@ votingPanel.setVisible(true); add(votingPanel, BorderLayout.CENTER); - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } +// if(enableSendButton) { +// sendMyVotes.setEnabled(true); +// buttonPanel.setVisible(true); +// add(buttonPanel, BorderLayout.SOUTH); +// } revalidate(); } @@ -242,49 +240,49 @@ } 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); +// 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); } public void initialize() { @@ -331,20 +329,21 @@ public JPanel getEnforcementPanel(int i){ enforcementPanel = new JPanel(); enforcementPanel.setBackground(color); - enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.X_AXIS)); + enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.Y_AXIS)); enforcementPanel.setBorder(BorderFactory.createTitledBorder(title)); //create Text area and JSCroll pane for it 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); + regulationText.setWrapStyleWord(true); + JScrollPane scrollForRegulationText = new JScrollPane(regulationText); enforcementPanel.add(scrollForRegulationText); rankPanel = new JPanel(); rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Rank")); group = new ButtonGroup(); int length = buttonLabels.length; // Assumes even length 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 17:05:29 UTC (rev 407) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 18:24:23 UTC (rev 408) @@ -235,8 +235,8 @@ } private void startRegulationDisplayTimer(){ - if (timer == null) { - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationDisplayDuration()); + if (timer == null) { + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationDisplayDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -256,9 +256,9 @@ private void startEnforcementVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementVotingDuration()); + 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()) { @@ -280,8 +280,8 @@ private void startRegulationVotingTimer() { - if (timer == null) { - duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingtDuration()); + if (timer == null) { + duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingtDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { @@ -307,10 +307,10 @@ } } - + private void startRegulationSubmissionTimer() { - if (timer == null) { - duration = Duration.create(dataModel.getRoundConfiguration().getRegulationSubmissionDuration()); + if (timer == null) { + duration = Duration.create(dataModel.getRoundConfiguration().getRegulationSubmissionDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { @@ -330,9 +330,9 @@ } } private void startChatTimer() { - if (timer == null) { - // final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); - 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()) { @@ -421,7 +421,7 @@ subjectWindow.setBackground(Color.WHITE); subjectWindow.setForeground(Color.BLACK); subjectWindow.add(subjectView, BorderLayout.CENTER); -// setBackground(SubjectView.FIELD_OF_VISION_COLOR); + // setBackground(SubjectView.FIELD_OF_VISION_COLOR); setBackground(Color.WHITE); // replace with progress bar. timeLeftLabel = new JLabel("Connecting ..."); @@ -432,16 +432,16 @@ // 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); + // 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)); @@ -531,11 +531,11 @@ 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 (! dataModel.isSanctioningAllowed()) { - // get rid of magic constants - displayErrorMessage("You aren't allowed to reduce other participants tokens at this time.", 1); - return; - } + 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.canPerformRealTimeSanction()) { //System.out.println("Can do sanctioning"); int assignedNumber = keyChar - 48; @@ -768,26 +768,34 @@ } public void displayActiveEnforcementMechanism() { - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { public void run() { - 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()); + String activeRegulation = dataModel.getActiveRegulation().getText(); + if (activeRegulation == null || activeRegulation.trim().isEmpty()) { + activeRegulation = "No regulation specified."; + } + instructionsBuilder.append("<hr/><h2>Active regulation</h2><hr/><p>").append(activeRegulation).append("</p>"); + instructionsBuilder.append("<hr/><h2>Active enforcement mechanism</h2><hr/><p>").append(dataModel.getActiveEnforcementMechanism().getDescription()).append("</p>"); + setInstructions(instructionsBuilder.toString()); addCenterComponent(instructionsScrollPane); } }); } private void displayVotingWaitMessage() { - setInstructions("<h3>Please wait while we finish collecting information from all the participants.</h3>"); - addCenterComponent(instructionsScrollPane); + setInstructions("<h3>Please wait while we finish collecting information from all the participants.</h3>"); + addCenterComponent(instructionsScrollPane); } public void displayActiveRegulation() { SwingUtilities.invokeLater(new Runnable() { public void run() { - setInstructions( - "<h3>The following regulation received the most votes:</h3><pre>" + dataModel.getActiveRegulation() + "</pre>"); + String activeRegulation = dataModel.getActiveRegulation().getText(); + if (activeRegulation == null || activeRegulation.trim().isEmpty()) { + activeRegulation = "No regulation specified."; + } + setInstructions( + "<h3>The following regulation received the most votes:</h3><pre>" + activeRegulation + "</pre>"); addCenterComponent(instructionsScrollPane); startRegulationDisplayTimer(); } @@ -837,7 +845,7 @@ } public void initializeEnforcementVotingPanel() { - // TODO: revisit + // TODO: revisit SwingUtilities.invokeLater(new Runnable() { public void run() { EnforcementPanel enforcementPanel = getEnforcementPanel(); @@ -861,26 +869,26 @@ } public void initializeRegulationPanel() { -// getRegulationPanel().initialize(); - // System.out.println("Initialization done"); - addCenterComponent(getSubmitRegulationPanel()); - 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; + 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() { 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 17:05:29 UTC (rev 407) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java 2009-12-04 18:24:23 UTC (rev 408) @@ -3,8 +3,6 @@ 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; @@ -12,9 +10,7 @@ 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; @@ -52,6 +48,7 @@ private ForagingClient client; public RegulationPanel (ForagingClient client) { + this(); this.client = client; // client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { // public void handle(final RegulationEvent regulationEvent) { @@ -80,15 +77,13 @@ // }); } - public RegulationPanel () - { + public RegulationPanel() { // regulations = new ArrayList<RegulationData>(); + // FIXME: get rid of hardcoded constants, this should be dynamic based on the size of the group. newPanel = new SixChoicePanel[5]; noOfRegulations = 5; } - private RegulationData votedRegulation; - private int noOfRegulations; private int[] currentRankingInformation; @@ -97,9 +92,9 @@ private JPanel votingPanel; private JPanel instructionsPanel; - private JPanel buttonPanel; - private JButton sendMyVotes; - private JButton reset; +// private JPanel buttonPanel; +// private JButton sendMyVotes; +// private JButton reset; private String[] votes = { "1", "2", "3","4", "5"}; @@ -126,11 +121,6 @@ // } // } // } - - public RegulationData getVotedRegulation(){ - return this.votedRegulation; - } - private void addStylesToMessageWindow() { StyledDocument styledDocument = messageWindow.getStyledDocument(); // and why not have something like... StyleContext.getDefaultStyle() to @@ -146,11 +136,11 @@ .addStyle("italic", defaultStyle), true); } - // FIXME: extremely inefficient, refactor after experiment. + // FIXME: messy, refactor after experiment. private void updateVotingPanel(int currentActive){ int r,c,i; SixChoicePanel temp = null; - boolean enableSendButton = true; +// 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 @@ -160,7 +150,7 @@ for(r = 0; r < noOfRegulations; r++) { System.out.print(newPanel[r].currentRanking+" "); - if(newPanel[r].currentRanking == -1)enableSendButton = false; +// if(newPanel[r].currentRanking == -1) enableSendButton = false; if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) { @@ -206,11 +196,11 @@ votingPanel.setVisible(true); add(votingPanel, BorderLayout.CENTER); - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } +// if(enableSendButton) { +// sendMyVotes.setEnabled(true); +// buttonPanel.setVisible(true); +// add(buttonPanel, BorderLayout.SOUTH); +// } revalidate(); } @@ -288,61 +278,70 @@ // end //for(int i=0; i<5; i++) { - int i = 0; - for (RegulationData regulationData : client.getDataModel().getSubmittedRegulations()) { + List<RegulationData> submittedRegulations = client.getDataModel().getSubmittedRegulations(); +// List<RegulationData> submittedRegulations = +// Arrays.asList(new RegulationData(new Identifier.Base(), "Regulation 1", 0), +// new RegulationData(new Identifier.Base(), "Regulation 2", 1), +// new RegulationData(new Identifier.Base(), "Regulation 3", 2), +// new RegulationData(new Identifier.Base(), "Regulation 4", 3), +// new RegulationData(new Identifier.Base(), "Regulation 5", 4)); + + for (RegulationData regulationData : submittedRegulations) { + System.err.println("creating six choice panel from regulation data: " + regulationData); // 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)); +// String s = sb.toString(); + int index = regulationData.getIndex(); + + newPanel[index] = new SixChoicePanel(votes, index, getColor(index)); // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); - votingPanel.add(newPanel[i].getRegulationPanel(i,regulationData.getText())); - i++; + votingPanel.add(newPanel[index].getRegulationPanel(index,regulationData.getText())); } 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) { +// 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); - 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); +// add(buttonPanel, BorderLayout.SOUTH); } private JPanel getInstructionPanel() @@ -352,9 +351,11 @@ instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); - String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); - JTextArea instructionText = new JTextArea(instructions); +// String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); + String instructions = "Voting instructions"; + JTextArea instructionText = new JTextArea(instructions, 3, 50); instructionText.setWrapStyleWord(true); + instructionText.setEditable(false); JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); instructionPanel.add(scrollForRegulationText); @@ -383,11 +384,17 @@ //dummy regulation instructions are //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); - regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); +// regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); + + setInstructions("Regulation instructions"); add(regulationsInstructionsScrollPane, BorderLayout.NORTH); add(messageScrollPane, BorderLayout.CENTER); } + + public void setInstructions(String instructions) { + regulationsInstructionsPane.setText(instructions); + } public void clear() { participants.clear(); @@ -406,7 +413,7 @@ JRadioButton option []; Color color; - public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { + public SixChoicePanel(String[] buttonLabels, int regulationID, Color color ) { //this.title = title; this.buttonLabels = buttonLabels; this.regulationID = regulationID; @@ -433,19 +440,20 @@ public JPanel getRegulationPanel(int i, String information){ regulationPanel = new JPanel(); regulationPanel.setBackground(color); - regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); + regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.Y_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); + JTextArea regulationText = new JTextArea(information, 3, 50); + regulationText.setWrapStyleWord(true); + JScrollPane scrollForRegulationText = new JScrollPane(regulationText); regulationPanel.add(scrollForRegulationText); rankPanel = new JPanel(); rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Rank")); group = new ButtonGroup(); int length = buttonLabels.length; // Assumes even length 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 17:05:29 UTC (rev 407) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 18:24:23 UTC (rev 408) @@ -283,7 +283,7 @@ } public int getRegulationSubmissionDuration() { - return getIntProperty("regulation-submission-duration", 60); + return getIntProperty("regulation-submission-duration", 20); } public int getRegulationDisplayDuration() { 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 17:05:29 UTC (rev 407) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/GroupDataModel.java 2009-12-04 18:24:23 UTC (rev 408) @@ -150,12 +150,16 @@ for (ClientData clientData : clients.values()) { int[] regulationRankings = clientData.getRegulationRankings(); 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; + for (int rank = 0; rank < numberOfRegulations; rank++) { + int actualRegulationIndex = regulationRankings[rank]; + if (actualRegulationIndex == -1) { + continue; + } + regulationVotingTally[actualRegulationIndex] += rankToValue(rank); + submittedRegulations.get(actualRegulationIndex).setRank(regulationVotingTally[actualRegulationIndex]); + if (regulationVotingTally[actualRegulationIndex] > maxRankingValue) { + maxRankingValue = regulationVotingTally[actualRegulationIndex]; + maxRankingIndex = actualRegulationIndex; } } } @@ -182,12 +186,19 @@ double maxRankingValue = 0.0d; for (ClientData clientData: clients.values()) { int[] enforcementRankings = clientData.getEnforcementRankings(); - for (int index = 0; index < enforcementRankings.length; index++) { - enforcementVotingTally[index] += rankToValue(enforcementRankings[index]); + logger.info("XXX: enforcement rankings: " + enforcementRankings); + for (int rank = 0; rank < enforcementRankings.length; rank++) { + // 0 is top choice + int actualEnforcementIndex = enforcementRankings[rank]; + if (actualEnforcementIndex == -1) { + // nothing selected for this rank + continue; + } + enforcementVotingTally[actualEnforcementIndex] += rankToValue(rank); // keep a tally of the max index so we don't have to make another pass. - if (enforcementVotingTally[index] > maxRankingValue) { - maxRankingValue = enforcementVotingTally[index]; - maxRankingIndex = index; + if (enforcementVotingTally[actualEnforcementIndex] > maxRankingValue) { + maxRankingValue = enforcementVotingTally[actualEnforcementIndex]; + maxRankingIndex = actualEnforcementIndex; } } } @@ -235,6 +246,7 @@ clientData.setRegulationData(submittedRegulation); submittedRegulations.add(submittedRegulation); submittedRegulation.setIndex(submittedRegulations.size() - 1); + System.err.println("submitted regulation: " + submittedRegulation); } public boolean hasReceivedAllRegulations() { 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 17:05:29 UTC (rev 407) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/RegulationData.java 2009-12-04 18:24:23 UTC (rev 408) @@ -24,8 +24,13 @@ private int index; public RegulationData(Identifier id, String text) { + this(id, text, -1); + } + + public RegulationData(Identifier id, String text, int index) { this.id = id; this.text = text; + this.index = index; } /** @@ -71,7 +76,7 @@ } public String toString() { - return text; + return String.format("regulation from %s and index %d : %s", id, index, text); } public int compareTo(RegulationData regulationData) { 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 17:05:29 UTC (rev 407) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java 2009-12-04 18:24:23 UTC (rev 408) @@ -280,6 +280,7 @@ // FIXME: start new implementation here. addEventProcessor(new EventTypeProcessor<EnforcementRankingRequest>(EnforcementRankingRequest.class) { public void handle(final EnforcementRankingRequest request) { + logger.info("received enforcement ranking request: " + request.getRankings()); GroupDataModel group = serverDataModel.getGroup(request.getId()); group.submitEnforcementRanking(request); if (group.hasReceivedAllEnforcementRankings()) { @@ -457,7 +458,7 @@ } private void sendEnforcementUpdate(GroupDataModel group) { - EnforcementMechanism enforcementMechanism = group.generateEnforcementRankings(); + group.generateEnforcementRankings(); for (Identifier id: group.getClientIdentifiers()) { 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 18:32:15
|
Revision: 409 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=409&view=rev Author: alllee Date: 2009-12-04 18:32:03 +0000 (Fri, 04 Dec 2009) Log Message: ----------- stuff 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/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 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 18:24:23 UTC (rev 408) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 18:32:03 UTC (rev 409) @@ -281,7 +281,7 @@ private void startRegulationVotingTimer() { if (timer == null) { - duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingtDuration()); + duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { 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 18:24:23 UTC (rev 408) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-04 18:32:03 UTC (rev 409) @@ -34,7 +34,7 @@ protected Image tokenImage, otherSubjectImage, selfImage, selfExplicitCollectionModeImage, beingSanctionedImage, sanctioningImage, monitorImage; protected Image scaledTokenImage, scaledOtherSubjectImage, scaledSelfImage, - scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMoniterImage; + scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMonitorImage; /** * 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); - scaledMoniterImage = monitorImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); + scaledMonitorImage = 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-04 18:24:23 UTC (rev 408) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-04 18:32:03 UTC (rev 409) @@ -180,8 +180,8 @@ graphics2D.fillRect(x, y, getCellWidth(), getCellHeight()); graphics2D.drawImage(scaledBeingSanctionedImage, x, y, this); } - else if (dataModel.isMonitor()) { - graphics2D.drawImage(scaledMoniterImage, x, y, this); + else if (id.equals(dataModel.getMonitorId())) { + graphics2D.drawImage(scaledMonitorImage, x, y, this); } else if (dataModel.isSanctioning(id)) { graphics2D.setColor(Color.WHITE); @@ -189,7 +189,6 @@ graphics2D.drawImage(scaledSanctioningImage, x, y, this); } else if (id.equals(dataModel.getId())) { - // self image if (dataModel.isExplicitCollectionMode()) { graphics2D.drawImage(scaledSelfExplicitCollectionModeImage, 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-04 18:24:23 UTC (rev 408) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java 2009-12-04 18:32:03 UTC (rev 409) @@ -279,18 +279,18 @@ } public int getChatDuration() { - return getIntProperty("chat-duration", 10); + return getIntProperty("chat-duration", 120); } public int getRegulationSubmissionDuration() { - return getIntProperty("regulation-submission-duration", 20); + return getIntProperty("regulation-submission-duration", 60); } public int getRegulationDisplayDuration() { - return getIntProperty("regulation-display-duration", 60); + return getIntProperty("regulation-display-duration", 30); } - public int getRegulationVotingtDuration() { + public int getRegulationVotingDuration() { return getIntProperty("regulation-voting-duration", 60); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-12-04 19:42:06
|
Revision: 410 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=410&view=rev Author: alllee Date: 2009-12-04 19:41:59 +0000 (Fri, 04 Dec 2009) Log Message: ----------- several NPE bug fixes: - added null check for active monitors - fixed NPE in sanction handling where ClientData.latestSanctions was null (http://opensource.asu.edu/jira/browse/COMMONS-9) 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/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/event/SubmitRegulationRequest.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.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 18:32:03 UTC (rev 409) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-04 19:41:59 UTC (rev 410) @@ -63,7 +63,10 @@ } public Identifier getMonitorId() { - return groupDataModel.getActiveMonitor().getId(); + if (groupDataModel.getActiveMonitor() != null) { + return groupDataModel.getActiveMonitor().getId(); + } + return Identifier.NULL; } public boolean isSanctioningAllowed() { 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 18:32:03 UTC (rev 409) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-04 19:41:59 UTC (rev 410) @@ -795,7 +795,7 @@ activeRegulation = "No regulation specified."; } setInstructions( - "<h3>The following regulation received the most votes:</h3><pre>" + activeRegulation + "</pre>"); + "<h3>The following regulation received the most votes:</h3><p>" + activeRegulation + "</p>"); addCenterComponent(instructionsScrollPane); startRegulationDisplayTimer(); } 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 18:32:03 UTC (rev 409) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java 2009-12-04 19:41:59 UTC (rev 410) @@ -180,14 +180,14 @@ graphics2D.fillRect(x, y, getCellWidth(), getCellHeight()); graphics2D.drawImage(scaledBeingSanctionedImage, x, y, this); } - else if (id.equals(dataModel.getMonitorId())) { - graphics2D.drawImage(scaledMonitorImage, x, y, this); - } else if (dataModel.isSanctioning(id)) { graphics2D.setColor(Color.WHITE); graphics2D.fillRect(x, y, getCellWidth(), getCellHeight()); graphics2D.drawImage(scaledSanctioningImage, x, y, this); } + else if (id.equals(dataModel.getMonitorId())) { + graphics2D.drawImage(scaledMonitorImage, x, y, this); + } else if (id.equals(dataModel.getId())) { if (dataModel.isExplicitCollectionMode()) { graphics2D.drawImage(scaledSelfExplicitCollectionModeImage, x, y, this); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/SubmitRegulationRequest.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/SubmitRegulationRequest.java 2009-12-04 18:32:03 UTC (rev 409) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/SubmitRegulationRequest.java 2009-12-04 19:41:59 UTC (rev 410) @@ -13,7 +13,7 @@ * @version $Revision: 1 $ */ -public class SubmitRegulationRequest extends AbstractEvent { +public class SubmitRegulationRequest extends AbstractPersistableEvent { private static final long serialVersionUID = 475300882222383637L; 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 18:32:03 UTC (rev 409) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/model/ClientData.java 2009-12-04 19:41:59 UTC (rev 410) @@ -49,7 +49,7 @@ private volatile boolean collecting; private volatile boolean explicitCollectionMode; private Duration freezeDuration; - private LinkedList<RealTimeSanctionRequest> latestSanctions; + private LinkedList<RealTimeSanctionRequest> latestSanctions = new LinkedList<RealTimeSanctionRequest>(); private AnimationData animationData; private boolean subjectsFieldOfVisionEnabled; @@ -290,9 +290,7 @@ } public void resetLatestSanctions() { - if (latestSanctions != null) { - latestSanctions.clear(); - } + latestSanctions.clear(); } private void resetCurrentTokens() { @@ -397,9 +395,6 @@ if (tokensFieldOfVisionEnabled) { viewTokensRadius = roundConfiguration.getViewTokensRadius(); } - if (roundConfiguration.isRealTimeSanctioningEnabled()) { - latestSanctions = new LinkedList<RealTimeSanctionRequest>(); - } if (roundConfiguration.isPrivateProperty()) { setPosition (new Point(roundConfiguration.getResourceWidth() / 2, roundConfiguration.getResourceDepth() / 2)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |