KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > client > widgets > DialogBox


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2002-2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.client.widgets;
20
21 import java.util.Vector JavaDoc;
22 import javax.swing.*;
23 import javax.swing.JOptionPane JavaDoc;
24
25 import org.lucane.client.util.Translation;
26 import org.lucane.common.Logging;
27
28
29 public class DialogBox
30 {
31   /**
32    * Outputs and logs a graphical error message
33    *
34    * @param message the error message
35    */

36   public static void error(String JavaDoc message)
37   {
38     JOptionPane.showMessageDialog(null, message, "Lucane", JOptionPane.ERROR_MESSAGE);
39     Logging.getLogger().info(message);
40   }
41
42   /**
43    * Outputs and logs a graphical informative message
44    *
45    * @param message the informative message
46    */

47   public static void info(String JavaDoc message)
48   {
49     JOptionPane.showMessageDialog(null, message, "Lucane", JOptionPane.INFORMATION_MESSAGE);
50     Logging.getLogger().info(message);
51   }
52
53   /**
54    * Display a question box (yes/no)
55    *
56    * @param title the dialog box title
57    * @param message the message
58    * @return true if yes is cliqued, false otherwise
59    */

60   public static boolean question(String JavaDoc title, String JavaDoc message)
61   {
62     Object JavaDoc[] options = {Translation.tr("yes"), Translation.tr("no")};
63     int response = JOptionPane.showOptionDialog(
64         null, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
65         null, //don't use a custom Icon
66
options, //the titles of buttons
67
options[0]); //default button title);
68

69     if(response == JOptionPane.YES_OPTION)
70       return true;
71     else
72       return false;
73   }
74   
75   /**
76    * Display a text box
77    *
78    * @param title the dialog box title
79    * @param message the message
80    * @return the user answer
81    */

82   public static String JavaDoc input(String JavaDoc title, String JavaDoc message)
83   {
84     return JOptionPane.showInputDialog(null, message, title, JOptionPane.QUESTION_MESSAGE);
85   }
86
87   /**
88    * Display a text box
89    *
90    * @param title the dialog box title
91    * @param message the message
92    * @param defaultValue the default value
93    * @return the user answer
94    */

95   public static String JavaDoc input(String JavaDoc title, String JavaDoc message, String JavaDoc defaultValue)
96   {
97     return (String JavaDoc)JOptionPane.showInputDialog(null, message, title, JOptionPane.QUESTION_MESSAGE, null, null, defaultValue);
98   }
99
100   /**
101    * Display a ListBox
102    *
103    * @param owner the owner JFrame or null
104    * @param title the dialog title
105    * @param message the dialog message
106    * @param list the selectables items
107    * @return the selected index
108    */

109   public static int list(JFrame owner, String JavaDoc title, String JavaDoc message, Vector JavaDoc list)
110   {
111     return (new ListBox(owner, title, message, list)).selectItemByIndex();
112   }
113 }
114
Popular Tags