1 11 package org.eclipse.pde.internal.core.product; 12 13 import java.io.PrintWriter ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.pde.internal.core.iproduct.ILauncherInfo; 18 import org.eclipse.pde.internal.core.iproduct.IProductModel; 19 import org.w3c.dom.Element ; 20 import org.w3c.dom.Node ; 21 import org.w3c.dom.NodeList ; 22 23 public class LauncherInfo extends ProductObject implements ILauncherInfo { 24 25 private static final long serialVersionUID = 1L; 26 private boolean fUseIcoFile; 27 private Map fIcons = new HashMap (); 28 private String fLauncherName; 29 30 public LauncherInfo(IProductModel model) { 31 super(model); 32 } 33 34 public String getLauncherName() { 35 return fLauncherName; 36 } 37 38 public void setLauncherName(String name) { 39 String old = fLauncherName; 40 fLauncherName = name; 41 if (isEditable()) 42 firePropertyChanged(P_LAUNCHER, old, fLauncherName); 43 } 44 45 public void setIconPath(String iconId, String path) { 46 if (path == null) 47 path = ""; String old = (String )fIcons.get(iconId); 49 fIcons.put(iconId, path); 50 if (isEditable()) 51 firePropertyChanged(iconId, old, path); 52 } 53 54 public String getIconPath(String iconId) { 55 return (String )fIcons.get(iconId); 56 } 57 58 public boolean usesWinIcoFile() { 59 return fUseIcoFile; 60 } 61 62 public void setUseWinIcoFile(boolean use) { 63 boolean old = fUseIcoFile; 64 fUseIcoFile = use; 65 if (isEditable()) 66 firePropertyChanged(P_USE_ICO, Boolean.toString(old), Boolean.toString(fUseIcoFile)); 67 } 68 69 public void parse(Node node) { 70 if (node.getNodeType() == Node.ELEMENT_NODE) { 71 fLauncherName = ((Element )node).getAttribute("name"); NodeList children = node.getChildNodes(); 73 for (int i = 0; i < children.getLength(); i++) { 74 Node child = children.item(i); 75 if (child.getNodeType() == Node.ELEMENT_NODE) { 76 String name = child.getNodeName(); 77 if (name.equals("linux")) { parseLinux((Element )child); 79 } else if (name.equals("macosx")) { parseMac((Element )child); 81 } else if (name.equals("solaris")) { parseSolaris((Element )child); 83 } else if (name.equals("win")) { parseWin((Element )child); 85 } 86 } 87 } 88 } 89 } 90 91 private void parseWin(Element element) { 92 fUseIcoFile = "true".equals(element.getAttribute(P_USE_ICO)); NodeList children = element.getChildNodes(); 94 for (int i = 0; i < children.getLength(); i++) { 95 if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { 96 Element child = (Element )children.item(i); 97 String name = child.getNodeName(); 98 if (name.equals("ico")) { fIcons.put(P_ICO_PATH, child.getAttribute("path")); } else if (name.equals("bmp")) { fIcons.put(WIN32_16_HIGH, child.getAttribute(WIN32_16_HIGH)); 102 fIcons.put(WIN32_16_LOW, child.getAttribute(WIN32_16_LOW)); 103 fIcons.put(WIN32_32_HIGH, child.getAttribute(WIN32_32_HIGH)); 104 fIcons.put(WIN32_32_LOW, child.getAttribute(WIN32_32_LOW)); 105 fIcons.put(WIN32_48_HIGH, child.getAttribute(WIN32_48_HIGH)); 106 fIcons.put(WIN32_48_LOW, child.getAttribute(WIN32_48_LOW)); 107 } 108 } 109 } 110 } 111 112 private void parseSolaris(Element element) { 113 fIcons.put(SOLARIS_LARGE, element.getAttribute(SOLARIS_LARGE)); 114 fIcons.put(SOLARIS_MEDIUM, element.getAttribute(SOLARIS_MEDIUM)); 115 fIcons.put(SOLARIS_SMALL, element.getAttribute(SOLARIS_SMALL)); 116 fIcons.put(SOLARIS_TINY, element.getAttribute(SOLARIS_TINY)); 117 } 118 119 private void parseMac(Element element) { 120 fIcons.put(MACOSX_ICON, element.getAttribute("icon")); } 122 123 private void parseLinux(Element element) { 124 fIcons.put(LINUX_ICON, element.getAttribute("icon")); } 126 127 public void write(String indent, PrintWriter writer) { 128 writer.print(indent + "<launcher"); if (fLauncherName != null && fLauncherName.length() > 0) 130 writer.print(" name=\"" + fLauncherName + "\""); writer.println(">"); 133 writeLinux(indent + " ", writer); writeMac(indent + " ", writer); writeSolaris(indent + " ", writer); writerWin(indent + " ", writer); writer.println(indent + "</launcher>"); } 139 140 private void writerWin(String indent, PrintWriter writer) { 141 writer.println(indent + "<win " + P_USE_ICO + "=\"" + Boolean.toString(fUseIcoFile) + "\">"); String path = (String )fIcons.get(P_ICO_PATH); 143 if (path != null && path.length() > 0) 144 writer.println(indent + " <ico path=\"" + getWritableString(path) + "\"/>"); writer.print(indent + " <bmp"); writeIcon(indent + " ", WIN32_16_HIGH, writer); writeIcon(indent + " ", WIN32_16_LOW, writer); writeIcon(indent + " ", WIN32_32_HIGH, writer); writeIcon(indent + " ", WIN32_32_LOW, writer); writeIcon(indent + " ", WIN32_48_HIGH, writer); writeIcon(indent + " ", WIN32_48_LOW, writer); writer.println("/>"); writer.println(indent + "</win>"); } 155 156 private void writeSolaris(String indent, PrintWriter writer) { 157 writer.print(indent + "<solaris"); writeIcon(indent + " ", SOLARIS_LARGE, writer); writeIcon(indent + " ", SOLARIS_MEDIUM, writer); writeIcon(indent + " ", SOLARIS_SMALL, writer); writeIcon(indent + " ", SOLARIS_TINY, writer); writer.println("/>"); } 164 165 private void writeIcon(String indent, String iconId, PrintWriter writer) { 166 String icon = (String )fIcons.get(iconId); 167 if (icon != null && icon.length() > 0) { 168 writer.println(); 169 writer.print(indent + " " + iconId + "=\"" + getWritableString(icon) + "\""); } 171 172 } 173 174 private void writeMac(String indent, PrintWriter writer) { 175 String icon = (String )fIcons.get(MACOSX_ICON); 176 if (icon != null && icon.length() > 0) 177 writer.println(indent + "<macosx icon=\"" + getWritableString(icon) + "\"/>"); } 179 180 private void writeLinux(String indent, PrintWriter writer) { 181 String icon = (String )fIcons.get(LINUX_ICON); 182 if (icon != null && icon.length() > 0) 183 writer.println(indent + "<linux icon=\"" + getWritableString(icon) + "\"/>"); } 185 186 } 187 | Popular Tags |