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