You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- remove the commented former and unused class `RefBuffer`
- add more information about architecture (events)
to read-me; update information about versions and branches
Copy file name to clipboardExpand all lines: README.md
+45-9Lines changed: 45 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -14,28 +14,35 @@ The widget class hierarchy loosely resembles that of Java Swing. The main differ
14
14
a number of components, like TextField, CheckBox, RadioButton, and so on. Our guess is that
15
15
this architecture was chosen because Java lacks multiple inheritance.
16
16
In scala-swing, components that can have child components extend the Container trait.
17
-
-Layout managers and panels are coupled. There is no way to exchange the layout manager
17
+
- Layout managers and panels are coupled. There is no way to exchange the layout manager
18
18
of a panel. As a result, the layout constraints for widgets can be typed.
19
19
(Note that you gain more type-safety and don't loose much flexibility here. Besides
20
20
being not a common operation, exchanging the layout manager of a panel in Java
21
21
Swing almost always leads to exchanging the layout constraints for every of the panel's
22
22
child component. In the end, it is not more work to move all children to a newly created
23
23
panel.)
24
-
25
-
The event system. TODO.
26
-
24
+
- Widget hierarchies are built by adding children to their parent container's `contents`
25
+
collection. The typical usage style is to create anonymous subclasses of the widgets to
26
+
customize their properties, and nest children and event reactions.
27
+
- The scala-swing event system follows a different approach than the underlying Java system.
28
+
Instead of add event listeners with a particular interface (such as `java.awt.ActionListener`),
29
+
a `Reactor` instances announces the interest in receiving events by calling `listenTo` for
30
+
a `Publisher`. Publishers are also reactors and listen to themselves per default as a convenience.
31
+
A reactor contains an object `reactions` which serves as a convenient place to register observers
32
+
by adding partial functions that pattern match for any event that the observer is interested in.
33
+
This is shown in the examples section below.
27
34
- For more details see [SIP-8](docs/SIP-8.md)
28
35
29
36
The library comprises two main packages:
30
37
31
38
-`scala.swing`: All widget classes and traits.
32
39
-`scala.swing.event`: The event hierarchy.
33
40
34
-
35
41
## Examples
36
42
37
43
A number of examples can be found in the `examples` project.
38
-
A good place to start is `[12] scala.swing.examples.UIDemo` (_index number may be different for you_). This pulls in the all the other examples into a tabbed window.
44
+
A good place to start is `[16] scala.swing.examples.UIDemo`.
45
+
This pulls in the all the other examples into a tabbed window.
39
46
40
47
```
41
48
$ sbt examples/run
@@ -62,22 +69,51 @@ Multiple main classes detected, select one to run:
62
69
Enter number:
63
70
```
64
71
72
+
### Frame with a Button
73
+
74
+
The following example shows how to plug components and containers together and react to a
75
+
mouse click on a button:
76
+
77
+
```scala
78
+
importscala.swing._
79
+
80
+
newFrame {
81
+
title ="Hello world"
82
+
83
+
contents =newFlowPanel {
84
+
contents +=newLabel("Launch rainbows:")
85
+
contents +=newButton("Click me") {
86
+
reactions += {
87
+
case event.ButtonClicked(_) =>
88
+
println("All the colours!")
89
+
}
90
+
}
91
+
}
92
+
93
+
pack()
94
+
centerOnScreen()
95
+
open()
96
+
}
97
+
```
65
98
66
99
## Versions
67
100
68
101
- The `1.0.x` branch is compiled with JDK 6 and released for Scala 2.10, 2.11. The 1.0.x releases can be used with both Scala versions on JDK 6 or newer.
69
102
- The `2.0.x` branch is compiled with JDK 8 and released for Scala 2.11 and 2.12.
70
103
- When using Scala 2.11, you can use the Scala swing 2.0.x releases on JDK 6 or newer.
71
104
- Scala 2.12 requires you to use JDK 8 (that has nothing to do with scala-swing).
105
+
- Version `2.1.0` adds support for Scala 2.13, while dropping Scala 2.10.
72
106
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.
107
+
The reason to have different major versions is to allow for binary incompatible changes. Also, some java-swing classes were
108
+
generified in JDK 7 (see [SI-3634](https://issues.scala-lang.org/browse/SI-3634)) and require the scala-swing sources to be adjusted.
74
109
75
110
76
111
## API documentation (Scaladoc)
77
112
78
-
The API documentation for scala-swing can be found at [http://www.scala-lang.org/documentation/api.html](http://www.scala-lang.org/documentation/api.html).
113
+
The API documentation for scala-swing can be found
114
+
at [http://www.scala-lang.org/documentation/api.html](http://www.scala-lang.org/documentation/api.html).
79
115
80
116
81
117
## Current Work
82
118
83
-
Current changes are being made on the `2.0.x` branch.
119
+
Current changes are being made on the `work` branch.
0 commit comments