1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
2:
3: /* ---------------------------------------- demo: scala
4: cd /Users/sketch/home_sketch/worldCup/scala/
5:
6: scalac ex09/wcFrame.scala
7: scala WorldCup
8: */
9:
10: // ----------------------------------------
11: import swing._
12: import swing.event._
13:
14: object WorldCup extends SimpleSwingApplication {
15: println("version: #1.0.49")
16:
17: def top = new MainFrame {
18: title = "FIFA World Cup #09"
19: contents = TopPanel
20: }
21: }
22:
23: // ----------------------------------------
24: object WcModel {
25: val groups = Map(
26: "A" -> Map( // Group A
27: "rsa" -> "South Africa",
28: "mex" -> "Mexico",
29: "uru" -> "Uruguay",
30: "fra" -> "France"
31: ),
32: "B" -> Map( // Group B
33: "arg" -> "Argentina",
34: "nga" -> "Nigeria",
35: "kor" -> "Korea Republic",
36: "gre" -> "Greece"
37: ),
38: "C" -> Map( // Group C
39: "eng" -> "England",
40: "usa" -> "USA",
41: "alg" -> "Algeria",
42: "svn" -> "Slovenia"
43: ),
44: "D" -> Map( // Group D
45: "ger" -> "Germany",
46: "aus" -> "Australia",
47: "srb" -> "Serbia",
48: "gha" -> "Ghana"
49: ),
50: "E" -> Map( // Group E
51: "ned" -> "Netherlands",
52: "den" -> "Denmark",
53: "jpn" -> "Japan",
54: "cmr" -> "Cameroon"
55: ),
56: "F" -> Map( // Group F
57: "ita" -> "Italy",
58: "par" -> "Paraguay",
59: "nzl" -> "New Zealand",
60: "svk" -> "Slovakia"
61: ),
62: "G" -> Map( // Group G
63: "bra" -> "Brazil",
64: "prk" -> "Korea DPR",
65: "civ" -> "Cote d Ivoire",
66: "por" -> "Portugal"
67: ),
68: "H" -> Map( // Group H
69: "esp" -> "Spain",
70: "sui" -> "Switzerland",
71: "hon" -> "Honduras",
72: "chi" -> "Chile"
73: )
74: )
75: import scala.collection.mutable
76: def teamNames = {
77: val map = mutable.Map[String,String]()
78: for {
79: group <- WcModel.groups.keys
80: teams = WcModel.groups(group)
81: team <- teams.keys
82: } map += (team -> teams(team))
83: map
84: }
85: }
86:
87: // ----------------------------------------
88: import javax.swing.ImageIcon
89:
90: object TopPanel extends FlowPanel {
91: def _leftComponent = {
92: def view = new ListView(WcModel.teamNames.keys.toList sortWith (_ < _)) {
93: reactions += {
94: case ListSelectionChanged(source, range, live) =>
95: val value = source.selection.items(0).toString
96: println(":: %s" format WcModel.teamNames(value))
97: }
98: listenTo(this.selection)
99: }
100: new ScrollPane {
101: viewportView = view
102: preferredSize = new Dimension(120,150)
103: }
104: }
105: def _rightComponent = {
106: def view = new Label {
107: icon = new ImageIcon("matches/fifa.png")
108: }
109: new ScrollPane {
110: viewportView = view
111: preferredSize = new Dimension(180,0)
112: }
113: }
114: contents += new SplitPane {
115: orientation = Orientation.Vertical
116: oneTouchExpandable = true
117: dividerLocation = 100
118: leftComponent = _leftComponent
119: rightComponent = _rightComponent
120: }
121: }
122:
123: // ========================================