diff --git a/build.xml b/build.xml
index 94efa70..a18872a 100644
--- a/build.xml
+++ b/build.xml
@@ -66,7 +66,7 @@
destfile="${build.dir}/${app.name}-${app.version}.${build.number}.jar"
basedir="${build.dir}/classes">
-
+
diff --git a/lib/slf4j-api-1.6.1.jar b/lib/slf4j-api-1.6.1.jar
new file mode 100755
index 0000000..42e0ad0
Binary files /dev/null and b/lib/slf4j-api-1.6.1.jar differ
diff --git a/lib/slf4j-log4j12-1.6.1.jar b/lib/slf4j-log4j12-1.6.1.jar
new file mode 100755
index 0000000..873d119
Binary files /dev/null and b/lib/slf4j-log4j12-1.6.1.jar differ
diff --git a/project.properties b/project.properties
index faa0772..8363b06 100644
--- a/project.properties
+++ b/project.properties
@@ -1,7 +1,7 @@
-#Fri, 27 Aug 2010 05:37:05 -0500
+#Sun, 29 Aug 2010 22:59:56 -0500
#Mon Jul 05 23:10:39 CDT 2010
app.version=0.4.0
-build.number=9
+build.number=36
src.dir=src
lib.dir=lib
build.dir=build
diff --git a/resources/board.xcf b/resources/board.xcf
new file mode 100644
index 0000000..7c04889
Binary files /dev/null and b/resources/board.xcf differ
diff --git a/resources/default-teammakerrc b/resources/default-teammakerrc
new file mode 100644
index 0000000..0a6d5d6
--- /dev/null
+++ b/resources/default-teammakerrc
@@ -0,0 +1,2 @@
+base-point-value=1
+team.size=4
diff --git a/resources/plus1T1.png b/resources/plus1T1.png
new file mode 100644
index 0000000..bcec2ba
Binary files /dev/null and b/resources/plus1T1.png differ
diff --git a/resources/plus1T2.png b/resources/plus1T2.png
new file mode 100644
index 0000000..1e0014d
Binary files /dev/null and b/resources/plus1T2.png differ
diff --git a/resources/plus2T1.png b/resources/plus2T1.png
new file mode 100644
index 0000000..072299e
Binary files /dev/null and b/resources/plus2T1.png differ
diff --git a/resources/plus2T2.png b/resources/plus2T2.png
new file mode 100644
index 0000000..b0bfb48
Binary files /dev/null and b/resources/plus2T2.png differ
diff --git a/resources/plus3T1.png b/resources/plus3T1.png
new file mode 100644
index 0000000..2298d05
Binary files /dev/null and b/resources/plus3T1.png differ
diff --git a/resources/plus3T2.png b/resources/plus3T2.png
new file mode 100644
index 0000000..9dcf52b
Binary files /dev/null and b/resources/plus3T2.png differ
diff --git a/resources/reboundT1.png b/resources/reboundT1.png
new file mode 100644
index 0000000..c3578a1
Binary files /dev/null and b/resources/reboundT1.png differ
diff --git a/resources/reboundT2.png b/resources/reboundT2.png
new file mode 100644
index 0000000..64daab1
Binary files /dev/null and b/resources/reboundT2.png differ
diff --git a/resources/turnover.png b/resources/turnover.png
new file mode 100644
index 0000000..f0559ef
Binary files /dev/null and b/resources/turnover.png differ
diff --git a/resources/turnoverT1.png b/resources/turnoverT1.png
new file mode 100644
index 0000000..87dcc08
Binary files /dev/null and b/resources/turnoverT1.png differ
diff --git a/resources/turnoverT2.png b/resources/turnoverT2.png
new file mode 100644
index 0000000..b78e1af
Binary files /dev/null and b/resources/turnoverT2.png differ
diff --git a/src/com/jdbernard/teammaker/Game.groovy b/src/com/jdbernard/teammaker/Game.groovy
index b161fda..e848b7f 100644
--- a/src/com/jdbernard/teammaker/Game.groovy
+++ b/src/com/jdbernard/teammaker/Game.groovy
@@ -3,6 +3,16 @@ package com.jdbernard.teammaker
public class Game {
static int BASE_POINT_VALUE = 1
+ public static enum Team {
+ TEAM1("T1"), TEAM2("T2");
+
+ public final String suffix;
+
+ private Team(String suffix) { this.suffix = suffix }
+
+ public String toString() { return "Team ${ordinal() + 1}" }
+ }
+
// lists of players for each team
List team1
List team2
@@ -33,4 +43,9 @@ public class Game {
public int getTeamTurnovers(List team) {
return team.sum { turnovers[(it.name)] ?: 0 }
}
+
+ public List getTeam(Team team) {
+ if (team == Team.TEAM1) return team1
+ else return team2
+ }
}
diff --git a/src/com/jdbernard/teammaker/Player.groovy b/src/com/jdbernard/teammaker/Player.groovy
index 077e28b..b3ea8b9 100644
--- a/src/com/jdbernard/teammaker/Player.groovy
+++ b/src/com/jdbernard/teammaker/Player.groovy
@@ -11,8 +11,8 @@ public class Player implements Comparable {
public int getPlusMinus() {
if (games.size() == 0) return 0
- int plusMinus games.sum { game ->
- if (game.team1.contains(this)) {
+ int plusMinus = games.sum { game ->
+ if (game.team1.contains(this))
return game.team1Score - game.team2Score
else return game.team2Score - game.team1Score
}
@@ -26,7 +26,7 @@ public class Player implements Comparable {
points += (game.twoPointers[(name)] ?: 0) * (Game.BASE_POINT_VALUE)
}
- return (games.size() == 0 ? 0 : points /= games.size())
+ return (games.size() == 0 ? 0 : points / games.size())
}
public float getReboundsPerGame() {
diff --git a/src/com/jdbernard/teammaker/PlayerListCellRenderer.groovy b/src/com/jdbernard/teammaker/PlayerListCellRenderer.groovy
index 5c860c4..8a3d1b9 100644
--- a/src/com/jdbernard/teammaker/PlayerListCellRenderer.groovy
+++ b/src/com/jdbernard/teammaker/PlayerListCellRenderer.groovy
@@ -14,7 +14,7 @@ public class PlayerListCellRenderer extends JPanel implements ListCellRenderer {
boolean showStats
boolean colored
- private TeamMaker teamMaker
+ private ProfessionalPickup teamMaker
private JLabel nameLabel
private JLabel statsLabel
diff --git a/src/com/jdbernard/teammaker/PlayerPanel.groovy b/src/com/jdbernard/teammaker/PlayerPanel.groovy
index 43c8fcd..ac55ff4 100644
--- a/src/com/jdbernard/teammaker/PlayerPanel.groovy
+++ b/src/com/jdbernard/teammaker/PlayerPanel.groovy
@@ -1,19 +1,124 @@
package com.jdbernard.teammaker
+import groovy.beans.Bindable
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+import static java.awt.event.MouseEvent.BUTTON1 as LEFT_BUTTON
+import static java.awt.event.MouseEvent.BUTTON2 as RIGHT_BUTTON
+
public class PlayerPanel {
/* ======== MODEL ======== */
+ static def swing = ProfessionalPickup.swing
+ static def icons = [:]
+
+ TeamPanel teamPanel
+ Logger log = LoggerFactory.getLogger(getClass())
+
// GUI Components
class View {
def panel
+ def nameLabel
+ def twoPtrButton
+ def twoPtAttemptsButton
+ def threePtrButton
+ def threePtAttemptsButton
+ def rebsButton
+ def toversButton
}
- View view
+ View view = new View()
class Model {
+ @Bindable Player player
+ @Bindable Game game
+ @Bindable Game.Team team
}
- Model model
+ Model model = new Model()
/* ======== VIEW ======== */
+
+ private void initGUI() {
+ view.panel = swing.hbox {
+ hstrut(5)
+ view.nameLabel = label(model.player.name)
+ hstrut(5)
+ view.twoPtrButton = button(
+ icon: getIcon("plus${Game.BASE_POINT_VALUE}"),
+ iconTextGap: 0, margin: [0, 0, 0, 0],
+ actionPerformed: { evt ->
+ if (LEFT_BUTTON == evt.button) {
+ model.game.twoPointers[(model.player.name)]++
+ model.game.twoPointAttemps[(model.player.name)]++
+ } else {
+ model.game.twoPointers[(model.player.name)]--
+ model.game.twoPointAttemps[(model.player.name)]--
+ }},
+ toolTipText: "Click to add a successful " +
+ Game.BASE_POINT_VALUE + " point shot.\nRight-click to " +
+ "undo (remove the shot).")
+ hstrut(5)
+ view.threePtrButton = button(
+ icon: getIcon("plus${Game.BASE_POINT_VALUE + 1}"),
+ iconTextGap: 0, margin: [0, 0, 0, 0],
+ actionPerformed: { evt ->
+ if (LEFT_BUTTON == evt.button) {
+ model.game.threePointers[(model.player.name)]++
+ model.game.threePointAttempts[(model.player.name)]++
+ } else {
+ model.game.threePointers[(model.player.name)]--
+ model.game.threePointAttempts[(model.player.name)]--
+ }},
+ toolTipText: "Click to add a successful " +
+ (Game.BASE_POINT_VALUE + 1) + " point shot.\nRight-click " +
+ "to undo (remove the shot).")
+ hstrut(5)
+ view.rebsButton = button(
+ icon: getIcon("rebound"),
+ iconTextGap: 0, margin: [0, 0, 0, 0],
+ actionPerformed: { evt ->
+ if (LEFT_BUTTON == evt.button)
+ model.game.rebounds[(model.player.name)]++
+ else model.game.rebounds[(model.player.name)]-- },
+ toolTipText: "Click to add a rebound.\nRight-click to undo.")
+ hstrut(5)
+ view.toversButton = button(
+ icon: getIcon("turnover"),
+ iconTextGap: 0, margin: [0, 0, 0, 0],
+ actionPerformed: { evt ->
+ if (LEFT_BUTTON == evt.button)
+ model.game.turnovers[(model.player.name)]++
+ else model.game.turnovers[(model.player.name)]-- },
+ toolTipText: "Click to add a turnover.\nRight click to undo.")
+ hglue()
+ }
+ }
+
+ private def getIcon(String type) {
+ String iconKey = type + model.team.suffix
+
+ if (!icons[iconKey]) {
+
+ if (log.isDebugEnabled())
+ log.debug("Looking for icon resources: /${iconKey}.png")
+
+ icons[iconKey] = swing.imageIcon("/${iconKey}.png")
+ }
+
+ return icons[iconKey]
+ }
+
+ /* ======== CONTROLLER ======== */
+
+ public PlayerPanel(TeamPanel teamPanel, Player player) {
+ this.teamPanel = teamPanel
+ model.player = player
+ model.game = teamPanel.model.game
+ model.team = teamPanel.model.team
+
+ initGUI()
+ }
+}
diff --git a/src/com/jdbernard/teammaker/ProfessionalPickup.groovy b/src/com/jdbernard/teammaker/ProfessionalPickup.groovy
index f43f05d..254ad2d 100644
--- a/src/com/jdbernard/teammaker/ProfessionalPickup.groovy
+++ b/src/com/jdbernard/teammaker/ProfessionalPickup.groovy
@@ -11,6 +11,8 @@ import javax.swing.JFrame
import javax.swing.JOptionPane
import org.apache.log4j.Logger
+import static com.jdbernard.teammaker.Game.Team.*
+
public class ProfessionalPickup {
/* ======== MODEL ======== */
@@ -233,7 +235,7 @@ public class ProfessionalPickup {
.withInputStream { is -> teammakerrc.text = is.text }
// load config
- teammakerrc.withInputStream { model.config.load(is) }
+ teammakerrc.withInputStream { model.config.load(it) }
// set configured properties
Game.BASE_POINT_VALUE = model.config.getProperty('base-point-value',
@@ -253,11 +255,11 @@ public class ProfessionalPickup {
}
private void setTeamSize() {
- def newSize = JOptionPane.showMessageDialog(view.frame,
+ def newSize = JOptionPane.showInputDialog(view.frame,
"Enter the new team size: ", "Set Team Size...",
JOptionPane.QUESTION_MESSAGE)
- if (newSize.isInteger()) model.teamSize = newSize.toInteger()
+ if (newSize && newSize.isInteger()) model.teamSize = newSize.toInteger()
else JOptionPane.showMessageDialog(view.frame,
"$newSize is not a valid team size (it is not a number...).",
"Set Team Size...", JOptionPane.ERROR_MESSAGE)
@@ -291,9 +293,14 @@ public class ProfessionalPickup {
}
- private void declareLoser(int teamNum) {
+ public void declareWinner(Game.Team team) {
+ if (team == TEAM1) declareLoser(TEAM2)
+ else declareLoser(TEAM1)
+ }
+
+ public void declareLoser(Game.Team team) {
model.sittingPlayers.each { it.gamesSat++ }
- def teamPlayers = playersForTeam(teamNum)
+ def teamPlayers = playersForTeam(team)
teamPlayers.each { player ->
player.gamesSat = 0
model.sittingPlayers << player
@@ -337,8 +344,8 @@ public class ProfessionalPickup {
}
- private void populate(int teamNum) {
- def teamPlayers = playersForTeam(teamNum)
+ private void populate(Game.Team team) {
+ def teamPlayers = playersForTeam(team)
while (teamPlayers.size() < model.teamSize) {
def player = model.playerChooser.choose(model.sittingPlayers)
teamPlayers << player
@@ -348,15 +355,15 @@ public class ProfessionalPickup {
refreshGUI();
}
- private benchPlayer(Player p, int teamNum) {
- def teamPlayers = playersForTeam(teamNum)
+ private benchPlayer(Player p, Game.Team team) {
+ def teamPlayers = playersForTeam(team)
teamPlayers.remove(p)
model.sittingPlayers << p
refreshGUI()
}
- private assignPlayer(Player p, int teamNum) {
- def teamPlayers = playersForTeam(teamNum)
+ private assignPlayer(Player p, Game.Team team) {
+ def teamPlayers = playersForTeam(team)
model.sittingPlayers.remove(p)
teamPlayers << p
refreshGUI()
@@ -410,13 +417,13 @@ public class ProfessionalPickup {
refreshGUI()
}
- private List playersForTeam(int teamNum) {
- if (teamNum == 1) return model.team1Players
+ private List playersForTeam(Game.Team team) {
+ if (team == Game.Team.TEAM1) return model.team1Players
else return model.team2Players
}
- private List listForTeam(int teamNum) {
- if (teamNum == 1) return view.team1List
+ private List listForTeam(Game.Team team) {
+ if (team == Game.Team.TEAM11) return view.team1List
else return view.team2List
}
}
diff --git a/src/com/jdbernard/teammaker/TeamPanel.groovy b/src/com/jdbernard/teammaker/TeamPanel.groovy
index db6ed78..c731771 100644
--- a/src/com/jdbernard/teammaker/TeamPanel.groovy
+++ b/src/com/jdbernard/teammaker/TeamPanel.groovy
@@ -1,23 +1,97 @@
package com.jdbernard.teammaker
+import groovy.beans.Bindable
+import javax.swing.BoxLayout
+
+import static com.jdbernard.teammaker.Game.Team.*
+
public class TeamPanel {
/* ======== MODEL ======== */
+ private static def swing = ProfessionalPickup.swing
+
+ ProfessionalPickup main
+
// GUI components
class View {
def panel
+ def teamStatsBox
+ def scoreLabel
+ def reboundsLabel
+ def turnoversLabel
+ def playerPanels
+ def winsButton
}
View view = new View()
class Model {
- @Bindable String name
+ //@Bindable String name
+ @Bindable Game game
+ @Bindable Game.Team team
+ @Bindable List players
}
Model model = new Model()
/* ======== VIEW ======== */
- view.panel = swing.panel(border: titledBorder(model.name)) {
+ private void initGUI() {
+ view.panel = swing.vbox {
+
+ view.teamStatsBox = hbox {
+
+ vstrut(5)
+ view.scoreLabel = label("0")
+ vstrut(5)
+ view.reboundsLabel = label("Rebs: 0")
+ vstrut(5)
+ view.turnoversLabel = label("T/Os: 0")
+ hglue()
+ view.winsButton = button("Winners",
+ actionPerformed: { main.declareWinner(model.team) })
+ vstrut(5)
+ }
+ }
+
+ view.playerPanels = []
+ }
+
+ private void initPlayerPanels(List players) {
+ view.playerPanels.each { view.panel.remove(it.view.panel) }
+ view.playerPanels.clear()
+
+ // create and add player panels
+ model.players.each { player ->
+ def playerPanel = new PlayerPanel(this, player)
+ view.panel << playerPanel.view.panel
+ view.playerPanels << playerPanel.view.panel
+ }
+
+ }
+
+ /* ======== CONTROLLER ======== */
+
+ public TeamPanel(ProfessionalPickup main, Game.Team team) {
+ this.main = main
+ model.team = team
+
+ initGUI()
+ }
+
+ public void newGame(Game game) {
+ model.game = game
+ model.players = game.getTeam(model.team)
+
+ view.panel.border = swing.titledBorder(model.team.toString())
+
+ initPlayerPanels(model.players)
+ }
+
+ public void updateStats() {
+ view.scoreLabel = model.game.getTeamScore(model.players)
+ view.reboundsLabel = model.game.getTeamRebounds(model.players)
+ view.turnoversLabel = model.game.getTeamTurnovers(model.players)
+ }
}
diff --git a/src/com/jdbernard/teammaker/Test.groovy b/src/com/jdbernard/teammaker/Test.groovy
new file mode 100644
index 0000000..043b697
--- /dev/null
+++ b/src/com/jdbernard/teammaker/Test.groovy
@@ -0,0 +1,28 @@
+package com.jdbernard.teammaker
+
+import groovy.swing.SwingBuilder
+
+public class Test {
+
+ public static void main(String[] args) {
+ Game.BASE_POINT_VALUE = 2
+ Player bob = new Player(name: "Bob", games: [], gamesSat: 0, benched: false)
+ Player stan = new Player(name: "Stan", games: [], gamesSat: 0, benched: false)
+
+ Game game = new Game(team1: [bob], team2: [stan])
+
+ def tp = new TeamPanel(null, Game.Team.TEAM1)
+ tp.newGame(game)
+
+ def pp = new PlayerPanel(tp, bob)
+ def swing = new SwingBuilder()
+
+ def frame = swing.frame(size: [400, 400]) {
+ vbox {
+ widget(pp.view.panel)
+ }
+ }
+
+ frame.show()
+ }
+}