KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > util > CommonSwing


1 /* Copyright (c) 2001-2005, The HSQL Development Group
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the HSQL Development Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31
32 package org.hsqldb.util;
33
34 import java.awt.Dimension JavaDoc;
35 import java.awt.Image JavaDoc;
36 import java.awt.Toolkit JavaDoc;
37
38 import javax.swing.ImageIcon JavaDoc;
39 import javax.swing.JFrame JavaDoc;
40 import javax.swing.JOptionPane JavaDoc;
41 import javax.swing.SwingUtilities JavaDoc;
42 import javax.swing.UIManager JavaDoc;
43
44 // sqlbob@users 20020407 - patch 1.7.0 - reengineering
45
// weconsultants@users 20041109 - patch 1.8.0 - enhancements:
46
// Added Methods: setSwingLAF(), LookAndFeelInfo(), setFramePositon()
47
// errorMessage(String errorMessage),
48
// errorMessage(Exception exceptionMsg,
49
// Added: Ability to switch the current LAF while runing (Native,Java or Motif)
50

51 /**
52  * Common code in the Swing versions of DatabaseManager and Tranfer
53  *
54  * @author sqlbob@users
55  * @version 1.7.2
56  * @since 1.7.0
57  */

58 class CommonSwing {
59
60     protected static String JavaDoc messagerHeader = "Database Manager Swing Error";
61     protected static String JavaDoc Native = "Native";
62     protected static String JavaDoc Java = "Java";
63     protected static String JavaDoc Motif = "Motif";
64     protected static String JavaDoc plaf = "plaf";
65     protected static String JavaDoc GTK = "GTK";
66
67     // (ulrivo): An actual Image.
68
static Image JavaDoc getIcon(String JavaDoc target) {
69
70         if (target.equalsIgnoreCase("SystemCursor")) {
71             return (new ImageIcon JavaDoc(
72                 CommonSwing.class.getResource("Hourglass.gif")).getImage());
73         } else if (target.equalsIgnoreCase("Frame")) {
74             return (new ImageIcon JavaDoc(
75                 CommonSwing.class.getResource("hsqldb.gif")).getImage());
76         } else if (target.equalsIgnoreCase("Execute")) {
77             return (new ImageIcon JavaDoc(
78                 CommonSwing.class.getResource("run_exc.gif")).getImage());
79         } else if (target.equalsIgnoreCase("StatusRunning")) {
80             return (new ImageIcon JavaDoc(
81                 CommonSwing.class.getResource("RedCircle.gif")).getImage());
82         } else if (target.equalsIgnoreCase("StatusReady")) {
83             return (new ImageIcon JavaDoc(
84                 CommonSwing.class.getResource("GreenCircle.gif")).getImage());
85         } else if (target.equalsIgnoreCase("Clear")) {
86             return (new ImageIcon JavaDoc(
87                 CommonSwing.class.getResource("Clear.png")).getImage());
88         } else if (target.equalsIgnoreCase("Problem")) {
89             return (new ImageIcon JavaDoc(
90                 CommonSwing.class.getResource("problems.gif")).getImage());
91         } else if (target.equalsIgnoreCase("BoldFont")) {
92             return (new ImageIcon JavaDoc(
93                 CommonSwing.class.getResource("Bold.gif")).getImage());
94         } else if (target.equalsIgnoreCase("ItalicFont")) {
95             return (new ImageIcon JavaDoc(
96                 CommonSwing.class.getResource("Italic.gif")).getImage());
97         } else if (target.equalsIgnoreCase("ColorSelection")) {
98             return (new ImageIcon JavaDoc(
99                 CommonSwing.class.getResource("Colors.png")).getImage());
100         } else if (target.equalsIgnoreCase("Close")) {
101             return (new ImageIcon JavaDoc(
102                 CommonSwing.class.getResource("Close.png")).getImage());
103         } else {
104             return (null);
105         }
106     }
107
108     // (weconsultants@users: Callable errorMessage method
109
protected static void errorMessage(String JavaDoc errorMessage) {
110
111         /**
112          * Display Jpanel Error messages any text Errors. Overloads
113          * errorMessage(Exception exceptionMsg)
114          */

115         Object JavaDoc[] options = { "OK" };
116
117         JOptionPane.showOptionDialog(null, errorMessage, messagerHeader,
118                                      JOptionPane.DEFAULT_OPTION,
119                                      JOptionPane.WARNING_MESSAGE, null,
120                                      options, options[0]);
121
122         // DatabaseManagerSwing.StatusMessage(READY_STATUS);
123
}
124
125     public static void errorMessage(Exception JavaDoc exceptionMsg) {
126         errorMessage(exceptionMsg, false);
127     }
128
129     // (weconsultants@users: Callable errorMessage method
130
public static void errorMessage(Exception JavaDoc exceptionMsg, boolean quiet) {
131
132         /**
133          * Display Jpanel Error messages any SQL Errors. Overloads
134          * errorMessage(String e)
135          */

136         Object JavaDoc[] options = { "OK", };
137
138         JOptionPane.showOptionDialog(null, exceptionMsg, messagerHeader,
139                                      JOptionPane.DEFAULT_OPTION,
140                                      JOptionPane.ERROR_MESSAGE, null,
141                                      options, options[0]);
142
143         if (!quiet) {
144             exceptionMsg.printStackTrace();
145         }
146
147         // DatabaseManagerSwing.StatusMessage(READY_STATUS);
148
}
149
150     // (weconsultants@users: Callable setFramePositon method
151
static void setFramePositon(JFrame JavaDoc inTargetFrame) {
152
153         Dimension JavaDoc d = Toolkit.getDefaultToolkit().getScreenSize();
154         Dimension JavaDoc size = inTargetFrame.getSize();
155
156         // (ulrivo): full size on screen with less than 640 width
157
if (d.width >= 640) {
158             inTargetFrame.setLocation((d.width - size.width) / 2,
159                                       (d.height - size.height) / 2);
160         } else {
161             inTargetFrame.setLocation(0, 0);
162             inTargetFrame.setSize(d);
163         }
164     }
165
166 // (weconsultants@users: Commented out, Not need now. Was not being called anyway.. Could delete?
167
// static void setDefaultColor() {
168
//
169
// Color hsqlBlue = new Color(102, 153, 204);
170
// Color hsqlGreen = new Color(153, 204, 204);
171
// UIDefaults d = UIManager.getLookAndFeelDefaults();
172
//
173
// d.put("MenuBar.background", SystemColor.control);
174
// d.put("Menu.background", SystemColor.control);
175
// d.put("Menu.selectionBackground", hsqlBlue);
176
// d.put("MenuItem.background", SystemColor.menu);
177
// d.put("MenuItem.selectionBackground", hsqlBlue);
178
// d.put("Separator.foreground", SystemColor.controlDkShadow);
179
// d.put("Button.background", SystemColor.control);
180
// d.put("CheckBox.background", SystemColor.control);
181
// d.put("Label.background", SystemColor.control);
182
// d.put("Label.foreground", Color.black);
183
// d.put("Panel.background", SystemColor.control);
184
// d.put("PasswordField.selectionBackground", hsqlGreen);
185
// d.put("PasswordField.background", SystemColor.white);
186
// d.put("TextArea.selectionBackground", hsqlGreen);
187
// d.put("TextField.background", SystemColor.white);
188
// d.put("TextField.selectionBackground", hsqlGreen);
189
// d.put("TextField.background", SystemColor.white);
190
// d.put("ScrollBar.background", SystemColor.controlHighlight);
191
// d.put("ScrollBar.foreground", SystemColor.control);
192
// d.put("ScrollBar.track", SystemColor.controlHighlight);
193
// d.put("ScrollBar.trackHighlight", SystemColor.controlDkShadow);
194
// d.put("ScrollBar.thumb", SystemColor.control);
195
// d.put("ScrollBar.thumbHighlight", SystemColor.controlHighlight);
196
// d.put("ScrollBar.thumbDarkShadow", SystemColor.controlDkShadow);
197
// d.put("ScrollBar.thumbLightShadow", SystemColor.controlShadow);
198
// d.put("ComboBox.background", SystemColor.control);
199
// d.put("ComboBox.selectionBackground", hsqlBlue);
200
// d.put("Table.background", SystemColor.white);
201
// d.put("Table.selectionBackground", hsqlBlue);
202
// d.put("TableHeader.background", SystemColor.control);
203
//
204
// // This doesn't seem to work.
205
// d.put("SplitPane.background", SystemColor.control);
206
// d.put("Tree.selectionBackground", hsqlBlue);
207
// d.put("List.selectionBackground", hsqlBlue);
208
// }
209
// (weconsultants@users: Callable setSwingLAF method for changing LAF
210
static void setSwingLAF(java.awt.Component JavaDoc comp, String JavaDoc targetTheme) {
211
212         try {
213             if (targetTheme.equalsIgnoreCase(Native)) {
214                 UIManager.setLookAndFeel(
215                     UIManager.getSystemLookAndFeelClassName());
216             } else if (targetTheme.equalsIgnoreCase(Java)) {
217                 UIManager.setLookAndFeel(
218                     UIManager.getCrossPlatformLookAndFeelClassName());
219             } else if (targetTheme.equalsIgnoreCase(Motif)) {
220                 UIManager.setLookAndFeel(
221                     "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
222             }
223
224 // if (targetTheme.equalsIgnoreCase(plaf)){
225
// UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
226
// }
227
//
228
// if (targetTheme.equalsIgnoreCase(GTK)){
229
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
230
// }
231
SwingUtilities.updateComponentTreeUI(comp);
232
233             if (comp instanceof java.awt.Frame JavaDoc) {
234                 ((java.awt.Frame JavaDoc) comp).pack();
235             }
236         } catch (Exception JavaDoc e) {
237             errorMessage(e);
238         }
239     }
240 }
241
Popular Tags