|
9 | 9 | package scala.swing.uitest |
10 | 10 |
|
11 | 11 |
|
12 | | -import scala.swing.FileChooser.Result |
| 12 | + |
13 | 13 | import scala.swing.Swing._ |
14 | 14 | import scala.swing.event.ButtonClicked |
15 | 15 | import scala.swing._ |
16 | 16 |
|
| 17 | + |
17 | 18 | /** |
18 | 19 | * Test for issue SI-7597 https://issues.scala-lang.org/browse/SI-7597 |
| 20 | + * (expanded to include other showXXXDialog dialogs ) |
19 | 21 | */ |
20 | 22 | object SI7597 extends SimpleSwingApplication { |
21 | 23 | def top = new MainFrame { |
22 | | - title = "SI7597 FileChooser test" |
23 | | - |
| 24 | + title = "SI7597 showXXXDialog tests" |
| 25 | + size = new Dimension(900, 200) |
24 | 26 |
|
25 | 27 | lazy val dialog = aDialog |
26 | 28 |
|
27 | | - val fileChooser = new FileChooser |
28 | | - |
| 29 | + val fileChooserDialog = new FileChooser |
| 30 | + val colorChooser = new ColorChooser |
29 | 31 |
|
30 | | - contents = new FlowPanel { |
| 32 | + contents = new BoxPanel(Orientation.Vertical) { |
31 | 33 | contents ++= Seq( |
32 | | - fileChooserStyles[Component]("Component", this), |
33 | | - fileChooserStyles[Frame]("Frame", top), |
34 | | - fileChooserStyles[Dialog]("Dialog", dialog) |
| 34 | + fileChooserStyles("Component", parent = this), |
| 35 | + fileChooserStyles("Frame", parent = top), |
| 36 | + fileChooserStyles("Dialog", parent = dialog) |
35 | 37 | ) |
36 | 38 | } |
37 | 39 |
|
38 | | - size = new Dimension(400, 400) |
| 40 | + def fileChooserStyles(rowTitle : String, parent : => PeerContainer) = new FlowPanel { |
| 41 | + contents ++= Seq(new Label(s"Parent is $rowTitle")) |
39 | 42 |
|
40 | | - |
41 | | - def fileChooserStyles[T <: PeerContainer](rowTitle: String, parent: => T) = new FlowPanel { |
42 | 43 | contents ++= Seq( |
43 | | - new Label(s"Parent is $rowTitle"), |
44 | | - fileChooserButton("Open", fileChooser.showOpenDialog(parent)), |
45 | | - fileChooserButton("Save", fileChooser.showSaveDialog(parent)), |
46 | | - fileChooserButton("Text", fileChooser.showDialog(parent, "Text")) |
| 44 | + simpleButton("Open", fileChooserDialog.showOpenDialog(parent)), |
| 45 | + simpleButton("Save", fileChooserDialog.showSaveDialog(parent)), |
| 46 | + simpleButton("Text", fileChooserDialog.showDialog(parent, "Text")), |
| 47 | + simpleButton("Confirmation", Dialog.showConfirmation(parent, "Confirmation") ), |
| 48 | + simpleButton("Input", Dialog.showInput(parent, "Input", initial = "Some text") ), |
| 49 | + simpleButton("Message", Dialog.showMessage(parent, "Message" )), |
| 50 | + simpleButton("Message", Dialog.showOptions(parent, "Message", entries = List("First", "Second", "Third"), initial=1 )), |
| 51 | + simpleButton("Color", ColorChooser.showDialog(parent, "Color", java.awt.Color.RED)) |
47 | 52 | ) |
48 | 53 | } |
49 | 54 |
|
50 | | - def fileChooserButton(parentTitle: String, fileChooserStyle: => Result.Value): Button = new Button { |
| 55 | + def simpleButton(parentTitle : String, dialogChooser : => Any): Button = new Button { |
51 | 56 | text = parentTitle |
52 | 57 | reactions += { |
53 | | - case ButtonClicked(_) => |
54 | | - text = fileChooserStyle match { |
55 | | - case Result.Approve => s"$parentTitle: ${fileChooser.selectedFile.toString}" |
56 | | - case _ => parentTitle |
| 58 | + case _ : ButtonClicked => |
| 59 | + dialogChooser match { |
| 60 | + case action => println(s"Result: $action") |
57 | 61 | } |
58 | 62 | } |
59 | 63 | } |
60 | | - |
61 | 64 | } |
62 | 65 |
|
63 | 66 |
|
64 | | - def aDialog = new Dialog(top) { |
| 67 | + def aDialog:Dialog = new Dialog(top) { |
65 | 68 | title = "A Dialog" |
66 | | - size = new Dimension(300, 300) |
67 | | - contents = new Label("Do not Close") |
| 69 | + size = new Dimension(300, 600) |
| 70 | + contents = new Label("Test Dialog. Do Not Close") |
68 | 71 | visible = true |
69 | 72 | } |
70 | | - |
71 | 73 | } |
0 commit comments