KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mullassery > act > util > GUIUtil


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if
20  * any, must include the following acknowlegement:
21  * "This product includes software developed by the
22  * Apache Software Foundation (http://www.apache.org/)."
23  * Alternately, this acknowlegement may appear in the software itself,
24  * if and wherever such third-party acknowlegements normally appear.
25  *
26  * 4. The names "The Jakarta Project", "Ant", and "Apache Software
27  * Foundation" must not be used to endorse or promote products derived
28  * from this software without prior written permission. For written
29  * permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache"
32  * nor may "Apache" appear in their names without prior written
33  * permission of the Apache Group.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation. For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  */

54
55 package com.mullassery.act.util;
56
57 import java.awt.Component JavaDoc;
58 import java.awt.Dimension JavaDoc;
59 import java.awt.Point JavaDoc;
60 import java.awt.Toolkit JavaDoc;
61 import java.util.MissingResourceException JavaDoc;
62 import java.util.ResourceBundle JavaDoc;
63
64 import javax.swing.JOptionPane JavaDoc;
65
66 /**
67  *
68  * @author Abey Mullassery
69  *
70  */

71 public final class GUIUtil {
72     public static final String JavaDoc ACT_GUI_BUNDLE_NAME = "com.mullassery.act.gui.actGui";
73     public static final ResourceBundle JavaDoc ACT_GUI_RESOURCE_BUNDLE =
74         ResourceBundle.getBundle(GUIUtil.ACT_GUI_BUNDLE_NAME);
75     public static final String JavaDoc TASK = getString("ACT.xml.task");
76     public static final String JavaDoc TASK_CLASS = getString("ACT.xml.class");
77     public static final String JavaDoc TASK_DESCRIPTION = getString("ACT.xml.description");
78     public static final String JavaDoc TASK_DISPLAY = getString("ACT.xml.display");
79
80     public static final String JavaDoc TASK_GROUP = getString("ACT.xml.taskgroup");
81     public static final String JavaDoc TASK_LIST = getString("ACT.xml.tasks");
82     public static final String JavaDoc TASK_NAME = getString("ACT.xml.name");
83     public static final String JavaDoc TASK_VISIBLE = getString("ACT.xml.visible");
84
85     public static void centralize(Component JavaDoc comp) {
86         Dimension JavaDoc size = comp.getSize();
87         Dimension JavaDoc scr = Toolkit.getDefaultToolkit().getScreenSize();
88         int x = (scr.width - size.width) / 2;
89         int y = (scr.height - size.height) / 2;
90         comp.setBounds(x, y, size.width, size.height);
91     }
92
93     public static Point JavaDoc getCenter() {
94         Dimension JavaDoc scr = Toolkit.getDefaultToolkit().getScreenSize();
95         return new Point JavaDoc(scr.width / 2, scr.height / 2);
96     }
97
98     public static final boolean getConfirmation(Component JavaDoc comp, String JavaDoc message) {
99         int ret =
100             showConfirm(
101                 comp,
102                 message,
103                 GUIUtil.getString("ACT.confirmDialogTitle"),
104                 JOptionPane.YES_NO_OPTION);
105         return (ret == JOptionPane.YES_OPTION || ret == JOptionPane.OK_OPTION);
106     }
107
108     public static final String JavaDoc getInput(Component JavaDoc comp, String JavaDoc message) {
109         return JOptionPane.showInputDialog(
110             comp,
111             message,
112             GUIUtil.getString("ACT.inputDialogTitle"),
113             JOptionPane.QUESTION_MESSAGE);
114     }
115
116     public static String JavaDoc getString(String JavaDoc key) {
117         try {
118             return GUIUtil.ACT_GUI_RESOURCE_BUNDLE.getString(key);
119         } catch (MissingResourceException JavaDoc e) {
120             return '!' + key + '!';
121         }
122     }
123
124     public static final int showConfirm(Component JavaDoc comp, String JavaDoc message, String JavaDoc title, int type) {
125         return JOptionPane.showConfirmDialog(comp, message, title, type);
126     }
127
128     public static final void showErrorMessage(Component JavaDoc comp, String JavaDoc message) {
129         showMessage(
130             comp,
131             message,
132             GUIUtil.getString("ACT.errorDialogTitle"),
133             JOptionPane.ERROR_MESSAGE);
134     }
135
136     public static final void showInfoMessage(Component JavaDoc comp, String JavaDoc message) {
137         showMessage(
138             comp,
139             message,
140             GUIUtil.getString("ACT.infoDialogTitle"),
141             JOptionPane.INFORMATION_MESSAGE);
142     }
143
144     public static final void showMessage(Component JavaDoc comp, String JavaDoc message, String JavaDoc title, int type) {
145         JOptionPane.showMessageDialog(comp, message, title, type);
146     }
147
148     public static final void showWarningMessage(Component JavaDoc comp, String JavaDoc message) {
149         showMessage(
150             comp,
151             message,
152             GUIUtil.getString("ACT.infoDialogTitle"),
153             JOptionPane.WARNING_MESSAGE);
154     }
155 }
156
Popular Tags