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


001:        package com.xoetrope.awt;
002:
003:        import java.awt.Color;
004:        import java.awt.Component;
005:        import java.awt.Dimension;
006:        import java.awt.Font;
007:        import java.awt.FontMetrics;
008:        import java.awt.Graphics;
009:        import java.awt.Image;
010:        import java.awt.Point;
011:
012:        import com.xoetrope.event.XClickListener;
013:        import net.xoetrope.xui.XImageHolder;
014:        import net.xoetrope.xui.XTextHolder;
015:
016:        /**
017:         * A button with an associated image icon.
018:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
019:         * the GNU Public License (GPL), please see license.txt for more details. If
020:         * you make commercial use of this software you must purchase a commercial
021:         * license from Xoetrope.</p>
022:         * <p>$Revision: 1.2 $</p>
023:         */
024:        public class XImageButton extends Component implements  XImageHolder,
025:                XTextHolder {
026:            private XClickListener clickListener;
027:
028:            private Image toggleImage;
029:            private String caption;
030:
031:            /**
032:             * Constructor for a new XImageButton
033:             */
034:            public XImageButton() {
035:                clickListener = new XClickListener(this );
036:
037:                addMouseListener(clickListener);
038:                addMouseMotionListener(clickListener);
039:            }
040:
041:            /**
042:             * Renders the image
043:             * @param g Graphics g
044:             */
045:            public void paint(Graphics g) {
046:                Dimension d = getSize();
047:
048:                g.setColor(getBackground());
049:                g.fillRect(0, 0, d.width - 1, d.height - 1);
050:
051:                if (!clickListener.getIsSelected()
052:                        || !clickListener.getIsEntered())
053:                    super .paint(g);
054:                else {
055:                    if (toggleImage != null)
056:                        g.drawImage(toggleImage, 0, 0, getBackground(), this );
057:                    else
058:                        super .paint(g);
059:                }
060:
061:                if ((clickListener.getIsEntered()) && (toggleImage != null)) {
062:                    g.setColor(Color.lightGray);
063:                    g.drawRect(0, 0, d.width - 1, d.height - 1);
064:                }
065:
066:                if (caption != null) {
067:                    // Get the font size
068:                    Font f = getFont();
069:                    g.setFont(f);
070:                    FontMetrics fm = g.getFontMetrics(f);
071:
072:                    // Determine the position for centering the text.
073:                    int xLoc = (int) ((d.width - fm.stringWidth(caption)) / 2.0);
074:                    int yLoc = fm.getAscent() + (d.height - fm.getAscent()) / 2;
075:
076:                    // Draw the text
077:                    g.setPaintMode();
078:                    g.setColor(getForeground());
079:                    g.drawString(caption, xLoc, yLoc);
080:
081:                }
082:            }
083:
084:            /**
085:             * Returns the location at which the mouse was clicked
086:             * @return The click location represented as a Point Object
087:             */
088:            public Point getClickLocation() {
089:                return clickListener.getClickLocation();
090:            }
091:
092:            /**
093:             * Sets the text for this button, if any. The text is centered over the image.
094:             * This method is also called by the localization methods.
095:             * @param newText the new text
096:             */
097:            public void setText(String newText) {
098:                caption = newText;
099:                repaint();
100:            }
101:
102:            /**
103:             * Gets the text for this button, if any.
104:             * @return the text/caption
105:             */
106:            public String getText() {
107:                return caption;
108:            }
109:
110:            /**
111:             * Sets the image to display
112:             * @param img the new image or null to clear.
113:             */
114:            public void setImage(Image img) {
115:                toggleImage = img;
116:                repaint();
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.