1 11 package org.eclipse.ui.internal.decorators; 12 13 import java.util.List ; 14 import java.util.ListIterator ; 15 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.swt.graphics.Color; 18 import org.eclipse.swt.graphics.Font; 19 import org.eclipse.swt.graphics.Image; 20 21 24 public class DecorationResult { 25 26 private List prefixes; 27 28 private List suffixes; 29 30 private ImageDescriptor[] descriptors; 31 32 private Color foregroundColor; 33 34 private Color backgroundColor; 35 36 private Font font; 37 38 DecorationResult(List prefixList, List suffixList, 39 ImageDescriptor[] imageDescriptors, 40 Color resultForegroundColor, 41 Color resultBackgroundColor, 42 Font resultFont) { 43 prefixes = prefixList; 44 suffixes = suffixList; 45 46 if (hasOverlays(imageDescriptors)) { 48 descriptors = imageDescriptors; 49 } 50 foregroundColor = resultForegroundColor; 51 backgroundColor = resultBackgroundColor; 52 font = resultFont; 53 } 54 55 62 private boolean hasOverlays(ImageDescriptor[] imageDescriptors) { 63 for (int i = 0; i < imageDescriptors.length; i++) { 64 if (imageDescriptors[i] != null) { 65 return true; 66 } 67 } 68 return false; 69 } 70 71 77 Image decorateWithOverlays(Image image, OverlayCache overlayCache) { 78 79 if (image == null || descriptors == null) { 81 return image; 82 } 83 84 return overlayCache.applyDescriptors(image, descriptors); 85 } 86 87 94 public String decorateWithText(String text) { 95 96 if (prefixes.isEmpty() && suffixes.isEmpty()) { 97 return text; 98 } 99 100 StringBuffer result = new StringBuffer (); 101 102 ListIterator prefixIterator = prefixes.listIterator(); 103 104 while (prefixIterator.hasNext()) { 105 result.append(prefixIterator.next()); 106 } 107 108 result.append(text); 109 110 ListIterator suffixIterator = suffixes.listIterator(); 111 112 while (suffixIterator.hasNext()) { 113 result.append(suffixIterator.next()); 114 } 115 116 return result.toString(); 117 } 118 119 123 ImageDescriptor[] getDescriptors() { 124 return descriptors; 125 } 126 127 131 List getPrefixes() { 132 return prefixes; 133 } 134 135 139 List getSuffixes() { 140 return suffixes; 141 } 142 143 147 Color getBackgroundColor() { 148 return backgroundColor; 149 } 150 154 Font getFont() { 155 return font; 156 } 157 161 Color getForegroundColor() { 162 return foregroundColor; 163 } 164 } 165 | Popular Tags |