1 11 12 package org.eclipse.ui.internal; 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 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 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 startRects = new ArrayList (); 38 private List endRects = new ArrayList (); 39 40 public DefaultAnimationFeedback() {} 41 42 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 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 getStartRects() { 72 return startRects; 73 } 74 75 public List 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 Iterator startIter = startRects.iterator(); 87 Iterator endIter = endRects.iterator(); 88 while (startIter.hasNext()) { 89 Rectangle start = (Rectangle) startIter.next(); 90 Rectangle end = (Rectangle) endIter.next(); 91 92 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 113 public void dispose() { 114 theShell.setVisible(false); 115 theShell.dispose(); 116 shellRegion.dispose(); 117 } 118 119 123 public void jobInit() { 124 Rectangle shellBounds = Geometry.copy((Rectangle) startRects.get(0)); 126 Iterator startIter = startRects.iterator(); 127 Iterator 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 theShell.setVisible(true); 137 } 138 } 139 | Popular Tags |