[virtualcommons-svn] SF.net SVN: virtualcommons:[400] foraging/branches/deepak-branch-fall-09/ src
Status: Beta
Brought to you by:
alllee
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] |