1 11 package org.eclipse.jdt.internal.junit.ui; 12 13 import org.eclipse.swt.graphics.Image; 14 15 18 public class ProgressImages { 19 private static final int PROGRESS_STEPS= 9; 20 21 private static final String BASE= "prgss/"; private static final String FAILURE= "ff"; private static final String OK= "ss"; 25 private Image[] fOKImages= new Image[PROGRESS_STEPS]; 26 private Image[] fFailureImages= new Image[PROGRESS_STEPS]; 27 28 private void load() { 29 if (isLoaded()) 30 return; 31 32 for (int i= 0; i < PROGRESS_STEPS; i++) { 33 String okname= BASE+OK+Integer.toString(i+1)+".gif"; fOKImages[i]= createImage(okname); 35 String failurename= BASE+FAILURE+Integer.toString(i+1)+".gif"; fFailureImages[i]= createImage(failurename); 37 } 38 } 39 40 private Image createImage(String name) { 41 return JUnitPlugin.getImageDescriptor(name).createImage(); 42 } 43 44 public void dispose() { 45 if (!isLoaded()) 46 return; 47 48 for (int i= 0; i < PROGRESS_STEPS; i++) { 49 fOKImages[i].dispose(); 50 fOKImages[i]= null; 51 fFailureImages[i].dispose(); 52 fFailureImages[i]= null; 53 } 54 } 55 56 public Image getImage(int current, int total, int errors, int failures) { 57 if (!isLoaded()) 58 load(); 59 60 if (total == 0) 61 return fOKImages[0]; 62 int index= ((current*PROGRESS_STEPS)/total)-1; 63 index= Math.min(Math.max(0, index), PROGRESS_STEPS-1); 64 65 if (errors + failures == 0) 66 return fOKImages[index]; 67 return fFailureImages[index]; 68 } 69 70 private boolean isLoaded() { 71 return fOKImages[0] != null; 72 } 73 } 74 | Popular Tags |