001: package Schmortopf.Utility.gui;
002:
003: import javax.swing.*;
004: import java.awt.*;
005:
006: /** some static utilities
007: 1) can be shown modal or not ;
008: 2) thread secure (invokeandwait) can be called from any thread ;
009: 3) write his content in the console (=> outputFile), to help debugging.
010: */
011:
012: public class EFCNDialog {
013:
014: /** show a modal warning dialog
015: */
016: public static void showWarning(String message, Component parent) {
017: optionPane(message, "Warning", parent,
018: JOptionPane.WARNING_MESSAGE, null);
019: }
020:
021: /** show a modal information dialog attached to the parent
022: */
023: public static void showInformation(String message, Component parent) {
024: optionPane(message, "Information", parent,
025: JOptionPane.INFORMATION_MESSAGE, null);
026: }
027:
028: /** show a modal error dialog attached to the parent
029: */
030: public static void showError(String message, Component parent) {
031: optionPane(message, "Error", parent, JOptionPane.ERROR_MESSAGE,
032: null);
033: }
034:
035: /** show a modal question dialog attached to the parent
036: */
037: public static void showQuestion(String message, Component parent) {
038: optionPane(message, "Question", parent,
039: JOptionPane.QUESTION_MESSAGE, null);
040: }
041:
042: public static String showInputDialog(String message,
043: Component parent) {
044: return JOptionPane.showInputDialog(parent, message);
045: }
046:
047: public static int showOptionDialog(String message,
048: Component parent, Object[] options, int defaultOption) {
049: JSenseButton[] js = new JSenseButton[options.length];
050: for (int i = 0; i < options.length; i++) {
051: js[i] = new JSenseButton(options[i].toString(), true, null);
052: js[i]
053: .addActionListener(new java.awt.event.ActionListener() {
054: public void actionPerformed(
055: java.awt.event.ActionEvent e) {
056: return;
057: }
058: });
059: }
060:
061: return JOptionPane.showOptionDialog(parent, message,
062: "Option dialog", JOptionPane.DEFAULT_OPTION,
063: JOptionPane.QUESTION_MESSAGE, null, options,
064: options[defaultOption]);
065: }
066:
067: //
068: // private data and utilities
069: //
070:
071: /** All methods use this output method, which runs in all cases.
072: It must be modal and called with invoke and wait.
073: */
074: private static void optionPane(final String message,
075: final String title, final Component parent, final int type,
076: final ImageIcon im) {
077: if (SwingUtilities.isEventDispatchThread()) {
078: if (message.length() > 300) {
079: TextArea ta = new TextArea(message);
080: JScrollPane jsp = new JScrollPane(ta);
081: jsp.setPreferredSize(new Dimension(500, 220));
082: JOptionPane.showMessageDialog(parent, jsp, title, type,
083: im);
084: } else {
085: JOptionPane.showMessageDialog(parent, message, title,
086: type, im);
087: }
088: } else {
089: try {
090: SwingUtilities.invokeAndWait(new Runnable() {
091: public void run() {
092: if (message.length() > 300) {
093: TextArea ta = new TextArea(message);
094: JScrollPane jsp = new JScrollPane(ta);
095: jsp
096: .setPreferredSize(new Dimension(
097: 500, 220));
098: JOptionPane.showMessageDialog(parent, jsp,
099: title, type, im);
100: } else {
101: JOptionPane.showMessageDialog(parent,
102: message, title, type, im);
103: }
104: }
105: });
106: } catch (Exception e) {
107: }
108: }
109: }
110:
111: } // EFCNDialog
|