1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
2: package berry.colorChart.scala
3:
4: import java.awt.Color
5: import swing._
6: import swing.event._
7:
8: // ----------------------------------------
9: object ColorRadioButton {
10: val version = ColorRadioButton
11: .getClass.getName+": #1.0.03"
12: }
13:
14: // ----------------------------------------
15: class ColorRadioButton extends FlowPanel {
16:
17: val colorNames = Map(
18: "red" -> Color.red,
19: "green" -> Color.green,
20: "blue" -> Color.blue)
21: val items = for ((key, value) <- colorNames) yield { key }
22:
23: // ----------------------------------------
24: val canvasPane = new FlowPanel {
25: preferredSize = new Dimension(100,100)
26: }
27: val controlPane = new GridPanel(0,1) {
28: preferredSize = new Dimension(150,100)
29: val group = new ButtonGroup
30: for (e <- items.toArray) {
31: contents += new RadioButton(e) {
32: Command.listenTo(this)
33: group.buttons += this
34: }
35: }
36: }
37:
38: contents += new SplitPane(
39: Orientation.Vertical,
40: controlPane,
41: canvasPane) {
42: dividerLocation = 100
43: }
44:
45: // ----------------------------------------
46: def update(value: String) {
47: canvasPane.background = colorNames(value)
48: }
49:
50: // ----------------------------------------
51: object Command extends Publisher {
52: reactions += {
53: case ButtonClicked(source) =>
54: val value = source.text
55: update(value)
56: }
57: }
58: }
59:
60: // ========================================