[virtualcommons-svn] SF.net SVN: virtualcommons:[393] foraging/branches/deepak-branch-fall-09/ src/
Status: Beta
Brought to you by:
alllee
From: <see...@us...> - 2009-12-03 03:06:21
|
Revision: 393 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=393&view=rev Author: seematalele Date: 2009-12-03 03:06:15 +0000 (Thu, 03 Dec 2009) Log Message: ----------- 1) Created Interface for Regulation. 2) Created the dummy information. So, during the actual experiment, remove the dummy information. 3) Created TestSanction to test the SanctioningPanel class. Bugs- 1) Trying to reduce the height of the TextArea, written settings for it, but due to some reason, it is not reflecting in the GUI. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java Added Paths: ----------- foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java Added: foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java (rev 0) +++ foraging/branches/deepak-branch-fall-09/src/main/java/TestSanction.java 2009-12-03 03:06:15 UTC (rev 393) @@ -0,0 +1,36 @@ +import java.awt.Color; +import java.awt.Container; +import java.awt.FlowLayout; + +import javax.swing.JFrame; + +import edu.asu.commons.foraging.client.ForagingClient; +import edu.asu.commons.foraging.client.SanctioningPanel; + + +public class TestSanction { + + /** + * @param args + */ + public static void main(String[] args) { + // TODO Auto-generated method stub + //ForagingClient client = new ForagingClient(); + + SanctioningPanel testsanctioning = new SanctioningPanel(); + testsanctioning.initialize(); + //testsanctioning.getdata(); + testsanctioning.initRegulationVotingCompontents(); + JFrame f = new JFrame("This is a test"); + f.setSize(1000, 1000); + Container content = f.getContentPane(); + content.setBackground(Color.white); + content.setLayout(new FlowLayout()); + content.add(testsanctioning); + //f.setDefaultCloseOperation(0); + f.setVisible(true); + + + } + +} Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 01:15:41 UTC (rev 392) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 03:06:15 UTC (rev 393) @@ -5,10 +5,12 @@ import java.awt.Color; import java.awt.Component; import java.awt.GridLayout; +import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,7 +24,9 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; +import javax.swing.JTextArea; import javax.swing.JTextPane; +import javax.swing.ScrollPaneConstants; import javax.swing.Timer; import javax.swing.text.Style; import javax.swing.text.StyleConstants; @@ -52,370 +56,396 @@ @SuppressWarnings("serial") public class SanctioningPanel extends JPanel { - private ForagingClient client; + private ForagingClient client; - private Map<Identifier, RegulationData> regulations; + private Map<Identifier, RegulationData> regulations; - public SanctioningPanel (ForagingClient client) { - this.client = client; - this.clientId = client.getId(); - client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { - public void handle(final RegulationEvent regulationEvent) { - boolean votingFlag=false; - RegulationData regulationData = null; - regulations = regulationEvent.getAllRegulations(); - // System.out.println("Regulation received : "+regulations.size()); - noOfRegulations = regulations.size(); - for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - if(regulationData.isVoting())votingFlag = true; - break; - } - if(votingFlag) - { - votedRegulation = regulationData; - Utils.notify(GameWindow2D.regulationVotesSignal); - } - else - { - //System.out.println("Finding my ID"); - findAndSetMyRegulationID(); - Utils.notify(GameWindow2D.regulationSignal); - } - } - }); - } + public SanctioningPanel (ForagingClient client) { + this.client = client; + this.clientId = client.getId(); + client.getEventChannel().add(this, new EventTypeProcessor<RegulationEvent>(RegulationEvent.class) { + public void handle(final RegulationEvent regulationEvent) { + boolean votingFlag=false; + RegulationData regulationData = null; + regulations = regulationEvent.getAllRegulations(); + // System.out.println("Regulation received : "+regulations.size()); + noOfRegulations = regulations.size(); + for (Identifier targetId : regulations.keySet()) { + regulationData = regulations.get(targetId); + if(regulationData.isVoting())votingFlag = true; + break; + } + if(votingFlag) + { + votedRegulation = regulationData; + Utils.notify(GameWindow2D.regulationVotesSignal); + } + else + { + //System.out.println("Finding my ID"); + findAndSetMyRegulationID(); + Utils.notify(GameWindow2D.regulationSignal); + } + } + }); + } - public static int currentActive; + public SanctioningPanel () + { + regulations = new HashMap<Identifier, RegulationData>(); + newPanel = new SixChoicePanel[5]; - public static int currentLabel; + } - public static String regulationString = ""; + public static int currentActive; - private Identifier clientId; + public static int currentLabel; - private String message; + public static String regulationString = ""; - private RegulationData votedRegulation; + private Identifier clientId; - private int noOfRegulations; + private String message; - private int currentRankingInformation[]; + private RegulationData votedRegulation; - private Timer timer; - private SixChoicePanel newPanel[]; + private int noOfRegulations; - private JPanel votingPanel; - private JPanel informationPanel; - private JLabel label; - private JPanel instructionsPanel; - private JPanel buttonPanel; - private JButton sendMyVotes; - private JButton reset; + private int currentRankingInformation[]; - private String[] votes = { "1", "2", "3","4", "5"}; + private Timer timer; + private SixChoicePanel newPanel[]; - private JScrollPane messageScrollPane; + private JPanel votingPanel; + private JPanel informationPanel; + private JLabel label; + private JPanel instructionsPanel; + private JPanel buttonPanel; + private JButton sendMyVotes; + private JButton reset; - private JScrollPane regulationsInstructionsScrollPane; + private String[] votes = { "1", "2", "3","4", "5"}; - private JTextPane messageWindow; + private JScrollPane messageScrollPane; - private List<Identifier> participants; + private JScrollPane regulationsInstructionsScrollPane; - private JEditorPane regulationsInstructionsPane; + private JTextPane messageWindow; - public Map<Identifier, RegulationData> getAllRegulations() { - return regulations; - } + private List<Identifier> participants; - private void findAndSetMyRegulationID() - { - for (Identifier targetId : regulations.keySet()) { - if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ - client.setRegulationID(regulations.get(targetId).getRegulationID()); - //client.setEnforcementID(regulations.get(targetId).getToken()); - client.setToken(regulations.get(targetId).getToken()); - //System.out.println("My RegID:"+client.getRegulationID()); - //System.out.println("Token:"+client.getEnforcementID()); - return; - } - } - } + private JEditorPane regulationsInstructionsPane; - public RegulationData getVotedRegulation(){ - return this.votedRegulation; - } + public Map<Identifier, RegulationData> getAllRegulations() { + return regulations; + } - private void addStylesToMessageWindow() { - StyledDocument styledDocument = messageWindow.getStyledDocument(); - // and why not have something like... StyleContext.getDefaultStyle() to - // replace this junk - Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( - StyleContext.DEFAULT_STYLE); - // Style regularStyle = styledDocument.addStyle("regular", - // defaultStyle); - StyleConstants.setFontFamily(defaultStyle, "Helvetica"); - StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), - true); - StyleConstants.setItalic(styledDocument - .addStyle("italic", defaultStyle), true); - } + private void findAndSetMyRegulationID() + { + for (Identifier targetId : regulations.keySet()) { + if(regulations.get(targetId).getRegulationText().compareTo(message) == 0){ + client.setRegulationID(regulations.get(targetId).getRegulationID()); + //client.setEnforcementID(regulations.get(targetId).getToken()); + client.setToken(regulations.get(targetId).getToken()); + //System.out.println("My RegID:"+client.getRegulationID()); + //System.out.println("Token:"+client.getEnforcementID()); + return; + } + } + } - private void updateInstructionPanel(){ - // System.out.println("RegulationString:"+regulationString); + public RegulationData getVotedRegulation(){ + return this.votedRegulation; + } - if(regulationString.equals("")) - regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); - else - regulationsInstructionsPane.setText(regulationString); + private void addStylesToMessageWindow() { + StyledDocument styledDocument = messageWindow.getStyledDocument(); + // and why not have something like... StyleContext.getDefaultStyle() to + // replace this junk + Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( + StyleContext.DEFAULT_STYLE); + // Style regularStyle = styledDocument.addStyle("regular", + // defaultStyle); + StyleConstants.setFontFamily(defaultStyle, "Helvetica"); + StyleConstants.setBold(styledDocument.addStyle("bold", defaultStyle), + true); + StyleConstants.setItalic(styledDocument + .addStyle("italic", defaultStyle), true); + } - revalidate(); - instructionsPanel.repaint(); - repaint(); - //pack(); - // setVisible(true); - } + private void updateInstructionPanel(){ + // System.out.println("RegulationString:"+regulationString); + if(regulationString.equals("")) + regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); + else + regulationsInstructionsPane.setText(regulationString); - private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; - SixChoicePanel temp = null; - boolean enableSendButton = true; + revalidate(); + instructionsPanel.repaint(); + repaint(); + //pack(); + // setVisible(true); + } - // System.out.println("Active panel: "+SixChoicePanel.currentActive); - for(r = 0; r < noOfRegulations; r++) - { - // System.out.print(newPanel[r].currentRanking+" "); - if(newPanel[r].currentRanking == -1)enableSendButton = false; + private void updateVotingPanel(){ + int r,c,i,j; + int currentRanking; + SixChoicePanel temp = null; + boolean enableSendButton = true; - if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) - { - newPanel[r].currentRanking = -1; - newPanel[r].group.clearSelection(); - } - } + // System.out.println("Active panel: "+SixChoicePanel.currentActive); + for(r = 0; r < noOfRegulations; r++) + { + // System.out.print(newPanel[r].currentRanking+" "); + if(newPanel[r].currentRanking == -1)enableSendButton = false; - for(r = 0; r < noOfRegulations-1; r++) - { - for(c = 0; c < noOfRegulations-1; c++) - { - if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) - { - temp = newPanel[c]; - newPanel[c] = newPanel[c+1]; - newPanel[c+1] = temp; - } - } - } - for(c = 0; c < noOfRegulations; c++) - { - // System.out.print(newPanel[c].getCurrentRanking() +" "); - } + if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) + { + newPanel[r].currentRanking = -1; + newPanel[r].group.clearSelection(); + } + } - votingPanel.setVisible(false); - remove(votingPanel); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + for(r = 0; r < noOfRegulations-1; r++) + { + for(c = 0; c < noOfRegulations-1; c++) + { + if((newPanel[c].currentRanking > newPanel[c+1].currentRanking)&&(newPanel[c+1].currentRanking != -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + if((newPanel[c].currentRanking < newPanel[c+1].currentRanking)&&(newPanel[c].currentRanking == -1)) + { + temp = newPanel[c]; + newPanel[c] = newPanel[c+1]; + newPanel[c+1] = temp; + } + } + } + for(c = 0; c < noOfRegulations; c++) + { + // System.out.print(newPanel[c].getCurrentRanking() +" "); + } + votingPanel.setVisible(false); + remove(votingPanel); - for(i=0; i < noOfRegulations; i++) { - votingPanel.add(newPanel[i].regulationPanel); - votingPanel.add(newPanel[i].rankPanel); - } - votingPanel.setVisible(true); - add(votingPanel, BorderLayout.CENTER); + //votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + votingPanel.setLayout(new GridLayout(5,2)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); - if(enableSendButton) { - sendMyVotes.setEnabled(true); - buttonPanel.setVisible(true); - add(buttonPanel, BorderLayout.SOUTH); - } - revalidate(); - } - public void stopTimer(){ - timer.stop(); - } + for(i=0; i < noOfRegulations; i++) { + votingPanel.add(newPanel[i].regulationPanel); + votingPanel.add(newPanel[i].rankPanel); + } + votingPanel.setVisible(true); + add(votingPanel, BorderLayout.CENTER); - public void startTimer(){ - if (timer == null) { - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } - }); - timer.start(); - } - } + if(enableSendButton) { + sendMyVotes.setEnabled(true); + buttonPanel.setVisible(true); + add(buttonPanel, BorderLayout.SOUTH); + } + revalidate(); + } - public void sendRegulation() { - System.out.println("Regulation sent"); - message = messageWindow.getText(); - // System.err.println("message: " + message); + public void stopTimer(){ + timer.stop(); + } - RegulationData regulationData = new RegulationData(); - regulationData.setRegulationText(message); - regulationData.setVotingFlag(false); - //FIXME:All the clients have to send some regulation - // if (message == null || "".equals(message) || targetIdentifier == null) { - // return; - // } - client.transmit(new RegulationRequest(clientId, message, regulationData)); - } - - public void sendRegulationVotes() { - System.out.println("Regulation votes ready to be sent"); - // System.err.println("message: " + message); - int i; - for(i=0; i < noOfRegulations; i++) { - if(newPanel[i].currentRanking == -1) - this.currentRankingInformation[i] = -1; - else - this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); - } + public void startTimer(){ + if (timer == null) { + timer = new Timer(1000, new ActionListener() { + public void actionPerformed(ActionEvent event) { + //timer.stop(); + //timer = null; + // System.out.println("Timer called to update the voting panel:"); + updateVotingPanel(); + updateInstructionPanel(); + } + }); + timer.start(); + } + } - /* + public void sendRegulation() { + System.out.println("Regulation sent"); + message = messageWindow.getText(); + // System.err.println("message: " + message); + + RegulationData regulationData = new RegulationData(); + regulationData.setRegulationText(message); + regulationData.setVotingFlag(false); + //FIXME:All the clients have to send some regulation + // if (message == null || "".equals(message) || targetIdentifier == null) { + // return; + // } + client.transmit(new RegulationRequest(clientId, message, regulationData)); + } + + public void sendRegulationVotes() { + System.out.println("Regulation votes ready to be sent"); + // System.err.println("message: " + message); + int i; + for(i=0; i < noOfRegulations; i++) { + if(newPanel[i].currentRanking == -1) + this.currentRankingInformation[i] = -1; + else + this.currentRankingInformation[i] = newPanel[i].getCurrentRanking(); + } + + /* for(i=0 ; i<5 ; i++) { System.out.println(currentRankingInformation[i]); } - */ + */ - RegulationData regulationData = new RegulationData(); - regulationData.setCurrentRankingInformation(this.currentRankingInformation); - regulationData.setRegulationText(message); - regulationData.setVotingFlag(true); + RegulationData regulationData = new RegulationData(); + regulationData.setCurrentRankingInformation(this.currentRankingInformation); + regulationData.setRegulationText(message); + regulationData.setVotingFlag(true); - // System.out.println("ID:"+client.getRegulationID()); - regulationData.setRegulationID(client.getRegulationID()); + // System.out.println("ID:"+client.getRegulationID()); + regulationData.setRegulationID(client.getRegulationID()); - client.transmit(new RegulationRequest(clientId, message, regulationData)); - } + client.transmit(new RegulationRequest(clientId, message, regulationData)); + } - private Color getColor(int i) - { - Color color = null; - if(i==0) color=Color.green; - if(i==1) color=Color.lightGray; - if(i==2) color=Color.blue; - if(i==3) color=Color.red; - if(i==4) color=Color.cyan; - return color; - } + private Color getColor(int i) + { + Color color = null; + if(i==0) color=Color.lightGray; + if(i==1) color=Color.green; + if(i==2) color=Color.blue; + if(i==3) color=Color.red; + if(i==4) color=Color.cyan; + return color; + } - private String getVoteString(){ + private String getVoteString(){ - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - for(int c = 0; c < noOfRegulations; c++) - { - sb.append("\nRegulation "+(newPanel[c].getCurrentRanking()+1)); - } - return(sb.toString()); - } + for(int c = 0; c < noOfRegulations; c++) + { + sb.append("\nRegulation "+(newPanel[c].getCurrentRanking()+1)); + } + return(sb.toString()); + } - public void initRegulationVotingCompontents(){ + public void initRegulationVotingCompontents(){ - remove(regulationsInstructionsScrollPane); - remove(messageScrollPane); - this.currentRankingInformation = new int[5]; - this.timer=null; - this.newPanel = new SixChoicePanel[5]; - setBackground(Color.lightGray); - setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + remove(regulationsInstructionsScrollPane); + remove(messageScrollPane); + this.currentRankingInformation = new int[5]; + this.timer=null; + this.newPanel = new SixChoicePanel[5]; + setBackground(Color.lightGray); + setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - informationPanel = new JPanel(); - informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); - informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); - label = new JLabel("You have 30 seconds left to vote the regulations"); + informationPanel = new JPanel(); + informationPanel.setLayout(new BoxLayout(informationPanel, BoxLayout.X_AXIS)); + informationPanel.setBorder(BorderFactory.createTitledBorder("Time Left")); + label = new JLabel("You have 30 seconds left to vote the regulations"); - informationPanel.add(label); - // add(informationPanel, BorderLayout.NORTH); + informationPanel.add(label); + // add(informationPanel, BorderLayout.NORTH); - votingPanel = new JPanel(); - votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + votingPanel = new JPanel(); + votingPanel.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); + //votingPanel.setLayout(new GridLayout(5,2)); + votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + //add the instruction panel as the first panel in voting panel. + votingPanel.add(getInstructionPanel("this is instruction panel")); - RegulationData regulationData; + RegulationData regulationData; - //for(int i=0; i<5; i++) { - int i = 0; - for (Identifier targetId : regulations.keySet()) { - regulationData = regulations.get(targetId); - StringBuilder sb = new StringBuilder(); - sb.append(regulationData.getRegulationText()); - String s = sb.toString(); - newPanel[i] = new SixChoicePanel(s, votes, regulationData.getRegulationID(), getColor(i)); - votingPanel.add(newPanel[i].getRegulationPanel(i)); - votingPanel.add(newPanel[i].getRankPanel(i)); - i++; - } + // this is for dummy regulation data for testing + // start + for(int i=0; i<5; i++) { + RegulationData regulationData1 = new RegulationData(); + regulationData1.setRegulationID(i); + regulationData1.setRegulationText("Test Regulation " + i); + Identifier temp = new Identifier.Base (){}; + System.out.println("Idn : " + temp); + regulations.put(temp, regulationData1); + } + System.out.println(regulations.size()); + // end - add(votingPanel, BorderLayout.CENTER); - reset = new JButton("Reset All Ranks"); - reset.setAlignmentX(Component.CENTER_ALIGNMENT); - reset.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - for(int i=0; i<noOfRegulations; i++) { - for(int j=0; j<noOfRegulations; j++) { - newPanel[i].option[j].setEnabled(true); - newPanel[i].group.clearSelection(); - newPanel[i].currentRanking = -1; - } - } - } - }); - sendMyVotes = new JButton("Send votes"); - sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); - sendMyVotes.setEnabled(false); - sendMyVotes.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { + //for(int i=0; i<5; i++) { + int i = 0; + for (Identifier targetId : regulations.keySet()) { + regulationData = regulations.get(targetId); + StringBuilder sb = new StringBuilder(); + sb.append(regulationData.getRegulationText()); + String s = sb.toString(); + newPanel[i] = new SixChoicePanel(s, votes, regulationData.getRegulationID(), getColor(i)); + // votingPanel.add(newPanel[i].getRegulationPanel(i,client.getDataModel().getRoundConfiguration().getRegulationInstructions())); + votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); + //votingPanel.add(newPanel[i].getRankPanel(i)); + + i++; + } - int n = JOptionPane.showConfirmDialog( - null, "Are you sure to submit your votes ?"+ - "\nBelow is order of your voting" + - getVoteString(), - "Confirm and send votes", - JOptionPane.YES_NO_OPTION); + add(votingPanel, BorderLayout.CENTER); + reset = new JButton("Reset All Ranks"); + reset.setAlignmentX(Component.CENTER_ALIGNMENT); + reset.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + for(int i=0; i<noOfRegulations; i++) { + for(int j=0; j<noOfRegulations; j++) { + newPanel[i].option[j].setEnabled(true); + newPanel[i].group.clearSelection(); + newPanel[i].currentRanking = -1; + } + } + } + }); + sendMyVotes = new JButton("Send votes"); + sendMyVotes.setAlignmentX(Component.CENTER_ALIGNMENT); + sendMyVotes.setEnabled(false); + sendMyVotes.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { - if (n == JOptionPane.YES_OPTION) { - GameWindow2D.duration.expire(); - } - if (n == JOptionPane.NO_OPTION) { + int n = JOptionPane.showConfirmDialog( + null, "Are you sure to submit your votes ?"+ + "\nBelow is order of your voting" + + getVoteString(), + "Confirm and send votes", + JOptionPane.YES_NO_OPTION); - } + if (n == JOptionPane.YES_OPTION) { + GameWindow2D.duration.expire(); + } + if (n == JOptionPane.NO_OPTION) { - } - }); - buttonPanel = new JPanel(); - //buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); - buttonPanel.setLayout(new GridLayout(1,2)); - buttonPanel.add(reset); - buttonPanel.add(sendMyVotes); + } - add(buttonPanel, BorderLayout.SOUTH); + } + }); + buttonPanel = new JPanel(); + //buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); + buttonPanel.setLayout(new GridLayout(1,2)); + buttonPanel.add(reset); + buttonPanel.add(sendMyVotes); - instructionsPanel = new JPanel(); - instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); - instructionsPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); + add(buttonPanel, BorderLayout.SOUTH); - regulationsInstructionsPane = new JEditorPane(); + /*instructionsPanel = new JPanel(); + instructionsPanel.setLayout(new BoxLayout(instructionsPanel, BoxLayout.Y_AXIS)); + instructionsPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); +*/ + /*regulationsInstructionsPane = new JEditorPane(); regulationsInstructionsPane.setContentType("text/html"); regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); regulationsInstructionsPane.setEditable(false); @@ -426,128 +456,173 @@ //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getChatInstructions()); regulationsInstructionsPane.setText("This is the place of detailed information about regulations"); instructionsPanel.add(regulationsInstructionsScrollPane); + */ + // add(instructionsPanel, BorderLayout.CENTER); +// add(instructionsPanel, BorderLayout.EAST); - // add(instructionsPanel, BorderLayout.CENTER); - add(instructionsPanel, BorderLayout.EAST); + } - } - private void initGuiComponents() { - //System.out.println("Intializing GUI components"); - setLayout(new BorderLayout(4, 4)); - messageWindow = new JTextPane(); - messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); - messageWindow.requestFocusInWindow(); - messageScrollPane = new JScrollPane(messageWindow); - addStylesToMessageWindow(); + private JPanel getInstructionPanel(String instructions) + { + JPanel instructionPanel = new JPanel(); + //instructionPanel.setBackground(color); + instructionPanel.setLayout(new BoxLayout(instructionPanel, BoxLayout.X_AXIS)); + instructionPanel.setBorder(BorderFactory.createTitledBorder("Regulation Instruction")); + //regulationLabel = new JLabel(title); + //regulationLabel = new JLabel("Click here to get more information on right hand side"); - // orient the components in true lazyman fashion. - regulationsInstructionsPane = new JEditorPane(); - regulationsInstructionsPane.setContentType("text/html"); - regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); - regulationsInstructionsPane.setEditable(false); - regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation details")); - regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); + //create Text area and JSCroll pane for it - //FIXME: Need to fetch the regulation instructions over here - regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); + JTextArea instructionText = new JTextArea(instructions,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(instructionText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + instructionPanel.add(scrollForRegulationText); + + return instructionPanel; - add(regulationsInstructionsScrollPane, BorderLayout.NORTH); - add(messageScrollPane, BorderLayout.CENTER); + } + private void initGuiComponents() { + //System.out.println("Intializing GUI components"); + setLayout(new BorderLayout(4, 4)); + messageWindow = new JTextPane(); + messageWindow.setBorder(BorderFactory.createTitledBorder("Type your regulation here")); + messageWindow.requestFocusInWindow(); + messageScrollPane = new JScrollPane(messageWindow); + addStylesToMessageWindow(); - } + // orient the components in true lazyman fashion. - public void clear() { - participants.clear(); - } + regulationsInstructionsPane = new JEditorPane(); + regulationsInstructionsPane.setContentType("text/html"); + regulationsInstructionsPane.setEditorKit(new HTMLEditorKit()); + regulationsInstructionsPane.setEditable(false); + regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation details")); + regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); - public void initialize() { + //FIXME: Need to fetch the regulation instructions over here + //dummy regulation instructions are + //regulationsInstructionsPane.setText(client.getDataModel().getRoundConfiguration().getRegulationInstructions()); + regulationsInstructionsPane.setText("Test regulation instructions...."); + //add(regulationsInstructionsScrollPane, BorderLayout.NORTH); + //add(messageScrollPane, BorderLayout.CENTER); - // Collections.shuffle(Arrays.asList(HANDLES)); - // System.err.println("handles: " + HANDLES);*/ - // System.out.println("Calling init GUI components"); - initGuiComponents(); - } + } - private class SixChoicePanel implements ActionListener, MouseListener{ - String title; - String [] buttonLabels; - int regulationID; - int currentRanking; - JPanel regulationPanel; - JPanel rankPanel; - JLabel regulationLabel; - ButtonGroup group; - JRadioButton option []; - Color color; - // static int currentActive; + public void clear() { + participants.clear(); + } - public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { - this.title = title; - this.buttonLabels = buttonLabels; - this.regulationID = regulationID; - this.color = color; - this.currentRanking = -1; - this.option = new JRadioButton[5]; - } + public void initialize() { - public int getCurrentRanking(){ - return regulationID; - } - public void mouseClicked(MouseEvent arg0) { } - public void mouseEntered(MouseEvent arg0) { } + // Collections.shuffle(Arrays.asList(HANDLES)); + // System.err.println("handles: " + HANDLES);*/ + // System.out.println("Calling init GUI components"); + initGuiComponents(); + } - public void mouseExited(MouseEvent arg0) { } + private class SixChoicePanel implements ActionListener, MouseListener{ + String title; + String [] buttonLabels; + int regulationID; + int currentRanking; + JPanel regulationPanel; + JPanel rankPanel; + JLabel regulationLabel; + ButtonGroup group; + JRadioButton option []; + Color color; + // static int currentActive; - public void mousePressed(MouseEvent arg0) { - currentLabel = this.regulationID; - regulationString = this.title; - // System.out.println("Label No:"+currentLabel); - } + public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { + this.title = title; + this.buttonLabels = buttonLabels; + this.regulationID = regulationID; + this.color = color; + this.currentRanking = -1; + this.option = new JRadioButton[5]; + } - public void mouseReleased(MouseEvent arg0){ } + public int getCurrentRanking(){ + return regulationID; + } + public void mouseClicked(MouseEvent arg0) { } - public void actionPerformed(ActionEvent e) { - String choice = group.getSelection().getActionCommand(); - int buttonNo = Integer.parseInt(choice); - //System.out.println("ACTION Choice Selected: " + choice); - // System.out.println("Bno: " + buttonNo); - this.currentRanking = buttonNo; - SanctioningPanel.currentActive = this.regulationID; - } + public void mouseEntered(MouseEvent arg0) { } - public JPanel getRankPanel(int clientNo){ - rankPanel = new JPanel(); - rankPanel.setBackground(color); - rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.X_AXIS)); - rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); - group = new ButtonGroup(); - int length = buttonLabels.length; // Assumes even length - for(int i=0; i<length; i++) { - option[i] = new JRadioButton(buttonLabels[i]); - option[i].setActionCommand(buttonLabels[i]); - group.add(option[i]); - option[i].addActionListener(this); - rankPanel.add(option[i]); - } + public void mouseExited(MouseEvent arg0) { } - return rankPanel; - } - public JPanel getRegulationPanel(int i){ - regulationPanel = new JPanel(); - regulationPanel.setBackground(color); - regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); - regulationPanel.setBorder(BorderFactory.createTitledBorder("Regulation "+(i+1))); - //regulationLabel = new JLabel(title); - regulationLabel = new JLabel("Click here to get more information on right hand side"); - regulationLabel.addMouseListener(this); - regulationPanel.add(regulationLabel); - return regulationPanel; - } + public void mousePressed(MouseEvent arg0) { + currentLabel = this.regulationID; + regulationString = this.title; + // System.out.println("Label No:"+currentLabel); + } - } + public void mouseReleased(MouseEvent arg0){ } + public void actionPerformed(ActionEvent e) { + String choice = group.getSelection().getActionCommand(); + int buttonNo = Integer.parseInt(choice); + System.out.println("ACTION Choice Selected: " + choice); + System.out.println("Bno: " + buttonNo); + this.currentRanking = buttonNo; + SanctioningPanel.currentActive = this.regulationID; + updateVotingPanel(); + } + public JPanel getRankPanel(int clientNo){ + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length + for(int i=0; i<length; i++) { + option[i] = new JRadioButton(buttonLabels[i]); + option[i].setActionCommand(buttonLabels[i]); + group.add(option[i]); + option[i].addActionListener(this); + rankPanel.add(option[i]); + } + + return rankPanel; + } + public JPanel getRegulationPanel(int i, String information){ + regulationPanel = new JPanel(); + regulationPanel.setBackground(color); + regulationPanel.setLayout(new BoxLayout(regulationPanel, BoxLayout.X_AXIS)); + regulationPanel.setBorder(BorderFactory.createTitledBorder("Regulation "+(i+1))); + //regulationLabel = new JLabel(title); + //regulationLabel = new JLabel("Click here to get more information on right hand side"); + + + //create Text area and JSCroll pane for it + + JTextArea regulationText = new JTextArea(information,3,50); + JScrollPane scrollForRegulationText = new JScrollPane(regulationText,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + regulationPanel.add(scrollForRegulationText); + + rankPanel = new JPanel(); + rankPanel.setBackground(color); + rankPanel.setLayout(new BoxLayout(rankPanel, BoxLayout.Y_AXIS)); + rankPanel.setBorder(BorderFactory.createTitledBorder("Ranks")); + group = new ButtonGroup(); + int length = buttonLabels.length; // Assumes even length + + for(int j=0; j<length; j++) { + option[j] = new JRadioButton(buttonLabels[j]); + option[j].setActionCommand(buttonLabels[j]); + group.add(option[j]); + option[j].addActionListener(this); + rankPanel.add(option[j]); + } + + //regulationLabel.addMouseListener(this); + regulationPanel.add(rankPanel); + return regulationPanel; + } + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |