[virtualcommons-svn] SF.net SVN: virtualcommons:[365] irrigation/trunk
Status: Beta
Brought to you by:
alllee
From: <al...@us...> - 2009-11-17 00:42:42
|
Revision: 365 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=365&view=rev Author: alllee Date: 2009-11-17 00:42:32 +0000 (Tue, 17 Nov 2009) Log Message: ----------- refactoring / interface cleanup Modified Paths: -------------- irrigation/trunk/pom.xml irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java Modified: irrigation/trunk/pom.xml =================================================================== --- irrigation/trunk/pom.xml 2009-11-16 20:39:30 UTC (rev 364) +++ irrigation/trunk/pom.xml 2009-11-17 00:42:32 UTC (rev 365) @@ -108,7 +108,7 @@ <tasks> <!-- can be invoked via - mdeployvn -P ant -D target= + mvn -P ant -D target= --> <property name="compile.classpath" refid="maven.compile.classpath"/> <property name="runtime.classpath" refid="maven.runtime.classpath"/> @@ -130,6 +130,5 @@ </dependency> </dependencies> </profile> - </profiles> </project> Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-11-16 20:39:30 UTC (rev 364) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java 2009-11-17 00:42:32 UTC (rev 365) @@ -20,12 +20,13 @@ import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JEditorPane; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.Timer; +import javax.swing.text.html.HTMLEditorKit; import edu.asu.commons.irrigation.conf.RoundConfiguration; import edu.asu.commons.irrigation.conf.ServerConfiguration; @@ -52,29 +53,22 @@ private ChatPanel chatPanel; - private JScrollPane instructionsScrollPane; - private HtmlEditorPane instructionsEditorPane; private JPanel tokenInvestmentPanel; - private JPanel contributionInformationPanel; private JTextField investedTokensTextField; - private JButton submitTokensButton; - private InfrastructureEfficiencyChartPanel infrastructureEfficiencyChartPanel; private IrrigationClient client; -// private MainIrrigationGameWindow mainIrrigationGameWindow; - private MainIrrigationGameWindow irrigationGamePanel; private StringBuilder instructionsBuilder = new StringBuilder(); - private JTextArea contributionInformationTextArea; + private JEditorPane contributionInformationEditorPane; private JButton nextButton; @@ -90,27 +84,19 @@ private HtmlEditorPane tokenInstructionsEditorPane; - private JScrollPane tokenInstructionsScrollPane; - private int quizzesAnswered = 0; - private JPanel pieChartPanel; - private TokenInvestmentPieChartPanel pieChart; // private CanalAnimationPanel canalAnimationPanel; private CardLayout cardLayout; - private int numberOfQuestionPages; - private Map<Integer, String> quizPageResponses = new HashMap<Integer, String>(); - public ExperimentGameWindow(IrrigationClient client) { this.client = client; this.clientDataModel = client.getClientDataModel(); - this.numberOfQuestionPages = getServerConfiguration().getNumberOfQuestionPages(); } void initialize() { @@ -137,9 +123,8 @@ tokenInvestmentPanel.setLayout(new BorderLayout()); tokenInstructionsEditorPane = createInstructionsEditorPane(); tokenInstructionsEditorPane.setCaretPosition(0); - tokenInstructionsScrollPane = new JScrollPane(tokenInstructionsEditorPane); + JScrollPane tokenInstructionsScrollPane = new JScrollPane(tokenInstructionsEditorPane); tokenInvestmentPanel.add(tokenInstructionsScrollPane, BorderLayout.CENTER); - tokenInvestmentPanel.add(getSubmitTokenPanel(), BorderLayout.SOUTH); tokenInvestmentPanel.setBackground(Color.WHITE); } @@ -151,28 +136,29 @@ submitTokenPanel = new JPanel(); submitTokenPanel.setLayout(new BorderLayout()); submitTokenPanel.add(getInvestedTokensTextField(), BorderLayout.CENTER); - submitTokenPanel.add(getSubmitTokensButton(), BorderLayout.EAST); + JButton submitTokensButton = new JButton("Invest"); + submitTokensButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + submitInvestedTokens(); + } + }); + submitTokenPanel.add(submitTokensButton, BorderLayout.SOUTH); return submitTokenPanel; } return submitTokenPanel; } - - private JScrollPane getInstructionsScrollPane() { - if (instructionsScrollPane == null) { - instructionsScrollPane = new JScrollPane(getInstructionsEditorPane()); - instructionsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); - instructionsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - } - return instructionsScrollPane; - } private JPanel getInstructionsPanel() { if (instructionsPanel == null) { instructionsPanel = new JPanel(); instructionsPanel.setName("Instructions panel"); instructionsPanel.setLayout(new BorderLayout()); - instructionsPanel.add(getInstructionsScrollPane(), BorderLayout.CENTER); - instructionsPanel.add(getQuizNavigationPanel(), BorderLayout.PAGE_END); + JScrollPane instructionsScrollPane = new JScrollPane(getInstructionsEditorPane()); + instructionsScrollPane = new JScrollPane(getInstructionsEditorPane()); + instructionsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); + instructionsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + instructionsPanel.add(instructionsScrollPane, BorderLayout.CENTER); +// instructionsPanel.add(getQuizNavigationPanel(), BorderLayout.PAGE_END); } return instructionsPanel; } @@ -218,7 +204,7 @@ if (currentQuizPageNumber >= quizzesAnswered){ nextButton.setEnabled(false); } - if (currentQuizPageNumber < numberOfQuestionPages) { + if (currentQuizPageNumber < getServerConfiguration().getNumberOfQuestionPages()) { currentQuizPageNumber++; setInstructions(getQuizPage()); } @@ -248,10 +234,8 @@ } else { quizPage = quizPage.replace("<input type=\"submit\" name=\"submit\" value=\"Submit\">", ""); - builder.append(quizPage).append(quizPageResponse); } - return builder.toString(); } @@ -273,19 +257,6 @@ return investedTokensTextField; } - private JButton getSubmitTokensButton() { - if (submitTokensButton == null) { - submitTokensButton = new JButton(); - submitTokensButton.setText("Invest"); - submitTokensButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - submitInvestedTokens(); - } - }); - } - return submitTokensButton; - } - private void submitInvestedTokens() { try { int token = Integer.parseInt(investedTokensTextField.getText()); @@ -413,17 +384,24 @@ instructionsBuilder.append(getServerConfiguration().getFinalInstructions()); } instructionsBuilder.append("<hr/>"); - setInstructions(instructionsBuilder.toString()); + displayInstructions(instructionsBuilder.toString()); } // adding the instructions into the instruction Panel private void setInstructions(final String instructions) { + setInstructions(instructions, false); + } + + private void setInstructions(String instructions, boolean caretToEnd) { + instructionsEditorPane.setText(instructions); + instructionsEditorPane.setCaretPosition(caretToEnd ? instructions.length() : 0); + } + + private void displayInstructions(final String instructions) { SwingUtilities.invokeLater(new Runnable() { public void run() { - instructionsEditorPane.setText(instructions); - instructionsEditorPane.setCaretPosition(0); + setInstructions(instructions); addCenterComponent(getInstructionsPanel()); - getInstructionsScrollPane().revalidate(); } }); } @@ -434,6 +412,7 @@ public synchronized void actionPerformed(ActionEvent e) { if (quizPageResponses.containsKey(currentQuizPageNumber)) { // this form has already been submit. + // shouldn't happen // FIXME: report to user? return; } @@ -453,6 +432,11 @@ if (questionNumber.charAt(0) == 'q') { String number = questionNumber.substring(1, questionNumber.length()); String response = (String) entry.getValue(); + if (response == null || response.trim().isEmpty()) { + // if any responses are empty, abort. + + return; + } String correctAnswer = quizAnswers.get(questionNumber); builder.append(String.format("<p><b>Question %s</b><br/>", number)); String color = "blue"; @@ -475,12 +459,12 @@ quizPageResponses.put(currentQuizPageNumber, builder.toString()); // no matter what we move on to the next question page // tell them what was right and what was wrong. - if (currentQuizPageNumber <= numberOfQuestionPages) { + if (currentQuizPageNumber <= getServerConfiguration().getNumberOfQuestionPages()) { nextButton.setEnabled(true); } quizzesAnswered++; client.transmit(new QuizResponseEvent(client.getId(), currentQuizPageNumber, responses, incorrectAnswers)); - setInstructions(getQuizPage()); + setInstructions(getQuizPage(), true); } }; @@ -490,27 +474,27 @@ GroupDataModel groupDataModel = clientData.getGroupDataModel(); int totalContributedTokens = groupDataModel.getTotalContributedTokens(); final StringBuilder builder = new StringBuilder(); - builder.append("Infrastructure efficiency before investment: ") + builder.append("<ul><li>Infrastructure efficiency before investment: ") .append(groupDataModel.getInfrastructureEfficiencyBeforeInvestment()) - .append("%\n"); - builder.append("Irrigation capacity before investment: ").append(groupDataModel.getIrrigationCapacityBeforeInvestment()).append(" cubic feet per second\n\n"); + .append("%</li>"); + builder.append("<li>Irrigation capacity before investment: ").append(groupDataModel.getIrrigationCapacityBeforeInvestment()).append(" cubic feet per second</li>"); builder.append( String.format( - "Your group invested a total of %d tokens, increasing the infrastructure efficiency to %d%%.\n", + "<li>Total group investment: %d tokens, increasing the infrastructure efficiency to %d%%</li>", totalContributedTokens, groupDataModel.getInfrastructureEfficiency())); if (groupDataModel.getIrrigationCapacity() > groupDataModel.getIrrigationCapacityBeforeInvestment()) { - builder.append("Your group's investment has increased the irrigation capacity to "); + builder.append("<li><b>Your group's investment has increased the irrigation capacity to "); } else { - builder.append("Your group's investment was not enough to increase the irrigation capacity. Your group's irrigation capacity is still "); + builder.append("<li>Your group's investment was not enough to increase the irrigation capacity. Your group's irrigation capacity is still "); } - builder.append(groupDataModel.getIrrigationCapacity()).append(" cubic feet of water per second. The amount of water available to pass through your irrigation canal is ") - .append(groupDataModel.getActualFlowCapacity()); + builder.append(groupDataModel.getIrrigationCapacity()).append(" cubic feet of water per second.</li><li>The amount of water available to pass through your irrigation canal is ") + .append(groupDataModel.getActualFlowCapacity()).append(" cubic feet per second</li>"); SwingUtilities.invokeLater(new Runnable() { public void run() { - contributionInformationTextArea.setText(builder.toString()); + contributionInformationEditorPane.setText(builder.toString()); infrastructureEfficiencyChartPanel.initialize(); - pieChart.setClientData(clientData); + pieChart.initialize(clientData); addCenterComponent(getContributionInformationPanel()); } }); @@ -522,28 +506,29 @@ contributionInformationPanel = new JPanel(); contributionInformationPanel.setName("Graph panel"); contributionInformationPanel.setLayout(new BoxLayout(contributionInformationPanel, BoxLayout.Y_AXIS)); - contributionInformationPanel.add(getPieChartPanel()); + contributionInformationPanel.add(createPieChartPanel()); contributionInformationPanel.add(Box.createVerticalStrut(15)); - contributionInformationTextArea = new JTextArea(); - contributionInformationTextArea.setEditable(false); - contributionInformationPanel.add(contributionInformationTextArea); + contributionInformationEditorPane = new JEditorPane(); + contributionInformationEditorPane.setContentType("text/html"); + contributionInformationEditorPane.setEditorKit(new HTMLEditorKit()); + contributionInformationEditorPane.setEditable(false); + contributionInformationEditorPane.setBackground(Color.WHITE); + contributionInformationPanel.add(contributionInformationEditorPane); } return contributionInformationPanel; } - private JPanel getPieChartPanel() { - if (pieChartPanel == null) { - pieChartPanel = new JPanel(); - infrastructureEfficiencyChartPanel = new InfrastructureEfficiencyChartPanel(client); - pieChart = new TokenInvestmentPieChartPanel(); - GridLayout gridLayout = new GridLayout(); - gridLayout.setRows(1); - gridLayout.setColumns(2); - pieChartPanel.setLayout(gridLayout); - pieChartPanel.add(infrastructureEfficiencyChartPanel); - pieChartPanel.add(pieChart); - } - return pieChartPanel; + private JPanel createPieChartPanel() { + JPanel panel = new JPanel(); + infrastructureEfficiencyChartPanel = new InfrastructureEfficiencyChartPanel(client); + pieChart = new TokenInvestmentPieChartPanel(); + GridLayout gridLayout = new GridLayout(); + gridLayout.setRows(1); + gridLayout.setColumns(2); + panel.setLayout(gridLayout); + panel.add(infrastructureEfficiencyChartPanel); + panel.add(pieChart); + return panel; } @@ -597,7 +582,7 @@ roundConfiguration.getWaterSupplyCapacity() )); } - setInstructions(instructionsBuilder.toString()); + displayInstructions(instructionsBuilder.toString()); } } @@ -646,11 +631,11 @@ public void showQuiz() { SwingUtilities.invokeLater(new Runnable() { public void run() { + setInstructions(getQuizPage()); getInstructionsPanel().add(getQuizNavigationPanel(), BorderLayout.PAGE_END); getInstructionsPanel().revalidate(); } }); - setInstructions(getQuizPage()); } /** @@ -667,13 +652,13 @@ } public void showGameScreenshot() { - setInstructions(getServerConfiguration().getGameScreenshotInstructions()); + displayInstructions(getServerConfiguration().getGameScreenshotInstructions()); } /** * Invoked when the show instructions button is pressed. */ public void showInstructions() { - setInstructions(getServerConfiguration().getInitialInstructions()); + displayInstructions(getServerConfiguration().getInitialInstructions()); } } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-11-16 20:39:30 UTC (rev 364) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/InfrastructureEfficiencyChartPanel.java 2009-11-17 00:42:32 UTC (rev 365) @@ -12,6 +12,7 @@ import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; +import edu.asu.commons.irrigation.conf.RoundConfiguration; import edu.asu.commons.irrigation.server.GroupDataModel; /** @@ -51,30 +52,34 @@ final XYSeries potentialFlowCapacitySeries = new XYSeries("Potential"); // final XYSeries actualFlowCapacitySeriesY = new XYSeries("Actual"); final XYSeries initialInfrastructureEfficiencySeries = new XYSeries("Initial"); - int x,y; + final XYSeries waterSupplySeries = new XYSeries("Available water supply"); GroupDataModel group = client.getClientDataModel().getGroupDataModel(); - final int infrastructureEfficiency = group.getInfrastructureEfficiency(); + final int actualInfrastructureEfficiency = group.getInfrastructureEfficiency(); final int actualFlowCapacity = group.getIrrigationCapacity(); - for (y = 0; y <= actualFlowCapacity; y++) { - actualFlowCapacitySeries.add(infrastructureEfficiency, y); + for (int y = 0; y <= actualFlowCapacity; y++) { + actualFlowCapacitySeries.add(actualInfrastructureEfficiency, y); } - for(x =0; x<=client.getRoundConfiguration().getMaximumInfrastructureEfficiency();x++){ - y = group.calculateFlowCapacity(x); - potentialFlowCapacitySeries.add(x,y); + RoundConfiguration roundConfiguration = client.getRoundConfiguration(); + int maximumInfrastructureEfficiency = roundConfiguration.getMaximumInfrastructureEfficiency(); + int waterSupplyCapacity = roundConfiguration.getWaterSupplyCapacity(); + for(int x = 0; x <= maximumInfrastructureEfficiency; x++){ + int flowCapacity = group.calculateFlowCapacity(x); + potentialFlowCapacitySeries.add(x,flowCapacity); + waterSupplySeries.add(x, waterSupplyCapacity); } final int infrastructureEfficiencyBeforeInvestment = group.getInfrastructureEfficiencyBeforeInvestment(); final int irrigationCapacityBeforeInvestment = group.getIrrigationCapacityBeforeInvestment(); - for (y = 0; y <= irrigationCapacityBeforeInvestment; y++) { + for (int y = 0; y <= irrigationCapacityBeforeInvestment; y++) { initialInfrastructureEfficiencySeries.add(infrastructureEfficiencyBeforeInvestment, y); } + final XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(initialInfrastructureEfficiencySeries); data.addSeries(actualFlowCapacitySeries); data.addSeries(potentialFlowCapacitySeries); + data.addSeries(waterSupplySeries); - // data.addSeries(actualFlowCapacitySeriesY); - final JFreeChart chart = ChartFactory.createXYLineChart( "Water Delivery Capacity vs. Infrastructure Efficiency", "Infrastructure Efficiency", Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-11-16 20:39:30 UTC (rev 364) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/MainIrrigationGameWindow.java 2009-11-17 00:42:32 UTC (rev 365) @@ -373,7 +373,6 @@ tokensEarnedSeries.add(waterApplied, tokensEarned); } - XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(tokensEarnedSeries); data.addSeries(currentWaterAppliedSeries); @@ -387,6 +386,7 @@ true, false ); + chart.setAntiAlias(true); return new ChartPanel(chart); } Modified: irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java =================================================================== --- irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java 2009-11-16 20:39:30 UTC (rev 364) +++ irrigation/trunk/src/main/java/edu/asu/commons/irrigation/client/TokenInvestmentPieChartPanel.java 2009-11-17 00:42:32 UTC (rev 365) @@ -18,7 +18,12 @@ import edu.asu.commons.net.Identifier; /** + * $Id$ + * * Presents the group contributions as a pie chart. + * + * @author <a href='mailto:All...@as...'>Allen Lee</a> + * @version $Rev$ */ public class TokenInvestmentPieChartPanel extends JPanel { @@ -30,7 +35,7 @@ setLayout(new BorderLayout()); } - public void setClientData(final ClientData clientData) { + public void initialize(final ClientData clientData) { final PieDataset dataset = createPieDataset(clientData); final JFreeChart chart = createChart(dataset); if (chartPanel != null) { @@ -45,42 +50,22 @@ * Creates a pie dataset out of the client * @return a sample dataset. */ - private PieDataset createPieDataset(ClientData clientData) { + private PieDataset createPieDataset(ClientData thisClientData) { final DefaultPieDataset defaultPieDataset = new DefaultPieDataset(); - GroupDataModel groupDataModel = clientData.getGroupDataModel(); + GroupDataModel groupDataModel = thisClientData.getGroupDataModel(); Map<Identifier,ClientData>clientDataMap = groupDataModel.getClientDataMap(); - for (ClientData currentClientData : clientDataMap.values()) { + for (ClientData clientData : clientDataMap.values()) { StringBuilder labelBuilder = new StringBuilder(); - if (currentClientData.getId().equals(clientData.getId())) { - labelBuilder.append("You"); + labelBuilder.append(clientData.getPriorityString()); + if (clientData.getId().equals(thisClientData.getId())) { + labelBuilder.append(" (You)"); } - else { - labelBuilder.append(currentClientData.getPriorityString()); - } - labelBuilder.append(" invested ").append(currentClientData.getInvestedTokens()).append(" token(s)"); - defaultPieDataset.setValue(labelBuilder.toString(), currentClientData.getInvestedTokens()); + labelBuilder.append(" invested ").append(clientData.getInvestedTokens()).append(" token(s)"); + defaultPieDataset.setValue(labelBuilder.toString(), clientData.getInvestedTokens()); } return defaultPieDataset; } - // **************************************************************************** - // * JFREECHART DEVELOPER GUIDE * - // * The JFreeChart Developer Guide, written by David Gilbert, is available * - // * to purchase from Object Refinery Limited: * - // * * - // * http://www.object-refinery.com/jfreechart/guide.html * - // * * - // * Sales are used to provide funding for the JFreeChart project - please * - // * support us so that we can continue developing free software. * - // **************************************************************************** - - /** - * Creates a chart. - * - * @param dataset the dataset. - * - * @return a chart. - */ private JFreeChart createChart(final PieDataset dataset) { final JFreeChart chart = ChartFactory.createPieChart( @@ -94,11 +79,10 @@ final PiePlot plot = (PiePlot) chart.getPlot(); //plot.setLabelGenerator(new CustomLabelGenerator()); plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); - plot.setNoDataMessage("No data available"); + plot.setNoDataMessage("No contributions were made."); plot.setCircular(false); plot.setLabelGap(0.02); return chart; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |