[virtualcommons-svn] commit/irrigation: alllee: organize imports + formatting
Status: Beta
Brought to you by:
alllee
From: Bitbucket <com...@bi...> - 2012-03-28 06:54:58
|
1 new commit in irrigation: https://bitbucket.org/virtualcommons/irrigation/changeset/e5ca3f6531ad/ changeset: e5ca3f6531ad user: alllee date: 2012-03-28 08:54:35 summary: organize imports + formatting affected #: 34 files diff -r 4ea2f146b01c7d00a451884fdcdeabb43627836f -r e5ca3f6531adb3c270830bc97289560c5d2af71b src/main/java/edu/asu/commons/irrigation/client/Ball.java --- a/src/main/java/edu/asu/commons/irrigation/client/Ball.java +++ b/src/main/java/edu/asu/commons/irrigation/client/Ball.java @@ -3,66 +3,67 @@ import java.util.Random; public class Ball { - - private int size = 3; - - public int x; - - public int y; - - public int moveX; - public int moveY; - - public int xUpperBound; - public int xLowerBound; - public int yUpperBound; - public int yLowerBound; - - //just one global variable speciying the ten potential positions of the balls - private int position; - - public Ball(Random generator){ - - this.x = generator.nextInt(100); - this.y = generator.nextInt(100); - this.xUpperBound = 100; - this.yUpperBound = 100; - this.xLowerBound = 0; - this.yLowerBound = 0; - this.moveX = generator.nextInt(15); - this.moveY = generator.nextInt(10); - /*this.moveX = 3; - this.moveY = 3; - */ - setPosition(0); - } - - public void setPosition(int position) { - this.position = position; - } - public int getBallSize(){ - return size; - } - - public void setX(int x){ - this.x = x; - } - - public void setY(int y){ - this.y = y; - } + private int size = 3; - public int getPosition() { - return position; - } + public int x; - public int getX() { - return x; - } + public int y; - public int getY() { - return y; - } - + public int moveX; + public int moveY; + + public int xUpperBound; + public int xLowerBound; + public int yUpperBound; + public int yLowerBound; + + // just one global variable speciying the ten potential positions of the balls + private int position; + + public Ball(Random generator) { + + this.x = generator.nextInt(100); + this.y = generator.nextInt(100); + this.xUpperBound = 100; + this.yUpperBound = 100; + this.xLowerBound = 0; + this.yLowerBound = 0; + this.moveX = generator.nextInt(15); + this.moveY = generator.nextInt(10); + /* + * this.moveX = 3; + * this.moveY = 3; + */ + setPosition(0); + } + + public void setPosition(int position) { + this.position = position; + } + + public int getBallSize() { + return size; + } + + public void setX(int x) { + this.x = x; + } + + public void setY(int y) { + this.y = y; + } + + public int getPosition() { + return position; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + } \ No newline at end of file diff -r 4ea2f146b01c7d00a451884fdcdeabb43627836f -r e5ca3f6531adb3c270830bc97289560c5d2af71b src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java --- a/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java +++ b/src/main/java/edu/asu/commons/irrigation/client/CanalPanel.java @@ -138,8 +138,8 @@ || (particles[i].getPosition() == 3) || (particles[i].getPosition() == 4) || (particles[i].getPosition() == 5)) { - if (!((gates[particles[i].getPosition() - 1].isClosed()) - && particles[i].getY() >= (gates[particles[i].getPosition() - 1].getY() + gates[particles[i].getPosition() - 1].getHeight()))) + if (!((gates[particles[i].getPosition() - 1].isClosed()) + && particles[i].getY() >= (gates[particles[i].getPosition() - 1].getY() + gates[particles[i].getPosition() - 1].getHeight()))) graphics.fillOval(particles[i].x, particles[i].y, particles[i].getBallSize(), particles[i].getBallSize()); } else { @@ -180,10 +180,10 @@ * FIXME: needs major refactoring */ private void updateGates(List<ClientData> sortedClientDataList) { - ClientData thisClientData= clientDataModel.getClientData(); + ClientData thisClientData = clientDataModel.getClientData(); for (int i = 1; i < 6; i++) { if (gates[i - 1].isOpen()) { - if (restrictedVisibility && ! thisClientData.isImmediateNeighbor(sortedClientDataList.get(i-1))) { + if (restrictedVisibility && !thisClientData.isImmediateNeighbor(sortedClientDataList.get(i - 1))) { continue; } if (!(gates[i - 1].getHeight() - gateHeight < 0)) { @@ -203,7 +203,7 @@ // opening gate logic if (gates[i].isOpen()) { - if (restrictedVisibility && ! thisClientData.isImmediateNeighbor(sortedClientDataList.get(i))) { + if (restrictedVisibility && !thisClientData.isImmediateNeighbor(sortedClientDataList.get(i))) { continue; } gates[i].setx1(gates[i].getx2()); @@ -217,7 +217,7 @@ } if (gates[0].isOpen()) { - if (restrictedVisibility && ! thisClientData.isImmediateNeighbor(sortedClientDataList.get(0))) { + if (restrictedVisibility && !thisClientData.isImmediateNeighbor(sortedClientDataList.get(0))) { continue; } gates[0].setx1(gates[0].getx2()); @@ -265,12 +265,12 @@ * This will process the balls according to their position */ private void process(int i, List<ClientData> sortedClients, ClientData thisClientData) { - + switch (particles[i].getPosition()) { case 0: if ((particles[i].x >= (reservoirWidth - gateBuffer) && particles[i].x <= reservoirWidth) - && (particles[i].y >= reservoirHeight - (int) (maximumIrrigationCapacity * canalHeightMultiplier) && particles[i].y <= reservoirHeight)) + && (particles[i].y >= reservoirHeight - (int) (maximumIrrigationCapacity * canalHeightMultiplier) && particles[i].y <= reservoirHeight)) { particles[i].setPosition(1); setBounds(i); @@ -293,12 +293,13 @@ case 1: if (gates[0].isOpen() && (particles[i].x >= gates[0].getOpeningsX() && particles[i].x <= (gates[0].getOpeningsX() + gateBuffer)) - && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) + && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) { - if (restrictedVisibility && sortedClients.get(0).isImmediateNeighbor(thisClientData) || ! restrictedVisibility) + if (restrictedVisibility && sortedClients.get(0).isImmediateNeighbor(thisClientData) || !restrictedVisibility) { - // if we are in the restricted visibility condition AND gate 0 is an immediate neighbor of this client OR we are not in a restricted visibility condition at all, put this ball in the - // gate (or at least I *think* this is what Sanket's god-awful code is doing). + // if we are in the restricted visibility condition AND gate 0 is an immediate neighbor of this client OR we are not in a restricted + // visibility condition at all, put this ball in the + // gate (or at least I *think* this is what Sanket's god-awful code is doing). particles[i].setPosition(7); // directly pass in the information setBounds(i); @@ -321,7 +322,7 @@ if (gates[1].isOpen() && (particles[i].x >= gates[1].getOpeningsX() && particles[i].x <= (gates[1] .getOpeningsX() + gateBuffer)) - && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) + && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) { if (!restrictedVisibility || (restrictedVisibility && sortedClients.get(1).isImmediateNeighbor(thisClientData))) { particles[i].setPosition(8); @@ -329,7 +330,7 @@ setBounds(i); break; } - } + } setBounds(i); if (particles[i].getX() > particles[i].xUpperBound) { particles[i].setPosition(3); @@ -364,10 +365,10 @@ } break; case 4: - if (gates[3].isOpen() + if (gates[3].isOpen() && (particles[i].x >= gates[3].getOpeningsX() && particles[i].x <= (gates[3] .getOpeningsX() + gateBuffer)) - && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) + && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) { if (!restrictedVisibility || (restrictedVisibility && !sortedClients.get(3).isImmediateNeighbor(thisClientData))) { particles[i].setPosition(10); @@ -375,7 +376,7 @@ setBounds(i); break; } - } + } setBounds(i); if (particles[i].getX() > particles[i].xUpperBound) { particles[i].setPosition(5); @@ -390,7 +391,7 @@ if (gates[4].isOpen() && (particles[i].x >= gates[4].getOpeningsX() && particles[i].x <= (gates[4] .getOpeningsX() + gateBuffer)) - && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) + && (particles[i].y >= reservoirHeight - gateBuffer && particles[i].y <= reservoirHeight)) { if (!restrictedVisibility || (restrictedVisibility && !sortedClients.get(4).isImmediateNeighbor(thisClientData))) { particles[i].setPosition(11); @@ -398,7 +399,7 @@ setBounds(i); break; } - } + } setBounds(i); if (particles[i].getX() > particles[i].xUpperBound) { particles[i].setPosition(6); diff -r 4ea2f146b01c7d00a451884fdcdeabb43627836f -r e5ca3f6531adb3c270830bc97289560c5d2af71b src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java --- a/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java +++ b/src/main/java/edu/asu/commons/irrigation/client/ChatPanel.java @@ -32,7 +32,7 @@ /** * $Id$ * - * Chat panel used to communicate with other players. + * Chat panel used to communicate with other players. * * FIXME: randomize mappings from handle (e.g., A -> 1, B -> 2, C -> 3 ...) so that it's * not linear. @@ -53,7 +53,7 @@ private TextEntryPanel textEntryPanel; private JEditorPane chatInstructionsPane; - + private JTextField chatField; public ChatPanel(IrrigationClient irrigationClient) { @@ -96,16 +96,16 @@ add(timeLeftPanel, BorderLayout.PAGE_START); add(chatField, BorderLayout.CENTER); -// add(sendButton, BorderLayout.PAGE_END); + // add(sendButton, BorderLayout.PAGE_END); } private void sendMessage() { String message = chatField.getText(); - if (message != null && ! message.isEmpty() && targetIdentifier != null) { + if (message != null && !message.isEmpty() && targetIdentifier != null) { displayMessage(getChatHandle(getClientId()) + " (you): ", message); - chatField.setText(""); - irrigationClient.transmit(new ChatRequest(getClientId(), message, targetIdentifier)); - } + chatField.setText(""); + irrigationClient.transmit(new ChatRequest(getClientId(), message, targetIdentifier)); + } chatField.requestFocusInWindow(); } @@ -120,7 +120,7 @@ private final static String HANDLE_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static String[] HANDLES; - + private Map<Identifier, String> chatHandles = new HashMap<Identifier, String>(); private void addStylesToMessageWindow() { @@ -157,14 +157,14 @@ messageWindow.setEditable(false); messageWindow.setBackground(Color.WHITE); messageScrollPane = new JScrollPane(messageWindow); -// UserInterfaceUtils.addStyles(messageWindow, 16); + // UserInterfaceUtils.addStyles(messageWindow, 16); addStylesToMessageWindow(); textEntryPanel = new TextEntryPanel(); chatInstructionsPane = UserInterfaceUtils.createInstructionsEditorPane(); JScrollPane chatInstructionsScrollPane = new JScrollPane(chatInstructionsPane); add(chatInstructionsScrollPane, BorderLayout.PAGE_START); add(messageScrollPane, BorderLayout.CENTER); -// add(participantButtonPanel, BorderLayout.EAST); + // add(participantButtonPanel, BorderLayout.EAST); add(textEntryPanel, BorderLayout.PAGE_END); addFocusListener(this); messageScrollPane.addFocusListener(this); @@ -181,8 +181,7 @@ document.insertString(0, chatHandle, document.getStyle("bold")); document.insertString(chatHandle.length(), message + "\n", getDefaultStyle()); messageWindow.setCaretPosition(0); - } - catch (BadLocationException e) { + } catch (BadLocationException e) { e.printStackTrace(); } } @@ -199,14 +198,14 @@ chatHandles.put(participants.get(i), HANDLES[i]); } } - + public Identifier getClientId() { - return irrigationClient.getId(); + return irrigationClient.getId(); } - public void setFocusInChatField() { - chatField.requestFocusInWindow(); - } + public void setFocusInChatField() { + chatField.requestFocusInWindow(); + } @Override public void focusGained(FocusEvent e) { diff -r 4ea2f146b01c7d00a451884fdcdeabb43627836f -r e5ca3f6531adb3c270830bc97289560c5d2af71b src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java --- a/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java +++ b/src/main/java/edu/asu/commons/irrigation/client/ClientDataModel.java @@ -19,18 +19,18 @@ * $Id$ * * The client side data model, simply wraps a GroupDataModel. - * + * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev$ */ -public class ClientDataModel implements DataModel<ServerConfiguration, RoundConfiguration> { +public class ClientDataModel implements DataModel<ServerConfiguration, RoundConfiguration> { private static final long serialVersionUID = -3424256672940188027L; private GroupDataModel groupDataModel; - + private IrrigationClient client; - + private ServerConfiguration serverConfiguration; private RoundConfiguration roundConfiguration; private final EventChannel eventChannel; @@ -44,31 +44,31 @@ } public ClientData getClientData() { - return groupDataModel.getClientData( getId() ); + return groupDataModel.getClientData(getId()); } - + public String getPriorityString() { - return getClientData().getPriorityString(); + return getClientData().getPriorityString(); } - + public Identifier getId() { return client.getId(); } - + public List<Identifier> getAllClientIdentifiers() { return new ArrayList<Identifier>(groupDataModel.getAllClientIdentifiers()); } - public synchronized void initialize(RoundStartedEvent event) { + public synchronized void initialize(RoundStartedEvent event) { groupDataModel.clear(); setGroupDataModel(event.getGroupDataModel()); - setTimeLeft( getRoundConfiguration().getRoundDurationInSeconds() ); + setTimeLeft(getRoundConfiguration().getRoundDurationInSeconds()); } - public int getPriority(){ + public int getPriority() { return getClientData().getPriority(); } - + public void update(ClientUpdateEvent clientUpdateEvent) { setGroupDataModel(clientUpdateEvent.getGroupDataModel()); setTimeLeft(clientUpdateEvent.getTimeLeft()); @@ -89,11 +89,11 @@ public void setRoundConfiguration(RoundConfiguration roundConfiguration) { this.roundConfiguration = roundConfiguration; } - + public ServerConfiguration getServerConfiguration() { return serverConfiguration; } - + public void setGroupDataModel(GroupDataModel groupDataModel) { this.groupDataModel = groupDataModel; } @@ -101,15 +101,15 @@ public GroupDataModel getGroupDataModel() { return groupDataModel; } - + public Map<Identifier, ClientData> getClientDataMap() { - Map<Identifier, ClientData> clientDataMap = groupDataModel.getClientDataMap(); + Map<Identifier, ClientData> clientDataMap = groupDataModel.getClientDataMap(); // used by StringTemplate to determine whether or not the ClientData it's rendering values for // is this client. - getClientData().setSelf(true); - return clientDataMap; + getClientData().setSelf(true); + return clientDataMap; } - + public List<ClientData> getClientDataSortedByPriority() { Map<Identifier, ClientData> clientDataMap = getClientDataMap(); ArrayList<ClientData> clientDataList = new ArrayList<ClientData>(clientDataMap.values()); @@ -138,29 +138,28 @@ return serverConfiguration; } - public List<ClientData> getOrderedVisibleClients() { - if (getRoundConfiguration().isRestrictedVisibility()) { - // FIXME: replace hard-coded immediate neighbor check with field of vision radius from RoundConfiguration - ArrayList<ClientData> neighbors = new ArrayList<ClientData>(); - List<ClientData> sortedClients = getClientDataSortedByPriority(); - ClientData thisClientData = getClientData(); - int thisClientIndex = sortedClients.indexOf(thisClientData); - if (thisClientIndex > 0) { - // upstream neighbor - neighbors.add(sortedClients.get(thisClientIndex - 1)); - } - // this is needed for the charts, but probably weird for general-purpose usage - neighbors.add(thisClientData); - if (thisClientIndex < sortedClients.size() - 1) { - // downstream neighbor - neighbors.add(sortedClients.get(thisClientIndex + 1)); - } - return neighbors; - } - else { - return getClientDataSortedByPriority(); - } - } - + public List<ClientData> getOrderedVisibleClients() { + if (getRoundConfiguration().isRestrictedVisibility()) { + // FIXME: replace hard-coded immediate neighbor check with field of vision radius from RoundConfiguration + ArrayList<ClientData> neighbors = new ArrayList<ClientData>(); + List<ClientData> sortedClients = getClientDataSortedByPriority(); + ClientData thisClientData = getClientData(); + int thisClientIndex = sortedClients.indexOf(thisClientData); + if (thisClientIndex > 0) { + // upstream neighbor + neighbors.add(sortedClients.get(thisClientIndex - 1)); + } + // this is needed for the charts, but probably weird for general-purpose usage + neighbors.add(thisClientData); + if (thisClientIndex < sortedClients.size() - 1) { + // downstream neighbor + neighbors.add(sortedClients.get(thisClientIndex + 1)); + } + return neighbors; + } + else { + return getClientDataSortedByPriority(); + } + } } diff -r 4ea2f146b01c7d00a451884fdcdeabb43627836f -r e5ca3f6531adb3c270830bc97289560c5d2af71b src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java --- a/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java +++ b/src/main/java/edu/asu/commons/irrigation/client/ExperimentGameWindow.java @@ -41,8 +41,8 @@ /** * $Id$ * - * The root experiment window placed in the client's JFrame. - * + * The root experiment window placed in the client's JFrame. + * * @author <a href='mailto:All...@as...'>Allen Lee</a> * @version $Rev$ */ @@ -51,7 +51,7 @@ private static final long serialVersionUID = -5636795631355367711L; private ClientDataModel clientDataModel; - + private ChatPanel chatPanel; private HtmlEditorPane instructionsEditorPane; @@ -64,7 +64,7 @@ private InfrastructureEfficiencyChartPanel infrastructureEfficiencyChartPanel; private IrrigationClient client; - + private GamePanel irrigationGamePanel; private StringBuilder instructionsBuilder = new StringBuilder(); @@ -79,10 +79,10 @@ private TokenContributionChartPanel tokenContributionChartPanel; -// private CanalAnimationPanel canalAnimationPanel; + // private CanalAnimationPanel canalAnimationPanel; private CardLayout cardLayout; - + private JLabel investedTokensLabel; public ExperimentGameWindow(IrrigationClient client) { @@ -90,7 +90,7 @@ this.clientDataModel = client.getClientDataModel(); initialize(); } - + private void initialize() { cardLayout = new CardLayout(); setLayout(cardLayout); @@ -102,7 +102,7 @@ addToCardLayout(getContributionInformationPanel()); setInstructions(getServerConfiguration().getWelcomeInstructions()); } - + private void addToCardLayout(Component component) { add(component, component.getName()); } @@ -149,7 +149,7 @@ 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); + // instructionsPanel.add(getQuizNavigationPanel(), BorderLayout.PAGE_END); } return instructionsPanel; } @@ -157,12 +157,12 @@ private ServerConfiguration getServerConfiguration() { return clientDataModel.getServerConfiguration(); } - + private JLabel getInvestedTokensLabel() { if (investedTokensLabel == null) { investedTokensLabel = new JLabel(); } - return investedTokensLabel; + return investedTokensLabel; } private JTextField getInvestedTokensTextField() { @@ -188,12 +188,11 @@ investedTokensLabel.setText(""); setInstructions("Please wait while the server computes your total flow capacity based on your group's total token contribution investment."); addCenterComponent(getInstructionsPanel()); - } + } else { investedTokensLabel.setText("Please enter a number between 0 and 10"); } - } - catch(NumberFormatException e){ + } catch (NumberFormatException e) { investedTokensLabel.setText("Please enter a number between 0 and 10"); } } @@ -245,17 +244,17 @@ private void info(String message) { System.err.println(message); } - + public void showDebriefing(boolean showExitInstructions) { instructionsBuilder.delete(0, instructionsBuilder.length()); instructionsBuilder.append(clientDataModel.getRoundConfiguration().generateClientDebriefing(clientDataModel, showExitInstructions)); setInstructions(instructionsBuilder.toString()); } - + private void setInstructions(String instructions) { instructionsEditorPane.setText(instructions); } - + private void displayInstructions(final String instructions) { SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -264,10 +263,11 @@ } }); } - + private ActionListener createQuizListener(final ServerConfiguration configuration) { return new ActionListener() { private Map<String, String> quizAnswers = configuration.getQuizAnswers(); + public synchronized void actionPerformed(ActionEvent e) { FormActionEvent formEvent = (FormActionEvent) e; Properties actualAnswers = formEvent.getData(); @@ -283,20 +283,20 @@ String correctAnswer = entry.getValue(); String actualAnswer = actualAnswers.getProperty(questionNumber); if (actualAnswer == null || actualAnswer.trim().isEmpty()) { - missingQuestions.add(number); - continue; + missingQuestions.add(number); + continue; } - ((correctAnswer.equals(actualAnswer)) ? correctQuestionNumbers : incorrectQuestionNumbers).add(questionNumber); + ((correctAnswer.equals(actualAnswer)) ? correctQuestionNumbers : incorrectQuestionNumbers).add(questionNumber); } int numberOfMissingQuestions = missingQuestions.size(); if (numberOfMissingQuestions > 0) { - Collections.sort(missingQuestions); - JOptionPane.showMessageDialog(ExperimentGameWindow.this, "Please enter a quiz answer for questions " + missingQuestions); - return; + Collections.sort(missingQuestions); + JOptionPane.showMessageDialog(ExperimentGameWindow.this, "Please enter a quiz answer for questions " + missingQuestions); + return; } else if (numberOfMissingQuestions == 1) { - JOptionPane.showMessageDialog(ExperimentGameWindow.this, "Please enter a quiz answer for question " + missingQuestions.get(0)); - return; + JOptionPane.showMessageDialog(ExperimentGameWindow.this, "Please enter a quiz answer for question " + missingQuestions.get(0)); + return; } setQuestionColors(correctQuestionNumbers, "blue"); setQuestionColors(incorrectQuestionNumbers, "red"); @@ -309,7 +309,7 @@ }; } - + private void setQuestionColors(List<String> questionNumbers, String color) { HTMLEditorKit editorKit = (HTMLEditorKit) instructionsEditorPane.getEditorKit(); StyleSheet styleSheet = editorKit.getStyleSheet(); @@ -320,8 +320,8 @@ } public void displayContributionInformation(final ClientData clientData) { - final RoundConfiguration configuration = clientDataModel.getRoundConfiguration(); - final String contributionSummary = configuration.generateContributionSummary(clientData); + final RoundConfiguration configuration = clientDataModel.getRoundConfiguration(); + final String contributionSummary = configuration.generateContributionSummary(clientData); SwingUtilities.invokeLater(new Runnable() { public void run() { contributionInformationEditorPane.setText(contributionSummary); @@ -332,7 +332,7 @@ }); irrigationGamePanel.setClientDataModel(clientDataModel); } - + public JPanel getContributionInformationPanel() { if (contributionInformationPanel == null) { contributionInformationPanel = new JPanel(); @@ -359,7 +359,6 @@ return panel; } - public void showTokenInvestmentScreen() { Runnable runnable = new Runnable() { public void run() { @@ -374,7 +373,7 @@ public void updateRoundInstructions() { RoundConfiguration roundConfiguration = clientDataModel.getRoundConfiguration(); - if (! roundConfiguration.isFirstRound()) { + if (!roundConfiguration.isFirstRound()) { instructionsBuilder.append(roundConfiguration.generateUpdatedInstructions(clientDataModel)); displayInstructions(instructionsBuilder.toString()); } @@ -393,13 +392,14 @@ public void run() { startTimer(getServerConfiguration().getChatDuration() * 1000L); chatPanel.initialize(clientDataModel.getAllClientIdentifiers()); - addCenterComponent( chatPanel ); + addCenterComponent(chatPanel); chatPanel.setFocusInChatField(); } }); } private Timer timer; + private void startTimer(final long waitTime) { final long endTime = waitTime + System.currentTimeMillis(); if (timer == null) { @@ -407,9 +407,9 @@ public void actionPerformed(ActionEvent event) { final long timeRemaining = endTime - System.currentTimeMillis(); if (timeRemaining < 0) { - showTokenInvestmentScreen(); + showTokenInvestmentScreen(); getInvestedTokensTextField().requestFocusInWindow(); -// chatPanel.displayMessage("", "---- chat round ending ----"); + // chatPanel.displayMessage("", "---- chat round ending ----"); timer.stop(); timer = null; } @@ -421,7 +421,7 @@ timer.start(); } } - + public void showQuiz() { SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -430,20 +430,20 @@ } }); } - + public void showGameScreenshot() { displayInstructions(getServerConfiguration().getGameScreenshotInstructions()); } - /** + /** * Invoked when the show instructions button is pressed. */ public void showInstructions() { - if (clientDataModel == null || clientDataModel.getRoundConfiguration().isFirstRound()) { - displayInstructions(getServerConfiguration().getInitialInstructions()); - } - else { - displayInstructions(clientDataModel.getRoundConfiguration().getInstructions()); - } + if (clientDataModel == null || clientDataModel.getRoundConfiguration().isFirstRound()) { + displayInstructions(getServerConfiguration().getInitialInstructions()); + } + else { + displayInstructions(clientDataModel.getRoundConfiguration().getInstructions()); + } } } diff -r 4ea2f146b01c7d00a451884fdcdeabb43627836f -r e5ca3f6531adb3c270830bc97289560c5d2af71b src/main/java/edu/asu/commons/irrigation/client/GamePanel.java --- a/src/main/java/edu/asu/commons/irrigation/client/GamePanel.java +++ b/src/main/java/edu/asu/commons/irrigation/client/GamePanel.java @@ -27,10 +27,11 @@ import edu.asu.commons.irrigation.conf.ServerConfiguration; import edu.asu.commons.irrigation.model.ClientData; + /** * $Id$ * - * Primary in-round game interface window for the irrigation game + * Primary in-round game interface window for the irrigation game * * FIXME: refactor layout, currently a hodge podge of fixed sizes * @@ -41,335 +42,340 @@ private static final long serialVersionUID = 5900368694556557132L; - private CanalPanel canalPanel; + private CanalPanel canalPanel; - private JPanel jPanelMain = null; - //this contains the CanalPanel - private JPanel centerPanel = null; - //this contains the upstream and downstream Panel - private JPanel jPanelUpStreamWindow = null; - private JPanel jPanelDownStreamWindow = null; - private JPanel mainInterfacePanel = null; + private JPanel jPanelMain = null; + // this contains the CanalPanel + private JPanel centerPanel = null; + // this contains the upstream and downstream Panel + private JPanel jPanelUpStreamWindow = null; + private JPanel jPanelDownStreamWindow = null; + private JPanel mainInterfacePanel = null; - private IrrigationClient client; + private IrrigationClient client; - private JProgressBar timeLeftProgressBar; + private JProgressBar timeLeftProgressBar; - private ClientDataModel clientDataModel; // @jve:decl-index=0: + private ClientDataModel clientDataModel; // @jve:decl-index=0: - private MiddleWindowPanel middleWindowPanel; + private MiddleWindowPanel middleWindowPanel; - private JLabel gateSwitchLabel = null; + private JLabel gateSwitchLabel = null; - private JLabel scoreBoardLabel = null; + private JLabel scoreBoardLabel = null; - private JButton gateSwitchButton; + private JButton gateSwitchButton; - private boolean open; + private boolean open; -// private JTextField waterCollectedTextField; -// private JLabel waterCollectedLabel; -// private JTextField tokensNotInvestedTextField; -// private JLabel tokensNotInvestedLabel; -// private JTextField tokensEarnedTextField; -// private JLabel tokensEarnedLabel; -// private JTextField totalTokensEarnedTextField; -// private JLabel totalTokensEarnedLabel; - - private JLabel irrigationCapacityLabel; - private JLabel waterSupplyLabel; + // private JTextField waterCollectedTextField; + // private JLabel waterCollectedLabel; + // private JTextField tokensNotInvestedTextField; + // private JLabel tokensNotInvestedLabel; + // private JTextField tokensEarnedTextField; + // private JLabel tokensEarnedLabel; + // private JTextField totalTokensEarnedTextField; + // private JLabel totalTokensEarnedLabel; - private JTextField irrigationCapacityTextField; - private JTextField waterSupplyTextField; + private JLabel irrigationCapacityLabel; + private JLabel waterSupplyLabel; - public GamePanel(IrrigationClient client) { - super(); - this.client = client; - setName("main irrigation game window"); - initGuiComponents(); - } + private JTextField irrigationCapacityTextField; + private JTextField waterSupplyTextField; - private void initGuiComponents() { - this.setLayout(new BorderLayout(4,4)); - this.setSize(1130, 558); - this.add(getPanel(),null); + public GamePanel(IrrigationClient client) { + super(); + this.client = client; + setName("main irrigation game window"); + initGuiComponents(); + } - } + private void initGuiComponents() { + this.setLayout(new BorderLayout(4, 4)); + this.setSize(1130, 558); + this.add(getPanel(), null); - private JPanel getPanel() { - if(jPanelMain == null){ - jPanelMain = new JPanel(); - jPanelMain.setLayout(new BorderLayout(4,4)); - jPanelMain.setBackground(Color.WHITE); - jPanelMain.setForeground(Color.BLACK); - JPanel upperPanel = new JPanel(); - upperPanel.setLayout(new BoxLayout(upperPanel, BoxLayout.X_AXIS)); - upperPanel.add(getIrrigationCapacityLabel()); - upperPanel.add(Box.createHorizontalGlue()); - upperPanel.add(getWaterSupplyLabel()); - jPanelMain.add(upperPanel, BorderLayout.NORTH); - jPanelMain.add(getMainInterfacePanel(), BorderLayout.CENTER); - return jPanelMain; - } - return jPanelMain; - } + } - private JPanel getMainInterfacePanel() { - if(mainInterfacePanel == null){ - scoreBoardLabel = new JLabel(""); - scoreBoardLabel.setBounds(new Rectangle(582,225+100+35,530,20)); - scoreBoardLabel.setHorizontalAlignment(SwingConstants.CENTER); - gateSwitchLabel = new JLabel(""); - gateSwitchLabel.setBounds(new Rectangle(13,225+100+35,530,20)); - gateSwitchLabel.setHorizontalAlignment(SwingConstants.CENTER); - mainInterfacePanel = new JPanel(); - mainInterfacePanel.setLayout(null); - mainInterfacePanel.setName("Main interface panel"); - mainInterfacePanel.setBackground(Color.WHITE); - mainInterfacePanel.add(getCenterPanel(),null); - mainInterfacePanel.add(getTimeLeftProgressBar(), null); - mainInterfacePanel.add(gateSwitchLabel, null); - mainInterfacePanel.add(scoreBoardLabel, null); - } - return mainInterfacePanel; - } + private JPanel getPanel() { + if (jPanelMain == null) { + jPanelMain = new JPanel(); + jPanelMain.setLayout(new BorderLayout(4, 4)); + jPanelMain.setBackground(Color.WHITE); + jPanelMain.setForeground(Color.BLACK); + JPanel upperPanel = new JPanel(); + upperPanel.setLayout(new BoxLayout(upperPanel, BoxLayout.X_AXIS)); + upperPanel.add(getIrrigationCapacityLabel()); + upperPanel.add(Box.createHorizontalGlue()); + upperPanel.add(getWaterSupplyLabel()); + jPanelMain.add(upperPanel, BorderLayout.NORTH); + jPanelMain.add(getMainInterfacePanel(), BorderLayout.CENTER); + return jPanelMain; + } + return jPanelMain; + } - private JProgressBar getTimeLeftProgressBar() { - if (timeLeftProgressBar == null) { - timeLeftProgressBar = new JProgressBar(0, 50); - timeLeftProgressBar.setBounds(new Rectangle(360, 15, 370, 17)); - timeLeftProgressBar.setStringPainted(true); - } - return timeLeftProgressBar; - } - /** - * This method initializes jPanel - * - * @return javax.swing.JPanel - */ - private JPanel getCenterPanel() { - if (centerPanel == null) { - centerPanel = new JPanel(); - centerPanel.setLayout(null); - centerPanel.setBounds(new Rectangle(13, 64, 1098, 123)); - } - return centerPanel; - } + private JPanel getMainInterfacePanel() { + if (mainInterfacePanel == null) { + scoreBoardLabel = new JLabel(""); + scoreBoardLabel.setBounds(new Rectangle(582, 225 + 100 + 35, 530, 20)); + scoreBoardLabel.setHorizontalAlignment(SwingConstants.CENTER); + gateSwitchLabel = new JLabel(""); + gateSwitchLabel.setBounds(new Rectangle(13, 225 + 100 + 35, 530, 20)); + gateSwitchLabel.setHorizontalAlignment(SwingConstants.CENTER); + mainInterfacePanel = new JPanel(); + mainInterfacePanel.setLayout(null); + mainInterfacePanel.setName("Main interface panel"); + mainInterfacePanel.setBackground(Color.WHITE); + mainInterfacePanel.add(getCenterPanel(), null); + mainInterfacePanel.add(getTimeLeftProgressBar(), null); + mainInterfacePanel.add(gateSwitchLabel, null); + mainInterfacePanel.add(scoreBoardLabel, null); + } + return mainInterfacePanel; + } - private JPanel getCanalPanel(ClientDataModel clientDataModel) { - if (canalPanel == null) { - canalPanel = new CanalPanel(clientDataModel); - canalPanel.setSize(new Dimension(1098, 123)); - } - else { - canalPanel.setClientDataModel(clientDataModel); - } - return canalPanel; - } + private JProgressBar getTimeLeftProgressBar() { + if (timeLeftProgressBar == null) { + timeLeftProgressBar = new JProgressBar(0, 50); + timeLeftProgressBar.setBounds(new Rectangle(360, 15, 370, 17)); + timeLeftProgressBar.setStringPainted(true); + } + return timeLeftProgressBar; + } - /** - * This method initializes jPanel1 - * - * @return javax.swing.JPanel - */ - private JPanel getJPanelUpStreamWindow() { - if (jPanelUpStreamWindow == null) { - jPanelUpStreamWindow = new JPanel(); - jPanelUpStreamWindow.setLayout(new BorderLayout()); - jPanelUpStreamWindow.setBackground(new Color(186, 226, 237)); - jPanelUpStreamWindow.setBounds(new Rectangle(13, 225+100+50, 530, 326)); - jPanelUpStreamWindow.add(getGateSwitchButton(), BorderLayout.CENTER); -// jPanelUpStreamWindow.add(getControlPanel(), BorderLayout.SOUTH); - } - return jPanelUpStreamWindow; - } - private final static String OPEN_GATE_LABEL = "OPEN YOUR GATE"; - private final static String CLOSE_GATE_LABEL = "CLOSE YOUR GATE"; - private JButton getGateSwitchButton() { - if (gateSwitchButton == null) { - gateSwitchButton = new JButton(OPEN_GATE_LABEL); - gateSwitchButton.setFont(new Font("sansserif", Font.TRUETYPE_FONT, 18)); - gateSwitchButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - open = !open; - if (open) { - client.openGate(); - gateSwitchButton.setText(CLOSE_GATE_LABEL); - } - else { - client.closeGate(); - gateSwitchButton.setText(OPEN_GATE_LABEL); - } - } - }); - } - return gateSwitchButton; - } - + /** + * This method initializes jPanel + * + * @return javax.swing.JPanel + */ + private JPanel getCenterPanel() { + if (centerPanel == null) { + centerPanel = new JPanel(); + centerPanel.setLayout(null); + centerPanel.setBounds(new Rectangle(13, 64, 1098, 123)); + } + return centerPanel; + } -// private JPanel getControlPanel() { -// JPanel bottomInformationPanel = new JPanel(); -// GroupLayout layout = new GroupLayout(bottomInformationPanel); -// bottomInformationPanel.setLayout(layout); -// layout.setAutoCreateContainerGaps(true); -// layout.setAutoCreateGaps(true); -// -// GroupLayout.SequentialGroup horizontalGroup = layout.createSequentialGroup(); -// ParallelGroup labelsGroup = layout.createParallelGroup(); -// labelsGroup.addComponent(getWaterCollectedLabel()).addComponent(getTokensNotInvestedLabel()).addComponent(getTokensEarnedLabel()).addComponent(getTotalTokensEarnedLabel()); -// -// horizontalGroup.addGroup(labelsGroup); -// -// ParallelGroup textFieldGroup = layout.createParallelGroup(); -// textFieldGroup.addComponent(getWaterCollectedTextField()); -// textFieldGroup.addComponent(getTokensNotInvestedTextField()); -// textFieldGroup.addComponent(getTokensEarnedTextField()); -// textFieldGroup.addComponent(getTotalTokensEarnedTextField()); -// horizontalGroup.addGroup(textFieldGroup); -// layout.setHorizontalGroup(horizontalGroup); -// -// GroupLayout.SequentialGroup verticalGroup = layout.createSequentialGroup(); -// verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) -// .addComponent(getWaterCollectedLabel()).addComponent(getWaterCollectedTextField())); -// -// verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) -// .addComponent(getTokensNotInvestedLabel()).addComponent(getTokensNotInvestedTextField())); -// -// verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) -// .addComponent(getTokensEarnedLabel()).addComponent(getTokensEarnedTextField())); -// -// verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) -// .addComponent(getTotalTokensEarnedLabel()).addComponent(getTotalTokensEarnedTextField())); -// -// layout.setVerticalGroup(verticalGroup); -// return bottomInformationPanel; -// } + private JPanel getCanalPanel(ClientDataModel clientDataModel) { + if (canalPanel == null) { + canalPanel = new CanalPanel(clientDataModel); + canalPanel.setSize(new Dimension(1098, 123)); + } + else { + canalPanel.setClientDataModel(clientDataModel); + } + return canalPanel; + } + + /** + * This method initializes jPanel1 + * + * @return javax.swing.JPanel + */ + private JPanel getJPanelUpStreamWindow() { + if (jPanelUpStreamWindow == null) { + jPanelUpStreamWindow = new JPanel(); + jPanelUpStreamWindow.setLayout(new BorderLayout()); + jPanelUpStreamWindow.setBackground(new Color(186, 226, 237)); + jPanelUpStreamWindow.setBounds(new Rectangle(13, 225 + 100 + 50, 530, 326)); + jPanelUpStreamWindow.add(getGateSwitchButton(), BorderLayout.CENTER); + // jPanelUpStreamWindow.add(getControlPanel(), BorderLayout.SOUTH); + } + return jPanelUpStreamWindow; + } + + private final static String OPEN_GATE_LABEL = "OPEN YOUR GATE"; + private final static String CLOSE_GATE_LABEL = "CLOSE YOUR GATE"; + + private JButton getGateSwitchButton() { + if (gateSwitchButton == null) { + gateSwitchButton = new JButton(OPEN_GATE_LABEL); + gateSwitchButton.setFont(new Font("sansserif", Font.TRUETYPE_FONT, 18)); + gateSwitchButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + open = !open; + if (open) { + client.openGate(); + gateSwitchButton.setText(CLOSE_GATE_LABEL); + } + else { + client.closeGate(); + gateSwitchButton.setText(OPEN_GATE_LABEL); + } + } + }); + } + return gateSwitchButton; + } + + // private JPanel getControlPanel() { + // JPanel bottomInformationPanel = new JPanel(); + // GroupLayout layout = new GroupLayout(bottomInformationPanel); + // bottomInformationPanel.setLayout(layout); + // layout.setAutoCreateContainerGaps(true); + // layout.setAutoCreateGaps(true); + // + // GroupLayout.SequentialGroup horizontalGroup = layout.createSequentialGroup(); + // ParallelGroup labelsGroup = layout.createParallelGroup(); + // labelsGroup.addComponent(getWaterCollectedLabel()).addComponent(getTokensNotInvestedLabel()).addComponent(getTokensEarnedLabel()).addComponent(getTotalTokensEarnedLabel()); + // + // horizontalGroup.addGroup(labelsGroup); + // + // ParallelGroup textFieldGroup = layout.createParallelGroup(); + // textFieldGroup.addComponent(getWaterCollectedTextField()); + // textFieldGroup.addComponent(getTokensNotInvestedTextField()); + // textFieldGroup.addComponent(getTokensEarnedTextField()); + // textFieldGroup.addComponent(getTotalTokensEarnedTextField()); + // horizontalGroup.addGroup(textFieldGroup); + // layout.setHorizontalGroup(horizontalGroup); + // + // GroupLayout.SequentialGroup verticalGroup = layout.createSequentialGroup(); + // verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + // .addComponent(getWaterCollectedLabel()).addComponent(getWaterCollectedTextField())); + // + // verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + // .addComponent(getTokensNotInvestedLabel()).addComponent(getTokensNotInvestedTextField())); + // + // verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + // .addComponent(getTokensEarnedLabel()).addComponent(getTokensEarnedTextField())); + // + // verticalGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE) + // .addComponent(getTotalTokensEarnedLabel()).addComponent(getTotalTokensEarnedTextField())); + // + // layout.setVerticalGroup(verticalGroup); + // return bottomInformationPanel; + // } private JTextField createTextField() { JTextField textField = new JTextField(); textField.setEditable(false); -// textField.setBackground(Color.LIGHT_GRAY); + // textField.setBackground(Color.LIGHT_GRAY); textField.setBackground(Color.YELLOW); return textField; - } - -// private JTextField getWaterCollectedTextField() { -// if (waterCollectedTextField == null) { -// waterCollectedTextField = createTextField(); -// } -// return waterCollectedTextField; -// } -// -// -// -// private JLabel getWaterCollectedLabel() { -// if (waterCollectedLabel == null) { -// waterCollectedLabel = new JLabel("Total water applied to your field: "); -// } -// return waterCollectedLabel; -// } -// -// private JTextField getTokensNotInvestedTextField() { -// if (tokensNotInvestedTextField == null) { -// tokensNotInvestedTextField = createTextField(); -// } -// return tokensNotInvestedTextField; -// } -// private JLabel getTokensNotInvestedLabel() { -// if (tokensNotInvestedLabel == null) { -// tokensNotInvestedLabel = new JLabel("Tokens not invested: "); -// } -// return tokensNotInvestedLabel; -// } -// -// private JTextField getTokensEarnedTextField() { -// if (tokensEarnedTextField == null) { -// tokensEarnedTextField = createTextField(); -// } -// return tokensEarnedTextField; -// } -// private JLabel getTokensEarnedLabel() { -// if (tokensEarnedLabel == null) { -// tokensEarnedLabel = new JLabel("Tokens earned by crop production: "); -// } -// return tokensEarnedLabel; -// } -// -// private JTextField getTotalTokensEarnedTextField() { -// if (totalTokensEarnedTextField == null) { -// totalTokensEarnedTextField = createTextField(); -// } -// return totalTokensEarnedTextField; -// -// } -// -// private JLabel getTotalTokensEarnedLabel() { -// if (totalTokensEarnedLabel == null) { -// totalTokensEarnedLabel = new JLabel("Total tokens earned this round: "); -// } -// return totalTokensEarnedLabel; -// } - - private JLabel getIrrigationCapacityLabel() { - if (irrigationCapacityLabel == null) { - irrigationCapacityLabel = new JLabel(); - irrigationCapacityLabel.setLabelFor(getIrrigationCapacityTextField()); - irrigationCapacityLabel.setFont(new Font("sansserif", Font.BOLD, 16)); - } - return irrigationCapacityLabel; - } + } - private JTextField getIrrigationCapacityTextField() { - if (irrigationCapacityTextField == null) { - irrigationCapacityTextField = createTextField(); - } - return irrigationCapacityTextField; - } - - private JLabel getWaterSupplyLabel() { - if (waterSupplyLabel == null) { - waterSupplyLabel = new JLabel("Water supply: "); - waterSupplyLabel.setLabelFor(getWaterSupplyTextField()); - waterSupplyLabel.setFont(new Font("sansserif", Font.BOLD, 16)); - } - return waterSupplyLabel; - } - private JTextField getWaterSupplyTextField() { - if (waterSupplyTextField == null) { - waterSupplyTextField = createTextField(); - } - return waterSupplyTextField; - } - /** - * This method initializes jPanel3 - * summary scoreboard - * @return javax.swing.JPanel - */ - private JPanel getJPanelDownStreamWindow() { - if (jPanelDownStreamWindow == null) { - jPanelDownStreamWindow = new JPanel(); - jPanelDownStreamWindow.setLayout(new BorderLayout()); - jPanelDownStreamWindow.setBackground(new Color(186, 226, 237)); - jPanelDownStreamWindow.setBounds(new Rectangle(582, 225 + 100+50, 530, 326)); - jPanelDownStreamWindow.add(getWaterCollectedToTokensTable(),BorderLayout.CENTER); - } - return jPanelDownStreamWindow; - } - - private XYSeries currentWaterAppliedSeries = new XYSeries("Current water applied"); + // private JTextField getWaterCollectedTextField() { + // if (waterCollectedTextField == null) { + // waterCollectedTextField = createTextField(); + // } + // return waterCollectedTextField; + // } + // + // + // + // private JLabel getWaterCollectedLabel() { + // if (waterCollectedLabel == null) { + // waterCollectedLabel = new JLabel("Total water applied to your field: "); + // } + // return waterCollectedLabel; + // } + // + // private JTextField getTokensNotInvestedTextField() { + // if (tokensNotInvestedTextField == null) { + // tokensNotInvestedTextField = createTextField(); + // } + // return tokensNotInvestedTextField; + // } + // private JLabel getTokensNotInvestedLabel() { + // if (tokensNotInvestedLabel == null) { + // tokensNotInvestedLabel = new JLabel("Tokens not invested: "); + // } + // return tokensNotInvestedLabel; + // } + // + // private JTextField getTokensEarnedTextField() { + // if (tokensEarnedTextField == null) { + // tokensEarnedTextField = createTextField(); + // } + // return tokensEarnedTextField; + // } + // private JLabel getTokensEarnedLabel() { + // if (tokensEarnedLabel == null) { + // tokensEarnedLabel = new JLabel("Tokens earned by crop production: "); + // } + // return tokensEarnedLabel; + // } + // + // private JTextField getTotalTokensEarnedTextField() { + // if (totalTokensEarnedTextField == null) { + // totalTokensEarnedTextField = createTextField(); + // } + // return totalTokensEarnedTextField; + // + // } + // + // private JLabel getTotalTokensEarnedLabel() { + // if (totalTokensEarnedLabel == null) { + // totalTokensEarnedLabel = new JLabel("Total tokens earned this round: "); + // } + // return totalTokensEarnedLabel; + // } - private ChartPanel getWaterCollectedToTokensTable() { + private JLabel getIrrigationCapacityLabel() { + if (irrigationCapacityLabel == null) { + irrigationCapacityLabel = new JLabel(); + irrigationCapacityLabel.setLabelFor(getIrrigationCapacityTextField()); + irrigationCapacityLabel.setFont(new Font("sansserif", Font.BOLD, 16)); + } + return irrigationCapacityLabel; + } + + private JTextField getIrrigationCapacityTextField() { + if (irrigationCapacityTextField == null) { + irrigationCapacityTextField = createTextField(); + } + return irrigationCapacityTextField; + } + + private JLabel getWaterSupplyLabel() { + if (waterSupplyLabel == null) { + waterSupplyLabel = new JLabel("Water supply: "); + waterSupplyLabel.setLabelFor(getWaterSupplyTextField()); + waterSupplyLabel.setFont(new Font("sansserif", Font.BOLD, 16)); + } + return waterSupplyLabel; + } + + private JTextField getWaterSupplyTextField() { + if (waterSupplyTextField == null) { + waterSupplyTextField = createTextField(); + } + return waterSupplyTextField; + } + + /** + * This method initializes jPanel3 + * summary scoreboard + * + * @return javax.swing.JPanel + */ + private JPanel getJPanelDownStreamWindow() { + if (jPanelDownStreamWindow == null) { + jPanelDownStreamWindow = new JPanel(); + jPanelDownStreamWindow.setLayout(new BorderLayout()); + jPanelDownStreamWindow.setBackground(new Color(186, 226, 237)); + jPanelDownStreamWindow.setBounds(new Rectangle(582, 225 + 100 + 50, 530, 326)); + jPanelDownStreamWindow.add(getWaterCollectedToTokensTable(), BorderLayout.CENTER); + } + return jPanelDownStreamWindow; + } + + private XYSeries currentWaterAppliedSeries = new XYSeries("Current water applied"); + + private ChartPanel getWaterCollectedToTokensTable() { final XYSeries tokensEarnedSeries = new XYSeries("Tokens earned from water applied"); - + for (int waterApplied = 0; waterApplied < 1000; waterApplied++) { - int tokensEarned = ServerConfiguration.getTokensEarned(waterApplied); - tokensEarnedSeries.add(waterApplied, tokensEarned); + int tokensEarned = ServerConfiguration.getTokensEarned(waterApplied); + tokensEarnedSeries.add(waterApplied, tokensEarned); } - + XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(tokensEarnedSeries); data.addSeries(currentWaterAppliedSeries); - JFreeChart chart = ChartFactory.createXYLineChart( + JFreeChart chart = ChartFactory.createXYLineChart( "Water applied to tokens earned", "Cubic feet of water applied to your field", "Tokens earned", @@ -378,104 +384,104 @@ true, true, false - ); - chart.setAntiAlias(true); - return new ChartPanel(chart); - } + ); + chart.setAntiAlias(true); + return new ChartPanel(chart); + } - /** - * Should be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. - */ - public void updateClientStatus(final ClientDataModel clientDataModel) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - int timeLeft = clientDataModel.getTimeLeft(); - String timeLeftString = String.format("%d sec", timeLeft); - timeLeftProgressBar.setValue( timeLeft ); - timeLeftProgressBar.setString(timeLeftString); - // FIXME: figure out how to reliably set the progress bar colors regardless of OS. -// setProgressBarColor(timeLeft); - // only show open gates for immediately neighboring clients. - boolean restrictedVisibility = clientDataModel.getRoundConfiguration().isRestrictedVisibility(); - final ClientData thisClientData = clientDataModel.getClientData(); + /** + * Should be invoked every second throughout the experiment, from a ClientUpdateEvent sent by the server. + */ + public void updateClientStatus(final ClientDataModel clientDataModel) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + int timeLeft = clientDataModel.getTimeLeft(); + String timeLeftString = String.format("%d sec", timeLeft); + timeLeftProgressBar.setValue(timeLeft); + timeLeftProgressBar.setString(timeLeftString); + // FIXME: figure out how to reliably set the progress bar colors regardless of OS. + // setProgressBarColor(timeLeft); + // only show open gates for immediately neighboring clients. + boolean restrictedVisibility = clientDataModel.getRoundConfiguration().isRestrictedVisibility(); + final ClientData thisClientData = clientDataModel.getClientData(); - for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { - if (clientData.isGateOpen()) { - if (restrictedVisibility && ! thisClientData.isImmediateNeighbor(clientData)) { - continue; - } - canalPanel.openGate(clientData.getPriority()); - } - else { - canalPanel.closeGate(clientData.getPriority()); - } - } - ClientData clientData = clientDataModel.getClientData(); -// getWaterCollectedTextField().setText("" + clientData.getWaterCollected()); -// getTokensNotInvestedTextField().setText("" + clientData.getUninvestedTokens()); -// getTokensEarnedTextField().setText("" + clientData.getTokensEarnedFromWaterCollected()); -// getTotalTokensEarnedTextField().setText("" + clientData.getAllTokensEarnedThisRound()); - getMiddleWindowPanel().update(clientDataModel); - - currentWaterAppliedSeries.clear(); - for (int i = 0; i <= clientData.getTokensEarnedFromWaterCollected(); i++) { - currentWaterAppliedSeries.add(clientData.getWaterCollected(), i); - } - } + for (final ClientData clientData : clientDataModel.getClientDataMap().values()) { + if (clientData.isGateOpen()) { + if (restrictedVisibility && !thisClientData.isImmediateNeighbor(clientData)) { + continue; + } + canalPanel.openGate(clientData.getPriority()); + } + else { + canalPanel.closeGate(clientData.getPriority()); + } + } + ClientData clientData = clientDataModel.getClientData(); + // getWaterCollectedTextField().setText("" + clientData.getWaterCollected()); + // getTokensNotInvestedTextField().setText("" + clientData.getUninvestedTokens()); + // getTokensEarnedTextField().setText("" + clientData.getTokensEarnedFromWaterCollected()); + // getTotalTokensEarnedTextField().setText("" + clien... [truncated message content] |