Dialog

object Dialog

This object provides convenience methods for displaying messages and reading user input via simple Swing dialogs.

class Object
trait Matchable
class Any
Dialog.type

Type members

Classlikes

case object Centered extends Position

A positioning policy that centers the dialog onscreen. An alternative to RelativeTo.

A positioning policy that centers the dialog onscreen. An alternative to RelativeTo.

sealed trait Position

The positioning policy of an input dialog. Used with the methods on Dialog.

The positioning policy of an input dialog. Used with the methods on Dialog.

See also:
final case class RelativeTo(locator: Component) extends Position

A positioning policy that places the dialog near another Swing component. An alternative to Centered.

A positioning policy that places the dialog near another Swing component. An alternative to Centered.

Value parameters:
locator

the Swing component in front of which the dialog should appear

Companion:
object
case object RelativeTo

A companion object with factory methods.

A companion object with factory methods.

Companion:
class

Value members

Concrete methods

def display(message: String, position: Position): Unit

Displays a textual message in a Swing dialog.

Displays a textual message in a Swing dialog.

Value parameters:
message

a message to the end user

position

the location of the dialog onscreen

def requestAnyDouble(prompt: String, position: Position): Option[Double]

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a Double or the user cancels.

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a Double or the user cancels.

Value parameters:
position

the location of the dialog(s) onscreen

prompt

a message that prompts the user for input

Returns:

the user input, converted from the textual input with toDouble; None if the user cancelled

def requestAnyInt(prompt: String, errorMessage: String, position: Position): Option[Int]

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a Double or the user cancels.

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives text interpretable as a Double or the user cancels.

Value parameters:
errorMessage

a prefix added to prompt on each request except the first

position

the location of the dialog(s) onscreen

prompt

a message that prompts the user for input

Returns:

the user input, converted from the textual input with toInt; None if the user cancelled

def requestAnyLine(prompt: String, position: Position): Option[String]

Asks the user to input a line of text via a Swing dialog; accepts any string as input.

Asks the user to input a line of text via a Swing dialog; accepts any string as input.

Value parameters:
position

the location of the dialog onscreen

prompt

a message that prompts the user for input

Returns:

the string entered by the user; None if they cancelled

def requestChoice[Choice](prompt: String, options: Seq[Choice], position: Position): Option[Choice]

Asks the user to choose among the given options via a Swing dialog.

Asks the user to choose among the given options via a Swing dialog.

Value parameters:
options

any objects that the user will choose one of; their toStrings will show in the input dialog

position

the location of the dialog onscreen

prompt

a message that prompts the user for input

Returns:

one of the options as chosen by the user; None if the user cancelled

def requestDouble(prompt: String, isOK: Double => Boolean, errorMessage: String, position: Position): Option[Double]

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(inputString.toDouble) returns false or fails with an exception.

Asks the user to input a decimal number by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(inputString.toDouble) returns false or fails with an exception.

Value parameters:
errorMessage

a prefix added to prompt on each request except the first

isOK

a function applied to any actual Double input to check if it’s valid

position

the location of the dialog(s) onscreen

prompt

a message that prompts the user for input

Returns:

the user input, converted from the textual input with toDouble; None if the user cancelled

def requestInput[Input](prompt: String, convert: String => Input, isOK: Input => Boolean, errorMessage: String, position: Position): Option[Input]

Asks the user to input a line of text via a Swing dialog and interprets the input with the given functions. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(convert(input)) returns false or fails with an exception.

Asks the user to input a line of text via a Swing dialog and interprets the input with the given functions. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(convert(input)) returns false or fails with an exception.

Type parameters:
Input

the type of the user input (converted from a string to this type)

Value parameters:
convert

a function applied to the input string to produce the actual return value

errorMessage

a prefix added to prompt on each request except the first

isOK

a function applied to the input string to check if it’s valid

position

the location of the dialog(s) onscreen

prompt

a message that prompts the user for input

Returns:

a valid user input (converted from a string); None if the user cancelled

def requestInt(prompt: String, isOK: Int => Boolean, errorMessage: String, position: Position): Option[Int]

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(inputString.toInt) returns false or fails with an exception.

Asks the user to input an integer by typing it in a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(inputString.toInt) returns false or fails with an exception.

Value parameters:
errorMessage

a prefix added to prompt on each request except the first

isOK

a function applied to any actual integer input to check if it’s valid

position

the location of the dialog(s) onscreen

prompt

a message that prompts the user for input

Returns:

the user input, converted from the textual input with toInt; None if the user cancelled

def requestNonEmptyLine(prompt: String, errorMessage: String, position: Position): Option[String]

Asks the user to input a non-empty line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a non-empty string as input or the user cancels.

Asks the user to input a non-empty line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a non-empty string as input or the user cancels.

Value parameters:
errorMessage

a prefix added to prompt on each request except the first

position

the location of the dialog(s) onscreen

prompt

a message that prompts the user for input

Returns:

the user input, a non-empty string; None if the user cancelled

def requestString(prompt: String, isOK: String => Boolean, errorMessage: String, position: Position): Option[String]

Asks the user to input a line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(input.trim) returns false or fails with an exception.

Asks the user to input a line of text via a Swing dialog. Keeps prompting the user with new dialogs until it receives a valid input or the user cancels. An input is invalid if isOK(input.trim) returns false or fails with an exception.

Value parameters:
errorMessage

a prefix added to prompt on each request except the first

isOK

a function applied to the input string to check if it’s valid

position

the location of the dialog(s) onscreen

prompt

a message that prompts the user for input

Returns:

a valid user input, trimmed for whitespce; None if the user cancelled