1 11 package org.eclipse.ui.internal.misc; 12 13 import org.eclipse.jface.resource.*; 14 import org.eclipse.swt.graphics.*; 15 import java.util.*; 16 20 public class OverlayComposite extends CompositeImageDescriptor { 21 private ImageData backgroundImage; 22 private ImageData leftImage; 23 private ImageData rightImage; 24 private ImageData topImage; 25 private ImageData bottomImage; 26 27 private List foregroundImages = new ArrayList(); 28 31 public OverlayComposite(ImageData background) { 32 backgroundImage = background; 33 } 34 38 public void addForegroundImage(ImageData image) { 39 foregroundImages.add(image); 40 } 41 46 protected void drawCompositeImage(int width, int height) { 47 drawImage(backgroundImage, getLeftBound(), getTopBound()); 49 50 Iterator e = foregroundImages.iterator(); 52 while (e.hasNext()) 53 drawImage(((ImageData) e.next()), getLeftBound(), getTopBound()); 54 55 if (topImage != null) 57 drawImage(topImage, getLeftBound(), 0); 58 if (bottomImage != null) 59 drawImage(bottomImage, getLeftBound(), height - bottomImage.height); 60 if (leftImage != null) 61 drawImage(leftImage, 0, getTopBound()); 62 if (rightImage != null) 63 drawImage(rightImage, width - rightImage.width, getTopBound()); 64 65 } 66 69 public boolean equals(Object o) { 70 if (!(o instanceof OverlayComposite)) { 71 return false; 72 } 73 OverlayComposite other = (OverlayComposite) o; 74 75 return equals(backgroundImage, other.backgroundImage) 76 && equals(leftImage, other.leftImage) 77 && equals(rightImage, other.rightImage) 78 && equals(topImage, other.topImage) 79 && equals(bottomImage, other.bottomImage) 80 && equals(foregroundImages, other.foregroundImages); 81 } 82 85 private boolean equals(Object o1, Object o2) { 86 return o1 == null ? o2 == null : o1.equals(o2); 87 } 88 93 protected int getLeftBound() { 94 if (leftImage == null) 95 return 0; 96 97 return leftImage.width; 98 } 99 103 protected Point getSize() { 104 Point size = new Point(backgroundImage.width,backgroundImage.height); 106 107 if (topImage != null) 109 size.y += topImage.height; 110 111 if (bottomImage != null) 112 size.y += bottomImage.height; 113 114 if (leftImage != null) 115 size.x += leftImage.width; 116 117 if (rightImage != null) 118 size.x += rightImage.width; 119 120 return size; 121 } 122 127 protected int getTopBound() { 128 if (topImage == null) 129 return 0; 130 131 return topImage.height; 132 } 133 136 public int hashCode() { 137 return hashCode(backgroundImage) 138 + hashCode(leftImage) 139 + hashCode(rightImage) 140 + hashCode(topImage) 141 + hashCode(bottomImage) 142 + hashCode(foregroundImages); 143 } 144 148 private int hashCode(Object o) { 149 return o == null ? 0 : o.hashCode(); 150 } 151 154 public void setBottomExtension(ImageData value) { 155 bottomImage = value; 156 } 157 160 public void setLeftExtension(ImageData value) { 161 leftImage = value; 162 } 163 166 public void setRightExtension(ImageData value) { 167 rightImage = value; 168 } 169 172 public void setTopExtension(ImageData value) { 173 topImage = value; 174 } 175 } 176 | Popular Tags |