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


001:        /*
002:         * Main.java
003:         *
004:         * Created on 03 November 2006, 17:03
005:         *
006:         * To change this template, choose Tools | Template Manager
007:         * and open the template in the editor.
008:         */
009:
010:        package com.xoetrope.svgcomponentswizard;
011:
012:        import com.kitfox.svg.SVGElement;
013:        import com.kitfox.svg.SVGRoot;
014:        import com.kitfox.svg.animation.AnimationElement;
015:        import com.kitfox.svg.animation.TimeDiscrete;
016:        import com.xoetrope.svg.XSvgImageMap;
017:        import java.awt.BorderLayout;
018:        import java.awt.Color;
019:        import java.awt.Insets;
020:        import java.awt.Point;
021:        import java.awt.event.ActionEvent;
022:        import java.awt.event.ActionListener;
023:        import java.awt.event.ComponentAdapter;
024:        import java.awt.event.ComponentEvent;
025:        import java.awt.event.MouseEvent;
026:        import java.awt.event.MouseListener;
027:        import java.io.File;
028:        import java.lang.reflect.Field;
029:        import java.net.MalformedURLException;
030:        import net.xoetrope.optional.svg.XSvgButton;
031:        import net.xoetrope.swing.XPanel;
032:        import net.xoetrope.xui.XPage;
033:        import net.xoetrope.xui.XPageManager;
034:        import net.xoetrope.xui.XProjectManager;
035:
036:        /**
037:         *
038:         * @author luano
039:         */
040:        public class SvgGuage extends XPage {
041:            protected XPanel guagePanel, buttonPanel;
042:            protected XSvgButton svgButton;
043:            protected boolean first;
044:            protected int x, y, guageWidth, guageHeight, percentage;
045:
046:            /**
047:             * Set-up svg button and add component listener to guage panel.
048:             */
049:            public void pageCreated() {
050:                guagePanel = (XPanel) findComponent("guagePanel");
051:                guagePanel.setBackground(Color.white);
052:
053:                buttonPanel = (XPanel) findComponent("buttonPanel");
054:                buttonPanel.setBackground(Color.white);
055:
056:                svgButton = new XSvgButton();
057:                svgButton.setOpaque(false);
058:                svgButton.setBackground(Color.white);
059:                guagePanel.add(svgButton);
060:
061:                try {
062:                    svgButton.setAnimate(true);
063:                    svgButton.setImage(new File("resources/animatedGuage.svg")
064:                            .toURL());
065:
066:                    final String[][] ids = { { "needle", null, null } };
067:                    svgButton.setElementIds(ids);
068:                    final RotationTransform rotationTransform = new RotationTransform();
069:                    svgButton.addActionListener(new ActionListener() {
070:                        public void actionPerformed(ActionEvent ae) {
071:                            SVGElement element = svgButton
072:                                    .getElement("rotateNeedleTransform");
073:                            rotationTransform.setElement(element, 193.0, 190.0);
074:
075:                            if ((ae.getModifiers() & ae.CTRL_MASK) == 0)
076:                                rotationTransform
077:                                        .setRotation(Math
078:                                                .min(255.0, rotationTransform
079:                                                        .getRotation() + 20.0));
080:                            else
081:                                rotationTransform
082:                                        .setRotation(Math
083:                                                .max(0.0, rotationTransform
084:                                                        .getRotation() - 20.0));
085:                            svgButton.update();
086:                            svgButton.setElementIds(ids);
087:                            return;
088:                        }
089:                    });
090:
091:                    svgButton.setElementIds(ids);
092:                    svgButton.setup();
093:                    svgButton.play();
094:                } catch (MalformedURLException ex) {
095:                    ex.printStackTrace();
096:                }
097:
098:                setVisible(true);
099:
100:                svgButton.addActionListener(new ActionListener() {
101:                    public void actionPerformed(ActionEvent ae) {
102:                        System.out.println("Clicked");
103:                    }
104:                });
105:
106:                /**
107:                 * Re-position svg button if the guage panel's size changes.
108:                 */
109:                guagePanel.addComponentListener(new ComponentAdapter() {
110:                    public void componentResized(ComponentEvent evt) {
111:                        int width = guagePanel.getWidth();
112:                        int height = guagePanel.getHeight();
113:
114:                        if (svgButton.getWidth() == 0
115:                                && svgButton.getHeight() == 0) {
116:                            guageWidth = height;
117:                            guageHeight = height;
118:                        } else {
119:                            if (width < height) {
120:                                guageWidth = width;
121:                                guageHeight = width;
122:                            } else {
123:                                guageWidth = height;
124:                                guageHeight = height;
125:                            }
126:                        }
127:
128:                        if (height < width) {
129:                            x = (width - guageWidth) / 2;
130:                            width = height;
131:                        } else {
132:                            y = (height - guageHeight) / 2;
133:                            height = width;
134:                        }
135:
136:                        svgButton.setBounds(x, y, width, height);
137:                    }
138:                });
139:            }
140:
141:            /**
142:             * Show the welcome page if the back button is pressed.
143:             */
144:            public void showPage() {
145:                XPageManager pageMgr = XProjectManager.getPageManager();
146:                pageMgr.showPage("Welcome");
147:            }
148:
149:            /**
150:             * Inner class used to set the rotation transform for the svg guage.
151:             */
152:            class RotationTransform {
153:                private SVGElement element;
154:                private double rotation;
155:                private Point.Double centre;
156:
157:                /**
158:                 * Get the currently used svg element.
159:                 * @return <CODE>SVGElemnt</CODE> specifying the returned element.
160:                 */
161:                public SVGElement getElement() {
162:                    return element;
163:                }
164:
165:                /**
166:                 * Set the currently used SVGElement. 
167:                 * @param element <CODE>SVGElemnt</CODE> specifying the new element.
168:                 */
169:                public void setElement(SVGElement element) {
170:                    this .element = element;
171:                }
172:
173:                /**
174:                 * Set location of the specified svg element.
175:                 * @param element <CODE>SVGElemnt</CODE> specifying the element to be modified.
176:                 * @param cx <CODE>double</CODE> specifying the new x co-ordinate.
177:                 * @param cy <CODE>double</CODE> specifying the new y co-ordinate.
178:                 */
179:                public void setElement(SVGElement element, double cx, double cy) {
180:                    this .element = element;
181:                    centre = new Point.Double(cx, cy);
182:                }
183:
184:                /**
185:                 * Get the current rotation. 
186:                 * @return <CODE>double</CODE> specifying the current rotation.
187:                 */
188:                public double getRotation() {
189:                    return rotation;
190:                }
191:
192:                /**
193:                 * Set the amount of rotation to be applied to the needle.
194:                 * @param rotation <CODE>double</CODE> specifying the amount of rotation to be applied.
195:                 */
196:                public void setRotation(double rotation) {
197:                    double oldRotation = Math.max(15.0, this .rotation);
198:                    this .rotation = rotation;
199:                    try {
200:                        //          element.setAttribute( "transform", AnimationElement.AT_XML, "translate(195,198) rotate(" + Double.toString( rotation )+ ") translate(-195,-198)" );
201:                        Field f = element.getClass().getDeclaredField("values");
202:                        f.setAccessible(true);
203:                        double[][] values = (double[][]) f.get(element);
204:                        values[0][0] = oldRotation;
205:                        values[1][0] = rotation;
206:                        f.set(element, values);
207:
208:                        f = AnimationElement.class
209:                                .getDeclaredField("beginTime");
210:                        f.setAccessible(true);
211:                        TimeDiscrete value = (TimeDiscrete) f.get(element);
212:                        value = new TimeDiscrete(svgButton.getCurTime());
213:                        f.set(element, value);
214:
215:                        element.updateTime(0.0);
216:                    } catch (Exception ex) {
217:                        ex.printStackTrace();
218:                    }
219:
220:                    //          element.setAttribute( "from", AnimationElement.AT_XML, Integer.toString( (int)oldRotation ) );
221:                    //          element.setAttribute( "to", AnimationElement.AT_XML, Integer.toString( (int)rotation ) );
222:                }
223:
224:                /**
225:                 * Get the centre point.
226:                 * @return <CODE>Point.Double</CODE> specifying the current centre point.
227:                 */
228:                public Point.Double getCentre() {
229:                    return centre;
230:                }
231:
232:                /**
233:                 * Set the centre point.
234:                 * @param centre <CODE>Point.Double</CODE> specifying the new centre point.
235:                 */
236:                public void setCentre(Point.Double centre) {
237:                    this.centre = centre;
238:                }
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.