PageRenderTime 45ms CodeModel.GetById 2ms app.highlight 38ms RepoModel.GetById 1ms app.codeStats 0ms

/EyesInTheSkyGUI/src/eyesInTheSkyGUI/houseAdminGUI.scala

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