Incremental commit.
This commit is contained in:
parent
abc8f72beb
commit
73284c6fea
19
src/com/jdbernard/teammaker/PlayerPanel.groovy
Normal file
19
src/com/jdbernard/teammaker/PlayerPanel.groovy
Normal file
@ -0,0 +1,19 @@
|
||||
package com.jdbernard.teammaker
|
||||
|
||||
public class PlayerPanel {
|
||||
|
||||
/* ======== MODEL ======== */
|
||||
|
||||
// GUI Components
|
||||
class View {
|
||||
def panel
|
||||
}
|
||||
|
||||
View view
|
||||
|
||||
class Model {
|
||||
}
|
||||
|
||||
Model model
|
||||
|
||||
/* ======== VIEW ======== */
|
@ -11,7 +11,7 @@ import javax.swing.JFrame
|
||||
import javax.swing.JOptionPane
|
||||
import org.apache.log4j.Logger
|
||||
|
||||
public class TeamMaker {
|
||||
public class ProfessionalPickup {
|
||||
|
||||
/* ======== MODEL ======== */
|
||||
|
||||
@ -19,26 +19,25 @@ public class TeamMaker {
|
||||
public static final String version = "0.4"
|
||||
|
||||
// GUI Components
|
||||
def frame // main frame
|
||||
def team1List // JList for team 1
|
||||
def team2List // JList for team 2
|
||||
def team1WinsButton
|
||||
def team2WinsButton
|
||||
def newGameButton
|
||||
def sittingList // JList for sitting players
|
||||
class View {
|
||||
def frame // main frame
|
||||
def team1List // JList for team 1
|
||||
def team2List // JList for team 2
|
||||
def team1WinsButton
|
||||
def team2WinsButton
|
||||
def newGameButton
|
||||
def sittingList // JList for sitting players
|
||||
|
||||
def inGamePlayerDropMenu
|
||||
def sittingPlayerDropMenu
|
||||
def inGamePlayerDropMenu
|
||||
def sittingPlayerDropMenu
|
||||
}
|
||||
|
||||
def config
|
||||
View view = new View()
|
||||
|
||||
protected Logger log = Logger.getLogger(getClass())
|
||||
|
||||
PlayerChooser playerChooser = new WeightedChooser(hardLimit: 2)
|
||||
OddsCalculator oddsCalculator = new OddsCalculator()
|
||||
|
||||
// Data components
|
||||
class Observables {
|
||||
class Model {
|
||||
@Bindable List team1Players = []
|
||||
@Bindable List team2Players = []
|
||||
@Bindable List sittingPlayers = []
|
||||
@ -46,16 +45,19 @@ public class TeamMaker {
|
||||
@Bindable int teamSize = 4
|
||||
@Bindable List popupPlayers = null
|
||||
@Bindable int popupTeam;
|
||||
@Bindable PlayerChooser playerChooser = new WeightedChooser(hardLimit: 2)
|
||||
@Bindable OddsCalculator oddsCalculator = new OddsCalculator()
|
||||
@Bindable Properties config
|
||||
}
|
||||
|
||||
def model = new Observables()
|
||||
Model model = new Model()
|
||||
|
||||
|
||||
/* ======== VIEW ======== */
|
||||
|
||||
/*
|
||||
+--------------------------------------------------+
|
||||
| JDB TeamMaker v0.2 _[]X |
|
||||
| JDB Professional Pickup v0.5 _[]X |
|
||||
+--------------------------------------------------+
|
||||
| |
|
||||
| +-Current-Game--------------+ +-Sitting-Players+ |
|
||||
@ -79,13 +81,13 @@ public class TeamMaker {
|
||||
|
||||
private void initGUI() {
|
||||
|
||||
inGamePlayerDropMenu = swing.popupMenu(/*'Player Options'*/) {
|
||||
view.inGamePlayerDropMenu = swing.popupMenu(/*'Player Options'*/) {
|
||||
menuItem('Bench Player',/* enabled: bind { !model.inGame },*/
|
||||
actionPerformed: { benchPlayer(model.popupPlayers,
|
||||
model.popupTeam) })
|
||||
}
|
||||
|
||||
sittingPlayerDropMenu = swing.popupMenu(/*'Player Options'*/) {
|
||||
view.sittingPlayerDropMenu = swing.popupMenu(/*'Player Options'*/) {
|
||||
menuItem('Assign to Team A', /*enabled: bind { !model.inGame },*/
|
||||
actionPerformed: {
|
||||
model.popupPlayers.each { assignPlayer(it, 1) }})
|
||||
@ -102,7 +104,7 @@ public class TeamMaker {
|
||||
// TODO
|
||||
// settingsDialog = new SettingsDialog(main: this)
|
||||
|
||||
frame = swing.frame(title: "JDB Professional Pickup v$version",
|
||||
view.frame = swing.frame(title: "JDB Professional Pickup v$version",
|
||||
iconImages: [swing.imageIcon("/bb128.png").image,
|
||||
swing.imageIcon("/bb64.png").image,
|
||||
swing.imageIcon("/bb48.png").image,
|
||||
@ -144,7 +146,7 @@ public class TeamMaker {
|
||||
def teamListRenderer = new PlayerListCellRenderer(this,
|
||||
showStats: false, colored: false)
|
||||
|
||||
team1List = list(cellRenderer: teamListRenderer,
|
||||
view.team1List = list(cellRenderer: teamListRenderer,
|
||||
constraints: gbc(gridx: 0, gridy: 1, fill: GBC.BOTH,
|
||||
insets: [5, 5, 0, 0], weightx: 2, weighty: 2),
|
||||
model: new DefaultListModel(),
|
||||
@ -153,13 +155,13 @@ public class TeamMaker {
|
||||
showInGamePlayerDropMenu(evt)
|
||||
})
|
||||
|
||||
team1WinsButton = button('Team A Wins',
|
||||
view.team1WinsButton = button('Team A Wins',
|
||||
constraints: gbc(gridx: 0, gridy: 2, anchor:
|
||||
GBC.CENTER, insets: [5, 5, 5, 0]),
|
||||
enabled: bind { model.inGame },
|
||||
actionPerformed: { declareLoser(2)})
|
||||
|
||||
team2List = list(cellRenderer: teamListRenderer,
|
||||
view.team2List = list(cellRenderer: teamListRenderer,
|
||||
constraints: gbc(gridx: 1, gridy: 1, fill: GBC.BOTH,
|
||||
insets: [5, 5, 0, 5], weightx: 2, weighty: 2),
|
||||
model: new DefaultListModel(),
|
||||
@ -168,7 +170,7 @@ public class TeamMaker {
|
||||
showInGamePlayerDropMenu(evt)
|
||||
})
|
||||
|
||||
team2WinsButton = button('Team B Wins',
|
||||
view.team2WinsButton = button('Team B Wins',
|
||||
constraints: gbc(gridx: 1, gridy: 2,
|
||||
anchor: GBC.CENTER, insets: [5, 5, 5, 5]),
|
||||
enabled: bind { model.inGame },
|
||||
@ -180,7 +182,7 @@ public class TeamMaker {
|
||||
fill: GBC.BOTH, insets: [5, 5, 0, 5], weighty: 1),
|
||||
border: titledBorder(title: 'Sitting Players')) {
|
||||
|
||||
sittingList = list(cellRenderer: new PlayerListCellRenderer(
|
||||
view.sittingList = list(cellRenderer: new PlayerListCellRenderer(
|
||||
this, showStats: true, colored: true),
|
||||
model: new SortedPlayerModel(),
|
||||
mouseClicked: { evt ->
|
||||
@ -198,11 +200,11 @@ public class TeamMaker {
|
||||
anchor: GBC.CENTER, insets: [5, 5, 5, 0]),
|
||||
actionPerformed: { addPlayer() })
|
||||
|
||||
newGameButton = button('Delete Player',
|
||||
view.newGameButton = button('Delete Player',
|
||||
constraints: gbc(gridx: 2, gridy: 1, anchor: GBC.CENTER,
|
||||
insets: [5, 5, 5, 5]),
|
||||
actionPerformed: {
|
||||
model.sittingPlayers.remove(sittingList.selectedValues)
|
||||
model.sittingPlayers.remove(view.sittingList.selectedValues)
|
||||
refreshGUI() })
|
||||
|
||||
}
|
||||
@ -216,12 +218,12 @@ public class TeamMaker {
|
||||
/* ======== CONTROLLER ======== */
|
||||
|
||||
public static void main(String[] args) {
|
||||
def inst = new TeamMaker()
|
||||
inst.frame.show()
|
||||
def inst = new ProfessionalPickup()
|
||||
inst.view.frame.show()
|
||||
}
|
||||
|
||||
TeamMaker() {
|
||||
config = new Properties()
|
||||
ProfessionalPickup() {
|
||||
model.config = new Properties()
|
||||
|
||||
// look for team maker config file
|
||||
File teammakerrc = new File(System.getProperty('user.home'),
|
||||
@ -231,12 +233,12 @@ public class TeamMaker {
|
||||
.withInputStream { is -> teammakerrc.text = is.text }
|
||||
|
||||
// load config
|
||||
teammakerrc.withInputStream { config.load(is) }
|
||||
teammakerrc.withInputStream { model.config.load(is) }
|
||||
|
||||
// set configured properties
|
||||
Game.BASE_POINT_VALUE = config.getProperty('base-point-value',
|
||||
Game.BASE_POINT_VALUE = model.config.getProperty('base-point-value',
|
||||
'1').toInteger()
|
||||
model.teamSize = config.getProperty('team.size', '4').toInteger()
|
||||
model.teamSize = model.config.getProperty('team.size', '4').toInteger()
|
||||
|
||||
initGUI()
|
||||
}
|
||||
@ -251,18 +253,18 @@ public class TeamMaker {
|
||||
}
|
||||
|
||||
private void setTeamSize() {
|
||||
def newSize = JOptionPane.showMessageDialog(frame,
|
||||
def newSize = JOptionPane.showMessageDialog(view.frame,
|
||||
"Enter the new team size: ", "Set Team Size...",
|
||||
JOptionPane.QUESTION_MESSAGE)
|
||||
|
||||
if (newSize.isInteger()) model.teamSize = newSize.toInteger()
|
||||
else JOptionPane.showMessageDialog(frame,
|
||||
else JOptionPane.showMessageDialog(view.frame,
|
||||
"$newSize is not a valid team size (it is not a number...).",
|
||||
"Set Team Size...", JOptionPane.ERROR_MESSAGE)
|
||||
}
|
||||
|
||||
private void addPlayer() {
|
||||
def name = JOptionPane.showInputDialog(frame,
|
||||
def name = JOptionPane.showInputDialog(view.frame,
|
||||
"Enter the new player's name: ", "New Player...",
|
||||
JOptionPane.QUESTION_MESSAGE)
|
||||
|
||||
@ -312,15 +314,15 @@ public class TeamMaker {
|
||||
log.debug("team2Players: ${model.team2Players}")
|
||||
}
|
||||
|
||||
team1List.model = new DefaultListModel()
|
||||
team2List.model = new DefaultListModel()
|
||||
sittingList.model = new SortedPlayerModel()
|
||||
view.team1List.model = new DefaultListModel()
|
||||
view.team2List.model = new DefaultListModel()
|
||||
view.sittingList.model = new SortedPlayerModel()
|
||||
|
||||
model.team1Players.each { team1List.model.addElement(it) }
|
||||
model.team2Players.each { team2List.model.addElement(it) }
|
||||
model.sittingPlayers.each { sittingList.model.addElement(it) }
|
||||
model.team1Players.each { view.team1List.model.addElement(it) }
|
||||
model.team2Players.each { view.team2List.model.addElement(it) }
|
||||
model.sittingPlayers.each { view.sittingList.model.addElement(it) }
|
||||
|
||||
frame.repaint()
|
||||
view.frame.repaint()
|
||||
|
||||
recalculateOdds()
|
||||
|
||||
@ -329,8 +331,8 @@ public class TeamMaker {
|
||||
private void recalculateOdds() {
|
||||
def players = model.sittingPlayers
|
||||
swing.doOutside {
|
||||
oddsCalculator.recalculate(players, getSpotsOpen(), playerChooser)
|
||||
swing.edt { sittingList.repaint() }
|
||||
model.oddsCalculator.recalculate(players, getSpotsOpen(), model.playerChooser)
|
||||
swing.edt { view.sittingList.repaint() }
|
||||
}
|
||||
|
||||
}
|
||||
@ -338,7 +340,7 @@ public class TeamMaker {
|
||||
private void populate(int teamNum) {
|
||||
def teamPlayers = playersForTeam(teamNum)
|
||||
while (teamPlayers.size() < model.teamSize) {
|
||||
def player = playerChooser.choose(model.sittingPlayers)
|
||||
def player = model.playerChooser.choose(model.sittingPlayers)
|
||||
teamPlayers << player
|
||||
model.sittingPlayers.remove(player)
|
||||
}
|
||||
@ -361,15 +363,15 @@ public class TeamMaker {
|
||||
}
|
||||
|
||||
private void showSittingPlayerDropMenu(def evt) {
|
||||
int index = sittingList.locationToIndex(evt.point)
|
||||
if (sittingList.isSelectedIndex(index))
|
||||
this.model.popupPlayers = sittingList.selectedValues
|
||||
int index = view.sittingList.locationToIndex(evt.point)
|
||||
if (view.sittingList.isSelectedIndex(index))
|
||||
this.model.popupPlayers = view.sittingList.selectedValues
|
||||
else {
|
||||
sittingList.selectedIndex = index
|
||||
this.model.popupPlayers = [sittingList.model.getElementAt(index)]
|
||||
view.sittingList.selectedIndex = index
|
||||
this.model.popupPlayers = [view.sittingList.model.getElementAt(index)]
|
||||
}
|
||||
|
||||
sittingPlayerDropMenu.show(sittingList, evt.point.@x, evt.point.@y)
|
||||
view.sittingPlayerDropMenu.show(view.sittingList, evt.point.@x, evt.point.@y)
|
||||
}
|
||||
|
||||
private void showInGamePlayerDropMenu(def evt) {
|
||||
@ -382,13 +384,13 @@ public class TeamMaker {
|
||||
model.popupPlayers = [teamList.model.getElementAt(index)]
|
||||
}
|
||||
|
||||
this.model.popupTeam = (teamList == team1List ? 1 : 2)
|
||||
this.model.popupTeam = (teamList == view.team1List ? 1 : 2)
|
||||
|
||||
inGamePlayerDropMenu.show(teamList, evt.point.@x, evt.point.@y)
|
||||
view.inGamePlayerDropMenu.show(teamList, evt.point.@x, evt.point.@y)
|
||||
}
|
||||
|
||||
private void setGamesSat(Player p) {
|
||||
String value = JOptionPane.showInputDialog(frame,
|
||||
String value = JOptionPane.showInputDialog(view.frame,
|
||||
"How many games has ${p.name} sat?", "Set Games Sat.",
|
||||
JOptionPane.QUESTION_MESSAGE)
|
||||
int newGames
|
||||
@ -396,7 +398,7 @@ public class TeamMaker {
|
||||
if (!value) return
|
||||
try { newGames = value.toInteger() }
|
||||
catch (Throwable t) {
|
||||
JOptionPane.showMessageDialog(frame,
|
||||
JOptionPane.showMessageDialog(view.frame,
|
||||
"The value $value is not a valid number.",
|
||||
"Invalid Input", JOptionPane.ERROR_MESSAGE)
|
||||
setGamesSat(p)
|
||||
@ -414,7 +416,7 @@ public class TeamMaker {
|
||||
}
|
||||
|
||||
private List listForTeam(int teamNum) {
|
||||
if (teamNum == 1) return team1List
|
||||
else return team2List
|
||||
if (teamNum == 1) return view.team1List
|
||||
else return view.team2List
|
||||
}
|
||||
}
|
@ -2,5 +2,22 @@ package com.jdbernard.teammaker
|
||||
|
||||
public class TeamPanel {
|
||||
|
||||
/* ======== MODEL ======== */
|
||||
|
||||
// GUI components
|
||||
class View {
|
||||
def panel
|
||||
}
|
||||
|
||||
View view = new View()
|
||||
|
||||
class Model {
|
||||
@Bindable String name
|
||||
}
|
||||
|
||||
Model model = new Model()
|
||||
|
||||
/* ======== VIEW ======== */
|
||||
|
||||
view.panel = swing.panel(border: titledBorder(model.name)) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user