KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > product > LauncherInfo


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core.product;
12
13 import java.io.PrintWriter JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
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 JavaDoc;
20 import org.w3c.dom.Node JavaDoc;
21 import org.w3c.dom.NodeList JavaDoc;
22
23 public class LauncherInfo extends ProductObject implements ILauncherInfo {
24
25     private static final long serialVersionUID = 1L;
26     private boolean fUseIcoFile;
27     private Map JavaDoc fIcons = new HashMap JavaDoc();
28     private String JavaDoc fLauncherName;
29
30     public LauncherInfo(IProductModel model) {
31         super(model);
32     }
33
34     public String JavaDoc getLauncherName() {
35         return fLauncherName;
36     }
37
38     public void setLauncherName(String JavaDoc name) {
39         String JavaDoc old = fLauncherName;
40         fLauncherName = name;
41         if (isEditable())
42             firePropertyChanged(P_LAUNCHER, old, fLauncherName);
43     }
44
45     public void setIconPath(String JavaDoc iconId, String JavaDoc path) {
46         if (path == null)
47             path = ""; //$NON-NLS-1$
48
String JavaDoc old = (String JavaDoc)fIcons.get(iconId);
49         fIcons.put(iconId, path);
50         if (isEditable())
51             firePropertyChanged(iconId, old, path);
52     }
53
54     public String JavaDoc getIconPath(String JavaDoc iconId) {
55         return (String JavaDoc)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 JavaDoc node) {
70         if (node.getNodeType() == Node.ELEMENT_NODE) {
71             fLauncherName = ((Element JavaDoc)node).getAttribute("name"); //$NON-NLS-1$
72
NodeList JavaDoc children = node.getChildNodes();
73             for (int i = 0; i < children.getLength(); i++) {
74                 Node JavaDoc child = children.item(i);
75                 if (child.getNodeType() == Node.ELEMENT_NODE) {
76                     String JavaDoc name = child.getNodeName();
77                     if (name.equals("linux")) { //$NON-NLS-1$
78
parseLinux((Element JavaDoc)child);
79                     } else if (name.equals("macosx")) { //$NON-NLS-1$
80
parseMac((Element JavaDoc)child);
81                     } else if (name.equals("solaris")) { //$NON-NLS-1$
82
parseSolaris((Element JavaDoc)child);
83                     } else if (name.equals("win")) { //$NON-NLS-1$
84
parseWin((Element JavaDoc)child);
85                     }
86                 }
87             }
88         }
89     }
90     
91     private void parseWin(Element JavaDoc element) {
92         fUseIcoFile = "true".equals(element.getAttribute(P_USE_ICO)); //$NON-NLS-1$
93
NodeList JavaDoc children = element.getChildNodes();
94         for (int i = 0; i < children.getLength(); i++) {
95             if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
96                 Element JavaDoc child = (Element JavaDoc)children.item(i);
97                 String JavaDoc name = child.getNodeName();
98                 if (name.equals("ico")) { //$NON-NLS-1$
99
fIcons.put(P_ICO_PATH, child.getAttribute("path")); //$NON-NLS-1$
100
} else if (name.equals("bmp")) { //$NON-NLS-1$
101
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 JavaDoc 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 JavaDoc element) {
120         fIcons.put(MACOSX_ICON, element.getAttribute("icon")); //$NON-NLS-1$
121
}
122
123     private void parseLinux(Element JavaDoc element) {
124         fIcons.put(LINUX_ICON, element.getAttribute("icon")); //$NON-NLS-1$
125
}
126
127     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
128         writer.print(indent + "<launcher"); //$NON-NLS-1$
129
if (fLauncherName != null && fLauncherName.length() > 0)
130             writer.print(" name=\"" + fLauncherName + "\""); //$NON-NLS-1$ //$NON-NLS-2$
131
writer.println(">"); //$NON-NLS-1$
132

133         writeLinux(indent + " ", writer); //$NON-NLS-1$
134
writeMac(indent + " ", writer); //$NON-NLS-1$
135
writeSolaris(indent + " ", writer); //$NON-NLS-1$
136
writerWin(indent + " ", writer); //$NON-NLS-1$
137
writer.println(indent + "</launcher>"); //$NON-NLS-1$
138
}
139
140     private void writerWin(String JavaDoc indent, PrintWriter JavaDoc writer) {
141         writer.println(indent + "<win " + P_USE_ICO + "=\"" + Boolean.toString(fUseIcoFile) + "\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
142
String JavaDoc path = (String JavaDoc)fIcons.get(P_ICO_PATH);
143         if (path != null && path.length() > 0)
144             writer.println(indent + " <ico path=\"" + getWritableString(path) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
145
writer.print(indent + " <bmp"); //$NON-NLS-1$
146
writeIcon(indent + " ", WIN32_16_HIGH, writer); //$NON-NLS-1$
147
writeIcon(indent + " ", WIN32_16_LOW, writer); //$NON-NLS-1$
148
writeIcon(indent + " ", WIN32_32_HIGH, writer); //$NON-NLS-1$
149
writeIcon(indent + " ", WIN32_32_LOW, writer); //$NON-NLS-1$
150
writeIcon(indent + " ", WIN32_48_HIGH, writer); //$NON-NLS-1$
151
writeIcon(indent + " ", WIN32_48_LOW, writer); //$NON-NLS-1$
152
writer.println("/>"); //$NON-NLS-1$
153
writer.println(indent + "</win>"); //$NON-NLS-1$
154
}
155
156     private void writeSolaris(String JavaDoc indent, PrintWriter JavaDoc writer) {
157         writer.print(indent + "<solaris"); //$NON-NLS-1$
158
writeIcon(indent + " ", SOLARIS_LARGE, writer); //$NON-NLS-1$
159
writeIcon(indent + " ", SOLARIS_MEDIUM, writer); //$NON-NLS-1$
160
writeIcon(indent + " ", SOLARIS_SMALL, writer); //$NON-NLS-1$
161
writeIcon(indent + " ", SOLARIS_TINY, writer); //$NON-NLS-1$
162
writer.println("/>"); //$NON-NLS-1$
163
}
164     
165     private void writeIcon(String JavaDoc indent, String JavaDoc iconId, PrintWriter JavaDoc writer) {
166         String JavaDoc icon = (String JavaDoc)fIcons.get(iconId);
167         if (icon != null && icon.length() > 0) {
168             writer.println();
169             writer.print(indent + " " + iconId + "=\"" + getWritableString(icon) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
170
}
171         
172     }
173
174     private void writeMac(String JavaDoc indent, PrintWriter JavaDoc writer) {
175         String JavaDoc icon = (String JavaDoc)fIcons.get(MACOSX_ICON);
176         if (icon != null && icon.length() > 0)
177             writer.println(indent + "<macosx icon=\"" + getWritableString(icon) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
178
}
179
180     private void writeLinux(String JavaDoc indent, PrintWriter JavaDoc writer) {
181         String JavaDoc icon = (String JavaDoc)fIcons.get(LINUX_ICON);
182         if (icon != null && icon.length() > 0)
183             writer.println(indent + "<linux icon=\"" + getWritableString(icon) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
184
}
185
186 }
187
Popular Tags