11package dartzee
22
3+ import com.github.alyssaburlton.swingtest.clickCancel
34import com.github.alyssaburlton.swingtest.clickChild
45import com.github.alyssaburlton.swingtest.clickOk
56import com.github.alyssaburlton.swingtest.clickYes
@@ -68,6 +69,7 @@ import javax.swing.JTextField
6869import javax.swing.SwingUtilities
6970import javax.swing.table.DefaultTableModel
7071import javax.swing.text.JTextComponent
72+ import kotlin.jvm.javaClass
7173
7274val bullseye = DartboardSegment (SegmentType .DOUBLE , 25 )
7375val outerBull = DartboardSegment (SegmentType .OUTER_SINGLE , 25 )
@@ -213,13 +215,20 @@ fun GameplayDartboard.throwDartByClick(
213215
214216fun GameplayDartboard.segmentStatuses () = getChild<PresentationDartboard >().segmentStatuses
215217
216- fun getFileChooser () = getWindow<JDialog > { it.title == " Open " }
218+ fun getFileChooser (title : String ) = getWindow<JDialog > { it.title == title }
217219
218220fun <T > List<T>.only (): T {
219221 size shouldBe 1
220222 return first()
221223}
222224
225+ fun selectFile (path : String , title : String ) {
226+ val chooserDialog = getFileChooser(title)
227+ chooserDialog.getChild<JTextComponent >().typeText(path)
228+ chooserDialog.clickChild<JButton >(text = title)
229+ flushEdt()
230+ }
231+
223232fun PlayerImageDialog.selectImage (playerImageId : String ) {
224233 getChild<JTabbedPane >().selectTab<JPanel >(" uploadTab" )
225234
@@ -232,11 +241,8 @@ fun PlayerImageDialog.selectImage(playerImageId: String) {
232241fun FileUploader.uploadFileFromResource (resourceName : String ) {
233242 clickChild<JButton >(text = " ..." , async = true )
234243
235- val chooserDialog = getFileChooser()
236244 val rsrcPath = javaClass.getResource(resourceName)!! .path
237- chooserDialog.getChild<JTextComponent >().typeText(rsrcPath)
238- chooserDialog.clickChild<JButton >(text = " Open" )
239- flushEdt()
245+ selectFile(rsrcPath, " Open" )
240246
241247 getChild<JTextField >().text shouldBe File (rsrcPath).path
242248 clickChild<JButton >(text = " Upload" , async = true )
@@ -271,20 +277,40 @@ fun findLoadingDialog(text: String) = findWindow<LoadingDialog> { it.message ==
271277
272278private fun getInfoDialog () = findInfoDialog()!!
273279
274- private fun findInfoDialog () = findOptionPaneDialog(" Information" )
280+ fun findInfoDialog (predicate : (window: JDialog ) -> Boolean = { true }) =
281+ findOptionPaneDialog(" Information" , predicate)
275282
276- fun getQuestionDialog () = findQuestionDialog() !!
283+ fun getQuestionDialog () = getOptionPaneDialog( " Question " )
277284
278285fun findQuestionDialog () = findOptionPaneDialog(" Question" )
279286
280287fun getErrorDialog (predicate : (window: JDialog ) -> Boolean = { true }) =
281- findErrorDialog( predicate)!!
288+ getOptionPaneDialog( " Error " , predicate)
282289
283290fun findErrorDialog (predicate : (window: JDialog ) -> Boolean = { true }) =
284291 findOptionPaneDialog(" Error" , predicate)
285292
286293fun waitForQuestionDialog (): JDialog = waitForWindow<JDialog > { it.title == " Question" }
287294
295+ fun selectFromOptionDialog (title : String , selection : String ) {
296+ val dialog = getOptionPaneDialog(title) { it.isVisible }
297+ dialog.clickButton(text = selection, async = true )
298+ }
299+
300+ fun cancelOptionDialog (title : String ) {
301+ val dialog = getOptionPaneDialog(title) { it.isVisible }
302+ dialog.clickCancel(async = true )
303+ }
304+
305+ fun dismissOptionDialog (title : String ) {
306+ val dialog = getOptionPaneDialog(title) { it.isVisible }
307+ dialog.dispose()
308+ flushEdt()
309+ }
310+
311+ private fun getOptionPaneDialog (title : String , predicate : (window: JDialog ) -> Boolean = { true }) =
312+ getWindow<JDialog > { it.title == title && predicate(it) }
313+
288314private fun findOptionPaneDialog (
289315 title : String ,
290316 predicate : (window: JDialog ) -> Boolean = { true },
0 commit comments