diff --git a/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java b/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java index 68af3f082..213845c99 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java @@ -35,14 +35,18 @@ import com.jme3.asset.AssetEventListener; import com.jme3.asset.AssetKey; import com.jme3.asset.AssetManager; import com.jme3.asset.DesktopAssetManager; +import java.io.FileNotFoundException; +import java.io.InputStream; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.api.java.classpath.ClassPath; @@ -200,7 +204,7 @@ public class ProjectAssetManager extends DesktopAssetManager { clearClassLoader(); loadClassLoader(); } - + @Override public void setAssetEventListener(AssetEventListener listener) { throw new UnsupportedOperationException("Setting the asset event listener is not allowed for ProjectAssetManager, use addAssetEventListener instead"); @@ -329,7 +333,7 @@ public class ProjectAssetManager extends DesktopAssetManager { * @return */ private String[] collectFilesWithSuffix(String suffix) { - ArrayList list = new ArrayList(); + Set list = new HashSet(); FileObject assetsFolder = getAssetFolder(); if (assetsFolder != null) { Enumeration assets = (Enumeration) assetsFolder.getChildren(true); @@ -364,6 +368,34 @@ public class ProjectAssetManager extends DesktopAssetManager { return list.toArray(new String[list.size()]); } + public InputStream getResourceAsStream(String name) { + InputStream in = this.getClass().getResourceAsStream(name); + + if (in == null && classPathItems != null) { + // TODO I need to find out if classPathItems contains all jars added to a project + Iterator classPathItemsIter = classPathItems.iterator(); + while (classPathItemsIter.hasNext()) { + ClassPathItem classPathItem = classPathItemsIter.next(); + FileObject jarFile = classPathItem.object; + + Enumeration jarEntry = (Enumeration) jarFile.getChildren(true); + while (jarEntry.hasMoreElements()) { + FileObject jarEntryAsset = jarEntry.nextElement(); + if (jarEntryAsset.getPath().equalsIgnoreCase(name)) { + try { + in = jarEntryAsset.getInputStream(); + } catch (FileNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + break; + } + } + } + } + + return in; + } + /** * @return the folderName */ diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java index 264f1ff8c..858721e39 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java @@ -177,7 +177,7 @@ public class EditableMaterialFile { fs = FileUtil.createMemoryFileSystem(); matDef = fs.getRoot().createData(name, "j3md"); OutputStream out = matDef.getOutputStream(); - InputStream in = JmeSystem.getResourceAsStream("/" + getMatDefName()); + InputStream in = manager.getResourceAsStream(getMatDefName()); if (in != null) { int input = in.read(); while (input != -1) {