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


001:        package net.xoetrope.xui.helper;
002:
003:        import java.awt.Component;
004:        import java.awt.Container;
005:
006:        import net.xoetrope.xui.XPage;
007:        import net.xoetrope.xui.style.XStyleFactory;
008:
009:        /**
010:         * Extends XStyleFactory by adding a caption component whenever a
011:         * new component is added. This is intended for use with components such as
012:         * TextFields, Choice and so on that normally have an associated label or caption
013:         * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003<br>
014:         * License:      see license.txt
015:         * @version $Revision: 1.18 $
016:         */
017:        public class BuddyHelper {
018:            private XStyleFactory styleFactory;
019:            private boolean hasSuffix = false;
020:
021:            /**
022:             * Constructs a new BuddyHelper.
023:             * @param sf the XStyleFactory used to create the new components.
024:             */
025:            public BuddyHelper(XStyleFactory sf) {
026:                styleFactory = sf;
027:            }
028:
029:            /**
030:             * Pass the addNamedComponent call to the XStyleFactory base Class
031:             * @param type The type of object being constructed
032:             * @param x1 The x coordinate of the new label component
033:             * @param x2 The x coordinate of the new primary component
034:             * @param y The y coordinate of the new component
035:             * @param w The total width of the new components
036:             * @param h The height of the new component
037:             * @param caption The text of the associated label
038:             * @param txt The text/content of the new component
039:             * @param style The name of the style to apply
040:             */
041:            public Component addComponent(String type, int x1, int x2, int y,
042:                    int w, int h, String caption, String txt, String style) {
043:                styleFactory.addComponent(XPage.LABEL, x1, y, x2 - x1 - 2, h,
044:                        caption, style);
045:                return styleFactory.addComponent(type, x2, y, w - (x2 - x1), h,
046:                        txt, style);
047:            }
048:
049:            /**
050:             * Pass the addNamedComponent call to the XStyleFactory base Class
051:             * @param type The type of object being constructed
052:             * @param x1 The x coordinate of the new label component
053:             * @param x2 The x coordinate of the new primary component
054:             * @param x3 The x coordinate of the suffix label
055:             * @param y The y coordinate of the new component
056:             * @param w The total width of the new components
057:             * @param h The height of the new component
058:             * @param caption The text of the associated label
059:             * @param txt The text/content of the new component
060:             * @param style The name of the style to apply
061:             */
062:            public Component addComponent(String type, int x1, int x2, int x3,
063:                    int y, int w, int h, String caption, String txt,
064:                    String suffix, String style) {
065:                hasSuffix = true;
066:                styleFactory.addComponent(XPage.LABEL, x1, y, x2 - x1 - 2, h,
067:                        caption, style);
068:                Component c = styleFactory.addComponent(type, x2, y, x3 - x2
069:                        - 2, h, txt, style);
070:                styleFactory.addComponent(XPage.LABEL, x3, y, x1 + w - x3, h,
071:                        suffix, style);
072:                return c;
073:            }
074:
075:            /**
076:             * Pass the addNamedComponent call to the XStyleFactory base Class
077:             * @param type The type of object being constructed
078:             * @param x The x coordinate of the new component
079:             * @param y The y coordinate of the new component
080:             * @param w The total width of the new components
081:             * @param h The height of the new component
082:             * @param caption The text of the associated label
083:             * @param txt The text/content of the new component
084:             * @param style The name of the style to apply
085:             */
086:            public Component addComponent(String type, int x, int y, int w,
087:                    int h, String caption, String txt, String style) {
088:                styleFactory.addComponent(XPage.LABEL, x, y, w / 2 - 2, h,
089:                        caption, style);
090:                return styleFactory.addComponent(type, x + w / 2, y, w / 2, h,
091:                        txt, style);
092:            }
093:
094:            /**
095:             * Pass the addNamedComponent call to the XStyleFactory base Class
096:             * @param className The name of the class to be constructed
097:             * @param x The x coordinate of the new component
098:             * @param y The y coordinate of the new component
099:             * @param w The total width of the new components
100:             * @param h The height of the new component
101:             * @param caption The text of the associated label
102:             * @param style The name of the style to apply
103:             */
104:            public Component addComponent(String className, int x, int y,
105:                    int w, int h, String caption, String style) {
106:                styleFactory.addComponent(XPage.LABEL, x, y, w / 2 - 2, h,
107:                        caption, style);
108:                return styleFactory.addClass(className, x + w / 2, y, w / 2, h,
109:                        style);
110:            }
111:
112:            /**
113:             * Gets the associated buddy label. The buddy is assumed
114:             * @param comp the component for which the buddy label was added
115:             */
116:            public Component getBuddy(Component comp) {
117:                try {
118:                    Container cont = comp.getParent();
119:                    Component[] comps = cont.getComponents();
120:                    int numComps = comps.length;
121:                    for (int i = 1; i < numComps; i++) {
122:                        if (cont.getComponent(i) == comp)
123:                            return cont.getComponent(i - 1);
124:                    }
125:                } catch (Exception e) {
126:                }
127:
128:                return null;
129:            }
130:
131:            /**
132:             * Get a component following the referenced component. This method can be used
133:             * to retrieve the suffix of a component added using the addComponent method
134:             * for 3 components.
135:             * @param comp the main component
136:             * @param item the offset, normally 1
137:             * @return the suffix component
138:             */
139:            public Component getBuddySuffix(Component comp, int item) {
140:                try {
141:                    Container cont = comp.getParent();
142:                    Component[] comps = cont.getComponents();
143:                    int numComps = comps.length;
144:                    for (int i = 1; i < numComps; i++) {
145:                        if (cont.getComponent(i) == comp)
146:                            return cont.getComponent(i + item);
147:                    }
148:                } catch (Exception e) {
149:                }
150:
151:                return null;
152:            }
153:
154:            /**
155:             * Set the visible state for the component and its buddy
156:             * @param comp the component for which the buddy label was added
157:             * @param b true to show the component, false to hide
158:             */
159:            public void setVisible(Component comp, boolean b) {
160:                comp.setVisible(b);
161:                getBuddy(comp).setVisible(b);
162:                if (hasSuffix) {
163:                    getBuddySuffix(comp, 1).setVisible(b);
164:                }
165:            }
166:
167:            /**
168:             * Set the enabled state for the component and its buddy
169:             * @param comp the component for which the buddy label was added
170:             * @param b true to enable the component, false to disable
171:             */
172:            public void setEnabled(Component comp, boolean b) {
173:                comp.setEnabled(b);
174:                getBuddy(comp).setEnabled(b);
175:                if (hasSuffix) {
176:                    getBuddySuffix(comp, 1).setEnabled(b);
177:                }
178:            }
179:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.