[virtualcommons-svn] SF.net SVN: virtualcommons:[395] foraging/branches/deepak-branch-fall-09/ src
Status: Beta
Brought to you by:
alllee
From: <db...@us...> - 2009-12-03 20:58:10
|
Revision: 395 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=395&view=rev Author: dbarge Date: 2009-12-03 20:57:59 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Made changes in the SanctioningPanel.java to get rid of the timers to update the GUI (sanctioning panel) Changed the look of the sanctioning panel with more meaning GUI components with the help from Seema Changed the use of colors for the panels. Modified Paths: -------------- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java Modified: foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java =================================================================== --- foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 18:16:22 UTC (rev 394) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/GameWindow2D.java 2009-12-03 20:57:59 UTC (rev 395) @@ -368,7 +368,7 @@ timer.stop(); timer = null; //remove(sanctioningPanel); - getSanctioningPanel().stopTimer(); + //getSanctioningPanel().stopTimer(); getSanctioningPanel().sendRegulationVotes(); System.out.println("Regulation voting sent"); //displayRegulationWaitMessage(); @@ -1032,7 +1032,7 @@ remove(sanctioningPanel); SanctioningPanel sanctioningPanel = updateRegulationVotingPanel(); addCenterComponent( sanctioningPanel ); - sanctioningPanel.startTimer(); + //sanctioningPanel.startTimer(); startRegulationVotingTimer(); } }); 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 18:16:22 UTC (rev 394) +++ foraging/branches/deepak-branch-fall-09/src/main/java/edu/asu/commons/foraging/client/SanctioningPanel.java 2009-12-03 20:57:59 UTC (rev 395) @@ -94,15 +94,9 @@ { regulations = new HashMap<Identifier, RegulationData>(); newPanel = new SixChoicePanel[5]; - + noOfRegulations = 5; } - public static int currentActive; - - public static int currentLabel; - - public static String regulationString = ""; - private Identifier clientId; private String message; @@ -113,12 +107,9 @@ private int currentRankingInformation[]; - private Timer timer; private SixChoicePanel newPanel[]; private JPanel votingPanel; - private JPanel informationPanel; - private JLabel label; private JPanel instructionsPanel; private JPanel buttonPanel; private JButton sendMyVotes; @@ -173,33 +164,19 @@ .addStyle("italic", defaultStyle), 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); - - revalidate(); - instructionsPanel.repaint(); - repaint(); - //pack(); - // setVisible(true); - } - - - private void updateVotingPanel(){ - int r,c,i,j; - int currentRanking; + 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+" "); + System.out.print(newPanel[r].currentRanking+" "); if(newPanel[r].currentRanking == -1)enableSendButton = false; if((newPanel[currentActive].currentRanking == newPanel[r].currentRanking) && (r != currentActive)) @@ -209,6 +186,8 @@ } } + //The below for loops are used for sorting the panels when the ranks are + //changed for(r = 0; r < noOfRegulations-1; r++) { @@ -228,23 +207,23 @@ } } } + 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.setLayout(new BoxLayout(votingPanel, BoxLayout.Y_AXIS)); - votingPanel.setLayout(new GridLayout(5,2)); - votingPanel.setBorder(BorderFactory.createTitledBorder("Regulation Information")); + votingPanel.add(getInstructionPanel("This is instruction panel")); for(i=0; i < noOfRegulations; i++) { votingPanel.add(newPanel[i].regulationPanel); - votingPanel.add(newPanel[i].rankPanel); } + votingPanel.setVisible(true); add(votingPanel, BorderLayout.CENTER); @@ -256,25 +235,6 @@ revalidate(); } - public void stopTimer(){ - timer.stop(); - } - - public void startTimer(){ - if (timer == null) { - timer = new Timer(1000, new ActionListener() { - public void actionPerformed(ActionEvent event) { - //timer.stop(); - //timer = null; - // System.out.println("Timer called to update the voting panel:"); - updateVotingPanel(); - updateInstructionPanel(); - } - }); - timer.start(); - } - } - public void sendRegulation() { System.out.println("Regulation sent"); message = messageWindow.getText(); @@ -322,11 +282,13 @@ 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; + //if(i==0) color = Color.lightGray; + if(i==0) color = new Color(153,153,204); + //if(i==1) color=Color.green; + 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; } @@ -346,26 +308,16 @@ 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.add(label); - // add(informationPanel, BorderLayout.NORTH); - 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")); + instructionsPanel = getInstructionPanel("This is instruction panel"); + votingPanel.add(instructionsPanel); RegulationData regulationData; @@ -391,9 +343,7 @@ 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)); - + votingPanel.add(newPanel[i].getRegulationPanel(i,"This is dummy regulation instructions")); i++; } @@ -434,32 +384,11 @@ } }); 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); - - /*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); - // regulationsInstructionsPane.setBorder(BorderFactory.createTitledBorder("Regulation Instructions")); - regulationsInstructionsScrollPane = new JScrollPane(regulationsInstructionsPane); - - //FIXME: Need to fetch the regulation instructions over here - //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); - } private JPanel getInstructionPanel(String instructions) @@ -468,10 +397,7 @@ //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"); - - + //create Text area and JSCroll pane for it JTextArea instructionText = new JTextArea(instructions,3,50); @@ -482,7 +408,6 @@ } 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")); @@ -514,29 +439,23 @@ } public void initialize() { - - - // 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; + private class SixChoicePanel implements ActionListener{ + //String title; String [] buttonLabels; int regulationID; int currentRanking; JPanel regulationPanel; JPanel rankPanel; - JLabel regulationLabel; ButtonGroup group; JRadioButton option []; Color color; - // static int currentActive; public SixChoicePanel(String title, String[] buttonLabels, int regulationID, Color color ) { - this.title = title; + //this.title = title; this.buttonLabels = buttonLabels; this.regulationID = regulationID; this.color = color; @@ -547,56 +466,24 @@ public int getCurrentRanking(){ return regulationID; } - public void mouseClicked(MouseEvent arg0) { } - public void mouseEntered(MouseEvent arg0) { } - - public void mouseExited(MouseEvent arg0) { } - - 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); + System.out.println("CurrentActive : "+this.regulationID); this.currentRanking = buttonNo; - SanctioningPanel.currentActive = this.regulationID; - updateVotingPanel(); + updateVotingPanel(this.regulationID); } - 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); @@ -617,8 +504,6 @@ 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. |