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


001:        package net.xoetrope.swing;
002:
003:        import java.io.Reader;
004:        import java.util.Enumeration;
005:        import java.util.StringTokenizer;
006:        import java.util.Vector;
007:
008:        import java.awt.Cursor;
009:        import java.awt.Point;
010:        import java.awt.Polygon;
011:        import java.awt.event.MouseEvent;
012:        import java.awt.event.MouseMotionListener;
013:
014:        import net.xoetrope.xml.XmlElement;
015:        import net.xoetrope.xml.XmlSource;
016:        import net.xoetrope.xui.XResourceManager;
017:
018:        /**
019:         * <p>A widget for displaying an image and associating hotspots at
020:         * coordinates specified in an external file</p>
021:         * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003<br>
022:         * License:      see license.txt
023:         * @version 1.0
024:         */
025:        public class XHotspotImage extends XImage implements 
026:                MouseMotionListener {
027:            protected static Cursor handCursor, defaultCursor;
028:            protected Vector hotspots;
029:            protected Vector names;
030:
031:            /**
032:             * Constructor. Sets cursors and creates the Vector which stores the hotspots.
033:             * Adds a new MouseMotionListener to the image
034:             */
035:            public XHotspotImage() {
036:                if (handCursor == null) {
037:                    handCursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
038:                    defaultCursor = Cursor
039:                            .getPredefinedCursor(Cursor.DEFAULT_CURSOR);
040:                }
041:
042:                hotspots = new Vector();
043:                addMouseMotionListener(this );
044:            }
045:
046:            /**
047:             * Get the name of the hotspot in element i of the names vector
048:             * @param i The index of the hotspot
049:             * @return The Name of the hotspot
050:             */
051:            public String getName(int i) {
052:                if (i != -1)
053:                    return (String) names.elementAt(i);
054:                return null;
055:            }
056:
057:            /**
058:             * Reads the hotspot information from the reader parameter and adds them to
059:             * the names and hotspots vectors.
060:             * @param r Reader of the file.
061:             */
062:            public void read(Reader r) {
063:                names = new Vector();
064:                hotspots = new Vector();
065:                XmlElement element = XmlSource.read(r);
066:                Enumeration e = element.getChildren().elements();
067:                while (e.hasMoreElements()) {
068:                    XmlElement ele = (XmlElement) e.nextElement();
069:                    Object name = ele.getAttribute("name");
070:                    if (name == null) {
071:                        names.addElement("");
072:                    } else {
073:                        names.addElement(ele.getAttribute("name").toString());
074:                    }
075:                    addHotspot(ele.getAttribute("coords").toString());
076:                }
077:            }
078:
079:            private int getNextTokenAsInt(StringTokenizer tokenizer) {
080:                String s = tokenizer.nextToken().trim();
081:                return Integer.parseInt(s);
082:            }
083:
084:            /**
085:             * Creates a polygon and iterates the coordinates in the pts paramater adding
086:             * each to the polygon. Adds the polygon to the hotspots Vector
087:             * @param pts String containing the points pairs of the polygon.
088:             */
089:            private void addHotspot(String pts) {
090:                Polygon p = new Polygon();
091:                StringTokenizer tokenizer = new StringTokenizer(pts, ",");
092:                int x0 = getNextTokenAsInt(tokenizer);
093:                int y0 = getNextTokenAsInt(tokenizer);
094:                p.addPoint(x0, y0);
095:
096:                int x, y;
097:                while (tokenizer.hasMoreTokens()) {
098:                    x = getNextTokenAsInt(tokenizer);
099:                    y = getNextTokenAsInt(tokenizer);
100:                    p.addPoint(x, y);
101:                }
102:
103:                // Close the polygon
104:                p.addPoint(x0, y0);
105:                hotspots.addElement(p);
106:            }
107:
108:            /**
109:             * Check the Point p to see if any of the polygons in the hotspots Vector contain
110:             * it. If so return the index of the Vector element.
111:             * @param p The Point which we are checking
112:             * @return The index of the polygon which contains the point or -1 if none of
113:             * the polygons contain the Point
114:             */
115:            public int checkHotspot(Point p) {
116:                int numPolygons = hotspots.size();
117:                for (int i = 0; i < numPolygons; i++) {
118:                    Polygon poly = (Polygon) hotspots.elementAt(i);
119:
120:                    if (poly.contains(p)) {
121:                        setCursor(handCursor);
122:                        return i;
123:                    }
124:                }
125:                setCursor(defaultCursor);
126:                return -1;
127:            }
128:
129:            /**
130:             * Call the checkHotSpot function to change the cursor
131:             * @param e MouseEvent
132:             */
133:            public void mouseMoved(MouseEvent e) {
134:                checkHotspot(e.getPoint());
135:            }
136:
137:            /**
138:             * Unused method.
139:             * @param e
140:             */
141:            public void mouseDragged(MouseEvent e) {
142:            }
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.