-
Notifications
You must be signed in to change notification settings - Fork 9
Dialogues
One of the most basic means of (or tool to use when) creating a GUI is that of dialogue boxes. These are pop-up windows that offer a "one-shot" means of interacting with the user. The GUI
class within JISA
provides several methods for easy dialogues.
The most basic dialogues are those that simply deliver a message to the user for them to acknowledge (by pressing "OK"). These are called "Alerts" and come in three varieties:
- Information
- Warning
- Error
Each time you want to display one of these you need to provide 3 pieces of information:
- Title Text - The text to show in the title-bar of the window
- Header Text - The text to show at the top of the window content
- Message Text - The message to show in the window
To make a dialogue appear, use one of the following:
// Information
GUI.infoAlert("Title Text", "Header Text", "Message Text");
// Warning
GUI.warningAlert("Title Text", "Header Text", "Message Text");
// Error
GUI.errorAlert("Title Text", "Header Text", "Message Text");
These methods will not return until "OK" has been pressed, meaning that your code will halt at the line where you call one of these dialogues until the user has acknowledged the message.
If needed, you can change the width of the dialogue by adding your custom width as a fourth argument:
// Info dialogue that is 500 pixels wide
GUI.infoAlert("Title", "Header", "Message", 500);
(this applies for all three types).
The next type of dialogue is the one that gives the user a yes/no or ok/cancel choice. This is called a confirmation window and is called much like the alerts, except that this time it will return a boolean
indicating the user's choice:
boolean choice = GUI.confirmWindow("Title", "Header", "Message");
which will result in:
Again, this will not return until the user has pressed either "OK" or "Cancel". Pressing "OK" will return true
and pressing "Cancel" will return false
. For example, you could use this to confirm exiting the program:
boolean result = GUI.confirmWindow(
"Confirm Quit",
"Quit?",
"Do you really want to quit?"
);
if (result) {
System.out.println("Goodbye!");
System.exit(0);
} else {
System.out.println("Quit aborted.");
}
You can offer the user a choice between several options by use of the choice window:
int choice = GUI.choiceWindow(
"Title",
"Header",
"Message",
"Choice 0",
"Choice 1",
etc...
);
This will create a dialogue with buttons to represent each option. Clicking a button will close the dialogue and return an integer representing the button that was pressed (starting at 0
for the first button).
For example:
int choice = GUI.choiceWindow(
"Choice",
"Select an option",
"What do you want to do?",
"Sweep Voltage",
"Sweep Current",
"Quit"
);
switch (choice) {
case 0:
// Code to sweep voltage
break;
case 1:
// Code to sweep current
break;
case 2:
System.exit(0);
}
This results in:
You can create dialogues that ask for the user to type in some input. This is done by opening an "Input Window" like so:
String[] responses = GUI.inputWindow(
"Title",
"Header",
"Message",
"Field 1",
"Field 2",
etc...
);
Like with GUI.choiceWindow
you specify the fields you want the user to be presented with by adding their names after the first three normal arguments. When submitted, all the user-input are returned as an array of strings (in the order the fields were specified). For example:
String[] responses = GUI.inputWindow(
"Info",
"Info Needed",
"Please fill in the following info...",
"Name",
"Age",
"Height",
"Eye Colour"
);
which will result in:
when pressing "OK" after entering the displayed information, the array returned into resonses
will look like:
Index | Code | Value |
---|---|---|
0 | responses[0] |
Bob Smith |
1 | responses[1] |
28 |
2 | responses[2] |
175 cm |
3 | responses[3] |
Green |
If the user pressed "Cancel" instead, then the method will return null
into responses
instead of an array.
Often you will want to ask the user to select a file path. Either for writing data to, or reading data from. One way of doing this is by using the file-save and file-open dialogue calls like so:
// To open a "select file to open" dialogue
String openPath = GUI.openFileSelect();
// To open a "select path to save to" dialogue
String savePath = GUI.saveFileSelect();
Each will return the selected path as a string.
On a Linux system, this will result in the following for openFileSelect()
:
and for saveFileSelect()
:
You can also open a dialogue that lists all detected instruments connected to the system. Despite the name, it doesn't only use VISA
but scans for devices on any of the available protocols and drivers used by JISA
. To open this use:
Address selected = GUI.browseVISA();
When the user selects an instrument from the list, it will return its address as an Address
object. If the user presses "Cancel", it will return null
.
For example:
GUI.infoAlert(
"Select Instrument",
"Select Instrument",
"Please select the Keithley 2450"
);
Address selected = GUI.browseVISA();
// Check if it returned null (ie user pressed cancel)
if (selected == null) {
System.out.println("User pressed cancel, terminating.");
System.exit(0);
} else {
System.out.printf("User selected %s\n", selected.toString());
// Connect to instrument using selected address
SMU smu = new K2450(selected);
}
- Getting Started
- Object Orientation
- Choosing a Language
- Using JISA in Java
- Using JISA in Python
- Using JISA in Kotlin
- Exceptions
- Functions as Objects
- Instrument Basics
- SMUs
- Thermometers (and old TCs)
- PID and Temperature Controllers
- Lock-Ins
- Power Supplies
- Pre-Amplifiers
- Writing New Drivers