- 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
This commit is contained in:
parent
85d5666644
commit
6936c34b75
@ -36,6 +36,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import org.openide.filesystems.FileAlreadyLockedException;
|
import org.openide.filesystems.FileAlreadyLockedException;
|
||||||
import org.openide.filesystems.FileLock;
|
import org.openide.filesystems.FileLock;
|
||||||
@ -77,6 +78,14 @@ public class AssetData extends Properties {
|
|||||||
file.saveAsset();
|
file.saveAsset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FileObject> getAssetList(){
|
||||||
|
return file.getAssetList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AssetKey> getFailedList() {
|
||||||
|
return file.getFailedList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized String getProperty(String key) {
|
public synchronized String getProperty(String key) {
|
||||||
return super.getProperty(key);
|
return super.getProperty(key);
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.jme3.gde.core.assets;
|
package com.jme3.gde.core.assets;
|
||||||
|
|
||||||
|
import com.jme3.asset.AssetEventListener;
|
||||||
import com.jme3.asset.AssetKey;
|
import com.jme3.asset.AssetKey;
|
||||||
import com.jme3.export.Savable;
|
import com.jme3.export.Savable;
|
||||||
import com.jme3.export.binary.BinaryExporter;
|
import com.jme3.export.binary.BinaryExporter;
|
||||||
@ -38,6 +39,8 @@ import com.jme3.gde.core.scene.SceneApplication;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -91,12 +94,16 @@ public class AssetDataObject extends MultiDataObject {
|
|||||||
protected Savable savable;
|
protected Savable savable;
|
||||||
protected String saveExtension;
|
protected String saveExtension;
|
||||||
protected AbstractLookup contentLookup;
|
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 {
|
public AssetDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
|
||||||
super(pf, loader);
|
super(pf, loader);
|
||||||
contentLookup = new AbstractLookup(getLookupContents());
|
contentLookup = new AbstractLookup(getLookupContents());
|
||||||
lookupContents.add(new AssetData(this));
|
lookupContents.add(new AssetData(this));
|
||||||
lookup = new ProxyLookup(getCookieSet().getLookup(), contentLookup);
|
lookup = new ProxyLookup(getCookieSet().getLookup(), contentLookup);
|
||||||
|
listListener = new AssetListListener(this, assetList, failedList);
|
||||||
setSaveCookie(saveCookie);
|
setSaveCookie(saveCookie);
|
||||||
findAssetManager();
|
findAssetManager();
|
||||||
}
|
}
|
||||||
@ -168,7 +175,9 @@ public class AssetDataObject extends MultiDataObject {
|
|||||||
FileLock lock = null;
|
FileLock lock = null;
|
||||||
try {
|
try {
|
||||||
lock = getPrimaryFile().lock();
|
lock = getPrimaryFile().lock();
|
||||||
|
listListener.start();
|
||||||
Savable spatial = (Savable) mgr.loadAsset(getAssetKey());
|
Savable spatial = (Savable) mgr.loadAsset(getAssetKey());
|
||||||
|
listListener.stop();
|
||||||
savable = spatial;
|
savable = spatial;
|
||||||
lock.releaseLock();
|
lock.releaseLock();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -238,4 +247,71 @@ public class AssetDataObject extends MultiDataObject {
|
|||||||
Exceptions.printStackTrace(ex);
|
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;
|
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.AssetManager;
|
||||||
import com.jme3.asset.DesktopAssetManager;
|
import com.jme3.asset.DesktopAssetManager;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -55,6 +57,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
|
|
||||||
private Project project;
|
private Project project;
|
||||||
private List<String> folderNames = new LinkedList<String>();
|
private List<String> folderNames = new LinkedList<String>();
|
||||||
|
private List<AssetEventListener> assetEventListeners = new LinkedList<AssetEventListener>();
|
||||||
|
|
||||||
public ProjectAssetManager(Project prj, String folderName) {
|
public ProjectAssetManager(Project prj, String folderName) {
|
||||||
super(true);
|
super(true);
|
||||||
@ -74,17 +77,40 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
}
|
}
|
||||||
String string = project.getProjectDirectory().getPath();
|
String string = project.getProjectDirectory().getPath();
|
||||||
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Add locator: {0}", string);
|
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Add locator: {0}", string);
|
||||||
registerLocator(string,
|
registerLocator(string, "com.jme3.asset.plugins.FileLocator");
|
||||||
"com.jme3.asset.plugins.FileLocator");
|
|
||||||
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
|
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
|
||||||
di.prepareManager(this);
|
di.prepareManager(this);
|
||||||
}
|
}
|
||||||
|
prepAssetEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectAssetManager() {
|
public ProjectAssetManager() {
|
||||||
this(null);
|
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
|
* 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);
|
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
|
* For situations with no Project
|
||||||
*/
|
*/
|
||||||
|
@ -86,7 +86,9 @@ public class SpatialAssetDataObject extends AssetDataObject {
|
|||||||
try {
|
try {
|
||||||
lock = getPrimaryFile().lock();
|
lock = getPrimaryFile().lock();
|
||||||
mgr.deleteFromCache(getAssetKey());
|
mgr.deleteFromCache(getAssetKey());
|
||||||
|
listListener.start();
|
||||||
Spatial spatial = mgr.loadModel(getAssetKey());
|
Spatial spatial = mgr.loadModel(getAssetKey());
|
||||||
|
listListener.stop();
|
||||||
savable = spatial;
|
savable = spatial;
|
||||||
lock.releaseLock();
|
lock.releaseLock();
|
||||||
return spatial;
|
return spatial;
|
||||||
|
@ -85,7 +85,9 @@ public class OgreSceneDataObject extends SpatialAssetDataObject {
|
|||||||
try {
|
try {
|
||||||
lock = getPrimaryFile().lock();
|
lock = getPrimaryFile().lock();
|
||||||
mgr.deleteFromCache(getAssetKey());
|
mgr.deleteFromCache(getAssetKey());
|
||||||
|
listListener.start();
|
||||||
Spatial spatial = mgr.loadModel(getAssetKey());
|
Spatial spatial = mgr.loadModel(getAssetKey());
|
||||||
|
listListener.stop();
|
||||||
savable = spatial;
|
savable = spatial;
|
||||||
lock.releaseLock();
|
lock.releaseLock();
|
||||||
return spatial;
|
return spatial;
|
||||||
|
@ -109,7 +109,9 @@ public class OgreXMLDataObject extends SpatialAssetDataObject {
|
|||||||
try {
|
try {
|
||||||
lock = getPrimaryFile().lock();
|
lock = getPrimaryFile().lock();
|
||||||
mgr.deleteFromCache(getAssetKey());
|
mgr.deleteFromCache(getAssetKey());
|
||||||
|
listListener.start();
|
||||||
Spatial spatial = mgr.loadModel(getAssetKey());
|
Spatial spatial = mgr.loadModel(getAssetKey());
|
||||||
|
listListener.stop();
|
||||||
savable = spatial;
|
savable = spatial;
|
||||||
lock.releaseLock();
|
lock.releaseLock();
|
||||||
return spatial;
|
return spatial;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user