KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > MessageBox


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * MessageBox.java
28  *
29  * Created on 11 febbraio 2003, 16.07
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34
35 import javax.swing.*;
36 /**
37  *
38  * @author Administrator
39  */

40 public class MessageBox {
41     
42     // Buttons
43
/** Indicates that the message box should display an OK button */
44     public static final int OK = 1;
45     /** Indicates that the message box should display OK and Cancel buttons */
46     public static final int OKCANCEL = 2;
47     /** Indicates that the message box should display Yes and No buttons */
48     public static final int YESNO = 4;
49     /** Indicates that the message box should display Yes, No, and Cancel buttons */
50     public static final int YESNOCANCEL = 8;
51     
52     // ICONS
53
/** Indicates that the message box should display an error icon */
54     public static final int ICONERROR = 16;
55     /** Indicates that the message box should display an exclamation (!) icon */
56     public static final int ICONINFORMATION = 32;
57     /** Indicates that the message box should display a question mark (?) icon */
58     public static final int ICONQUESTION = 64;
59     /** Indicates that the message box should display a warning icon */
60     public static final int ICONWARNING = 128;
61    
62     /** Creates a new instance of MessageBox */
63     public MessageBox() {
64     }
65     
66     public static int show(String JavaDoc msg, String JavaDoc title, int flags)
67     {
68         return MessageBox.show(null, msg,title,flags);
69     }
70     
71     public static int show(String JavaDoc msg)
72     {
73         return MessageBox.show(null, msg,"",MessageBox.OK);
74     }
75         
76     public static int show(JComponent parent, String JavaDoc msg)
77     {
78         return MessageBox.show(parent, msg,"",MessageBox.OK);
79     }
80     
81     public static int show(JComponent parent, String JavaDoc msg, String JavaDoc title, int flags)
82     {
83          
84         int messageType = JOptionPane.PLAIN_MESSAGE;
85         if ( (flags & MessageBox.ICONERROR) != 0)
86             messageType = JOptionPane.ERROR_MESSAGE;
87         else if ( (flags & MessageBox.ICONINFORMATION) != 0)
88             messageType = JOptionPane.INFORMATION_MESSAGE;
89         else if ( (flags & MessageBox.ICONQUESTION) != 0)
90             messageType = JOptionPane.QUESTION_MESSAGE;
91         else if ( (flags & MessageBox.ICONWARNING) != 0)
92             messageType = JOptionPane.WARNING_MESSAGE;
93         
94         int buttonType = JOptionPane.DEFAULT_OPTION;
95         if ( (flags & MessageBox.YESNO) != 0)
96             buttonType = JOptionPane.YES_NO_OPTION;
97         else if ( (flags & MessageBox.YESNOCANCEL) != 0)
98             buttonType = JOptionPane.YES_NO_CANCEL_OPTION;
99         else if ( (flags & MessageBox.OKCANCEL) != 0)
100             buttonType = JOptionPane.OK_CANCEL_OPTION;
101       
102          return JOptionPane.showConfirmDialog( parent,msg,title,buttonType, messageType);
103     }
104 }
105
Popular Tags