berry/colorChart/scala/colorRadioButton.scala
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: // ========================================
berry/colorChart/scala/Tips.scala
1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 2: 3: /*'****************************************'demo: scala 4: cd /Users/sketch/book/java_useBetter_1/berry/colorChart/scala/ 5: 6: scalac -d bin {Tips,TreeView,colorList,colorTabbedPane,colorTable}.scala 7: scala -cp bin berry.colorChart.scala.Tips; date 8: $ 9: ---------------------------------------- 10: version: berry.colorChart.scala.Tips$: #1.0.06 11: berry.colorChart.scala.ColorList$: #1.0.09 12: berry.colorChart.scala.ColorTabbedPane$: #1.0.06 13: berry.colorChart.scala.ColorTable$: #1.0.15a 14: berry.colorChart.scala.TreeView$: #1.0.03 15: ---------------------------------------- 16: $ 17: '****************************************'*/ 18: package berry.colorChart.scala 19: 20: // ---------------------------------------- 21: import swing._ 22: import berry.colorChart.scala._ 23: 24: object Tips extends SimpleSwingApplication { 25: val version = Tips 26: .getClass.getName+": #1.0.06" 27: 28: // ---------------------------------------- 29: println("-"*40) 30: println("version: %s" format version) 31: println(ColorList.version) 32: println(ColorTabbedPane.version) 33: println(ColorTable.version) 34: println(TreeView.version) 35: println("-"*40) 36: 37: // ---------------------------------------- 38: def top = new MainFrame { 39: /*'****************************************' 40: title = "Color: ListView" 41: contents = new ColorList 42: title = "Color: TabbedPane" 43: contents = new ColorTabbedPane 44: '****************************************'*/ 45: title = "Color: Table" 46: contents = new ColorTable 47: 48: peer.setLocationRelativeTo(null) 49: } 50: } 51: 52: // ========================================