[virtualcommons-svn] commit/foraging: alllee: refactoring instructions and tweaking TrustGamePanel
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2011-11-18 22:25:19
|
1 new commit in foraging: https://bitbucket.org/virtualcommons/foraging/changeset/5e1f60ad6394/ changeset: 5e1f60ad6394 user: alllee date: 2011-11-18 23:25:08 summary: refactoring instructions and tweaking TrustGamePanel UI a bit, colors need more work. affected #: 4 files diff -r e2b29db0ddf574438e03859936a33e9c9107aa49 -r 5e1f60ad639478149e012ed2aa7471798c795cbd src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java --- a/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java +++ b/src/main/java/edu/asu/commons/foraging/conf/RoundConfiguration.java @@ -569,7 +569,7 @@ } public StringBuilder getCurrentRoundInstructions() { - return buildInstructions(new StringBuilder()); + return buildAllInstructions(new StringBuilder()); } /** @@ -585,21 +585,22 @@ * @param instructionsBuilder * @return */ - public StringBuilder buildInstructions(StringBuilder instructionsBuilder) { + public StringBuilder buildAllInstructions(StringBuilder instructionsBuilder) { + // add the quiz instructions if the quiz is enabled. if (isFirstRound()) { instructionsBuilder.append(getGeneralInstructions()); - instructionsBuilder.append(getInstructions()); } - else { - // FIXME: dirty hack, need to fix after we paginate things - instructionsBuilder.append(getInstructions()); - addAllSpecialInstructions(instructionsBuilder); - } - // and add the quiz instructions if the quiz is enabled. - if (isQuizEnabled()) { - instructionsBuilder.append(getQuizInstructions()); - } - return instructionsBuilder; + return isQuizEnabled() + ? buildInstructions(instructionsBuilder).append(getQuizInstructions()) + : buildInstructions(instructionsBuilder); + } + + public StringBuilder buildInstructions() { + return buildInstructions(new StringBuilder()); + } + + public StringBuilder buildInstructions(StringBuilder instructionsBuilder) { + return addAllSpecialInstructions(instructionsBuilder.append(getInstructions())); } public StringBuilder addAllSpecialInstructions(StringBuilder instructionsBuilder) { @@ -632,7 +633,7 @@ return instructionsBuilder; } else { - return instructionsBuilder.append("<h1>Additional instructions</h1><hr><ul>").append(builder).append("</ul>"); + return instructionsBuilder.append("<h2>Additional instructions</h2><hr><ul>").append(builder).append("</ul>"); } } @@ -709,4 +710,8 @@ return String.format("Round %d of %d\n\t%s", allParameters.indexOf(this) + 1, allParameters.size(), getProperties()); } + public String getQuizInstructionsWithoutInputs() { + return getQuizInstructions().replaceAll("<input.*value=\"[\\w]+\">", ""); + } + } diff -r e2b29db0ddf574438e03859936a33e9c9107aa49 -r 5e1f60ad639478149e012ed2aa7471798c795cbd src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java --- a/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java +++ b/src/main/java/edu/asu/commons/foraging/ui/GameWindow2D.java @@ -219,22 +219,18 @@ } client.transmit(new QuizResponseEvent(client.getId(), actualAnswers, incorrectAnswers)); - StringBuilder builder = new StringBuilder(); + StringBuilder builder = configuration.buildInstructions(); setQuestionColors(correctAnswers, "black"); setQuestionColors(incorrectAnswers, "red"); if (incorrectAnswers.isEmpty()) { - builder.append(configuration.getInstructions()); - configuration.addAllSpecialInstructions(builder); // notify the server and also notify the participant. builder.append("<br><b>Congratulations!</b> You have answered all questions correctly."); setInstructions(builder.toString()); } else { - String currentInstructions = instructionsBuilder.toString(); + // add the quiz instructions back, but remove all inputs + builder.append(configuration.getQuizInstructionsWithoutInputs()); // remove all inputs. - currentInstructions = currentInstructions.replaceAll("<input.*value=\"[\\w]+\">", ""); - System.err.println("new instructions: " + currentInstructions); - builder.append(currentInstructions); Collections.sort(incorrectAnswers); Collections.sort(correctAnswers); HTMLEditorKit editorKit = (HTMLEditorKit) instructionsEditorPane.getEditorKit(); @@ -494,8 +490,8 @@ case KeyEvent.VK_8: case KeyEvent.VK_9: if (!dataModel.isSanctioningAllowed()) { - // get rid of magic constants - displayErrorMessage("You may not reduce other participants tokens at this time."); + // FIXME: get rid of magic constants +// displayErrorMessage("You may not reduce other participants tokens at this time."); return; } if (client.canPerformRealTimeSanction()) { @@ -764,7 +760,7 @@ public void showInstructions() { final RoundConfiguration roundConfiguration = dataModel.getRoundConfiguration(); instructionsBuilder.delete(0, instructionsBuilder.length()); - roundConfiguration.buildInstructions(instructionsBuilder); + roundConfiguration.buildAllInstructions(instructionsBuilder); // and add the quiz instructions if the quiz is enabled. SwingUtilities.invokeLater(new Runnable() { public void run() { diff -r e2b29db0ddf574438e03859936a33e9c9107aa49 -r 5e1f60ad639478149e012ed2aa7471798c795cbd src/main/java/edu/asu/commons/foraging/ui/SubjectView.java --- a/src/main/java/edu/asu/commons/foraging/ui/SubjectView.java +++ b/src/main/java/edu/asu/commons/foraging/ui/SubjectView.java @@ -86,8 +86,8 @@ if (subjectFieldOfVision) { viewSubjectsRadius = configuration.getViewSubjectsRadius(); viewSubjectsField = new Circle(dataModel.getCurrentPosition(), viewSubjectsRadius); - fieldOfVisionXOffset = (dw / 3.0); - fieldOfVisionYOffset = (dh / 3.0); + fieldOfVisionXOffset = (dw * 0.3); + fieldOfVisionYOffset = (dh * 0.3); } } super.setup(configuration); @@ -162,7 +162,7 @@ double x = Math.ceil(scaleXDouble(topLeftCorner.x) + fieldOfVisionXOffset); double y = Math.ceil(scaleYDouble(topLeftCorner.y) + fieldOfVisionYOffset); double diameter = radius * 2.0d; - diameter = Math.min(scaleXDouble(diameter), scaleYDouble(diameter)) + (dw * 0.75); + diameter = Math.min(scaleXDouble(diameter), scaleYDouble(diameter)) + (dw * 0.85); Ellipse2D.Double circle = new Ellipse2D.Double(x, y, diameter, diameter); // clip the rendered part of the Field of vision circle that crosses the playing boundary graphics2D.setClip(circle); diff -r e2b29db0ddf574438e03859936a33e9c9107aa49 -r 5e1f60ad639478149e012ed2aa7471798c795cbd src/main/java/edu/asu/commons/foraging/ui/TrustGamePanel.java --- a/src/main/java/edu/asu/commons/foraging/ui/TrustGamePanel.java +++ b/src/main/java/edu/asu/commons/foraging/ui/TrustGamePanel.java @@ -1,5 +1,6 @@ package edu.asu.commons.foraging.ui; +import java.awt.Color; import java.awt.Component; import javax.swing.ButtonModel; @@ -9,6 +10,7 @@ import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; @@ -84,6 +86,7 @@ } } + @SuppressWarnings("unused") @Deprecated private class PlayerTwoInputColumnCellEditor extends DefaultCellEditor { private static final long serialVersionUID = -981239232309467766L; @@ -121,7 +124,8 @@ this.client = client; setRoundConfiguration(client.getCurrentRoundConfiguration()); TableColumn column = playerTwoTable.getColumnModel().getColumn(2); - column.setCellEditor(new DefaultCellEditor(new JComboBox()) { + column.setCellEditor(new DefaultCellEditor(new JComboBox()) { + @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean selected, int row, int column) { JComboBox combo = (JComboBox) super.getTableCellEditorComponent(table, value, selected, row, column); combo.removeAllItems(); @@ -132,6 +136,19 @@ return combo; } }); + playerTwoTable.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + if (column == 2) { + setBackground(Color.YELLOW); + } + else { + setBackground(Color.LIGHT_GRAY); + } + return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + } + + }); } public void setRoundConfiguration(RoundConfiguration configuration) { Repository URL: https://bitbucket.org/virtualcommons/foraging/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. |