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 ColorButton {
10: val version = ColorButton
11: .getClass.getName+": #1.0.04"
12: }
13:
14: // ----------------------------------------
15: class ColorButton 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:
28: val controlPane = new GridPanel(0,1) {
29: preferredSize = new Dimension(150,100)
30: for (e <- items.toArray) {
31: contents += new Button(e) {
32: Command.listenTo(this)
33: }
34: }
35: }
36:
37: contents += new SplitPane(
38: Orientation.Vertical,
39: controlPane,
40: canvasPane) {
41: dividerLocation = 100
42: }
43:
44: // ----------------------------------------
45: def update(value: String) {
46: canvasPane.background = colorNames(value)
47: }
48:
49: // ----------------------------------------
50: object Command extends Publisher {
51: reactions += {
52: case ButtonClicked(source) =>
53: val value = source.text
54: update(value)
55: }
56: }
57: }
58:
59: // ========================================