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.SWT; 19 import org.eclipse.swt.events.PaintEvent; 20 import org.eclipse.swt.events.PaintListener; 21 import org.eclipse.swt.graphics.GC; 22 import org.eclipse.swt.graphics.Image; 23 import org.eclipse.swt.graphics.Rectangle; 24 import org.eclipse.swt.widgets.Canvas; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Display; 27 import org.eclipse.swt.widgets.Shell; 28 import org.eclipse.ui.internal.AnimationEngine; 29 30 38 public class RectangleAnimationImageFeedback extends 39 RectangleAnimationFeedbackBase { 40 private class ImageCanvas extends Canvas { 41 private Image image; 42 43 47 public ImageCanvas(Composite parent, int style, Image image) { 48 super(parent, style); 49 this.image = image; 50 51 addPaintListener(new PaintListener() { 52 public void paintControl(PaintEvent e) { 53 paintImage(e.gc); 54 } 55 }); 56 } 57 58 61 protected void paintImage(GC gc) { 62 gc.drawImage(image, 0, 0, image.getBounds().width, image 63 .getBounds().height, 0, 0, getBounds().width, 64 getBounds().height); 65 } 66 67 70 public void dispose() { 71 super.dispose(); 72 image.dispose(); 73 } 74 } 75 76 private Image backingStore; 77 private Shell theShell; 78 private Display display; 79 private List controls = new ArrayList (); 80 81 82 public RectangleAnimationImageFeedback(Shell parentShell, Rectangle start, 83 Rectangle end) { 84 super(parentShell, start, end); 85 } 86 87 public void dispose() { 88 backingStore.dispose(); 89 for (Iterator ctrlIter = controls.iterator(); ctrlIter.hasNext();) { 90 ImageCanvas canvas = (ImageCanvas) ctrlIter.next(); 91 canvas.dispose(); 92 } 93 94 theShell.setVisible(false); 95 theShell.dispose(); 96 } 97 98 public void initialize(AnimationEngine engine) { 99 display = getAnimationShell().getDisplay(); 100 101 Rectangle psRect = getAnimationShell().getBounds(); 102 theShell = new Shell(getAnimationShell(), SWT.NO_TRIM | SWT.ON_TOP); 103 theShell.setBounds(getAnimationShell().getBounds()); 104 105 backingStore = new Image(theShell.getDisplay(), psRect); 107 GC gc = new GC(display); 108 gc.copyArea(backingStore, psRect.x, psRect.y); 109 gc.dispose(); 110 theShell.setBackgroundImage(backingStore); 113 theShell.setVisible(true); 114 display.update(); 115 116 } 117 118 121 public boolean jobInit(AnimationEngine engine) { 122 changeCoordinates(); 123 captureImages(); 124 return super.jobInit(engine); 125 } 126 127 public void addStartRect(Rectangle rect) { 128 if (rect == null) 129 return; 130 131 super.addStartRect(rect); 133 134 } 135 136 public void addEndRect(Rectangle rect) { 137 if (rect != null) { 138 super.addEndRect(rect); 140 } 141 } 142 143 public void renderStep(AnimationEngine engine) { 144 Iterator ctrlIter = controls.iterator(); 145 Iterator currentRects = getCurrentRects(engine.amount()).iterator(); 146 while (currentRects.hasNext()) { 147 ImageCanvas canvas = (ImageCanvas) ctrlIter.next(); 148 canvas.setBounds((Rectangle) currentRects.next()); 149 } 150 display.update(); 151 152 } 153 154 public void changeCoordinates() { 155 Iterator startRectIter = getStartRects().iterator(); 156 Iterator endRectIter = getEndRects().iterator(); 157 while (startRectIter.hasNext()) { 158 Rectangle startRect = (Rectangle) startRectIter.next(); 159 Rectangle mapStartRect = Geometry.toControl(theShell, startRect); 160 startRect.x = mapStartRect.x; 161 startRect.y = mapStartRect.y; 162 Rectangle endRect = (Rectangle) endRectIter.next(); 163 Rectangle mapEndRect = Geometry.toControl(theShell, endRect); 164 endRect.x = mapEndRect.x; 165 endRect.y = mapEndRect.y; 166 } 167 } 168 169 private void captureImages() { 170 171 for (Iterator iterator = getStartRects().iterator(); iterator.hasNext();) { 172 Rectangle rect = (Rectangle) iterator.next(); 173 Image image = new Image(display, rect.width, rect.height); 174 GC gc = new GC(backingStore); 175 gc.copyArea(image, rect.x, rect.y); 176 gc.dispose(); 177 ImageCanvas canvas = new ImageCanvas(theShell, SWT.BORDER 178 | SWT.NO_BACKGROUND, image); 179 controls.add(canvas); 180 181 } 182 } 183 184 } 185 | Popular Tags |