1 11 package org.eclipse.pde.internal.core.product; 12 13 import java.io.PrintWriter ; 14 import java.util.StringTokenizer ; 15 16 import org.eclipse.pde.internal.core.iproduct.IProductModel; 17 import org.eclipse.pde.internal.core.iproduct.ISplashInfo; 18 import org.w3c.dom.Element ; 19 import org.w3c.dom.Node ; 20 21 public class SplashInfo extends ProductObject implements ISplashInfo { 22 23 public static final int F_DEFAULT_BAR_X_OFFSET = 5; 24 public static final int F_DEFAULT_BAR_Y_OFFSET = 275; 25 public static final int F_DEFAULT_BAR_WIDTH = 445; 26 public static final int F_DEFAULT_BAR_HEIGHT = 15; 27 28 public static final int F_DEFAULT_MESSAGE_X_OFFSET = 7; 29 public static final int F_DEFAULT_MESSAGE_Y_OFFSET = 252; 30 public static final int F_DEFAULT_MESSAGE_WIDTH = 445; 31 public static final int F_DEFAULT_MESSAGE_HEIGHT = 20; 32 33 private static final char[] VALID_HEX_CHARS = new char[] { 34 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 35 'a', 'b', 'c', 'd', 'e', 'f', 36 'A', 'B', 'C', 'D', 'E', 'F' 37 }; 38 private static final long serialVersionUID = 1L; 39 private String fLocation; 40 private boolean fCustomizeProgressBar; 41 private int[] fProgressGeometry; 42 private boolean fCustomizeProgressMessage; 43 private int[] fMessageGeometry; 44 private boolean fCustomizeForegroundColor; 45 private String fForegroundColor; 46 47 private String fFieldSplashHandlerType; 48 49 public SplashInfo(IProductModel model) { 50 super(model); 51 } 52 53 public void setLocation(String location, boolean blockNotification) { 54 String old = fLocation; 55 fLocation = location; 56 if (!blockNotification && isEditable()) 57 firePropertyChanged(P_LOCATION, old, fLocation); 58 } 59 60 public String getLocation() { 61 return fLocation; 62 } 63 64 public void parse(Node node) { 65 if (node.getNodeType() == Node.ELEMENT_NODE) { 66 Element element = (Element )node; 67 setLocation(element.getAttribute(P_LOCATION), true); 68 setProgressGeometry(getGeometryArray(element.getAttribute(P_PROGRESS_GEOMETRY)), true); 69 setMessageGeometry(getGeometryArray(element.getAttribute(P_MESSAGE_GEOMETRY)), true); 70 setForegroundColor(element.getAttribute(P_FOREGROUND_COLOR), true); 71 setFieldSplashHandlerType(element.getAttribute(F_ATTRIBUTE_HANDLER_TYPE), true); 73 } 74 } 75 76 public void write(String indent, PrintWriter writer) { 77 if (!hasData()) 78 return; 79 80 writer.print(indent + "<splash"); 82 if (fLocation != null && fLocation.length() > 0) 83 writeProperty(indent, writer, P_LOCATION, getWritableString(fLocation)); 84 85 String progres = getGeometryString(fProgressGeometry); 86 if (fCustomizeProgressBar && progres != null) 87 writeProperty(indent, writer, P_PROGRESS_GEOMETRY, getWritableString(progres)); 88 89 String message = getGeometryString(fMessageGeometry); 90 if (fCustomizeProgressMessage && message != null) 91 writeProperty(indent, writer, P_MESSAGE_GEOMETRY, getWritableString(message)); 92 93 if (fCustomizeForegroundColor && isValidHexValue(fForegroundColor)) 94 writeProperty(indent, writer, P_FOREGROUND_COLOR, getWritableString(fForegroundColor)); 95 96 if (isDefinedSplashHandlerType()) { 98 writeProperty(indent, writer, F_ATTRIBUTE_HANDLER_TYPE, 99 fFieldSplashHandlerType); 100 } 101 102 writer.print(" />"); } 104 105 private void writeProperty(String indent, PrintWriter writer, String name, String value) { 106 writer.println(); 107 writer.print(indent + indent + name + "=\"" + value + "\""); } 109 110 public void setProgressGeometry(int[] geo, boolean blockNotification) { 111 fCustomizeProgressBar = geo != null; 112 int[] old = fProgressGeometry; 113 fProgressGeometry = geo; 114 if (!blockNotification && isEditable()) 115 firePropertyChanged(P_PROGRESS_GEOMETRY, old, fProgressGeometry); 116 } 117 118 public int[] getProgressGeometry() { 119 return fCustomizeProgressBar ? fProgressGeometry : null; 120 } 121 122 public void setMessageGeometry(int[] geo, boolean blockNotification) { 123 fCustomizeProgressMessage = geo != null; 124 int[] old = fMessageGeometry; 125 fMessageGeometry = geo; 126 if (!blockNotification && isEditable()) 127 firePropertyChanged(P_MESSAGE_GEOMETRY, old, fMessageGeometry); 128 } 129 130 public int[] getMessageGeometry() { 131 return fCustomizeProgressMessage ? fMessageGeometry : null; 132 } 133 134 public void setForegroundColor(String hexColor, boolean blockNotification) throws IllegalArgumentException { 135 if (hexColor != null && hexColor.length() == 0) 136 hexColor = null; 137 if (hexColor != null && !isValidHexValue(hexColor)) 138 throw new IllegalArgumentException (); 139 fCustomizeForegroundColor = hexColor != null; 140 String old = fForegroundColor; 141 fForegroundColor = hexColor; 142 if (!blockNotification && isEditable()) 143 firePropertyChanged(P_FOREGROUND_COLOR, old, fForegroundColor); 144 } 145 146 public String getForegroundColor() { 147 return fCustomizeForegroundColor ? fForegroundColor : null; 148 } 149 150 public static String getGeometryString(int[] geometry) { 151 if (geometry == null || geometry.length < 4) 152 return null; 153 return Integer.toString(geometry[0]) + "," + Integer.toString(geometry[1]) + "," + Integer.toString(geometry[2]) + "," + Integer.toString(geometry[3]); 157 } 158 159 public static int[] getGeometryArray(String tokenizedValue) { 160 if (tokenizedValue == null || tokenizedValue.length() == 0) 161 return null; 162 163 StringTokenizer tokenizer = new StringTokenizer (tokenizedValue, ","); int position = 0; 165 int[] geo = new int[4]; 166 while (tokenizer.hasMoreTokens()) 167 geo[position++] = Integer.parseInt(tokenizer.nextToken()); 168 return geo; 169 } 170 171 private boolean isValidHexValue(String value) { 172 if (value == null || value.length() != 6) 173 return false; 174 for (int i = 0; i < value.length(); i++) { 175 boolean found = false; 176 for (int j = 0; j < VALID_HEX_CHARS.length; j++) { 177 if (value.charAt(i) == VALID_HEX_CHARS[j]) { 178 found = true; 179 break; 180 } 181 } 182 if (!found) 183 return false; 184 } 185 return true; 186 } 187 188 private boolean hasData() { 189 return (fLocation != null && fLocation.length() > 0) || 190 (fCustomizeForegroundColor && fForegroundColor != null && isValidHexValue(fForegroundColor)) || 191 isDefinedGeometry() || 192 isDefinedSplashHandlerType(); 193 } 194 195 198 public boolean isDefinedSplashHandlerType() { 199 if ((fFieldSplashHandlerType != null) && 200 (fFieldSplashHandlerType.length() > 0)) { 201 return true; 202 } 203 return false; 204 } 205 206 public void addProgressBar(boolean add, boolean blockNotification) { 207 boolean old = fCustomizeProgressBar; 208 fCustomizeProgressBar = add; 209 int[] geo = getProgressGeometry(); 210 if (add) 211 setProgressGeometry(geo != null ? geo : new int[] { 212 F_DEFAULT_BAR_X_OFFSET, 213 F_DEFAULT_BAR_Y_OFFSET, 214 F_DEFAULT_BAR_WIDTH, 215 F_DEFAULT_BAR_HEIGHT}, 216 blockNotification); 217 else if (!blockNotification && isEditable()) 218 firePropertyChanged("", Boolean.toString(old), Boolean.toString(add)); } 220 221 public void addProgressMessage(boolean add, boolean blockNotification) { 222 boolean mold = fCustomizeProgressMessage; 223 boolean cold = fCustomizeForegroundColor; 224 fCustomizeProgressMessage = add; 225 fCustomizeForegroundColor = add; 226 int[] geo = getMessageGeometry(); 227 String foreground = getForegroundColor(); 228 if (add) { 229 setMessageGeometry(geo != null ? geo : new int[] { 230 F_DEFAULT_MESSAGE_X_OFFSET, 231 F_DEFAULT_MESSAGE_Y_OFFSET, 232 F_DEFAULT_MESSAGE_WIDTH, 233 F_DEFAULT_MESSAGE_HEIGHT}, 234 blockNotification); 235 setForegroundColor(foreground != null ? foreground : "000000", blockNotification); } else if (!blockNotification && isEditable()) 237 firePropertyChanged("", Boolean.toString(mold || cold), Boolean.toString(add)); } 239 240 243 public String getFieldSplashHandlerType() { 244 return fFieldSplashHandlerType; 245 } 246 247 250 public void setFieldSplashHandlerType(String type, boolean blockNotification) { 251 String old = fFieldSplashHandlerType; 252 fFieldSplashHandlerType = type; 253 if ((blockNotification == false) && 254 isEditable()) { 255 firePropertyChanged(F_ATTRIBUTE_HANDLER_TYPE, old, fFieldSplashHandlerType); 256 } 257 } 258 259 262 public boolean isDefinedGeometry() { 263 if ((fCustomizeProgressBar && fProgressGeometry != null) || 264 (fCustomizeProgressMessage && fMessageGeometry != null)) { 265 return true; 266 } 267 return false; 268 } 269 } 270 | Popular Tags |