Source Code Cross Referenced for ScalablePanel.java in  » UML » jrefactory » org » acm » seguin » uml » line » 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 » UML » jrefactory » org.acm.seguin.uml.line 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         * The JRefactory License, Version 1.0
003:         *
004:         * Copyright (c) 2001 JRefactory.  All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution,
019:         *    if any, must include the following acknowledgment:
020:         *       "This product includes software developed by the
021:         *        JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022:         *    Alternately, this acknowledgment may appear in the software itself,
023:         *    if and wherever such third-party acknowledgments normally appear.
024:         *
025:         * 4. The names "JRefactory" must not be used to endorse or promote
026:         *    products derived from this software without prior written
027:         *    permission. For written permission, please contact seguin@acm.org.
028:         *
029:         * 5. Products derived from this software may not be called "JRefactory",
030:         *    nor may "JRefactory" appear in their name, without prior written
031:         *    permission of Chris Seguin.
032:         *
033:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036:         * DISCLAIMED.  IN NO EVENT SHALL THE CHRIS SEGUIN OR
037:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044:         * SUCH DAMAGE.
045:         * ====================================================================
046:         *
047:         * This software consists of voluntary contributions made by many
048:         * individuals on behalf of JRefactory.  For more information on
049:         * JRefactory, please see
050:         * <http://www.sourceforge.org/projects/jrefactory>.
051:         */
052:        package org.acm.seguin.uml.line;
053:
054:        import java.awt.Dimension;
055:        import java.awt.LayoutManager;
056:        import java.awt.Point;
057:        import java.awt.Rectangle;
058:        import javax.swing.JPanel;
059:
060:        /**
061:         *  Panel that can be scaled and shifted
062:         *
063:         *@author     Chris Seguin
064:         *@author     <a href="JRefactory@ladyshot.demon.co.uk">Mike Atkinson</a>
065:         *@version    $Id: ScalablePanel.java,v 1.4 2003/07/29 20:51:57 mikeatkinson Exp $
066:         *@created    September 12, 2001
067:         */
068:        public abstract class ScalablePanel extends JPanel {
069:            private boolean inShapeChange;
070:            private boolean inScaling = false;
071:
072:            private double scale = 1.0;
073:
074:            private int absoluteWidth = -1;
075:            private int absoluteHeight = -1;
076:            private int absoluteX = -1;
077:            private int absoluteY = -1;
078:
079:            /**
080:             *  Constructor for the ScalablePanel object
081:             */
082:            public ScalablePanel() {
083:                init();
084:            }
085:
086:            /**
087:             *  Constructor for the ScalablePanel object
088:             *
089:             *@param  doubleBuffered  Description of Parameter
090:             */
091:            public ScalablePanel(boolean doubleBuffered) {
092:                super (doubleBuffered);
093:                init();
094:            }
095:
096:            /**
097:             *  Constructor for the ScalablePanel object
098:             *
099:             *@param  layout  Description of Parameter
100:             */
101:            public ScalablePanel(LayoutManager layout) {
102:                super (layout);
103:                init();
104:            }
105:
106:            /**
107:             *  Constructor for the ScalablePanel object
108:             *
109:             *@param  layout          Description of Parameter
110:             *@param  doubleBuffered  Description of Parameter
111:             */
112:            public ScalablePanel(LayoutManager layout, boolean doubleBuffered) {
113:                super (layout, doubleBuffered);
114:                init();
115:            }
116:
117:            /**
118:             *  Sets the Location attribute of the ScalablePanel object
119:             *
120:             *@param  x  The new Location value
121:             *@param  y  The new Location value
122:             */
123:            public void setLocation(int x, int y) {
124:                if (inShapeChange) {
125:                    super .setLocation(x, y);
126:                } else {
127:                    inShapeChange = true;
128:                    absoluteX = x;
129:                    absoluteY = y;
130:                    super .setLocation(scaleInteger(x), scaleInteger(y));
131:                    inShapeChange = false;
132:                }
133:            }
134:
135:            /**
136:             *  Sets the Location attribute of the ScalablePanel object
137:             *
138:             *@param  pt  The new Location value
139:             */
140:            public void setLocation(Point pt) {
141:                if (inShapeChange) {
142:                    super .setLocation(pt);
143:                } else {
144:                    inShapeChange = true;
145:                    absoluteX = pt.x;
146:                    absoluteY = pt.y;
147:                    super .setLocation(scaleInteger(pt.x), scaleInteger(pt.y));
148:                    inShapeChange = false;
149:                }
150:            }
151:
152:            /**
153:             *  Sets the Size attribute of the ScalablePanel object
154:             *
155:             *@param  w  The new Size value
156:             *@param  h  The new Size value
157:             */
158:            public void setSize(int w, int h) {
159:                if (inShapeChange) {
160:                    super .setSize(w, h);
161:                } else {
162:                    inShapeChange = true;
163:                    absoluteWidth = w;
164:                    absoluteHeight = h;
165:                    super .setSize(scaleInteger(w), scaleInteger(h));
166:                    inShapeChange = false;
167:                }
168:            }
169:
170:            /**
171:             *  Sets the Size attribute of the ScalablePanel object
172:             *
173:             *@param  dim  The new Size value
174:             */
175:            public void setSize(Dimension dim) {
176:                if (inShapeChange) {
177:                    super .setSize(dim);
178:                } else {
179:                    inShapeChange = true;
180:                    absoluteWidth = dim.width;
181:                    absoluteHeight = dim.height;
182:                    super .setSize(scaleInteger(dim.width),
183:                            scaleInteger(dim.height));
184:                    inShapeChange = false;
185:                }
186:            }
187:
188:            /**
189:             *  Sets the Bounds attribute of the ScalablePanel object
190:             *
191:             *@param  x  The new Bounds value
192:             *@param  y  The new Bounds value
193:             *@param  w  The new Bounds value
194:             *@param  h  The new Bounds value
195:             */
196:            public void setBounds(int x, int y, int w, int h) {
197:                if (inShapeChange) {
198:                    super .setBounds(x, y, w, h);
199:                } else {
200:                    inShapeChange = true;
201:                    absoluteX = x;
202:                    absoluteY = y;
203:                    absoluteWidth = w;
204:                    absoluteHeight = h;
205:                    super .setBounds(scaleInteger(x), scaleInteger(y),
206:                            scaleInteger(h), scaleInteger(h));
207:                    inShapeChange = false;
208:                }
209:            }
210:
211:            /**
212:             *  Sets the Bounds attribute of the ScalablePanel object
213:             *
214:             *@param  rect  The new Bounds value
215:             */
216:            public void setBounds(Rectangle rect) {
217:                if (inShapeChange) {
218:                    super .setBounds(rect);
219:                } else {
220:                    inShapeChange = true;
221:                    absoluteX = rect.x;
222:                    absoluteY = rect.y;
223:                    absoluteWidth = rect.width;
224:                    absoluteHeight = rect.height;
225:                    super 
226:                            .setBounds(scaleInteger(rect.x),
227:                                    scaleInteger(rect.y),
228:                                    scaleInteger(rect.width),
229:                                    scaleInteger(rect.height));
230:                    inShapeChange = false;
231:                }
232:            }
233:
234:            /**
235:             *  This method moves the class diagram around on the screen
236:             *
237:             *@param  x  the x coordinate (scaled value)
238:             *@param  y  the y coordinate (scaled value)
239:             */
240:            public void shift(int x, int y) {
241:                Point pt = getLocation();
242:                inShapeChange = true;
243:                absoluteX = Math.max(0, unscaleInteger(x + pt.x));
244:                absoluteY = Math.max(0, unscaleInteger(y + pt.y));
245:                setLocation(Math.max(0, x + pt.x), Math.max(0, y + pt.y));
246:                inShapeChange = false;
247:            }
248:
249:            /**
250:             *  Scales the image
251:             *
252:             *@param  value  the amount to scale
253:             */
254:            public void scale(double value) {
255:                if (Math.abs(scale - value) > 0.001) {
256:                    Rectangle rect = getUnscaledBounds();
257:
258:                    scale = value;
259:
260:                    inScaling = true;
261:                    setBounds(rect);
262:                    inScaling = false;
263:                }
264:            }
265:
266:            /**
267:             *  Invokes old version of setLocation
268:             *
269:             *@param  x  Description of Parameter
270:             *@param  y  Description of Parameter
271:             */
272:            public void move(int x, int y) {
273:                if (inShapeChange) {
274:                    super .move(x, y);
275:                } else {
276:                    inShapeChange = true;
277:                    absoluteX = x;
278:                    absoluteY = y;
279:                    super .move(scaleInteger(x), scaleInteger(y));
280:                    inShapeChange = false;
281:                }
282:            }
283:
284:            /**
285:             *  Description of the Method
286:             *
287:             *@param  w  Description of Parameter
288:             *@param  h  Description of Parameter
289:             */
290:            public void resize(int w, int h) {
291:                if (inShapeChange) {
292:                    super .resize(w, h);
293:                } else {
294:                    inShapeChange = true;
295:                    absoluteWidth = w;
296:                    absoluteHeight = h;
297:                    super .resize(scaleInteger(w), scaleInteger(h));
298:                    inShapeChange = false;
299:                }
300:            }
301:
302:            /**
303:             *  Description of the Method
304:             *
305:             *@param  dim  Description of Parameter
306:             */
307:            public void resize(Dimension dim) {
308:                if (inShapeChange) {
309:                    super .resize(dim);
310:                } else {
311:                    inShapeChange = true;
312:                    absoluteWidth = dim.width;
313:                    absoluteHeight = dim.height;
314:                    super .resize(scaleInteger(dim.width),
315:                            scaleInteger(dim.height));
316:                    inShapeChange = false;
317:                }
318:            }
319:
320:            /**
321:             *  Description of the Method
322:             *
323:             *@param  x  Description of Parameter
324:             *@param  y  Description of Parameter
325:             *@param  w  Description of Parameter
326:             *@param  h  Description of Parameter
327:             */
328:            public void reshape(int x, int y, int w, int h) {
329:                if (inShapeChange) {
330:                    super .reshape(x, y, w, h);
331:                } else {
332:                    inShapeChange = true;
333:                    absoluteX = x;
334:                    absoluteY = y;
335:                    absoluteWidth = w;
336:                    absoluteHeight = h;
337:                    super .reshape(scaleInteger(x), scaleInteger(y),
338:                            scaleInteger(h), scaleInteger(h));
339:                    inShapeChange = false;
340:                }
341:            }
342:
343:            /**
344:             *  Return the scaling factor
345:             *
346:             *@return    the scaling factor
347:             */
348:            protected double getScale() {
349:                return scale;
350:            }
351:
352:            /**
353:             *  Scale the integer
354:             *
355:             *@param  value  the value to be converted
356:             *@return        the scaled version
357:             */
358:            protected int scaleInteger(int value) {
359:                return (int) Math.round(1.0 + scale * value);
360:            }
361:
362:            /**
363:             *  Get the bounds without scaling factors
364:             *
365:             *@return    the rectangle containing the boundaries
366:             */
367:            public Rectangle getUnscaledBounds() {
368:                return new Rectangle(absoluteX, absoluteY, absoluteWidth,
369:                        absoluteHeight);
370:            }
371:
372:            /**
373:             *  Computes the location without the scaling factor
374:             *
375:             *@return    the unscaled location
376:             */
377:            public Point getUnscaledLocation() {
378:                return new Point(absoluteX, absoluteY);
379:            }
380:
381:            /**
382:             *  Inverse of the scaleInteger operation
383:             *
384:             *@param  value  the input value
385:             *@return        the result of the unscape operation
386:             */
387:            protected int unscaleInteger(int value) {
388:                return (int) (value / scale);
389:            }
390:
391:            /**
392:             *  Initialize the valuse
393:             */
394:            private void init() {
395:                inShapeChange = false;
396:                scale = 1.0;
397:            }
398:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.