Source Code Cross Referenced for GUIUtils.java in  » XML-UI » xmlgui » org » beryl » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML UI » xmlgui » org.beryl.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Beryl - A web platform based on XML, XSLT and Java
003:         * This file is part of the Beryl XML GUI
004:         *
005:         * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU Lesser General Public
009:         * License as published by the Free Software Foundation; either
010:         * version 2.1 of the License, or (at your option) any later version.
011:
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107  USA
020:         */
021:
022:        package org.beryl.gui;
023:
024:        import java.awt.Component;
025:        import java.awt.EventQueue;
026:        import java.awt.Toolkit;
027:        import java.io.PrintWriter;
028:        import java.io.Writer;
029:        import java.lang.ref.WeakReference;
030:        import java.net.URL;
031:        import java.util.ArrayList;
032:        import java.util.Iterator;
033:        import java.util.Locale;
034:        import java.util.Properties;
035:
036:        import javax.swing.LookAndFeel;
037:        import javax.swing.SwingUtilities;
038:        import javax.swing.UIManager;
039:
040:        import org.apache.log4j.PropertyConfigurator;
041:
042:        /**
043:         * Miscellaneous functions to get the XML GUI ready for use and to perform common tasks
044:         */
045:        public class GUIUtils {
046:            public static final String KUNSTSTOFF_LNF = "com.incors.plaf.kunststoff.KunststoffLookAndFeel";
047:            private static ArrayList widgets = new ArrayList();
048:
049:            private static class ExceptionWriter extends Writer {
050:                public String exception = new String();
051:
052:                /**
053:                 * Overwritten IO function (from <tt>java.io.Writer</tt>)
054:                 */
055:                public void close() {
056:                }
057:
058:                /**
059:                 * Overwritten IO function (from <tt>java.io.Writer</tt>)
060:                 */
061:                public void flush() {
062:                }
063:
064:                /**
065:                 * Overwritten IO function (from <tt>java.io.Writer</tt>)
066:                 */
067:                public void write(String string) {
068:                }
069:
070:                /**
071:                 * Overwritten IO function (from <tt>java.io.Writer</tt>)
072:                 */
073:                public void write(char[] cbuf, int off, int len) {
074:                    String str = new String(cbuf, off, len);
075:                    exception += str + "\n";
076:                }
077:
078:            };
079:
080:            /**
081:             * Convert a <tt>Throwable</tt> into a <tt>String</tt>
082:             * @param throwable The <tt>Throwable</tt> to convert
083:             * @return A <tt>String</tt> describing the <tt>Throwable</tt>
084:             */
085:            public static String getStringForThrowable(Throwable throwable) {
086:                ExceptionWriter writer = new ExceptionWriter();
087:                throwable.printStackTrace(new PrintWriter(writer));
088:                return writer.exception;
089:            }
090:
091:            /**
092:             * Add the core internationalization & icons to the search path
093:             */
094:            public static void initializeBase() throws GUIException {
095:                ImageIconFactory.addSearchPath("resources/xmlgui/icons");
096:                InternationalizationManager
097:                        .addLanguageFile("resources/xmlgui/base");
098:            }
099:
100:            /**
101:             * MacOS X specific initialization
102:             */
103:            public static void initializeOSX() {
104:                System.setProperty("apple.laf.useScreenMenuBar", "true");
105:            }
106:
107:            /**
108:             * Initialize the event queue
109:             */
110:            public static void initializeEventQueue() {
111:                EventQueue waitQueue = new WaitCursorEventQueue(500);
112:                Toolkit.getDefaultToolkit().getSystemEventQueue().push(
113:                        waitQueue);
114:            }
115:
116:            /**
117:             * Initialize log4j with a basic console appender
118:             */
119:            public static void initializeLogging() throws GUIException {
120:                try {
121:
122:                    URL url = GUIUtils.class
123:                            .getResource("/resources/xmlgui/log4j.properties");
124:                    Properties properties = new Properties();
125:                    properties.load(url.openStream());
126:                    PropertyConfigurator.configure(properties);
127:                } catch (Exception e) {
128:                    throw new GUIException("Error while initializing logging",
129:                            e);
130:                }
131:            }
132:
133:            /**
134:             * Initialize a custom look and feel
135:             */
136:            public static void initializeLookAndFeel(String className)
137:                    throws GUIException {
138:                try {
139:                    Class lnfClass = Class.forName(className);
140:
141:                    UIManager.setLookAndFeel((LookAndFeel) lnfClass
142:                            .newInstance());
143:                    UIManager.getLookAndFeelDefaults().put("ClassLoader",
144:                            GUIUtils.class.getClassLoader());
145:                } catch (Exception e) {
146:                    throw new GUIException(
147:                            "Error while initializing LookAndFeel");
148:                }
149:            }
150:
151:            /**
152:             * Initialize everything using the given locale
153:             */
154:            public static void defaultInitialization(Locale locale)
155:                    throws GUIException {
156:                if (locale != null)
157:                    Locale.setDefault(locale);
158:                initializeLogging();
159:                initializeBase();
160:                initializeEventQueue();
161:
162:                if (System.getProperty("os.name").equals("Mac OS X")) {
163:                    initializeOSX();
164:                } else {
165:                    try {
166:                        initializeLookAndFeel(KUNSTSTOFF_LNF);
167:                    } catch (GUIException e) {
168:                        /* Ignore */
169:                    }
170:                }
171:            }
172:
173:            /**
174:             * Initialize everything while taking the default locale
175:             */
176:            public static void defaultInitialization() throws GUIException {
177:                defaultInitialization(null);
178:            }
179:
180:            /**
181:             * Dynamically update the look and feel of all widgets
182:             */
183:            public static void updateAllWidgets() {
184:                synchronized (widgets) {
185:                    for (int i = 0; i < widgets.size(); i++) {
186:                        WeakReference ref = (WeakReference) widgets.get(i);
187:                        Widget referent = (Widget) ref.get();
188:
189:                        if (referent != null) {
190:                            Component component = referent.getWidget();
191:                            if (component != null)
192:                                SwingUtilities.updateComponentTreeUI(component);
193:                        }
194:                    }
195:                }
196:            }
197:
198:            /**
199:             * Internally used by Frame/Dialogs to register themselves
200:             * when they are created. Needed for dynamic Look And Feel
201:             * changes
202:             */
203:            public static void register(Widget widget) {
204:                WeakReference reference = new WeakReference(widget);
205:                reference.enqueue();
206:                synchronized (widgets) {
207:                    widgets.add(reference);
208:                }
209:                System.gc();
210:            }
211:
212:            /**
213:             * Internally used by Frame/Dialogs to unregister themselves
214:             * when they are finalized. Needed for dynamic Look And Feel
215:             * changes
216:             */
217:            public static void unregister(Widget widget) {
218:                synchronized (widgets) {
219:                    for (Iterator i = widgets.iterator(); i.hasNext();) {
220:                        WeakReference ref = (WeakReference) i.next();
221:                        Object referent = ref.get();
222:
223:                        if (referent == widget || referent == null) {
224:                            i.remove();
225:                        }
226:                    }
227:                }
228:            }
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.