KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > progress > AnimationItem


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.progress;
12
13 import org.eclipse.swt.events.DisposeEvent;
14 import org.eclipse.swt.events.DisposeListener;
15 import org.eclipse.swt.events.MouseEvent;
16 import org.eclipse.swt.events.MouseListener;
17 import org.eclipse.swt.events.PaintEvent;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.graphics.ImageData;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.ui.internal.WorkbenchWindow;
23
24 /**
25  * The AnimationItem is the class that manages the animation for the progress.
26  */

27 public abstract class AnimationItem {
28     WorkbenchWindow window;
29
30     interface IAnimationContainer {
31         /**
32          * The animation has started.
33          */

34         public abstract void animationStart();
35
36         /**
37          * The animation has ended.
38          */

39         public abstract void animationDone();
40     }
41
42     //Create a containter that does nothing by default
43
IAnimationContainer animationContainer = new IAnimationContainer() {
44         /* (non-Javadoc)
45          * @see org.eclipse.ui.internal.progress.AnimationItem.IAnimationContainer#animationDone()
46          */

47         public void animationDone() {
48             //Do nothing by default
49
}
50
51         /* (non-Javadoc)
52          * @see org.eclipse.ui.internal.progress.AnimationItem.IAnimationContainer#animationStart()
53          */

54         public void animationStart() {
55             //Do nothing by default
56
}
57     };
58
59     /**
60      * Create a new instance of the receiver.
61      *
62      * @param workbenchWindow
63      * the window being created
64      */

65     public AnimationItem(WorkbenchWindow workbenchWindow) {
66         this.window = workbenchWindow;
67     }
68
69     /**
70      * Create the canvas that will display the image.
71      *
72      * @param parent
73      */

74     public void createControl(Composite parent) {
75
76         Control animationItem = createAnimationItem(parent);
77
78         animationItem.addMouseListener(new MouseListener() {
79             /*
80              * (non-Javadoc)
81              *
82              * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
83              */

84             public void mouseDoubleClick(MouseEvent arg0) {
85                 ProgressManagerUtil.openProgressView(AnimationItem.this.window);
86             }
87
88             /*
89              * (non-Javadoc)
90              *
91              * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
92              */

93             public void mouseDown(MouseEvent arg0) {
94                 //Do nothing
95
}
96
97             /*
98              * (non-Javadoc)
99              *
100              * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
101              */

102             public void mouseUp(MouseEvent arg0) {
103                 //Do nothing
104
}
105         });
106         animationItem.addDisposeListener(new DisposeListener() {
107             public void widgetDisposed(DisposeEvent e) {
108                 AnimationManager.getInstance().removeItem(AnimationItem.this);
109             }
110         });
111         AnimationManager.getInstance().addItem(this);
112     }
113
114     /**
115      * Create the animation item control.
116      * @param parent the parent Composite
117      * @return Control
118      */

119     protected abstract Control createAnimationItem(Composite parent);
120
121     /**
122      * Paint the image in the canvas.
123      *
124      * @param event
125      * The PaintEvent that generated this call.
126      * @param image
127      * The image to display
128      * @param imageData
129      * The array of ImageData. Required to show an animation.
130      */

131     void paintImage(PaintEvent event, Image image, ImageData imageData) {
132         event.gc.drawImage(image, 0, 0);
133     }
134
135     /**
136      * Get the SWT control for the receiver.
137      *
138      * @return Control
139      */

140     public abstract Control getControl();
141
142     /**
143      * The animation has begun.
144      */

145     void animationStart() {
146         animationContainer.animationStart();
147     }
148
149     /**
150      * The animation has ended.
151      */

152     void animationDone() {
153         animationContainer.animationDone();
154     }
155
156     /**
157      * Get the preferred width of the receiver.
158      *
159      * @return int
160      */

161     public int getPreferredWidth() {
162         return AnimationManager.getInstance().getPreferredWidth() + 5;
163     }
164
165     /**
166      * Set the container that will be updated when this runs.
167      * @param container The animationContainer to set.
168      */

169     void setAnimationContainer(IAnimationContainer container) {
170         this.animationContainer = container;
171     }
172 }
173
Popular Tags