KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > DefaultAnimationFeedback


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
12 package org.eclipse.ui.internal;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.jface.util.Geometry;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.graphics.Color;
21 import org.eclipse.swt.graphics.Rectangle;
22 import org.eclipse.swt.graphics.Region;
23 import org.eclipse.swt.widgets.Display;
24 import org.eclipse.swt.widgets.Shell;
25
26 /**
27  * @since 3.3
28  *
29  */

30 public class DefaultAnimationFeedback {
31     private static final int LINE_WIDTH = 1;
32     
33     private Display display;
34     private Shell theShell;
35     private Region shellRegion;
36     
37     private List JavaDoc startRects = new ArrayList JavaDoc();
38     private List JavaDoc endRects = new ArrayList JavaDoc();
39     
40     public DefaultAnimationFeedback() {}
41
42     /**
43      * @param parentShell
44      */

45     public void initialize(Shell parentShell, Rectangle startRect, Rectangle endRect) {
46         addStartRect(startRect);
47         addEndRect(endRect);
48
49         theShell = new Shell(parentShell, SWT.NO_TRIM | SWT.ON_TOP);
50         display = theShell.getDisplay();
51         Color color = display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
52         theShell.setBackground(color);
53
54         // Ensure that the background won't show on the initial display
55
shellRegion = new Region(display);
56         theShell.setRegion(shellRegion);
57     }
58     
59     public void addStartRect(Rectangle rect) {
60         if (rect != null) {
61             startRects.add(rect);
62         }
63     }
64     
65     public void addEndRect(Rectangle rect) {
66         if (rect != null) {
67             endRects.add(rect);
68         }
69     }
70     
71     public List JavaDoc getStartRects() {
72         return startRects;
73     }
74     
75     public List JavaDoc getEndRects() {
76         return endRects;
77     }
78     
79     public void renderStep(double amount) {
80         if (shellRegion != null) {
81             shellRegion.dispose();
82             shellRegion = new Region(display);
83         }
84
85         // Iterate across the set of start/end rects
86
Iterator JavaDoc startIter = startRects.iterator();
87         Iterator JavaDoc endIter = endRects.iterator();
88         while (startIter.hasNext()) {
89             Rectangle start = (Rectangle) startIter.next();
90             Rectangle end = (Rectangle) endIter.next();
91             
92             // Get the bounds of the interpolated rect
93
Rectangle curRect = RectangleAnimation.interpolate(start, end, amount);
94             
95             Rectangle rect = Geometry.toControl(theShell, curRect);
96             shellRegion.add(rect);
97             rect.x += LINE_WIDTH;
98             rect.y += LINE_WIDTH;
99             rect.width = Math.max(0, rect.width - 2 * LINE_WIDTH);
100             rect.height = Math.max(0, rect.height - 2 * LINE_WIDTH);
101     
102             shellRegion.subtract(rect);
103         }
104
105         theShell.setRegion(shellRegion);
106         
107         display.update();
108     }
109
110     /**
111      *
112      */

113     public void dispose() {
114         theShell.setVisible(false);
115         theShell.dispose();
116         shellRegion.dispose();
117     }
118
119     /**
120      * Perform any initialization you want to have happen -before- the
121      * amination starts
122      */

123     public void jobInit() {
124         // Compute the shell's bounds
125
Rectangle shellBounds = Geometry.copy((Rectangle) startRects.get(0));
126         Iterator JavaDoc startIter = startRects.iterator();
127         Iterator JavaDoc endIter = endRects.iterator();
128         while (startIter.hasNext()) {
129             shellBounds.add((Rectangle) startIter.next());
130             shellBounds.add((Rectangle) endIter.next());
131         }
132         theShell.setBounds(shellBounds);
133         
134         // Making the shell visible will be slow on old video cards, so only start
135
// the timer once it is visible.
136
theShell.setVisible(true);
137     }
138 }
139
Popular Tags