KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jface.util.Geometry;
18 import org.eclipse.swt.graphics.Rectangle;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.ui.internal.AnimationEngine;
22 import org.eclipse.ui.internal.AnimationFeedbackBase;
23
24 /**
25  * RectangleAnimationFeedbackBase is an abstract base class for all the
26  * rectangle animations.
27  * @since 3.3
28  *
29  */

30 public abstract class RectangleAnimationFeedbackBase extends AnimationFeedbackBase {
31
32     private List JavaDoc startRects = new ArrayList JavaDoc();
33     private List JavaDoc endRects = new ArrayList JavaDoc();
34
35     /**
36      * Creates a Rectangle Animation Feedback
37      *
38      * @param parentShell specifies the composite where the animation will be drawn
39      * @param start initial rectangle (display coordinates)
40      * @param end final rectangle (display coordinates)
41      */

42     public RectangleAnimationFeedbackBase(Shell parentShell, Rectangle start,
43             Rectangle end) {
44         super(parentShell);
45         addStartRect(start);
46         addEndRect(end);
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.ui.internal.AnimationFeedbackBase#jobInit(org.eclipse.ui.internal.AnimationEngine)
51      *
52      * Prevent execution if there are no rects to draw or there's a mismatch in the count
53      */

54     public boolean jobInit(AnimationEngine engine) {
55         if (!super.jobInit(engine))
56             return false;
57         
58         return startRects.size() > 0 && startRects.size() == endRects.size();
59     }
60
61     public void addStartRect(Rectangle rect) {
62         if (rect != null) {
63             startRects.add(rect);
64         }
65     }
66
67     public void addEndRect(Rectangle rect) {
68         if (rect != null) {
69             endRects.add(rect);
70         }
71     }
72
73     public void addStartRect(Control ctrl) {
74         Rectangle ctrlBounds = ctrl.getBounds();
75         Rectangle startRect = Geometry.toDisplay(ctrl.getParent(), ctrlBounds);
76         addStartRect(startRect);
77     }
78
79     public void addEndRect(Control ctrl) {
80         Rectangle ctrlBounds = ctrl.getBounds();
81         Rectangle endRect = Geometry.toDisplay(ctrl.getParent(), ctrlBounds);
82         addEndRect(endRect);
83     }
84
85     public static Rectangle interpolate(Rectangle start, Rectangle end,
86             double amount) {
87         double initialWeight = 1.0 - amount;
88
89         Rectangle result = new Rectangle((int) (start.x * initialWeight + end.x
90                 * amount), (int) (start.y * initialWeight + end.y * amount),
91                 (int) (start.width * initialWeight + end.width * amount),
92                 (int) (start.height * initialWeight + end.height * amount));
93
94         return result;
95     }
96
97     public List JavaDoc getStartRects() {
98         return startRects;
99     }
100
101     public List JavaDoc getEndRects() {
102         return endRects;
103     }
104
105     public List JavaDoc getCurrentRects(double amount) {
106         List JavaDoc currentRects = new ArrayList JavaDoc();
107         Iterator JavaDoc startIter = getStartRects().iterator();
108         Iterator JavaDoc endIter = getEndRects().iterator();
109         while (startIter.hasNext()) {
110             Rectangle start = (Rectangle) startIter.next();
111             Rectangle end = (Rectangle) endIter.next();
112
113             // Get the bounds of the interpolated rect
114
Rectangle curRect = interpolate(start, end, amount);
115             currentRects.add(curRect);
116         }
117         return currentRects;
118     }
119
120 }
121
Popular Tags