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


001:        package net.xoetrope.awt;
002:
003:        import java.awt.Canvas;
004:        import java.awt.Graphics;
005:
006:        import net.xoetrope.xui.XAttributedComponent;
007:        import net.xoetrope.xui.XTextHolder;
008:        import net.xoetrope.xui.XTextRenderer;
009:        import java.awt.Dimension;
010:        import java.awt.Image;
011:
012:        /**
013:         * Draws text. The text may be wrapped over multiple lines. Double buffering is
014:         * switched off by default.
015:         * <p>Copyright (c) Xoetrope Ltd., 1998-2003<br>
016:         * License:      see license.txt
017:         * @version $Revision: 1.16 $
018:         */
019:        public class XLabel extends Canvas implements  XTextHolder,
020:                XAttributedComponent {
021:            protected String text;
022:            protected XTextRenderer renderer = new XTextRenderer();
023:            protected boolean doubleBuffered = false;
024:            protected Image bufferImage = null;
025:            protected int bufferWidth;
026:            protected int bufferHeight;
027:
028:            /**
029:             * Reset the text
030:             * @param str the new text
031:             */
032:            public void setText(String str) {
033:                text = str;
034:                repaint();
035:            }
036:
037:            /**
038:             * Update the component
039:             * @param g
040:             */
041:            public void update(Graphics g) {
042:                paint(g);
043:            }
044:
045:            /**
046:             * Repaint the component once it has been created
047:             */
048:            public void addNotify() {
049:                super .addNotify();
050:                repaint(0);
051:            }
052:
053:            /**
054:             * Render the text
055:             * @param g
056:             */
057:            public void paint(Graphics g) {
058:                if (doubleBuffered) {
059:                    // Check the buffersize with the current panelsize
060:                    // or initialises the image with the first paint
061:                    if (bufferWidth != getSize().width
062:                            || bufferHeight != getSize().height
063:                            || bufferImage == null)
064:                        resetBuffer();
065:
066:                    Graphics bufferGraphics = bufferImage.getGraphics();
067:                    // Clear the offscreen image
068:                    bufferGraphics.clearRect(0, 0, bufferWidth, bufferHeight);
069:
070:                    if (text != null)
071:                        renderer.paintText(this , bufferGraphics, text);
072:
073:                    // Copy offscreen image onto the onscreen image
074:                    g.drawImage(bufferImage, 0, 0, this );
075:
076:                    // Cleanup
077:                    bufferGraphics.dispose();
078:                    bufferGraphics = null;
079:                } else if (text != null)
080:                    renderer.paintText(this , g, text);
081:            }
082:
083:            /**
084:             * Gets the text.
085:             * @return the label text
086:             */
087:            public String getText() {
088:                return text;
089:            }
090:
091:            public int getAlignment() {
092:                return renderer.getAlignment();
093:            }
094:
095:            /**
096:             * Sets the alignment of the text.
097:             * @param b 1 to right align the text, 0 for left alignment and 2 for centered text
098:             */
099:            public void setAlignment(int align) {
100:                renderer.setAlignment(align);
101:            }
102:
103:            /**
104:             * Sets the transparency of the text.
105:             * @param b true to make text transparent
106:             */
107:            public void setTransparent(boolean b) {
108:                renderer.setTransparent(b);
109:            }
110:
111:            /**
112:             * Set one or more attributes of the component. Attributes include <br>
113:             * <OL>
114:             * <LI>align (left|right|center ) or</LI>
115:             * <LI>alignment  (left|right|center )</LI>
116:             * <LI>buffered (true|false) double buffering</LI>
117:             * </OL>
118:             * @param attribName the attribute name
119:             * @param attribValue the attribute value
120:             */
121:            public void setAttribute(String attribName, String attribValue) {
122:                String attribNameLwr = attribName.toLowerCase();
123:                String attribValueLwr = attribValue.toLowerCase();
124:                if ((attribNameLwr.compareTo("align") == 0)
125:                        || (attribNameLwr.compareTo("alignment") == 0)) {
126:                    if (attribValueLwr.compareTo("right") == 0)
127:                        setAlignment(XTextRenderer.RIGHT);
128:                    else if (attribValueLwr.compareTo("center") == 0)
129:                        setAlignment(XTextRenderer.CENTER);
130:                    else
131:                        setAlignment(XTextRenderer.LEFT);
132:                } else if (attribNameLwr.compareTo("buffered") == 0)
133:                    setDoubleBuffered(attribValueLwr.equals("true"));
134:                //    else if ( attribNameLwr.compareTo( "opaque" ) == 0 )
135:                //      this.setop
136:            }
137:
138:            /**
139:             * Gets the preferred size of this component.
140:             * @return a dimension object indicating this component's preferred size
141:             * @see #getMinimumSize
142:             * @see LayoutManager
143:             */
144:            public Dimension getPreferredSize() {
145:                return renderer.getPreferredSize(this , text);
146:            }
147:
148:            /**
149:             * Toggle use of double buffering when painting this component
150:             * @param buffer  true to double buffer
151:             */
152:            public void setDoubleBuffered(boolean buffer) {
153:                doubleBuffered = buffer;
154:            }
155:
156:            private void resetBuffer() {
157:                // always keep track of the image size
158:                Dimension size = getSize();
159:                bufferWidth = size.width;
160:                bufferHeight = size.height;
161:
162:                if (bufferImage != null) {
163:                    bufferImage.flush();
164:                    bufferImage = null;
165:                }
166:                System.gc();
167:
168:                // create the new image with the size of the panel
169:                bufferImage = createImage(bufferWidth, bufferHeight);
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.