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


001:        /*
002:         * XSelectionZoom.java
003:         *
004:         * Created on 14 August 2007, 10:07
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package com.xoetrope.svg;
011:
012:        import com.kitfox.svg.SVGRoot;
013:        import com.kitfox.svg.animation.AnimationElement;
014:        import com.xoetrope.carousel.build.BuildProperties;
015:        import com.xoetrope.svg.XPointSystem;
016:        import com.xoetrope.svg.XSvgImageMap;
017:        import java.awt.BasicStroke;
018:        import java.awt.Color;
019:        import java.awt.Graphics;
020:        import java.awt.Graphics2D;
021:        import java.awt.Point;
022:        import java.awt.event.ComponentAdapter;
023:        import java.awt.event.ComponentEvent;
024:        import java.awt.event.KeyEvent;
025:        import java.awt.event.KeyListener;
026:        import java.awt.event.MouseEvent;
027:        import java.awt.event.MouseListener;
028:        import java.awt.event.MouseMotionListener;
029:        import java.awt.geom.Point2D;
030:        import java.awt.geom.Rectangle2D;
031:        import java.beans.PropertyChangeEvent;
032:        import java.beans.PropertyChangeListener;
033:        import java.text.DecimalFormat;
034:        import java.text.NumberFormat;
035:        import javax.swing.JComponent;
036:
037:        /**
038:         * 
039:         *
040:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
041:         * the GNU Public License (GPL), please see license.txt for more details. If
042:         * you make commercial use of this software you must purchase a commercial
043:         * license from Xoetrope.</p>
044:         * <p> $Revision: 1.2 $</p>
045:         */
046:        public class XSelectionZoom extends JComponent implements 
047:                MouseListener, MouseMotionListener {
048:            protected boolean dragged, firstZoom;
049:            protected XSvgImageMap imageMap;
050:            protected Point startPt, endPt;
051:            protected Rectangle2D.Double rect;
052:            protected XPointSystem pointSystem;
053:            protected NumberFormat formatter;
054:
055:            /** 
056:             * Creates a new instance of XZoomSelection 
057:             * @param iMap <CODE>XSvgImageMap</CODE>
058:             */
059:            public XSelectionZoom(XSvgImageMap iMap) {
060:                imageMap = iMap;
061:                formatter = new DecimalFormat(".00000");
062:                imageMap.addMouseListener(this );
063:                imageMap.addMouseMotionListener(this );
064:
065:                imageMap.getGlassPane().add(this );
066:                imageMap.addComponentListener(new ComponentAdapter() {
067:                    public void componentResized(ComponentEvent evt) {
068:                        setBounds(0, 0, imageMap.getWidth(), imageMap
069:                                .getHeight());
070:                        firstZoom = true;
071:                    }
072:                });
073:
074:                pointSystem = new XPointSystem(imageMap);
075:            }
076:
077:            /**
078:             * Displays the selection box which will be used to select the area to be zoomed.
079:             * @param e the passed <CODE>MouseEvent</CODE> instance.
080:             */
081:            public void mousePressed(MouseEvent e) {
082:                if ((e.getModifiers() & e.CTRL_MASK) != 0) {
083:                    startPt = e.getPoint();
084:                    setVisible(true);
085:                }
086:            }
087:
088:            /**
089:             * Zooms to the selected region of the image once the mouse is released
090:             * @param e the passed <CODE>MouseEvent</CODE> instance.
091:             */
092:            public void mouseReleased(MouseEvent e) {
093:                if (dragged) {
094:                    dragged = false;
095:
096:                    setVisible(false);
097:                    SVGRoot root = imageMap.getSvgDiagram().getRoot();
098:                    try {
099:                        Point2D p1 = pointSystem.glassPaneToSvg(rect.getX(),
100:                                rect.getY());
101:                        Point2D p2 = pointSystem.glassPaneToSvg(rect.getX()
102:                                + rect.getWidth(), rect.getY()
103:                                + rect.getHeight());
104:
105:                        double x = p1.getX();
106:                        double y = p1.getY();
107:                        double rectW = p2.getX() - p1.getX();
108:                        double rectH = p2.getY() - p1.getY();
109:
110:                        Point2D start = pointSystem.glassPaneToSvg(0, 0);
111:                        Point2D end = pointSystem.glassPaneToSvg(imageMap
112:                                .getWidth(), imageMap.getHeight());
113:
114:                        double totalWidth = end.getX() - start.getX();
115:                        double totalHeight = end.getY() - start.getY();
116:
117:                        double zoom;
118:                        if (rect.getWidth() > rect.getHeight())
119:                            zoom = totalWidth / rectW;
120:                        else
121:                            zoom = totalHeight / rectH;
122:
123:                        imageMap.startCoalesce();
124:                        imageMap.zoom(zoom);
125:
126:                        double[] attr = root.getPresAbsolute("viewBox")
127:                                .getDoubleList();
128:
129:                        double newX = x - attr[0];
130:                        double newY = y - attr[1];
131:
132:                        newX = newX / attr[2];
133:                        newY = newY / attr[3];
134:
135:                        if (newX > 0)
136:                            newX = newX + 1.0;
137:                        else
138:                            newX = newX - 1.0;
139:
140:                        if (newY > 0)
141:                            newY = newY + 1.0;
142:                        else
143:                            newY = newY - 1.0;
144:
145:                        imageMap.endCoalesce();
146:                        imageMap.pan(newX, newY);
147:                    } catch (Exception ex) {
148:                        if (BuildProperties.DEBUG)
149:                            ex.printStackTrace();
150:                    }
151:                }
152:            }
153:
154:            /**
155:             * Re-sizes the selection box as the mouse is dragged.
156:             * @param e the passed <CODE>MouseEvent</CODE> instance.
157:             */
158:            public void mouseDragged(MouseEvent e) {
159:                if ((e.getModifiers() & e.CTRL_MASK) != 0) {
160:                    endPt = e.getPoint();
161:                    dragged = true;
162:                    repaint();
163:                }
164:            }
165:
166:            /**
167:             * Paints the selection box.
168:             * @param g the delegate <CODE>Graphics</Code> object.
169:             */
170:            public void paintComponent(Graphics g) {
171:                if (dragged) {
172:                    Graphics2D g2d = (Graphics2D) g.create();
173:                    g2d.setColor(new Color(0, 148, 255));
174:                    g2d.setStroke(new BasicStroke(2.0F));
175:
176:                    double width = endPt.getX() - startPt.getX();
177:                    double height = endPt.getY() - startPt.getY();
178:                    rect = new Rectangle2D.Double(startPt.getX(), startPt
179:                            .getY(), width, height);
180:                    g2d.draw(rect);
181:
182:                    g2d.dispose();
183:                }
184:            }
185:
186:            public void mouseClicked(MouseEvent e) {
187:            }
188:
189:            public void mouseEntered(MouseEvent e) {
190:            }
191:
192:            public void mouseExited(MouseEvent e) {
193:            }
194:
195:            public void mouseMoved(MouseEvent e) {
196:            }
197:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.