|
8 | 8 |
|
9 | 9 | package scala
|
10 | 10 |
|
11 |
| -/** |
12 |
| - * Useful imports that do not have wrappers. |
13 |
| - */ |
| 11 | +/** Scala-swing is a graphical user interface library that will wrap most of Java Swing |
| 12 | + * for Scala in a straightforward manner. |
| 13 | + * |
| 14 | + * ==Overview== |
| 15 | + * |
| 16 | + * The widget class hierarchy loosely resembles that of Java Swing. |
| 17 | + * The main differences are: |
| 18 | + * |
| 19 | + * - In Java Swing all components are containers per default. This does not make much sense for a number |
| 20 | + * of components, like [[scala.swing.TextField]], [[scala.swing.CheckBox]], [[scala.swing.RadioButton]], |
| 21 | + * and so on. Our guess is that this architecture |
| 22 | + * was chosen because Java lacks multiple inheritance. In scala-swing, components that can have child |
| 23 | + * components extend the [[scala.swing.Container]] trait. |
| 24 | + * - Layout managers and panels are coupled. There is no way to exchange the layout manager of a panel. |
| 25 | + * As a result, the layout constraints for widgets can be typed. (Note that you gain more type-safety |
| 26 | + * and do not loose much flexibility here. Besides being not a common operation, exchanging the layout |
| 27 | + * manager of a panel in Java Swing almost always leads to exchanging the layout constraints for every |
| 28 | + * of the panel's child component. In the end, it is not more work to move all children to a newly |
| 29 | + * created panel.) |
| 30 | + * - Widget hierarchies are built by adding children to their parent container's contents collection. |
| 31 | + * The typical usage style is to create anonymous subclasses of the widgets to customize their |
| 32 | + * properties, and nest children and event reactions. |
| 33 | + * - The scala-swing event system follows a different approach than the underlying Java system. Instead |
| 34 | + * of adding event listeners with a particular interface (such as `java.awt.ActionListener`), |
| 35 | + * a [[scala.swing.Reactor]] |
| 36 | + * instance announces the interest in receiving events by calling `listenTo` for a [[scala.swing.Publisher]]. |
| 37 | + * Publishers |
| 38 | + * are also reactors and listen to themselves per default as a convenience. A reactor contains an object |
| 39 | + * `reactions` which serves as a convenient place to register observers by adding partial functions that |
| 40 | + * pattern match for any event that the observer is interested in. This is shown in the examples section |
| 41 | + * below. |
| 42 | + * - For more details see [[https://github.com/scala/scala-swing/blob/work/docs/SIP-8.md SIP-8]]. |
| 43 | + * |
| 44 | + * Scala-swing comprises two main packages: |
| 45 | + * |
| 46 | + * - `scala.swing`: All widget classes and traits. |
| 47 | + * - `scala.swing.event`: The event hierarchy. |
| 48 | + * |
| 49 | + * This package object contains useful type aliases that do not have wrappers. |
| 50 | + * |
| 51 | + * ==Examples== |
| 52 | + * |
| 53 | + * The following example shows how to plug components and containers together and react to a |
| 54 | + * mouse click on a button: |
| 55 | + * |
| 56 | + * {{{ |
| 57 | + * import scala.swing._ |
| 58 | + * |
| 59 | + * new Frame { |
| 60 | + * title = "Hello world" |
| 61 | + * |
| 62 | + * contents = new FlowPanel { |
| 63 | + * contents += new Label("Launch rainbows:") |
| 64 | + * contents += new Button("Click me") { |
| 65 | + * reactions += { |
| 66 | + * case event.ButtonClicked(_) => |
| 67 | + * println("All the colours!") |
| 68 | + * } |
| 69 | + * } |
| 70 | + * } |
| 71 | + * |
| 72 | + * pack() |
| 73 | + * centerOnScreen() |
| 74 | + * open() |
| 75 | + * } |
| 76 | + * }}} |
| 77 | + */ |
14 | 78 | package object swing {
|
15 | 79 | type Point = java.awt.Point
|
16 | 80 | type Dimension = java.awt.Dimension
|
|
0 commit comments