1 11 12 package org.eclipse.ui.internal.cheatsheets.composite.explorer; 13 14 import org.eclipse.jface.resource.*; 15 import org.eclipse.swt.graphics.*; 16 17 20 public abstract class AbstractOverlayIcon extends CompositeImageDescriptor { 21 22 static final int DEFAULT_WIDTH = 16; 23 static final int DEFAULT_HEIGHT = 16; 24 25 private Point fSize = null; 26 27 private ImageDescriptor fOverlays[][]; 28 29 public AbstractOverlayIcon(ImageDescriptor[][] overlays) { 30 this(overlays, null); 31 } 32 33 public AbstractOverlayIcon(ImageDescriptor[][] overlays, Point size) { 34 fOverlays = overlays; 35 if (size != null) 36 fSize = size; 37 else 38 fSize = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT); 39 } 40 protected void drawBottomLeft(ImageDescriptor[] overlays) { 41 if (overlays == null) 42 return; 43 int length = overlays.length; 44 int x = 0; 45 for (int i = 0; i < 3; i++) { 46 if (i < length && overlays[i] != null) { 47 ImageData id = overlays[i].getImageData(); 48 drawImage(id, x, getSize().y - id.height); 49 x += id.width; 50 } 51 } 52 } 53 protected void drawBottomRight(ImageDescriptor[] overlays) { 54 if (overlays == null) 55 return; 56 int length = overlays.length; 57 int x = getSize().x; 58 for (int i = 2; i >= 0; i--) { 59 if (i < length && overlays[i] != null) { 60 ImageData id = overlays[i].getImageData(); 61 x -= id.width; 62 drawImage(id, x, getSize().y - id.height); 63 } 64 } 65 } 66 67 protected abstract ImageData getBaseImageData(); 68 69 protected void drawCompositeImage(int width, int height) { 70 ImageData base = getBaseImageData(); 71 drawImage(base, 0, 0); 72 if (fOverlays != null) { 73 if (fOverlays.length > 0) 74 drawTopRight(fOverlays[0]); 75 76 if (fOverlays.length > 1) 77 drawBottomRight(fOverlays[1]); 78 79 if (fOverlays.length > 2) 80 drawBottomLeft(fOverlays[2]); 81 82 if (fOverlays.length > 3) 83 drawTopLeft(fOverlays[3]); 84 } 85 } 86 protected void drawTopLeft(ImageDescriptor[] overlays) { 87 if (overlays == null) 88 return; 89 int length = overlays.length; 90 int x = 0; 91 for (int i = 0; i < 3; i++) { 92 if (i < length && overlays[i] != null) { 93 ImageData id = overlays[i].getImageData(); 94 drawImage(id, x, 0); 95 x += id.width; 96 } 97 } 98 } 99 protected void drawTopRight(ImageDescriptor[] overlays) { 100 if (overlays == null) 101 return; 102 int length = overlays.length; 103 int x = getSize().x; 104 for (int i = 2; i >= 0; i--) { 105 if (i < length && overlays[i] != null) { 106 ImageData id = overlays[i].getImageData(); 107 x -= id.width; 108 drawImage(id, x, 0); 109 } 110 } 111 } 112 113 protected Point getSize() { 114 return fSize; 115 } 116 } 117 | Popular Tags |