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


001:        package net.suberic.util.gui.propedit;
002:
003:        import javax.swing.*;
004:        import java.util.Vector;
005:        import java.util.List;
006:        import net.suberic.util.VariableBundle;
007:
008:        /**
009:         * This is a Property Editor which displays a group of properties.
010:         * These properties should all be definte by a single property.
011:         *
012:         * An example:
013:         *
014:         * Configuration=foo:bar
015:         * Configuration.propertyType=Composite
016:         * Configuration.scoped=false
017:         * foo=zork
018:         * bar=frobozz
019:         *
020:         * Options:
021:         *
022:         * Configuration.scoped - shows that the properties listed are subproperties
023:         *   of both the property and the template.  So, in this example, if you 
024:         *   had Configuration.scoped, the properties edited would be 
025:         *   Configuration.foo and Configuration.bar
026:         * Configuration.scopeRoot - if the setting is scoped, then this is the
027:         *   root for the template's scope.  Useful when dealing with properties that
028:         *   can be reached from multiple points (i.e. if 
029:         *   Configuration.one.two.three=foo:bar also, then you could set the 
030:         *   scopeRoot to Configuration and use the already configured foo and bar.
031:         * Configuration.subProperty.addSubProperty - shows whether or not you
032:         *   should add the given subproperty to the edited property for this editor.
033:         *   Useful if you have a CompositeEditorPane that contains other 
034:         *   Composite or Tabbed EditorPanes.  If Configuration.foo is another
035:         *   CompositeEditorPane which in turn edits .frotz and .ozmoo, and 
036:         *   Configuration.foo.addSubProperty=true (the default), then 
037:         *   Configuration.foo.frotz and Configuration.foo.ozmoo will be edited.
038:         *   If Configuration.foo.addSubProperty=false, then Configuration.frotz
039:         *   and Configuration.ozmoo will be edited, using Configuration.foo.frotz
040:         *   and Configuration.foo.ozmoo as templates.  This is primarily useful
041:         *   when using MultiEditorPanes.
042:         *
043:         */
044:        public class CompositeEditorPane extends CompositeSwingPropertyEditor {
045:            boolean scoped;
046:
047:            /**
048:             * Creates a CompositeEditorPane.
049:             */
050:            public CompositeEditorPane() {
051:
052:            }
053:
054:            /**
055:             * Creates a CompositeEditorPane editing the given list.
056:             */
057:            public CompositeEditorPane(List properties, List templates,
058:                    PropertyEditorManager mgr) {
059:                configureEditor(properties, templates, mgr);
060:            }
061:
062:            /**
063:             * This configures this editor with the following values.
064:             *
065:             * @param propertyName The property to be edited.  
066:             * @param template The property that will define the layout of the 
067:             *                 editor.
068:             * @param manager The PropertyEditorManager that will manage the
069:             *                   changes.
070:             * @param isEnabled Whether or not this editor is enabled by default. 
071:             */
072:            public void configureEditor(String propertyName, String template,
073:                    PropertyEditorManager newManager, boolean isEnabled) {
074:                property = propertyName;
075:                manager = newManager;
076:                editorTemplate = template;
077:                enabled = isEnabled;
078:                originalValue = manager.getProperty(property, "");
079:
080:                this .setBorder(BorderFactory.createEtchedBorder());
081:
082:                debug = manager.getProperty("editors.debug", "false")
083:                        .equalsIgnoreCase("true");
084:
085:                if (debug) {
086:                    System.out.println("creating CompositeEditorPane for "
087:                            + property + " with template " + editorTemplate);
088:                }
089:
090:                scoped = manager.getProperty(template + ".scoped", "false")
091:                        .equalsIgnoreCase("true");
092:
093:                if (debug) {
094:                    System.out.println("manager.getProperty ("
095:                            + template
096:                            + ".scoped) = "
097:                            + manager
098:                                    .getProperty(template + ".scoped", "false")
099:                            + " = " + scoped);
100:                }
101:
102:                List properties = new Vector();
103:                List templates = new Vector();
104:
105:                if (scoped) {
106:                    if (debug) {
107:                        System.out.println("testing for template " + template);
108:                    }
109:                    String scopeRoot = manager.getProperty(template
110:                            + ".scopeRoot", template);
111:                    if (debug) {
112:                        System.out.println("scopeRoot is " + scopeRoot);
113:                    }
114:                    List templateNames = manager
115:                            .getPropertyAsList(template, "");
116:                    if (debug) {
117:                        System.out.println("templateNames = getProp("
118:                                + template + ") = "
119:                                + manager.getProperty(template, ""));
120:                    }
121:
122:                    for (int i = 0; i < templateNames.size(); i++) {
123:                        String propToEdit = null;
124:                        String currentSubProperty = (String) templateNames
125:                                .get(i);
126:                        if (manager.getProperty(
127:                                scopeRoot + "." + currentSubProperty
128:                                        + ".addSubProperty", "true")
129:                                .equalsIgnoreCase("false")) {
130:                            propToEdit = property;
131:                        } else {
132:                            propToEdit = property + "."
133:                                    + (String) templateNames.get(i);
134:                        }
135:                        String templateToEdit = scopeRoot + "."
136:                                + (String) templateNames.get(i);
137:                        properties.add(propToEdit);
138:                        templates.add(templateToEdit);
139:                        if (debug) {
140:                            System.out.println("adding " + propToEdit
141:                                    + ", template " + templateToEdit);
142:                        }
143:                    }
144:                } else {
145:                    if (debug) {
146:                        System.out
147:                                .println("creating prop list for Composite EP using "
148:                                        + property + ", " + template);
149:                    }
150:                    properties = manager.getPropertyAsList(property, "");
151:                    templates = manager.getPropertyAsList(template, "");
152:                }
153:
154:                addEditors(properties, templates);
155:            }
156:
157:            public void addEditors(List properties, List templates) {
158:                SwingPropertyEditor currentEditor;
159:
160:                editors = new Vector();
161:
162:                java.awt.GridBagConstraints constraints = new java.awt.GridBagConstraints();
163:                constraints.insets = new java.awt.Insets(1, 3, 0, 3);
164:
165:                java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
166:                JPanel contentPanel = new JPanel();
167:                contentPanel.setLayout(layout);
168:
169:                constraints.weightx = 1.0;
170:                constraints.fill = java.awt.GridBagConstraints.BOTH;
171:
172:                if (debug) {
173:                    System.out.println("creating editors for "
174:                            + properties.size() + " properties.");
175:                }
176:
177:                for (int i = 0; i < properties.size(); i++) {
178:                    currentEditor = (SwingPropertyEditor) manager.createEditor(
179:                            (String) properties.get(i), (String) templates
180:                                    .get(i));
181:                    currentEditor.setEnabled(enabled);
182:                    editors.add(currentEditor);
183:
184:                    if (currentEditor.valueComponent != null) {
185:                        if (currentEditor.labelComponent != null) {
186:                            layout.setConstraints(currentEditor.labelComponent,
187:                                    constraints);
188:                            contentPanel.add(currentEditor.labelComponent);
189:                        }
190:                        constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
191:                        layout.setConstraints(currentEditor.valueComponent,
192:                                constraints);
193:                        contentPanel.add(currentEditor.valueComponent);
194:                    } else {
195:                        constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
196:                        layout.setConstraints(currentEditor, constraints);
197:                        contentPanel.add(currentEditor);
198:                    }
199:
200:                    constraints.weightx = 0.0;
201:                    constraints.gridwidth = 1;
202:
203:                }
204:
205:                this .add(contentPanel);
206:                alignEditorSizes();
207:
208:                manager.registerPropertyEditor(property, this );
209:            }
210:
211:            /**
212:             * This configures this editor with the following values.
213:             *
214:             * @param propertyName The property to be edited.  
215:             * @param template The property that will define the layout of the 
216:             *                 editor.
217:             * @param manager The PropertyEditorManager that will manage the
218:             *                   changes.
219:             * @param isEnabled Whether or not this editor is enabled by default. 
220:             */
221:            public void configureEditor(List properties, List templates,
222:                    PropertyEditorManager newManager) {
223:                manager = newManager;
224:                enabled = true;
225:
226:                this .setBorder(BorderFactory.createEtchedBorder());
227:
228:                debug = manager.getProperty("editors.debug", "false")
229:                        .equalsIgnoreCase("true");
230:
231:                addEditors(properties, templates);
232:            }
233:
234:            /**
235:             * This should even out the various editors on the panel.
236:             */
237:            public void alignEditorSizes() {
238:                int labelWidth = 0;
239:                int valueWidth = 0;
240:                int totalWidth = 0;
241:                for (int i = 0; i < editors.size(); i++) {
242:                    labelWidth = Math.max(labelWidth,
243:                            ((SwingPropertyEditor) editors.get(i))
244:                                    .getMinimumLabelSize().width);
245:                    valueWidth = Math.max(valueWidth,
246:                            ((SwingPropertyEditor) editors.get(i))
247:                                    .getMinimumValueSize().width);
248:                    totalWidth = Math.max(totalWidth,
249:                            ((SwingPropertyEditor) editors.get(i))
250:                                    .getMinimumTotalSize().width);
251:                }
252:
253:                if (totalWidth > labelWidth + valueWidth) {
254:                    int difference = totalWidth - labelWidth - valueWidth;
255:                    labelWidth = labelWidth + (difference / 2);
256:                    valueWidth = totalWidth - labelWidth;
257:                }
258:
259:                for (int i = 0; i < editors.size(); i++) {
260:                    ((SwingPropertyEditor) editors.get(i)).setWidths(
261:                            labelWidth, valueWidth);
262:                }
263:
264:            }
265:
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.