Source Code Cross Referenced for AbstractRubberBand.java in  » Swing-Library » swingfx » net » java » swingfx » rubberband » rubberbands » 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 » Swing Library » swingfx » net.java.swingfx.rubberband.rubberbands 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005, romain guy (romain.guy@jext.org) and craig wickesser (craig@codecraig.com)
003:         * All rights reserved.
004:         * 
005:         * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
006:         * 
007:         *     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
008:         *     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
009:         *     * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
010:         * 
011:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
012:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
013:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
014:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
015:         * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
016:         * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
017:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
018:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
019:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
020:         * POSSIBILITY OF SUCH DAMAGE.
021:         */
022:
023:        package net.java.swingfx.rubberband.rubberbands;
024:
025:        import java.awt.Rectangle;
026:        import java.awt.event.MouseEvent;
027:
028:        import javax.swing.event.MouseInputAdapter;
029:
030:        import net.java.swingfx.rubberband.canvas.RubberBandCanvas;
031:
032:        /**
033:         * An abstract implementation of {@link RubberBand} which handles
034:         * the basic drawing/setup of the rubber band.
035:         *
036:         * @author rwickesser
037:         * @since 1.0
038:         * $Revision: 1.2 $
039:         */
040:        public abstract class AbstractRubberBand extends MouseInputAdapter
041:                implements  RubberBand {
042:            /** the canvas where the rubber band will be drawn onto */
043:            protected RubberBandCanvas canvas;
044:
045:            /** maintains the size and location of the rubber band */
046:            protected Rectangle rubberband;
047:
048:            /** stores the x coordinate of the mouse pressed event */
049:            private int pressX;
050:            /** stores the y coordinate of the mouse pressed event */
051:            private int pressY;
052:
053:            /** 
054:             * if <code>true</code> then the rubber band will disappear
055:             * after the mouse is released, otherwise the rubber band stays
056:             * visible until a new rubber band is drawn.  Subclasses
057:             * should override 
058:             */
059:            private boolean hideOnRelease;
060:
061:            /**
062:             * Creates a new <code>RubberBand</code> and sets the canvas
063:             * 
064:             * @param canvas    the <code>RubberBandCanvas</code> on which the rubber band
065:             *                  will be drawn
066:             *                  
067:             * @see #setCanvas(RubberBandCanvas)
068:             */
069:            public AbstractRubberBand(RubberBandCanvas canvas) {
070:                this .canvas = canvas;
071:                init();
072:            }
073:
074:            /**
075:             * Initializes the rubber band
076:             */
077:            private void init() {
078:                rubberband = new Rectangle();
079:                setHideOnRelease(true);
080:
081:                if (canvas != null) {
082:                    canvas.setRubberBand(this );
083:                    addMouseListeners();
084:                }
085:            }
086:
087:            /* (non-Javadoc)
088:             * @see gui.rubberband.RubberBand#addMouseListeners()
089:             */
090:            public void addMouseListeners() {
091:                canvas.getCanvas().addMouseListener(this );
092:                canvas.getCanvas().addMouseMotionListener(this );
093:            }
094:
095:            /* (non-Javadoc)
096:             * @see net.java.swingfx.rubberband.RubberBand#getBounds()
097:             */
098:            public Rectangle getBounds() {
099:                return rubberband.getBounds();
100:            }
101:
102:            /* (non-Javadoc)
103:             * @see gui.rubberband.RubberBand#setCanvas(RubberBandCanvas)
104:             */
105:            public void setCanvas(RubberBandCanvas canvas) {
106:                this .canvas = canvas;
107:                this .canvas.setRubberBand(this );
108:                addMouseListeners();
109:            }
110:
111:            /* (non-Javadoc)
112:             * @see javax.swing.event.MouseInputAdapter#mouseDragged(java.awt.event.MouseEvent)
113:             */
114:            public void mouseDragged(MouseEvent e) {
115:                updateRubberBand(e);
116:
117:                int x = e.getX();
118:                int y = e.getY();
119:                int w = 0;
120:                int h = 0;
121:
122:                // adjust x and width
123:                if (pressX < x) {
124:                    int tmp = x;
125:                    x = pressX;
126:                    w = tmp - x;
127:                } else {
128:                    w = pressX - x;
129:                }
130:
131:                // adjust y and height
132:                if (pressY < y) {
133:                    int tmp = y;
134:                    y = pressY;
135:                    h = tmp - y;
136:                } else {
137:                    h = pressY - y;
138:                }
139:
140:                // update rubber band size and location
141:                update(x, y, w, h);
142:
143:                // repaint the canvas so the rubber band is updated visually
144:                updateCanvas();
145:            }
146:
147:            /* (non-Javadoc)
148:             * @see javax.swing.event.MouseInputAdapter#mousePressed(java.awt.event.MouseEvent)
149:             */
150:            public void mousePressed(MouseEvent e) {
151:                startRubberBand(e);
152:                pressX = e.getX();
153:                pressY = e.getY();
154:
155:                // update rubber band size and location
156:                update(pressX, pressY, 0, 0);
157:            }
158:
159:            /* (non-Javadoc)
160:             * @see javax.swing.event.MouseInputAdapter#mouseReleased(java.awt.event.MouseEvent)
161:             */
162:            public void mouseReleased(MouseEvent e) {
163:                stopRubberBand(e);
164:
165:                // erase the rubber band if hideOnRelease is true
166:                if (isHideOnRelease()) {
167:                    // update rubber band size and location
168:                    update(-1, -1, 0, 0);
169:
170:                    // repaint the canvas so the rubber band disappears
171:                    updateCanvas();
172:                }
173:            }
174:
175:            /**
176:             * Makes a call to the canvas' repaint method
177:             */
178:            private void updateCanvas() {
179:                canvas.getCanvas().repaint();
180:            }
181:
182:            /**
183:             * Sets whether the rubber band should disappear when the mouse
184:             * is released or not
185:             * 
186:             * @param hideOnRelease	if <code>true</code> the rubber band will
187:             * 						disappear when the mouse is released, if
188:             * 						<code>false</code> the rubber band will remain
189:             * 						visible until a new rubber band is created
190:             */
191:            protected void setHideOnRelease(boolean hideOnRelease) {
192:                this .hideOnRelease = hideOnRelease;
193:            }
194:
195:            /**
196:             * Returns whether or not the rubber band should disappear
197:             * after the mouse is released
198:             * 
199:             * @return	<code>true</code> if the rubber band should
200:             * 			disappear when the mouse is released, else if
201:             * 			<code>false</code> the rubber band should remain
202:             * 			visible until a new rubber band is created
203:             */
204:            protected boolean isHideOnRelease() {
205:                return hideOnRelease;
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.