diff --git a/project.properties b/project.properties index e53b4ae..13295c4 100644 --- a/project.properties +++ b/project.properties @@ -1,7 +1,7 @@ -#Tue, 06 Jul 2010 06:30:26 -0500 +#Mon, 09 Aug 2010 19:14:52 -0500 #Mon Jul 05 23:10:39 CDT 2010 app.version=0.3.0 -build.number=67 +build.number=85 src.dir=src lib.dir=lib build.dir=build diff --git a/src/com/jdbernard/teammaker/TeamMaker.groovy b/src/com/jdbernard/teammaker/TeamMaker.groovy index eea7e04..ffd8e31 100644 --- a/src/com/jdbernard/teammaker/TeamMaker.groovy +++ b/src/com/jdbernard/teammaker/TeamMaker.groovy @@ -5,6 +5,7 @@ import groovy.swing.SwingBuilder import java.awt.GridBagConstraints as GBC import java.awt.GridBagLayout import java.awt.BorderLayout +import java.awt.event.MouseEvent import javax.swing.DefaultListModel import javax.swing.JFrame import javax.swing.JOptionPane @@ -19,11 +20,17 @@ public class TeamMaker { def frame def team1List + List team1Players def team2List + List team2Players def team1WinsButton def team2WinsButton def newGameButton def sittingList + List sittingPlayers + + def inGamePlayerDropMenu + def sittingPlayerDropMenu protected Logger log = Logger.getLogger(getClass()) @@ -33,6 +40,7 @@ public class TeamMaker { class Observables { @Bindable boolean inGame = false @Bindable int teamSize = 4 + @Bindable Player popupPlayer = null } def model = new Observables() @@ -65,6 +73,23 @@ public class TeamMaker { */ private void init() { + + inGamePlayerDropMenu = swing.popupMenu(/*'Player Options'*/) { + menuItem('Bench Player',/* enabled: bind { !model.inGame },*/ + actionPerformed: { benchPlayer(model.popupPlayer) }) + } + + sittingPlayerDropMenu = swing.popupMenu(/*'Player Options'*/) { + menuItem('Assign to Team 1', /*enabled: bind { !model.inGame },*/ + actionPerformed: { assignPlayer(model.popupPlayer, team1List) }) + + menuItem('Assign to Team 2', /*enabled: bind { !model.inGame },*/ + actionPerformed: { assignPlayer(model.popupPlayer, team2List) }) + + menuItem('Set Games Sat', + actionPerformed: { setGamesSat(model.popupPlayer) }) + } + frame = swing.frame(title: "JDB TeamMaker v$version", size: [600, 400], locationRelativeTo: null, defaultCloseOperation: JFrame.EXIT_ON_CLOSE) { @@ -90,24 +115,32 @@ public class TeamMaker { 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()) + model: new DefaultListModel(), + mouseClicked: { evt -> + if (evt.button != MouseEvent.BUTTON3) return + showInGamePlayerDropMenu(evt) + }) team1WinsButton = button('Team A Wins', constraints: gbc(gridx: 0, gridy: 2, anchor: GBC.CENTER, insets: [5, 5, 5, 0]), enabled: bind { model.inGame }, - actionPerformed: { declareWinner(team1List)}) + actionPerformed: { declareLoser(team2List)}) 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()) + model: new DefaultListModel(), + mouseClicked: { evt -> + if (evt.button != MouseEvent.BUTTON3) return + showInGamePlayerDropMenu(evt) + }) team2WinsButton = button('Team B Wins', constraints: gbc(gridx: 1, gridy: 2, anchor: GBC.CENTER, insets: [5, 5, 5, 5]), enabled: bind { model.inGame }, - actionPerformed: { declareWinner(team2List)} ) + actionPerformed: { declareLoser(team1List)} ) } @@ -117,7 +150,11 @@ public class TeamMaker { sittingList = list(cellRenderer: new PlayerListCellRenderer( this, showStats: true, colored: true), - model: new SortedPlayerModel()) + model: new SortedPlayerModel(), + mouseClicked: { evt -> + if (evt.button != MouseEvent.BUTTON3) return + showSittingPlayerDropMenu(evt) + }) } button('Next Game', constraints: gbc(gridx: 0, gridy: 1, @@ -152,7 +189,6 @@ public class TeamMaker { } TeamMaker() { - log.fatal("Is this thing on?") init() } @@ -189,34 +225,34 @@ public class TeamMaker { if (team2List.model.size() < model.teamSize) populate(team2List) + recalculateOdds() + model.inGame = true - // recalculate odds - def players = sittingList.model.collect { it } - swing.doOutside { - oddsCalculator.recalculate(players, getSpotsOpen(), playerChooser) - swing.edt { sittingList.repaint() } - } } - private void declareWinner(def teamList) { + private void declareLoser(def teamList) { sittingList.model.each { it.gamesSat++ } teamList.model.each { player -> player.gamesSat = 0 sittingList.model.addElement(player) } - //recalculate odds + recalculateOdds() + + teamList.model.clear() + teamList.repaint() + sittingList.repaint() + model.inGame = false + } + + private void recalculateOdds() { def players = sittingList.model.collect { it } swing.doOutside { oddsCalculator.recalculate(players, getSpotsOpen(), playerChooser) swing.edt { sittingList.repaint() } } - teamList.model.clear() - teamList.repaint() - sittingList.repaint() - model.inGame = false } private void populate(def teamList) { @@ -227,4 +263,56 @@ public class TeamMaker { } } + private benchPlayer(Player p) { + team1List.remove(p) + sittingList.model.addElement(p) + recalculateOdds() + } + + private assignPlayer(Player p, def teamList) { + sittingList.model.removeElement(p) + teamList.model.addElement(p) + recalculateOdds() + } + + private void showSittingPlayerDropMenu(def evt) { + int index = sittingList.locationToIndex(evt.point) + sittingList.selectedIndex = index + this.model.popupPlayer = sittingList.model.getElementAt(index) + + sittingPlayerDropMenu.show(sittingList, evt.point.@x, evt.point.@y) + } + + private void showInGamePlayerDropMenu(def evt) { + def teamList = evt.source + int index = teamList.locationToIndex(evt.point) + teamList.selectedIndex = index + this.model.popupPlayer = teamList.model.getElementAt(index) + + inGamePlayerDropMenu.show(teamList, evt.point.@x, evt.point.@y) + } + + private void setGamesSat(Player p) { + String value = JOptionPane.showInputDialog(frame, + "How many games has ${p.name} sat?", "Set Games Sat.", + JOptionPane.QUESTION_MESSAGE) + int newGames + + sittingList.model.removeElement(p) + + if (!value) return + try { newGames = value.toInteger() } + catch (Throwable t) { + JOptionPane.showMessageDialog(frame, + "The value $value is not a valid number.", + "Invalid Input", JOptionPane.ERROR_MESSAGE) + setGamesSat(p) + return + } + + p.gamesSat = newGames + if (!sittingList.model.set.contains(p)) sittingList.model.addElement(p) + + recalculateOdds() + } }