[virtualcommons-svn] commit/foraging: 2 new changesets
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-08-02 23:09:01
|
2 new changesets in foraging: http://bitbucket.org/virtualcommons/foraging/changeset/5eb26ee59de2/ changeset: 5eb26ee59de2 user: alllee date: 2011-08-03 00:15:38 summary: fixing field of vision offsets via hacky trial & error affected #: 5 files (501 bytes) --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Aug 02 15:15:38 2011 -0700 @@ -0,0 +1,11 @@ +syntax:glob + +*~ +target +*.jar +experiment-data/* +build.properties +*.log +*.log.lck +.classpath +.project --- a/pom.xml Tue Aug 02 13:19:15 2011 -0700 +++ b/pom.xml Tue Aug 02 15:15:38 2011 -0700 @@ -114,6 +114,7 @@ </plugin><plugin><artifactId>maven-compiler-plugin</artifactId> + <version>2.3.2</version><configuration><source>1.6</source><target>1.6</target> --- a/src/main/java/edu/asu/commons/foraging/client/GridView.java Tue Aug 02 13:19:15 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GridView.java Tue Aug 02 15:15:38 2011 -0700 @@ -73,11 +73,15 @@ dw = (availableWidth / boardSize.getWidth()); dh = (availableHeight / boardSize.getHeight()); // ensure square proportions - dw = Math.floor(Math.min(dw, dh)); - dh = dw; + dh = dw = Math.min(dw, dh); +// dh = dw; xoffset = (int) Math.floor((availableWidth - (dw * boardSize.getWidth())) / 2); yoffset = (int) Math.floor((availableHeight - (dh * boardSize.getHeight())) / 2); +// System.err.println("x offset: " + xoffset); +// System.err.println("y offset: " + yoffset); +// System.err.println("dw : " + dw); +// System.err.println("dh: " + dh); fontSize = (int)(0.85 * dh); font = new Font("sansserif", Font.BOLD, fontSize); @@ -165,6 +169,7 @@ // this super call to let the UI delegate some paintage as well. // super.paintComponent(graphics); Graphics2D graphics2D = (Graphics2D) graphics; +// graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // FIXME: can be made more efficient. // Could just update the parts that have changed (tokens removed, subjects moved) // paint the background @@ -182,8 +187,8 @@ protected void paintCollection(Collection<Point> collection, Graphics2D graphics2D, Image image, ImageObserver observer) { synchronized (collection) { for (Point point: collection) { - int x = scaleX(point.getX()); - int y = scaleY(point.getY()); + int x = scaleX(point.x); + int y = scaleY(point.y); graphics2D.drawImage(image, x, y, observer); } } @@ -193,8 +198,8 @@ synchronized (collection) { for (Point point: collection) { if (fieldOfView.contains(point)) { - int x = scaleX(point.getX()); - int y = scaleY(point.getY()); + int x = scaleX(point.x); + int y = scaleY(point.y); graphics2D.drawImage(image, x, y, observer); } } @@ -208,22 +213,22 @@ return (int) dh; } - // FIXME: both scaleX and scaleY are called quite often in the course of - // running, should see if we can optimize them further. + // FIXME: profiling shows that both scaleX and scaleY are called a lot at runtime, + // should see if we can optimize them further. protected int scaleX(int x) { return (int) ((dw * x) + xoffset); } - protected int scaleX(double x) { - return (int) ((dw * x) + xoffset); + protected double scaleXDouble(double x) { + return ((dw * x) + xoffset); } protected int scaleY(int y) { return (int) ((dh * y) + yoffset); } - protected int scaleY(double y) { - return (int) ((dh * y) + yoffset); + protected double scaleYDouble(double y) { + return ((dh * y) + yoffset); } --- a/src/main/java/edu/asu/commons/foraging/client/SubjectView.java Tue Aug 02 13:19:15 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/SubjectView.java Tue Aug 02 15:15:38 2011 -0700 @@ -3,7 +3,6 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.FontMetrics; -import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Point; @@ -127,20 +126,20 @@ Point currentPosition = dataModel.getCurrentPosition(); RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); if (roundConfiguration.isSubjectsFieldOfVisionEnabled()) { - double radius = roundConfiguration.getViewSubjectsRadius(); + // paint a transparent circle centered on the current position of the subject. + int radius = roundConfiguration.getViewSubjectsRadius(); fieldOfVision = new Circle(currentPosition, radius); - // paint field of vision - 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); + Point topLeftCorner = new Point(currentPosition.x - radius, currentPosition.y - radius); + double x = scaleXDouble(topLeftCorner.x) + (dw / 3); + double y = scaleYDouble(topLeftCorner.y) + (dh / 3); + double diameter = radius * 2.0d; + diameter = Math.min(scaleXDouble(diameter), scaleYDouble(diameter)) + (dw / 2); + Ellipse2D.Double circle = new Ellipse2D.Double(x, y, diameter, diameter); //graphics2D.fillOval(x, y, diameter, diameter); // clip the rendered part of the Field of vision circle that crosses the playing boundary graphics2D.setClip(circle); + Paint originalPaint = graphics2D.getPaint(); + graphics2D.setPaint(FIELD_OF_VISION_COLOR); graphics2D.fill(circle); graphics2D.setPaint(originalPaint); } --- a/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java Tue Aug 02 13:19:15 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java Tue Aug 02 15:15:38 2011 -0700 @@ -122,7 +122,7 @@ return ( isPracticeRound() && isPrivateProperty() ) || getBooleanProperty("randomize-group", false); } - + /** * Returns the number of seconds that the flashing visualization of * sanctioning should occur. @@ -149,9 +149,9 @@ return getBooleanProperty("subjects-field-of-vision", false); } - public double getViewSubjectsRadius() { + public int getViewSubjectsRadius() { if (isSubjectsFieldOfVisionEnabled()) { - return getDoubleProperty("view-subjects-radius", 6.0d); + return getIntProperty("view-subjects-radius", 6); } throw new UnsupportedOperationException("subject field of vision is not enabled."); } http://bitbucket.org/virtualcommons/foraging/changeset/9c77588de0dd/ changeset: 9c77588de0dd user: alllee date: 2011-08-03 01:08:46 summary: ripping out most of the unused regulation / enforcement mechanism code, will need to reimplement voting again later in a cleaner way. starting to add chat panel logic to GameWindow2D when in round chat is enabled. affected #: 15 files (11.2 KB) --- a/src/main/java/edu/asu/commons/foraging/client/EnforcementPanel.java Tue Aug 02 15:15:38 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,362 +0,0 @@ -package edu.asu.commons.foraging.client; - - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.BorderFactory; -import javax.swing.BoxLayout; -import javax.swing.ButtonGroup; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - -import edu.asu.commons.foraging.event.EnforcementRankingRequest; -import edu.asu.commons.foraging.model.EnforcementMechanism; -import edu.asu.commons.net.Identifier; - -/** - * $Id: EnforcementPanel.java 529 2010-08-17 00:08:01Z alllee $ - * - * Enforcement panel is used to vote enforcement mechanism - * - * @author dbarge - * @version $Revision: 529 $ - */ - -@SuppressWarnings("serial") -public class EnforcementPanel extends JPanel { - - private ForagingClient client; - - - private String[] votes = { "1", "2", "3","4"}; - private EnforcementMechanism[] enforcementOptions = EnforcementMechanism.values(); - // private String[] enforcementOptions = { - // "No Enforcement - Click here for more info ", - // "Everyone sanctions - Click here for more info ", - // "Randomly picked monitering - Click here for more info", - // "Random sanctioning - Click here for more info " - // }; - - private String[] enforcementText = { - "Everybody can harvest. Nobody can subtract tokens<br>" + - "from others<br>", - - "Each participant can reduce the token amount of<br>" + - "another participant by two tokens at a cost of <br>" + - "one by pressing the numeric key that identifies<br>" + - "the other participant.<br>", - - "Randomly one of the participants is selected to<br>" + - "be the monitoring participant. This participant<br>" + - "can not harvest, but can force another particip<br>" + - "ant to pay a token to the monitoring participan<br>" + - "by pressing the responding numeric key. At the <br>" + - "end of the round each participant who could har<br>" + - "vest pays 25% of the earning to the monitoring <br>" + - "participant.<br>", - - "Same as two, but now each participant takes turns<br>" + - "of 48 seconds randomly assigned by the computer.<br>" - }; - - public EnforcementPanel (ForagingClient client) { - this(); - this.client = client; - this.clientId = client.getId(); - } - - private Identifier clientId; - private JPanel votingPanel; -// private JButton reset; -// private JButton sendMyVotes; - private JPanel instructionsPanel; - private SixChoicePanel[] newPanel; - - private int noOfEnforcements = EnforcementMechanism.values().length; - - private int currentRankingInformation[]; - - private JPanel buttonPanel; - - public EnforcementPanel () - { - newPanel = new SixChoicePanel[4]; - } - - public String getVotedEnforcementOptions(int index){ - return this.enforcementText[index]; - } - - private JPanel getInstructionPanel() - { - JPanel instructionPanel = new JPanel(); - - //instructionPanel.setBackground(color); - instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); - instructionPanel.setBorder(BorderFactory.createTitledBorder("Enforcement Instructions")); - - //create Text area and JSCroll pane for it - String instructions = client.getDataModel().getRoundConfiguration().getVotingInstructions(); - - JTextArea instructionText = new JTextArea(instructions,3,50); - instructionText.setWrapStyleWord(true); - JScrollPane scrollForRegulationText = new JScrollPane(instructionText); - instructionPanel.add(scrollForRegulationText); - - return instructionPanel; - - } - - private Color getColor(int i) - { - Color color = null; - if(i==0) color = new Color(153,153,204); - if(i==1) color = new Color(204,153,153); - if(i==2) color = new Color(153,204,102); - if(i==3) color = new Color(204,204,102); - if(i==4) color = new Color(255,255,153); - return color; - } - - // FIXME: this is extremely inefficient, reimplement later - private void updateVotingPanel(int currentActive){ - int r,c,i; - SixChoicePanel temp = null; -// boolean enableSendButton = true; - - - for(r = 0; r < noOfEnforcements; r++) - { - -// if(newPanel[r].currentRanking == -1)enableSendButton = false; - - if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) - { - newPanel[r].currentRanking = -1; - newPanel[r].group.clearSelection(); - } - } - - - for(r = 0; r < noOfEnforcements-1; r++) - { - for(c = 0; c < noOfEnforcements-1; c++) - { - if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - } - } - for(c = 0; c < noOfEnforcements; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } - - votingPanel.setVisible(false); - remove(votingPanel); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - - votingPanel.add(getInstructionPanel()); - - - for(i=0; i < noOfEnforcements; i++) { - votingPanel.add(newPanel[i].enforcementPanel); - } - - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); - -// if(enableSendButton) { -// sendMyVotes.setEnabled(true); -// buttonPanel.setVisible(true); -// add(buttonPanel, BorderLayout.SOUTH); -// } - revalidate(); - } - - private String getVoteString(){ - - StringBuilder sb = new StringBuilder(); - - for(int c = 0; c < noOfEnforcements; c++) - { - sb.append("\nEnforcement "+(newPanel[c].getCurrentRanking()+1)); - } - return(sb.toString()); - } - - public void sendEnforcementVotes() { - int i; - for(i=0; i < noOfEnforcements; i++) { - if(newPanel[i].currentRanking == -1) - this.currentRankingInformation[i] = -1; - else - this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); - } - client.transmit(new EnforcementRankingRequest(clientId, currentRankingInformation)); - } - - public void initGuiComponents(){ - - // remove(enforcementInstructionsScrollPane); - // remove(messageScrollPane); - this.currentRankingInformation = new int[4]; - this.newPanel = new SixChoicePanel[4]; - 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(); - votingPanel.add(instructionsPanel); - - - - - for(int i=0; i<noOfEnforcements; i++) { - - //newPanel[i] = new SixChoicePanel(s, votes, enforcementData.getEnforcementID(), getColor(i)); - //newPanel[i] = new SixChoicePanel(s, votes, client.getEnforcementID(), getColor(i)); - newPanel[i] = new SixChoicePanel(enforcementOptions[i], votes, i, getColor(i)); - votingPanel.add(newPanel[i].getEnforcementPanel(i)); - } - - add(votingPanel, BorderLayout.CENTER); -// reset = new JButton("Reset All Ranks"); -// reset.setAlignmentX(Component.CENTER_ALIGNMENT); -// reset.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent e) { -// for(int i=0; i<noOfEnforcements; i++) { -// for(int j=0; j<noOfEnforcements; j++) { -// newPanel[i].option[j].setEnabled(true); -// newPanel[i].group.clearSelection(); -// newPanel[i].currentRanking = -1; -// } -// } -// } -// }); -// sendMyVotes = new JButton("Send votes"); -// sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); -// sendMyVotes.setEnabled(false); -// sendMyVotes.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent e) { -// -// int n = JOptionPane.showConfirmDialog( -// null, "Are you sure to submit your votes ?"+ -// "\nBelow is order of your voting" + -// getVoteString(), -// "Confirm and send votes", -// JOptionPane.YES_NO_OPTION); -// -// if (n == JOptionPane.YES_OPTION) { -// GameWindow2D.duration.expire(); -// } -// if (n == JOptionPane.NO_OPTION) { -// -// } -// -// } -// }); -// buttonPanel = new JPanel(); -// //buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); -// buttonPanel.setLayout(new GridLayout(1,2)); -// buttonPanel.add(reset); -// buttonPanel.add(sendMyVotes); -// buttonPanel.setVisible(true); -// buttonPanel.repaint(); -// add(buttonPanel, BorderLayout.SOUTH); - } - - public void initialize() { - initGuiComponents(); - } - - private class SixChoicePanel implements ActionListener{ - String title; - String description; - String [] buttonLabels; - int enforcementID; - int currentRanking; - JPanel enforcementPanel; - JPanel rankPanel; - ButtonGroup group; - JRadioButton option []; - Color color; - - - public SixChoicePanel(EnforcementMechanism enforcementMechanism, String[] buttonLabels, int enforcementID, Color color ) { - this.title = enforcementMechanism.getTitle(); - this.description = enforcementMechanism.getDescription(); - this.buttonLabels = buttonLabels; - this.enforcementID = enforcementID; - this.color = color; - this.currentRanking = -1; - this.option = new JRadioButton[4]; - } - public int getCurrentRanking(){ - return enforcementID; - } - - public void actionPerformed(ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - System.out.println("ACTION Choice Selected: " + choice); - System.out.println("Bno: " + buttonNo); - System.out.println("CurrentActive : "+this.enforcementID); - this.currentRanking = buttonNo; - updateVotingPanel(this.enforcementID); - } - - - public JPanel getEnforcementPanel(int i){ - enforcementPanel = new JPanel(); - enforcementPanel.setBackground(color); - enforcementPanel.setLayout(new BoxLayout(enforcementPanel, BoxLayout.Y_AXIS)); - enforcementPanel.setBorder(BorderFactory.createTitledBorder(title)); - - //create Text area and JSCroll pane for it - - JTextArea regulationText = new JTextArea(title,3,50); - regulationText.setText(description); - regulationText.setWrapStyleWord(true); - JScrollPane scrollForRegulationText = new JScrollPane(regulationText); - enforcementPanel.add(scrollForRegulationText); - - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Rank")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length - - for(int j=0; j<length; j++) { - option[j] = new JRadioButton(buttonLabels[j]); - option[j].setActionCommand(buttonLabels[j]); - group.add(option[j]); - option[j].addActionListener(this); - rankPanel.add(option[j]); - } - enforcementPanel.add(rankPanel); - return enforcementPanel; - } - - } - -} --- a/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java Tue Aug 02 15:15:38 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/ForagingClient.java Tue Aug 02 16:08:46 2011 -0700 @@ -25,16 +25,12 @@ import edu.asu.commons.foraging.event.ClientPositionUpdateEvent; import edu.asu.commons.foraging.event.CollectTokenRequest; import edu.asu.commons.foraging.event.EndRoundEvent; -import edu.asu.commons.foraging.event.EnforcementMechanismUpdateEvent; import edu.asu.commons.foraging.event.LockResourceEvent; import edu.asu.commons.foraging.event.PostRoundSanctionRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.RealTimeSanctionRequest; -import edu.asu.commons.foraging.event.RegulationSubmissionUpdateEvent; -import edu.asu.commons.foraging.event.RegulationUpdateEvent; import edu.asu.commons.foraging.event.ResetTokenDistributionRequest; import edu.asu.commons.foraging.event.RoundStartedEvent; -import edu.asu.commons.foraging.event.SanctionUpdateEvent; import edu.asu.commons.foraging.event.ShowInstructionsRequest; import edu.asu.commons.foraging.event.SynchronizeClientEvent; import edu.asu.commons.net.SocketIdentifier; @@ -181,7 +177,6 @@ if (state == ClientState.RUNNING) { dataModel.setGroupDataModel(event.getGroupDataModel()); getGameWindow().endRound(event); - getGameWindow().resetPanels(); if (dataModel.is2dExperiment()) { messageQueue.stop(); } @@ -237,31 +232,31 @@ gameWindow2D.displayMessage(event.toString()); } }); - addEventProcessor(new EventTypeProcessor<EnforcementMechanismUpdateEvent>(EnforcementMechanismUpdateEvent.class) { - public void handle(final EnforcementMechanismUpdateEvent event) { - dataModel.setGroupDataModel(event.getGroupDataModel()); - gameWindow2D.displayActiveEnforcementMechanism(); - } - }); - addEventProcessor(new EventTypeProcessor<RegulationSubmissionUpdateEvent>(RegulationSubmissionUpdateEvent.class) { - public void handle(final RegulationSubmissionUpdateEvent event) { - dataModel.setGroupDataModel(event.getGroupDataModel()); - gameWindow2D.initializeRegulationVotingPanel(); - } - }); - addEventProcessor(new EventTypeProcessor<RegulationUpdateEvent>(RegulationUpdateEvent.class) { - public void handle(final RegulationUpdateEvent event) { - dataModel.setActiveRegulation(event.getRegulationData()); - gameWindow2D.displayActiveRegulation(); - } - }); - - addEventProcessor(new EventTypeProcessor<SanctionUpdateEvent>(SanctionUpdateEvent.class) { - public void handle(final SanctionUpdateEvent event) { - dataModel.setGroupDataModel(event.getGroupDataModel()); - gameWindow2D.displaySanctionMechanism(); - } - }); +// addEventProcessor(new EventTypeProcessor<EnforcementMechanismUpdateEvent>(EnforcementMechanismUpdateEvent.class) { +// public void handle(final EnforcementMechanismUpdateEvent event) { +// dataModel.setGroupDataModel(event.getGroupDataModel()); +// gameWindow2D.displayActiveEnforcementMechanism(); +// } +// }); +// addEventProcessor(new EventTypeProcessor<RegulationSubmissionUpdateEvent>(RegulationSubmissionUpdateEvent.class) { +// public void handle(final RegulationSubmissionUpdateEvent event) { +// dataModel.setGroupDataModel(event.getGroupDataModel()); +// gameWindow2D.initializeRegulationVotingPanel(); +// } +// }); +// addEventProcessor(new EventTypeProcessor<RegulationUpdateEvent>(RegulationUpdateEvent.class) { +// public void handle(final RegulationUpdateEvent event) { +// dataModel.setActiveRegulation(event.getRegulationData()); +// gameWindow2D.displayActiveRegulation(); +// } +// }); +// +// addEventProcessor(new EventTypeProcessor<SanctionUpdateEvent>(SanctionUpdateEvent.class) { +// public void handle(final SanctionUpdateEvent event) { +// dataModel.setGroupDataModel(event.getGroupDataModel()); +// gameWindow2D.displaySanctionMechanism(); +// } +// }); } public boolean canPerformRealTimeSanction() { @@ -292,9 +287,6 @@ private int messagesPerSecond = DEFAULT_MESSAGES_PER_SECOND; private int messagesSent; - // samples are collected over 3 seconds. -// private final static int SAMPLE_TIME = 3; - private int totalMessagesPerSample; private int averageMessagesPerSecond; private Duration secondTick = Duration.create(1); @@ -362,7 +354,7 @@ // moveClient(request); transmit(request); } - Utils.sleep(50); + Utils.sleep(30); } } @@ -383,7 +375,6 @@ private void tick() { if (secondTick.hasExpired()) { secondTick.restart(); - totalMessagesPerSample += messagesSent; messagesSent = 0; } } --- a/src/main/java/edu/asu/commons/foraging/client/GameWindow.java Tue Aug 02 15:15:38 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GameWindow.java Tue Aug 02 16:08:46 2011 -0700 @@ -17,6 +17,5 @@ public void init(); public void update(long millisecondsLeft); public void showInstructions(); - public void resetPanels(); } --- a/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java Tue Aug 02 15:15:38 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java Tue Aug 02 16:08:46 2011 -0700 @@ -18,19 +18,15 @@ import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Properties; -import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; -import javax.swing.ButtonGroup; import javax.swing.JLabel; import javax.swing.JPanel; -import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.SwingUtilities; @@ -49,7 +45,6 @@ import edu.asu.commons.foraging.event.ClientMovementRequest; import edu.asu.commons.foraging.event.CollectTokenRequest; import edu.asu.commons.foraging.event.EndRoundEvent; -import edu.asu.commons.foraging.event.EnforcementRankingRequest; import edu.asu.commons.foraging.event.PostRoundSanctionUpdateEvent; import edu.asu.commons.foraging.event.QuizCompletedEvent; import edu.asu.commons.foraging.event.QuizResponseEvent; @@ -73,7 +68,7 @@ * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Revision: 529 $ */ -public class GameWindow2D extends JPanel implements GameWindow, ActionListener { +public class GameWindow2D extends JPanel implements GameWindow { private static final long serialVersionUID = -7733523846114902166L; @@ -89,8 +84,8 @@ private HtmlEditorPane instructionsEditorPane; private JPanel messagePanel; - private JScrollPane errorMessageScrollPane; - private JTextPane errorMessageTextPane; + private JScrollPane messageScrollPane; + private JTextPane messageTextPane; private JPanel labelPanel; @@ -99,10 +94,6 @@ private ChatPanel chatPanel; - private RegulationPanel regulationPanel; - - private EnforcementPanel enforcementPanel; - private JLabel informationLabel; private JLabel timeLeftLabel; @@ -119,6 +110,7 @@ private EventChannel channel; + // FIXME: replace switchXXXPanel with CardLayout switching. private CardLayout cardLayout; // private EnergyLevel energyLevel; @@ -133,10 +125,6 @@ Dimension subjectViewSize = new Dimension((int) Math.floor(size.getWidth()), (int) Math.floor(size.getHeight() * 0.85)); subjectView = new SubjectView(subjectViewSize, dataModel); - // subjectView.addKeyListener(this); - this.currentRankingInformation = new int [2]; - Arrays.fill(currentRankingInformation, -1); -// this.currentRankingInformation[0] = this.currentRankingInformation[1] = -1; initGuiComponents(); } @@ -151,22 +139,11 @@ timeLeftLabel.setText(getTimeLeftLabelText(roundTimeLeft)); // FIXME: subjectView.repaint() causes graphical glitches here // only when we transition from 3D -> 2D experiment. Find out why. - informationLabel.repaint(); - timeLeftLabel.repaint(); subjectView.repaint(); } }); } - public void resetSanctionRanks() { - Arrays.fill(currentRankingInformation, -1); - } - - public void sendSanctionDecisionVotes() { - client.transmit(new EnforcementRankingRequest(client.getId(), currentRankingInformation)); - resetSanctionRanks(); - } - /** * In certain cases, init() _can_ be called before endRound() is finished. Need to lock * access! @@ -195,11 +172,6 @@ } } - private String createStyleString(String questionNumber, String color) { - return String.format(".%s { color: %s; }", questionNumber, color); - } - - private ActionListener createQuizListener(final RoundConfiguration configuration) { return new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -281,98 +253,78 @@ subjectView.collectToken(position); } - private void startRegulationDisplayTimer(){ - if (timer == null) { - final Duration duration = Duration.create(dataModel.getRoundConfiguration().getRegulationDisplayDuration()); - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - if (duration.hasExpired()) { - timeLeftLabel.setText("Regulation voting will start soon."); - timer.stop(); - timer = null; - initializeEnforcementVotingPanel(); - } - else { - timeLeftLabel.setText( String.format("Voting for the enforcement mechanism will start in %d seconds.", duration.getTimeLeft() / 1000L) ); - } - } - }); - timer.start(); - } - } +// private void startEnforcementVotingTimer() { +// if (timer == null) { +// //FIXME: Need to fetch this value from the round4.xml +// duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementVotingDuration()); +// timer = new Timer(1000, new ActionListener() { +// public void actionPerformed(ActionEvent event) { +// if (duration.hasExpired()) { +// timeLeftLabel.setText("Voting is now disabled."); +// timer.stop(); +// timer = null; +// getEnforcementPanel().sendEnforcementVotes(); +// displayVotingWaitMessage(); +// } +// else { +// timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); +// } +// } +// }); +// timer.start(); +// } +// } - private void startEnforcementVotingTimer() { - if (timer == null) { - //FIXME: Need to fetch this value from the round4.xml - duration = Duration.create(dataModel.getRoundConfiguration().getEnforcementVotingDuration()); - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - if (duration.hasExpired()) { - timeLeftLabel.setText("Voting is now disabled."); - timer.stop(); - timer = null; - getEnforcementPanel().sendEnforcementVotes(); - displayVotingWaitMessage(); - } - else { - timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); - } - } - }); - timer.start(); - } - } - - private void startRegulationVotingTimer() { - - if (timer == null) { - duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingDuration()); - - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - if (duration.hasExpired()) { - timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); - - //new code - //Need to add the enforcementVotingPane over here - //instead of the instructionsScrollPane - timer.stop(); - timer = null; - //remove(sanctioningPanel); - //getSanctioningPanel().stopTimer(); - getRegulationPanel().sendRegulationVotes(); - displayVotingWaitMessage(); - } - else { - timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); - } - } - }); - timer.start(); - } - } - - private void startSanctionVotingTimer() { - if (timer == null) { - duration = Duration.create(dataModel.getRoundConfiguration().getSanctionVotingDuration()); - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - if (duration.hasExpired()) { - timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); - timer.stop(); - timer = null; - sendSanctionDecisionVotes(); - displayVotingWaitMessage(); - } - else { - timeLeftLabel.setText( String.format("Voting period will now end in %d seconds.", duration.getTimeLeft() / 1000L) ); - } - } - }); - timer.start(); - } - } +// private void startRegulationVotingTimer() { +// +// if (timer == null) { +// duration = Duration.create(dataModel.getRoundConfiguration().getRegulationVotingDuration()); +// +// timer = new Timer(1000, new ActionListener() { +// public void actionPerformed(ActionEvent event) { +// if (duration.hasExpired()) { +// timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); +// +// //new code +// //Need to add the enforcementVotingPane over here +// //instead of the instructionsScrollPane +// timer.stop(); +// timer = null; +// //remove(sanctioningPanel); +// //getSanctioningPanel().stopTimer(); +// getRegulationPanel().sendRegulationVotes(); +// displayVotingWaitMessage(); +// } +// else { +// timeLeftLabel.setText( String.format("Voting period will end in %d seconds.", duration.getTimeLeft() / 1000L) ); +// } +// } +// }); +// timer.start(); +// } +// } +// +// private void startSanctionVotingTimer() { +// if (timer == null) { +// duration = Duration.create(dataModel.getRoundConfiguration().getSanctionVotingDuration()); +// timer = new Timer(1000, new ActionListener() { +// public void actionPerformed(ActionEvent event) { +// if (duration.hasExpired()) { +// timeLeftLabel.setText("Voting is now disabled. Next round begins shortly."); +// timer.stop(); +// timer = null; +// sendSanctionDecisionVotes(); +// displayVotingWaitMessage(); +// } +// else { +// timeLeftLabel.setText( String.format("Voting period will now end in %d seconds.", duration.getTimeLeft() / 1000L) ); +// } +// } +// }); +// timer.start(); +// } +// } private void startChatTimer() { if (timer == null) { @@ -384,9 +336,9 @@ timeLeftLabel.setText("Chat is now disabled."); timer.stop(); timer = null; - if (roundConfiguration.isVotingAndRegulationEnabled()) { - initializeSanctionDecisionPanel(); - } +// if (roundConfiguration.isVotingAndRegulationEnabled()) { +// initializeSanctionDecisionPanel(); +// } } else { timeLeftLabel.setText( String.format("Chat will end in %d seconds.", duration.getTimeLeft() / 1000L) ); @@ -467,12 +419,6 @@ return htmlPane; } - private RegulationPanel updateRegulationVotingPanel(){ - RegulationPanel regulationPanel = getRegulationPanel(); - regulationPanel.initRegulationVotingComponents(); - return regulationPanel; - } - private void initGuiComponents() { // FIXME: replace with CardLayout for easier switching between panels // cardLayout = new CardLayout(); @@ -507,23 +453,22 @@ // add message window. messagePanel = new JPanel(new BorderLayout()); // 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)); - errorMessageTextPane.setBackground(Color.WHITE); + messagePanel.add(new JLabel("Messages"), BorderLayout.NORTH); + messageTextPane = new JTextPane(); + messageTextPane.setEditable(false); + messageTextPane.setFont(new Font("arial", Font.BOLD, 12)); + messageTextPane.setBackground(Color.WHITE); - addStyles(errorMessageTextPane.getStyledDocument()); - errorMessageScrollPane = new JScrollPane(errorMessageTextPane); + addStyles(messageTextPane.getStyledDocument()); + messageScrollPane = new JScrollPane(messageTextPane); Dimension scrollPaneSize = new Dimension(getPreferredSize().width, 50); - errorMessageScrollPane.setMinimumSize(scrollPaneSize); - errorMessageScrollPane.setPreferredSize(scrollPaneSize); - errorMessageScrollPane.setMaximumSize(scrollPaneSize); - messagePanel.add(errorMessageScrollPane, BorderLayout.CENTER); + messageScrollPane.setMinimumSize(scrollPaneSize); + messageScrollPane.setPreferredSize(scrollPaneSize); + messageScrollPane.setMaximumSize(scrollPaneSize); + messagePanel.add(messageScrollPane, BorderLayout.CENTER); add(messagePanel, BorderLayout.SOUTH); - - + addKeyListener( createGameWindowKeyListener() ); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { @@ -535,7 +480,8 @@ addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent event) { Component component = event.getComponent(); - int subjectViewHeight = component.getHeight() - (errorMessageScrollPane.getHeight() + 35); + // offset by 35 to allow for chat message box + int subjectViewHeight = component.getHeight() - 35; Dimension size = new Dimension(component.getWidth(), subjectViewHeight); subjectView.setScreenSize(size); subjectView.setImageSizes(); @@ -682,7 +628,13 @@ // has begun. update(configuration.getRoundDuration().getTimeLeft()); add(messagePanel, BorderLayout.SOUTH); + if (configuration.isInRoundChatEnabled()) { + ChatPanel chatPanel = getChatPanel(); + chatPanel.initialize(); + add(chatPanel, BorderLayout.EAST); + } addCenterComponent(subjectWindow); + requestFocusInWindow(); } }; @@ -699,11 +651,11 @@ public void displayMessage(String errorMessage, Color color) { // String chatHandle = getChatHandle(source); - errorMessageTextPane.setForeground(color); - StyledDocument document = errorMessageTextPane.getStyledDocument(); + messageTextPane.setForeground(color); + StyledDocument document = messageTextPane.getStyledDocument(); try { document.insertString(document.getLength(), errorMessage + "\n", document.getStyle("bold")); - errorMessageTextPane.setCaretPosition(document.getLength()); + messageTextPane.setCaretPosition(document.getLength()); } catch (BadLocationException e) { e.printStackTrace(); @@ -791,20 +743,7 @@ } return chatPanel; } - private RegulationPanel getRegulationPanel() { - if (regulationPanel == null) { - //System.out.println("Sanc panel is null"); - regulationPanel = new RegulationPanel(client); - } - return regulationPanel; - } - private EnforcementPanel getEnforcementPanel() { - if (enforcementPanel == null) { - //System.out.println("enf panel is null"); - enforcementPanel = new EnforcementPanel(client); - } - return enforcementPanel; - } + public void showInstructions() { RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); instructionsBuilder.delete(0, instructionsBuilder.length()); @@ -865,20 +804,20 @@ addCenterComponent(instructionsScrollPane); } - public void displayActiveRegulation() { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - String activeRegulation = dataModel.getActiveRegulation().getText(); - if (activeRegulation == null || activeRegulation.trim().isEmpty()) { - activeRegulation = "No regulation specified."; - } - setInstructions( - "<h3>The following regulation received the most votes:</h3><p>" + activeRegulation + "</p>"); - addCenterComponent(instructionsScrollPane); - startRegulationDisplayTimer(); - } - }); - } +// public void displayActiveRegulation() { +// SwingUtilities.invokeLater(new Runnable() { +// public void run() { +// String activeRegulation = dataModel.getActiveRegulation().getText(); +// if (activeRegulation == null || activeRegulation.trim().isEmpty()) { +// activeRegulation = "No regulation specified."; +// } +// setInstructions( +// "<h3>The following regulation received the most votes:</h3><p>" + activeRegulation + "</p>"); +// addCenterComponent(instructionsScrollPane); +// startRegulationDisplayTimer(); +// } +// }); +// } public void updateDebriefing(final PostRoundSanctionUpdateEvent event) { Runnable runnable = new Runnable() { @@ -890,12 +829,6 @@ SwingUtilities.invokeLater(runnable); } - public void resetPanels() { - regulationPanel = null; - enforcementPanel = null; - } - - public void endRound(final EndRoundEvent event) { Runnable runnable = new Runnable() { public void run() { @@ -910,7 +843,7 @@ } // generate debriefing text from data culled from the Event addDebriefingText(event); - errorMessageTextPane.setText(""); + messageTextPane.setText(""); } }; try { @@ -922,106 +855,9 @@ } } - public void initializeEnforcementVotingPanel() { - // TODO: revisit + public void initializeChatPanel() { SwingUtilities.invokeLater(new Runnable() { public void run() { - EnforcementPanel enforcementPanel = getEnforcementPanel(); - enforcementPanel.initialize(); - addCenterComponent(enforcementPanel); - startEnforcementVotingTimer(); - } - }); - } - - - public void initializeRegulationVotingPanel() { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - RegulationPanel regulationPanel = updateRegulationVotingPanel(); - addCenterComponent( regulationPanel ); - //sanctioningPanel.startTimer(); - startRegulationVotingTimer(); - } - }); - } - - public void actionPerformed (ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - System.out.println("Choice : "+choice); - System.out.println("Button : "+buttonNo); - //currentRankingInformation[buttonNo] = 1; - currentRankingInformation[0] = buttonNo; - - } - - private JPanel getDecisionPanel() { - - if (decisionPanel == null) { - decisionPanel = new JPanel(new BorderLayout()); - decisionPanel.setBackground(Color.GRAY); - - HtmlEditorPane editorPane = createInstructionsEditorPane(); - JScrollPane scrollPane = new JScrollPane(editorPane); - editorPane.setText(dataModel.getRoundConfiguration().getSanctionInstructions()); - decisionPanel.add(scrollPane, BorderLayout.PAGE_START); - - group = new ButtonGroup(); - - JPanel rankPanel = new JPanel(); - rankPanel.setBackground(Color.WHITE); - rankPanel.setLayout(new BoxLayout (rankPanel, BoxLayout.Y_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Voting")); - - JLabel sanctionText = new JLabel("Please select one of the options below: "); - - rankPanel.add(Box.createVerticalStrut(5)); - - rankPanel.add(sanctionText); - - rankPanel.add(Box.createVerticalStrut(8)); - - noSanction = new JRadioButton("No penalties [No one can subtract tokens from anyone]"); - noSanction.setActionCommand("0"); - group.add(noSanction); - noSanction.addActionListener(this); - rankPanel.add(noSanction); - - rankPanel.add(Box.createVerticalStrut(8)); - - sanction = new JRadioButton("Allow penalties [Everyone can subtract tokens from each other]"); - sanction.setActionCommand("1"); - group.add(sanction); - sanction.addActionListener(this); - rankPanel.add(sanction); - - decisionPanel.add(rankPanel); - } - group.clearSelection(); - return decisionPanel; - } - - public void initializeSanctionDecisionPanel() { - addCenterComponent(getDecisionPanel()); - startSanctionVotingTimer(); - } - - private JPanel decisionPanel; - private ButtonGroup group; - private JRadioButton sanction; - private JRadioButton noSanction; - private int currentRankingInformation[]; - - - - public void initializeChatPanel() { - //new code - // System.out.println("*****Inside initialize chatPanel()"); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - //new code - // System.out.println("*****Inside thread initialize chatPanel()"); ChatPanel chatPanel = getChatPanel(); chatPanel.initialize(); remove( messagePanel ); --- a/src/main/java/edu/asu/commons/foraging/client/GameWindow3D.java Tue Aug 02 15:15:38 2011 -0700 +++ b/src/main/java/edu/asu/commons/foraging/client/GameWindow3D.java Tue Aug 02 16:08:46 2011 -0700 @@ -117,10 +117,6 @@ } - public void resetPanels() { - - } - private void initializeChatPanel() { getChatPanel().initialize(); } --- a/src/main/java/edu/asu/commons/foraging/client/RegulationPanel.java Tue Aug 02 15:15:38 2011 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,473 +0,0 @@ -package edu.asu.commons.foraging.client; - - -import java.awt.BorderLayout; -import java.awt.Color; -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.JEditorPane; -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: RegulationPanel.java 522 2010-06-30 19:17:48Z alllee $ - * - * Sanctioning panel is used to create regulations and - * enforcement mechanism - * - * FIXME: split this functionality out into two different panels, one for submission and the other for voting. - * - * @author dbarge - * @version $Revision: 522 $ - */ - -@SuppressWarnings("serial") -public class RegulationPanel extends JPanel { - - private ForagingClient client; - - public RegulationPanel (ForagingClient client) { - this(); - this.client = client; -// client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { -// public void handle(final RegulationEvent regulationEvent) { -// 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>(); - // FIXME: get rid of hardcoded constants, this should be dynamic based on the size of the group. - newPanel = new SixChoicePanel[5]; - noOfRegulations = 5; - } - - 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; -// } -// } -// } - 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); - } - - // FIXME: messy, refactor after experiment. - 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; - } - } - } - - votingPanel.setVisible(false); - remove(votingPanel); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - - votingPanel.add(getInstructionPanel()); - - - 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(); - } - - 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(){ - - if (regulationsInstructionsScrollPane != null) { - remove(regulationsInstructionsScrollPane); - } - if (messageScrollPane != null) { - 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(); - 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++) { - List<RegulationData> submittedRegulations = client.getDataModel().getSubmittedRegulations(); -// List<RegulationData> submittedRegulations = -// Arrays.asList(new RegulationData(new Identifier.Base(), "Regulation 1", 0), -// new RegulationData(new Identifier.Base(), "Regulation 2", 1), -// new RegulationData(new Identifier.Base(), "Regulation 3", 2), -// new RegulationData(new Identifier.Base(), "Regulation 4", 3), -// new RegulationData(new Identifier.Base(), "Regulation 5", 4)); - - for (RegulationData regulationData : submittedRegulations) { - System.err.println("creating six choice panel from regulation data: " + regulationData); - // FIXME: are you aware that th... [truncated message content] |