Source Code Cross Referenced for ScrollingImagePanel.java in  » 6.0-JDK-Modules » Java-Advanced-Imaging » javax » media » jai » widget » 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 » 6.0 JDK Modules » Java Advanced Imaging » javax.media.jai.widget 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: ScrollingImagePanel.java,v $
003:         *
004:         * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * Use is subject to license terms.
007:         *
008:         * $Revision: 1.1 $
009:         * $Date: 2005/02/11 04:57:59 $
010:         * $State: Exp $
011:         */
012:        package javax.media.jai.widget;
013:
014:        import java.awt.BorderLayout;
015:        import java.awt.Cursor;
016:        import java.awt.Dimension;
017:        import java.awt.Panel;
018:        import java.awt.Point;
019:        import java.awt.Scrollbar;
020:        import java.awt.event.AdjustmentEvent;
021:        import java.awt.event.AdjustmentListener;
022:        import java.awt.event.MouseEvent;
023:        import java.awt.event.MouseListener;
024:        import java.awt.event.MouseMotionListener;
025:        import java.awt.image.RenderedImage;
026:        import java.util.Vector;
027:
028:        import java.awt.ScrollPane;
029:        import java.awt.event.ComponentEvent;
030:        import java.awt.event.ComponentListener;
031:        import java.awt.Container;
032:        import java.awt.peer.ScrollPanePeer;
033:
034:        /**
035:         * An extension of java.awt.Panel that contains an ImageCanvas and
036:         * vertical and horizontal scrollbars.  The origin of the ImageCanvas
037:         * is set according to the value of the scrollbars.  Additionally, the
038:         * origin may be changed by dragging the mouse.  The window cursor
039:         * will be changed to Cursor.MOVE_CURSOR for the duration of the
040:         * drag.
041:         *
042:         * <p> Due to the limitations of BufferedImage, only TYPE_BYTE of band
043:         * 1, 2, 3, 4, and TYPE_USHORT of band 1, 2, 3 images can be displayed
044:         * using this widget.
045:         *
046:         *
047:         * <p>
048:         * This class has been deprecated.  The source
049:         * code has been moved to the samples/widget
050:         * directory.  These widgets are no longer
051:         * supported.
052:         *
053:         * @deprecated as of JAI 1.1
054:         */
055:
056:        public class ScrollingImagePanel extends ScrollPane implements 
057:                AdjustmentListener, ComponentListener, MouseListener,
058:                MouseMotionListener {
059:
060:            /** The ImageCanvas we are controlling. */
061:            protected ImageCanvas ic;
062:            /** The RenderedImage displayed by the ImageCanvas. */
063:            protected RenderedImage im;
064:            /** The width of the panel. */
065:            protected int panelWidth;
066:            /** The height of the panel. */
067:            protected int panelHeight;
068:            /** Vector of ViewportListeners. */
069:            protected Vector viewportListeners = new Vector();
070:
071:            /** 
072:             * Constructs a ScrollingImagePanel of a given size for a 
073:             * given RenderedImage.
074:             */
075:            public ScrollingImagePanel(RenderedImage im, int width, int height) {
076:                super ();
077:                this .im = im;
078:                this .panelWidth = width;
079:                this .panelHeight = height;
080:
081:                ic = new ImageCanvas(im);
082:
083:                getHAdjustable().addAdjustmentListener(this );
084:                getVAdjustable().addAdjustmentListener(this );
085:
086:                super .setSize(width, height);
087:                addComponentListener(this );
088:                add("Center", ic);
089:            }
090:
091:            /** Adds the specified ViewportListener to the panel */
092:            public void addViewportListener(ViewportListener l) {
093:                viewportListeners.addElement(l);
094:                l.setViewport(getXOrigin(), getYOrigin(), panelWidth,
095:                        panelHeight);
096:            }
097:
098:            /** Removes the specified ViewportListener  */
099:            public void removeViewportListener(ViewportListener l) {
100:                viewportListeners.removeElement(l);
101:            }
102:
103:            private void notifyViewportListeners(int x, int y, int w, int h) {
104:                int i;
105:                int numListeners = viewportListeners.size();
106:                for (i = 0; i < numListeners; i++) {
107:                    ViewportListener l = (ViewportListener) (viewportListeners
108:                            .elementAt(i));
109:                    l.setViewport(x, y, w, h);
110:                }
111:            }
112:
113:            /**
114:             *  Returns the image canvas.  Allows mouse listeners
115:             *  to be used on the image canvas.
116:             *
117:             * @since JAI 1.1
118:             */
119:            public ImageCanvas getImageCanvas() {
120:                return ic;
121:            }
122:
123:            /** Returns the XOrigin of the image */
124:            public int getXOrigin() {
125:                return ic.getXOrigin();
126:            }
127:
128:            /** Returns the YOrigin of the image */
129:            public int getYOrigin() {
130:                return ic.getYOrigin();
131:            }
132:
133:            /**
134:             * Sets the image origin to a given (x, y) position.
135:             * The scrollbars are updated appropriately.
136:             */
137:            public void setOrigin(int x, int y) {
138:                ic.setOrigin(x, y);
139:                notifyViewportListeners(x, y, panelWidth, panelHeight);
140:            }
141:
142:            /**
143:             * Set the center of the image to the given coordinates
144:             * of the scroll window.
145:             */
146:            public synchronized void setCenter(int x, int y) {
147:
148:                // scrollbar position
149:                int sx = 0;
150:                int sy = 0;
151:
152:                // bounds
153:                int iw = im.getWidth();
154:                int ih = im.getHeight();
155:                int vw = getViewportSize().width;
156:                int vh = getViewportSize().height;
157:
158:                // scrollbar lengths (proportional indicator)
159:                int fx = getHAdjustable().getBlockIncrement();
160:                int fy = getVAdjustable().getBlockIncrement();
161:
162:                if (x < (vw - iw / 2)) {
163:                    sx = 0;
164:                } else if (x > iw / 2) {
165:                    sx = iw - vw;
166:                } else {
167:                    sx = x + (iw - vw - fx) / 2;
168:                }
169:
170:                if (y < (vh - ih / 2)) {
171:                    sy = 0;
172:                } else if (y > ih / 2) {
173:                    sy = ih - vh;
174:                } else {
175:                    sy = y + (ih - vh - fy) / 2;
176:                }
177:
178:                getHAdjustable().setValue(sx);
179:                getVAdjustable().setValue(sy);
180:
181:                notifyViewportListeners(getXOrigin(), getYOrigin(), panelWidth,
182:                        panelHeight);
183:            }
184:
185:            /** Sets the panel to display the specified image */
186:            public void set(RenderedImage im) {
187:                this .im = im;
188:                ic.set(im);
189:            }
190:
191:            /** Returns the X co-ordinate of the image center. */
192:            public int getXCenter() {
193:                return getXOrigin() + panelWidth / 2;
194:            }
195:
196:            /** Returns the Y co-ordinate of the image center. */
197:            public int getYCenter() {
198:                return getYOrigin() + panelHeight / 2;
199:            }
200:
201:            /** Called by the AWT when instantiating the component. */
202:            public Dimension getPreferredSize() {
203:                return new Dimension(panelWidth, panelHeight);
204:            }
205:
206:            /** Called by the AWT during instantiation and
207:             * when events such as resize occur. 
208:             */
209:            public void setBounds(int x, int y, int width, int height) {
210:
211:                // must set this first
212:                super .setBounds(x, y, width, height);
213:
214:                int vpw = getViewportSize().width;
215:                int vph = getViewportSize().height;
216:                int imw = im.getWidth();
217:                int imh = im.getHeight();
218:
219:                if (vpw >= imw && vph >= imh) {
220:                    ic.setBounds(x, y, width, height);
221:                } else {
222:                    //  BUG
223:                    //  This fixes bad image positions during resize
224:                    //  but breaks tiles (causes them all to load)
225:                    //  Somehow the graphics context clip area gets
226:                    //  changed in the ImageCanvas update(g) call.
227:                    //  This occurs when the image size is greater
228:                    //  than the viewport when the display first
229:                    //  comes up.  Removing the repaint in the
230:                    //  ImageCanvas fixes this, but breaks ImageCanvas.
231:                    //  Should have a new ImageCanvas call that sets
232:                    //  the origin without a repaint.
233:
234:                    /* causes all tiles to be loaded, breaks scrolling, fixes resize */
235:                    //setOrigin(0, 0);
236:                    /* causes image to shift incorrectly on resize event */
237:                    ic.setBounds(x, y, vpw, vph);
238:                }
239:
240:                this .panelWidth = width;
241:                this .panelHeight = height;
242:            }
243:
244:            /** Called by the AWT when either scrollbar changes. */
245:            public void adjustmentValueChanged(AdjustmentEvent e) {
246:            }
247:
248:            /// ComponentListener Interface     
249:
250:            /** Called when the ImagePanel is resized */
251:            public void componentResized(ComponentEvent e) {
252:                notifyViewportListeners(getXOrigin(), getYOrigin(), panelWidth,
253:                        panelHeight);
254:            }
255:
256:            /** Ignored   */
257:            public void componentHidden(ComponentEvent e) {
258:            }
259:
260:            /** Ignored   */
261:            public void componentMoved(ComponentEvent e) {
262:            }
263:
264:            /** Ignored   */
265:            public void componentShown(ComponentEvent e) {
266:            }
267:
268:            //
269:            // Mouse drag interface
270:            //
271:
272:            /** The initial Point of a mouse drag. */
273:            protected Point moveSource;
274:            /** True if we are in the middle of a mouse drag. */
275:            protected boolean beingDragged = false;
276:            /** A place to save the cursor. */
277:            protected Cursor defaultCursor = null;
278:
279:            /** Called at the beginning of a mouse drag. */
280:            private synchronized void startDrag(Point p) {
281:                this .setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
282:                beingDragged = true;
283:                moveSource = p;
284:            }
285:
286:            /** Called for each point of a mouse drag. */
287:            protected synchronized void updateDrag(Point moveTarget) {
288:                if (beingDragged) {
289:                    int dx = moveSource.x - moveTarget.x;
290:                    int dy = moveSource.y - moveTarget.y;
291:                    moveSource = moveTarget;
292:
293:                    int x = getHAdjustable().getValue() + dx;
294:                    int y = getVAdjustable().getValue() + dy;
295:                    setOrigin(x, y);
296:                }
297:            }
298:
299:            /** Called at the end of a mouse drag. */
300:            private synchronized void endDrag() {
301:                this .setCursor(Cursor
302:                        .getPredefinedCursor(Cursor.DEFAULT_CURSOR));
303:                beingDragged = false;
304:            }
305:
306:            /** Called by the AWT when the mouse button is pressed. */
307:            public void mousePressed(MouseEvent me) {
308:                startDrag(me.getPoint());
309:            }
310:
311:            /** Called by the AWT as the mouse is dragged. */
312:            public void mouseDragged(MouseEvent me) {
313:                updateDrag(me.getPoint());
314:            }
315:
316:            /** Called by the AWT when the mouse button is released. */
317:            public void mouseReleased(MouseEvent me) {
318:                endDrag();
319:            }
320:
321:            /** Called by the AWT when the mouse leaves the component. */
322:            public void mouseExited(MouseEvent me) {
323:                endDrag();
324:            }
325:
326:            /** Ignored. */
327:            public void mouseClicked(MouseEvent me) {
328:            }
329:
330:            /** Ignored. */
331:            public void mouseMoved(MouseEvent me) {
332:            }
333:
334:            /** Ignored. */
335:            public void mouseEntered(MouseEvent me) {
336:            }
337:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.