Skip to content

Commit

Permalink
[#76] ScoreUI moved out of SwingChemistryLines.
Browse files Browse the repository at this point in the history
  • Loading branch information
soulne4ny committed Dec 18, 2012
1 parent 09a548f commit 1057746
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
16 changes: 2 additions & 14 deletions Swing/src/com/yarcat/chemistrylines/swing/SwingChemistryLines.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,25 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTextArea;

import com.yarcat.chemistrylines.game.GameLogic;
import com.yarcat.chemistrylines.game.GameLogic.GameListener;
import com.yarcat.chemistrylines.game.GameLogic.InvalidMove;
import com.yarcat.chemistrylines.game.Scorer;
import com.yarcat.chemistrylines.game.Scorer.ScoreListener;
import com.yarcat.chemistrylines.swing.SwingField.FieldButton;
import com.yarcat.chemistrylines.view.SelectionInView;

class SwingChemistryLines implements GameListener, MouseListener, ScoreListener {
class SwingChemistryLines implements GameListener, MouseListener {

private final SwingField mFieldUI;
private final GameLogic mGame;
private final JTextArea mScoreUI;
private SwingPreview mPreviewUI;
private DefferedCleanerUI mCleanerUI;

public SwingChemistryLines(GameLogic game, SwingField fieldUI,
SwingPreview previewUI, JTextArea scoreUI) {
SwingPreview previewUI) {
mFieldUI = fieldUI;
mGame = game;
mPreviewUI = previewUI;
mCleanerUI = null;
mScoreUI = scoreUI;
}

void refresh() {
Expand Down Expand Up @@ -116,12 +110,6 @@ public void onFieldChange(GameLogic game) {
refresh();
}

@Override
public void onScoreChange(Scorer scorer) {
mScoreUI.setText("");
mScoreUI.append(scorer.get());
}

@Override
public void onInit(GameLogic game) {
refresh();
Expand Down
20 changes: 20 additions & 0 deletions Swing/src/com/yarcat/chemistrylines/swing/SwingScore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.yarcat.chemistrylines.swing;

import javax.swing.JTextArea;

import com.yarcat.chemistrylines.game.Scorer;
import com.yarcat.chemistrylines.game.Scorer.ScoreListener;

public class SwingScore implements ScoreListener {
public final JTextArea textArea;

public SwingScore() {
textArea = new JTextArea();
}

@Override
public void onScoreChange(Scorer scorer) {
textArea.setText("");
textArea.append(scorer.get());
}
}
13 changes: 8 additions & 5 deletions Swing/src/com/yarcat/chemistrylines/swing/SwingUIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Builder {
SwingPreview mPreviewUI;
PreviewButton[] mPreview;
SwingChemistryLines mGameUI;
JTextArea mScoreUI;

public SwingChemistryLines newInstance() {
Field field = new RectField(mCols, mRows);
Expand All @@ -59,11 +58,8 @@ public SwingChemistryLines newInstance() {
mGame = mGameFactory.newInstance(field);
mFieldUI = new SwingField(mGame, mButtons);
mPreviewUI = new SwingPreview(mGame, mPreview);
mScoreUI = new JTextArea();
mGameUI =
new SwingChemistryLines(mGame, mFieldUI, mPreviewUI, mScoreUI);
mGameUI = new SwingChemistryLines(mGame, mFieldUI, mPreviewUI);
mGame.setChangeListener(mGameUI);
mGame.getScorer().setScoreListener(mGameUI);

JFrame f =
new JFrame("Chemistry Lines - " + mGameFactory.getModeName());
Expand Down Expand Up @@ -134,6 +130,7 @@ protected Container createPreviewPane(PreviewButton[] preview) {
private Component createScorePane() {
Panel p = new Panel();
p.add(style.defaultColor(new JLabel("Score:")));
JTextArea mScoreUI = createScoreUI().textArea;
p.add(mScoreUI);
style.frame(mScoreUI);
mScoreUI.setEditable(false);
Expand All @@ -144,6 +141,12 @@ private Component createScorePane() {
return p;
}

private SwingScore createScoreUI() {
SwingScore r = new SwingScore();
mGame.getScorer().setScoreListener(r);
return r;
}

protected Container createRightPane() {
Panel p = new Panel();
style.defaultColor(p);
Expand Down

0 comments on commit 1057746

Please sign in to comment.