summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSimon Ochsenreither <simon@ochsenreither.de>2011-12-07 21:52:20 +0100
committerSimon Ochsenreither <simon@ochsenreither.de>2011-12-07 22:09:04 +0100
commitf3e7e98cc0f47eacb59400b2c56c6bd2cb8b2ebc (patch)
tree6d77a6dbbb3de69bc38a7e2d55a37596960675a0 /docs
parent332fec96e31840878bed41dd7b5314b97d8da7c2 (diff)
downloadscala-f3e7e98cc0f47eacb59400b2c56c6bd2cb8b2ebc.tar.gz
scala-f3e7e98cc0f47eacb59400b2c56c6bd2cb8b2ebc.tar.bz2
scala-f3e7e98cc0f47eacb59400b2c56c6bd2cb8b2ebc.zip
Clean up standard/swing library by deprecating/moving code examples
Deprecate scala/xml/include/sax/Main.scala. Move scala/swing/test/* to docs/examples. Saves 160KB in scala-swing.jar. Fixes SI-4627.
Diffstat (limited to 'docs')
-rw-r--r--docs/examples/swing/ButtonApp.scala24
-rw-r--r--docs/examples/swing/CelsiusConverter.scala42
-rw-r--r--docs/examples/swing/CelsiusConverter2.scala36
-rw-r--r--docs/examples/swing/ComboBoxes.scala86
-rw-r--r--docs/examples/swing/CountButton.scala30
-rw-r--r--docs/examples/swing/Dialogs.scala176
-rw-r--r--docs/examples/swing/GridBagDemo.scala64
-rw-r--r--docs/examples/swing/HelloWorld.scala13
-rw-r--r--docs/examples/swing/LabelTest.scala19
-rw-r--r--docs/examples/swing/LinePainting.scala53
-rw-r--r--docs/examples/swing/ListViewDemo.scala17
-rw-r--r--docs/examples/swing/SimpleApplet.scala18
-rw-r--r--docs/examples/swing/SwingApp.scala29
-rw-r--r--docs/examples/swing/TableSelection.scala96
-rw-r--r--docs/examples/swing/UIDemo.scala147
-rw-r--r--docs/examples/swing/images/banana.jpgbin0 -> 6000 bytes
-rw-r--r--docs/examples/swing/images/margarita1.jpgbin0 -> 14770 bytes
-rw-r--r--docs/examples/swing/images/margarita2.jpgbin0 -> 17310 bytes
-rw-r--r--docs/examples/swing/images/rose.jpgbin0 -> 13808 bytes
19 files changed, 850 insertions, 0 deletions
diff --git a/docs/examples/swing/ButtonApp.scala b/docs/examples/swing/ButtonApp.scala
new file mode 100644
index 0000000000..96799b24f2
--- /dev/null
+++ b/docs/examples/swing/ButtonApp.scala
@@ -0,0 +1,24 @@
+package examples.swing
+
+import java.awt.Dimension
+
+import swing._
+import swing.event._
+
+object ButtonApp extends SimpleSwingApplication {
+ def top = new MainFrame {
+ title = "My Frame"
+ contents = new GridPanel(2, 2) {
+ hGap = 3
+ vGap = 3
+ contents += new Button {
+ text = "Press Me!"
+ reactions += {
+ case ButtonClicked(_) => text = "Hello Scala"
+ }
+ }
+ }
+ size = new Dimension(300, 80)
+ }
+}
+
diff --git a/docs/examples/swing/CelsiusConverter.scala b/docs/examples/swing/CelsiusConverter.scala
new file mode 100644
index 0000000000..b4a62fb366
--- /dev/null
+++ b/docs/examples/swing/CelsiusConverter.scala
@@ -0,0 +1,42 @@
+package examples.swing
+
+import swing._
+import event._
+
+/** A GUI app to convert celsius to centigrade
+ */
+object CelsiusConverter extends SimpleSwingApplication {
+ def top = new MainFrame {
+ title = "Convert Celsius to Fahrenheit"
+ val tempCelsius = new TextField
+ val celsiusLabel = new Label {
+ text = "Celsius"
+ border = Swing.EmptyBorder(5, 5, 5, 5)
+ }
+ val convertButton = new Button {
+ text = "Convert"//new javax.swing.ImageIcon("c:\\workspace\\gui\\images\\convert.gif")
+ //border = Border.Empty(5, 5, 5, 5)
+ }
+ val fahrenheitLabel = new Label {
+ text = "Fahrenheit "
+ border = Swing.EmptyBorder(5, 5, 5, 5)
+ listenTo(convertButton, tempCelsius)
+
+ def convert() {
+ val c = Integer.parseInt(tempCelsius.text)
+ val f = c * 9 / 5 + 32
+ text = "<html><font color = red>"+f+"</font> Fahrenheit</html>"
+ }
+
+ reactions += {
+ case ButtonClicked(_) | EditDone(_) => convert()
+ }
+ }
+ contents = new GridPanel(2,2) {
+ contents.append(tempCelsius, celsiusLabel, convertButton, fahrenheitLabel)
+ border = Swing.EmptyBorder(10, 10, 10, 10)
+ }
+ //defaultButton = Some(convertButton)
+ }
+}
+
diff --git a/docs/examples/swing/CelsiusConverter2.scala b/docs/examples/swing/CelsiusConverter2.scala
new file mode 100644
index 0000000000..3630d61b61
--- /dev/null
+++ b/docs/examples/swing/CelsiusConverter2.scala
@@ -0,0 +1,36 @@
+package examples.swing
+
+import swing._
+import event._
+
+object CelsiusConverter2 extends SimpleSwingApplication {
+ def newField = new TextField {
+ text = "0"
+ columns = 5
+ horizontalAlignment = Alignment.Right
+ }
+ val celsius = newField
+ val fahrenheit = newField
+
+ listenTo(fahrenheit, celsius)
+ reactions += {
+ case EditDone(`fahrenheit`) =>
+ val f = Integer.parseInt(fahrenheit.text)
+ val c = (f - 32) * 5 / 9
+ celsius.text = c.toString
+ case EditDone(`celsius`) =>
+ val c = Integer.parseInt(celsius.text)
+ val f = c * 9 / 5 + 32
+ fahrenheit.text = f.toString
+ }
+
+ lazy val ui = new FlowPanel(celsius, new Label(" Celsius = "),
+ fahrenheit, new Label(" Fahrenheit")) {
+ border = Swing.EmptyBorder(15, 10, 10, 10)
+ }
+ def top = new MainFrame {
+ title = "Convert Celsius / Fahrenheit"
+ contents = ui
+ }
+}
+
diff --git a/docs/examples/swing/ComboBoxes.scala b/docs/examples/swing/ComboBoxes.scala
new file mode 100644
index 0000000000..c6ee19013a
--- /dev/null
+++ b/docs/examples/swing/ComboBoxes.scala
@@ -0,0 +1,86 @@
+package examples.swing
+
+import swing._
+import event._
+import java.util.Date
+import java.awt.Color
+import java.text.SimpleDateFormat
+import javax.swing.{Icon, ImageIcon}
+
+/**
+ * Demonstrates how to use combo boxes and custom item renderers.
+ *
+ * TODO: clean up layout
+ */
+object ComboBoxes extends SimpleSwingApplication {
+ import ComboBox._
+ lazy val ui = new FlowPanel {
+ contents += new ComboBox(List(1,2,3,4))
+
+ val patterns = List("dd MMMMM yyyy",
+ "dd.MM.yy",
+ "MM/dd/yy",
+ "yyyy.MM.dd G 'at' hh:mm:ss z",
+ "EEE, MMM d, ''yy",
+ "h:mm a",
+ "H:mm:ss:SSS",
+ "K:mm a,z",
+ "yyyy.MMMMM.dd GGG hh:mm aaa")
+ val dateBox = new ComboBox(patterns) { makeEditable() }
+ contents += dateBox
+ val field = new TextField(20) { editable = false }
+ contents += field
+
+ reactions += {
+ case SelectionChanged(`dateBox`) => reformat()
+ }
+ listenTo(dateBox.selection)
+
+ def reformat() {
+ try {
+ val today = new Date
+ val formatter = new SimpleDateFormat(dateBox.selection.item)
+ val dateString = formatter.format(today)
+ field.foreground = Color.black
+ field.text = dateString
+ } catch {
+ case e: IllegalArgumentException =>
+ field.foreground = Color.red
+ field.text = "Error: " + e.getMessage
+ }
+ }
+
+
+ val icons = try {
+ List(new ImageIcon(resourceFromClassloader("images/margarita1.jpg")),
+ new ImageIcon(resourceFromClassloader("images/margarita2.jpg")),
+ new ImageIcon(resourceFromClassloader("images/rose.jpg")),
+ new ImageIcon(resourceFromClassloader("images/banana.jpg")))
+ } catch {
+ case _ =>
+ println("Couldn't load images for combo box")
+ List(Swing.EmptyIcon)
+ }
+
+ val iconBox = new ComboBox(icons) {
+ renderer = new ListView.AbstractRenderer[Icon, Label](new Label) {
+ def configure(list: ListView[_], isSelected: Boolean, focused: Boolean, icon: Icon, index: Int) {
+ component.icon = icon
+ component.xAlignment = Alignment.Center
+ if(isSelected) {
+ component.border = Swing.LineBorder(list.selectionBackground, 3)
+ } else {
+ component.border = Swing.EmptyBorder(3)
+ }
+ }
+ }
+ }
+ contents += iconBox
+ }
+
+ def top = new MainFrame {
+ title = "ComboBoxes Demo"
+ contents = ui
+ }
+}
+
diff --git a/docs/examples/swing/CountButton.scala b/docs/examples/swing/CountButton.scala
new file mode 100644
index 0000000000..5fb14681d6
--- /dev/null
+++ b/docs/examples/swing/CountButton.scala
@@ -0,0 +1,30 @@
+package examples.swing
+
+import scala.swing._
+import scala.swing.event._
+
+object CountButton extends SimpleSwingApplication {
+ def top = new MainFrame {
+ title = "My Frame"
+ contents = new GridPanel(2, 2) {
+ hGap = 3
+ vGap = 3
+ val button = new Button {
+ text = "Press Me!"
+ }
+ contents += button
+ val label = new Label {
+ text = "No button clicks registered"
+ }
+ contents += label
+
+ listenTo(button)
+ var nclicks = 0
+ reactions += {
+ case ButtonClicked(b) =>
+ nclicks += 1
+ label.text = "Number of button clicks: "+nclicks
+ }
+ }
+ }
+}
diff --git a/docs/examples/swing/Dialogs.scala b/docs/examples/swing/Dialogs.scala
new file mode 100644
index 0000000000..0b4ac258cf
--- /dev/null
+++ b/docs/examples/swing/Dialogs.scala
@@ -0,0 +1,176 @@
+package examples.swing
+
+import swing._
+import swing.event._
+
+object Dialogs extends SimpleSwingApplication {
+ import TabbedPane._
+
+ lazy val label = new Label("No Result yet")
+ lazy val tabs = new TabbedPane {
+ pages += new Page("File", new GridBagPanel { grid =>
+ import GridBagPanel._
+ val buttonText = new TextField("Click Me")
+
+ val c = new Constraints
+ c.fill = Fill.Horizontal
+ c.grid = (1,1)
+
+ val chooser = new FileChooser
+ layout(new Button(Action("Open") {
+ chooser.showOpenDialog(grid)
+ })) = c
+
+ c.grid = (1,2)
+ layout(new Button(Action("Save") {
+ chooser.showSaveDialog(grid)
+ })) = c
+
+ c.grid = (1,3)
+ layout(new Button(Action("Custom") {
+ chooser.showDialog(grid, buttonText.text)
+ })) = c
+
+ c.grid = (2,3)
+ layout(new Label(" with Text ")) = c
+
+ c.grid = (3,3)
+ c.ipadx = 50
+ layout(buttonText) = c
+
+ border = Swing.EmptyBorder(5, 5, 5, 5)
+ })
+ pages += new Page("Simple Modal Dialogs", new BorderPanel {
+ import BorderPanel._
+ val mutex = new ButtonGroup
+ val ok = new RadioButton("OK (in the L&F's words)")
+ val ynlf = new RadioButton("Yes/No (in the L&F's words)")
+ val ynp = new RadioButton("Yes/No (in the programmer's words)")
+ val yncp = new RadioButton("Yes/No/Cancel (in the programmer's words)")
+ val radios = List(ok, ynlf, ynp, yncp)
+ mutex.buttons ++= radios
+ mutex.select(ok)
+ val buttons = new BoxPanel(Orientation.Vertical) {
+ contents ++= radios
+ }
+ layout(buttons) = Position.North
+ layout(new Button(Action("Show It!") {
+ import Dialog._
+ mutex.selected.get match {
+ case `ok` =>
+ showMessage(buttons, "Eggs aren't supposed to be green.")
+ case `ynlf` =>
+ label.text = showConfirmation(buttons,
+ "Would you like green eggs and ham?",
+ "An Inane Question") match {
+ case Result.Yes => "Ewww!"
+ case Result.No => "Me neither!"
+ case _ => "Come on -- tell me!"
+ }
+ case `ynp` =>
+ val options = List("Yes, please",
+ "No, thanks",
+ "No eggs, no ham!")
+ label.text = showOptions(buttons,
+ "Would you like some green eggs to go with that ham?",
+ "A Silly Question",
+ entries = options,
+ initial = 2) match {
+ case Result.Yes => "You're kidding!"
+ case Result.No => "I don't like them, either."
+ case _ => "Come on -- 'fess up!"
+ }
+ case `yncp` =>
+ val options = List("Yes, please",
+ "No, thanks",
+ "No eggs, no ham!")
+ label.text = showOptions(buttons,
+ message = "Would you like some green eggs to go with that ham?",
+ title = "A Silly Question",
+ entries = options,
+ initial = 2) match {
+ case Result.Yes => "Here you go: green eggs and ham!"
+ case Result.No => "OK, just the ham, then."
+ case Result.Cancel => "Well, I'm certainly not going to eat them!"
+ case _ => "Please tell me what you want!"
+ }
+ }
+ })) = Position.South
+ })
+ pages += new Page("More Dialogs", new BorderPanel {
+ import BorderPanel._
+ val mutex = new ButtonGroup
+ val pick = new RadioButton("Pick one of several choices")
+ val enter = new RadioButton("Enter some text")
+ val custom = new RadioButton("Custom")
+ val customUndec = new RadioButton("Custom undecorated")
+ val custom2 = new RadioButton("2 custom dialogs")
+ val radios = List(pick, enter, custom, customUndec, custom2)
+ mutex.buttons ++= radios
+ mutex.select(pick)
+ val buttons = new BoxPanel(Orientation.Vertical) {
+ contents ++= radios
+ }
+ layout(buttons) = Position.North
+ layout(new Button(Action("Show It!") {
+ import Dialog._
+ mutex.selected.get match {
+ case `pick` =>
+ val possibilities = List("ham", "spam", "yam")
+ val s = showInput(buttons,
+ "Complete the sentence:\n\"Green eggs and...\"",
+ "Customized Dialog",
+ Message.Plain,
+ Swing.EmptyIcon,
+ possibilities, "ham")
+
+ //If a string was returned, say so.
+ label.text = if ((s != None) && (s.get.length > 0))
+ "Green eggs and... " + s.get + "!"
+ else
+ "Come on, finish the sentence!"
+ case `enter` =>
+ val s = showInput(buttons,
+ "Complete the sentence:\n\"Green eggs and...\"",
+ "Customized Dialog",
+ Message.Plain,
+ Swing.EmptyIcon,
+ Nil, "ham")
+
+ //If a string was returned, say so.
+ label.text = if ((s != None) && (s.get.length > 0))
+ "Green eggs and... " + s.get + "!"
+ else
+ "Come on, finish the sentence!"
+ case `custom` =>
+ val dialog = new Dialog(top)
+ dialog.open()
+ dialog.contents = Button("Close Me!") { dialog.close() }
+ case `customUndec` =>
+ val dialog = new Dialog with RichWindow.Undecorated
+ dialog.open()
+ dialog.contents = Button("Close Me!") { dialog.close() }
+ case `custom2` =>
+ val d1 = new Dialog
+ val d2 = new Dialog(d1)
+ d1.open()
+ d2.open()
+ d1.contents = Button("Close Me! I am the owner and will automatically close the other one") { d1.close() }
+ d2.contents = Button("Close Me!") { d2.close() }
+ }
+ })) = Position.South
+ })
+ }
+
+ lazy val ui: Panel = new BorderPanel {
+ layout(tabs) = BorderPanel.Position.Center
+ layout(label) = BorderPanel.Position.South
+ }
+
+
+ lazy val top = new MainFrame {
+ title = "Dialog Demo"
+ contents = ui
+ }
+}
+
diff --git a/docs/examples/swing/GridBagDemo.scala b/docs/examples/swing/GridBagDemo.scala
new file mode 100644
index 0000000000..60cfc13acb
--- /dev/null
+++ b/docs/examples/swing/GridBagDemo.scala
@@ -0,0 +1,64 @@
+package examples.swing
+
+import swing._
+import swing.event._
+import GridBagPanel._
+import java.awt.Insets
+
+object GridBagDemo extends SimpleSwingApplication {
+ lazy val ui = new GridBagPanel {
+ val c = new Constraints
+ val shouldFill = true
+ if (shouldFill) {
+ c.fill = Fill.Horizontal
+ }
+
+ val button1 = new Button("Button 1")
+
+ c.weightx = 0.5
+
+ c.fill = Fill.Horizontal
+ c.gridx = 0;
+ c.gridy = 0;
+ layout(button1) = c
+
+ val button2 = new Button("Button 2")
+ c.fill = Fill.Horizontal
+ c.weightx = 0.5;
+ c.gridx = 1;
+ c.gridy = 0;
+ layout(button2) = c
+
+ val button3 = new Button("Button 3")
+ c.fill = Fill.Horizontal
+ c.weightx = 0.5;
+ c.gridx = 2;
+ c.gridy = 0;
+ layout(button3) = c
+
+ val button4 = new Button("Long-Named Button 4")
+ c.fill = Fill.Horizontal
+ c.ipady = 40; //make this component tall
+ c.weightx = 0.0;
+ c.gridwidth = 3;
+ c.gridx = 0;
+ c.gridy = 1;
+ layout(button4) = c
+
+ val button5 = new Button("5")
+ c.fill = Fill.Horizontal
+ c.ipady = 0; //reset to default
+ c.weighty = 1.0; //request any extra vertical space
+ c.anchor = Anchor.PageEnd
+ c.insets = new Insets(10,0,0,0); //top padding
+ c.gridx = 1; //aligned with button 2
+ c.gridwidth = 2; //2 columns wide
+ c.gridy = 2; //third row
+ layout(button5) = c
+ }
+
+ def top = new MainFrame {
+ title = "GridBag Demo"
+ contents = ui
+ }
+}
diff --git a/docs/examples/swing/HelloWorld.scala b/docs/examples/swing/HelloWorld.scala
new file mode 100644
index 0000000000..e89bfedd8a
--- /dev/null
+++ b/docs/examples/swing/HelloWorld.scala
@@ -0,0 +1,13 @@
+package examples.swing
+
+import swing._
+
+/**
+ * A simple swing demo.
+ */
+object HelloWorld extends SimpleSwingApplication {
+ def top = new MainFrame {
+ title = "Hello, World!"
+ contents = new Button("Click Me!")
+ }
+}
diff --git a/docs/examples/swing/LabelTest.scala b/docs/examples/swing/LabelTest.scala
new file mode 100644
index 0000000000..edd7a14634
--- /dev/null
+++ b/docs/examples/swing/LabelTest.scala
@@ -0,0 +1,19 @@
+package examples.swing
+
+import scala.swing._
+import scala.swing.event._
+
+object LabelTest extends SimpleSwingApplication {
+ def top = new MainFrame{
+ contents = new Label {
+ text = "Hello"
+ import java.awt.event._
+ listenTo(mouse.clicks)
+ reactions += {
+ case MousePressed(_,_,_,_,_) =>
+ println("Mouse pressed2")
+ }
+ }
+ }
+}
+
diff --git a/docs/examples/swing/LinePainting.scala b/docs/examples/swing/LinePainting.scala
new file mode 100644
index 0000000000..f72f8701ed
--- /dev/null
+++ b/docs/examples/swing/LinePainting.scala
@@ -0,0 +1,53 @@
+package examples.swing
+
+import scala.swing.Swing._
+import scala.swing.{MainFrame, Panel}
+import scala.swing.event._
+import java.awt.{Color, Graphics2D, Point, geom}
+
+/**
+ * Dragging the mouse draws a simple graph
+ *
+ * @author Frank Teubler, Ingo Maier
+ */
+object LinePainting extends SimpleSwingApplication {
+ lazy val ui = new Panel {
+ background = Color.white
+ preferredSize = (200,200)
+
+ focusable = true
+ listenTo(mouse.clicks, mouse.moves, keys)
+
+ reactions += {
+ case e: MousePressed =>
+ moveTo(e.point)
+ requestFocusInWindow()
+ case e: MouseDragged => lineTo(e.point)
+ case e: MouseReleased => lineTo(e.point)
+ case KeyTyped(_,'c',_,_) =>
+ path = new geom.GeneralPath
+ repaint()
+ case _: FocusLost => repaint()
+ }
+
+ /* records the dragging */
+ var path = new geom.GeneralPath
+
+ def lineTo(p: Point) { path.lineTo(p.x, p.y); repaint() }
+ def moveTo(p: Point) { path.moveTo(p.x, p.y); repaint() }
+
+ override def paintComponent(g: Graphics2D) = {
+ super.paintComponent(g)
+ g.setColor(new Color(100,100,100))
+ g.drawString("Press left mouse button and drag to paint." +
+ (if(hasFocus) " Press 'c' to clear." else ""), 10, size.height-10)
+ g.setColor(Color.black)
+ g.draw(path)
+ }
+ }
+
+ def top = new MainFrame {
+ title = "Simple Line Painting Demo"
+ contents = ui
+ }
+}
diff --git a/docs/examples/swing/ListViewDemo.scala b/docs/examples/swing/ListViewDemo.scala
new file mode 100644
index 0000000000..5630f2871d
--- /dev/null
+++ b/docs/examples/swing/ListViewDemo.scala
@@ -0,0 +1,17 @@
+package examples.swing
+
+object ListViewDemo extends SimpleSwingApplication {
+ def top = new MainFrame {
+ case class City(name: String, country: String, population: Int, capital: Boolean)
+ val items = List(City("Lausanne", "Switzerland", 129273, false),
+ City("Paris", "France", 2203817, true),
+ City("New York", "USA", 8363710 , false),
+ City("Berlin", "Germany", 3416300, true),
+ City("Tokio", "Japan", 12787981, true))
+ import ListView._
+ contents = new FlowPanel(new ScrollPane(new ListView(items) {
+ renderer = Renderer(_.name)
+ }))
+ //new ScrollPane(new Table(items)))
+ }
+}
diff --git a/docs/examples/swing/SimpleApplet.scala b/docs/examples/swing/SimpleApplet.scala
new file mode 100644
index 0000000000..502de537a3
--- /dev/null
+++ b/docs/examples/swing/SimpleApplet.scala
@@ -0,0 +1,18 @@
+package examples.swing
+
+import event._
+
+class SimpleApplet extends Applet {
+ object ui extends UI with Reactor {
+ def init() = {
+ val button = new Button("Press here!")
+ val text = new TextArea("Java Version: " + util.Properties.javaVersion + "\n")
+ listenTo(button)
+ reactions += {
+ case ButtonClicked(_) => text.text += "Button Pressed!\n"
+ case _ =>
+ }
+ contents = new BoxPanel(Orientation.Vertical) { contents.append(button, text) }
+ }
+ }
+}
diff --git a/docs/examples/swing/SwingApp.scala b/docs/examples/swing/SwingApp.scala
new file mode 100644
index 0000000000..b3fe7447ef
--- /dev/null
+++ b/docs/examples/swing/SwingApp.scala
@@ -0,0 +1,29 @@
+package examples.swing
+
+import swing._
+import swing.event._
+
+object SwingApp extends SimpleSwingApplication {
+ def top = new MainFrame {
+ title = "SwingApp"
+ var numclicks = 0
+ object label extends Label {
+ val prefix = "Number of button clicks: "
+ text = prefix + "0 "
+ listenTo(button)
+ reactions += {
+ case ButtonClicked(button) =>
+ numclicks = numclicks + 1
+ text = prefix + numclicks
+ }
+ }
+ object button extends Button {
+ text = "I am a button"
+ }
+ contents = new FlowPanel {
+ contents.append(button, label)
+ border = Swing.EmptyBorder(5, 5, 5, 5)
+ }
+ }
+}
+
diff --git a/docs/examples/swing/TableSelection.scala b/docs/examples/swing/TableSelection.scala
new file mode 100644
index 0000000000..8c8ea4ffcc
--- /dev/null
+++ b/docs/examples/swing/TableSelection.scala
@@ -0,0 +1,96 @@
+package examples.swing
+
+import java.awt.Dimension
+import swing.event._
+
+object TableSelection extends SimpleSwingApplication {
+ val model = Array(List("Mary", "Campione", "Snowboarding", 5, false).toArray,
+ List("Alison", "Huml", "Rowing", 5, false).toArray,
+ List("Kathy", "Walrath", "Knitting", 5, false).toArray,
+ List("Sharon", "Zakhour", "Speed reading", 5, false).toArray,
+ List("Philip", "Milne", "Pool", 5, false).toArray)
+ /*val model = Array.tabulate(10000) { i =>
+ List("Mary", "Campione", "Snowboarding", i, false).toArray
+ }*/
+
+ lazy val ui = new BoxPanel(Orientation.Vertical) {
+ val table = new Table(model, Array("First Name", "Last Name", "Sport", "# of Years", "Vegetarian")) {
+ preferredViewportSize = new Dimension(500, 70)
+ }
+ //1.6:table.fillsViewportHeight = true
+ listenTo(table.selection)
+
+ contents += new ScrollPane(table)
+ contents += new Label("Selection Mode")
+
+ def radio(mutex: ButtonGroup, text: String): RadioButton = {
+ val b = new RadioButton(text)
+ listenTo(b)
+ mutex.buttons += b
+ contents += b
+ b
+ }
+
+ val intervalMutex = new ButtonGroup
+ val multiInterval = radio(intervalMutex, "Multiple Interval Selection")
+ val elementInterval = radio(intervalMutex, "Single Selection")
+ val singleInterval = radio(intervalMutex, "Single Interval Selection")
+ intervalMutex.select(multiInterval)
+
+ contents += new Label("Selection Options")
+ val elemMutex = new ButtonGroup
+ val rowSelection = radio(elemMutex, "Row Selection")
+ val columnSelection = radio(elemMutex, "Column Selection")
+ val cellSelection = radio(elemMutex, "Cell Selection")
+ elemMutex.select(rowSelection)
+
+ val output = new TextArea(5, 40) { editable = false }
+ contents += new ScrollPane(output)
+
+ def outputSelection() {
+ output.append("Lead: " + table.selection.rows.leadIndex + "," +
+ table.selection.columns.leadIndex + ". ")
+ output.append("Rows:")
+ for (c <- table.selection.rows) output.append(" " + c)
+ output.append(". Columns:")
+ for (c <- table.selection.columns) output.append(" " + c)
+ output.append(".\n")
+ }
+
+ reactions += {
+ case ButtonClicked(`multiInterval`) =>
+ table.selection.intervalMode = Table.IntervalMode.MultiInterval
+ if (cellSelection.selected) {
+ elemMutex.select(rowSelection)
+ table.selection.elementMode = Table.ElementMode.None
+ }
+ cellSelection.enabled = false
+ case ButtonClicked(`elementInterval`) =>
+ table.selection.intervalMode = Table.IntervalMode.Single
+ cellSelection.enabled = true
+ case ButtonClicked(`singleInterval`) =>
+ table.selection.intervalMode = Table.IntervalMode.SingleInterval
+ cellSelection.enabled = true
+ case ButtonClicked(`rowSelection`) =>
+ if (rowSelection.selected)
+ table.selection.elementMode = Table.ElementMode.Row
+ case ButtonClicked(`columnSelection`) =>
+ if (columnSelection.selected)
+ table.selection.elementMode = Table.ElementMode.Column
+ case ButtonClicked(`cellSelection`) =>
+ if (cellSelection.selected)
+ table.selection.elementMode = Table.ElementMode.Cell
+ case TableRowsSelected(_, range, false) =>
+ output.append("Rows selected, changes: " + range + "\n")
+ outputSelection()
+ case TableColumnsSelected(_, range, false) =>
+ output.append("Columns selected, changes " + range + "\n")
+ outputSelection()
+ }
+ }
+
+ def top = new MainFrame {
+ title = "Table Selection"
+ contents = ui
+ }
+}
diff --git a/docs/examples/swing/UIDemo.scala b/docs/examples/swing/UIDemo.scala
new file mode 100644
index 0000000000..6d77c049e0
--- /dev/null
+++ b/docs/examples/swing/UIDemo.scala
@@ -0,0 +1,147 @@
+package examples.swing
+
+import swing._
+import event._
+import Swing._
+import ListView._
+
+object UIDemo extends SimpleSwingApplication {
+ def top = new MainFrame {
+ title = "Scala Swing Demo"
+
+ /*
+ * Create a menu bar with a couple of menus and menu items and
+ * set the result as this frame's menu bar.
+ */
+ menuBar = new MenuBar {
+ contents += new Menu("A Menu") {
+ contents += new MenuItem("An item")
+ contents += new MenuItem(Action("An action item") {
+ println("Action '"+ title +"' invoked")
+ })
+ contents += new Separator
+ contents += new CheckMenuItem("Check me")
+ contents += new CheckMenuItem("Me too!")
+ contents += new Separator
+ val a = new RadioMenuItem("a")
+ val b = new RadioMenuItem("b")
+ val c = new RadioMenuItem("c")
+ val mutex = new ButtonGroup(a,b,c)
+ contents ++= mutex.buttons
+ }
+ contents += new Menu("Empty Menu")
+ }
+
+ /*
+ * The root component in this frame is a panel with a border layout.
+ */
+ contents = new BorderPanel {
+ import BorderPanel.Position._
+
+ var reactLive = false
+
+ val tabs = new TabbedPane {
+ import TabbedPane._
+ val buttons = new FlowPanel {
+ border = Swing.EmptyBorder(5,5,5,5)
+
+ contents += new BoxPanel(Orientation.Vertical) {
+ border = CompoundBorder(TitledBorder(EtchedBorder, "Radio Buttons"), EmptyBorder(5,5,5,10))
+ val a = new RadioButton("Green Vegetables")
+ val b = new RadioButton("Red Meat")
+ val c = new RadioButton("White Tofu")
+ val mutex = new ButtonGroup(a,b,c)
+ contents ++= mutex.buttons
+ }
+ contents += new BoxPanel(Orientation.Vertical) {
+ border = CompoundBorder(TitledBorder(EtchedBorder, "Check Boxes"), EmptyBorder(5,5,5,10))
+ val paintLabels = new CheckBox("Paint Labels")
+ val paintTicks = new CheckBox("Paint Ticks")
+ val snapTicks = new CheckBox("Snap To Ticks")
+ val live = new CheckBox("Live")
+ contents.append(paintLabels, paintTicks, snapTicks, live)
+ listenTo(paintLabels, paintTicks, snapTicks, live)
+ reactions += {
+ case ButtonClicked(`paintLabels`) =>
+ slider.paintLabels = paintLabels.selected
+ case ButtonClicked(`paintTicks`) =>
+ slider.paintTicks = paintTicks.selected
+ case ButtonClicked(`snapTicks`) =>
+ slider.snapToTicks = snapTicks.selected
+ case ButtonClicked(`live`) =>
+ reactLive = live.selected
+ }
+ }
+ contents += new Button(Action("Center Frame") { centerOnScreen() })
+ }
+ pages += new Page("Buttons", buttons)
+ pages += new Page("GridBag", GridBagDemo.ui)
+ pages += new Page("Converter", CelsiusConverter2.ui)
+ pages += new Page("Tables", TableSelection.ui)
+ pages += new Page("Dialogs", Dialogs.ui)
+ pages += new Page("Combo Boxes", ComboBoxes.ui)
+ pages += new Page("Split Panes",
+ new SplitPane(Orientation.Vertical, new Button("Hello"), new Button("World")) {
+ continuousLayout = true
+ })
+
+ val password = new FlowPanel {
+ contents += new Label("Enter your secret password here ")
+ val field = new PasswordField(10)
+ contents += field
+ val label = new Label(field.text)
+ contents += label
+ listenTo(field)
+ reactions += {
+ case EditDone(`field`) => label.text = field.password.mkString
+ }
+ }
+
+ pages += new Page("Password", password)
+ pages += new Page("Painting", LinePainting.ui)
+ //pages += new Page("Text Editor", TextEditor.ui)
+ }
+
+ val list = new ListView(tabs.pages) {
+ selectIndices(0)
+ selection.intervalMode = ListView.IntervalMode.Single
+ renderer = ListView.Renderer(_.title)
+ }
+ val center = new SplitPane(Orientation.Vertical, new ScrollPane(list), tabs) {
+ oneTouchExpandable = true
+ continuousLayout = true
+ }
+ layout(center) = Center
+
+ /*
+ * This slider is used above, so we need lazy initialization semantics.
+ * Objects or lazy vals are the way to go, but objects give us better
+ * type inference at times.
+ */
+ object slider extends Slider {
+ min = 0
+ value = tabs.selection.index
+ max = tabs.pages.size-1
+ majorTickSpacing = 1
+ }
+ layout(slider) = South
+
+ /*
+ * Establish connection between the tab pane, slider, and list view.
+ */
+ listenTo(slider)
+ listenTo(tabs.selection)
+ listenTo(list.selection)
+ reactions += {
+ case ValueChanged(`slider`) =>
+ if(!slider.adjusting || reactLive) tabs.selection.index = slider.value
+ case SelectionChanged(`tabs`) =>
+ slider.value = tabs.selection.index
+ list.selectIndices(tabs.selection.index)
+ case SelectionChanged(`list`) =>
+ if (list.selection.items.length == 1)
+ tabs.selection.page = list.selection.items(0)
+ }
+ }
+ }
+}
diff --git a/docs/examples/swing/images/banana.jpg b/docs/examples/swing/images/banana.jpg
new file mode 100644
index 0000000000..62267a4325
--- /dev/null
+++ b/docs/examples/swing/images/banana.jpg
Binary files differ
diff --git a/docs/examples/swing/images/margarita1.jpg b/docs/examples/swing/images/margarita1.jpg
new file mode 100644
index 0000000000..d315f7c79f
--- /dev/null
+++ b/docs/examples/swing/images/margarita1.jpg
Binary files differ
diff --git a/docs/examples/swing/images/margarita2.jpg b/docs/examples/swing/images/margarita2.jpg
new file mode 100644
index 0000000000..c8b076e5f9
--- /dev/null
+++ b/docs/examples/swing/images/margarita2.jpg
Binary files differ
diff --git a/docs/examples/swing/images/rose.jpg b/docs/examples/swing/images/rose.jpg
new file mode 100644
index 0000000000..d4a2b58062
--- /dev/null
+++ b/docs/examples/swing/images/rose.jpg
Binary files differ