From 5a5f321304453dbf1f8887f2f169154423d7f014 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Sun, 8 Jan 2012 16:23:19 +0000 Subject: [PATCH] SDK: - improve "filter enabled" logic git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9000 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../filters/FilterExplorerTopComponent.java | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/sdk/jme3-core/src/com/jme3/gde/core/filters/FilterExplorerTopComponent.java b/sdk/jme3-core/src/com/jme3/gde/core/filters/FilterExplorerTopComponent.java index 34f24b060..18bb3f957 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/filters/FilterExplorerTopComponent.java +++ b/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 FilterDataObject currentFile; private FilterPostProcessorNode node; - private boolean added = false; + private boolean filterEnabled = false; public FilterExplorerTopComponent() { initComponents(); @@ -133,8 +133,7 @@ public final class FilterExplorerTopComponent extends TopComponent implements Ex @Override public void componentClosed() { // TODO add custom code on component closing - //explorerManager.setRootContext(Node.EMPTY); - setActivatedNodes(new Node[]{}); + closeFile(); } void writeProperties(java.util.Properties p) { @@ -150,52 +149,60 @@ public final class FilterExplorerTopComponent extends TopComponent implements Ex } public void loadFile(FilterDataObject object) { - explorerManager.setRootContext(object.getLookup().lookup(FilterPostProcessorNode.class)); + currentFile = object; node = object.getLookup().lookup(FilterPostProcessorNode.class); + explorerManager.setRootContext(node); setActivatedNodes(new Node[]{object.getNodeDelegate()}); + updateFilterState(); open(); - boolean wasAdded = added; - if (currentFile != null && added) { - setFilterEnabled(false); - } - currentFile = object; - if (wasAdded) { - setFilterEnabled(true); - } requestVisible(); } + public void closeFile() { + currentFile = null; + node = null; + explorerManager.setRootContext(Node.EMPTY); + setActivatedNodes(new Node[]{}); + updateFilterState(); + } + public synchronized void setFilterEnabled(final boolean enabled) { - if (added == enabled) { - return; - } - if (currentFile != null) { - added = enabled; - final FilterPostProcessor fpp = this.node.getFilterPostProcessor(); + filterEnabled = enabled; + updateFilterState(); + } + + private synchronized void updateFilterState() { + final FilterPostProcessor fpp = this.node != null ? this.node.getFilterPostProcessor() : null; + clearFilters(); + if (filterEnabled && fpp != null) { SceneApplication.getApplication().enqueue(new Callable() { public Object call() throws Exception { - if (enabled) { - SceneApplication.getApplication().getViewPort().addProcessor(fpp); - Logger.getLogger(FilterExplorerTopComponent.class.getName()).log(Level.INFO, "Enabled post filters"); - } else { - for (Iterator 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"); - } + SceneApplication.getApplication().getViewPort().addProcessor(fpp); + Logger.getLogger(FilterExplorerTopComponent.class.getName()).log(Level.INFO, "Enabled post filters"); return null; } }); - } } + private synchronized void clearFilters() { + SceneApplication.getApplication().enqueue(new Callable() { + + public Object call() throws Exception { + for (Iterator 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, * i.e. deserialization routines; otherwise you could get a non-deserialized instance.