Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
blob: 9e5e8324641b6c724371ef35c1a4ef26f3811920 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/

package org.eclipse.ui.internal;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.util.Geometry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Region;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * @since 3.3
 *
 */
public class DefaultAnimationFeedback {
	private static final int LINE_WIDTH = 1;
	
	private Display display;
	private Shell theShell;
	private Region shellRegion;
	
	private List startRects = new ArrayList();
	private List endRects = new ArrayList();
	
	public DefaultAnimationFeedback() {}

    /**
	 * @param parentShell
	 */
	public void initialize(Shell parentShell, Rectangle startRect, Rectangle endRect) {
		addStartRect(startRect);
		addEndRect(endRect);

		theShell = new Shell(parentShell, SWT.NO_TRIM | SWT.ON_TOP);
		display = theShell.getDisplay();
        Color color = display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
        theShell.setBackground(color);

        // Ensure that the background won't show on the initial display
        shellRegion = new Region(display);
        theShell.setRegion(shellRegion);
	}
	
	public void addStartRect(Rectangle rect) {
		if (rect != null) {
			startRects.add(rect);
		}
	}
	
	public void addEndRect(Rectangle rect) {
		if (rect != null) {
			endRects.add(rect);
		}
	}
	
	public void renderStep(double amount) {
		if (shellRegion != null) {
        	shellRegion.dispose();
        	shellRegion = new Region(display);
        }

		// Iterate across the set of start/end rects
        Iterator startIter = startRects.iterator();
        Iterator endIter = endRects.iterator();
        while (startIter.hasNext()) {
            Rectangle start = (Rectangle) startIter.next();
            Rectangle end = (Rectangle) endIter.next();
            
			// Get the bounds of the interpolated rect
			Rectangle curRect = RectangleAnimation.interpolate(start, end, amount);
			
	        Rectangle rect = Geometry.toControl(theShell, curRect);
	        shellRegion.add(rect);
	        rect.x += LINE_WIDTH;
	        rect.y += LINE_WIDTH;
	        rect.width = Math.max(0, rect.width - 2 * LINE_WIDTH);
	        rect.height = Math.max(0, rect.height - 2 * LINE_WIDTH);
	
	        shellRegion.subtract(rect);
        }

        theShell.setRegion(shellRegion);
        
        display.update();
	}

	/**
	 * 
	 */
	public void dispose() {
		theShell.setVisible(false);
		theShell.dispose();
		shellRegion.dispose();
	}

	/**
	 * Perform any initialization you want to have happen -before- the
	 * amination starts
	 */
	public void jobInit() {
    	// Compute the shell's bounds
        Rectangle shellBounds = Geometry.copy((Rectangle) startRects.get(0));
        Iterator startIter = startRects.iterator();
        Iterator endIter = endRects.iterator();
        while (startIter.hasNext()) {
            shellBounds.add((Rectangle) startIter.next());
            shellBounds.add((Rectangle) endIter.next());
        }
        theShell.setBounds(shellBounds);
        
    	// Making the shell visible will be slow on old video cards, so only start
    	// the timer once it is visible.
    	theShell.setVisible(true);
	}
}

Back to the top