Source Code Cross Referenced for XLayoutHelper.java in  » XML-UI » XUI » net » xoetrope » xui » 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 » XUI » net.xoetrope.xui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.xoetrope.xui;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.FlowLayout;
005:        import java.awt.LayoutManager;
006:        import java.awt.Container;
007:        import java.awt.CardLayout;
008:        import java.awt.GridLayout;
009:        import java.awt.GridBagLayout;
010:        import java.util.Hashtable;
011:
012:        /**
013:         * A helper class for working with layout managers. This class provides mappings
014:         * between the names of layout styles and constraints and the corresponding
015:         * Java constants.
016:         * <p>Copyright (c) Xoetrope Ltd., 2002-2003</p>
017:         * <p>License: see license.txt</p>
018:         * $Revision: 1.8 $
019:         */
020:        public class XLayoutHelper {
021:            public static final int LEFT = 0;
022:            public static final int RIGHT = 1;
023:            public static final int TOP = 2;
024:            public static final int BOTTOM = 3;
025:
026:            /**
027:             * Sets a LayoutManager for the panel
028:             * @param cont the container whose layout manager is being set or null to set the parent panel's layout manager
029:             * @param type the layout manager as defined in the XLayoutHelper class
030:             * @param style the style containing the layout manager attributes
031:             */
032:            public static LayoutManager addLayout(Container cont, int type) {
033:                LayoutManager lm = null;
034:                switch (type) {
035:                case XPage.BORDER_LAYOUT:
036:                    lm = new BorderLayout();
037:                    break;
038:                case XPage.FLOW_LAYOUT:
039:                    lm = new FlowLayout();
040:                    break;
041:                case XPage.CARD_LAYOUT:
042:                    lm = new CardLayout();
043:                    break;
044:                case XPage.GRID_LAYOUT:
045:                    lm = new GridLayout();
046:                    break;
047:                case XPage.GRIDBAG_LAYOUT:
048:                    lm = new GridBagLayout();
049:                    break;
050:                case XPage.NULL_LAYOUT:
051:                default:
052:                    break;
053:                }
054:
055:                cont.setLayout(lm);
056:                return lm;
057:            }
058:
059:            /**
060:             * Sets a LayoutManager for the panel
061:             * @param cont the container whose layout manager is being set or null to set the parent panel's layout manager
062:             * @param type the layout manager as defined in the XLayoutHelper class
063:             * @param style the style containing the layout manager attributes
064:             */
065:            public static LayoutManager addLayout(Container cont, int type,
066:                    Hashtable attribs) {
067:                LayoutManager lm = addLayout(cont, type);
068:
069:                if (attribs != null) {
070:                    switch (type) {
071:                    case XPage.BORDER_LAYOUT:
072:                        ((BorderLayout) lm).setHgap(getIntAttrib(attribs,
073:                                "hgap"));
074:                        ((BorderLayout) lm).setVgap(getIntAttrib(attribs,
075:                                "vgap"));
076:                        break;
077:
078:                    case XPage.FLOW_LAYOUT:
079:                        ((FlowLayout) lm)
080:                                .setHgap(getIntAttrib(attribs, "hgap"));
081:                        ((FlowLayout) lm)
082:                                .setVgap(getIntAttrib(attribs, "vgap"));
083:                        int alignment = getIntAttrib(attribs, "alignment");
084:                        ((FlowLayout) lm).setAlignment(alignment);
085:                        break;
086:
087:                    case XPage.CARD_LAYOUT:
088:                        ((CardLayout) lm)
089:                                .setHgap(getIntAttrib(attribs, "hgap"));
090:                        ((CardLayout) lm)
091:                                .setVgap(getIntAttrib(attribs, "vgap"));
092:                        break;
093:
094:                    case XPage.GRID_LAYOUT:
095:                        ((GridLayout) lm)
096:                                .setHgap(getIntAttrib(attribs, "hgap"));
097:                        ((GridLayout) lm)
098:                                .setVgap(getIntAttrib(attribs, "vgap"));
099:                        int rows = getIntAttrib(attribs, "rows");
100:                        int cols = getIntAttrib(attribs, "cols");
101:                        if ((rows > 0) || (cols > 0)) {
102:                            if (rows == 0) {
103:                                ((GridLayout) lm).setColumns(cols);
104:                                ((GridLayout) lm).setRows(rows);
105:                            } else {
106:                                ((GridLayout) lm).setRows(rows);
107:                                ((GridLayout) lm).setColumns(cols);
108:                            }
109:                        }
110:                        break;
111:
112:                    case XPage.GRIDBAG_LAYOUT:
113:                        break;
114:
115:                    default:
116:                    case XPage.NULL_LAYOUT:
117:                        break;
118:                    }
119:                }
120:
121:                if (type == XPage.BOX_LAYOUT) {
122:                    String orientation = (attribs != null ? (String) attribs
123:                            .get("isHorz") : "");
124:                    boolean isHorz = orientation.equals("true");
125:                    lm = new GridLayout(isHorz ? 0 : 1, isHorz ? 1 : 0);
126:                    cont.setLayout(lm);
127:                }
128:
129:                return lm;
130:            }
131:
132:            /**
133:             * Gets a constraint object corresponding to a constraint name
134:             * @param name the constraint name
135:             * @return the constraint object
136:             */
137:            public int getAlignment(String name) {
138:                int alignment = FlowLayout.CENTER;
139:                name = name.toUpperCase();
140:                if (name == null)
141:                    return alignment;
142:                else if (name.compareTo("LEADING") == 0)
143:                    return 3;//FlowLayout.LEADING;
144:                else if (name.compareTo("CENTER") == 0)
145:                    return FlowLayout.CENTER;
146:                else if (name.compareTo("LEFT") == 0)
147:                    return FlowLayout.LEFT;
148:                else if (name.compareTo("RIGHT") == 0)
149:                    return FlowLayout.RIGHT;
150:                else if (name.compareTo("TRAILING") == 0)
151:                    return 4;//FlowLayout.TRAILING;
152:
153:                return alignment;
154:            }
155:
156:            /**
157:             * Get the layout type enumerated in XPage
158:             * @param ls the layout style
159:             * @return the type id
160:             */
161:            public static int getLayoutType(String ls) {
162:                ls = ls.toUpperCase();
163:                if (ls.compareTo("FLOW") == 0)
164:                    return XPage.FLOW_LAYOUT;
165:                else if (ls.compareTo("BORDER") == 0)
166:                    return XPage.BORDER_LAYOUT;
167:                else if (ls.compareTo("GRID") == 0)
168:                    return XPage.GRID_LAYOUT;
169:                else if (ls.compareTo("GRIDBAG") == 0)
170:                    return XPage.GRIDBAG_LAYOUT;
171:                else if (ls.compareTo("CARD") == 0)
172:                    return XPage.CARD_LAYOUT;
173:                else if (ls.compareTo("BOX") == 0)
174:                    return XPage.BOX_LAYOUT;
175:
176:                return XPage.NULL_LAYOUT;
177:            }
178:
179:            /**
180:             * Gets a constraint object corresponding to a constraint name
181:             * @param name the constraint name
182:             * @return the constraint object
183:             */
184:            public Object getConstraint(String name) {
185:                Object constraint = null;
186:                name = name.toUpperCase();
187:                if (name == null)
188:                    return constraint;
189:                else if (name.compareTo("WEST") == 0)
190:                    return BorderLayout.WEST;
191:                else if (name.compareTo("EAST") == 0)
192:                    return BorderLayout.EAST;
193:                else if (name.compareTo("NORTH") == 0)
194:                    return BorderLayout.NORTH;
195:                else if (name.compareTo("SOUTH") == 0)
196:                    return BorderLayout.SOUTH;
197:                else if (name.compareTo("CENTER") == 0)
198:                    return BorderLayout.CENTER;
199:                else if (name.compareTo("AFTER_LAST_LINE") == 0)
200:                    return "Last";//BorderLayout.AFTER_LAST_LINE;
201:                else if (name.compareTo("AFTER_LINE_ENDS") == 0)
202:                    return "After";//BorderLayout.AFTER_LINE_ENDS;
203:                else if (name.compareTo("BEFORE_FIRST_LINE") == 0)
204:                    return "First";//BorderLayout.BEFORE_FIRST_LINE;
205:                else if (name.compareTo("BEFORE_LINE_BEGINS") == 0)
206:                    return "Before";//BorderLayout.BEFORE_LINE_BEGINS;
207:
208:                return constraint;
209:            }
210:
211:            /**
212:             * Get an attribute as an int value
213:             * @param attribs the attribs hashtable
214:             * @param attrib the attribute key
215:             * @return the integer value
216:             */
217:            protected static int getIntAttrib(Hashtable attribs, String attrib) {
218:                try {
219:                    Object value = attribs.get(attrib);
220:                    if (value != null)
221:                        return new Integer((String) value).intValue();
222:                } catch (NumberFormatException ex) {
223:                }
224:                return 0;
225:            }
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.