001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.util;
032:
033: import java.awt.Dimension;
034: import java.awt.Image;
035: import java.awt.Toolkit;
036:
037: import javax.swing.ImageIcon;
038: import javax.swing.JFrame;
039: import javax.swing.JOptionPane;
040: import javax.swing.SwingUtilities;
041: import javax.swing.UIManager;
042:
043: // sqlbob@users 20020407 - patch 1.7.0 - reengineering
044: // weconsultants@users 20041109 - patch 1.8.0 - enhancements:
045: // Added Methods: setSwingLAF(), LookAndFeelInfo(), setFramePositon()
046: // errorMessage(String errorMessage),
047: // errorMessage(Exception exceptionMsg,
048: // Added: Ability to switch the current LAF while runing (Native,Java or Motif)
049:
050: /**
051: * Common code in the Swing versions of DatabaseManager and Tranfer
052: *
053: * @author sqlbob@users
054: * @version 1.7.2
055: * @since 1.7.0
056: */
057: class CommonSwing {
058:
059: protected static String messagerHeader = "Database Manager Swing Error";
060: protected static String Native = "Native";
061: protected static String Java = "Java";
062: protected static String Motif = "Motif";
063: protected static String plaf = "plaf";
064: protected static String GTK = "GTK";
065:
066: // (ulrivo): An actual Image.
067: static Image getIcon(String target) {
068:
069: if (target.equalsIgnoreCase("SystemCursor")) {
070: return (new ImageIcon(CommonSwing.class
071: .getResource("Hourglass.gif")).getImage());
072: } else if (target.equalsIgnoreCase("Frame")) {
073: return (new ImageIcon(CommonSwing.class
074: .getResource("hsqldb.gif")).getImage());
075: } else if (target.equalsIgnoreCase("Execute")) {
076: return (new ImageIcon(CommonSwing.class
077: .getResource("run_exc.gif")).getImage());
078: } else if (target.equalsIgnoreCase("StatusRunning")) {
079: return (new ImageIcon(CommonSwing.class
080: .getResource("RedCircle.gif")).getImage());
081: } else if (target.equalsIgnoreCase("StatusReady")) {
082: return (new ImageIcon(CommonSwing.class
083: .getResource("GreenCircle.gif")).getImage());
084: } else if (target.equalsIgnoreCase("Clear")) {
085: return (new ImageIcon(CommonSwing.class
086: .getResource("Clear.png")).getImage());
087: } else if (target.equalsIgnoreCase("Problem")) {
088: return (new ImageIcon(CommonSwing.class
089: .getResource("problems.gif")).getImage());
090: } else if (target.equalsIgnoreCase("BoldFont")) {
091: return (new ImageIcon(CommonSwing.class
092: .getResource("Bold.gif")).getImage());
093: } else if (target.equalsIgnoreCase("ItalicFont")) {
094: return (new ImageIcon(CommonSwing.class
095: .getResource("Italic.gif")).getImage());
096: } else if (target.equalsIgnoreCase("ColorSelection")) {
097: return (new ImageIcon(CommonSwing.class
098: .getResource("Colors.png")).getImage());
099: } else if (target.equalsIgnoreCase("Close")) {
100: return (new ImageIcon(CommonSwing.class
101: .getResource("Close.png")).getImage());
102: } else {
103: return (null);
104: }
105: }
106:
107: // (weconsultants@users: Callable errorMessage method
108: protected static void errorMessage(String errorMessage) {
109:
110: /**
111: * Display Jpanel Error messages any text Errors. Overloads
112: * errorMessage(Exception exceptionMsg)
113: */
114: Object[] options = { "OK" };
115:
116: JOptionPane.showOptionDialog(null, errorMessage,
117: messagerHeader, JOptionPane.DEFAULT_OPTION,
118: JOptionPane.WARNING_MESSAGE, null, options, options[0]);
119:
120: // DatabaseManagerSwing.StatusMessage(READY_STATUS);
121: }
122:
123: public static void errorMessage(Exception exceptionMsg) {
124: errorMessage(exceptionMsg, false);
125: }
126:
127: // (weconsultants@users: Callable errorMessage method
128: public static void errorMessage(Exception exceptionMsg,
129: boolean quiet) {
130:
131: /**
132: * Display Jpanel Error messages any SQL Errors. Overloads
133: * errorMessage(String e)
134: */
135: Object[] options = { "OK", };
136:
137: JOptionPane.showOptionDialog(null, exceptionMsg,
138: messagerHeader, JOptionPane.DEFAULT_OPTION,
139: JOptionPane.ERROR_MESSAGE, null, options, options[0]);
140:
141: if (!quiet) {
142: exceptionMsg.printStackTrace();
143: }
144:
145: // DatabaseManagerSwing.StatusMessage(READY_STATUS);
146: }
147:
148: // (weconsultants@users: Callable setFramePositon method
149: static void setFramePositon(JFrame inTargetFrame) {
150:
151: Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
152: Dimension size = inTargetFrame.getSize();
153:
154: // (ulrivo): full size on screen with less than 640 width
155: if (d.width >= 640) {
156: inTargetFrame.setLocation((d.width - size.width) / 2,
157: (d.height - size.height) / 2);
158: } else {
159: inTargetFrame.setLocation(0, 0);
160: inTargetFrame.setSize(d);
161: }
162: }
163:
164: // (weconsultants@users: Commented out, Not need now. Was not being called anyway.. Could delete?
165: // static void setDefaultColor() {
166: //
167: // Color hsqlBlue = new Color(102, 153, 204);
168: // Color hsqlGreen = new Color(153, 204, 204);
169: // UIDefaults d = UIManager.getLookAndFeelDefaults();
170: //
171: // d.put("MenuBar.background", SystemColor.control);
172: // d.put("Menu.background", SystemColor.control);
173: // d.put("Menu.selectionBackground", hsqlBlue);
174: // d.put("MenuItem.background", SystemColor.menu);
175: // d.put("MenuItem.selectionBackground", hsqlBlue);
176: // d.put("Separator.foreground", SystemColor.controlDkShadow);
177: // d.put("Button.background", SystemColor.control);
178: // d.put("CheckBox.background", SystemColor.control);
179: // d.put("Label.background", SystemColor.control);
180: // d.put("Label.foreground", Color.black);
181: // d.put("Panel.background", SystemColor.control);
182: // d.put("PasswordField.selectionBackground", hsqlGreen);
183: // d.put("PasswordField.background", SystemColor.white);
184: // d.put("TextArea.selectionBackground", hsqlGreen);
185: // d.put("TextField.background", SystemColor.white);
186: // d.put("TextField.selectionBackground", hsqlGreen);
187: // d.put("TextField.background", SystemColor.white);
188: // d.put("ScrollBar.background", SystemColor.controlHighlight);
189: // d.put("ScrollBar.foreground", SystemColor.control);
190: // d.put("ScrollBar.track", SystemColor.controlHighlight);
191: // d.put("ScrollBar.trackHighlight", SystemColor.controlDkShadow);
192: // d.put("ScrollBar.thumb", SystemColor.control);
193: // d.put("ScrollBar.thumbHighlight", SystemColor.controlHighlight);
194: // d.put("ScrollBar.thumbDarkShadow", SystemColor.controlDkShadow);
195: // d.put("ScrollBar.thumbLightShadow", SystemColor.controlShadow);
196: // d.put("ComboBox.background", SystemColor.control);
197: // d.put("ComboBox.selectionBackground", hsqlBlue);
198: // d.put("Table.background", SystemColor.white);
199: // d.put("Table.selectionBackground", hsqlBlue);
200: // d.put("TableHeader.background", SystemColor.control);
201: //
202: // // This doesn't seem to work.
203: // d.put("SplitPane.background", SystemColor.control);
204: // d.put("Tree.selectionBackground", hsqlBlue);
205: // d.put("List.selectionBackground", hsqlBlue);
206: // }
207: // (weconsultants@users: Callable setSwingLAF method for changing LAF
208: static void setSwingLAF(java.awt.Component comp, String targetTheme) {
209:
210: try {
211: if (targetTheme.equalsIgnoreCase(Native)) {
212: UIManager.setLookAndFeel(UIManager
213: .getSystemLookAndFeelClassName());
214: } else if (targetTheme.equalsIgnoreCase(Java)) {
215: UIManager.setLookAndFeel(UIManager
216: .getCrossPlatformLookAndFeelClassName());
217: } else if (targetTheme.equalsIgnoreCase(Motif)) {
218: UIManager
219: .setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
220: }
221:
222: // if (targetTheme.equalsIgnoreCase(plaf)){
223: // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
224: // }
225: //
226: // if (targetTheme.equalsIgnoreCase(GTK)){
227: // UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
228: // }
229: SwingUtilities.updateComponentTreeUI(comp);
230:
231: if (comp instanceof java.awt.Frame) {
232: ((java.awt.Frame) comp).pack();
233: }
234: } catch (Exception e) {
235: errorMessage(e);
236: }
237: }
238: }
|