001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.product;
011:
012: import java.io.PrintWriter;
013: import java.util.HashMap;
014: import java.util.Map;
015:
016: import org.eclipse.pde.internal.core.iproduct.ILauncherInfo;
017: import org.eclipse.pde.internal.core.iproduct.IProductModel;
018: import org.w3c.dom.Element;
019: import org.w3c.dom.Node;
020: import org.w3c.dom.NodeList;
021:
022: public class LauncherInfo extends ProductObject implements
023: ILauncherInfo {
024:
025: private static final long serialVersionUID = 1L;
026: private boolean fUseIcoFile;
027: private Map fIcons = new HashMap();
028: private String fLauncherName;
029:
030: public LauncherInfo(IProductModel model) {
031: super (model);
032: }
033:
034: public String getLauncherName() {
035: return fLauncherName;
036: }
037:
038: public void setLauncherName(String name) {
039: String old = fLauncherName;
040: fLauncherName = name;
041: if (isEditable())
042: firePropertyChanged(P_LAUNCHER, old, fLauncherName);
043: }
044:
045: public void setIconPath(String iconId, String path) {
046: if (path == null)
047: path = ""; //$NON-NLS-1$
048: String old = (String) fIcons.get(iconId);
049: fIcons.put(iconId, path);
050: if (isEditable())
051: firePropertyChanged(iconId, old, path);
052: }
053:
054: public String getIconPath(String iconId) {
055: return (String) fIcons.get(iconId);
056: }
057:
058: public boolean usesWinIcoFile() {
059: return fUseIcoFile;
060: }
061:
062: public void setUseWinIcoFile(boolean use) {
063: boolean old = fUseIcoFile;
064: fUseIcoFile = use;
065: if (isEditable())
066: firePropertyChanged(P_USE_ICO, Boolean.toString(old),
067: Boolean.toString(fUseIcoFile));
068: }
069:
070: public void parse(Node node) {
071: if (node.getNodeType() == Node.ELEMENT_NODE) {
072: fLauncherName = ((Element) node).getAttribute("name"); //$NON-NLS-1$
073: NodeList children = node.getChildNodes();
074: for (int i = 0; i < children.getLength(); i++) {
075: Node child = children.item(i);
076: if (child.getNodeType() == Node.ELEMENT_NODE) {
077: String name = child.getNodeName();
078: if (name.equals("linux")) { //$NON-NLS-1$
079: parseLinux((Element) child);
080: } else if (name.equals("macosx")) { //$NON-NLS-1$
081: parseMac((Element) child);
082: } else if (name.equals("solaris")) { //$NON-NLS-1$
083: parseSolaris((Element) child);
084: } else if (name.equals("win")) { //$NON-NLS-1$
085: parseWin((Element) child);
086: }
087: }
088: }
089: }
090: }
091:
092: private void parseWin(Element element) {
093: fUseIcoFile = "true".equals(element.getAttribute(P_USE_ICO)); //$NON-NLS-1$
094: NodeList children = element.getChildNodes();
095: for (int i = 0; i < children.getLength(); i++) {
096: if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
097: Element child = (Element) children.item(i);
098: String name = child.getNodeName();
099: if (name.equals("ico")) { //$NON-NLS-1$
100: fIcons.put(P_ICO_PATH, child.getAttribute("path")); //$NON-NLS-1$
101: } else if (name.equals("bmp")) { //$NON-NLS-1$
102: fIcons.put(WIN32_16_HIGH, child
103: .getAttribute(WIN32_16_HIGH));
104: fIcons.put(WIN32_16_LOW, child
105: .getAttribute(WIN32_16_LOW));
106: fIcons.put(WIN32_32_HIGH, child
107: .getAttribute(WIN32_32_HIGH));
108: fIcons.put(WIN32_32_LOW, child
109: .getAttribute(WIN32_32_LOW));
110: fIcons.put(WIN32_48_HIGH, child
111: .getAttribute(WIN32_48_HIGH));
112: fIcons.put(WIN32_48_LOW, child
113: .getAttribute(WIN32_48_LOW));
114: }
115: }
116: }
117: }
118:
119: private void parseSolaris(Element element) {
120: fIcons.put(SOLARIS_LARGE, element.getAttribute(SOLARIS_LARGE));
121: fIcons
122: .put(SOLARIS_MEDIUM, element
123: .getAttribute(SOLARIS_MEDIUM));
124: fIcons.put(SOLARIS_SMALL, element.getAttribute(SOLARIS_SMALL));
125: fIcons.put(SOLARIS_TINY, element.getAttribute(SOLARIS_TINY));
126: }
127:
128: private void parseMac(Element element) {
129: fIcons.put(MACOSX_ICON, element.getAttribute("icon")); //$NON-NLS-1$
130: }
131:
132: private void parseLinux(Element element) {
133: fIcons.put(LINUX_ICON, element.getAttribute("icon")); //$NON-NLS-1$
134: }
135:
136: public void write(String indent, PrintWriter writer) {
137: writer.print(indent + "<launcher"); //$NON-NLS-1$
138: if (fLauncherName != null && fLauncherName.length() > 0)
139: writer.print(" name=\"" + fLauncherName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
140: writer.println(">"); //$NON-NLS-1$
141:
142: writeLinux(indent + " ", writer); //$NON-NLS-1$
143: writeMac(indent + " ", writer); //$NON-NLS-1$
144: writeSolaris(indent + " ", writer); //$NON-NLS-1$
145: writerWin(indent + " ", writer); //$NON-NLS-1$
146: writer.println(indent + "</launcher>"); //$NON-NLS-1$
147: }
148:
149: private void writerWin(String indent, PrintWriter writer) {
150: writer
151: .println(indent
152: + "<win " + P_USE_ICO + "=\"" + Boolean.toString(fUseIcoFile) + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
153: String path = (String) fIcons.get(P_ICO_PATH);
154: if (path != null && path.length() > 0)
155: writer
156: .println(indent
157: + " <ico path=\"" + getWritableString(path) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
158: writer.print(indent + " <bmp"); //$NON-NLS-1$
159: writeIcon(indent + " ", WIN32_16_HIGH, writer); //$NON-NLS-1$
160: writeIcon(indent + " ", WIN32_16_LOW, writer); //$NON-NLS-1$
161: writeIcon(indent + " ", WIN32_32_HIGH, writer); //$NON-NLS-1$
162: writeIcon(indent + " ", WIN32_32_LOW, writer); //$NON-NLS-1$
163: writeIcon(indent + " ", WIN32_48_HIGH, writer); //$NON-NLS-1$
164: writeIcon(indent + " ", WIN32_48_LOW, writer); //$NON-NLS-1$
165: writer.println("/>"); //$NON-NLS-1$
166: writer.println(indent + "</win>"); //$NON-NLS-1$
167: }
168:
169: private void writeSolaris(String indent, PrintWriter writer) {
170: writer.print(indent + "<solaris"); //$NON-NLS-1$
171: writeIcon(indent + " ", SOLARIS_LARGE, writer); //$NON-NLS-1$
172: writeIcon(indent + " ", SOLARIS_MEDIUM, writer); //$NON-NLS-1$
173: writeIcon(indent + " ", SOLARIS_SMALL, writer); //$NON-NLS-1$
174: writeIcon(indent + " ", SOLARIS_TINY, writer); //$NON-NLS-1$
175: writer.println("/>"); //$NON-NLS-1$
176: }
177:
178: private void writeIcon(String indent, String iconId,
179: PrintWriter writer) {
180: String icon = (String) fIcons.get(iconId);
181: if (icon != null && icon.length() > 0) {
182: writer.println();
183: writer
184: .print(indent
185: + " " + iconId + "=\"" + getWritableString(icon) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
186: }
187:
188: }
189:
190: private void writeMac(String indent, PrintWriter writer) {
191: String icon = (String) fIcons.get(MACOSX_ICON);
192: if (icon != null && icon.length() > 0)
193: writer
194: .println(indent
195: + "<macosx icon=\"" + getWritableString(icon) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
196: }
197:
198: private void writeLinux(String indent, PrintWriter writer) {
199: String icon = (String) fIcons.get(LINUX_ICON);
200: if (icon != null && icon.length() > 0)
201: writer
202: .println(indent
203: + "<linux icon=\"" + getWritableString(icon) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
204: }
205:
206: }
|