Skip to content

Commit ca1579e

Browse files
committed
cross-compiles Scala 2.11, 2.12, 2.13.0-M5.
- introduce SetWrapper and MapWrapper, similar to @som-snytt 's shims (seems we can't do without) - clean up code - add scala.swing.Seq alias (as in @som-snytt 's version) - TODO: ListView#selection.items is still `???`
1 parent 8407cac commit ca1579e

File tree

104 files changed

+482
-416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+482
-416
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
[<img src="https://img.shields.io/maven-central/v/org.scala-lang.modules/scala-swing_2.12.svg?label=latest%20release%20for%202.12"/>](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.scala-lang.modules%20a%3Ascala-swing_2.12)
66
[![Stories in Ready](https://badge.waffle.io/scala/scala-swing.svg?label=ready&title=Ready)](http://waffle.io/scala/scala-swing)
77

8-
This is now community maintained by @benhutchison & @Sciss. If you're interested in helping then contact them or @adriaanm.
8+
This is now community maintained by @benhutchison & @Sciss. If you are interested in helping then contact them or @adriaanm.
99

1010
This is a UI library that will wrap most of Java Swing for Scala in a straightforward manner.
1111
The widget class hierarchy loosely resembles that of Java Swing. The main differences are:
1212

13-
- In Java Swing all components are containers per default. This doesn't make much sense for
13+
- In Java Swing all components are containers per default. This does not make much sense for
1414
a number of components, like TextField, CheckBox, RadioButton, and so on. Our guess is that
1515
this architecture was chosen because Java lacks multiple inheritance.
1616
In scala-swing, components that can have child components extend the Container trait.
@@ -43,21 +43,21 @@ $ sbt examples/run
4343
Multiple main classes detected, select one to run:
4444
4545
[1] scala.swing.examples.ButtonApp
46-
[2] scala.swing.examples.Dialogs
47-
[3] scala.swing.examples.ComboBoxes
48-
[4] scala.swing.examples.CelsiusConverter2
49-
[5] scala.swing.examples.ListViewDemo
50-
[6] scala.swing.examples.HelloWorld
51-
[7] scala.swing.examples.LabelTest
52-
[8] scala.swing.examples.PopupDemo
53-
[9] scala.swing.examples.ColorChooserDemo
54-
[10] scala.swing.examples.LinePainting
55-
[11] scala.swing.examples.GridBagDemo
56-
[12] scala.swing.examples.UIDemo
57-
[13] scala.swing.examples.TableSelection
58-
[14] scala.swing.examples.CelsiusConverter
59-
[15] scala.swing.examples.SwingApp
60-
[16] scala.swing.examples.CountButton
46+
[2] scala.swing.examples.CelsiusConverter
47+
[3] scala.swing.examples.CelsiusConverter2
48+
[4] scala.swing.examples.ColorChooserDemo
49+
[5] scala.swing.examples.ComboBoxes
50+
[6] scala.swing.examples.CountButton
51+
[7] scala.swing.examples.Dialogs
52+
[8] scala.swing.examples.GridBagDemo
53+
[9] scala.swing.examples.HelloWorld
54+
[10] scala.swing.examples.LabelTest
55+
[11] scala.swing.examples.LinePainting
56+
[12] scala.swing.examples.ListViewDemo
57+
[13] scala.swing.examples.PopupDemo
58+
[14] scala.swing.examples.SwingApp
59+
[15] scala.swing.examples.TableSelection
60+
[16] scala.swing.examples.UIDemo
6161
6262
Enter number:
6363
```
@@ -70,7 +70,7 @@ Enter number:
7070
- When using Scala 2.11, you can use the Scala swing 2.0.x releases on JDK 6 or newer.
7171
- Scala 2.12 requires you to use JDK 8 (that has nothing to do with scala-swing).
7272

73-
The reason to have two versions is to allow for binary incompatible changes. Also, some java-swing classes were generified in JDK 7 (see [SI-3634](https://issues.scala-lang.org/browse/SI-3634)) and require the scala-swing soruces to be adjusted.
73+
The reason to have two versions is to allow for binary incompatible changes. Also, some java-swing classes were generified in JDK 7 (see [SI-3634](https://issues.scala-lang.org/browse/SI-3634)) and require the scala-swing sources to be adjusted.
7474

7575

7676
## API documentation (Scaladoc)

build.sbt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ name := "scala-swing"
66

77
version := "2.1.0-SNAPSHOT"
88

9-
scalacOptions ++= Seq("-deprecation", "-feature")
9+
scalacOptions in ThisBuild ++= Seq("-deprecation", "-feature")
1010

1111
// Map[JvmMajorVersion, List[(ScalaVersion, UseForPublishing)]]
1212
scalaVersionsByJvm in ThisBuild := Map(
13-
8 -> List("2.11.12", "2.12.6", "2.13.0-M5").map(_ -> true),
14-
9 -> List("2.11.12", "2.12.6", "2.13.0-M5").map(_ -> false),
15-
10 -> List("2.11.12", "2.12.6", "2.13.0-M5").map(_ -> false),
16-
11 -> List("2.11.12", "2.12.6", "2.13.0-M5").map(_ -> false)
13+
8 -> List("2.11.12", "2.12.8", "2.13.0-M5").map(_ -> true),
14+
9 -> List("2.11.12", "2.12.8", "2.13.0-M5").map(_ -> false),
15+
10 -> List("2.11.12", "2.12.8", "2.13.0-M5").map(_ -> false),
16+
11 -> List("2.11.12", "2.12.8", "2.13.0-M5").map(_ -> false)
1717
)
1818

19-
scalaVersion in ThisBuild := "2.12.8" // for testing
19+
scalaVersion in ThisBuild := "2.13.0-M5" // for testing
2020

2121
OsgiKeys.exportPackage := Seq(s"scala.swing.*;version=${version.value}")
2222

examples/src/main/scala/scala/swing/examples/ButtonApp.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scala.swing._
1212
import scala.swing.event._
1313

1414
object ButtonApp extends SimpleSwingApplication {
15-
def top = new MainFrame {
15+
def top: Frame = new MainFrame {
1616
title = "My Frame"
1717
contents = new GridPanel(2, 2) {
1818
hGap = 3
@@ -27,4 +27,3 @@ object ButtonApp extends SimpleSwingApplication {
2727
size = new Dimension(300, 80)
2828
}
2929
}
30-

examples/src/main/scala/scala/swing/examples/CelsiusConverter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import scala.swing.event._
1515
* A GUI app to convert celsius to centigrade
1616
*/
1717
object CelsiusConverter extends SimpleSwingApplication {
18-
def top = new MainFrame {
18+
def top: Frame = new MainFrame {
1919
title = "Convert Celsius to Fahrenheit"
2020
val tempCelsius = new TextField
2121
val celsiusLabel = new Label {
@@ -42,7 +42,7 @@ object CelsiusConverter extends SimpleSwingApplication {
4242
}
4343
}
4444
contents = new GridPanel(2, 2) {
45-
contents.append(tempCelsius, celsiusLabel, convertButton, fahrenheitLabel)
45+
contents ++= Seq(tempCelsius, celsiusLabel, convertButton, fahrenheitLabel)
4646
border = Swing.EmptyBorder(10, 10, 10, 10)
4747
}
4848
//defaultButton = Some(convertButton)

examples/src/main/scala/scala/swing/examples/CelsiusConverter2.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import scala.swing._
1212
import scala.swing.event._
1313

1414
object CelsiusConverter2 extends SimpleSwingApplication {
15-
def newField = new TextField {
15+
def newField: TextField = new TextField {
1616
text = "0"
1717
columns = 5
1818
horizontalAlignment = Alignment.Right
1919
}
2020

21-
val celsius = newField
22-
val fahrenheit = newField
21+
val celsius = newField
22+
val fahrenheit = newField
2323

2424
listenTo(fahrenheit, celsius)
2525
reactions += {
@@ -38,7 +38,7 @@ object CelsiusConverter2 extends SimpleSwingApplication {
3838
border = Swing.EmptyBorder(15, 10, 10, 10)
3939
}
4040

41-
def top = new MainFrame {
41+
def top: Frame = new MainFrame {
4242
title = "Convert Celsius / Fahrenheit"
4343
contents = ui
4444
}

examples/src/main/scala/scala/swing/examples/ColorChooserDemo.scala

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
package scala.swing.examples
1010

1111
import java.awt.{Color, Font}
12+
13+
import scala.swing.BorderPanel._
14+
import scala.swing.Swing._
1215
import scala.swing._
1316
import scala.swing.event._
14-
import scala.swing.Swing._
15-
import scala.swing.BorderPanel._
1617

1718
/**
1819
* Demo for ColorChooser.
@@ -21,23 +22,23 @@ import scala.swing.BorderPanel._
2122
* @author andy@hicks.net
2223
*/
2324
object ColorChooserDemo extends SimpleSwingApplication {
24-
def top = new MainFrame {
25+
def top: Frame = new MainFrame {
2526
title = "ColorChooser Demo"
2627
size = new Dimension(400, 400)
2728

2829
contents = ui
2930
}
3031

31-
val banner = new Label("Welcome to Scala Swing") {
32+
val banner: Label = new Label("Welcome to Scala Swing") {
3233
horizontalAlignment = Alignment.Center
3334
foreground = Color.yellow
3435
background = Color.blue
3536
opaque = true
3637
font = new Font("SansSerif", Font.BOLD, 24)
3738
}
3839

39-
def ui = new BorderPanel {
40-
val colorChooser = new ColorChooser {
40+
def ui: BorderPanel = new BorderPanel {
41+
val colorChooser: ColorChooser = new ColorChooser {
4142
reactions += {
4243
case ColorChanged(_, c) =>
4344
banner.foreground = c
@@ -46,13 +47,13 @@ object ColorChooserDemo extends SimpleSwingApplication {
4647

4748
colorChooser.border = TitledBorder(EtchedBorder, "Choose Text Color")
4849

49-
val bannerArea = new BorderPanel {
50+
val bannerArea: BorderPanel = new BorderPanel {
5051
layout(banner) = Position.Center
5152
border = TitledBorder(EtchedBorder, "Banner")
5253
}
5354

5455
// Display a color selection dialog when button pressed
55-
val selectColor = new Button("Choose Background Color") {
56+
val selectColor: Button = new Button("Choose Background Color") {
5657
reactions += {
5758
case ButtonClicked(_) =>
5859
ColorChooser.showDialog(this, "Test", Color.red) match {
@@ -62,8 +63,8 @@ object ColorChooserDemo extends SimpleSwingApplication {
6263
}
6364
}
6465

65-
layout(bannerArea) = Position.North
66-
layout(colorChooser) = Position.Center
67-
layout(selectColor) = Position.South
66+
layout(bannerArea) = Position.North
67+
layout(colorChooser) = Position.Center
68+
layout(selectColor) = Position.South
6869
}
6970
}

examples/src/main/scala/scala/swing/examples/ComboBoxes.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
package scala.swing.examples
1010

11-
import scala.swing._
12-
import scala.swing.event._
13-
import java.util.Date
1411
import java.awt.Color
1512
import java.text.SimpleDateFormat
13+
import java.util.Date
14+
1615
import javax.swing.{Icon, ImageIcon}
1716

17+
import scala.swing._
18+
import scala.swing.event._
19+
1820
/**
1921
* Demonstrates how to use combo boxes and custom item renderers.
2022
*
@@ -24,7 +26,7 @@ object ComboBoxes extends SimpleSwingApplication {
2426

2527
import ComboBox._
2628

27-
lazy val ui = new FlowPanel {
29+
lazy val ui: FlowPanel = new FlowPanel {
2830
contents += new ComboBox(List(1, 2, 3, 4))
2931

3032
val patterns = List(
@@ -100,10 +102,9 @@ object ComboBoxes extends SimpleSwingApplication {
100102
contents += iconBox
101103
}
102104

103-
def top = new MainFrame {
105+
def top: Frame = new MainFrame {
104106
title = "ComboBoxes Demo"
105107
contents = ui
106108
}
107-
108109
}
109110

examples/src/main/scala/scala/swing/examples/CountButton.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import scala.swing._
1212
import scala.swing.event._
1313

1414
object CountButton extends SimpleSwingApplication {
15-
def top = new MainFrame {
15+
def top: Frame = new MainFrame {
1616
title = "My Frame"
1717
contents = new GridPanel(2, 2) {
1818
hGap = 3
@@ -27,11 +27,11 @@ object CountButton extends SimpleSwingApplication {
2727
contents += label
2828

2929
listenTo(button)
30-
var nclicks = 0
30+
var nClicks = 0
3131
reactions += {
32-
case ButtonClicked(b) =>
33-
nclicks += 1
34-
label.text = "Number of button clicks: " + nclicks
32+
case ButtonClicked(_) =>
33+
nClicks += 1
34+
label.text = "Number of button clicks: " + nClicks
3535
}
3636
}
3737
}

examples/src/main/scala/scala/swing/examples/Dialogs.scala

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ object Dialogs extends SimpleSwingApplication {
5656
import BorderPanel._
5757

5858
val mutex = new ButtonGroup
59-
val ok = new RadioButton("OK (in the L&F's words)")
60-
val ynlf = new RadioButton("Yes/No (in the L&F's words)")
61-
val ynp = new RadioButton("Yes/No (in the programmer's words)")
62-
val yncp = new RadioButton("Yes/No/Cancel (in the programmer's words)")
59+
val ok = new RadioButton("OK (in the L&F's words)")
60+
val ynlf = new RadioButton("Yes/No (in the L&F's words)")
61+
val ynp = new RadioButton("Yes/No (in the programmer's words)")
62+
val yncp = new RadioButton("Yes/No/Cancel (in the programmer's words)")
6363
val radios = List(ok, ynlf, ynp, yncp)
6464
mutex.buttons ++= radios
6565
mutex.select(ok)
@@ -76,10 +76,10 @@ object Dialogs extends SimpleSwingApplication {
7676
label.text = showConfirmation(buttons,
7777
"Would you like green eggs and ham?",
7878
"An Inane Question") match {
79-
case Result.Yes => "Ewww!"
80-
case Result.No => "Me neither!"
81-
case _ => "Come on -- tell me!"
82-
}
79+
case Result.Yes => "Ewww!"
80+
case Result.No => "Me neither!"
81+
case _ => "Come on -- tell me!"
82+
}
8383
case `ynp` =>
8484
val options = List("Yes, please",
8585
"No, thanks",
@@ -89,10 +89,10 @@ object Dialogs extends SimpleSwingApplication {
8989
"A Silly Question",
9090
entries = options,
9191
initial = 2) match {
92-
case Result.Yes => "You're kidding!"
93-
case Result.No => "I don't like them, either."
94-
case _ => "Come on -- 'fess up!"
95-
}
92+
case Result.Yes => "You're kidding!"
93+
case Result.No => "I don't like them, either."
94+
case _ => "Come on -- 'fess up!"
95+
}
9696
case `yncp` =>
9797
val options = List("Yes, please",
9898
"No, thanks",
@@ -102,24 +102,24 @@ object Dialogs extends SimpleSwingApplication {
102102
title = "A Silly Question",
103103
entries = options,
104104
initial = 2) match {
105-
case Result.Yes => "Here you go: green eggs and ham!"
106-
case Result.No => "OK, just the ham, then."
107-
case Result.Cancel => "Well, I'm certainly not going to eat them!"
108-
case _ => "Please tell me what you want!"
109-
}
105+
case Result.Yes => "Here you go: green eggs and ham!"
106+
case Result.No => "OK, just the ham, then."
107+
case Result.Cancel => "Well, I'm certainly not going to eat them!"
108+
case _ => "Please tell me what you want!"
109+
}
110110
}
111111
})) = Position.South
112112
})
113113
pages += new Page("More Dialogs", new BorderPanel {
114114

115115
import BorderPanel._
116116

117-
val mutex = new ButtonGroup
118-
val pick = new RadioButton("Pick one of several choices")
119-
val enter = new RadioButton("Enter some text")
120-
val custom = new RadioButton("Custom")
117+
val mutex = new ButtonGroup
118+
val pick = new RadioButton("Pick one of several choices")
119+
val enter = new RadioButton("Enter some text")
120+
val custom = new RadioButton("Custom")
121121
val customUndec = new RadioButton("Custom undecorated")
122-
val custom2 = new RadioButton("2 custom dialogs")
122+
val custom2 = new RadioButton("2 custom dialogs")
123123
val radios = List(pick, enter, custom, customUndec, custom2)
124124
mutex.buttons ++= radios
125125
mutex.select(pick)
@@ -140,7 +140,7 @@ object Dialogs extends SimpleSwingApplication {
140140
possibilities, "ham")
141141

142142
//If a string was returned, say so.
143-
label.text = if ((s != None) && (s.get.length > 0))
143+
label.text = if (s.isDefined && (s.get.length > 0))
144144
"Green eggs and... " + s.get + "!"
145145
else
146146
"Come on, finish the sentence!"
@@ -153,7 +153,7 @@ object Dialogs extends SimpleSwingApplication {
153153
Nil, "ham")
154154

155155
//If a string was returned, say so.
156-
label.text = if ((s != None) && (s.get.length > 0))
156+
label.text = if (s.isDefined && (s.get.length > 0))
157157
"Green eggs and... " + s.get + "!"
158158
else
159159
"Come on, finish the sentence!"
@@ -191,7 +191,7 @@ object Dialogs extends SimpleSwingApplication {
191191
}
192192

193193

194-
lazy val top = new MainFrame {
194+
lazy val top: Frame = new MainFrame {
195195
title = "Dialog Demo"
196196
contents = ui
197197
}

0 commit comments

Comments
 (0)