- improve "filter enabled" logic

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9000 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent e6c6f047ba
commit 5a5f321304
  1. 73
      sdk/jme3-core/src/com/jme3/gde/core/filters/FilterExplorerTopComponent.java

@ -74,7 +74,7 @@ public final class FilterExplorerTopComponent extends TopComponent implements Ex
private transient ExplorerManager explorerManager = new ExplorerManager(); private transient ExplorerManager explorerManager = new ExplorerManager();
private FilterDataObject currentFile; private FilterDataObject currentFile;
private FilterPostProcessorNode node; private FilterPostProcessorNode node;
private boolean added = false; private boolean filterEnabled = false;
public FilterExplorerTopComponent() { public FilterExplorerTopComponent() {
initComponents(); initComponents();
@ -133,8 +133,7 @@ public final class FilterExplorerTopComponent extends TopComponent implements Ex
@Override @Override
public void componentClosed() { public void componentClosed() {
// TODO add custom code on component closing // TODO add custom code on component closing
//explorerManager.setRootContext(Node.EMPTY); closeFile();
setActivatedNodes(new Node[]{});
} }
void writeProperties(java.util.Properties p) { void writeProperties(java.util.Properties p) {
@ -150,52 +149,60 @@ public final class FilterExplorerTopComponent extends TopComponent implements Ex
} }
public void loadFile(FilterDataObject object) { public void loadFile(FilterDataObject object) {
explorerManager.setRootContext(object.getLookup().lookup(FilterPostProcessorNode.class)); currentFile = object;
node = object.getLookup().lookup(FilterPostProcessorNode.class); node = object.getLookup().lookup(FilterPostProcessorNode.class);
explorerManager.setRootContext(node);
setActivatedNodes(new Node[]{object.getNodeDelegate()}); setActivatedNodes(new Node[]{object.getNodeDelegate()});
updateFilterState();
open(); open();
boolean wasAdded = added;
if (currentFile != null && added) {
setFilterEnabled(false);
}
currentFile = object;
if (wasAdded) {
setFilterEnabled(true);
}
requestVisible(); requestVisible();
} }
public void closeFile() {
currentFile = null;
node = null;
explorerManager.setRootContext(Node.EMPTY);
setActivatedNodes(new Node[]{});
updateFilterState();
}
public synchronized void setFilterEnabled(final boolean enabled) { public synchronized void setFilterEnabled(final boolean enabled) {
if (added == enabled) { filterEnabled = enabled;
return; updateFilterState();
} }
if (currentFile != null) {
added = enabled; private synchronized void updateFilterState() {
final FilterPostProcessor fpp = this.node.getFilterPostProcessor(); final FilterPostProcessor fpp = this.node != null ? this.node.getFilterPostProcessor() : null;
clearFilters();
if (filterEnabled && fpp != null) {
SceneApplication.getApplication().enqueue(new Callable() { SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception { public Object call() throws Exception {
if (enabled) { SceneApplication.getApplication().getViewPort().addProcessor(fpp);
SceneApplication.getApplication().getViewPort().addProcessor(fpp); Logger.getLogger(FilterExplorerTopComponent.class.getName()).log(Level.INFO, "Enabled post filters");
Logger.getLogger(FilterExplorerTopComponent.class.getName()).log(Level.INFO, "Enabled post filters");
} else {
for (Iterator<SceneProcessor> it = SceneApplication.getApplication().getViewPort().getProcessors().iterator(); it.hasNext();) {
SceneProcessor proc = it.next();
if (proc instanceof FilterPostProcessor) {
it.remove();
proc.cleanup();
}
}
// SceneApplication.getApplication().getViewPort().removeProcessor(fpp);
Logger.getLogger(FilterExplorerTopComponent.class.getName()).log(Level.INFO, "Disabled post filters");
}
return null; return null;
} }
}); });
} }
} }
private synchronized void clearFilters() {
SceneApplication.getApplication().enqueue(new Callable() {
public Object call() throws Exception {
for (Iterator<SceneProcessor> it = SceneApplication.getApplication().getViewPort().getProcessors().iterator(); it.hasNext();) {
SceneProcessor proc = it.next();
if (proc instanceof FilterPostProcessor) {
it.remove();
proc.cleanup();
}
Logger.getLogger(FilterExplorerTopComponent.class.getName()).log(Level.INFO, "Disabled post filters");
}
return null;
}
});
}
/** /**
* Gets default instance. Do not use directly: reserved for *.settings files only, * Gets default instance. Do not use directly: reserved for *.settings files only,
* i.e. deserialization routines; otherwise you could get a non-deserialized instance. * i.e. deserialization routines; otherwise you could get a non-deserialized instance.

Loading…
Cancel
Save