- add code for keeping list of additional assets for AssetDataObject (not used anywhere yet)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8599 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent 85d5666644
commit 6936c34b75
  1. 9
      sdk/jme3-core/src/com/jme3/gde/core/assets/AssetData.java
  2. 76
      sdk/jme3-core/src/com/jme3/gde/core/assets/AssetDataObject.java
  3. 40
      sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java
  4. 2
      sdk/jme3-core/src/com/jme3/gde/core/assets/SpatialAssetDataObject.java
  5. 2
      sdk/jme3-ogrexml/src/com/jme3/gde/ogrexml/OgreSceneDataObject.java
  6. 2
      sdk/jme3-ogrexml/src/com/jme3/gde/ogrexml/OgreXMLDataObject.java

@ -36,6 +36,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Properties;
import org.openide.filesystems.FileAlreadyLockedException;
import org.openide.filesystems.FileLock;
@ -76,7 +77,15 @@ public class AssetData extends Properties {
public void saveAsset() throws IOException {
file.saveAsset();
}
public List<FileObject> getAssetList(){
return file.getAssetList();
}
public List<AssetKey> getFailedList() {
return file.getFailedList();
}
@Override
public synchronized String getProperty(String key) {
return super.getProperty(key);

@ -31,6 +31,7 @@
*/
package com.jme3.gde.core.assets;
import com.jme3.asset.AssetEventListener;
import com.jme3.asset.AssetKey;
import com.jme3.export.Savable;
import com.jme3.export.binary.BinaryExporter;
@ -38,6 +39,8 @@ import com.jme3.gde.core.scene.SceneApplication;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -91,12 +94,16 @@ public class AssetDataObject extends MultiDataObject {
protected Savable savable;
protected String saveExtension;
protected AbstractLookup contentLookup;
protected AssetListListener listListener;
protected List<FileObject> assetList = new LinkedList<FileObject>();
protected List<AssetKey> failedList = new LinkedList<AssetKey>();
public AssetDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
super(pf, loader);
contentLookup = new AbstractLookup(getLookupContents());
lookupContents.add(new AssetData(this));
lookup = new ProxyLookup(getCookieSet().getLookup(), contentLookup);
listListener = new AssetListListener(this, assetList, failedList);
setSaveCookie(saveCookie);
findAssetManager();
}
@ -168,7 +175,9 @@ public class AssetDataObject extends MultiDataObject {
FileLock lock = null;
try {
lock = getPrimaryFile().lock();
listListener.start();
Savable spatial = (Savable) mgr.loadAsset(getAssetKey());
listListener.stop();
savable = spatial;
lock.releaseLock();
} catch (Exception ex) {
@ -238,4 +247,71 @@ public class AssetDataObject extends MultiDataObject {
Exceptions.printStackTrace(ex);
}
}
public List<FileObject> getAssetList() {
return assetList;
}
public List<AssetKey> getFailedList() {
return failedList;
}
protected static class AssetListListener implements AssetEventListener {
private AssetDataObject obj;
private List<FileObject> assetList;
private List<AssetKey> failedList;
private Thread loadingThread;
public AssetListListener(AssetDataObject obj, List<FileObject> assetList, List<AssetKey> failedList) {
this.obj = obj;
this.assetList = assetList;
this.failedList = failedList;
}
public void assetLoaded(AssetKey ak) {
}
public void assetRequested(AssetKey ak) {
ProjectAssetManager pm = obj.getLookup().lookup(ProjectAssetManager.class);
if (pm == null || loadingThread != Thread.currentThread()) {
return;
}
FileObject obj = pm.getAssetFolder().getFileObject(ak.getName());
if (obj != null) {
assetList.add(obj);
}
}
public void assetDependencyNotFound(AssetKey ak, AssetKey ak1) {
ProjectAssetManager pm = obj.getLookup().lookup(ProjectAssetManager.class);
if (pm == null || loadingThread != Thread.currentThread()) {
return;
}
FileObject obj = pm.getAssetFolder().getFileObject(ak1.getName());
if (obj != null && assetList.contains(obj)) {
assetList.remove(obj);
failedList.add(ak1);
}
}
public void start() {
ProjectAssetManager pm = obj.getLookup().lookup(ProjectAssetManager.class);
loadingThread = Thread.currentThread();
assetList.clear();
failedList.clear();
if (pm == null) {
return;
}
pm.addAssetEventListener(this);
}
public void stop() {
ProjectAssetManager pm = obj.getLookup().lookup(ProjectAssetManager.class);
if (pm == null) {
return;
}
pm.removeAssetEventListener(this);
}
};
}

@ -31,6 +31,8 @@
*/
package com.jme3.gde.core.assets;
import com.jme3.asset.AssetEventListener;
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
import java.util.ArrayList;
@ -55,6 +57,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
private Project project;
private List<String> folderNames = new LinkedList<String>();
private List<AssetEventListener> assetEventListeners = new LinkedList<AssetEventListener>();
public ProjectAssetManager(Project prj, String folderName) {
super(true);
@ -73,18 +76,41 @@ public class ProjectAssetManager extends DesktopAssetManager {
this.project = new DummyProject(this, path);
}
String string = project.getProjectDirectory().getPath();
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Add locator:{0}", string);
registerLocator(string,
"com.jme3.asset.plugins.FileLocator");
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Add locator: {0}", string);
registerLocator(string, "com.jme3.asset.plugins.FileLocator");
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
di.prepareManager(this);
}
prepAssetEventListeners();
}
public ProjectAssetManager() {
this(null);
}
private void prepAssetEventListeners() {
setAssetEventListener(new AssetEventListener() {
public void assetLoaded(AssetKey ak) {
for (AssetEventListener assetEventListener : assetEventListeners) {
assetEventListener.assetLoaded(ak);
}
}
public void assetRequested(AssetKey ak) {
for (AssetEventListener assetEventListener : assetEventListeners) {
assetEventListener.assetRequested(ak);
}
}
public void assetDependencyNotFound(AssetKey ak, AssetKey ak1) {
for (AssetEventListener assetEventListener : assetEventListeners) {
assetEventListener.assetDependencyNotFound(ak, ak1);
}
}
});
}
/**
* Adds a locator to a folder within the main project directory
*/
@ -238,6 +264,14 @@ public class ProjectAssetManager extends DesktopAssetManager {
this.folderNames.add(0, folderName);
}
public void addAssetEventListener(AssetEventListener listener) {
assetEventListeners.add(listener);
}
public void removeAssetEventListener(AssetEventListener listener) {
assetEventListeners.remove(listener);
}
/**
* For situations with no Project
*/

@ -86,7 +86,9 @@ public class SpatialAssetDataObject extends AssetDataObject {
try {
lock = getPrimaryFile().lock();
mgr.deleteFromCache(getAssetKey());
listListener.start();
Spatial spatial = mgr.loadModel(getAssetKey());
listListener.stop();
savable = spatial;
lock.releaseLock();
return spatial;

@ -85,7 +85,9 @@ public class OgreSceneDataObject extends SpatialAssetDataObject {
try {
lock = getPrimaryFile().lock();
mgr.deleteFromCache(getAssetKey());
listListener.start();
Spatial spatial = mgr.loadModel(getAssetKey());
listListener.stop();
savable = spatial;
lock.releaseLock();
return spatial;

@ -109,7 +109,9 @@ public class OgreXMLDataObject extends SpatialAssetDataObject {
try {
lock = getPrimaryFile().lock();
mgr.deleteFromCache(getAssetKey());
listListener.start();
Spatial spatial = mgr.loadModel(getAssetKey());
listListener.stop();
savable = spatial;
lock.releaseLock();
return spatial;

Loading…
Cancel
Save