Source Code Cross Referenced for ConfigurableComboBox.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.HashMap;
006:        import java.util.Hashtable;
007:        import java.util.StringTokenizer;
008:        import java.util.MissingResourceException;
009:        import javax.swing.Action;
010:        import java.awt.event.*;
011:
012:        /**
013:         * This is a JComboBox which implements the ConfigurableUI interface, and
014:         * therefore may be dynamically created using a VariableBundle and key,
015:         * and updated using an array of Actions.
016:         */
017:
018:        public class ConfigurableComboBox extends JComboBox implements 
019:                ConfigurableUI {
020:
021:            // the latest commands list.  i'm storing this for now because i 
022:            // can't do a JButton.removeActionListeners().
023:
024:            protected HashMap selectionMap = new HashMap();
025:
026:            protected Hashtable commands = new Hashtable();
027:
028:            String mKey = null;
029:
030:            int minWidth = -1;
031:            int minHeight = -1;
032:
033:            public ConfigurableComboBox() {
034:                super ();
035:            }
036:
037:            /**
038:             * This creates a new ConfigurableComboBox using the buttonID as the
039:             * configuration key, and vars as the source for the values of all the
040:             * properties.
041:             *
042:             * If buttonID doesn't exist in vars, then this returns an empty 
043:             * ComboBox.
044:             */
045:            public ConfigurableComboBox(String buttonID, VariableBundle vars) {
046:                super ();
047:
048:                configureComponent(buttonID, vars);
049:            }
050:
051:            /**
052:             * This configures the ComboBox using the given buttonID and 
053:             * VariableBundle.
054:             *
055:             * As defined in interface net.suberic.util.gui.ConfigurableUI.
056:             */
057:            public void configureComponent(String key, VariableBundle vars) {
058:                this .setRenderer(new ConfigurableComboRenderer());
059:
060:                mKey = key;
061:
062:                StringTokenizer iKeys = null;
063:                try {
064:                    iKeys = new StringTokenizer(vars.getProperty(key), ":");
065:                } catch (MissingResourceException mre) {
066:                    mre.printStackTrace();
067:                    try {
068:                        System.err.println(vars
069:                                .getProperty("error.NoSuchResource")
070:                                + " " + mre.getKey());
071:                    } catch (MissingResourceException mretwo) {
072:                        System.err.println("Unable to load resource "
073:                                + mre.getKey());
074:                        return;
075:                    }
076:                    return;
077:                }
078:                String currentToken;
079:
080:                while (iKeys.hasMoreTokens()) {
081:                    currentToken = iKeys.nextToken();
082:                    Object i = createComboBoxItem(key + "." + currentToken,
083:                            vars);
084:                    this .addItem(i);
085:                }
086:
087:                this .addItemListener(new ItemListener() {
088:                    public void itemStateChanged(ItemEvent e) {
089:                        if (e.getStateChange() == ItemEvent.SELECTED) {
090:                            Object selectedItem = e.getItem();
091:                            String cmd = (String) selectionMap
092:                                    .get(selectedItem);
093:                            if (cmd != null) {
094:                                Action action = getAction(cmd);
095:                                if (action != null) {
096:                                    action.actionPerformed(new ActionEvent(e
097:                                            .getSource(), e.getID(), cmd));
098:                                }
099:                            }
100:                        }
101:                    }
102:                });
103:
104:                this .setMaximumSize(this .getPreferredSize());
105:
106:                String toolTip = vars.getProperty(key + ".ToolTip", "");
107:                if (toolTip != "") {
108:                    setToolTipText(toolTip);
109:                }
110:            }
111:
112:            /**
113:             * And this actually creates the menu items themselves.
114:             */
115:            protected Object createComboBoxItem(String buttonID,
116:                    VariableBundle vars) {
117:
118:                ImageIcon returnValue = null;
119:
120:                IconManager iconManager = IconManager.getIconManager(vars,
121:                        "IconManager._default");
122:                ImageIcon icon = iconManager.getIcon(vars.getProperty(buttonID
123:                        + ".Image"));
124:                if (icon != null) {
125:
126:                    if (minWidth < 0) {
127:                        minWidth = icon.getIconWidth();
128:                    } else {
129:                        minWidth = java.lang.Math.min(minWidth, icon
130:                                .getIconWidth());
131:                    }
132:
133:                    if (minHeight < 0) {
134:                        minHeight = icon.getIconHeight();
135:                    } else {
136:                        minHeight = java.lang.Math.min(minHeight, icon
137:                                .getIconHeight());
138:                    }
139:
140:                    //returnValue.setIcon(icon);
141:                    returnValue = icon;
142:                }
143:
144:                String cmd = vars.getProperty(buttonID + ".Action", buttonID);
145:
146:                selectionMap.put(returnValue, cmd);
147:
148:                return returnValue;
149:            }
150:
151:            /**
152:             * As defined in net.suberic.util.gui.ConfigurableUI
153:             */
154:            public void setActive(javax.swing.Action[] newActions) {
155:                Hashtable tmpHash = new Hashtable();
156:                if (newActions != null && newActions.length > 0) {
157:                    for (int i = 0; i < newActions.length; i++) {
158:                        String cmdName = (String) newActions[i]
159:                                .getValue(Action.NAME);
160:                        tmpHash.put(cmdName, newActions[i]);
161:                    }
162:                }
163:                setActive(tmpHash);
164:            }
165:
166:            /**
167:             * As defined in net.suberic.util.gui.ConfigurableUI
168:             */
169:            public void setActive(Hashtable newCommands) {
170:                commands = newCommands;
171:            }
172:
173:            /**
174:             * This gets an action from the supported commands.  If there is no
175:             * supported action, it returns null
176:             */
177:
178:            public Action getAction(String command) {
179:                return (Action) commands.get(command);
180:            }
181:
182:            class ConfigurableComboRenderer extends JLabel implements 
183:                    ListCellRenderer {
184:
185:                public ConfigurableComboRenderer() {
186:                    setOpaque(true);
187:                    setHorizontalAlignment(CENTER);
188:                    setVerticalAlignment(CENTER);
189:                }
190:
191:                public java.awt.Component getListCellRendererComponent(
192:                        JList list, Object value, int index,
193:                        boolean isSelected, boolean cellHasFocus) {
194:                    if (isSelected) {
195:                        setBackground(list.getSelectionBackground());
196:                        setForeground(list.getSelectionForeground());
197:                    } else {
198:                        setBackground(list.getBackground());
199:                        setForeground(list.getForeground());
200:                    }
201:
202:                    ImageIcon icon = (ImageIcon) value;
203:                    //setText(icon.getDescription());
204:                    setIcon(icon);
205:                    return this;
206:                }
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.