Lots of work towards team and player panels.
Created graphics for player panel. Fleshed out team and player panels.
@ -66,7 +66,7 @@
|
||||
destfile="${build.dir}/${app.name}-${app.version}.${build.number}.jar"
|
||||
basedir="${build.dir}/classes">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="com.jdbernard.teammaker.TeamMaker"/>
|
||||
<attribute name="Main-Class" value="com.jdbernard.teammaker.ProfessionalPickup"/>
|
||||
<attribute name="SplashScreen-Image" value="splash.png"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
|
BIN
lib/slf4j-api-1.6.1.jar
Executable file
BIN
lib/slf4j-log4j12-1.6.1.jar
Executable file
@ -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
|
||||
|
BIN
resources/board.xcf
Normal file
2
resources/default-teammakerrc
Normal file
@ -0,0 +1,2 @@
|
||||
base-point-value=1
|
||||
team.size=4
|
BIN
resources/plus1T1.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/plus1T2.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/plus2T1.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/plus2T2.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/plus3T1.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/plus3T2.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/reboundT1.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
resources/reboundT2.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
resources/turnover.png
Normal file
After Width: | Height: | Size: 342 B |
BIN
resources/turnoverT1.png
Normal file
After Width: | Height: | Size: 445 B |
BIN
resources/turnoverT2.png
Normal file
After Width: | Height: | Size: 446 B |
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ public class Player implements Comparable<Player> {
|
||||
|
||||
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<Player> {
|
||||
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() {
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
28
src/com/jdbernard/teammaker/Test.groovy
Normal file
@ -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()
|
||||
}
|
||||
}
|