1 11 package org.eclipse.ant.internal.ui.views.actions; 12 13 14 import org.eclipse.jface.resource.ImageDescriptor; 15 import org.eclipse.swt.graphics.Image; 16 import org.eclipse.swt.graphics.ImageData; 17 import org.eclipse.swt.program.Program; 18 import org.eclipse.ui.ISharedImages; 19 import org.eclipse.ui.PlatformUI; 20 21 25 public class EditorImageDescriptor extends ImageDescriptor { 26 27 public Program program; 28 29 33 public EditorImageDescriptor(Program program) { 34 this.program = program; 35 } 36 39 public boolean equals(Object o) { 40 if (!(o instanceof EditorImageDescriptor)) { 41 return false; 42 } 43 EditorImageDescriptor other = (EditorImageDescriptor) o; 44 45 String otherName = other.program.getName(); 47 if (otherName == null) { 48 return other.program.equals(program); 49 } 50 return otherName.equals(program.getName()); 51 } 52 56 public Image getImage() { 57 return createImage(); 58 } 59 60 63 public ImageData getImageData() { 64 65 ImageData defaultImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE).getImageData(); 66 if (defaultImage == null) { 67 return null; 68 } 69 ImageData data = null; 70 if (program == null || ((data = program.getImageData()) == null)) { 71 return defaultImage; 72 } 73 74 if (data.height > defaultImage.height || data.width > defaultImage.width) { 76 return defaultImage; 77 } 78 79 return data; 80 } 81 82 85 public int hashCode() { 86 String programName = program.getName(); 87 if (programName == null) { 88 return program.hashCode(); 89 } 90 return programName.hashCode(); 91 } 92 } 93 | Popular Tags |