Lines 41-60
Link Here
|
41 |
|
41 |
|
42 |
package org.netbeans.core.startup.layers; |
42 |
package org.netbeans.core.startup.layers; |
43 |
|
43 |
|
44 |
import java.awt.Image; |
|
|
45 |
import java.awt.Toolkit; |
46 |
import java.beans.BeanInfo; |
47 |
import java.beans.PropertyVetoException; |
44 |
import java.beans.PropertyVetoException; |
48 |
import java.io.File; |
45 |
import java.io.File; |
49 |
import java.io.IOException; |
46 |
import java.io.IOException; |
50 |
import java.io.NotSerializableException; |
47 |
import java.io.NotSerializableException; |
51 |
import java.io.ObjectStreamException; |
48 |
import java.io.ObjectStreamException; |
52 |
import java.io.Serializable; |
49 |
import java.io.Serializable; |
53 |
import java.net.URL; |
|
|
54 |
import java.util.Arrays; |
55 |
import java.util.HashSet; |
50 |
import java.util.HashSet; |
56 |
import java.util.MissingResourceException; |
|
|
57 |
import java.util.ResourceBundle; |
58 |
import java.util.Set; |
51 |
import java.util.Set; |
59 |
import java.util.logging.Level; |
52 |
import java.util.logging.Level; |
60 |
import java.util.logging.LogRecord; |
53 |
import java.util.logging.LogRecord; |
Lines 70-77
Link Here
|
70 |
import org.openide.filesystems.FileUtil; |
63 |
import org.openide.filesystems.FileUtil; |
71 |
import org.openide.filesystems.LocalFileSystem; |
64 |
import org.openide.filesystems.LocalFileSystem; |
72 |
import org.openide.filesystems.MultiFileSystem; |
65 |
import org.openide.filesystems.MultiFileSystem; |
|
|
66 |
import org.openide.filesystems.Repository; |
73 |
import org.openide.util.Exceptions; |
67 |
import org.openide.util.Exceptions; |
74 |
import org.openide.util.ImageUtilities; |
|
|
75 |
import org.openide.util.NbBundle; |
68 |
import org.openide.util.NbBundle; |
76 |
|
69 |
|
77 |
/** The system FileSystem - represents system files under $NETBEANS_HOME/system. |
70 |
/** The system FileSystem - represents system files under $NETBEANS_HOME/system. |
Lines 79-85
Link Here
|
79 |
* @author Jan Jancura, Ian Formanek, Petr Hamernik |
72 |
* @author Jan Jancura, Ian Formanek, Petr Hamernik |
80 |
*/ |
73 |
*/ |
81 |
public final class SystemFileSystem extends MultiFileSystem |
74 |
public final class SystemFileSystem extends MultiFileSystem |
82 |
implements FileSystem.Status, FileChangeListener { |
75 |
implements FileChangeListener { |
83 |
// Must be public for BeanInfo to work: #11186. |
76 |
// Must be public for BeanInfo to work: #11186. |
84 |
|
77 |
|
85 |
/** generated Serialized Version UID */ |
78 |
/** generated Serialized Version UID */ |
Lines 88-101
Link Here
|
88 |
/** system name of this filesystem */ |
81 |
/** system name of this filesystem */ |
89 |
private static final String SYSTEM_NAME = "SystemFileSystem"; // NOI18N |
82 |
private static final String SYSTEM_NAME = "SystemFileSystem"; // NOI18N |
90 |
|
83 |
|
91 |
/** name of file attribute with localizing bundle */ |
|
|
92 |
private static final String ATTR_BUNDLE = "SystemFileSystem.localizingBundle"; // NOI18N |
93 |
|
94 |
/** name of file attribute with URL to 16x16 color icon */ |
95 |
private static final String ATTR_ICON_16 = "SystemFileSystem.icon"; // NOI18N |
96 |
/** name of file attribute with URL to 32x32 color icon */ |
97 |
private static final String ATTR_ICON_32 = "SystemFileSystem.icon32"; // NOI18N |
98 |
|
99 |
private static final Logger LOG = Logger.getLogger(SystemFileSystem.class.getName()); |
84 |
private static final Logger LOG = Logger.getLogger(SystemFileSystem.class.getName()); |
100 |
|
85 |
|
101 |
/** user fs */ |
86 |
/** user fs */ |
Lines 189-300
Link Here
|
189 |
} |
174 |
} |
190 |
|
175 |
|
191 |
public @Override FileSystem.Status getStatus() { |
176 |
public @Override FileSystem.Status getStatus() { |
192 |
return this; |
177 |
return Repository.createDefaultFileSystemStatus(); |
193 |
} |
178 |
} |
194 |
|
179 |
|
195 |
static final String annotateName(FileObject fo) { |
|
|
196 |
|
197 |
String bundleName = (String) fo.getAttribute(ATTR_BUNDLE); // NOI18N |
198 |
if (bundleName != null) { |
199 |
try { |
200 |
bundleName = org.openide.util.Utilities.translate(bundleName); |
201 |
ResourceBundle b = NbBundle.getBundle(bundleName); |
202 |
try { |
203 |
return b.getString(fo.getPath()); |
204 |
} catch (MissingResourceException ex) { |
205 |
// ignore--normal |
206 |
} |
207 |
} catch (MissingResourceException ex) { |
208 |
Exceptions.attachMessage(ex, warningMessage(bundleName, fo)); |
209 |
ModuleLayeredFileSystem.err.log(Level.WARNING, null, ex); |
210 |
// ignore |
211 |
} |
212 |
} |
213 |
return (String)fo.getAttribute("displayName"); // NOI18N |
214 |
} |
215 |
private static String warningMessage(String name, FileObject fo) { |
216 |
Object by = fo.getAttribute("layers"); // NOI18N |
217 |
if (by instanceof Object[]) { |
218 |
by = Arrays.toString((Object[])by); |
219 |
} |
220 |
return "Cannot load " + name + " for " + fo + " defined by " + by; // NOI18N |
221 |
} |
222 |
|
223 |
/** Annotate name |
224 |
*/ |
225 |
public String annotateName(String s, Set<? extends FileObject> files) { |
226 |
|
227 |
// Look for a localized file name. |
228 |
// Note: all files in the set are checked. But please only place the attribute |
229 |
// on the primary file, and use this primary file name as the bundle key. |
230 |
for (FileObject fo : files) { |
231 |
// annotate a name |
232 |
String displayName = annotateName(fo); |
233 |
if (displayName != null) { |
234 |
return displayName; |
235 |
} |
236 |
} |
237 |
|
238 |
return s; |
239 |
} |
240 |
|
241 |
static Image annotateIcon(FileObject fo, int type) { |
242 |
String attr = null; |
243 |
if (type == BeanInfo.ICON_COLOR_16x16) { |
244 |
attr = ATTR_ICON_16; |
245 |
} else if (type == BeanInfo.ICON_COLOR_32x32) { |
246 |
attr = ATTR_ICON_32; |
247 |
} |
248 |
|
249 |
if (attr != null) { |
250 |
Object value = fo.getAttribute(attr); |
251 |
if (value != null) { |
252 |
if (value instanceof URL) { |
253 |
return Toolkit.getDefaultToolkit().getImage((URL) value); |
254 |
} else if (value instanceof Image) { |
255 |
// #18832 |
256 |
return (Image) value; |
257 |
} else { |
258 |
ModuleLayeredFileSystem.err.warning("Attribute " + attr + " on " + fo + " expected to be a URL or Image; was: " + value); |
259 |
} |
260 |
} |
261 |
} |
262 |
|
263 |
String base = (String) fo.getAttribute("iconBase"); // NOI18N |
264 |
if (base != null) { |
265 |
if (type == BeanInfo.ICON_COLOR_16x16) { |
266 |
return ImageUtilities.loadImage(base, true); |
267 |
} else if (type == BeanInfo.ICON_COLOR_32x32) { |
268 |
return ImageUtilities.loadImage(insertBeforeSuffix(base, "_32"), true); // NOI18N |
269 |
} |
270 |
} |
271 |
return null; |
272 |
} |
273 |
|
274 |
private static String insertBeforeSuffix(String path, String toInsert) { |
275 |
String withoutSuffix = path; |
276 |
String suffix = ""; // NOI18N |
277 |
|
278 |
if (path.lastIndexOf('.') >= 0) { |
279 |
withoutSuffix = path.substring(0, path.lastIndexOf('.')); |
280 |
suffix = path.substring(path.lastIndexOf('.'), path.length()); |
281 |
} |
282 |
|
283 |
return withoutSuffix + toInsert + suffix; |
284 |
} |
285 |
|
286 |
/** Annotate icon |
287 |
*/ |
288 |
public Image annotateIcon(Image im, int type, Set<? extends FileObject> files) { |
289 |
for (FileObject fo : files) { |
290 |
Image img = annotateIcon(fo, type); |
291 |
if (img != null) { |
292 |
return img; |
293 |
} |
294 |
} |
295 |
return im; |
296 |
} |
297 |
|
298 |
/** Initializes and creates new repository. This repository's system fs is |
180 |
/** Initializes and creates new repository. This repository's system fs is |
299 |
* based on the content of ${HOME_DIR}/system and ${USER_DIR}/system directories |
181 |
* based on the content of ${HOME_DIR}/system and ${USER_DIR}/system directories |
300 |
* |
182 |
* |