1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
2: package berry.colorChart.scala
3:
4: import java.awt.Color
5: import java.awt.Dimension
6: import swing._
7: import swing.event._
8:
9: // ----------------------------------------
10: object ColorSlider {
11: val version = ColorSlider
12: .getClass.getName+": #1.0.09"
13: }
14:
15: // ----------------------------------------
16: class ColorSlider extends FlowPanel {
17:
18: val colorNames = Array("red","green","blue")
19:
20: // ----------------------------------------
21: val canvasPane = new FlowPanel {
22: preferredSize = new Dimension(100,100)
23: }
24:
25: val controlPane = new GridPanel(0,1) {
26: for (e <- colorNames) {
27: contents += new Slider() {
28: min = 255
29: min = 0
30: paintTicks = true
31: majorTickSpacing = 32
32: minorTickSpacing = 8
33: minimumSize = new Dimension(200,100)
34: Command.listenTo(this)
35: }
36: }
37: }
38:
39: contents += new SplitPane(
40: Orientation.Vertical,
41: controlPane,
42: canvasPane) {
43: dividerLocation = 200
44: }
45:
46: // ----------------------------------------
47: def update {
48: val color = for (e <- controlPane.contents) yield {
49: e.asInstanceOf[Slider].value
50: }
51: color.toArray match {
52: case Array(r,g,b) =>
53: canvasPane.background = new Color(r,g,b)
54: }
55: }
56:
57: // ----------------------------------------
58: object Command extends Publisher {
59: reactions += {
60: case ValueChanged(source) => update
61: }
62: }
63: }
64:
65: // ========================================