|
| 1 | +/* __ *\ |
| 2 | +** ________ ___ / / ___ Scala API ** |
| 3 | +** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL ** |
| 4 | +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** |
| 5 | +** /____/\___/_/ |_/____/_/ | | ** |
| 6 | +** |/ ** |
| 7 | +\* */ |
| 8 | + |
| 9 | +package scala.swing.uitest |
| 10 | + |
| 11 | + |
| 12 | +import scala.swing.FileChooser.Result |
| 13 | +import scala.swing.Swing._ |
| 14 | +import scala.swing.event.ButtonClicked |
| 15 | +import scala.swing._ |
| 16 | + |
| 17 | +/** |
| 18 | + * Test for issue SI-7597 https://issues.scala-lang.org/browse/SI-7597 |
| 19 | + */ |
| 20 | +object SI7597 extends SimpleSwingApplication { |
| 21 | + def top = new MainFrame { |
| 22 | + title = "SI7597 FileChooser test" |
| 23 | + |
| 24 | + |
| 25 | + lazy val dialog = aDialog |
| 26 | + |
| 27 | + val fileChooser = new FileChooser |
| 28 | + |
| 29 | + |
| 30 | + contents = new FlowPanel { |
| 31 | + contents ++= Seq( |
| 32 | + fileChooserStyles[Component]("Component", this), |
| 33 | + fileChooserStyles[Frame]("Frame", top), |
| 34 | + fileChooserStyles[Dialog]("Dialog", dialog) |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + size = new Dimension(400, 400) |
| 39 | + |
| 40 | + |
| 41 | + def fileChooserStyles[T <: PeerContainer](rowTitle: String, parent: => T) = new FlowPanel { |
| 42 | + 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")) |
| 47 | + ) |
| 48 | + } |
| 49 | + |
| 50 | + def fileChooserButton(parentTitle: String, fileChooserStyle: => Result.Value): Button = new Button { |
| 51 | + text = parentTitle |
| 52 | + reactions += { |
| 53 | + case ButtonClicked(_) => |
| 54 | + text = fileChooserStyle match { |
| 55 | + case Result.Approve => s"$parentTitle: ${fileChooser.selectedFile.toString}" |
| 56 | + case _ => parentTitle |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + def aDialog = new Dialog(top) { |
| 65 | + title = "A Dialog" |
| 66 | + size = new Dimension(300, 300) |
| 67 | + contents = new Label("Do not Close") |
| 68 | + visible = true |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments