001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.internal;
011:
012: import java.util.Iterator;
013:
014: import org.eclipse.jface.util.Geometry;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.graphics.Color;
017: import org.eclipse.swt.graphics.Rectangle;
018: import org.eclipse.swt.graphics.Region;
019: import org.eclipse.swt.widgets.Display;
020: import org.eclipse.swt.widgets.Shell;
021:
022: /**
023: * Creates an animation feedback that will morph the start rectangle to the end rectangle
024: * for AnimationEngine.
025: *
026: * @since 3.3
027: *
028: */
029: public class LegacyAnimationFeedback extends
030: RectangleAnimationFeedbackBase {
031: private static final int LINE_WIDTH = 1;
032:
033: private Display display;
034: private Region shellRegion;
035:
036: private Shell theShell;
037:
038: public LegacyAnimationFeedback(Shell parentShell, Rectangle start,
039: Rectangle end) {
040: super (parentShell, start, end);
041: }
042:
043: public void renderStep(AnimationEngine engine) {
044: if (shellRegion != null) {
045: shellRegion.dispose();
046: shellRegion = new Region(display);
047: }
048:
049: // Iterate across the set of start/end rects
050: Iterator currentRects = getCurrentRects(engine.amount())
051: .iterator();
052: while (currentRects.hasNext()) {
053: Rectangle curRect = (Rectangle) currentRects.next();
054: Rectangle rect = Geometry.toControl(theShell, curRect);
055: shellRegion.add(rect);
056: rect.x += LINE_WIDTH;
057: rect.y += LINE_WIDTH;
058: rect.width = Math.max(0, rect.width - 2 * LINE_WIDTH);
059: rect.height = Math.max(0, rect.height - 2 * LINE_WIDTH);
060:
061: shellRegion.subtract(rect);
062: }
063:
064: theShell.setRegion(shellRegion);
065:
066: display.update();
067: }
068:
069: /* (non-Javadoc)
070: * @see org.eclipse.ui.internal.AnimationFeedbackBase#initialize(org.eclipse.ui.internal.AnimationEngine)
071: */
072: public void initialize(AnimationEngine engine) {
073:
074: theShell = new Shell(getAnimationShell(), SWT.NO_TRIM
075: | SWT.ON_TOP);
076: display = theShell.getDisplay();
077: Color color = display
078: .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
079: theShell.setBackground(color);
080:
081: // Ensure that the background won't show on the initial display
082: shellRegion = new Region(display);
083: theShell.setRegion(shellRegion);
084: }
085:
086: /* (non-Javadoc)
087: * @see org.eclipse.ui.internal.AnimationFeedbackBase#dispose()
088: */
089: public void dispose() {
090: theShell.setVisible(false);
091: theShell.dispose();
092: shellRegion.dispose();
093: }
094:
095: /**
096: * Perform any initialization you want to have happen -before- the
097: * amination starts
098: */
099: public boolean jobInit(AnimationEngine engine) {
100: if (!super .jobInit(engine))
101: return false;
102:
103: // Compute the shell's bounds
104: Rectangle shellBounds = Geometry
105: .copy((Rectangle) getStartRects().get(0));
106: Iterator startIter = getStartRects().iterator();
107: Iterator endIter = getEndRects().iterator();
108: while (startIter.hasNext()) {
109: shellBounds.add((Rectangle) startIter.next());
110: shellBounds.add((Rectangle) endIter.next());
111: }
112: theShell.setBounds(shellBounds);
113: // Making the shell visible will be slow on old video cards, so only start
114: // the timer once it is visible.
115: theShell.setVisible(true);
116:
117: return true; // OK to go...
118: }
119:
120: }
|