|
@@ -44,7 +44,6 @@ import com.jme3.math.Vector3f;
|
|
import java.lang.reflect.Constructor;
|
|
import java.lang.reflect.Constructor;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
-import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.concurrent.Callable;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
@@ -57,7 +56,7 @@ import org.openide.util.Mutex;
|
|
/**
|
|
/**
|
|
* This class allows editing jME scene values in property sheets in a threadsafe
|
|
* This class allows editing jME scene values in property sheets in a threadsafe
|
|
* manner. The getter and setter are called via reflection and changes in the
|
|
* manner. The getter and setter are called via reflection and changes in the
|
|
- * properties can be listed for.
|
|
|
|
|
|
+ * properties can be listened for.
|
|
*
|
|
*
|
|
* @author normenhansen
|
|
* @author normenhansen
|
|
*/
|
|
*/
|
|
@@ -136,12 +135,14 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
public void syncValue() {
|
|
public void syncValue() {
|
|
final T realValue = getSuperValue();
|
|
final T realValue = getSuperValue();
|
|
mutex.readAccess(new Runnable() {
|
|
mutex.readAccess(new Runnable() {
|
|
|
|
+ @Override
|
|
public void run() {
|
|
public void run() {
|
|
if (changing) {
|
|
if (changing) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if ((objectLocal == null) && !inited) {
|
|
if ((objectLocal == null) && !inited) {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
|
|
+ @Override
|
|
public void run() {
|
|
public void run() {
|
|
inited = true;
|
|
inited = true;
|
|
objectLocal = duplicateObject(realValue);
|
|
objectLocal = duplicateObject(realValue);
|
|
@@ -151,6 +152,7 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
});
|
|
});
|
|
} else if ((objectLocal != null) && !objectLocal.equals(realValue)) {
|
|
} else if ((objectLocal != null) && !objectLocal.equals(realValue)) {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
|
|
+ @Override
|
|
public void run() {
|
|
public void run() {
|
|
T oldObject = objectLocal;
|
|
T oldObject = objectLocal;
|
|
T newObject = duplicateObject(realValue);
|
|
T newObject = duplicateObject(realValue);
|
|
@@ -161,6 +163,7 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
});
|
|
});
|
|
} else if ((objectLocal == null) && (realValue != null)) {
|
|
} else if ((objectLocal == null) && (realValue != null)) {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
|
|
+ @Override
|
|
public void run() {
|
|
public void run() {
|
|
objectLocal = duplicateObject(realValue);
|
|
objectLocal = duplicateObject(realValue);
|
|
notifyListeners(PROP_SCENE_CHANGE, null, objectLocal);
|
|
notifyListeners(PROP_SCENE_CHANGE, null, objectLocal);
|
|
@@ -186,6 +189,7 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
@Override
|
|
@Override
|
|
public T getValue() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
public T getValue() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
return mutex.readAccess(new Mutex.Action<T>() {
|
|
return mutex.readAccess(new Mutex.Action<T>() {
|
|
|
|
+ @Override
|
|
public T run() {
|
|
public T run() {
|
|
logger.log(Level.FINE, "Return local value of {0}", objectLocal);
|
|
logger.log(Level.FINE, "Return local value of {0}", objectLocal);
|
|
return objectLocal;
|
|
return objectLocal;
|
|
@@ -205,6 +209,7 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
@Override
|
|
@Override
|
|
public void setValue(final T val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
public void setValue(final T val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
|
|
+ @Override
|
|
public void run() {
|
|
public void run() {
|
|
logger.log(Level.FINE, "Set local value to {0}", val);
|
|
logger.log(Level.FINE, "Set local value to {0}", val);
|
|
final T oldObject = objectLocal;
|
|
final T oldObject = objectLocal;
|
|
@@ -212,8 +217,10 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
objectLocal = val;
|
|
objectLocal = val;
|
|
final T sceneObject = duplicateObject(val);
|
|
final T sceneObject = duplicateObject(val);
|
|
SceneApplication.getApplication().enqueue(new Callable<Void>() {
|
|
SceneApplication.getApplication().enqueue(new Callable<Void>() {
|
|
|
|
+ @Override
|
|
public Void call() throws Exception {
|
|
public Void call() throws Exception {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
mutex.postWriteRequest(new Runnable() {
|
|
|
|
+ @Override
|
|
public void run() {
|
|
public void run() {
|
|
setSuperValue(sceneObject);
|
|
setSuperValue(sceneObject);
|
|
changing = false;
|
|
changing = false;
|
|
@@ -426,7 +433,9 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
protected void addUndo(final Object before, final Object after) {
|
|
protected void addUndo(final Object before, final Object after) {
|
|
SceneUndoRedoManager undoRedo = Lookup.getDefault().lookup(SceneUndoRedoManager.class);
|
|
SceneUndoRedoManager undoRedo = Lookup.getDefault().lookup(SceneUndoRedoManager.class);
|
|
if (undoRedo == null) {
|
|
if (undoRedo == null) {
|
|
- logger.log(Level.WARNING, "Cannot access SceneUndoRedoManager");
|
|
|
|
|
|
+ logger.log(Level.WARNING, "Cannot access SceneUndoRedoManager. "
|
|
|
|
+ + "If you are editing properties without having a j3o file open,"
|
|
|
|
+ + "you wont have undo/redo support!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
undoRedo.addEdit(this, new AbstractUndoableSceneEdit() {
|
|
undoRedo.addEdit(this, new AbstractUndoableSceneEdit() {
|
|
@@ -458,7 +467,7 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
* Add a ScenePropertyChangeListener to listen for changes of this propety.
|
|
* Add a ScenePropertyChangeListener to listen for changes of this propety.
|
|
* See the "PROP_XXX" properties for a list of change callback types.
|
|
* See the "PROP_XXX" properties for a list of change callback types.
|
|
*
|
|
*
|
|
- * @param listener
|
|
|
|
|
|
+ * @param listener The Listener
|
|
*/
|
|
*/
|
|
public void addPropertyChangeListener(ScenePropertyChangeListener listener) {
|
|
public void addPropertyChangeListener(ScenePropertyChangeListener listener) {
|
|
if (listener != null) {
|
|
if (listener != null) {
|
|
@@ -470,6 +479,8 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
/**
|
|
/**
|
|
* Removes a ScenePropertyChangeListener that was listening for changes of
|
|
* Removes a ScenePropertyChangeListener that was listening for changes of
|
|
* this propety.
|
|
* this propety.
|
|
|
|
+ *
|
|
|
|
+ * @param listener The Listener
|
|
*/
|
|
*/
|
|
public void removePropertyChangeListener(ScenePropertyChangeListener listener) {
|
|
public void removePropertyChangeListener(ScenePropertyChangeListener listener) {
|
|
if (listener != null) {
|
|
if (listener != null) {
|
|
@@ -486,10 +497,10 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|
*/
|
|
*/
|
|
protected void notifyListeners(final String type, final Object before, final Object after) {
|
|
protected void notifyListeners(final String type, final Object before, final Object after) {
|
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
|
|
|
+ @Override
|
|
public void run() {
|
|
public void run() {
|
|
logger.log(Level.FINE, "Notify SceneExplorer listeners");
|
|
logger.log(Level.FINE, "Notify SceneExplorer listeners");
|
|
- for (Iterator<ScenePropertyChangeListener> it = listeners.iterator(); it.hasNext();) {
|
|
|
|
- ScenePropertyChangeListener propertyChangeListener = it.next();
|
|
|
|
|
|
+ for (ScenePropertyChangeListener propertyChangeListener : listeners) {
|
|
propertyChangeListener.propertyChange(type, getName(), before, after);
|
|
propertyChangeListener.propertyChange(type, getName(), before, after);
|
|
}
|
|
}
|
|
}
|
|
}
|