/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.component;
import java.awt.Dialog;
import java.awt.Frame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
/**
* Contains a collection of dialogs that could be used to standardize messages
* of different types throughout an application. All messages are invoked within
* the event dispatching thread.
*
* If the parent is not explicitely specified,
* TopFrameReference.getTopFrameRef() is used.
*
* @author Markus Kraetzig
*/
public final class StdMessages {
private static final Logger log = Logger.getLogger(StdMessages.class);
/**
* Not to be invoked.
*/
private StdMessages() {
super();
}
/**
* User notification with msg that should be used for
* arbitrary error messages with title.
*
* @param msg
* string for user information
* @param title
* displayed in header
*/
public static void error(final String msg, final String title) {
error(msg, title, TopFrameReference.getTopFrameRef());
}
/**
* User notification with msg that should be used for
* arbitrary error messages with title.
*
* @param msg
* string for user information
* @param title
* displayed in header
* @param parent
* the parent frame
*/
public static void error(final String msg, final String title,
final Frame parent) {
if (SwingUtilities.isEventDispatchThread())
JOptionPane.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
else
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JOptionPane.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE);
}
});
} catch (Throwable ex) {
log.error("Error waiting for SwingUtilities.invokeAndWait", ex);
}
}
/**
* User notification with msg that should be used for
* arbitrary error messages with title.
*
* @param msg
* string for user information
* @param title
* displayed in header
* @param parent
* the parent dialog
*/
public static void error(final String msg, final String title,
final Dialog parent) {
if (SwingUtilities.isEventDispatchThread())
JOptionPane.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
else
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JOptionPane.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE);
}
});
} catch (Throwable ex) {
log.error("Error waiting for SwingUtilities.invokeAndWait", ex);
}
}
/**
* User notification with msg that should be used if some
* error with a computational engine occured. This is displayed as an error
* message.
*
* @param msg
* string that should inform the user about the cause of error
*/
public static void errorEngine(String msg) {
error(msg, "Engine Error");
}
/**
* User notification with msg that should be used if some
* error with a computational engine occured. This is displayed as an error
* message.
*
* @param msg
* string that should inform the user about the cause of error
* @param parent
* the parent frame
*/
public static void errorEngine(String msg, Frame parent) {
error(msg, "Engine Error", parent);
}
/**
* User notification with msg that should be used if some
* error with a computational engine occured. This is displayed as an error
* message.
*
* @param msg
* string that should inform the user about the cause of error
* @param parent
* the parent dialog
*/
public static void errorEngine(String msg, Dialog parent) {
error(msg, "Engine Error", parent);
}
/**
* User notification with msg that should be used if the user
* has provided wrong input. This is displayed as an error message.
*
* @param msg
* string that should guide the user to change the wrong input
*/
public static void errorInput(String msg) {
error(msg, "Input Error");
}
/**
* User notification with msg that should be used if the user
* has provided wrong input. This is displayed as an error message.
*
* @param msg
* string that should guide the user to change the wrong input
* @param parent
* the parent frame
*/
public static void errorInput(String msg, Frame parent) {
error(msg, "Input Error", parent);
}
/**
* User notification with msg that should be used if the user
* has provided wrong input. This is displayed as an error message.
*
* @param msg
* string that should guide the user to change the wrong input
* @param parent
* the parent dialof
*/
public static void errorInput(String msg, Dialog parent) {
error(msg, "Input Error", parent);
}
/**
* User notification with msg that should be used if the user
* has provided an inconsistent specification. This is displayed as an error
* message.
*
* @param msg
* string that should guide the user to change the wrong spec
*/
public static void errorSpecification(String msg) {
error(msg, "Specification Error");
}
/**
* User notification with msg that should be used if the user
* has provided an inconsistent specification. This is displayed as an error
* message.
*
* @param msg
* string that should guide the user to change the wrong spec
* @param parent
* the parent frame
*/
public static void errorSpecification(String msg, Frame parent) {
error(msg, "Specification Error", parent);
}
/**
* User notification with msg that should be used if the user
* has provided an inconsistent specification. This is displayed as an error
* message.
*
* @param msg
* string that should guide the user to change the wrong spec
* @param parent
* the parent dialog
*/
public static void errorSpecification(String msg, Dialog parent) {
error(msg, "Specification Error", parent);
}
/**
* User notification with msg that should be used for
* arbitrary messages with title.
*
* @param msg
* string for user information
* @param title
* to be displayed in header
*/
public static void info(final String msg, final String title) {
info(msg, title, TopFrameReference.getTopFrameRef());
}
/**
* User notification with msg that should be used for
* arbitrary messages with title.
*
* @param msg
* string for user information
* @param title
* to be displayed in header
* @param parent
* the parent frame
*/
public static void info(final String msg, final String title,
final Frame parent) {
if (SwingUtilities.isEventDispatchThread())
JOptionPane
.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE);
else
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JOptionPane.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE);
}
});
} catch (Throwable ex) {
log.error("Error waiting for SwingUtilities.invokeAndWait", ex);
}
}
/**
* User notification with msg that should be used for
* arbitrary messages with title.
*
* @param msg
* string for user information
* @param title
* to be displayed in header
* @param parent
* the parent dialog
*/
public static void info(final String msg, final String title,
final Dialog parent) {
if (SwingUtilities.isEventDispatchThread())
JOptionPane
.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE);
else
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JOptionPane.showConfirmDialog(parent, msg, title,
JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE);
}
});
} catch (Throwable ex) {
log.error("Error waiting for SwingUtilities.invokeAndWait", ex);
}
}
/**
* User notification with msg that should be used for general
* purpose information messages.
*
* @param msg
* string for user information
*/
public static void infoGeneral(String msg) {
info(msg, "Information");
}
/**
* User notification with msg that should be used for general
* purpose information messages.
*
* @param msg
* string for user information
* @param parent
* the parent frame
*/
public static void infoGeneral(String msg, Frame parent) {
info(msg, "Information", parent);
}
/**
* User notification with msg that should be used for general
* purpose information messages.
*
* @param msg
* string for user information
* @param parent
* the parent dialog
*/
public static void infoGeneral(String msg, Dialog parent) {
info(msg, "Information", parent);
}
/**
* User notification with msg that should be used if no
* variable was selected for a computation. This is displayed as an
* information message rather than an error.
*
* @param msg
* string that should guide the user to make a selection
*/
public static void infoNothingSelected(String msg) {
info(msg, "Nothing Selected");
}
/**
* User notification with msg that should be used if no
* variable was selected for a computation. This is displayed as an
* information message rather than an error.
*
* @param msg
* string that should guide the user to make a selection
* @param parent
* the parent frame
*/
public static void infoNothingSelected(String msg, Frame parent) {
info(msg, "Nothing Selected", parent);
}
/**
* User notification with msg that should be used if no
* variable was selected for a computation. This is displayed as an
* information message rather than an error.
*
* @param msg
* string that should guide the user to make a selection
* @param parent
* the parent dialog
*/
public static void infoNothingSelected(String msg, Dialog parent) {
info(msg, "Nothing Selected", parent);
}
}
Ads help maintain this website.