1 13 package org.eclipse.ui.internal.decorators; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.viewers.DecorationContext; 20 import org.eclipse.jface.viewers.IDecoration; 21 import org.eclipse.jface.viewers.IDecorationContext; 22 import org.eclipse.swt.graphics.Color; 23 import org.eclipse.swt.graphics.Font; 24 import org.eclipse.ui.internal.WorkbenchPlugin; 25 26 29 public class DecorationBuilder implements IDecoration { 30 31 private static int DECORATOR_ARRAY_SIZE = 5; 32 33 private List prefixes = new ArrayList (); 34 35 private List suffixes = new ArrayList (); 36 37 private ImageDescriptor[] descriptors = new ImageDescriptor[DECORATOR_ARRAY_SIZE]; 38 39 private Color foregroundColor; 40 41 private Color backgroundColor; 42 43 private Font font; 44 45 LightweightDecoratorDefinition currentDefinition; 46 47 private boolean valueSet = false; 49 50 private final IDecorationContext context; 51 52 55 DecorationBuilder() { 56 this(DecorationContext.DEFAULT_CONTEXT); 57 } 58 59 63 public DecorationBuilder(IDecorationContext context) { 64 this.context = context; 65 } 66 67 72 void setCurrentDefinition(LightweightDecoratorDefinition definition) { 73 this.currentDefinition = definition; 74 } 75 76 79 public void addOverlay(ImageDescriptor overlay) { 80 int quadrant = currentDefinition.getQuadrant(); 81 if (descriptors[quadrant] == null) { 82 descriptors[quadrant] = overlay; 83 } 84 valueSet = true; 85 } 86 87 90 public void addOverlay(ImageDescriptor overlay, int quadrant) { 91 if (quadrant >= 0 && quadrant < DECORATOR_ARRAY_SIZE) { 92 if (descriptors[quadrant] == null) { 93 descriptors[quadrant] = overlay; 94 } 95 valueSet = true; 96 } else { 97 WorkbenchPlugin 98 .log("Unable to apply decoration for " + currentDefinition.getId() + " invalid quadrant: " + quadrant); } 100 } 101 102 105 public void addPrefix(String prefixString) { 106 prefixes.add(prefixString); 107 valueSet = true; 108 } 109 110 113 public void addSuffix(String suffixString) { 114 suffixes.add(suffixString); 115 valueSet = true; 116 } 117 118 122 DecorationResult createResult() { 123 DecorationResult newResult = new DecorationResult(new ArrayList ( 124 prefixes), new ArrayList (suffixes), descriptors, 125 foregroundColor, backgroundColor, font); 126 127 return newResult; 128 } 129 130 133 void clearContents() { 134 this.prefixes.clear(); 135 this.suffixes.clear(); 136 this.descriptors = new ImageDescriptor[DECORATOR_ARRAY_SIZE]; 137 valueSet = false; 138 } 139 140 145 boolean hasValue() { 146 return valueSet; 147 } 148 149 154 void applyResult(DecorationResult result) { 155 prefixes.addAll(result.getPrefixes()); 156 suffixes.addAll(result.getSuffixes()); 157 ImageDescriptor[] resultDescriptors = result.getDescriptors(); 158 if (resultDescriptors != null) { 159 for (int i = 0; i < descriptors.length; i++) { 160 if (resultDescriptors[i] != null) { 161 descriptors[i] = resultDescriptors[i]; 162 } 163 } 164 } 165 166 setForegroundColor(result.getForegroundColor()); 167 setBackgroundColor(result.getBackgroundColor()); 168 setFont(result.getFont()); 169 valueSet = true; 170 } 171 172 176 177 public void setBackgroundColor(Color bgColor) { 178 this.backgroundColor = bgColor; 179 valueSet = true; 180 } 181 182 186 public void setFont(Font newFont) { 187 this.font = newFont; 188 valueSet = true; 189 } 190 191 195 public void setForegroundColor(Color fgColor) { 196 this.foregroundColor = fgColor; 197 valueSet = true; 198 } 199 200 203 public IDecorationContext getDecorationContext() { 204 return context; 205 } 206 } 207 | Popular Tags |