Source Code Cross Referenced for Gui4jTableLayoutFactory.java in  » XML-UI » gui4j » org » gui4j » component » factory » 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 » XML UI » gui4j » org.gui4j.component.factory 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.gui4j.component.factory;
002:
003:        import java.util.ArrayList;
004:        import java.util.Arrays;
005:        import java.util.HashMap;
006:        import java.util.Iterator;
007:        import java.util.List;
008:        import java.util.Map;
009:        import java.util.StringTokenizer;
010:
011:        import org.dom4j.LElement;
012:
013:        import org.gui4j.component.Gui4jJComponent;
014:        import org.gui4j.component.Gui4jTableLayout;
015:        import org.gui4j.core.Gui4jComponentContainer;
016:        import org.gui4j.core.Gui4jComponentContainerManager;
017:        import org.gui4j.core.Gui4jQualifiedComponent;
018:        import org.gui4j.core.definition.Attribute;
019:        import org.gui4j.core.definition.AttributeTypeEnumeration;
020:        import org.gui4j.core.definition.AttributeTypeID;
021:        import org.gui4j.core.definition.AttributeTypeInteger;
022:        import org.gui4j.core.definition.AttributeTypeString;
023:        import org.gui4j.core.swing.TableLayoutConstants;
024:        import org.gui4j.core.swing.TableLayoutConstraints;
025:        import org.gui4j.exception.Gui4jUncheckedException;
026:        import org.gui4j.util.Filter;
027:
028:        /**
029:         * Syntax:<br>
030:         * &lt;tableLayout rows=$rowStr col=$colStr&gt;<br>
031:         *   &lt;placeTl row="0" col="0" hAlign="left" vAlign="top" id="xxx"/&gt;<br>
032:         * &lt;/tableLayout&gt;<br>
033:         * rowStr="p,f,m,100.5"<br>
034:         * colStr="preferred,fill,minimum,100.5"<br>
035:         * 
036:         */
037:        public final class Gui4jTableLayoutFactory extends
038:                Gui4jJComponentFactory {
039:            private static final String NAME = "tableLayout";
040:            private static final String PLACEMENT = "placeTl";
041:            private static final String ROWS = "rows";
042:            private static final String COLS = "cols";
043:            private static final String HSPACING = "hSpacing";
044:            private static final String VSPACING = "vSpacing";
045:            private static final String ROW = "row";
046:            private static final String COL = "col";
047:            private static final String WIDTH = "width";
048:            private static final String HEIGHT = "height";
049:            private static final String HALIGN = "hAlign";
050:            private static final String VALIGN = "vAlign";
051:            private static final String ID = "id";
052:
053:            private static final Map mHAlign;
054:            private static final Map mVAlign;
055:
056:            static {
057:                mHAlign = new HashMap();
058:                mVAlign = new HashMap();
059:                mHAlign.put("left", new Integer(TableLayoutConstants.LEFT));
060:                mHAlign.put("center", new Integer(TableLayoutConstants.CENTER));
061:                mHAlign.put("full", new Integer(TableLayoutConstants.FULL));
062:                mHAlign.put("right", new Integer(TableLayoutConstants.RIGHT));
063:                mVAlign.put("top", new Integer(TableLayoutConstants.TOP));
064:                mVAlign.put("center", new Integer(TableLayoutConstants.CENTER));
065:                mVAlign.put("full", new Integer(TableLayoutConstants.FULL));
066:                mVAlign.put("bottom", new Integer(TableLayoutConstants.BOTTOM));
067:            }
068:
069:            /* (non-Javadoc)
070:             * @see org.gui4j.component.factory.Gui4jJComponentFactory#defineGui4jJComponentBy(org.gui4j.core.Gui4jComponentContainer, java.lang.String, org.dom4j.LElement)
071:             */
072:            protected Gui4jJComponent defineGui4jJComponentBy(
073:                    Gui4jComponentContainer gui4jComponentContainer, String id,
074:                    LElement e) {
075:                String rowStr = gui4jComponentContainer.getAttrValueReplaceAll(
076:                        e, ROWS);
077:                String colStr = gui4jComponentContainer.getAttrValueReplaceAll(
078:                        e, COLS);
079:                double[][] size = new double[2][];
080:                size[0] = parseRowColStr(colStr, gui4jComponentContainer
081:                        .getConfigurationName(), Gui4jComponentContainerManager
082:                        .getLineNumber(e.attribute(COLS)));
083:                size[1] = parseRowColStr(rowStr, gui4jComponentContainer
084:                        .getConfigurationName(), Gui4jComponentContainerManager
085:                        .getLineNumber(e.attribute(ROWS)));
086:                Gui4jTableLayout gui4jTableLayout = new Gui4jTableLayout(
087:                        gui4jComponentContainer, size, id);
088:                gui4jTableLayout.definePropertySetter(HSPACING,
089:                        getGui4jAccessInstance(Integer.TYPE, gui4jTableLayout,
090:                                e, HSPACING));
091:                gui4jTableLayout.definePropertySetter(VSPACING,
092:                        getGui4jAccessInstance(Integer.TYPE, gui4jTableLayout,
093:                                e, VSPACING));
094:
095:                List children = e.elements();
096:                List errorList = new ArrayList();
097:                for (Iterator it = children.iterator(); it.hasNext();) {
098:                    try {
099:                        LElement child = (LElement) it.next();
100:                        gui4jComponentContainer.autoExtend(child);
101:                        int row = getIntValue(gui4jComponentContainer, child,
102:                                ROW);
103:                        int col = getIntValue(gui4jComponentContainer, child,
104:                                COL);
105:                        int width = getIntValue(gui4jComponentContainer, child,
106:                                WIDTH, 1);
107:                        int height = getIntValue(gui4jComponentContainer,
108:                                child, HEIGHT, 1);
109:
110:                        int hAlign = getMapValue(gui4jComponentContainer,
111:                                child, HALIGN, mHAlign,
112:                                TableLayoutConstants.FULL);
113:                        int vAlign = getMapValue(gui4jComponentContainer,
114:                                child, VALIGN, mVAlign,
115:                                TableLayoutConstants.FULL);
116:
117:                        String gui4jId = child.attributeValue(ID);
118:                        Gui4jQualifiedComponent gui4jQualifiedComponent;
119:                        if (gui4jId == null) {
120:                            if (child.elements().isEmpty()) {
121:                                Object[] args = { PLACEMENT };
122:                                throw new Gui4jUncheckedException.ResourceError(
123:                                        gui4jComponentContainer
124:                                                .getConfigurationName(),
125:                                        Gui4jComponentContainerManager
126:                                                .getLineNumber(child),
127:                                        RESOURCE_ERROR_element_must_contain_gui4jComponent,
128:                                        args);
129:                            }
130:                            LElement gui4jElement = (LElement) child.elements()
131:                                    .iterator().next();
132:                            gui4jQualifiedComponent = gui4jComponentContainer
133:                                    .extractGui4jComponent(gui4jElement);
134:                        } else {
135:                            gui4jQualifiedComponent = gui4jComponentContainer
136:                                    .getGui4jQualifiedComponent(gui4jId);
137:                        }
138:
139:                        gui4jTableLayout.addPlacement(
140:                                new TableLayoutConstraints(col, row, col
141:                                        + width - 1, row + height - 1, hAlign,
142:                                        vAlign), gui4jQualifiedComponent);
143:                    } catch (Throwable t) {
144:                        errorList.add(t);
145:                    }
146:                }
147:                checkErrorList(errorList);
148:                return gui4jTableLayout;
149:            }
150:
151:            private double[] parseRowColStr(String str,
152:                    String configurationName, int line) {
153:                StringTokenizer tokenizer = new StringTokenizer(str, ",");
154:                List values = new ArrayList();
155:                boolean ok = true;
156:                while (tokenizer.hasMoreTokens()) {
157:                    String token = tokenizer.nextToken().trim();
158:                    if ("preferred".equalsIgnoreCase(token)
159:                            || "p".equalsIgnoreCase(token)) {
160:                        values.add(new Double(TableLayoutConstants.PREFERRED));
161:                    } else if ("minimum".equalsIgnoreCase(token)
162:                            || "m".equalsIgnoreCase(token)) {
163:                        values.add(new Double(TableLayoutConstants.MINIMUM));
164:                    } else if ("fill".equalsIgnoreCase(token)
165:                            || "f".equalsIgnoreCase(token)) {
166:                        values.add(new Double(TableLayoutConstants.FILL));
167:                    } else if (token.length() > 0) {
168:                        try {
169:                            values.add(Double.valueOf(token));
170:                        } catch (Throwable t) {
171:                            ok = false;
172:                        }
173:                    }
174:                }
175:                double[] val = new double[values.size()];
176:                for (int i = 0; i < values.size(); i++) {
177:                    val[i] = ((Double) values.get(i)).doubleValue();
178:                }
179:                if (!ok) {
180:                    Object[] args = { str };
181:                    throw new Gui4jUncheckedException.ResourceError(
182:                            configurationName, line,
183:                            RESOURCE_ERROR_tableLayout_invalid_col_row_str,
184:                            args);
185:                }
186:                return val;
187:            }
188:
189:            public SubElement getSubElement(String elementName) {
190:                if (PLACEMENT.equals(elementName)) {
191:                    return SubElement.optional(SubElement.gui4jComponent());
192:                }
193:                if (NAME.equals(elementName)) {
194:                    SubElement place = SubElement.getInstance(PLACEMENT);
195:                    return SubElement.star(place);
196:                }
197:                return null;
198:            }
199:
200:            public void addInnerAttributes(String elementName, List list) {
201:                if (PLACEMENT.equals(elementName)) {
202:                    Attribute[] attributesSubElement = {
203:                            new Attribute(ROW, new AttributeTypeInteger(),
204:                                    REQUIRED, false),
205:                            new Attribute(COL, new AttributeTypeInteger(),
206:                                    REQUIRED, false),
207:                            new Attribute(WIDTH, new AttributeTypeInteger(),
208:                                    IMPLIED, false),
209:                            new Attribute(HEIGHT, new AttributeTypeInteger(),
210:                                    IMPLIED, false),
211:                            new Attribute(HALIGN, new AttributeTypeEnumeration(
212:                                    mHAlign), IMPLIED, false),
213:                            new Attribute(VALIGN, new AttributeTypeEnumeration(
214:                                    mVAlign), IMPLIED, false),
215:                            new Attribute(ID, new AttributeTypeID(), IMPLIED,
216:                                    false), };
217:                    list.addAll(Arrays.asList(attributesSubElement));
218:                }
219:            }
220:
221:            public void addToplevelAttributes(List attrList, Filter filter) {
222:                super .addToplevelAttributes(attrList, filter);
223:                if (filter == null
224:                        || filter.takeIt(Gui4jTableLayoutFactory.class)) {
225:                    attrList.add(new Attribute(ROWS, new AttributeTypeString(),
226:                            REQUIRED, false));
227:                    attrList.add(new Attribute(COLS, new AttributeTypeString(),
228:                            REQUIRED, false));
229:                    attrList.add(new Attribute(HSPACING,
230:                            new AttributeTypeInteger(), IMPLIED, false));
231:                    attrList.add(new Attribute(VSPACING,
232:                            new AttributeTypeInteger(), IMPLIED, false));
233:                }
234:            }
235:
236:            public String[] getInnerElements() {
237:                String[] elems = { PLACEMENT };
238:                return elems;
239:            }
240:
241:            /**
242:             * @see org.gui4j.core.Gui4jComponentFactory#getName()
243:             */
244:            public String getName() {
245:                return NAME;
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.