Source Code Cross Referenced for LAFPreferencesTab.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.awt.Component;
022:        import java.awt.GridBagConstraints;
023:        import java.awt.GridBagLayout;
024:        import java.awt.Insets;
025:        import java.awt.event.ActionEvent;
026:        import java.awt.event.ActionListener;
027:
028:        import javax.swing.BorderFactory;
029:        import javax.swing.JCheckBox;
030:        import javax.swing.JLabel;
031:        import javax.swing.JPanel;
032:        import javax.swing.SwingConstants;
033:        import javax.swing.UIManager;
034:
035:        import net.sourceforge.squirrel_sql.fw.gui.MultipleLineLabel;
036:        import net.sourceforge.squirrel_sql.fw.gui.OutputLabel;
037:        import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
038:        import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
039:        import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
040:        import net.sourceforge.squirrel_sql.fw.util.StringManager;
041:
042:        import net.sourceforge.squirrel_sql.client.IApplication;
043:        import net.sourceforge.squirrel_sql.client.preferences.IGlobalPreferencesPanel;
044:
045:        /**
046:         * The Look and Feel panel for the Global Preferences dialog.
047:         *
048:         * @author  <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
049:         */
050:        public class LAFPreferencesTab implements  IGlobalPreferencesPanel {
051:
052:            private static final StringManager s_stringMgr = StringManagerFactory
053:                    .getStringManager(LAFPreferencesTab.class);
054:
055:            /** Logger for this class. */
056:            private static ILogger s_log = LoggerController
057:                    .createLogger(LAFPreferencesTab.class);
058:
059:            /** The plugin. */
060:            private LAFPlugin _plugin;
061:
062:            /** Plugin preferences object. */
063:            //private LAFPreferences _prefs;
064:            /** Look and Feel register. */
065:            private LAFRegister _lafRegister;
066:
067:            /** LAF panel to display in the Global preferences dialog. */
068:            private LAFPreferencesPanel _myPanel;
069:
070:            /**
071:             * Ctor.
072:             *
073:             * @param	plugin			The LAF plugin.
074:             * @param	lafRegister		Look and Feel register.
075:             *
076:             * @throws	IllegalArgumentException
077:             *			if <TT>LAFPlugin</TT>, or <TT>LAFRegister</TT> is <TT>null</TT>.
078:             */
079:            public LAFPreferencesTab(LAFPlugin plugin, LAFRegister lafRegister) {
080:                super ();
081:                if (plugin == null) {
082:                    throw new IllegalArgumentException("Null LAFPlugin passed");
083:                }
084:                if (lafRegister == null) {
085:                    throw new IllegalArgumentException(
086:                            "Null LAFRegister passed");
087:                }
088:                _plugin = plugin;
089:                //_prefs = plugin.getLAFPreferences();
090:                _lafRegister = lafRegister;
091:            }
092:
093:            /**
094:             * Load panel with data from plugin preferences.
095:             *
096:             * @param	app	Application API.
097:             *
098:             * @throws	IllegalArgumentException
099:             *			if <TT>IApplication</TT> is <TT>null</TT>.
100:             */
101:            public void initialize(IApplication app) {
102:                if (app == null) {
103:                    throw new IllegalArgumentException(
104:                            "Null IApplication passed");
105:                }
106:                //_app = app;
107:                ((LAFPreferencesPanel) getPanelComponent()).loadData();
108:            }
109:
110:            public void uninitialize(IApplication app) {
111:
112:            }
113:
114:            /**
115:             * Return the component to be displayed in the Preferences dialog.
116:             *
117:             * @return  the component to be displayed in the Preferences dialog.
118:             */
119:            public synchronized Component getPanelComponent() {
120:                if (_myPanel == null) {
121:                    _myPanel = new LAFPreferencesPanel(_plugin, _lafRegister);
122:                }
123:                return _myPanel;
124:            }
125:
126:            /**
127:             * User has pressed OK or Apply in the dialog so save data from
128:             * panel.
129:             */
130:            public void applyChanges() {
131:                _myPanel.applyChanges();
132:            }
133:
134:            /**
135:             * Return the title for this panel.
136:             *
137:             * @return  the title for this panel.
138:             */
139:            public String getTitle() {
140:                return LAFPreferencesPanel.LAFPreferencesPanelI18n.TAB_TITLE;
141:            }
142:
143:            /**
144:             * Return the hint for this panel.
145:             *
146:             * @return  the hint for this panel.
147:             */
148:            public String getHint() {
149:                return LAFPreferencesPanel.LAFPreferencesPanelI18n.TAB_HINT;
150:            }
151:
152:            /**
153:             * "Change L&F" panel to be displayed in the preferences dialog.
154:             */
155:            private static final class LAFPreferencesPanel extends JPanel {
156:                /**
157:                 * This interface defines locale specific strings. This should be
158:                 * replaced with a property file.
159:                 */
160:                interface LAFPreferencesPanelI18n {
161:                    // i18n[laf.lookAndFeel=Look and Feel:]
162:                    String LOOK_AND_FEEL = s_stringMgr
163:                            .getString("laf.lookAndFeel");
164:                    // i18n[laf.lafWarning=Note: Controls may not be drawn correctly after changes in this panel until the application is restarted.]
165:                    String LAF_WARNING = s_stringMgr
166:                            .getString("laf.lafWarning");
167:                    // i18n[laf.lf=L & F]
168:                    String TAB_TITLE = s_stringMgr.getString("laf.lf");
169:                    // i18n[laf.settings=Look and Feel settings]
170:                    String TAB_HINT = s_stringMgr.getString("laf.settings");
171:                    // i18n[laf.jars=L & F jars:]
172:                    String LAF_LOC = s_stringMgr.getString("laf.jars");
173:                    // i18n[laf.lafPerformanceWarning=Also note: Some Look and Feels may cause performance problems.
174:                    // If you think your selected Look and Feel slows down SQuirreL switch to a Metal or Plastic Look and Feel.]
175:                    String LAF_PERFROMANCE_WARNING = s_stringMgr
176:                            .getString("laf.lafPerformanceWarning");
177:                }
178:
179:                private LookAndFeelComboBox _lafCmb = new LookAndFeelComboBox();
180:                private JCheckBox _allowSetBorder = new JCheckBox(s_stringMgr
181:                        .getString("laf.allowsetborder"));
182:
183:                private LAFPlugin _plugin;
184:                private LAFRegister _lafRegister;
185:
186:                private LAFPreferences _prefs;
187:
188:                /** Listener on the Look and Feel combo box. */
189:                private LookAndFeelComboListener _lafComboListener;
190:
191:                /**
192:                 * Component for extra config for the current Look and Feel. This
193:                 * will be <TT>null</TT> if the Look and Feel doesn't require extra
194:                 * configuration information.
195:                 */
196:                private BaseLAFPreferencesPanelComponent _curLAFConfigComp;
197:
198:                private JPanel _lafPnl;
199:
200:                LAFPreferencesPanel(LAFPlugin plugin, LAFRegister lafRegister) {
201:                    super (new GridBagLayout());
202:                    _plugin = plugin;
203:                    _lafRegister = lafRegister;
204:                    _prefs = _plugin.getLAFPreferences();
205:                    createUserInterface();
206:                }
207:
208:                public void addNotify() {
209:                    super .addNotify();
210:                    _lafComboListener = new LookAndFeelComboListener();
211:                    _lafCmb.addActionListener(_lafComboListener);
212:                }
213:
214:                public void removeNotify() {
215:                    if (_lafComboListener != null) {
216:                        _lafCmb.removeActionListener(_lafComboListener);
217:                        _lafComboListener = null;
218:                    }
219:                    super .removeNotify();
220:                }
221:
222:                void loadData() {
223:                    final String selLafClassName = _prefs
224:                            .getLookAndFeelClassName();
225:                    _allowSetBorder.setSelected(_prefs.getCanLAFSetBorder());
226:                    _lafCmb.setSelectedLookAndFeelClassName(selLafClassName);
227:
228:                    updateLookAndFeelConfigControl();
229:                }
230:
231:                void applyChanges() {
232:                    _prefs.setCanLAFSetBorder(_allowSetBorder.isSelected());
233:                    _prefs.setLookAndFeelClassName(_lafCmb
234:                            .getSelectedLookAndFeel().getClassName());
235:
236:                    _lafRegister.applyPreferences();
237:
238:                    boolean forceChange = false;
239:                    if (_curLAFConfigComp != null) {
240:                        forceChange = _curLAFConfigComp.applyChanges();
241:                    }
242:
243:                    try {
244:                        _lafRegister.setLookAndFeel(forceChange);
245:                    } catch (Exception ex) {
246:                        s_log.error("Error setting Look and Feel", ex);
247:                    }
248:                }
249:
250:                private void createUserInterface() {
251:                    final GridBagConstraints gbc = new GridBagConstraints();
252:                    gbc.anchor = GridBagConstraints.WEST;
253:                    gbc.fill = GridBagConstraints.HORIZONTAL;
254:                    gbc.insets = new Insets(4, 4, 4, 4);
255:
256:                    gbc.gridy = 0;
257:                    gbc.gridx = 0;
258:                    add(createSettingsPanel(), gbc);
259:
260:                    ++gbc.gridy;
261:                    add(createLookAndFeelPanel(), gbc);
262:
263:                    ++gbc.gridy;
264:                    gbc.gridx = 0;
265:                    gbc.gridwidth = GridBagConstraints.REMAINDER;
266:                    add(new MultipleLineLabel(
267:                            LAFPreferencesPanelI18n.LAF_WARNING), gbc);
268:
269:                    ++gbc.gridy;
270:                    gbc.gridx = 0;
271:                    gbc.gridwidth = GridBagConstraints.REMAINDER;
272:                    add(new MultipleLineLabel(
273:                            LAFPreferencesPanelI18n.LAF_PERFROMANCE_WARNING),
274:                            gbc);
275:                }
276:
277:                private JPanel createLookAndFeelPanel() {
278:                    _lafPnl = new JPanel(new GridBagLayout());
279:                    // i18n[laf.broderLaf=Look and Feel]
280:                    _lafPnl.setBorder(BorderFactory
281:                            .createTitledBorder(s_stringMgr
282:                                    .getString("laf.broderLaf")));
283:
284:                    final GridBagConstraints gbc = new GridBagConstraints();
285:                    gbc.weightx = 1;
286:                    gbc.fill = GridBagConstraints.HORIZONTAL;
287:                    gbc.insets = new Insets(4, 4, 4, 4);
288:                    gbc.anchor = GridBagConstraints.WEST;
289:
290:                    gbc.gridx = 0;
291:                    gbc.gridy = 0;
292:                    _lafPnl.add(new JLabel(
293:                            LAFPreferencesPanelI18n.LOOK_AND_FEEL,
294:                            SwingConstants.RIGHT), gbc);
295:
296:                    ++gbc.gridx;
297:                    _lafPnl.add(_lafCmb, gbc);
298:
299:                    gbc.gridx = 0;
300:                    ++gbc.gridy;
301:                    _lafPnl.add(new JLabel(LAFPreferencesPanelI18n.LAF_LOC,
302:                            SwingConstants.RIGHT), gbc);
303:
304:                    ++gbc.gridx;
305:                    _lafPnl.add(new OutputLabel(_plugin.getLookAndFeelFolder()
306:                            .getAbsolutePath()), gbc);
307:
308:                    return _lafPnl;
309:                }
310:
311:                private JPanel createSettingsPanel() {
312:                    JPanel pnl = new JPanel(new GridBagLayout());
313:                    pnl.setBorder(BorderFactory.createTitledBorder(s_stringMgr
314:                            .getString("laf.general")));
315:
316:                    final GridBagConstraints gbc = new GridBagConstraints();
317:                    gbc.weightx = 1;
318:                    gbc.fill = GridBagConstraints.HORIZONTAL;
319:                    gbc.insets = new Insets(4, 4, 4, 4);
320:                    gbc.anchor = GridBagConstraints.WEST;
321:
322:                    gbc.gridx = 0;
323:                    gbc.gridy = 0;
324:                    pnl.add(_allowSetBorder, gbc);
325:
326:                    return pnl;
327:                }
328:
329:                private void updateLookAndFeelConfigControl() {
330:                    if (_curLAFConfigComp != null) {
331:                        _lafPnl.remove(_curLAFConfigComp);
332:                        _curLAFConfigComp = null;
333:                    }
334:
335:                    UIManager.LookAndFeelInfo lafInfo = _lafCmb
336:                            .getSelectedLookAndFeel();
337:                    if (lafInfo != null) {
338:                        final String selLafClassName = lafInfo.getClassName();
339:                        if (selLafClassName != null) {
340:                            ILookAndFeelController ctrl = _lafRegister
341:                                    .getLookAndFeelController(selLafClassName);
342:                            if (ctrl != null) {
343:                                _curLAFConfigComp = ctrl
344:                                        .getPreferencesComponent();
345:                                if (_curLAFConfigComp != null) {
346:                                    _curLAFConfigComp.loadPreferencesPanel();
347:                                    final GridBagConstraints gbc = new GridBagConstraints();
348:                                    gbc.fill = GridBagConstraints.HORIZONTAL;
349:                                    gbc.insets = new Insets(4, 4, 4, 4);
350:                                    gbc.gridx = 0;
351:                                    gbc.gridy = GridBagConstraints.RELATIVE;
352:                                    gbc.gridwidth = GridBagConstraints.REMAINDER;
353:                                    _lafPnl.add(_curLAFConfigComp, gbc);
354:                                }
355:                            } else {
356:                                s_log
357:                                        .debug("No ILookAndFeelController found for: "
358:                                                + selLafClassName);
359:                            }
360:                        }
361:                    } else {
362:                        s_log.debug("Selected Look and Feel class is null");
363:                    }
364:                    validate();
365:                }
366:
367:                private class LookAndFeelComboListener implements 
368:                        ActionListener {
369:                    public void actionPerformed(ActionEvent evt) {
370:                        LAFPreferencesPanel.this
371:                                .updateLookAndFeelConfigControl();
372:                    }
373:                }
374:
375:            }
376:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.