Source Code Cross Referenced for Label.java in  » Apache-Harmony-Java-SE » java-package » java » 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 » Apache Harmony Java SE » java package » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Dmitry A. Durnev
019:         * @version $Revision$
020:         */package java.awt;
021:
022:        import javax.accessibility.Accessible;
023:        import javax.accessibility.AccessibleContext;
024:        import javax.accessibility.AccessibleRole;
025:
026:        import org.apache.harmony.awt.internal.nls.Messages;
027:        import org.apache.harmony.awt.state.LabelState;
028:
029:        public class Label extends Component implements  Accessible {
030:
031:            private static final long serialVersionUID = 3094126758329070636L;
032:
033:            protected class AccessibleAWTLabel extends
034:                    Component.AccessibleAWTComponent {
035:
036:                private static final long serialVersionUID = -3568967560160480438L;
037:
038:                public AccessibleAWTLabel() {
039:                    // define default constructor explicitly just to make it public
040:                }
041:
042:                @Override
043:                public String getAccessibleName() {
044:                    return Label.this .getText();
045:                }
046:
047:                @Override
048:                public AccessibleRole getAccessibleRole() {
049:                    return AccessibleRole.LABEL;
050:                }
051:            }
052:
053:            class State extends Component.ComponentState implements  LabelState {
054:
055:                final Dimension textSize = new Dimension();
056:
057:                public String getText() {
058:                    return text;
059:                }
060:
061:                public Dimension getTextSize() {
062:                    return textSize;
063:                }
064:
065:                public void setTextSize(Dimension size) {
066:                    textSize.width = size.width;
067:                    textSize.height = size.height;
068:                }
069:
070:                public int getAlignment() {
071:                    return alignment;
072:                }
073:
074:                @Override
075:                public void calculate() {
076:                    toolkit.theme.calculateLabel(state);
077:                }
078:
079:            }
080:
081:            public static final int LEFT = 0;
082:
083:            public static final int CENTER = 1;
084:
085:            public static final int RIGHT = 2;
086:
087:            private String text = null;
088:
089:            private int alignment = LEFT;
090:
091:            Color savedBackground;
092:
093:            final State state = new State();
094:
095:            public Label(String text) throws HeadlessException {
096:                this (text, LEFT);
097:                toolkit.lockAWT();
098:                try {
099:                } finally {
100:                    toolkit.unlockAWT();
101:                }
102:            }
103:
104:            public Label() throws HeadlessException {
105:                this (new String(""), LEFT); //$NON-NLS-1$
106:                toolkit.lockAWT();
107:                try {
108:                } finally {
109:                    toolkit.unlockAWT();
110:                }
111:            }
112:
113:            public Label(String text, int alignment) throws HeadlessException {
114:                toolkit.lockAWT();
115:                try {
116:                    this .text = text;
117:                    setAlignmentImpl(alignment);
118:                } finally {
119:                    toolkit.unlockAWT();
120:                }
121:            }
122:
123:            @Override
124:            protected String paramString() {
125:                /* The format is based on 1.5 release behavior 
126:                 * which can be revealed by the following code:
127:                 * System.out.println(new Label());
128:                 */
129:
130:                toolkit.lockAWT();
131:                try {
132:                    return (super .paramString() + ",align=" + getAlignString() + //$NON-NLS-1$
133:                            ",text=" + text); //$NON-NLS-1$
134:                } finally {
135:                    toolkit.unlockAWT();
136:                }
137:            }
138:
139:            private String getAlignString() {
140:                String alignStr = "left"; //$NON-NLS-1$
141:                switch (alignment) {
142:                case CENTER:
143:                    alignStr = "center"; //$NON-NLS-1$
144:                    break;
145:                case RIGHT:
146:                    alignStr = "right"; //$NON-NLS-1$
147:                    break;
148:                }
149:                return alignStr;
150:            }
151:
152:            @Override
153:            public void addNotify() {
154:                toolkit.lockAWT();
155:                try {
156:                    super .addNotify();
157:                } finally {
158:                    toolkit.unlockAWT();
159:                }
160:            }
161:
162:            @Override
163:            public AccessibleContext getAccessibleContext() {
164:                toolkit.lockAWT();
165:                try {
166:                    return super .getAccessibleContext();
167:                } finally {
168:                    toolkit.unlockAWT();
169:                }
170:            }
171:
172:            public int getAlignment() {
173:                toolkit.lockAWT();
174:                try {
175:                    return alignment;
176:                } finally {
177:                    toolkit.unlockAWT();
178:                }
179:            }
180:
181:            public String getText() {
182:                toolkit.lockAWT();
183:                try {
184:                    return text;
185:                } finally {
186:                    toolkit.unlockAWT();
187:                }
188:            }
189:
190:            public void setAlignment(int alignment) {
191:                toolkit.lockAWT();
192:                try {
193:                    setAlignmentImpl(alignment);
194:                    doRepaint();
195:                } finally {
196:                    toolkit.unlockAWT();
197:                }
198:            }
199:
200:            private void setAlignmentImpl(int alignment) {
201:                if ((alignment < LEFT) || (alignment > RIGHT)) {
202:                    // awt.10F=improper alignment: {0}
203:                    throw new IllegalArgumentException(Messages.getString(
204:                            "awt.10F", //$NON-NLS-1$
205:                            alignment));
206:                }
207:                this .alignment = alignment;
208:            }
209:
210:            public void setText(String text) {
211:                toolkit.lockAWT();
212:                try {
213:                    this .text = text;
214:                    doRepaint();
215:                } finally {
216:                    toolkit.unlockAWT();
217:                }
218:            }
219:
220:            private void doRepaint() {
221:                if (isDisplayable()) {
222:                    invalidate();
223:                    if (isShowing()) {
224:                        repaint();
225:                    }
226:                }
227:            }
228:
229:            @Override
230:            void prepaint(Graphics g) {
231:                toolkit.theme.drawLabel(g, state);
232:            }
233:
234:            @Override
235:            boolean isPrepainter() {
236:                return true;
237:            }
238:
239:            @Override
240:            String autoName() {
241:                return ("label" + toolkit.autoNumber.nextLabel++); //$NON-NLS-1$
242:            }
243:
244:            @Override
245:            void validateImpl() {
246:                super .validateImpl();
247:                toolkit.theme.calculateLabel(state);
248:            }
249:
250:            @Override
251:            void setEnabledImpl(boolean value) {
252:                if (value != isEnabled()) { // to avoid dead loop in repaint()
253:                    super .setEnabledImpl(value);
254:                    repaint();
255:                }
256:            }
257:
258:            @Override
259:            ComponentBehavior createBehavior() {
260:                return new HWBehavior(this );
261:            }
262:
263:            @Override
264:            Dimension getDefaultMinimumSize() {
265:                if (getFont() == null) {
266:                    return new Dimension(0, 0);
267:                }
268:                return state.getDefaultMinimumSize();
269:            }
270:
271:            @Override
272:            void resetDefaultSize() {
273:                state.reset();
274:            }
275:
276:            @Override
277:            AccessibleContext createAccessibleContext() {
278:                return new AccessibleAWTLabel();
279:            }
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.