package cologne.eck.all_peas.gui;
/**
* Show messages and questions with JOptionPanes
*/
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JOptionPane;
public class PeaDialog {
private static Icon icon = null;//new ImageIcon(PswDialogView.getImage());
//private static Icon icon = new ImageIcon(MainView.getImage());
// ===== message dialog =====
/**
* Show a message.
*
* @param ownerComponent the Object will be casted to java.awtComponent
* @param message the message, lines separated by \n
* @param title the title of the message
* @param messageType possible values are:
* ERROR_MESSAGE 0
* INFORMATION_MESSAGE 1
* WARNING_MESSAGE 2
* QUESTION_MESSAGE 3
* PLAIN_MESSAGE -1
*/
public static void showMessage(Object ownerComponent,
Object message, String title, int messageType){
Component owner = null;
try {
owner = (Component) ownerComponent;
} catch (NullPointerException npe) {
System.err.println("Missing PeaMessage owner");
} catch (ClassCastException cce) {
System.err.println("Invalid PeaMessage owner");
}
JOptionPane.showMessageDialog(owner, message, title, messageType, icon);
}
/**
* Show a plain type message without title.
*
* @param ownerComponent the Object will be casted to java.awtComponent
* @param message the message, lines separated by \n
*/
public static void showMessage(Object ownerComponent,
Object message){
Component owner = null;
try {
owner = (Component) ownerComponent;
} catch (NullPointerException npe) {
System.err.println("Missing PeaMessage owner");
} catch (ClassCastException cce) {
System.err.println("Invalid PeaMessage owner");
}
JOptionPane.showMessageDialog(owner, message, null, -1, icon);
}
// ===== confirm dialog =====
/**
* Show a question dialog.
*
* @param ownerComponent the Object will be casted to java.awtComponent
* @param message the message, lines separated by \n
* @param title the title of the message
* @param optionType possible values are:
* DEFAULT_OPTION -1
* YES_NO_OPTION 0
* YES_NO_CANCEL_OPTION 1
* OK_CANCEL_OPTION 2
* @param messageType possible values are:
* ERROR_MESSAGE 0
* INFORMATION_MESSAGE 1
* WARNING_MESSAGE 2
* QUESTION_MESSAGE 3
* PLAIN_MESSAGE -1
*
* @result YES_OPTION 0
NO_OPTION 1
CANCEL_OPTION 2
OK_OPTION 0
CLOSED_OPTION -1
*/
public static int showQuestion(Object ownerComponent, Object message, String title, int optionType, int messageType){
Component owner = null;
try {
owner = (Component) ownerComponent;
} catch (NullPointerException npe) {
System.err.println("Missing PeaMessage owner");
} catch (ClassCastException cce) {
System.err.println("Invalid PeaMessage owner");
}
return JOptionPane.showConfirmDialog(owner, message, title, optionType, messageType, icon);
}
/**
* Show a plain type question dialog with default options
* and without title.
*
* @param ownerComponent the Object will be casted to java.awtComponent
* @param message the message, lines separated by \n
*
*
* @result YES_OPTION 0
NO_OPTION 1
CANCEL_OPTION 2
OK_OPTION 0
CLOSED_OPTION -1
*/
public static int showQuestion(Object ownerComponent, Object message){
Component owner = null;
try {
owner = (Component) ownerComponent;
} catch (NullPointerException npe) {
System.err.println("Missing PeaMessage owner");
} catch (ClassCastException cce) {
System.err.println("Invalid PeaMessage owner");
}
return JOptionPane.showConfirmDialog(owner, message, null, -1, -1, icon);
}
/**
* Show a plain type question dialog.
*
* @param ownerComponent the Object will be casted to java.awtComponent
* @param message the message, lines separated by \n
* @param title the title of the message
* @param optionType possible values are:
* DEFAULT_OPTION -1
* YES_NO_OPTION 0
* YES_NO_CANCEL_OPTION 1
* OK_CANCEL_OPTION 2
*
*
* @result YES_OPTION 0
NO_OPTION 1
CANCEL_OPTION 2
OK_OPTION 0
CLOSED_OPTION -1
*/
public static int showQuestion(Object ownerComponent, Object message, String title, int optionType){
Component owner = null;
try {
owner = (Component) ownerComponent;
} catch (NullPointerException npe) {
System.err.println("Missing PeaMessage owner");
} catch (ClassCastException cce) {
System.err.println("Invalid PeaMessage owner");
}
return JOptionPane.showConfirmDialog(owner, message, title, optionType, -1, icon);
}
// ===== option dialog =====
/**
* Show an option dialog.
*
*
* @param ownerComponent the Object will be casted to java.awtComponent
* @param message the message, lines separated by \n
* @param title the title of the message
* @param optionType possible values are:
* DEFAULT_OPTION -1
* YES_NO_OPTION 0
* YES_NO_CANCEL_OPTION 1
* OK_CANCEL_OPTION 2
* @param messageType possible values are:
* ERROR_MESSAGE 0
* INFORMATION_MESSAGE 1
* WARNING_MESSAGE 2
* QUESTION_MESSAGE 3
* PLAIN_MESSAGE -1
* @param options options, at least two
* @param initialValue initial value of options,
* one Object of the options array e.g.options[0]
*
*
* @result YES_OPTION 0
NO_OPTION 1
CANCEL_OPTION 2
OK_OPTION 0
CLOSED_OPTION -1
*/
public static int showOptions(Object ownerComponent, Object message, String title, int optionType, int messageType, Object[] options, Object initialValue){
Component owner = null;
try {
owner = (Component) ownerComponent;
} catch (NullPointerException npe) {
System.err.println("Missing PeaMessage owner");
} catch (ClassCastException cce) {
System.err.println("Invalid PeaMessage owner");
}
return JOptionPane.showOptionDialog(owner, message, title, optionType, messageType, icon, options, initialValue);
}
/**
* Show an input dialog.
*
*
* @param ownerComponent the Object will be casted to java.awtComponent
* @param message the message, lines separated by \n
* @param title the title of the message
* @param messageType possible values are:
* ERROR_MESSAGE 0
* INFORMATION_MESSAGE 1
* WARNING_MESSAGE 2
* QUESTION_MESSAGE 3
* PLAIN_MESSAGE -1
*
* @result input as String
*/
public static String showInputDialog(Object ownerComponent, Object message, String title, int messageType) {
Component owner = null;
try {
owner = (Component) ownerComponent;
} catch (NullPointerException npe) {
System.err.println("Missing PeaMessage owner");
} catch (ClassCastException cce) {
System.err.println("Invalid PeaMessage owner");
}
return (String) JOptionPane.showInputDialog(owner, message, title, messageType, icon, null, null);
}
}