Source Code Cross Referenced for ExtendedJLabel.java in  » Byte-Code » jclasslib » org » gjt » jclasslib » util » 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 » Byte Code » jclasslib » org.gjt.jclasslib.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:            This library is free software; you can redistribute it and/or
003:            modify it under the terms of the GNU General Public
004:            License as published by the Free Software Foundation; either
005:            version 2 of the license, or (at your option) any later version.
006:         */
007:
008:        package org.gjt.jclasslib.util;
009:
010:        import javax.swing.*;
011:        import java.awt.*;
012:
013:        /**
014:         A <tt>JLabel</tt> that can be underlined, implements <tt>Scrollable</tt>,
015:         may have a tooltip text equal to its text and exposes a few convenience methods
016:         for <tt>setText()</tt>.
017:        
018:         @author <a href="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
019:         @version $Revision: 1.3 $ $Date: 2003/08/18 07:47:20 $
020:         */
021:        public class ExtendedJLabel extends JLabel implements  Scrollable {
022:
023:            private boolean underlined = false;
024:            private boolean autoTooltip = false;
025:
026:            /**
027:                Constructor.
028:             */
029:            public ExtendedJLabel() {
030:            }
031:
032:            /**
033:                Constructor.
034:                @param text the label text.
035:             */
036:            public ExtendedJLabel(String text) {
037:                super (text);
038:            }
039:
040:            public Dimension getPreferredScrollableViewportSize() {
041:                return getSize();
042:            }
043:
044:            public int getScrollableBlockIncrement(Rectangle visibleRect,
045:                    int orientation, int direction) {
046:                return getWidth() / 10;
047:            }
048:
049:            public boolean getScrollableTracksViewportWidth() {
050:                return false;
051:            }
052:
053:            public boolean getScrollableTracksViewportHeight() {
054:                return false;
055:            }
056:
057:            public int getScrollableUnitIncrement(Rectangle visibleRect,
058:                    int orientation, int direction) {
059:                return 10;
060:            }
061:
062:            /**
063:                Check whether this label is underlined.
064:                @return underlined or not
065:             */
066:            public boolean isUnderlined() {
067:                return underlined;
068:            }
069:
070:            /**
071:                Set whether this label is underlined.
072:                @param underlined underlined or not
073:             */
074:            public void setUnderlined(boolean underlined) {
075:                this .underlined = underlined;
076:                repaint();
077:            }
078:
079:            /**
080:                Check whether the tooltip text is automatically equal
081:                to the text of this label or not.
082:                @return equal or not
083:             */
084:            public boolean getAutoTooltip() {
085:                return autoTooltip;
086:            }
087:
088:            /**
089:                Set whether the tooltip text is automatically equal
090:                to the text of this label or not.
091:                @param autoTooltip equal or not
092:             */
093:            public void setAutoTooltip(boolean autoTooltip) {
094:                this .autoTooltip = autoTooltip;
095:                setToolTipText(getText());
096:            }
097:
098:            public void setText(String text) {
099:                super .setText(text);
100:                if (autoTooltip) {
101:                    setToolTipText(text);
102:                }
103:            }
104:
105:            /**
106:                Convenience method for calling <tt>setText()</tt> with a <tt>short</tt>.
107:                @param number the <tt>short</tt>
108:             */
109:            public void setText(short number) {
110:                setText(String.valueOf(number));
111:            }
112:
113:            /**
114:                Convenience method for calling <tt>setText()</tt> with a <tt>int</tt>.
115:                @param number the <tt>int</tt>
116:             */
117:            public void setText(int number) {
118:                setText(String.valueOf(number));
119:            }
120:
121:            /**
122:                Convenience method for calling <tt>setText()</tt> with a <tt>double</tt>.
123:                @param number the <tt>double</tt>
124:             */
125:            public void setText(double number) {
126:                setText(String.valueOf(number));
127:            }
128:
129:            /**
130:                Convenience method for calling <tt>setText()</tt> with a <tt>float</tt>.
131:                @param number the <tt>float</tt>
132:             */
133:            public void setText(float number) {
134:                setText(String.valueOf(number));
135:            }
136:
137:            /**
138:                Convenience method for calling <tt>setText()</tt> with a <tt>long</tt>.
139:                @param number the <tt>long</tt>
140:             */
141:            public void setText(long number) {
142:                setText(String.valueOf(number));
143:            }
144:
145:            public void paint(Graphics g) {
146:                super .paint(g);
147:
148:                if (underlined) {
149:                    Insets i = getInsets();
150:                    FontMetrics fm = g.getFontMetrics();
151:
152:                    Rectangle textRect = new Rectangle();
153:                    Rectangle viewRect = new Rectangle(i.left, i.top,
154:                            getWidth() - (i.right + i.left), getHeight()
155:                                    - (i.bottom + i.top));
156:
157:                    SwingUtilities.layoutCompoundLabel(this , fm, getText(),
158:                            getIcon(), getVerticalAlignment(),
159:                            getHorizontalAlignment(),
160:                            getVerticalTextPosition(),
161:                            getHorizontalTextPosition(), viewRect,
162:                            new Rectangle(), textRect, getText() == null ? 0
163:                                    : ((Integer) UIManager
164:                                            .get("Button.textIconGap"))
165:                                            .intValue());
166:
167:                    int offset = 2;
168:                    if (UIManager.getLookAndFeel().isNativeLookAndFeel()
169:                            && System.getProperty("os.name").startsWith(
170:                                    "Windows")) {
171:                        offset = 1;
172:                    }
173:                    g.fillRect(textRect.x
174:                            + ((Integer) UIManager
175:                                    .get("Button.textShiftOffset")).intValue(),
176:                            textRect.y
177:                                    + fm.getAscent()
178:                                    + ((Integer) UIManager
179:                                            .get("Button.textShiftOffset"))
180:                                            .intValue() + offset,
181:                            textRect.width, 1);
182:                }
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.