Source Code Cross Referenced for ConfigurableToolbar.java in  » Mail-Clients » pooka » net » suberic » util » 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 » Mail Clients » pooka » net.suberic.util.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.suberic.util.gui;
002:
003:        import javax.swing.*;
004:        import net.suberic.util.VariableBundle;
005:        import java.util.Hashtable;
006:        import java.util.StringTokenizer;
007:        import java.util.MissingResourceException;
008:        import javax.swing.Action;
009:
010:        /**
011:         * This is a JToolbar which implements the ConfigurableUI interface, and
012:         * therefore may be dynamically created using a VariableBundle and key,
013:         * and updated using an array of Actions.
014:         */
015:
016:        public class ConfigurableToolbar extends JToolBar implements 
017:                ConfigurableUI {
018:
019:            // the latest commands list.  i'm storing this for now because i 
020:            // can't do a JButton.removeActionListeners().
021:
022:            private Hashtable commands = new Hashtable();
023:
024:            /**
025:             * This creates a new ConfigurableToolbar using the toolbarID as the
026:             * configuration key, and vars as the source forthe values of all the
027:             * properties.
028:             *
029:             * If toolbarID doesn't exist in vars, then this returns an empty 
030:             * Toolbar.
031:             */
032:
033:            public ConfigurableToolbar(String toolbarID, VariableBundle vars) {
034:                super ();
035:
036:                configureComponent(toolbarID, vars);
037:            }
038:
039:            /**
040:             * This configures the Toolbar using the given toolbarID and 
041:             * VariableBundle.
042:             *
043:             * As defined in interface net.suberic.util.gui.ConfigurableUI.
044:             */
045:
046:            public void configureComponent(String toolbarID, VariableBundle vars) {
047:                if ((toolbarID != null)
048:                        && (vars.getProperty(toolbarID, "") != "")) {
049:                    StringTokenizer tokens = new StringTokenizer(vars
050:                            .getProperty(toolbarID, ""), ":");
051:                    while (tokens.hasMoreTokens()) {
052:                        String nextToken = tokens.nextToken();
053:                        String nextID = toolbarID + "." + nextToken;
054:                        String nextClass = vars.getProperty(nextID + ".class",
055:                                "");
056:                        if (nextClass == "") {
057:                            JButton b = createToolButton(nextID, vars);
058:                            if (b != null) {
059:                                this .add(b);
060:                            }
061:                        } else {
062:                            try {
063:                                Class buttonClass = Class.forName(nextClass);
064:                                ConfigurableUI newUI = (ConfigurableUI) buttonClass
065:                                        .newInstance();
066:                                newUI.configureComponent(nextID, vars);
067:                                if (newUI instanceof  JComponent) {
068:                                    this .add((JComponent) newUI);
069:                                }
070:                            } catch (Exception e) {
071:                                e.printStackTrace();
072:                                // if we get any errors, don't create anything.
073:                            }
074:
075:                        }
076:                    }
077:                }
078:            }
079:
080:            protected JButton createToolButton(String key, VariableBundle vars) {
081:                JButton bi;
082:
083:                IconManager iconManager = IconManager.getIconManager(vars,
084:                        "IconManager._default");
085:
086:                try {
087:
088:                    ImageIcon icon = iconManager.getIcon(vars.getProperty(key
089:                            + ".Image"));
090:
091:                    bi = new JButton(icon);
092:
093:                    bi.setMargin(new java.awt.Insets(1, 1, 1, 1));
094:
095:                } catch (MissingResourceException mre) {
096:                    return null;
097:                }
098:
099:                try {
100:                    bi.setToolTipText(vars.getProperty(key + ".ToolTip"));
101:                } catch (MissingResourceException mre) {
102:                }
103:
104:                String cmd = vars.getProperty(key + ".Action", key);
105:
106:                bi.setActionCommand(cmd);
107:
108:                return bi;
109:            }
110:
111:            /**
112:             * This updates the Actions on the Toolbar.
113:             *
114:             * As defined in interface net.suberic.util.gui.ConfigurableUI.
115:             */
116:
117:            public void setActive(Hashtable newCommands) {
118:                clearListeners();
119:                commands = newCommands;
120:                for (int i = 0; i < this .getComponentCount(); i++) {
121:                    Object component = this .getComponentAtIndex(i);
122:                    if (component instanceof  ConfigurableUI) {
123:                        ((ConfigurableUI) component).setActive(newCommands);
124:                    } else if (component instanceof  JButton) {
125:                        JButton bi = (JButton) (component);
126:
127:                        Action a = getAction(bi.getActionCommand());
128:                        if (a != null) {
129:                            bi.addActionListener(a);
130:                            bi.setEnabled(true);
131:                        } else {
132:                            bi.setEnabled(false);
133:                        }
134:                    }
135:                }
136:            }
137:
138:            /**
139:             * This updates the Actions on the Toolbar.
140:             *
141:             * As defined in interface net.suberic.util.gui.ConfigurableUI.
142:             */
143:            public void setActive(Action[] newActions) {
144:                clearListeners();
145:                Hashtable tmpHash = new Hashtable();
146:                if (newActions != null && newActions.length > 0) {
147:                    for (int i = 0; i < newActions.length; i++) {
148:                        String cmdName = (String) newActions[i]
149:                                .getValue(Action.NAME);
150:                        tmpHash.put(cmdName, newActions[i]);
151:                    }
152:                }
153:                setActive(tmpHash);
154:            }
155:
156:            /**
157:             * This clears the current listeners.  I think this shouldn't be
158:             * necessary--I think that you can only have one listener at a time,
159:             * so this shouldn't really be necessary.  Still...
160:             */
161:            private void clearListeners() {
162:                for (int i = 0; i < this .getComponentCount(); i++) {
163:                    if ((this .getComponentAtIndex(i)) instanceof  JButton) {
164:                        JButton button = (JButton) (this .getComponentAtIndex(i));
165:                        Action a = getAction(button.getActionCommand());
166:                        if (a != null) {
167:                            button.removeActionListener(a);
168:                        }
169:                    }
170:
171:                }
172:            }
173:
174:            private Action getAction(String key) {
175:                try {
176:                    return (Action) commands.get(key);
177:                } catch (ClassCastException cce) {
178:                    return null;
179:                }
180:            }
181:
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.