Merged splash and icons commit.

This commit is contained in:
Jonathan Bernard 2010-08-27 06:05:15 -05:00
commit abc8f72beb
4 changed files with 132 additions and 2 deletions

View File

@ -0,0 +1,36 @@
package com.jdbernard.teammaker
public class Game {
static int BASE_POINT_VALUE = 1
// lists of players for each team
List team1
List team2
// stats for each game
Map threePointAttempts = [:]
Map threePointers = [:]
Map twoPointAttempts = [:]
Map twoPointers = [:]
Map rebounds = [:]
Map assists = [:]
Map turnovers = [:]
public int getTeam1Score() { return getTeamScore(team1) }
public int getTeam2Score() { return getTeamScore(team2) }
public int getTeamScore(List team) { return team.sum { getPlayerScore(it) } }
public int getPlayerScore(Player player) {
return (twoPointers[(player.name)] ?: 0) * BASE_POINT_VALUE +
(threePointers[(player.name)] ?: 0) * (BASE_POINT_VALUE + 1)
}
public int getTeamRebounds(List team) {
return team.sum { rebounds[(it.name)] ?: 0 }
}
public int getTeamTurnovers(List team) {
return team.sum { turnovers[(it.name)] ?: 0 }
}
}

View File

@ -1,8 +1,48 @@
package com.jdbernard.teammaker package com.jdbernard.teammaker
public class Player implements Comparable<Player> { public class Player implements Comparable<Player> {
// persistant data
String name String name
List games
// transient data
int gamesSat int gamesSat
boolean benched
public int getPlusMinus() {
if (games.size() == 0) return 0
int plusMinus games.sum { game ->
if (game.team1.contains(this)) {
return game.team1Score - game.team2Score
else return game.team2Score - game.team1Score
}
return plusMinus / games.size()
}
public float getPointsPerGame() {
float points = 0
games.each { game ->
points += (game.threePointers[(name)] ?: 0) * (Game.BASE_POINT_VALUE + 1)
points += (game.twoPointers[(name)] ?: 0) * (Game.BASE_POINT_VALUE)
}
return (games.size() == 0 ? 0 : points /= games.size())
}
public float getReboundsPerGame() {
if (games.size() == 0) return 0
return games.sum { it.rebounds[(name)] ?: 0 } / games.size()
}
public float getAssistsPerGame() {
if (games.size() == 0) return 0
return games.sum { it.assists[(name)] ?: 0 } / games.size()
}
public float getTurnoversPerGame() {
if (games.size() == 0) return 0
else return games.sum { it.turnovers[(name)] ?: 0 } / games.size()
}
public int compareTo(Player that) { public int compareTo(Player that) {
int r = that.gamesSat - this.gamesSat int r = that.gamesSat - this.gamesSat

View File

@ -30,6 +30,8 @@ public class TeamMaker {
def inGamePlayerDropMenu def inGamePlayerDropMenu
def sittingPlayerDropMenu def sittingPlayerDropMenu
def config
protected Logger log = Logger.getLogger(getClass()) protected Logger log = Logger.getLogger(getClass())
PlayerChooser playerChooser = new WeightedChooser(hardLimit: 2) PlayerChooser playerChooser = new WeightedChooser(hardLimit: 2)
@ -75,7 +77,7 @@ public class TeamMaker {
*/ */
private void init() { private void initGUI() {
inGamePlayerDropMenu = swing.popupMenu(/*'Player Options'*/) { inGamePlayerDropMenu = swing.popupMenu(/*'Player Options'*/) {
menuItem('Bench Player',/* enabled: bind { !model.inGame },*/ menuItem('Bench Player',/* enabled: bind { !model.inGame },*/
@ -97,6 +99,9 @@ public class TeamMaker {
model.popupPlayers.each { setGamesSat(it) }}) model.popupPlayers.each { setGamesSat(it) }})
} }
// TODO
// settingsDialog = new SettingsDialog(main: this)
frame = swing.frame(title: "JDB Professional Pickup v$version", frame = swing.frame(title: "JDB Professional Pickup v$version",
iconImages: [swing.imageIcon("/bb128.png").image, iconImages: [swing.imageIcon("/bb128.png").image,
swing.imageIcon("/bb64.png").image, swing.imageIcon("/bb64.png").image,
@ -106,6 +111,21 @@ public class TeamMaker {
size: [600, 400], locationRelativeTo: null, size: [600, 400], locationRelativeTo: null,
defaultCloseOperation: JFrame.EXIT_ON_CLOSE) { defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
menuBar() {
menu('Settings') {
pointsButtonGroup = buttonGroup()
pointsButtonGroup << radioButtonMenuItem("1's and 2's",
actionPerformed: { Game.BASE_POINT_VALUE = 1 })
pointsButtonGroup << radioButtonMenuItem("2's and 3's",
actionPerformed: { Game.BASE_POINT_VALUE = 2 })
separator()
menuItem('Team Size...',
actionPerformed: { setTeamSize() })
}
}
panel() { panel() {
gridBagLayout() gridBagLayout()
@ -201,7 +221,24 @@ public class TeamMaker {
} }
TeamMaker() { TeamMaker() {
init() config = new Properties()
// look for team maker config file
File teammakerrc = new File(System.getProperty('user.home'),
'.teammakerrc')
if (!teammakerrc.exists())
getClass().getResourceAsStream('/default-teammakerrc')
.withInputStream { is -> teammakerrc.text = is.text }
// load config
teammakerrc.withInputStream { config.load(is) }
// set configured properties
Game.BASE_POINT_VALUE = config.getProperty('base-point-value',
'1').toInteger()
model.teamSize = config.getProperty('team.size', '4').toInteger()
initGUI()
} }
/** /**
@ -213,6 +250,17 @@ public class TeamMaker {
return (spots == 0 ? model.teamSize : spots) return (spots == 0 ? model.teamSize : spots)
} }
private void setTeamSize() {
def newSize = JOptionPane.showMessageDialog(frame,
"Enter the new team size: ", "Set Team Size...",
JOptionPane.QUESTION_MESSAGE)
if (newSize.isInteger()) model.teamSize = newSize.toInteger()
else JOptionPane.showMessageDialog(frame,
"$newSize is not a valid team size (it is not a number...).",
"Set Team Size...", JOptionPane.ERROR_MESSAGE)
}
private void addPlayer() { private void addPlayer() {
def name = JOptionPane.showInputDialog(frame, def name = JOptionPane.showInputDialog(frame,
"Enter the new player's name: ", "New Player...", "Enter the new player's name: ", "New Player...",

View File

@ -0,0 +1,6 @@
package com.jdbernard.teammaker
public class TeamPanel {
}