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


001:        package net.xoetrope.xui.style;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.CardLayout;
005:        import java.awt.Component;
006:        import java.awt.Container;
007:        import java.awt.FlowLayout;
008:        import java.awt.GridLayout;
009:        import java.awt.LayoutManager;
010:
011:        import net.xoetrope.xui.XComponentFactory;
012:        import net.xoetrope.xui.XPage;
013:        import net.xoetrope.xui.XProjectManager;
014:        import java.util.Hashtable;
015:        import net.xoetrope.xui.XLayoutHelper;
016:
017:        /**
018:         * Extends the basic component factory by adding style information.
019:         * As the component are added the styles are applied.
020:         * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003<br>
021:         * License:      see license.txt
022:         * $Revision: 1.13 $
023:         */
024:        public class XStyleFactory extends XComponentFactory {
025:
026:            protected XStyleManager styleManager;
027:
028:            /**
029:             * Create the StyleFactory and initialise with an XStyleManager.
030:             * @param manager the XStyleManager to initialise with
031:             */
032:            public XStyleFactory(String packageName) {
033:                super (packageName);
034:                setup();
035:            }
036:
037:            /**
038:             * moved from the ctor so as to allow subclassed XStyleFactories to do the
039:             * initialisation in the getInstance().
040:             */
041:            protected void setup() {
042:                styleManager = XProjectManager.getStyleManager();
043:            }
044:
045:            /**
046:             * Pass the addNamedComponent call to the XStyleFactory base Class
047:             * @param type The type of object being constructed
048:             * @param constraint the layout constraint
049:             * @param txt The content to display
050:             * @param style The name of the style to apply
051:             * @deprecated since 1.0.4
052:             */
053:            public Component addComponent(String type, Object constraint,
054:                    String txt, String style) {
055:                Component c = super .addComponent(type, constraint, txt);
056:                applyStyle(c, style);
057:                return c;
058:            }
059:
060:            /**
061:             * Pass the addNamedComponent call to the XStyleFactory base Class
062:             * @param type The type of object being constructed
063:             * @param x The x coordinate of the new component
064:             * @param y The y coordinate of the new component
065:             * @param w The width of the new component
066:             * @param h The height of the new component
067:             * @param style The name of the style to apply
068:             */
069:            public Component addComponent(String type, int x, int y, int w,
070:                    int h, String txt, String style) {
071:                Component c = super .addComponent(type, x, y, w, h, txt);
072:                applyStyle(c, style);
073:                return c;
074:            }
075:
076:            /**
077:             * Overloading method with the same signature in XComponentFactory.
078:             * @param type The type of object being constructed
079:             * @param x The x coordinate of the new component
080:             * @param y The y coordinate of the new component
081:             * @param w The width of the new component
082:             * @param h The height of the new component
083:             * @param txt The text/caption of the component
084:             */
085:            public Component addComponent(String type, int x, int y, int w,
086:                    int h, String txt) {
087:                return addComponent(type, x, y, w, h, txt, null);
088:            }
089:
090:            /**
091:             * Pass the addComponent call to the XStyleFactory base Class
092:             * @param className The name of the class to be constructed
093:             * @param x The x coordinate of the new component
094:             * @param y The y coordinate of the new component
095:             * @param w The width of the new component
096:             * @param h The height of the new component
097:             * @param style The name of the style to apply
098:             */
099:            public Component addClass(String className, int x, int y, int w,
100:                    int h, String style) {
101:                Component c = super .addClass(className, x, y, w, h);
102:                applyStyle(c, style);
103:                return c;
104:            }
105:
106:            /**
107:             * Overloading the method with the same signature in XComponentFactory.
108:             * Applies a default style for the component.
109:             * @param className The name of the class to be constructed
110:             * @param x The x coordinate of the new component
111:             * @param y The y coordinate of the new component
112:             * @param w The width of the new component
113:             * @param h The height of the new component
114:             */
115:            public Component addClass(String className, int x, int y, int w,
116:                    int h) {
117:                Component c = super .addClass(className, x, y, w, h);
118:                applyStyle(c, (String) null);
119:                return c;
120:            }
121:
122:            /**
123:             * Pass the addNamedComponent call to the XStyleFactory base Class
124:             * @param type The type of object being constructed
125:             * @param x The x coordinate of the new component
126:             * @param y The y coordinate of the new component
127:             * @param w The width of the new component
128:             * @param h The height of the new component
129:             * @param style The name of the style to apply
130:             */
131:            public Component addComponent(String type, int x, int y, int w,
132:                    int h) {
133:                Component c = super .addComponent(type, x, y, w, h, null);
134:                applyStyle(c, (String) null);
135:                return c;
136:            }
137:
138:            /**
139:             * Sets a LayoutManager for the panel
140:             * @param cont the container whose layout manager is being set or null to set the parent panel's layout manager
141:             * @param type the layout manager as defined in the XLayoutHelper class
142:             * @param style the style containing the layout manager attributes
143:             */
144:            public LayoutManager addLayout(Container cont, int type,
145:                    Hashtable attribs) {
146:                if (cont == null)
147:                    cont = parentPanel;
148:                LayoutManager lm = layoutHelper.addLayout(cont, type, attribs);
149:                return lm;
150:            }
151:
152:            /**
153:             * Apply a style to a component, looking up the style name if necessary
154:             * @param c the component to style
155:             * @param style the style name
156:             * @param lookupComp true to lookup the style based on the component class
157:             */
158:            public void applyStyle(Component c, String style, boolean lookupComp) {
159:                boolean createStyle = true;
160:                if (style == null) {
161:                    lookupComp = true;
162:                    createStyle = false;
163:                    style = "";
164:                }
165:                if ((c != null) && (style != null)) {
166:                    String type = "";
167:                    if (lookupComp) {
168:                        type = c.getClass().getName();
169:                        int pos = type.lastIndexOf(".");
170:                        type = type.substring(pos + 1, type.length());
171:                    }
172:
173:                    XStyle xstyle = styleManager.getStyle(checkStyleName(style,
174:                            type, lookupComp), createStyle);
175:                    if (xstyle != null) {
176:                        c.setFont(styleManager.getFont(xstyle));
177:                        c.setBackground(xstyle
178:                                .getStyleAsColor(XStyle.COLOR_BACK));
179:                        c.setForeground(xstyle
180:                                .getStyleAsColor(XStyle.COLOR_FORE));
181:
182:                        if (c instanceof  XStyleComponent)
183:                            ((XStyleComponent) c).setStyle(style);
184:                    }
185:                }
186:            }
187:
188:            /**
189:             * Apply a style to a component. Set the font and foreground/background color.
190:             * @param c the component to style
191:             * @param style the style name
192:             */
193:            public void applyStyle(Component c, XStyle xstyle) {
194:                if ((c != null) && (xstyle != null)) {
195:                    c.setFont(styleManager.getFont(xstyle));
196:                    c.setBackground(xstyle.getStyleAsColor(XStyle.COLOR_BACK));
197:                    c.setForeground(xstyle.getStyleAsColor(XStyle.COLOR_FORE));
198:                }
199:            }
200:
201:            /**
202:             * Called after a new component is created. Append the style to the base and
203:             * then append the component classname with '/' delimiters.
204:             * @param c Component to apply the style to.
205:             * @param style the name of the style to apply.
206:             *
207:             */
208:            public void applyStyle(Component c, String style) {
209:                applyStyle(c, style, false);
210:            }
211:
212:            /**
213:             * Check that the style name is fully qualified with the 'base' name and
214:             * add the type name if needed.
215:             * @param style the style name
216:             * @param type the componnet type name
217:             * @param lookupComp append the style name to the type if true
218:             * @return the fully qualified style name
219:             */
220:            private String checkStyleName(String style, String type,
221:                    boolean lookupComp) {
222:                String retStyle = "";
223:                if (style != null)
224:                    retStyle = style;
225:
226:                if (lookupComp)
227:                    retStyle += type;
228:                return retStyle;
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.