[virtualcommons-svn] SF.net SVN: virtualcommons:[388] foraging/branches/deepak-branch-fall-09/ src/
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-12-01 23:22:28
|
Revision: 388 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=388&view=rev Author: alllee Date: 2009-12-01 23:22:11 +0000 (Tue, 01 Dec 2009) Log Message: ----------- minor refactoring Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SubjectView.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/event/NewClientRole.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/server/ForagingServer.java foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round0.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round4.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round5.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round6.xml foraging/branches/deepak-branch-fall-09/src/main/resources/configuration/asu-experiments/voting-regulation-enforcement/round7.xml Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ClientDataModel.java 2009-12-01 23:22:11 UTC (rev 388) @@ -42,7 +42,7 @@ private int role; - private static final int MONITER = 0; + private static final int MONITOR = 0; private static final int HARVEST = 1; private static final int SANCTION = 2; private static final int HARVESTANDSANCTION = 3; @@ -90,7 +90,7 @@ } return result;*/ - if(getMyRole() == MONITER || getMyRole() == SANCTION || getMyRole() == HARVESTANDSANCTION)return true; + if(getMyRole() == MONITOR || getMyRole() == SANCTION || getMyRole() == HARVESTANDSANCTION)return true; else return false; } @@ -100,6 +100,19 @@ else return false; } + public boolean isMonitor() { + return role == MONITOR; + } + + public boolean canHarvest() { + return role == HARVEST || role == HARVESTANDSANCTION; + } + + public boolean canSanction() { + return role == SANCTION || role == HARVESTANDSANCTION || role == MONITOR; + + } + /* * public Map<Identifier, Duration> getSanctioned() { return sanctioned; } */ Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java 2009-12-01 23:22:11 UTC (rev 388) @@ -123,7 +123,7 @@ private JButton sendMyVotes; private JPanel instructionsPanel; private Timer timer; - private SixChoicePanel newPanel[]; + private SixChoicePanel[] newPanel; private int noOfEnforcements; Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java 2009-12-01 23:22:11 UTC (rev 388) @@ -8,6 +8,7 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; import edu.asu.commons.client.BaseClient; import edu.asu.commons.event.ClientMessageEvent; @@ -440,6 +441,13 @@ public void run() { //System.out.println("inside client"); //Dimension defaultDimension = new Dimension(600, 600); + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch(Exception e) { + e.printStackTrace(); + System.err.println("Couldn't set native look and feel: "+ e); + } Dimension defaultDimension = new Dimension(600, 600); JFrame frame = new JFrame(); ForagingClient client = new ForagingClient(new ServerConfiguration(), defaultDimension); @@ -449,6 +457,7 @@ frame.add(client.panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); + } }; SwingUtilities.invokeLater(createGuiRunnable); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-01 23:22:11 UTC (rev 388) @@ -79,41 +79,41 @@ private final ClientDataModel dataModel; // instructions components. - + private Component currentCenterComponent; - + private JScrollPane instructionsScrollPane; private HtmlEditorPane instructionsEditorPane; - + private JPanel messagePanel; private JScrollPane errorMessageScrollPane; private JTextPane errorMessageTextPane; private JScrollPane regulationVotingIntructionsScrollPane; private JPanel regulationVotingPane; - + private JPanel labelPanel; - + public static Duration duration; - + private RegulationData votedRegulation; - + private EnforcementData votedEnforcement; - + private ChatPanel chatPanel; - + public static String roleDescription [] = { - "Moniter: You cannot harvest but can sanction other participants\n" + - "To sanction press numbers from 1-5. At the end of the round you\n" + - "will receive 25% tokens from every other participant", - "Harvest: You can collect tokens as in earlier rounds. But you \n" + - "cannot sanction", - "Sanction: You cannot harvest but only sanction \n", - "Harvest and Sanction: You can collect tokens and at the same & \n" + - "at the same time sanction other participants"}; - + "Moniter: You cannot harvest but can sanction other participants\n" + + "To sanction press numbers from 1-5. At the end of the round you\n" + + "will receive 25% tokens from every other participant", + "Harvest: You can collect tokens as in earlier rounds. But you \n" + + "cannot sanction", + "Sanction: You cannot harvest but only sanction \n", + "Harvest and Sanction: You can collect tokens and at the same & \n" + + "at the same time sanction other participants"}; + private SanctioningPanel sanctioningPanel; - + private EnforcementPanel enforcementPanel; private JLabel informationLabel; @@ -121,25 +121,25 @@ private JLabel timeLeftLabel; private JPanel subjectWindow; - + private JEditorPane regulationVotingIntructions; private ForagingClient client; - + private SubjectView subjectView; public Timer timer; - + public static final Object regulationSignal = new Object(); - + public static final Object enforcementVotesSignal = new Object(); - + public static final Object regulationVotesSignal = new Object(); - + public static final Object clientRoleSignal = new Object(); private final StringBuilder instructionsBuilder = new StringBuilder(); - + private EventChannel channel; private Map<Identifier, RegulationData> regulations; @@ -158,7 +158,7 @@ Dimension subjectViewSize = new Dimension((int) Math.floor(size.getWidth()), (int) Math.floor(size.getHeight() * 0.85)); subjectView = new SubjectView(subjectViewSize, dataModel); -// subjectView.addKeyListener(this); + // subjectView.addKeyListener(this); initGuiComponents(); } @@ -181,7 +181,7 @@ } - + /** * In certain cases, init() _can_ be called before endRound() is finished. Need to lock * access! @@ -194,22 +194,22 @@ } // don't display next round time, instead wait for the // facilitator signal. - + timeLeftLabel.setText("Waiting for facilitator's signal."); informationLabel.setText("Waiting for facilitator's signal."); // add the next round instructions to the existing debriefing text set by the previous // EndRoundEvent. } - - - + + + private ActionListener createQuizListener(final RoundConfiguration configuration) { return new ActionListener() { public void actionPerformed(ActionEvent e) { // System.err.println("In action performed with event: " + e); HtmlEditorPane.FormActionEvent formEvent = (HtmlEditorPane.FormActionEvent) e; Properties actualAnswers = formEvent.getData(); -// actualAnswers.list(System.err); + // actualAnswers.list(System.err); List<String> incorrectAnswers = new ArrayList<String>(); // iterate through expected answers for (Map.Entry<String, String> entry : configuration.getQuizAnswers().entrySet()) { @@ -245,25 +245,25 @@ public void collectToken(Point position) { subjectView.collectToken(position); } - + private void startEnforcementDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(15); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(10); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Round begins now."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; remove(enforcementPanel); - // System.out.println("Enforcement Panel removed : New Pane added"); + // System.out.println("Enforcement Panel removed : New Pane added"); addCenterComponent(instructionsScrollPane); - + } else { timeLeftLabel.setText( String.format("Voting for the enforcement mechanism will start in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -271,25 +271,25 @@ } }); timer.start(); - } + } } - + private void startRegulationDisplayTimer(){ - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(15); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(15); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Enforcement Voting begins now."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; //remove(sanctioningPanel); - // System.out.println("New Pane added"); + // System.out.println("New Pane added"); initializeEnforcementVotingPanel(); } else { @@ -298,43 +298,43 @@ } }); timer.start(); - } + } } - + private void startEnforcementVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(30); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; //remove(sanctioningPanel); getEnforcementPanel().stopTimer(); getEnforcementPanel().sendEnforcementVotes(); //displayEnforcementWaitMessage(); - + System.out.println("Enforcement voting sent"); Utils.waitOn(enforcementVotesSignal); - + System.out.println("Voted enforcement received"); - + //Utils.waitOn(clientRoleSignal); - - // System.out.println("Client Role received"); - + + // System.out.println("Client Role received"); + votedEnforcement = getEnforcementPanel().getVotedEnforcement(); - + displayVotedEnforcement(); - - // System.out.println("New Pane added"); + + // System.out.println("New Pane added"); } else { timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -342,23 +342,23 @@ } }); timer.start(); - } + } } - + private void startRegulationVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(30); + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + duration = Duration.create(30); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); - + //new code //Need to add the enforcementVotingPane over here //instead of the instructionsScrollPane - timer.stop(); + timer.stop(); timer = null; //remove(sanctioningPanel); getSanctioningPanel().stopTimer(); @@ -367,10 +367,10 @@ //displayRegulationWaitMessage(); Utils.waitOn(regulationVotesSignal); System.out.println("Voted regulation received"); - + votedRegulation = getSanctioningPanel().getVotedRegulation(); displayVotedRegulation(); - + //System.out.println("New Pane added"); } else { @@ -379,17 +379,17 @@ } }); timer.start(); - } + } } - - private void startSanctioningTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - final Duration duration = Duration.create(30); + + private void startRegulationSubmissionTimer() { + if (timer == null) { + //FIXME: Need to fetch this value from the round4.xml + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { - timeLeftLabel.setText("Your time to write the regualtion is finished. Next round begins shortly."); + timeLeftLabel.setText("Your time to write the regulation is finished. Next round begins shortly."); //new code //FIXME: //Need to add the regulationVotingPane over here @@ -398,7 +398,7 @@ //client.transmit(); //addCenterComponent(instructionsScrollPane); //addCenterComponent(regulationVotingPane); - timer.stop(); + timer.stop(); timer = null; getSanctioningPanel().sendRegulation(); Utils.waitOn(regulationSignal); @@ -410,24 +410,23 @@ } }); timer.start(); - } + } } private void startChatTimer() { - if (timer == null) { - // final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); - final Duration duration = Duration.create(30); + if (timer == null) { + final Duration duration = Duration.create(dataModel.getRoundConfiguration().getChatDuration()); timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { if (duration.hasExpired()) { timeLeftLabel.setText("Chat is now disabled. Next round begins shortly."); - + //new code //Need to add the regulationVotingPane over here //instead of the instructionsScrollPane //addCenterComponent(instructionsScrollPane); - timer.stop(); + timer.stop(); timer = null; - + initializeSanctioningPanel(); } @@ -437,7 +436,7 @@ } }); timer.start(); - } + } } private String getInformationLabelText() { @@ -470,7 +469,7 @@ long secondsLeft = roundTimeLeft / 1000L; return "Time left: " + secondsLeft + " second(s)"; } - + private void setInstructions(String s) { instructionsEditorPane.setText(s); instructionsEditorPane.setCaretPosition(0); @@ -482,7 +481,7 @@ private HtmlEditorPane createInstructionsEditorPane() { // JEditorPane pane = new JEditorPane("text/html", - // "Costly Sanctioning Experiment"); + // "Costly Sanctioning Experiment"); final HtmlEditorPane htmlPane = new HtmlEditorPane(); htmlPane.setPreferredSize(new Dimension(400, 400)); htmlPane.setEditable(false); @@ -491,30 +490,30 @@ } public static void setNativeLookAndFeel() { try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { - // System.out.println("Error setting native LAF: " + e); + // System.out.println("Error setting native LAF: " + e); } - } + } private SanctioningPanel updateRegulationVotingPanel(){ - // System.out.println("Inside update regulation"); - - SanctioningPanel sanctioningPanel = getSanctioningPanel(); + // System.out.println("Inside update regulation"); + + SanctioningPanel sanctioningPanel = getSanctioningPanel(); sanctioningPanel.initRegulationVotingCompontents(); regulations = getSanctioningPanel().getAllRegulations(); - // System.out.println("Fetched all the regulations from the server : "+regulations.size()); - // setNativeLookAndFeel(); - //regulationVotingPane.add(votingArea, BorderLayout.SOUTH); + // System.out.println("Fetched all the regulations from the server : "+regulations.size()); + // setNativeLookAndFeel(); + //regulationVotingPane.add(votingArea, BorderLayout.SOUTH); //regulationVotingPane.add(regulationVotingIntructionsScrollPane,BorderLayout.NORTH); return sanctioningPanel; } - + private void initGuiComponents() { // FIXME: replace with CardLayout for easier switching between panels -// cardLayout = new CardLayout(); - + // cardLayout = new CardLayout(); + setLayout(new BorderLayout(4, 4)); instructionsEditorPane = createInstructionsEditorPane(); instructionsScrollPane = new JScrollPane(instructionsEditorPane); @@ -532,9 +531,9 @@ // latencyLabel = new JLabel("Latency: 0"); informationLabel.setBackground(Color.YELLOW); informationLabel.setForeground(Color.BLUE); - -// getSanctioningPanel().initializeVotingPaneWithRegulations(); - + + // getSanctioningPanel().initializeVotingPaneWithRegulations(); + regulationVotingPane = new JPanel(); //regulationVotingPane.setLayout(new BoxLayout(regulationVotingPane, BoxLayout.LINE_AXIS)); regulationVotingPane.setLayout(new BorderLayout(4,4)); @@ -553,16 +552,16 @@ labelPanel.add(Box.createHorizontalGlue()); labelPanel.add(informationLabel); add(labelPanel, BorderLayout.NORTH); - + // add message window. messagePanel = new JPanel(new BorderLayout()); -// messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS)); + // messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS)); messagePanel.add(new JLabel("System Messages"), BorderLayout.NORTH); errorMessageTextPane = new JTextPane(); errorMessageTextPane.setEditable(false); errorMessageTextPane.setFont(new Font("arial", Font.BOLD, 12)); - + addStyles(errorMessageTextPane.getStyledDocument()); errorMessageScrollPane = new JScrollPane(errorMessageTextPane); Dimension scrollPaneSize = new Dimension(getPreferredSize().width, 50); @@ -571,15 +570,15 @@ errorMessageScrollPane.setMaximumSize(scrollPaneSize); messagePanel.add(errorMessageScrollPane, BorderLayout.CENTER); add(messagePanel, BorderLayout.SOUTH); - - + + addKeyListener( createGameWindowKeyListener() ); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { requestFocusInWindow(); } }); - + addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent event) { Component component = event.getComponent(); @@ -592,7 +591,7 @@ }); // add component listeners, chat panel, and sanctioning window IF chat/sanctioning are enabled, and after the end of the round... } - + /** * IMPORTANT: this method handles client keyboard inputs within the game. * @return @@ -619,23 +618,23 @@ switch (keyCode) { // token request handling case KeyEvent.VK_SPACE: - if(client.isHarvestingAllowed()) { - event = new CollectTokenRequest(client.getId()); - } - else - displayErrorMessage("You are either a Moniter or Sanctioner : You cannot harvest ", 1); - + if(client.isHarvestingAllowed()) { + event = new CollectTokenRequest(client.getId()); + } + else + displayErrorMessage("You are either a Moniter or Sanctioner : You cannot harvest ", 1); + break; // real-time sanctioning keycode handling case KeyEvent.VK_1: case KeyEvent.VK_2: case KeyEvent.VK_3: case KeyEvent.VK_4: case KeyEvent.VK_5: case KeyEvent.VK_6: case KeyEvent.VK_7: case KeyEvent.VK_8: case KeyEvent.VK_9: - // System.out.println("Key pressed : "+(keyChar-48)); - if(dataModel.getRoundConfiguration().isChatEnabled() == false) { - return; - } + // System.out.println("Key pressed : "+(keyChar-48)); + if(dataModel.getRoundConfiguration().isChatEnabled() == false) { + return; + } if (client.isSanctioningAllowed() && client.canPerformRealTimeSanction(getEnforcementPanel().getVotedEnforcement())) { - //System.out.println("Can do sanctioning"); + //System.out.println("Can do sanctioning"); int assignedNumber = keyChar - 48; Identifier sanctionee = dataModel.getClientId(assignedNumber); if (sanctionee == null || sanctionee.equals(dataModel.getId())) { @@ -645,21 +644,21 @@ // only allow sanctions for subjects within this subject's field of vision Point subjectPosition = dataModel.getClientDataMap().get(sanctionee).getPoint(); if (dataModel.getClientData().isSubjectInFieldOfVision(subjectPosition)) { - // System.out.println("sanctioning event sent"); + // System.out.println("sanctioning event sent"); event = new RealTimeSanctionRequest(dataModel.getId(), sanctionee); // below function must be used for enforcement type4 dataModel.sanction(dataModel.getId(), sanctionee); } else{ - displayErrorMessage("Sanctionee is out of range ", 1); - } + displayErrorMessage("Sanctionee is out of range ", 1); + } } else { - if(client.isSanctioningAllowed()==false){ - displayErrorMessage("You don't have the privilege to sanction",1); - } - return; + if(client.isSanctioningAllowed()==false){ + displayErrorMessage("You don't have the privilege to sanction",1); + } + return; } break; // reset token distribution request handling @@ -687,11 +686,11 @@ dataModel.getClientData().setPosition(newPosition); subjectView.repaint(); } - */ + */ } if (keyReleased) { // FIXME: have client directly render these requests? Would - // make the app more "responsive" and less tied to server latency. + // make the app more "responsive" and less tied to server latency. channel.handle(event); keyReleased = false; } @@ -699,7 +698,7 @@ }; } - + private boolean canResetTokenDistribution() { RoundConfiguration configuration = dataModel.getRoundConfiguration(); return configuration.isPracticeRound() && configuration.isPrivateProperty(); @@ -711,19 +710,19 @@ remove(currentCenterComponent); add(newCenterComponent, BorderLayout.CENTER); newCenterComponent.setVisible(true); - revalidate(); } currentCenterComponent = newCenterComponent; - // currentCenterComponent.repaint(); + revalidate(); + // currentCenterComponent.repaint(); } public void startRound() { final RoundConfiguration configuration = dataModel.getRoundConfiguration(); - if (timer != null) { - timer.stop(); - timer = null; - } - + if (timer != null) { + timer.stop(); + timer = null; + } + // currentExperimentConfiguration = configuration; Runnable runnable = new Runnable() { public void run() { @@ -735,22 +734,22 @@ // has begun. update(configuration.getRoundDuration().getTimeLeft()); if(configuration.isChatEnabled()){ - displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); + displayErrorMessage(roleDescription[client.getDataModel().getMyRole()], 1); } add(messagePanel, BorderLayout.SOUTH); - + addCenterComponent(subjectWindow); requestFocusInWindow(); } }; SwingUtilities.invokeLater(runnable); } - + public void displayErrorMessage(String errorMessage, int par) { // String chatHandle = getChatHandle(source); - if(par==1)errorMessageTextPane.setForeground(Color.RED); - else errorMessageTextPane.setForeground(Color.BLACK); - + if(par==1)errorMessageTextPane.setForeground(Color.RED); + else errorMessageTextPane.setForeground(Color.BLACK); + StyledDocument document = errorMessageTextPane.getStyledDocument(); try { document.insertString(document.getLength(), errorMessage + "\n", document.getStyle("bold")); @@ -761,7 +760,7 @@ throw new RuntimeException(e); } } - + // FIXME: add to some common GUI package? private void addStyles(StyledDocument styledDocument) { // and why not have something like... StyleContext.getDefaultStyle() to @@ -776,26 +775,26 @@ StyleConstants.setItalic(styledDocument .addStyle("italic", defaultStyle), true); } - - + + private double getIncome(float numTokens) { if (dataModel.getRoundConfiguration().isPracticeRound()) { return 0.0f; } return dataModel.getRoundConfiguration().getDollarsPerToken() * numTokens; } - + private void addDebriefingText(EndRoundEvent event) { instructionsBuilder.delete(0, instructionsBuilder.length()); instructionsBuilder.append( String.format("<h3>Your stats in this round:</h3>" + - "<ul>" + - "<li>Tokens collected: %d</li>" + - "<li>Income: $%3.2f</li>" + + "<ul>" + + "<li>Tokens collected: %d</li>" + + "<li>Income: $%3.2f</li>" + "</ul>", event.getCurrentTokens(), getIncome(event.getCurrentTokens())) - ); + ); double showUpFee = dataModel.getRoundConfiguration().getParentConfiguration().getShowUpFee(); instructionsBuilder.append(String.format("Your <b>total income</b> so far (including a $%3.2f bonus for showing up) is : $%3.2f<hr>", showUpFee, dataModel.getTotalIncome() + showUpFee)); @@ -805,7 +804,7 @@ } setInstructions(instructionsBuilder.toString()); } - + private void postSanctionDebriefingText(final PostRoundSanctionUpdateEvent event) { instructionsBuilder.delete(0, instructionsBuilder.length()); ClientData clientData = event.getClientData(); @@ -825,7 +824,7 @@ clientData.getSanctionCosts(), clientData.getCurrentTokens(), getIncome(clientData.getCurrentTokens())) - ); + ); instructionsBuilder.append(String.format("Your <b>total income</b> so far is: $%3.2f<hr>", getIncome(clientData.getTotalTokens()))); if (event.isLastRound()) { @@ -834,25 +833,25 @@ setInstructions(instructionsBuilder.toString()); } - + private ChatPanel getChatPanel() { if (chatPanel == null) { - //System.out.println("Chat panel is null"); + //System.out.println("Chat panel is null"); chatPanel = new ChatPanel(client); } return chatPanel; } private SanctioningPanel getSanctioningPanel() { if (sanctioningPanel == null) { - //System.out.println("Sanc panel is null"); - sanctioningPanel = new SanctioningPanel(client); + //System.out.println("Sanc panel is null"); + sanctioningPanel = new SanctioningPanel(client); } return sanctioningPanel; } private EnforcementPanel getEnforcementPanel() { if (enforcementPanel == null) { - //System.out.println("enf panel is null"); - enforcementPanel = new EnforcementPanel(client); + //System.out.println("enf panel is null"); + enforcementPanel = new EnforcementPanel(client); } return enforcementPanel; } @@ -876,65 +875,65 @@ instructionsEditorPane.setText("<b>Please wait while we compute your new token totals.</b>"); addCenterComponent(instructionsScrollPane); } - + public void displayVotedEnforcement(){ - //new code - // System.out.println("*****Inside display voting enforcement"); + //new code + // System.out.println("*****Inside display voting enforcement"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below enforcement has been voted from the voting conducting earlier<br><br>" + - "<b>"+getEnforcementPanel().getVotedEnforcementOptions(votedEnforcement.getResultIndex())+ - "</b><br><br>This is your role for the next round <br><br><b>"+roleDescription[client.getDataModel().getMyRole()]+"</b>"); + instructionsEditorPane.setText("Below enforcement has been voted from the voting conducting earlier<br><br>" + + "<b>"+getEnforcementPanel().getVotedEnforcementOptions(votedEnforcement.getResultIndex())+ + "</b><br><br>This is your role for the next round <br><br><b>"+roleDescription[client.getDataModel().getMyRole()]+"</b>"); remove(enforcementPanel); addCenterComponent(instructionsScrollPane); startEnforcementDisplayTimer(); } }); } - + public void displayRegulationWaitMessage(){ - //new code - // System.out.println("*****Inside reg wait mesg"); + //new code + // System.out.println("*****Inside reg wait mesg"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Message from the System:<br><br>" + - "<b>Please wait until the System receives votes from all players.System<br>"+ - "will calculate the result of the voting and display it in a moment</b>"); - remove(sanctioningPanel); + instructionsEditorPane.setText("Message from the System:<br><br>" + + "<b>Please wait until the System receives votes from all players.System<br>"+ + "will calculate the result of the voting and display it in a moment</b>"); + remove(sanctioningPanel); addCenterComponent(instructionsScrollPane); } }); } - + public void displayEnforcementWaitMessage(){ - //new code + //new code System.out.println("*****Inside enfr wait message"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Message from the System:<br><br>" + - "<b>Please wait until the System receives votes from all players.System<br>"+ - "will calculate the result of the voting and display it in a moment</b>"); - remove(enforcementPanel); + instructionsEditorPane.setText("Message from the System:<br><br>" + + "<b>Please wait until the System receives votes from all players.System<br>"+ + "will calculate the result of the voting and display it in a moment</b>"); + remove(enforcementPanel); addCenterComponent(instructionsScrollPane); } }); } - - + + public void displayVotedRegulation(){ - //new code - // System.out.println("*****Inside display voting regulation"); + //new code + // System.out.println("*****Inside display voting regulation"); SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getRegulationText()+".</b>"); + instructionsEditorPane.setText("Below regulation has been voted from the voting conducting earlier.<br><br><br><br><b>"+votedRegulation.getRegulationText()+".</b>"); remove(sanctioningPanel); addCenterComponent(instructionsScrollPane); startRegulationDisplayTimer(); } }); } - + public void updateDebriefing(final PostRoundSanctionUpdateEvent event) { Runnable runnable = new Runnable() { public void run() { @@ -945,20 +944,20 @@ }; SwingUtilities.invokeLater(runnable); } - + public void resetPanels() { - //System.out.println("Reseting the panels"); - if(sanctioningPanel != null) - sanctioningPanel.resetHandles(); - if(enforcementPanel != null) - enforcementPanel.resetHandles(); - - sanctioningPanel = null; - enforcementPanel = null; - // chatPanel = null; + //System.out.println("Reseting the panels"); + // if(sanctioningPanel != null) + // sanctioningPanel.resetHandles(); + // if(enforcementPanel != null) + // enforcementPanel.resetHandles(); + + sanctioningPanel = null; + enforcementPanel = null; + // chatPanel = null; } - + public void endRound(final EndRoundEvent event) { Runnable runnable = new Runnable() { public void run() { @@ -986,11 +985,11 @@ } public void initializeEnforcementVotingPanel() { - //new code - // System.out.println("*****Inside initialize enforcement()"); + //new code + // System.out.println("*****Inside initialize enforcement()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code + //new code System.out.println("*****Inside thread initialize sanctioningPanel()"); EnforcementPanel enforcementPanel = getEnforcementPanel(); enforcementPanel.initialize(); @@ -1002,13 +1001,13 @@ }); } - + public void initializeRegulationVotingPanel() { - //new code - // System.out.println("*****Inside initialize regulation votingPanel()"); + //new code + // System.out.println("*****Inside initialize regulation votingPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code + //new code //System.out.println("*****Inside thread initialize votingPanel()"); remove(sanctioningPanel); SanctioningPanel sanctioningPanel = updateRegulationVotingPanel(); @@ -1018,32 +1017,31 @@ } }); } - + public void initializeSanctioningPanel() { - //new code - // System.out.println("*****Inside initialize sanctioningPanel()"); + //new code + // System.out.println("*****Inside initialize sanctioningPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code - // System.out.println("*****Inside thread initialize sanctioningPanel()"); + //new code + // System.out.println("*****Inside thread initialize sanctioningPanel()"); SanctioningPanel sanctioningPanel = getSanctioningPanel(); sanctioningPanel.initialize(); - // System.out.println("Initialization done"); + // System.out.println("Initialization done"); //remove( messagePanel ); - remove(chatPanel); addCenterComponent( sanctioningPanel ); - startSanctioningTimer(); + startRegulationSubmissionTimer(); } }); } public void initializeChatPanel() { - //new code - // System.out.println("*****Inside initialize chatPanel()"); + //new code + // System.out.println("*****Inside initialize chatPanel()"); SwingUtilities.invokeLater(new Runnable() { public void run() { - //new code - // System.out.println("*****Inside thread initialize chatPanel()"); + //new code + // System.out.println("*****Inside thread initialize chatPanel()"); ChatPanel chatPanel = getChatPanel(); chatPanel.initialize(); remove( messagePanel ); Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GridView.java 2009-12-01 23:22:11 UTC (rev 388) @@ -31,9 +31,10 @@ * If the parameters call for a background, this object is created so that * the scaling calculation does not have to be performed for each paint. */ - protected Image tokenImage, otherSubjectImage, selfImage, selfExplicitCollectionModeImage, beingSanctionedImage, sanctioningImage; + protected Image tokenImage, otherSubjectImage, selfImage, selfExplicitCollectionModeImage, beingSanctionedImage, sanctioningImage, monitorImage; - protected Image scaledTokenImage, scaledOtherSubjectImage, scaledSelfImage, scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage; + protected Image scaledTokenImage, scaledOtherSubjectImage, scaledSelfImage, + scaledSelfExplicitCollectionModeImage, scaledBeingSanctionedImage, scaledSanctioningImage, scaledMonitorImage; /** * Use these for the dimensions when drawing. @@ -92,6 +93,7 @@ scaledSelfExplicitCollectionModeImage = selfExplicitCollectionModeImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledBeingSanctionedImage = beingSanctionedImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); scaledSanctioningImage = sanctioningImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); + scaledMonitorImage = monitorImage.getScaledInstance(cellWidth, cellHeight, IMAGE_SCALING_STRATEGY); } /** @@ -142,6 +144,10 @@ if (sanctioningImage == null) { sanctioningImage = loadImage("images/gem-purple.gif"); } + // FIXME: generate a new image for the monitor, for now just use the explicit-mode image. + if (monitorImage == null) { + monitorImage = loadImage("images/gem-self-explicit.gif"); + } } private Image loadImage(String path) { Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-01 22:28:49 UTC (rev 387) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-01 23:22:11 UTC (rev 388) @@ -9,8 +9,6 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -26,8 +24,6 @@ import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.Timer; -import javax.swing.UIManager; -import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; @@ -57,61 +53,55 @@ public class SanctioningPanel extends JPanel { private ForagingClient client; - + private Map<Identifier, RegulationData> regulations; - + public SanctioningPanel (ForagingClient client) { this.client = client; this.clientId = client.getId(); client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { public void handle(final RegulationEvent regulationEvent) { - boolean votingFlag=false; - RegulationData regulationData = null; - regulations = regulationEvent.getAllRegulations(); - // System.out.println("Regulation received : "+regulations.size()); - noOfRegulations = regulations.size(); + boolean votingFlag=false; + RegulationData regulationData = null; + regulations = regulationEvent.getAllRegulations(); + // System.out.println("Regulation received : "+regulations.size()); + noOfRegulations = regulations.size(); for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - if(regulationData.isVoting())votingFlag = true; - break; + regulationData = regulations.get(targetId); + if(regulationData.isVoting())votingFlag = true; + break; } if(votingFlag) { - votedRegulation = regulationData; - Utils.notify(GameWindow2D.regulationVotesSignal); + votedRegulation = regulationData; + Utils.notify(GameWindow2D.regulationVotesSignal); } else { - //System.out.println("Finding my ID"); - findAndSetMyRegulationID(); - Utils.notify(GameWindow2D.regulationSignal); + //System.out.println("Finding my ID"); + findAndSetMyRegulationID(); + Utils.notify(GameWindow2D.regulationSignal); } } }); } public static int currentActive; - + public static int currentLabel; - - public static String regulationString = new String(""); - - private Identifier targetIdentifier = Identifier.ALL; - - private final static String HANDLE_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - private static String[] HANDLES; + public static String regulationString = ""; + private Identifier clientId; - + private String message; - + private RegulationData votedRegulation; private int noOfRegulations; - + private int currentRankingInformation[]; - + private Timer timer; private SixChoicePanel newPanel[]; @@ -126,41 +116,37 @@ private String[] votes = { "1", "2", "3","4", "5"}; private JScrollPane messageScrollPane; - + private JScrollPane regulationsInstructionsScrollPane; private JTextPane messageWindow; private List<Identifier> participants; - + private JEditorPane regulationsInstructionsPane; - public Map<Identifier, RegulationData> getAllRegulations() { - return regulations; - } - + public Map<Identifier, RegulationData> getAllRegulations() { + return regulations; + } + private void findAndSetMyRegulationID() { for (Identifier targetId : regulations.keySet()) { - if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ - client.setRegulationID(regulations.get(targetId).getRegulationID()); - //client.setEnforcementID(regulations.get(targetId).getToken()); - client.setToken(regulations.get(targetId).getToken()); - //System.out.println("My RegID:"+client.getRegulationID()); - //System.out.println("Token:"+client.getEnforcementID()); - return; - } + if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ + client.setRegulationID(regulations.get(targetId).getRegulationID()); + //client.setEnforcementID(regulations.get(targetId).getToken()); + client.setToken(regulations.get(targetId).getToken()); + //System.out.println("My RegID:"+client.getRegulationID()); + //System.out.println("Token:"+client.getEnforcementID()); + return; + } } } - - public void resetHandles() { - HANDLES = null; - } - + public RegulationData getVotedRegulation(){ - return this.votedRegulation; + return this.votedRegulation; } - + private void addStylesToMessageWindow() { StyledDocument styledDocument = messageWindow.getStyledDocument(); // and why not have something like... StyleContext.getDefaultStyle() to @@ -175,195 +161,174 @@ StyleConstants.setItalic(styledDocument .addStyle("italic", defaultStyle), true); } - + private void updateInstructionPanel(){ - // System.out.println("RegulationString:"+regulationString); + // System.out.println("RegulationString:"+regulationString); - if(regulationString.equals("")) - regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); - else - regulationsInstructionsPane.setText(regulationString); - - invalidate(); - validate(); + if(regulationString.equals("")) + regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); + else + regulationsInstructionsPane.setText(regulationString); + + revalidate(); instructionsPanel.repaint(); repaint(); - //pack(); - // setVisible(true); + //pack(); + // setVisible(true); } - + private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; - SixChoicePanel temp = null; - boolean enableSendButton = true; + int r,c,i,j; + int currentRanking; + SixChoicePanel temp = null; + boolean enableSendButton = true; -// System.out.println("Active panel: "+SixChoicePanel.currentActive); - - for(r = 0; r < noOfRegulations; r++) - { - // System.out.print(newPanel[r].currentRanking+" "); - if(newPanel[r].currentRanking == -1)enableSendButton = false; + // System.out.println("Active panel: "+SixChoicePanel.currentActive); - if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) - { - newPanel[r].currentRanking = -1; - newPanel[r].group.clearSelection(); - } - } - - - for(r = 0; r < noOfRegulations-1; r++) - { - for(c = 0; c < noOfRegulations-1; c++) - { - if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - } - } - for(c = 0; c < noOfRegulations; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } - - votingPanel.setVisible(false); - remove(votingPanel); + for(r = 0; r < noOfRegulations; r++) + { + // System.out.print(newPanel[r].currentRanking+" "); + if(newPanel[r].currentRanking == -1)enableSendButton = false; - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) + { + newPanel[r].currentRanking = -1; + newPanel[r].group.clearSelection(); + } + } - - for(i=0; i < noOfRegulations; i++) { - votingPanel.add(newPanel[i].regulationPanel); - votingPanel.add(newPanel[i].rankPanel); - } - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } - invalidate(); - validate(); - votingPanel.repaint(); - repaint(); + for(r = 0; r < noOfRegulations-1; r++) + { + for(c = 0; c < noOfRegulations-1; c++) + { + if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + } + } + for(c = 0; c < noOfRegulations; c++) + { + // System.out.print(newPanel[c].getCurrentRanking() +" "); + } + + votingPanel.setVisible(false); + remove(votingPanel); + + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + + + for(i=0; i < noOfRegulations; i++) { + votingPanel.add(newPanel[i].regulationPanel); + votingPanel.add(newPanel[i].rankPanel); + } + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); + + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + revalidate(); } - + public void stopTimer(){ - timer.stop(); + timer.stop(); } - + public void startTimer(){ - if (timer == null) { + if (timer == null) { timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } + //timer.stop(); + //timer = null; + // System.out.println("Timer called to update the voting panel:"); + updateVotingPanel(); + updateInstructionPanel(); + } }); timer.start(); - } + } } public void sendRegulation() { - System.out.println("Regulation sent"); + System.out.println("Regulation sent"); message = messageWindow.getText(); // System.err.println("message: " + message); - + RegulationData regulationData = new RegulationData(); regulationData.setRegulationText(message); regulationData.setVotingFlag(false); //FIXME:All the clients have to send some regulation - if (message == null || "".equals(message) || targetIdentifier == null) { - return; - } + // i... [truncated message content] |