Source Code Cross Referenced for XStyle.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.Color;
004:        import java.lang.Cloneable;
005:
006:        /**
007:         * A style for storing information about the look of a component.
008:         * Information such as font (face, size, bold, italic), color (fore, back).
009:         * <p>Copyright (c) Xoetrope Ltd., 1998-2003<br>
010:         * License:      see license.txt
011:         * $Revision: 1.4 $
012:         */
013:        public class XStyle implements  Cloneable {
014:            // Text and component styles
015:            public static final int FONT_FACE = 0;
016:            public static final int FONT_SIZE = 1;
017:            public static final int FONT_WEIGHT = 2;
018:            public static final int FONT_ITALIC = 3;
019:            public static final int COLOR_BACK = 4;
020:            public static final int COLOR_FORE = 5;
021:            private static final int NUM_DEFAULT_STYLES = 6;
022:
023:            Object values[] = new Object[NUM_DEFAULT_STYLES];
024:
025:            private static final Integer zero = new Integer(0);
026:            private Integer fontHashCode = zero;
027:
028:            /**
029:             * Create a new style object
030:             */
031:            public XStyle() {
032:            }
033:
034:            /**
035:             * Set the number of styles. The current data is copied to the new style array.
036:             * The number of styles can only be increased with this method so as to
037:             * prevent any loss of data.
038:             * @param num the number of new parameters
039:             */
040:            public void setNumStyles(int num) {
041:                // Do not permit shrinking of the style array
042:                if (num <= values.length)
043:                    return;
044:
045:                Object temp[] = new Object[NUM_DEFAULT_STYLES];
046:                System.arraycopy(values, 0, temp, 0, values.length);
047:                values = temp;
048:            }
049:
050:            /**
051:             * Get the number of styles managed by this style object
052:             * @return
053:             */
054:            public int getNumStyles() {
055:                return values.length;
056:            }
057:
058:            /**
059:             * Create a  copy of this component
060:             * @return the copy
061:             */
062:            public Object clone() {
063:                XStyle copy = new XStyle();
064:                copy.setNumStyles(values.length);
065:                for (int i = 0; i < values.length; i++)
066:                    copy.values[i] = values[i];
067:
068:                return copy;
069:            }
070:
071:            /**
072:             * Set a style element.
073:             * @param key The index of the element
074:             * @param value The Object value of the element
075:             */
076:            public void setStyle(int key, Object value) {
077:                if (value instanceof  String) {
078:                    String temp = value.toString();
079:                    switch (key) {
080:                    case COLOR_FORE:
081:                    case COLOR_BACK:
082:                        try {
083:                            int r = Integer.parseInt(temp.substring(0, 2), 16);
084:                            int g = Integer.parseInt(temp.substring(2, 4), 16);
085:                            int b = Integer.parseInt(temp.substring(4, 6), 16);
086:                            values[key] = new Color(r, g, b);
087:                        } catch (Exception e) {
088:                            values[key] = new Integer(temp);
089:                        }
090:                        break;
091:
092:                    case FONT_SIZE:
093:                    case FONT_WEIGHT:
094:                    case FONT_ITALIC:
095:                        values[key] = new Integer(temp);
096:                        break;
097:
098:                    default:
099:                        values[key] = value;
100:                        break;
101:                    }
102:                } else
103:                    values[key] = value;
104:            }
105:
106:            /**
107:             * Set a style element.
108:             * @param key The index of the element
109:             * @param value The int value of the element
110:             */
111:            public void setStyle(int key, int value) {
112:                values[key % XStyle.NUM_DEFAULT_STYLES] = new Integer(value);
113:            }
114:
115:            /**
116:             * Retrieve a style element as an int.
117:             * @param key The index of the element
118:             */
119:            public int getStyleAsInt(int key) {
120:                Object o = values[key % XStyle.NUM_DEFAULT_STYLES];
121:                if (o instanceof  Integer)
122:                    return ((Integer) o).intValue();
123:
124:                return 0;
125:            }
126:
127:            /**
128:             * Retrieve a style element as a String.
129:             * @param key The index of the element
130:             */
131:            public String getStyleAsString(int key) {
132:                Object o = values[key % XStyle.NUM_DEFAULT_STYLES];
133:                if (o == null)
134:                    return null;
135:
136:                return (o).toString();
137:            }
138:
139:            /**
140:             * Retrieve a style element as a Color.
141:             * @param key The index of the element
142:             */
143:            public Color getStyleAsColor(int key) {
144:                Object o = values[key];
145:                if (o instanceof  Color)
146:                    return (Color) o;
147:
148:                return null;
149:            }
150:
151:            /**
152:             * For applying a hierarchy of styles to a new XStyle.
153:             * Only apply the style if it's found.
154:             * @param newStyle the style to merge with the current object.
155:             */
156:            public void mergeStyle(XStyle newStyle) {
157:                if (newStyle == null)
158:                    return;
159:
160:                for (int i = 0; i < newStyle.values.length; i++) {
161:                    if (newStyle.values[i] != null)
162:                        values[i] = newStyle.values[i];
163:                }
164:            }
165:
166:            /**
167:             * Gets the font hashcode
168:             * @return the hashcode
169:             */
170:            Integer getFontHashcode() {
171:                return fontHashCode;
172:            }
173:
174:            /**
175:             * Sets the hashcode for the font
176:             * @param h the new hashcode for the font
177:             */
178:            void setFontHashcode(int h) {
179:                fontHashCode = new Integer(h);
180:            }
181:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.