/EyesInTheSkyGUI/src/eyesInTheSkyGUI/houseAdminGUI.scala

http://jackblack.googlecode.com/ · Scala · 424 lines · 338 code · 59 blank · 27 comment · 7 complexity · fb76e03af6e37194132d0ea1ae583e8d MD5 · raw file

  1. package eyesInTheSkyGUI
  2. import swing._
  3. import scala.swing._
  4. import event._
  5. import java.awt.image._
  6. import javax.swing.ImageIcon
  7. import javax.imageio.ImageIO._
  8. import javax.swing.table._
  9. import java.awt.Graphics
  10. object HouseGUI extends SimpleSwingApplication {
  11. def top = new MainFrame {
  12. title = "House Admin Login"
  13. val lAdminID = new Label { text = "Adminitrator Login ID" }
  14. val tAdminID = new TextField { columns = 5 }
  15. val adminName = tAdminName
  16. val lAdminPW = new Label { text = "Password" }
  17. var tAdminPW = new PasswordField(8)
  18. val bLogin = new Button { text = "Login" }
  19. //Used as padding between components
  20. val space0 = new Label { text = " " }
  21. val space1 = new Label { text = " " }
  22. val space2 = new Label { text = " " }
  23. val space3 = new Label { text = " " }
  24. val space4 = new Label { text = " " }
  25. val label0 = new Label { text = " " }
  26. val space00 = new Label { text = " " }
  27. val space10 = new Label { text = " " }
  28. val space20 = new Label { text = " " }
  29. val space30 = new Label { text = " " }
  30. val space40 = new Label { text = " " }
  31. val space50 = new Label { text = " " }
  32. val space60 = new Label { text = " " }
  33. val label00 = new Label { text = " " }
  34. var tableNum = 0
  35. var playerNum = 0
  36. var count = 0
  37. var iconH = 0
  38. var iconW = 0
  39. var prevLogoff = false
  40. val casImg = new Label {
  41. icon = new ImageIcon("loginVirtualCasino.jpg")
  42. iconH = icon.getIconHeight()
  43. iconW = icon.getIconWidth()
  44. }
  45. val casImgPanel = new FlowPanel { background = java.awt.Color.GREEN }
  46. casImgPanel.contents += casImg
  47. val adminLoginPanel = new GridPanel(11, 1) {}
  48. adminLoginPanel.contents += space00
  49. adminLoginPanel.contents += space10
  50. adminLoginPanel.contents += lAdminID
  51. adminLoginPanel.contents += tAdminID
  52. adminLoginPanel.contents += lAdminPW
  53. adminLoginPanel.contents += tAdminPW
  54. adminLoginPanel.contents += space20
  55. adminLoginPanel.contents += space30
  56. adminLoginPanel.contents += space40
  57. adminLoginPanel.contents += space50
  58. adminLoginPanel.contents += bLogin
  59. //House Admin Screen
  60. val casImg2 = new Label {
  61. icon = new ImageIcon("casinoLogo.jpg")
  62. iconH = icon.getIconHeight()
  63. iconW = icon.getIconWidth()
  64. background = java.awt.Color.GREEN
  65. }
  66. val buttonStartHouse: scala.swing.AbstractButton = new scala.swing.Button { text = "StartHouse " }
  67. val buttonStopHouse: scala.swing.AbstractButton = new scala.swing.Button { text = "StopHouse " }
  68. val buttonViewTables: scala.swing.AbstractButton = new scala.swing.Button { text = "ViewTables " }
  69. val buttonTotal_PandL: scala.swing.AbstractButton = new scala.swing.Button { text = "Total_PandL" }
  70. val buttonViewPlayers: scala.swing.AbstractButton = new scala.swing.Button { text = "All Players" }
  71. val buttonLogoff: scala.swing.AbstractButton = new scala.swing.Button { text = "Logoff " }
  72. //RollOver info
  73. buttonStartHouse.rolloverEnabled = true
  74. buttonStartHouse.tooltip = "Resets current Earnings and Bets for all Players in the House.\n " +
  75. "If the StartButton is enabled - this means no Games are playing at the present!"
  76. buttonStopHouse.rolloverEnabled = true
  77. buttonStopHouse.tooltip = "End any games in progress at Tables, stops Tables, and Dealers."
  78. buttonViewTables.rolloverEnabled = true
  79. buttonViewTables.tooltip = "Displays a list of Tables with their current statuses, Earnings, and Loses. " +
  80. "From this list additional actions can be taken based on the status of a table."
  81. buttonTotal_PandL.rolloverEnabled = true
  82. buttonTotal_PandL.tooltip = "Displays the starting float for the House for the current day " +
  83. "and running totals for Earnings, Losses, and House Current Balance."
  84. buttonViewPlayers.rolloverEnabled = true
  85. buttonViewPlayers.tooltip = "Displays all players in the House. By Clicking on a Player Name, this " +
  86. "will display Betting history, & cureent Earnings and Losses."
  87. val buttonsPanel = new GridPanel(11, 1) {
  88. val houseButtons = new scala.swing.ButtonGroup() //not used; Couldn't figure out how to use ...
  89. }
  90. buttonsPanel.contents += buttonStartHouse
  91. buttonsPanel.contents += space0
  92. buttonsPanel.contents += buttonStopHouse
  93. buttonsPanel.contents += space1
  94. buttonsPanel.contents += buttonViewTables
  95. buttonsPanel.contents += space2
  96. buttonsPanel.contents += buttonTotal_PandL
  97. buttonsPanel.contents += space3
  98. buttonsPanel.contents += buttonViewPlayers
  99. buttonsPanel.contents += space4
  100. buttonsPanel.contents += buttonLogoff
  101. buttonStopHouse.enabled = false
  102. buttonViewTables.enabled = false
  103. buttonTotal_PandL.enabled = false
  104. buttonViewPlayers.enabled = false
  105. val lAdminName = new Label { text = "AdminName:" }
  106. var tAdminName = new TextField { columns = 10 }
  107. val lCurrHouseBal = new Label { text = "Current House Balance:" }
  108. var tCurrHouseBal = new TextField { columns = 10 }
  109. tCurrHouseBal.editable = false
  110. tCurrHouseBal.text = "$0"
  111. val houseBalStat = new FlowPanel {}
  112. houseBalStat.contents += lAdminName
  113. houseBalStat.contents += tAdminName
  114. houseBalStat.contents += lCurrHouseBal
  115. houseBalStat.contents += tCurrHouseBal
  116. houseBalStat.contents += space60
  117. runGUI
  118. def runGUI {
  119. def runLoginScreen {
  120. contents = new BorderPanel {
  121. //Login Page
  122. add(casImgPanel, BorderPanel.Position.West)
  123. val label0 = new Label { text = " " }
  124. add(label0, BorderPanel.Position.Center)
  125. add(adminLoginPanel, BorderPanel.Position.East)
  126. border = Swing.EmptyBorder(30, 30, 30, 30)
  127. }
  128. }
  129. listenTo(bLogin) //For the Login Screen
  130. reactions += { // Reactions# 1
  131. case ButtonClicked(`bLogin`) =>
  132. title = "House Administration Console"
  133. tAdminName.text = tAdminID.text
  134. println(tAdminID.text)
  135. tAdminName.editable = false
  136. tCurrHouseBal.editable = false
  137. contents = new BorderPanel {
  138. add(houseBalStat, BorderPanel.Position.North)
  139. add(buttonsPanel, BorderPanel.Position.West)
  140. add(label0, BorderPanel.Position.Center)
  141. add(casImg2, BorderPanel.Position.East)
  142. border = Swing.EmptyBorder(30, 30, 30, 30)
  143. }
  144. //listenTo(button0, button1) //StartButton, StopButton, etc.
  145. listenTo(buttonStartHouse, buttonStopHouse, buttonViewTables,
  146. buttonTotal_PandL, buttonViewPlayers, buttonLogoff)
  147. reactions += { //repaint House Admin screen based on button selection to the other Screens
  148. case ButtonClicked(`buttonStartHouse`) => runStartHouse
  149. case ButtonClicked(`buttonStopHouse`) => runStopHouse
  150. case ButtonClicked(`buttonViewTables`) => runViewTables
  151. case ButtonClicked(`buttonTotal_PandL`) => runTotalPandL
  152. case ButtonClicked(`buttonViewPlayers`) => runViewPlayers
  153. case ButtonClicked(`buttonLogoff`) => runLogoff
  154. } // End Reactions# 2
  155. def runStartHouse {
  156. println("Hello buttonStartHouse!")
  157. buttonStopHouse.enabled = true
  158. buttonViewTables.enabled = true
  159. buttonTotal_PandL.enabled = true
  160. buttonViewPlayers.enabled = true
  161. buttonStartHouse.enabled = false
  162. if (count == 0) //Temp; this will be a calculated value { CurrentBal = StartingBal + (Earnings - Losses) }
  163. tCurrHouseBal.text = "$10,000,000.00"
  164. else
  165. tCurrHouseBal.text = "$10,069,525.00"
  166. }
  167. def runStopHouse {//More to come
  168. println("Hello buttonStopHouse!")
  169. buttonStartHouse.enabled = true
  170. buttonStopHouse.enabled = false
  171. }
  172. def runViewTables {
  173. title = "View All Tables"
  174. count = 1
  175. val startButton = new Button { text = "Start" }
  176. val stopButton = new Button { text = "Stop " }
  177. val rowSelected = new Button { text = "View Table Selected" }
  178. val tableModel = new DefaultTableModel(new Array[Array[AnyRef]](0, 5), // Data
  179. Array[AnyRef]("TableNo", "Earnings", "Losses", "Status")) // Column names
  180. val table = new Table(4, 5) { model = tableModel }
  181. tableModel.addRow(Array[AnyRef]("TableNo", "Earnings", "Losses", "Status"))
  182. tableModel.addRow(Array[AnyRef]("1", "$100", "$10", "Started"))
  183. tableModel.addRow(Array[AnyRef]("2", "$50", "$50", "Stopped"))
  184. tableModel.addRow(Array[AnyRef]("3", "$500", "$100", "Started"))
  185. tableModel.addRow(Array[AnyRef]("4", "$250", "$200", "Started"))
  186. tableModel.addRow(Array[AnyRef]("5", "$1050", "$500", "Stopped"))
  187. tableModel.addRow(Array[AnyRef]("6", "$50000", "$1000", "Started"))
  188. tableModel.addRow(Array[AnyRef]("7", "$100000", "$2000", "Stopped"))
  189. tAdminName.editable = false
  190. tCurrHouseBal.text = "$10,069,525.00"
  191. tCurrHouseBal.editable = false
  192. val startStopTblButtons = new BorderPanel {
  193. background = java.awt.Color.GRAY
  194. add(startButton, BorderPanel.Position.West)
  195. add(rowSelected, BorderPanel.Position.Center)
  196. add(stopButton, BorderPanel.Position.East)
  197. //contents.append(startButton, stopButton) goes with FlowPanel
  198. border = Swing.EmptyBorder(10, 10, 0, 10)
  199. }
  200. var tablePanel = new BoxPanel(Orientation.Vertical) {
  201. background = java.awt.Color.GRAY
  202. contents += table
  203. contents += startStopTblButtons
  204. border = Swing.EmptyBorder(70, 10, 70, 10)
  205. }
  206. println("Hello buttonViewTables!")
  207. def repaintViewTablesScreen {
  208. contents = new BorderPanel {
  209. add(houseBalStat, BorderPanel.Position.North)
  210. add(buttonsPanel, BorderPanel.Position.West)
  211. add(label0, BorderPanel.Position.Center)
  212. add(tablePanel, BorderPanel.Position.East)
  213. border = Swing.EmptyBorder(30, 30, 30, 30)
  214. }
  215. }
  216. repaintViewTablesScreen
  217. //Used to generate the Row number for a Table
  218. //Take this number & get the Table stats {Earnings, Losses, Players at table}
  219. val tblRow = table.selection.rows.result()
  220. table.listenTo(table.selection)
  221. /*
  222. if(tableModel.getValueAt(tableNum, 3) == "Started")
  223. { stopButton.enabled = false
  224. startButton.enabled = true
  225. }
  226. else
  227. { stopButton.enabled = true
  228. startButton.enabled = false
  229. }
  230. */
  231. table.reactions += {
  232. case tableModel => tblRow foreach { kv => /*println("table " + kv + " was selected");*/ tableNum = kv }
  233. }
  234. listenTo(startButton, stopButton, rowSelected)
  235. reactions += {
  236. case ButtonClicked(`startButton`) => println("Tbl " + tableNum + " Started");
  237. startTablesMsg
  238. case ButtonClicked(`stopButton`) => println("Tbl " + tableNum + " Stoped")
  239. stopTablesMsg
  240. case ButtonClicked(`rowSelected`) => //println("Tbl " + tableNum + " Stoped")
  241. rowSelectedMsg
  242. }
  243. def startTablesMsg {
  244. val tblStartedMsg = new Label { text = "TABLE " + tableNum + " Started" }
  245. if(tableModel.getValueAt(tableNum, 3) == "Started")
  246. {
  247. stopButton.enabled = true
  248. startButton.enabled = false
  249. }
  250. table.update(tableNum, 3, "Started")
  251. tablePanel = new BoxPanel(Orientation.Vertical) {
  252. background = java.awt.Color.GRAY
  253. contents += table
  254. contents += startStopTblButtons
  255. contents.append(tblStartedMsg)
  256. border = Swing.EmptyBorder(70, 10, 70, 10)
  257. }
  258. tCurrHouseBal.text = "$10,069,525.00"
  259. tCurrHouseBal.editable = false
  260. repaintViewTablesScreen
  261. }//End startTableMsg
  262. def stopTablesMsg {
  263. val tblStartedMsg = new Label { text = "TABLE " + tableNum + " Stoped" }
  264. if(tableModel.getValueAt(tableNum, 3) == "Stopped")
  265. {
  266. stopButton.enabled = false
  267. startButton.enabled = true
  268. }
  269. table.update(tableNum, 3, "Stopped")
  270. tablePanel = new BoxPanel(Orientation.Vertical) {
  271. background = java.awt.Color.GRAY
  272. contents += table
  273. contents += startStopTblButtons
  274. contents.append(tblStartedMsg)
  275. border = Swing.EmptyBorder(70, 10, 70, 10)
  276. }
  277. repaintViewTablesScreen
  278. }//End stopTableMsg
  279. def rowSelectedMsg {
  280. //val tblStartedMsg = new Label { text = "TABLE " + tableNum + " Stoped" }
  281. val tblIconImg = new Label {
  282. icon = new ImageIcon("tableInfo.jpg")
  283. }
  284. //table.update(tableNum, 3, "Stopped")
  285. tablePanel = new BoxPanel(Orientation.Vertical) {
  286. background = java.awt.Color.GRAY
  287. contents += tblIconImg
  288. //contents += startStopTblButtons
  289. //contents.append(tblStartedMsg)
  290. border = Swing.EmptyBorder(70, 10, 70, 10)
  291. }
  292. repaintViewTablesScreen
  293. }
  294. }//End runViewTables
  295. def runTotalPandL {
  296. println("Hello buttonTotal_PandL!")
  297. count = 1
  298. title = "View Total Earnings & Losses for the House"
  299. val houseBalImg = new Label {
  300. icon = new ImageIcon("houseBalance.jpg")
  301. iconH = icon.getIconHeight()
  302. iconW = icon.getIconWidth()
  303. }
  304. val tablePanel = new BoxPanel(Orientation.Vertical) {
  305. background = java.awt.Color.GRAY
  306. contents += houseBalImg
  307. border = Swing.EmptyBorder(70, 10, 70, 10)
  308. }
  309. contents = new BorderPanel {
  310. add(houseBalStat, BorderPanel.Position.North)
  311. add(buttonsPanel, BorderPanel.Position.West)
  312. add(label0, BorderPanel.Position.Center)
  313. add(tablePanel, BorderPanel.Position.East)
  314. border = Swing.EmptyBorder(30, 30, 30, 30)
  315. }
  316. }//End runTotalPandL
  317. def runViewPlayers {
  318. println("Hello buttonViewPlayers!")
  319. count = 1
  320. title = "View All Players in the House"
  321. val tableModel = new DefaultTableModel(new Array[Array[AnyRef]](0, 3), // Data
  322. Array[AnyRef]("TableNo", "Earnings", "Losses")) // Column names
  323. val table = new Table(3, 4) { model = tableModel }
  324. tableModel.addRow(Array[AnyRef]("Player Name", "Earnings", "Losses"))
  325. tableModel.addRow(Array[AnyRef]("Don", "$100", "$10"))
  326. tableModel.addRow(Array[AnyRef]("Krish", "$50", "$50"))
  327. tableModel.addRow(Array[AnyRef]("Sean", "$500", "$100"))
  328. tableModel.addRow(Array[AnyRef]("Ankith", "$250", "$200"))
  329. tableModel.addRow(Array[AnyRef]("Venni", "$1050", "$500"))
  330. tableModel.addRow(Array[AnyRef]("John", "$50000", "$1000"))
  331. tableModel.addRow(Array[AnyRef]("Joe", "$100000", "$2000"))
  332. val tablePanel = new BoxPanel(Orientation.Vertical) {
  333. background = java.awt.Color.GRAY
  334. contents += table
  335. border = Swing.EmptyBorder(70, 10, 70, 10)
  336. }
  337. contents = new BorderPanel {
  338. add(houseBalStat, BorderPanel.Position.North)
  339. add(buttonsPanel, BorderPanel.Position.West)
  340. add(label0, BorderPanel.Position.Center)
  341. add(tablePanel, BorderPanel.Position.East)
  342. border = Swing.EmptyBorder(30, 30, 30, 30)
  343. }
  344. //Used to generate the Row number for a Player --> Take this number & get the Player History
  345. val tblRow = table.selection.rows.result()
  346. table.listenTo(table.selection)
  347. table.reactions += {
  348. case tableModel => tblRow foreach { kv => println("Player at Row " + kv + " is selected") }
  349. }
  350. }//End runViewPlayers
  351. def runLogoff { //Go back to Login Page
  352. title = "House Admin Login"
  353. println("Hello buttonLogoff!")
  354. //tAdminPW = new PasswordField
  355. //tAdminID.text = ""
  356. //for(x <- 0 to tAdminPW.password.size - 1 ) tAdminPW.password(x) = '\0'
  357. prevLogoff = true
  358. top.closeOperation()
  359. //runLoginScreen
  360. }//End runLogoff
  361. } // End Reactions# 1
  362. runLoginScreen
  363. } //End runGUI
  364. } //End top = MainFrame
  365. } //End HouseGUI