KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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 package org.eclipse.ui.internal;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.eclipse.jface.util.Geometry;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.graphics.Color;
18 import org.eclipse.swt.graphics.Rectangle;
19 import org.eclipse.swt.graphics.Region;
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.swt.widgets.Shell;
22
23 /**
24  * Creates an animation feedback that will morph the start rectangle to the end rectangle
25  * for AnimationEngine.
26  *
27  * @since 3.3
28  *
29  */

30 public class LegacyAnimationFeedback extends RectangleAnimationFeedbackBase {
31     private static final int LINE_WIDTH = 1;
32
33     private Display display;
34     private Region shellRegion;
35
36     private Shell theShell;
37
38     public LegacyAnimationFeedback(Shell parentShell, Rectangle start,
39             Rectangle end) {
40         super(parentShell, start, end);
41     }
42
43     public void renderStep(AnimationEngine engine) {
44         if (shellRegion != null) {
45             shellRegion.dispose();
46             shellRegion = new Region(display);
47         }
48
49         // Iterate across the set of start/end rects
50
Iterator JavaDoc currentRects = getCurrentRects(engine.amount()).iterator();
51         while (currentRects.hasNext()) {
52             Rectangle curRect = (Rectangle) currentRects.next();
53             Rectangle rect = Geometry.toControl(theShell, curRect);
54             shellRegion.add(rect);
55             rect.x += LINE_WIDTH;
56             rect.y += LINE_WIDTH;
57             rect.width = Math.max(0, rect.width - 2 * LINE_WIDTH);
58             rect.height = Math.max(0, rect.height - 2 * LINE_WIDTH);
59
60             shellRegion.subtract(rect);
61         }
62
63         theShell.setRegion(shellRegion);
64
65         display.update();
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.ui.internal.AnimationFeedbackBase#initialize(org.eclipse.ui.internal.AnimationEngine)
70      */

71     public void initialize(AnimationEngine engine) {
72
73         theShell = new Shell(getAnimationShell(), SWT.NO_TRIM | SWT.ON_TOP);
74         display = theShell.getDisplay();
75         Color color = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
76         theShell.setBackground(color);
77
78         // Ensure that the background won't show on the initial display
79
shellRegion = new Region(display);
80         theShell.setRegion(shellRegion);
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.ui.internal.AnimationFeedbackBase#dispose()
85      */

86     public void dispose() {
87         theShell.setVisible(false);
88         theShell.dispose();
89         shellRegion.dispose();
90     }
91
92     /**
93      * Perform any initialization you want to have happen -before- the
94      * amination starts
95      */

96     public boolean jobInit(AnimationEngine engine) {
97         if (!super.jobInit(engine))
98             return false;
99         
100         // Compute the shell's bounds
101
Rectangle shellBounds = Geometry.copy((Rectangle) getStartRects()
102                 .get(0));
103         Iterator JavaDoc startIter = getStartRects().iterator();
104         Iterator JavaDoc endIter = getEndRects().iterator();
105         while (startIter.hasNext()) {
106             shellBounds.add((Rectangle) startIter.next());
107             shellBounds.add((Rectangle) endIter.next());
108         }
109         theShell.setBounds(shellBounds);
110         // Making the shell visible will be slow on old video cards, so only start
111
// the timer once it is visible.
112
theShell.setVisible(true);
113         
114         return true; // OK to go...
115
}
116
117 }
118
Popular Tags