Source Code Cross Referenced for LAFPlugin.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » laf » 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 » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.laf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.laf;
002:
003:        /*
004:         * Copyright (C) 2001-2006 Colin Bell
005:         * colbell@users.sourceforge.net
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or 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
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:        import java.io.File;
022:        import java.io.FileNotFoundException;
023:        import java.io.IOException;
024:        import java.util.Iterator;
025:
026:        import javax.swing.JTabbedPane;
027:
028:        import com.jgoodies.looks.Options;
029:
030:        import net.sourceforge.squirrel_sql.fw.util.DuplicateObjectException;
031:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
032:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
033:        import net.sourceforge.squirrel_sql.fw.xml.XMLBeanReader;
034:        import net.sourceforge.squirrel_sql.fw.xml.XMLException;
035:        import net.sourceforge.squirrel_sql.fw.xml.XMLObjectCache;
036:
037:        import net.sourceforge.squirrel_sql.client.IApplication;
038:        import net.sourceforge.squirrel_sql.client.gui.builders.UIFactory;
039:        import net.sourceforge.squirrel_sql.client.gui.builders.UIFactoryAdapter;
040:        import net.sourceforge.squirrel_sql.client.gui.builders.UIFactoryComponentCreatedEvent;
041:        import net.sourceforge.squirrel_sql.client.plugin.DefaultPlugin;
042:        import net.sourceforge.squirrel_sql.client.plugin.PluginException;
043:        import net.sourceforge.squirrel_sql.client.plugin.PluginResources;
044:        import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
045:        import net.sourceforge.squirrel_sql.client.util.IdentifierFactory;
046:
047:        /**
048:         * The Look and Feel plugin class.
049:         *
050:         * @author  <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
051:         */
052:        public class LAFPlugin extends DefaultPlugin {
053:            /** Logger for this class. */
054:            private final static ILogger s_log = LoggerController
055:                    .createLogger(LAFPlugin.class);
056:
057:            /** Old name of file to store user prefs in. Replaced by USER_PREFS_FILE_NAME. */
058:            static final String OLD_USER_PREFS_FILE_NAME = "LAFPrefs.xml";
059:
060:            /** Name of file to store user prefs in. */
061:            static final String USER_PREFS_FILE_NAME = "LAFPreferences.xml";
062:
063:            /** Resources for this plugin. */
064:            private LAFPluginResources _resources;
065:
066:            /** Plugin preferences. */
067:            private LAFPreferences _lafPrefs;
068:
069:            /** A register of Look and Feels. */
070:            private LAFRegister _lafRegister;
071:
072:            /** The folder that contains LAF jars. */
073:            private File _lafFolder;
074:
075:            /** Folder to store user settings in. */
076:            private File _userSettingsFolder;
077:
078:            /** Folder to store extra LAFs supplied by the user. */
079:            private File _userExtraLAFFolder;
080:
081:            /** Cache of settings for the plugin. */
082:            private final XMLObjectCache<LAFPreferences> _settingsCache = new XMLObjectCache<LAFPreferences>();
083:
084:            /**
085:             * Return the internal name of this plugin.
086:             *
087:             * @return  the internal name of this plugin.
088:             */
089:            public String getInternalName() {
090:                return "laf";
091:            }
092:
093:            /**
094:             * Return the descriptive name of this plugin.
095:             *
096:             * @return  the descriptive name of this plugin.
097:             */
098:            public String getDescriptiveName() {
099:                return "Look & Feel Plugin";
100:            }
101:
102:            /**
103:             * Returns the current version of this plugin.
104:             *
105:             * @return  the current version of this plugin.
106:             */
107:            public String getVersion() {
108:                return "1.1";
109:            }
110:
111:            /**
112:             * Returns the authors name.
113:             *
114:             * @return  the authors name.
115:             */
116:            public String getAuthor() {
117:                return "Colin Bell";
118:            }
119:
120:            /**
121:             * Returns the name of the change log for the plugin. This should
122:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
123:             * directory.
124:             *
125:             * @return	the changelog file name or <TT>null</TT> if plugin doesn't have
126:             * 			a change log.
127:             */
128:            public String getChangeLogFileName() {
129:                return "changes.txt";
130:            }
131:
132:            /**
133:             * Returns the name of the Help file for the plugin. This should
134:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
135:             * directory.
136:             *
137:             * @return	the Help file name or <TT>null</TT> if plugin doesn't have
138:             * 			a help file.
139:             */
140:            public String getHelpFileName() {
141:                return "readme.html";
142:            }
143:
144:            /**
145:             * Returns the name of the Licence file for the plugin. This should
146:             * be a text or HTML file residing in the <TT>getPluginAppSettingsFolder</TT>
147:             * directory.
148:             *
149:             * @return	the Licence file name or <TT>null</TT> if plugin doesn't have
150:             * 			a licence file.
151:             */
152:            public String getLicenceFileName() {
153:                return "licences.html";
154:            }
155:
156:            /**
157:             * Load this plugin.
158:             *
159:             * @param   app	 Application API.
160:             */
161:            public synchronized void load(IApplication app)
162:                    throws PluginException {
163:                super .load(app);
164:
165:                // Load resources.
166:                _resources = new LAFPluginResources(this );
167:
168:                // Folder within plugins folder that belongs to this
169:                // plugin.
170:                File pluginAppFolder = null;
171:                try {
172:                    pluginAppFolder = getPluginAppSettingsFolder();
173:                } catch (IOException ex) {
174:                    throw new PluginException(ex);
175:                }
176:
177:                // Folder that stores Look and Feel jars.
178:                _lafFolder = new File(pluginAppFolder, "lafs");
179:                if (!_lafFolder.exists()) {
180:                    _lafFolder.mkdir();
181:                }
182:
183:                // Folder to store user settings.
184:                try {
185:                    _userSettingsFolder = getPluginUserSettingsFolder();
186:                } catch (IOException ex) {
187:                    throw new PluginException(ex);
188:                }
189:
190:                // Folder to contain extra LAFs supplied by the user.
191:                _userExtraLAFFolder = new File(_userSettingsFolder,
192:                        ILAFConstants.USER_EXTRA_LAFS_FOLDER);
193:
194:                // Create empty required files in user settings directory.
195:                createEmptyRequiredUserFiles();
196:
197:                // Load plugin preferences.
198:                loadPrefs();
199:
200:                // Setup preferences to make jGoodies LAF look better.
201:                //		UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, Boolean.TRUE);
202:                //		UIManager.put(Options.USE_NARROW_BUTTONS_KEY, Boolean.TRUE);
203:
204:                // Create the Look and Feel register.
205:                _lafRegister = new LAFRegister(app, this );
206:
207:                // Listen for GUI components being created.
208:                UIFactory.getInstance().addListener(new UIFactoryListener());
209:
210:                // Update font used for status bars.
211:                _lafRegister.updateStatusBarFont();
212:            }
213:
214:            /**
215:             * Application is shutting down so save preferences.
216:             */
217:            public void unload() {
218:                try {
219:                    savePrefs(new File(_userSettingsFolder,
220:                            USER_PREFS_FILE_NAME));
221:                } catch (IOException ex) {
222:                    s_log.error("Error occured writing to preferences file: "
223:                            + USER_PREFS_FILE_NAME, ex);
224:                } catch (XMLException ex) {
225:                    s_log.error("Error occured writing to preferences file: "
226:                            + USER_PREFS_FILE_NAME, ex);
227:                }
228:                super .unload();
229:            }
230:
231:            /**
232:             * Create Look and Feel preferences panels for the Global Preferences dialog.
233:             *
234:             * @return  Look and Feel preferences panels.
235:             */
236:            public IGlobalPreferencesPanel[] getGlobalPreferencePanels() {
237:                return new IGlobalPreferencesPanel[] {
238:                        new LAFPreferencesTab(this , _lafRegister),
239:                        new LAFFontsTab(this , _lafRegister), };
240:            }
241:
242:            /**
243:             * Return the folder that contains LAF jars.
244:             *
245:             * @return  folder as <TT>File</TT> that contains LAF jars.
246:             */
247:            File getLookAndFeelFolder() {
248:                return _lafFolder;
249:            }
250:
251:            /**
252:             * Retrieve the directory that contains the extra LAFs supplied
253:             * by the user.
254:             * 
255:             * @return	folder as <TT>File</TT> that contains the extra LAFs supplied
256:             * 			by the user.
257:             */
258:            File getUsersExtraLAFFolder() {
259:                return _userExtraLAFFolder;
260:            }
261:
262:            /**
263:             * Get the preferences info object for this plugin.
264:             *
265:             * @return	The preferences info object for this plugin.
266:             */
267:            LAFPreferences getLAFPreferences() {
268:                return _lafPrefs;
269:            }
270:
271:            /**
272:             * Retrieve plugins resources.
273:             * 
274:             * @return	Plugins resources.
275:             */
276:            PluginResources getResources() {
277:                return _resources;
278:            }
279:
280:            XMLObjectCache<LAFPreferences> getSettingsCache() {
281:                return _settingsCache;
282:            }
283:
284:            /**
285:             * Load from preferences file.
286:             */
287:            private void loadPrefs() {
288:                final File oldPrefsFile = new File(_userSettingsFolder,
289:                        OLD_USER_PREFS_FILE_NAME);
290:                final File newPrefsFile = new File(_userSettingsFolder,
291:                        USER_PREFS_FILE_NAME);
292:                final boolean oldExists = oldPrefsFile.exists();
293:                final boolean newExists = newPrefsFile.exists();
294:
295:                try {
296:                    if (oldExists) {
297:                        loadOldPrefs(oldPrefsFile);
298:                        try {
299:                            _settingsCache.add(_lafPrefs);
300:                        } catch (DuplicateObjectException ex) {
301:                            s_log.error(
302:                                    "LAFPreferences object already in cache",
303:                                    ex);
304:                        }
305:                        savePrefs(newPrefsFile);
306:                        if (!oldPrefsFile.delete()) {
307:                            s_log
308:                                    .error("Unable to delete old LAF preferences file");
309:                        }
310:
311:                    } else if (newExists) {
312:                        loadNewPrefs(newPrefsFile);
313:                    }
314:                } catch (IOException ex) {
315:                    s_log.error("Error occured in preferences file", ex);
316:                } catch (XMLException ex) {
317:                    s_log.error("Error occured in preferences file", ex);
318:                }
319:
320:                if (_lafPrefs == null) {
321:                    _lafPrefs = new LAFPreferences(IdentifierFactory
322:                            .getInstance().createIdentifier());
323:                    _lafPrefs
324:                            .setLookAndFeelClassName(PlasticLookAndFeelController.DEFAULT_LOOK_AND_FEEL_CLASS_NAME);
325:                    try {
326:                        _settingsCache.add(_lafPrefs);
327:                    } catch (DuplicateObjectException ex) {
328:                        s_log.error("LAFPreferences object already in cache",
329:                                ex);
330:                    }
331:                }
332:            }
333:
334:            /**
335:             * Load preferences from the old file format.
336:             * 
337:             * @param	oldPrefsFile	File containing the preferences info.
338:             * 
339:             * @throws	XMLException	Thrown if an error occurs eradign the rpeferences data.
340:             */
341:            private void loadOldPrefs(File oldPrefsFile) throws XMLException {
342:                try {
343:                    XMLBeanReader doc = new XMLBeanReader();
344:                    doc.load(oldPrefsFile, getClass().getClassLoader());
345:                    Iterator<?> it = doc.iterator();
346:                    if (it.hasNext()) {
347:                        _lafPrefs = (LAFPreferences) it.next();
348:                    }
349:                } catch (FileNotFoundException ignore) {
350:                    // property file not found for user - first time user ran pgm.
351:                }
352:            }
353:
354:            /**
355:             * Load preferences from the new file format.
356:             * 
357:             * @param	newPerfsFile	File containing the preferences information.
358:             * 
359:             * @throws	XMLException	Thrown if error reading preferences file.
360:             */
361:            private void loadNewPrefs(File newPrefsFile) throws XMLException {
362:                try {
363:                    try {
364:                        _settingsCache.load(newPrefsFile.getPath(), getClass()
365:                                .getClassLoader());
366:                    } catch (DuplicateObjectException ex) {
367:                        s_log.error("Cache should have been empty", ex);
368:                    }
369:                    Iterator<LAFPreferences> it = _settingsCache
370:                            .getAllForClass(LAFPreferences.class);
371:                    if (it.hasNext()) {
372:                        _lafPrefs = it.next();
373:                    } else {
374:                        s_log.error("LAFPreferences object not loaded");
375:                    }
376:                } catch (FileNotFoundException ignore) {
377:                    // property file not found for user - first time user ran pgm.
378:                }
379:            }
380:
381:            /**
382:             * Save preferences to disk.
383:             * 
384:             * @param	prefsFile	File to save preferences to.
385:             */
386:            private void savePrefs(File prefsFile) throws IOException,
387:                    XMLException {
388:                _settingsCache.save(prefsFile.getPath());
389:            }
390:
391:            private void createEmptyRequiredUserFiles() {
392:                _userExtraLAFFolder.mkdirs();
393:
394:                File file = new File(_userExtraLAFFolder,
395:                        ILAFConstants.USER_EXTRA_LAFS_PROPS_FILE);
396:                try {
397:                    file.createNewFile();
398:                } catch (IOException ex) {
399:                    s_log
400:                            .error("Error creating file "
401:                                    + file.getAbsolutePath(), ex);
402:                }
403:            }
404:
405:            private static class UIFactoryListener extends UIFactoryAdapter {
406:                /**
407:                 * A tabbed panel object has been created.
408:                 * 
409:                 * @param	evt	event object.
410:                 */
411:                public void tabbedPaneCreated(UIFactoryComponentCreatedEvent evt) {
412:                    final JTabbedPane pnl = (JTabbedPane) evt.getComponent();
413:                    pnl.putClientProperty(Options.NO_CONTENT_BORDER_KEY,
414:                            Boolean.TRUE);
415:                }
416:            }
417:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.