Skip to content

Commit af2ede6

Browse files
committed
allow showXXXDialogs to have a Dialog as a parent
1 parent f848b68 commit af2ede6

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

src/main/scala/scala/swing/ColorChooser.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
package scala.swing
1212

1313
import javax.swing.JColorChooser
14-
import event._
14+
import scala.swing.event._
15+
import scala.swing.Swing._
1516

1617
/**
1718
* Wrapper for JColorChooser. Publishes `ColorChanged` events, when the color selection changes.
@@ -21,7 +22,7 @@ import event._
2122
* @see javax.swing.JColorChooser
2223
*/
2324
object ColorChooser {
24-
def showDialog(parent: Component, title: String, color: Color): scala.Option[Color] = {
25+
def showDialog(parent: PeerContainer, title: String, color: scala.swing.Color): scala.Option[Color] = {
2526
toOption[Color](javax.swing.JColorChooser.showDialog(parent.peer, title, color))
2627
}
2728
}

src/main/scala/scala/swing/FileChooser.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,34 @@ object FileChooser {
4040
* @see [[javax.swing.JFileChooser]]
4141
*/
4242
class FileChooser(dir: File) {
43-
import FileChooser._
43+
import scala.swing.FileChooser._
4444
lazy val peer: JFileChooser = new JFileChooser(dir)
4545

4646
def this() = this(null)
4747

48-
import Swing._
48+
import scala.swing.Swing._
4949

5050
/**
5151
* Display a dialog box to select a file.
5252
* @param over Parent container - Component, Frame or Dialog
5353
* @return Status of how the dialog was closed.
5454
*/
55-
def showOpenDialog[T <: PeerContainer](over: T): Result.Value = Result(peer.showOpenDialog(nullPeer(over)))
55+
def showOpenDialog(over: PeerContainer): Result.Value = Result(peer.showOpenDialog(nullPeer(over)))
5656

5757
/**
5858
* Display a dialog box to select a file.
5959
* @param over Parent container - Component, Frame or Dialog
6060
* @return Parent container - Component, Frame or Dialog
6161
*/
62-
def showSaveDialog[T <: PeerContainer](over: T): Result.Value = Result(peer.showSaveDialog(nullPeer(over)))
62+
def showSaveDialog(over: PeerContainer): Result.Value = Result(peer.showSaveDialog(nullPeer(over)))
6363

6464
/**
6565
* Display a dialog box to select a file.
6666
* @param over Parent container - Component, Frame or Dialog
6767
* @param approveText text for the 'ok' button
6868
* @return Parent container - Component, Frame or Dialog
6969
*/
70-
def showDialog[T <: PeerContainer](over: T, approveText: String): Result.Value = Result(peer.showDialog(nullPeer(over), approveText))
70+
def showDialog(over: PeerContainer, approveText: String): Result.Value = Result(peer.showDialog(nullPeer(over), approveText))
7171

7272
def controlButtonsAreShown: Boolean = peer.getControlButtonsAreShown
7373
def controlButtonsAreShown_=(b: Boolean) { peer.setControlButtonsAreShown(b) }

src/main/scala/scala/swing/RichWindow.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ object Dialog {
126126

127127
private def uiString(txt: String) = UIManager.getString(txt)
128128

129-
def showConfirmation(parent: Component = null,
129+
def showConfirmation(parent: PeerContainer = null,
130130
message: Any,
131131
title: String = uiString("OptionPane.titleText"),
132132
optionType: Options.Value = Options.YesNo,
@@ -135,7 +135,7 @@ object Dialog {
135135
Result(JOptionPane.showConfirmDialog(nullPeer(parent), message, title,
136136
optionType.id, messageType.id, Swing.wrapIcon(icon)))
137137

138-
def showOptions(parent: Component = null,
138+
def showOptions(parent: PeerContainer = null,
139139
message: Any,
140140
title: String = uiString("OptionPane.titleText"),
141141
optionType: Options.Value = Options.YesNo,
@@ -149,7 +149,7 @@ object Dialog {
149149
Result(r)
150150
}
151151

152-
def showInput[A](parent: Component = null,
152+
def showInput[A](parent: PeerContainer = null,
153153
message: Any,
154154
title: String = uiString("OptionPane.inputDialogTitle"),
155155
messageType: Message.Value = Message.Question,
@@ -164,7 +164,7 @@ object Dialog {
164164

165165
toOption[A](r)
166166
}
167-
def showMessage(parent: Component = null,
167+
def showMessage(parent: PeerContainer = null,
168168
message: Any,
169169
title: String = uiString("OptionPane.messageDialogTitle"),
170170
messageType: Message.Value = Message.Info,

uitest/src/main/scala/scala/swing/uitest/SI7597.scala

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,65 @@
99
package scala.swing.uitest
1010

1111

12-
import scala.swing.FileChooser.Result
12+
1313
import scala.swing.Swing._
1414
import scala.swing.event.ButtonClicked
1515
import scala.swing._
1616

17+
1718
/**
1819
* Test for issue SI-7597 https://issues.scala-lang.org/browse/SI-7597
20+
* (expanded to include other showXXXDialog dialogs )
1921
*/
2022
object SI7597 extends SimpleSwingApplication {
2123
def top = new MainFrame {
22-
title = "SI7597 FileChooser test"
23-
24+
title = "SI7597 showXXXDialog tests"
25+
size = new Dimension(900, 200)
2426

2527
lazy val dialog = aDialog
2628

27-
val fileChooser = new FileChooser
28-
29+
val fileChooserDialog = new FileChooser
30+
val colorChooser = new ColorChooser
2931

30-
contents = new FlowPanel {
32+
contents = new BoxPanel(Orientation.Vertical) {
3133
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)
3537
)
3638
}
3739

38-
size = new Dimension(400, 400)
40+
def fileChooserStyles(rowTitle : String, parent : => PeerContainer) = new FlowPanel {
41+
contents ++= Seq(new Label(s"Parent is $rowTitle"))
3942

40-
41-
def fileChooserStyles[T <: PeerContainer](rowTitle: String, parent: => T) = new FlowPanel {
4243
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))
4752
)
4853
}
4954

50-
def fileChooserButton(parentTitle: String, fileChooserStyle: => Result.Value): Button = new Button {
55+
def simpleButton(parentTitle : String, dialogChooser : => Any): Button = new Button {
5156
text = parentTitle
5257
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")
5761
}
5862
}
5963
}
60-
6164
}
6265

6366

64-
def aDialog = new Dialog(top) {
67+
def aDialog:Dialog = new Dialog(top) {
6568
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")
6871
visible = true
6972
}
70-
7173
}

0 commit comments

Comments
 (0)