1 11 package org.eclipse.ui.internal; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 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 30 public abstract class RectangleAnimationFeedbackBase extends AnimationFeedbackBase { 31 32 private List startRects = new ArrayList (); 33 private List endRects = new ArrayList (); 34 35 42 public RectangleAnimationFeedbackBase(Shell parentShell, Rectangle start, 43 Rectangle end) { 44 super(parentShell); 45 addStartRect(start); 46 addEndRect(end); 47 } 48 49 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 getStartRects() { 98 return startRects; 99 } 100 101 public List getEndRects() { 102 return endRects; 103 } 104 105 public List getCurrentRects(double amount) { 106 List currentRects = new ArrayList (); 107 Iterator startIter = getStartRects().iterator(); 108 Iterator endIter = getEndRects().iterator(); 109 while (startIter.hasNext()) { 110 Rectangle start = (Rectangle) startIter.next(); 111 Rectangle end = (Rectangle) endIter.next(); 112 113 Rectangle curRect = interpolate(start, end, amount); 115 currentRects.add(curRect); 116 } 117 return currentRects; 118 } 119 120 } 121 | Popular Tags |