001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * MessageBox.java
028: *
029: * Created on 11 febbraio 2003, 16.07
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import javax.swing.*;
036:
037: /**
038: *
039: * @author Administrator
040: */
041: public class MessageBox {
042:
043: // Buttons
044: /** Indicates that the message box should display an OK button */
045: public static final int OK = 1;
046: /** Indicates that the message box should display OK and Cancel buttons */
047: public static final int OKCANCEL = 2;
048: /** Indicates that the message box should display Yes and No buttons */
049: public static final int YESNO = 4;
050: /** Indicates that the message box should display Yes, No, and Cancel buttons */
051: public static final int YESNOCANCEL = 8;
052:
053: // ICONS
054: /** Indicates that the message box should display an error icon */
055: public static final int ICONERROR = 16;
056: /** Indicates that the message box should display an exclamation (!) icon */
057: public static final int ICONINFORMATION = 32;
058: /** Indicates that the message box should display a question mark (?) icon */
059: public static final int ICONQUESTION = 64;
060: /** Indicates that the message box should display a warning icon */
061: public static final int ICONWARNING = 128;
062:
063: /** Creates a new instance of MessageBox */
064: public MessageBox() {
065: }
066:
067: public static int show(String msg, String title, int flags) {
068: return MessageBox.show(null, msg, title, flags);
069: }
070:
071: public static int show(String msg) {
072: return MessageBox.show(null, msg, "", MessageBox.OK);
073: }
074:
075: public static int show(JComponent parent, String msg) {
076: return MessageBox.show(parent, msg, "", MessageBox.OK);
077: }
078:
079: public static int show(JComponent parent, String msg, String title,
080: int flags) {
081:
082: int messageType = JOptionPane.PLAIN_MESSAGE;
083: if ((flags & MessageBox.ICONERROR) != 0)
084: messageType = JOptionPane.ERROR_MESSAGE;
085: else if ((flags & MessageBox.ICONINFORMATION) != 0)
086: messageType = JOptionPane.INFORMATION_MESSAGE;
087: else if ((flags & MessageBox.ICONQUESTION) != 0)
088: messageType = JOptionPane.QUESTION_MESSAGE;
089: else if ((flags & MessageBox.ICONWARNING) != 0)
090: messageType = JOptionPane.WARNING_MESSAGE;
091:
092: int buttonType = JOptionPane.DEFAULT_OPTION;
093: if ((flags & MessageBox.YESNO) != 0)
094: buttonType = JOptionPane.YES_NO_OPTION;
095: else if ((flags & MessageBox.YESNOCANCEL) != 0)
096: buttonType = JOptionPane.YES_NO_CANCEL_OPTION;
097: else if ((flags & MessageBox.OKCANCEL) != 0)
098: buttonType = JOptionPane.OK_CANCEL_OPTION;
099:
100: return JOptionPane.showConfirmDialog(parent, msg, title,
101: buttonType, messageType);
102: }
103: }
|