Ver código fonte

A whole lot of code formatting, unused import removal and other readability fixes.
Syntax checking should now stop from generating errors with passed jME3 built-in vars. Those variables are only accepted used with "in" or "uniform".

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9346 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

dan..om 13 anos atrás
pai
commit
46d777bf88

+ 6 - 6
jme3-glsl-support/nbproject/project.properties

@@ -1,6 +1,6 @@
-javac.compilerargs=-Xlint -Xlint:-serial
-javac.source=1.5
-license.file=license.txt
-nbm.homepage=http://kenai.com/projects/netbeans-opengl-pack
-nbm.module.author=Mathias Henze, Michael Bien
-spec.version.base=3.0.0
+javac.compilerargs=-Xlint -Xlint:-serial
+javac.source=1.5
+license.file=license.txt
+nbm.homepage=http://kenai.com/projects/netbeans-opengl-pack
+nbm.module.author=Mathias Henze, Michael Bien, Dany Rioux
+spec.version.base=3.0.1.0

+ 28 - 33
jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslCompletionProvider.java

@@ -23,7 +23,6 @@ import java.awt.Graphics;
 import java.awt.event.KeyEvent;
 import java.net.URL;
 import java.util.Iterator;
-import java.util.Map;
 import net.java.nboglpack.glsleditor.dataobject.GlslFragmentShaderDataLoader;
 import net.java.nboglpack.glsleditor.dataobject.GlslGeometryShaderDataLoader;
 import net.java.nboglpack.glsleditor.dataobject.GlslVertexShaderDataLoader;
@@ -31,7 +30,6 @@ import net.java.nboglpack.glsleditor.glsl.Glsl;
 import net.java.nboglpack.glsleditor.vocabulary.GLSLElementDescriptor;
 import org.netbeans.spi.editor.completion.support.CompletionUtilities;
 
-
 /**
  * Completion provider for the OpenGL Shading Language editor.
  *
@@ -41,9 +39,8 @@ import org.netbeans.spi.editor.completion.support.CompletionUtilities;
 public class GlslCompletionProvider implements CompletionProvider {
 
     private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslCompletionProvider.class.getName());
-
     private final String mimeType;
-    
+
     private GlslCompletionProvider(String mimeType) {
         this.mimeType = mimeType;
     }
@@ -55,20 +52,19 @@ public class GlslCompletionProvider implements CompletionProvider {
     public int getAutoQueryTypes(JTextComponent component, String typedText) {
         return 0;
     }
-    
-    public static GlslCompletionProvider createVSCompletionProvider(){
+
+    public static GlslCompletionProvider createVSCompletionProvider() {
         return new GlslCompletionProvider(GlslVertexShaderDataLoader.REQUIRED_MIME);
     }
-    
-    public static GlslCompletionProvider createGSCompletionProvider(){
+
+    public static GlslCompletionProvider createGSCompletionProvider() {
         return new GlslCompletionProvider(GlslGeometryShaderDataLoader.REQUIRED_MIME);
     }
-    
-    public static GlslCompletionProvider createFSCompletionProvider(){
+
+    public static GlslCompletionProvider createFSCompletionProvider() {
         return new GlslCompletionProvider(GlslFragmentShaderDataLoader.REQUIRED_MIME);
     }
 
-    
     private static class GlslCompletionQuery extends AsyncCompletionQuery {
 
         private GlslVocabularyManager vocabulary;
@@ -78,13 +74,13 @@ public class GlslCompletionProvider implements CompletionProvider {
         }
 
         protected void query(CompletionResultSet completionResultSet, Document document, int pos) {
-            
+
             fillResultset(completionResultSet, document, pos);
             completionResultSet.finish();
         }
 
         private void fillResultset(CompletionResultSet completionResultSet, Document doc, int pos) {
-            
+
             Element paragraph = ((BaseDocument) doc).getParagraphElement(pos);
             String prefix;
             try {
@@ -99,14 +95,14 @@ public class GlslCompletionProvider implements CompletionProvider {
             }
 
             // add user declared functions first
-            synchronized(Glsl.declaredFunctions) {
+            synchronized (Glsl.declaredFunctions) {
                 Set<Entry<String, GLSLElementDescriptor>> entrySet = Glsl.declaredFunctions.entrySet();
 
                 for (Entry<String, GLSLElementDescriptor> entry : entrySet) {
 
                     String name = entry.getKey();
                     GLSLElementDescriptor desc = entry.getValue();
-                    
+
                     if (name.regionMatches(true, 0, prefix, 0, prefix.length())) {
                         completionResultSet.addItem(new GlslCompletionItem(name.substring(0, name.indexOf('(')), desc, prefix, pos));
                     }
@@ -116,21 +112,22 @@ public class GlslCompletionProvider implements CompletionProvider {
 
             // add core GLSL completion items
             Iterator it = vocabulary.getKeys().iterator();
-            
+
             while (it.hasNext()) {
 
                 String name = (String) it.next();
-                
+
                 if (name.regionMatches(true, 0, prefix, 0, prefix.length())) {
 
                     GLSLElementDescriptor[] elements = vocabulary.getDesc(name);
-                    
+
                     if (elements != null) {
-                        for (GLSLElementDescriptor element : elements) 
+                        for (GLSLElementDescriptor element : elements) {
                             completionResultSet.addItem(new GlslCompletionItem(name, element, prefix, pos));
+                        }
                     }
                 }
-                
+
             }
         }
     }
@@ -141,14 +138,11 @@ public class GlslCompletionProvider implements CompletionProvider {
         private GLSLElementDescriptor content;
         private int carretPosition = 0;
         private String prefix;
-
         private String leftText;
         private String rightText;
-
         private String ARGUMENTS_COLOR = "<font color=#b28b00>";
         private String BUILD_IN_VAR_COLOR = "<font color=#ce7b00>";
         private String KEYWORD_COLOR = "<font color=#000099>";
-
         private int priority;
 
         public GlslCompletionItem(String key, GLSLElementDescriptor content, String prefix, int carretPosition) {
@@ -207,7 +201,7 @@ public class GlslCompletionProvider implements CompletionProvider {
                     text.append(BUILD_IN_VAR_COLOR);
                     break;
             }
-            
+
             text.append("<b>");
             text.append(key);
             text.append("</b></font>");
@@ -224,8 +218,8 @@ public class GlslCompletionProvider implements CompletionProvider {
             Completion.get().hideAll();
             // replace prefix with key
             try {
-                component.getDocument().remove(carretPosition-prefix.length(), prefix.length());
-                component.getDocument().insertString(carretPosition-prefix.length(), key, null);
+                component.getDocument().remove(carretPosition - prefix.length(), prefix.length());
+                component.getDocument().insertString(carretPosition - prefix.length(), key, null);
             } catch (BadLocationException e) {
                 LOGGER.notify(e);
             }
@@ -240,9 +234,9 @@ public class GlslCompletionProvider implements CompletionProvider {
         }
 
         public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
-            
+
             CompletionUtilities.renderHtml(null, leftText, rightText, g, defaultFont, defaultColor, width, height, selected);
-            
+
         }
 
         public CompletionTask createDocumentationTask() {
@@ -250,8 +244,9 @@ public class GlslCompletionProvider implements CompletionProvider {
             if (content.doc == null) {
                 return null;
             }
-            
+
             return new AsyncCompletionTask(new AsyncCompletionQuery() {
+
                 private GlslDocItem item = new GlslDocItem(key, content);
 
                 protected void query(CompletionResultSet completionResultSet, Document document, int i) {
@@ -288,23 +283,23 @@ public class GlslCompletionProvider implements CompletionProvider {
         private String text;
 
         public GlslDocItem(String item, GLSLElementDescriptor content) {
-            
+
             StringBuilder sb = new StringBuilder();
             sb.append("<code>");
-            if(content.type != null) {
+            if (content.type != null) {
                 sb.append(content.type);
                 sb.append(" ");
             }
             sb.append("<b>");
             sb.append(item);
             sb.append("</b>");
-            if(content.arguments != null) {
+            if (content.arguments != null) {
                 sb.append(content.arguments);
             }
             sb.append("</code><p>");
             sb.append(content.doc);
             sb.append("</p>");
-            
+
             text = sb.toString();
         }
 

+ 17 - 18
jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslShaderFileObserver.java

@@ -2,14 +2,11 @@ package net.java.nboglpack.glsleditor;
 
 /**
  * Created on 26. March 2007, 00:49
- * 
+ *
  */
-
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
-//import net.java.nboglpack.glslcompiler.GLSLCompilerService;
 import org.openide.loaders.DataObject;
-import org.openide.util.Lookup;
 import org.openide.util.RequestProcessor;
 
 /**
@@ -17,17 +14,18 @@ import org.openide.util.RequestProcessor;
  * @author Michael Bien
  */
 public class GlslShaderFileObserver implements DocumentListener {
-    
- private final DataObject observedDao;
- private final static RequestProcessor RP = new RequestProcessor("compiler");
- private final RequestProcessor.Task compilerTask;
- private boolean runOnDocUpdate = true;
- private int compileDelay = 500;
-    
+
+    private final DataObject observedDao;
+    private final static RequestProcessor RP = new RequestProcessor("compiler");
+    private final RequestProcessor.Task compilerTask;
+    private boolean runOnDocUpdate = true;
+    private int compileDelay = 500;
+
     public GlslShaderFileObserver(DataObject dao) {
         observedDao = dao;
-        
+
         compilerTask = RP.create(new Runnable() {
+
             public void run() {
 //                GLSLCompilerService compiler = Lookup.getDefault().lookup(GLSLCompilerService.class);
 //                compiler.compileShader(new DataObject[] {observedDao}, false);
@@ -36,20 +34,22 @@ public class GlslShaderFileObserver implements DocumentListener {
         compilerTask.setPriority(Thread.MIN_PRIORITY);
     }
 
-    
     // DocumentListener
     public void insertUpdate(DocumentEvent arg0) {
-        if(runOnDocUpdate)
+        if (runOnDocUpdate) {
             runCompileTask();
+        }
     }
+
     public void removeUpdate(DocumentEvent arg0) {
-        if(runOnDocUpdate)
+        if (runOnDocUpdate) {
             runCompileTask();
+        }
     }
+
     public void changedUpdate(DocumentEvent arg0) {
     }
-    
-    
+
     public final void runCompileTask() {
         compilerTask.schedule(compileDelay);
     }
@@ -61,5 +61,4 @@ public class GlslShaderFileObserver implements DocumentListener {
     public void setRunOnDocUpdate(boolean runOnDocUpdate) {
         this.runOnDocUpdate = runOnDocUpdate;
     }
-    
 }

+ 68 - 70
jme3-glsl-support/src/net/java/nboglpack/glsleditor/GlslVocabularyManager.java

@@ -4,7 +4,6 @@
  * Created on 12. Februar 2006, 03:37
  *
  */
-
 package net.java.nboglpack.glsleditor;
 
 import java.io.InputStream;
@@ -30,143 +29,142 @@ import org.openide.filesystems.FileUtil;
  * @author Michael Bien
  */
 public class GlslVocabularyManager {
-    
- private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslVocabularyManager.class.getName());
- private static final HashMap<String, GlslVocabularyManager> instances = new HashMap<String, GlslVocabularyManager>();
- private static GLSLVocabulary vocabulary = null;
-
- private final String mimetype;
- private final Set<String> keySet;
- private final Map<String, GLSLElementDescriptor[]> vocabularyExtention;
-    
-    /** Creates a new instance of GlslVocabularyManager */
+
+    private static final ErrorManager LOGGER = ErrorManager.getDefault().getInstance(GlslVocabularyManager.class.getName());
+    private static final HashMap<String, GlslVocabularyManager> instances = new HashMap<String, GlslVocabularyManager>();
+    private static GLSLVocabulary vocabulary = null;
+    private final String mimetype;
+    private final Set<String> keySet;
+    private final Map<String, GLSLElementDescriptor[]> vocabularyExtention;
+
+    /**
+     * Creates a new instance of GlslVocabularyManager
+     */
     private GlslVocabularyManager(String mimetype) {
-        
-        if(    !mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)
-            && !mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)
-            && !mimetype.equals(GlslGeometryShaderDataLoader.REQUIRED_MIME)) {
-            throw new IllegalArgumentException(mimetype+" is no GLSL mime type");
+
+        if (!mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)
+                && !mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)
+                && !mimetype.equals(GlslGeometryShaderDataLoader.REQUIRED_MIME)) {
+            throw new IllegalArgumentException(mimetype + " is no GLSL mime type");
         }
-        
-        
+
+
         this.mimetype = mimetype;
-        
-        if(vocabulary == null)
+
+        if (vocabulary == null) {
             loadVocabulary();
-        
-        if(mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)) {
+        }
+
+        if (mimetype.equals(GlslFragmentShaderDataLoader.REQUIRED_MIME)) {
             vocabularyExtention = vocabulary.fragmentShaderVocabulary;
-        }else if(mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)) {
+        } else if (mimetype.equals(GlslVertexShaderDataLoader.REQUIRED_MIME)) {
             vocabularyExtention = vocabulary.vertexShaderVocabulary;
-        }else {
+        } else {
             vocabularyExtention = vocabulary.geometryShaderVocabulary;
         }
-        
+
         // merges two views
         keySet = new AbstractSet<String>() {
-            
+
             private final Set<String> mainSet = vocabulary.mainVocabulary.keySet();
             private final Set<String> extSet = vocabularyExtention.keySet();
-            
-            
+
             public Iterator<String> iterator() {
-                return new Iterator<String>(){
-                    
+                return new Iterator<String>() {
+
                     Iterator<String> mainIt = mainSet.iterator();
                     Iterator<String> extIt = extSet.iterator();
-                    
+
                     public boolean hasNext() {
                         return mainIt.hasNext() || extIt.hasNext();
                     }
-                    
+
                     public String next() {
-                        if(mainIt.hasNext())
+                        if (mainIt.hasNext()) {
                             return mainIt.next();
-                        else
+                        } else {
                             return extIt.next();
+                        }
                     }
-                    
+
                     public void remove() {
                         throw new UnsupportedOperationException("Not supported yet.");
                     }
-                    
                 };
             }
-            
+
             public int size() {
-                return mainSet.size()+extSet.size();
+                return mainSet.size() + extSet.size();
             }
-            
         };
-        
+
     }
-    
+
     public static GlslVocabularyManager getInstance(String mimetype) {
-        
+
         GlslVocabularyManager instance = instances.get(mimetype);
-        
-        if(instance == null) {
+
+        if (instance == null) {
             instance = new GlslVocabularyManager(mimetype);
-            instances.put(mimetype,instance);
+            instances.put(mimetype, instance);
         }
-        
+
         return instance;
     }
-    
+
     private void loadVocabulary() {
-        
-        FileObject vocabularyfile = FileUtil.getConfigFile("Editors/"+mimetype+"/vocabulary.xml");
-        
+
+        FileObject vocabularyfile = FileUtil.getConfigFile("Editors/" + mimetype + "/vocabulary.xml");
+
         if (vocabularyfile != null) {
-            
+
             InputStream is = null;
-            
+
             try {
-                
+
                 is = vocabularyfile.getInputStream();
-                
+
                 // workaround; nb does not allow usage of jdk's jaxb implementation
                 // => we have to provide JAXB as library wrapper module and load it via module classloader
                 JAXBContext jc = JAXBContext.newInstance("net.java.nboglpack.glsleditor.vocabulary", this.getClass().getClassLoader());
 
                 Unmarshaller unmarshaller = jc.createUnmarshaller();
-                vocabulary = (GLSLVocabulary)unmarshaller.unmarshal(is);
+                vocabulary = (GLSLVocabulary) unmarshaller.unmarshal(is);
 
             } catch (Exception ex) {
-                
+
                 // create empty vocab
                 vocabulary = new GLSLVocabulary();
                 LOGGER.notify(ex);
-                
+
             } finally {
-                
-                if(is != null) {
+
+                if (is != null) {
                     try {
                         is.close();
                     } catch (Exception e) {
                         LOGGER.notify(e);
                     }
                 }
-                
+
             }
-            
+
         }
-        
+
     }
-    
+
     public Set getKeys() {
         return keySet;
     }
-    
+
     public GLSLElementDescriptor[] getDesc(String key) {
-        
+
         GLSLElementDescriptor[] desc = vocabulary.mainVocabulary.get(key);
-        
-        if(desc == null)
+
+        if (desc == null) {
             desc = vocabularyExtention.get(key);
-        
+        }
+
         return desc;
     }
-    
-    
 }

+ 30 - 28
jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslFragmentShaderDataObject.java

@@ -13,45 +13,47 @@ import org.openide.nodes.Node;
 import org.openide.text.CloneableEditorSupport;
 import org.openide.text.DataEditorSupport;
 
+public class GlslFragmentShaderDataObject extends MultiDataObject {
 
+    private final GlslShaderFileObserver observer;
 
-public class GlslFragmentShaderDataObject extends MultiDataObject {
-    
- private final GlslShaderFileObserver observer;
-    
     public GlslFragmentShaderDataObject(FileObject pf, GlslFragmentShaderDataLoader loader) throws DataObjectExistsException, IOException {
-        
+
         super(pf, loader);
-        
+
         CookieSet cookies = getCookieSet();
-        observer= new GlslShaderFileObserver(this);
-        
-        final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies);
+        observer = new GlslShaderFileObserver(this);
+
+        final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
         support.addPropertyChangeListener(
-            new PropertyChangeListener(){
-                public void propertyChange(PropertyChangeEvent event) {
-                    if("document".equals(event.getPropertyName())){
-                        if(event.getNewValue()!=null)
-                        {
-                            support.getDocument().addDocumentListener(observer);
-                            observer.runCompileTask();
-                        }
-                        else if(event.getOldValue()!=null)
-                        {
-                            // cylab: I think this is never called.
-                            // But I don't know if unregistering the observer makes any difference...
-                            ((Document)event.getOldValue()).removeDocumentListener(observer);
-                        }
-                    }
-                }
-            }
-        );
+                new PropertyChangeListenerImpl(support));
         cookies.add((Node.Cookie) support);
     }
-    
+
     @Override
     protected Node createNodeDelegate() {
         return new GlslFragmentShaderDataNode(this);
     }
 
+    private class PropertyChangeListenerImpl implements PropertyChangeListener {
+
+        private final CloneableEditorSupport support;
+
+        public PropertyChangeListenerImpl(CloneableEditorSupport support) {
+            this.support = support;
+        }
+
+        public void propertyChange(PropertyChangeEvent event) {
+            if ("document".equals(event.getPropertyName())) {
+                if (event.getNewValue() != null) {
+                    support.getDocument().addDocumentListener(observer);
+                    observer.runCompileTask();
+                } else if (event.getOldValue() != null) {
+                    // cylab: I think this is never called.
+                    // But I don't know if unregistering the observer makes any difference...
+                    ((Document) event.getOldValue()).removeDocumentListener(observer);
+                }
+            }
+        }
+    }
 }

+ 23 - 16
jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslGeometryShaderDataObject.java

@@ -14,7 +14,6 @@ import org.openide.text.CloneableEditorSupport;
 import org.openide.util.Lookup;
 import org.openide.text.DataEditorSupport;
 
-
 /**
  * @author Michael Bien
  */
@@ -30,21 +29,7 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
         observer = new GlslShaderFileObserver(this);
 
         final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
-        support.addPropertyChangeListener(new PropertyChangeListener() {
-
-            public void propertyChange(PropertyChangeEvent event) {
-                if ("document".equals(event.getPropertyName())) {
-                    if (event.getNewValue() != null) {
-                        support.getDocument().addDocumentListener(observer);
-                        observer.runCompileTask();
-                    } else if (event.getOldValue() != null) {
-                        // cylab: I think this is never called.
-                        // But I don't know if unregistering the observer makes any difference...
-                        ((Document) event.getOldValue()).removeDocumentListener(observer);
-                    }
-                }
-            }
-        });
+        support.addPropertyChangeListener(new PropertyChangeListenerImpl(support));
         cookies.add((Node.Cookie) support);
     }
 
@@ -57,4 +42,26 @@ public class GlslGeometryShaderDataObject extends MultiDataObject {
     public Lookup getLookup() {
         return getCookieSet().getLookup();
     }
+
+    private class PropertyChangeListenerImpl implements PropertyChangeListener {
+
+        private final CloneableEditorSupport support;
+
+        public PropertyChangeListenerImpl(CloneableEditorSupport support) {
+            this.support = support;
+        }
+
+        public void propertyChange(PropertyChangeEvent event) {
+            if ("document".equals(event.getPropertyName())) {
+                if (event.getNewValue() != null) {
+                    support.getDocument().addDocumentListener(observer);
+                    observer.runCompileTask();
+                } else if (event.getOldValue() != null) {
+                    // cylab: I think this is never called.
+                    // But I don't know if unregistering the observer makes any difference...
+                    ((Document) event.getOldValue()).removeDocumentListener(observer);
+                }
+            }
+        }
+    }
 }

+ 30 - 26
jme3-glsl-support/src/net/java/nboglpack/glsleditor/dataobject/GlslVertexShaderDataObject.java

@@ -1,6 +1,5 @@
 package net.java.nboglpack.glsleditor.dataobject;
 
-import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
 import net.java.nboglpack.glsleditor.GlslShaderFileObserver;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
@@ -15,40 +14,45 @@ import org.openide.text.CloneableEditorSupport;
 import org.openide.text.DataEditorSupport;
 
 public class GlslVertexShaderDataObject extends MultiDataObject {
-    
- private GlslShaderFileObserver observer;
+
+    private GlslShaderFileObserver observer;
 
     public GlslVertexShaderDataObject(FileObject pf, GlslVertexShaderDataLoader loader) throws DataObjectExistsException, IOException {
-        
+
         super(pf, loader);
         CookieSet cookies = getCookieSet();
-        observer= new GlslShaderFileObserver(this);
-        
-        final CloneableEditorSupport support= DataEditorSupport.create(this, getPrimaryEntry(), cookies);
+        observer = new GlslShaderFileObserver(this);
+
+        final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
         support.addPropertyChangeListener(
-            new PropertyChangeListener(){
-                public void propertyChange(PropertyChangeEvent event) {
-                    if("document".equals(event.getPropertyName())){
-                        if(event.getNewValue()!=null)
-                        {
-                            support.getDocument().addDocumentListener(observer);
-                            observer.runCompileTask();
-                        }
-                        else if(event.getOldValue()!=null)
-                        {
-                            // cylab: I think this is never called.
-                            // But I don't know if unregistering the observer makes any difference...
-                            ((Document)event.getOldValue()).removeDocumentListener(observer);
-                        }
-                    }
-                }
-            }
-        );
+                new PropertyChangeListenerImpl(support));
         cookies.add((Node.Cookie) support);
     }
-    
+
     @Override
     protected Node createNodeDelegate() {
         return new GlslVertexShaderDataNode(this);
     }
+
+    private class PropertyChangeListenerImpl implements PropertyChangeListener {
+
+        private final CloneableEditorSupport support;
+
+        public PropertyChangeListenerImpl(CloneableEditorSupport support) {
+            this.support = support;
+        }
+
+        public void propertyChange(PropertyChangeEvent event) {
+            if ("document".equals(event.getPropertyName())) {
+                if (event.getNewValue() != null) {
+                    support.getDocument().addDocumentListener(observer);
+                    observer.runCompileTask();
+                } else if (event.getOldValue() != null) {
+                    // cylab: I think this is never called.
+                    // But I don't know if unregistering the observer makes any difference...
+                    ((Document) event.getOldValue()).removeDocumentListener(observer);
+                }
+            }
+        }
+    }
 }

+ 12 - 11
jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/GLSL_130.nbs

@@ -176,10 +176,10 @@ assignment_operator = <EQ>
 
 comperator = <LEFT_ANGLE> | <RIGHT_ANGLE> | <LE> | <GE> | <EQEQ> | <NE>;
 
-operator = <PLUS> 
-         | <MINUS> 
-         | <STAR> 
-         | <SLASH> 
+operator = <PLUS>
+         | <MINUS>
+         | <STAR>
+         | <SLASH>
          | <AMP>
          | <AMPAMP>
          | <BAR>            # reserved
@@ -191,13 +191,13 @@ operator = <PLUS>
          | <LEFT_BITSHIFT>; # reserved
 
 unary_operator = <PLUS>
-               | <MINUS> 
-               | <BANG> 
+               | <MINUS>
+               | <BANG>
                | <TILDE>; # reserved
 
 increment_or_decrement_operator = <PLUSPLUS> | <MINUSMINUS>;
 
-reserved = "asm" 
+reserved = "asm"
          | "common"
          | "partition"
          | "active"
@@ -213,9 +213,9 @@ reserved = "asm"
          | "noinline"
          | "volatile"
          | "public"
-         | "static" 
-         | "extern" 
-         | "external" 
+         | "static"
+         | "extern"
+         | "external"
          | "interface"
          | "long"
          | "short"
@@ -284,6 +284,7 @@ global_identifier_list = global_declared_identifier [array_index] (<COMMA> globa
 global_declared_identifier = <IDENTIFIER>;
 global_preprocessor = <PREPROCESSOR>;
 
+field_declaration = ("in" | "uniform") type_specifier_or_identifier <BUILD_IN_VAR> ;
 field_declaration = global_type_qualifier struct_declaration;
 field_declaration = global_type_qualifier global_type_declaration [assignment2];
 
@@ -364,7 +365,7 @@ constructor_call = type_specifier [array_index] "(" [expression_list] ")"; #TODO
 expression_list = "void" | (expression (<COMMA> expression)*);
 
 ## code flow ###################################################################
-conditional_statement = if_statement 
+conditional_statement = if_statement
                       | for_statement
                       | while_statement
                       | do_while_statement

+ 138 - 126
jme3-glsl-support/src/net/java/nboglpack/glsleditor/glsl/Glsl.java

@@ -1,10 +1,9 @@
 /*
  * Glsl.java
- * 
+ *
  * Created on 24.09.2007, 00:46:53
- * 
+ *
  */
-
 package net.java.nboglpack.glsleditor.glsl;
 
 import java.util.HashMap;
@@ -27,79 +26,86 @@ import org.netbeans.api.lexer.TokenUtilities;
  * @author Michael Bien
  */
 public final class Glsl {
-    
- private final static String KEYWORD_FONT_COLOR = "<font color=808080>";
- 
- public final static Map<String, GLSLElementDescriptor> declaredFunctions = new HashMap<String, GLSLElementDescriptor>();
-    
- private Glsl() {}
-    
-     /**
+
+    private final static String KEYWORD_FONT_COLOR = "<font color=808080>";
+    public final static Map<String, GLSLElementDescriptor> declaredFunctions = new HashMap<String, GLSLElementDescriptor>();
+
+    private Glsl() {
+    }
+
+    /**
      * Assembles a human readable String containing the declaraton of a function.
      * Asumes that the current token of the SyntaxContext represents the function name.
      */
     public static final String createFunctionDeclarationString(SyntaxContext context) {
-        
-        AbstractDocument document = (AbstractDocument)context.getDocument();
-        
+
+        AbstractDocument document = (AbstractDocument) context.getDocument();
+
         StringBuilder sb = new StringBuilder();
-        
+
         try {
 
             document.readLock();
-            
+
             TokenSequence sequence = TokenHierarchy.get(context.getDocument()).tokenSequence();
             sequence.move(context.getOffset());
             sequence.moveNext();
-            
+
             sb.append("<html>");
 
             int moved = 0;
-            while(sequence.movePrevious() && isIgnoredToken(sequence.token()))
+            while (sequence.movePrevious() && isIgnoredToken(sequence.token())) {
                 moved++;
+            }
 
             String type = sequence.token().toString();
-            while(moved-- >= 0)
+            while (moved-- >= 0) {
                 sequence.moveNext();
+            }
 
             // append function name
             sb.append(sequence.token().text());
 
-            while(!TokenUtilities.equals(sequence.token().text(), "("))
+            while (!TokenUtilities.equals(sequence.token().text(), "(")) {
                 sequence.moveNext();
+            }
 
             sb.append("(");
 
             Token token;
             boolean first = true;
-            while(sequence.moveNext() && !TokenUtilities.equals(sequence.token().text(), ")")) {
+            while (sequence.moveNext() && !TokenUtilities.equals(sequence.token().text(), ")")) {
 
                 token = sequence.token();
 
-                if(!isIgnoredToken(token)) {
+                if (!isIgnoredToken(token)) {
 
-                    if(first) {
+                    if (first) {
                         sb.append(KEYWORD_FONT_COLOR);
-                    }else if(token.id() != GlslTokenId.COMMA && token.id() != GlslTokenId.BRACKET && token.id() != GlslTokenId.INTEGER_LITERAL) {
+                    } else if (token.id() != GlslTokenId.COMMA && token.id() != GlslTokenId.BRACKET && token.id() != GlslTokenId.INTEGER_LITERAL) {
                         sb.append(" ");
                     }
 
-                    if(!TokenUtilities.equals(token.text(), "void")) {
+                    if (!TokenUtilities.equals(token.text(), "void")) {
 
                         moved = 0;
-                        while(sequence.moveNext() && isIgnoredToken(sequence.token())) 
+                        while (sequence.moveNext() && isIgnoredToken(sequence.token())) {
                             moved++;
+                        }
 
-                        if(sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")"))
+                        if (sequence.token().id() == GlslTokenId.COMMA || TokenUtilities.equals(sequence.token().text(), ")")) {
                             sb.append("</font>");
+                        }
 
-                        while(moved-- >= 0)
+                        while (moved-- >= 0) {
                             sequence.movePrevious();
+                        }
 
                         sb.append(token.text());
 
-                        if(token.id() == GlslTokenId.COMMA) 
+                        if (token.id() == GlslTokenId.COMMA) {
                             sb.append(KEYWORD_FONT_COLOR);
+                        }
                     }
 
                     first = false;
@@ -109,39 +115,39 @@ public final class Glsl {
 
             sb.append("</font>)");
 
-            if(!"void".equals(type)) {
+            if (!"void".equals(type)) {
                 sb.append(" : ");
                 sb.append(KEYWORD_FONT_COLOR);
                 sb.append(type);
                 sb.append("</font>");
             }
             sb.append("</html>");
-            
+
         } finally {
-          document.readUnlock();
-        }         
-        
+            document.readUnlock();
+        }
+
         return sb.toString();
     }
-    
+
     /**
      * Assambles a human readable String containing the declaraton of a field and the field name itself.
      * Asumes that the current token of the SyntaxContext represents the field name.
      */
     public static final String createFieldDeclarationString(SyntaxContext context) {
-        
-        AbstractDocument document = (AbstractDocument)context.getDocument();
-        
+
+        AbstractDocument document = (AbstractDocument) context.getDocument();
+
         StringBuilder sb = new StringBuilder();
-        
+
         try {
 
             document.readLock();
-            
+
             TokenSequence sequence = TokenHierarchy.get(context.getDocument()).tokenSequence();
             sequence.move(context.getOffset());
             sequence.moveNext();
-            
+
             sb.append("<html>");
             sb.append(sequence.token().text());
             sb.append(KEYWORD_FONT_COLOR);
@@ -152,53 +158,55 @@ public final class Glsl {
             // read forward
             int moved = 0;
             Token token;
-            while(     sequence.moveNext()
+            while (sequence.moveNext()
                     && sequence.token().id() != GlslTokenId.SEMICOLON
                     && sequence.token().id() != GlslTokenId.COMMA
-                    && sequence.token().id() != GlslTokenId.EQ  ) {
+                    && sequence.token().id() != GlslTokenId.EQ) {
                 token = sequence.token();
-                if(!isIgnoredToken(token)) 
+                if (!isIgnoredToken(token)) {
                     sb.append(token);
+                }
                 moved++;
             }
-            while(moved-- >= 0)
+            while (moved-- >= 0) {
                 sequence.movePrevious();
+            }
 
             // read backwards throw the declaration
             boolean skipToken = false;
 
-            while(     sequence.movePrevious() 
-                    && sequence.token().id() != GlslTokenId.SEMICOLON 
-                    && sequence.token().id() != GlslTokenId.END_OF_LINE ) {
+            while (sequence.movePrevious()
+                    && sequence.token().id() != GlslTokenId.SEMICOLON
+                    && sequence.token().id() != GlslTokenId.END_OF_LINE) {
 
                 token = sequence.token();
 
-                if(!isIgnoredToken(token)) {
+                if (!isIgnoredToken(token)) {
 
                     // we have a struct declaration; skip everything between { }
-                    if(token.id() == GlslTokenId.BRACE && TokenUtilities.equals(token.text(), "}")) {
+                    if (token.id() == GlslTokenId.BRACE && TokenUtilities.equals(token.text(), "}")) {
                         movePreviousUntil(sequence, GlslTokenId.BRACE, "}", "{");
                         continue;
-                    }                
+                    }
 
                     // skip token in case of an comma seperated identifier list
-                    if(skipToken) {
-                        if(     token.id() == GlslTokenId.BRACKET
-                             && TokenUtilities.equals(token.text(), "]")    ) {
+                    if (skipToken) {
+                        if (token.id() == GlslTokenId.BRACKET
+                                && TokenUtilities.equals(token.text(), "]")) {
                             movePreviousUntil(sequence, GlslTokenId.BRACKET, "]", "[");
                             skipToken = false;
-                        }else {
+                        } else {
                             skipToken = false;
                         }
                         continue;
                     }
 
-                    if(token.id() == GlslTokenId.COMMA) {
+                    if (token.id() == GlslTokenId.COMMA) {
                         skipToken = true;
                         continue;
                     }
 
-                    if(!TokenUtilities.equals(token.text(), "struct")) {
+                    if (!TokenUtilities.equals(token.text(), "struct")) {
                         sb.insert(insertIndex, token.text());
                         sb.insert(insertIndex, " ");
                     }
@@ -209,50 +217,54 @@ public final class Glsl {
             sb.append("</font></html>");
         } finally {
             document.readUnlock();
-        } 
-        
-        
+        }
+
+
         return sb.toString();
     }
-   
-        
+
     public static final String createPreprocessorString(SyntaxContext context) {
-        
-        ASTNode node = (ASTNode)context.getASTPath().getLeaf();
+
+        ASTNode node = (ASTNode) context.getASTPath().getLeaf();
         List<ASTItem> children = node.getChildren();
-        
+
         String str = null;
-        
-        for (ASTItem item : children)
-            if (isTokenType(item, GlslTokenId.PREPROCESSOR.name()))
-                str = ((ASTToken)item).getIdentifier();
-        
-        
-        for(int i = 0; i < str.length(); i++) {
-            
+
+        for (ASTItem item : children) {
+            if (isTokenType(item, GlslTokenId.PREPROCESSOR.name())) {
+                str = ((ASTToken) item).getIdentifier();
+            }
+        }
+
+
+        for (int i = 0; i < str.length(); i++) {
+
             char c = str.charAt(i);
-            
-            if(c != '#' && !Character.isWhitespace(c))
-                for(int j = str.length()-1; j > i; j--)
-                    if(!Character.isWhitespace(str.charAt(j)))
-                        return str.substring(i, j+1);
-            
+
+            if (c != '#' && !Character.isWhitespace(c)) {
+                for (int j = str.length() - 1; j > i; j--) {
+                    if (!Character.isWhitespace(str.charAt(j))) {
+                        return str.substring(i, j + 1);
+                    }
+                }
+            }
+
         }
-        
+
         return str;
     }
-    
+
     /**
-     * called from withen GLSL_*.nbs each time the document has been modified.
+     * Called from withen GLSL_*.nbs each time the document has been modified.
      */
     public static void process(SyntaxContext context) {
-        
-        AbstractDocument document = (AbstractDocument)context.getDocument();
-        try{
+
+        AbstractDocument document = (AbstractDocument) context.getDocument();
+        try {
             document.readLock();
-            
-            // remember all declared funktions for auto completion
-            synchronized(declaredFunctions) {
+
+            // remember all declared functions for auto-completion
+            synchronized (declaredFunctions) {
                 declaredFunctions.clear();
             }
 
@@ -262,41 +274,43 @@ public final class Glsl {
 
                 for (ASTItem declarationItem : declaration.getChildren()) {
 
-                    if(isNode(declarationItem, "function")) {
-                        
-                        
+                    if (isNode(declarationItem, "function")) {
+
                         List<ASTItem> functionItems = declarationItem.getChildren();
-                        
-                        if(functionItems.size() < 3)
+
+                        if (functionItems.size() < 3) {
                             break;
-                        
+                        }
+
                         ASTItem nameToken = functionItems.get(0);
 
-                        if(isTokenType(nameToken, GlslTokenId.FUNCTION.name())) {
-                            
+                        if (isTokenType(nameToken, GlslTokenId.FUNCTION.name())) {
+
                             // determine return type
                             StringBuilder returnType = new StringBuilder();
                             for (ASTItem typeItem : declaration.getChildren()) {
 
-                                if(isNode(typeItem, "function"))
+                                if (isNode(typeItem, "function")) {
                                     break;
+                                }
 
-                                if(typeItem instanceof ASTNode) {
-                                    returnType.append(((ASTNode)typeItem).getAsText().trim());
-                                }else if(typeItem instanceof ASTToken) {
+                                if (typeItem instanceof ASTNode) {
+                                    returnType.append(((ASTNode) typeItem).getAsText().trim());
+                                } else if (typeItem instanceof ASTToken) {
                                     final ASTToken t = (ASTToken) typeItem;
                                     returnType.append(t.getIdentifier().trim());
                                 }
 
                             }
-                            
+
                             // determine name and parameter list
                             StringBuilder name = new StringBuilder();
-                            
+
                             name.append("(");
                             ASTItem parameterList = functionItems.get(2);
-                            if(isNode(parameterList, "parameter_declaration_list"))
-                                name.append(((ASTNode)parameterList).getAsText());
+                            if (isNode(parameterList, "parameter_declaration_list")) {
+                                name.append(((ASTNode) parameterList).getAsText());
+                            }
                             name.append(")");
 
                             GLSLElementDescriptor elementDesc = new GLSLElementDescriptor(
@@ -307,55 +321,53 @@ public final class Glsl {
                                     returnType.toString());
 
                             name.insert(0, ((ASTToken) nameToken).getIdentifier());
-                            
-                            synchronized(declaredFunctions) {
+
+                            synchronized (declaredFunctions) {
                                 declaredFunctions.put(name.toString(), elementDesc);
                             }
-                            
+
 //                            System.out.println("|"+returnType.toString()+"|"+name.toString()+"|");
                         }
-                        
+
                         break;
                     }
                 }
             }
-        }finally{
+        } finally {
             document.readUnlock();
         }
 
 
     }
-    
-    private static final void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) {
+
+    private static void movePreviousUntil(TokenSequence sequence, GlslTokenId id, String countToken, String stopToken) {
         int counter = 1;
-        while(sequence.movePrevious() && counter > 0) {
-            if(sequence.token().id() == id) {
-                if(TokenUtilities.equals(sequence.token().text(), stopToken)) {
+        while (sequence.movePrevious() && counter > 0) {
+            if (sequence.token().id() == id) {
+                if (TokenUtilities.equals(sequence.token().text(), stopToken)) {
                     counter--;
-                }else if(TokenUtilities.equals(sequence.token().text(), countToken)){
+                } else if (TokenUtilities.equals(sequence.token().text(), countToken)) {
                     counter++;
                 }
             }
         }
     }
-    
-    private static final boolean isIgnoredToken(Token token) {
-        return     token.id() == GlslTokenId.WHITESPACE
+
+    private static boolean isIgnoredToken(Token token) {
+        return token.id() == GlslTokenId.WHITESPACE
                 || token.id() == GlslTokenId.COMMENT
                 || token.id() == GlslTokenId.PREPROCESSOR;
     }
-    
-    private static final boolean isNode(ASTItem item, String nodeToken) {
-        return item != null && item instanceof ASTNode && ((ASTNode)item).getNT().equals(nodeToken);
+
+    private static boolean isNode(ASTItem item, String nodeToken) {
+        return item != null && item instanceof ASTNode && ((ASTNode) item).getNT().equals(nodeToken);
     }
 
-    private static final boolean isToken(ASTItem item, String id) {
-        return item != null && item instanceof ASTToken && ((ASTToken)item).getIdentifier().equals(id);
+    private static boolean isToken(ASTItem item, String id) {
+        return item != null && item instanceof ASTToken && ((ASTToken) item).getIdentifier().equals(id);
     }
 
-    private static final boolean isTokenType(ASTItem item, String type) {
+    private static boolean isTokenType(ASTItem item, String type) {
         return item != null && item instanceof ASTToken && ((ASTToken) item).getTypeName().equals(type);
     }
-
-
 }

+ 19 - 19
jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/Glsl.java

@@ -1,10 +1,9 @@
 /*
  * VertexLanguage.java
- * 
+ *
  * Created on 19.08.2007, 18:25:24
- * 
+ *
  */
-
 package net.java.nboglpack.glsleditor.lexer;
 
 import java.util.Collection;
@@ -23,17 +22,16 @@ import org.netbeans.spi.lexer.LexerRestartInfo;
  * @author Michael Bien
  */
 public class Glsl extends LanguageHierarchy<GlslTokenId> {
- 
- public static final Glsl VERTEX_LANGUAGE = new Glsl(GlslVertexShaderDataLoader.REQUIRED_MIME);
- public static final Glsl GEOMETRY_LANGUAGE = new Glsl(GlslGeometryShaderDataLoader.REQUIRED_MIME);
- public static final Glsl FRAGMENT_LANGUAGE = new Glsl(GlslFragmentShaderDataLoader.REQUIRED_MIME);
- 
- private final String mimeType;
- 
- private Glsl(String mimeType) {
-     this.mimeType = mimeType;
- }
- 
+
+    public static final Glsl VERTEX_LANGUAGE = new Glsl(GlslVertexShaderDataLoader.REQUIRED_MIME);
+    public static final Glsl GEOMETRY_LANGUAGE = new Glsl(GlslGeometryShaderDataLoader.REQUIRED_MIME);
+    public static final Glsl FRAGMENT_LANGUAGE = new Glsl(GlslFragmentShaderDataLoader.REQUIRED_MIME);
+    private final String mimeType;
+
+    private Glsl(String mimeType) {
+        this.mimeType = mimeType;
+    }
+
     @Override
     protected String mimeType() {
         return mimeType;
@@ -43,19 +41,21 @@ public class Glsl extends LanguageHierarchy<GlslTokenId> {
     protected Collection<GlslTokenId> createTokenIds() {
         return EnumSet.allOf(GlslTokenId.class);
     }
-    
+
     @Override
     protected Lexer<GlslTokenId> createLexer(LexerRestartInfo<GlslTokenId> info) {
         return new GlslLexer(info, GlslVocabularyManager.getInstance(mimeType()));
     }
-    
-    public static Language<GlslTokenId> vertexLanguage(){
+
+    public static Language<GlslTokenId> vertexLanguage() {
         return VERTEX_LANGUAGE.language();
     }
-    public static Language<GlslTokenId> fragmentLanguage(){
+
+    public static Language<GlslTokenId> fragmentLanguage() {
         return FRAGMENT_LANGUAGE.language();
     }
-    public static Language<GlslTokenId> geometryLanguage(){
+
+    public static Language<GlslTokenId> geometryLanguage() {
         return GEOMETRY_LANGUAGE.language();
     }
 }

+ 122 - 126
jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslLexer.java

@@ -1,10 +1,9 @@
 /*
  * GlslLexer.java
- * 
+ *
  * Created on 19.08.2007, 18:31:16
- * 
+ *
  */
-
 package net.java.nboglpack.glsleditor.lexer;
 
 import net.java.nboglpack.glsleditor.GlslVocabularyManager;
@@ -15,33 +14,29 @@ import org.netbeans.spi.lexer.LexerInput;
 import org.netbeans.spi.lexer.LexerRestartInfo;
 import org.netbeans.spi.lexer.TokenFactory;
 
-
 /**
  * Lexer for the OpenGL Shading Language.
  * @author Michael Bien
  */
 public class GlslLexer implements Lexer<GlslTokenId> {
- 
- private final LexerInput input;
- private final TokenFactory<GlslTokenId> factory;
- private final GlslVocabularyManager manager;
- private final StringBuilder stringBuilder;
- 
- 
- public GlslLexer(LexerRestartInfo<GlslTokenId> info, GlslVocabularyManager manager) {
-     this.input = info.input();
-     this.factory = info.tokenFactory();
-     this.manager = manager;
-     this.stringBuilder = new StringBuilder();
- }
+
+    private final LexerInput input;
+    private final TokenFactory<GlslTokenId> factory;
+    private final GlslVocabularyManager manager;
+    private final StringBuilder stringBuilder;
+
+    public GlslLexer(LexerRestartInfo<GlslTokenId> info, GlslVocabularyManager manager) {
+        this.input = info.input();
+        this.factory = info.tokenFactory();
+        this.manager = manager;
+        this.stringBuilder = new StringBuilder();
+    }
 
     @SuppressWarnings("fallthrough")
     public Token<GlslTokenId> nextToken() {
-        
+
         int character = input.read();
-        
-        switch(character) {
-            
+        switch (character) {
             case '(':
             case ')':
                 return factory.createToken(GlslTokenId.PAREN);
@@ -64,76 +59,76 @@ public class GlslLexer implements Lexer<GlslTokenId> {
             case '~':
                 return factory.createToken(GlslTokenId.TILDE);
             case '*':
-                if(input.read() == '=') {
+                if (input.read() == '=') {
                     return factory.createToken(GlslTokenId.MUL_ASSIGN);
-                }else{
+                } else {
                     input.backup(1);
                     return factory.createToken(GlslTokenId.STAR);
                 }
             case '%':
-                if(input.read() == '=') {
+                if (input.read() == '=') {
                     return factory.createToken(GlslTokenId.MOD_ASSIGN);
-                }else{
+                } else {
                     input.backup(1);
                     return factory.createToken(GlslTokenId.PERCENT);
                 }
             case '!':
-                if(input.read() == '=') {
+                if (input.read() == '=') {
                     return factory.createToken(GlslTokenId.NE);
-                }else{
+                } else {
                     input.backup(1);
                     return factory.createToken(GlslTokenId.BANG);
                 }
             case '=':
-                if(input.read() == '=') {
+                if (input.read() == '=') {
                     return factory.createToken(GlslTokenId.EQEQ);
-                }else{
+                } else {
                     input.backup(1);
                     return factory.createToken(GlslTokenId.EQ);
                 }
             case '^':
-                switch(input.read()) {
-                    case('^'):
+                switch (input.read()) {
+                    case ('^'):
                         return factory.createToken(GlslTokenId.CARETCARET);
-                    case('='):
+                    case ('='):
                         return factory.createToken(GlslTokenId.XOR_ASSIGN);
                     default:
                         input.backup(1);
                         return factory.createToken(GlslTokenId.CARET);
                 }
             case '+':
-                switch(input.read()) {
-                    case('+'):
+                switch (input.read()) {
+                    case ('+'):
                         return factory.createToken(GlslTokenId.PLUSPLUS);
-                    case('='):
+                    case ('='):
                         return factory.createToken(GlslTokenId.ADD_ASSIGN);
                     default:
                         input.backup(1);
                         return factory.createToken(GlslTokenId.PLUS);
                 }
             case '-':
-                switch(input.read()) {
-                    case('-'):
+                switch (input.read()) {
+                    case ('-'):
                         return factory.createToken(GlslTokenId.MINUSMINUS);
-                    case('='):
+                    case ('='):
                         return factory.createToken(GlslTokenId.SUB_ASSIGN);
                     default:
                         input.backup(1);
                         return factory.createToken(GlslTokenId.MINUS);
                 }
             case '&':
-                switch(input.read()) {
-                    case('&'):
+                switch (input.read()) {
+                    case ('&'):
                         return factory.createToken(GlslTokenId.AMPAMP);
-                    case('='):
+                    case ('='):
                         return factory.createToken(GlslTokenId.AND_ASSIGN);
                     default:
                         input.backup(1);
                         return factory.createToken(GlslTokenId.AMP);
                 }
             case '|':
-                switch(input.read()) {
-                    case('|'):
+                switch (input.read()) {
+                    case ('|'):
                         return factory.createToken(GlslTokenId.BARBAR);
                     case ('='):
                         return factory.createToken(GlslTokenId.OR_ASSIGN);
@@ -142,30 +137,30 @@ public class GlslLexer implements Lexer<GlslTokenId> {
                         return factory.createToken(GlslTokenId.BAR);
                 }
             case '<':
-                switch(input.read()) {
-                    case('<'):
-                        if(input.read() == '=') {
+                switch (input.read()) {
+                    case ('<'):
+                        if (input.read() == '=') {
                             return factory.createToken(GlslTokenId.LEFT_BITSHIFT_ASSIGN);
-                        }else{
+                        } else {
                             input.backup(1);
                             return factory.createToken(GlslTokenId.LEFT_BITSHIFT);
                         }
-                    case('='):
+                    case ('='):
                         return factory.createToken(GlslTokenId.LE);
                     default:
                         input.backup(1);
                         return factory.createToken(GlslTokenId.LEFT_ANGLE);
                 }
             case '>':
-                switch(input.read()) {
-                    case('>'):
-                        if(input.read() == '=') {
+                switch (input.read()) {
+                    case ('>'):
+                        if (input.read() == '=') {
                             return factory.createToken(GlslTokenId.RIGHT_BITSHIFT_ASSIGN);
-                        }else{
+                        } else {
                             input.backup(1);
                             return factory.createToken(GlslTokenId.RIGHT_BITSHIFT);
                         }
-                    case('='):
+                    case ('='):
                         return factory.createToken(GlslTokenId.GE);
                     default:
                         input.backup(1);
@@ -173,14 +168,14 @@ public class GlslLexer implements Lexer<GlslTokenId> {
                 }
             case '/':
                 int c = input.read();
-                if(c == '/') {
+                if (c == '/') {
                     readRemainingLine();
                     return factory.createToken(GlslTokenId.COMMENT);
-                }else if(c == '*') {
+                } else if (c == '*') {
                     return tokenizeMLComment();
-                }else if(c == '=') {
+                } else if (c == '=') {
                     return factory.createToken(GlslTokenId.DIV_ASSIGN);
-                }else{
+                } else {
                     input.backup(1);
                     return factory.createToken(GlslTokenId.SLASH);
                 }
@@ -189,36 +184,37 @@ public class GlslLexer implements Lexer<GlslTokenId> {
                 return factory.createToken(GlslTokenId.PREPROCESSOR);
             case ' ':
             case '\t':
-                do{
+                do {
                     character = input.read();
-                }while(character == ' ' || character == '\t');
-                input.backup(1);                
+                } while (character == ' ' || character == '\t');
+                input.backup(1);
                 return factory.createToken(GlslTokenId.WHITESPACE);
             case '\r':
                 input.consumeNewline();
             case LexerInput.EOF:
-                if(input.readLength() == 0)
+                if (input.readLength() == 0) {
                     return null;
+                }
             case '\n':
                 return factory.createToken(GlslTokenId.END_OF_LINE);
             default:
-                if(Character.isDigit(character)) {
+                if (Character.isDigit(character)) {
                     return tokenizeNumber();
-                }else if(Character.isUnicodeIdentifierStart(character)) {
+                } else if (Character.isUnicodeIdentifierStart(character)) {
                     return tokenizeName();
-                }else{
+                } else {
                     return factory.createToken(GlslTokenId.error);
                 }
         }
-      
+
     }
-    
+
     @SuppressWarnings("fallthrough")
-    private final void readRemainingLine() {
-        
+    private void readRemainingLine() {
+
         int character = input.read();
-        
-        while(character != LexerInput.EOF) {
+
+        while (character != LexerInput.EOF) {
             switch (character) {
                 case '\r':
                     input.consumeNewline();
@@ -228,92 +224,93 @@ public class GlslLexer implements Lexer<GlslTokenId> {
             }
             character = input.read();
         }
-        
+
     }
-    
-    private final Token<GlslTokenId> tokenizeMLComment() {
-        
+
+    private Token<GlslTokenId> tokenizeMLComment() {
+
         int character = input.read();
-        
-        while(character != LexerInput.EOF) {
-            if(character == '*' && input.read() == '/') {
+
+        while (character != LexerInput.EOF) {
+            if (character == '*' && input.read() == '/') {
                 return factory.createToken(GlslTokenId.ML_COMMENT);
             }
             character = input.read();
         }
         return factory.createToken(GlslTokenId.ML_COMMENT);
-        
+
     }
-    
-    private final Token<GlslTokenId> tokenizeNumber() {
-        
+
+    private Token<GlslTokenId> tokenizeNumber() {
+
         int character;
-        
-        do{
+
+        do {
             character = input.read();
-        }while(Character.isDigit(character));
-        
-        if(character == '.') {
-            
-            do{
+        } while (Character.isDigit(character));
+
+        if (character == '.') {
+
+            do {
                 character = input.read();
-            }while(Character.isDigit(character));
-            
-            if(character != 'f' && character != 'F')
+            } while (Character.isDigit(character));
+
+            if (character != 'f' && character != 'F') {
                 input.backup(1);
-            
+            }
+
             return factory.createToken(GlslTokenId.FLOAT_LITERAL);
-            
-        }else{
 
-            if(character != 'u' && character != 'U')
+        } else {
+
+            if (character != 'u' && character != 'U') {
                 input.backup(1);
-            
-//            input.backup(1);
+            }
+
             return factory.createToken(GlslTokenId.INTEGER_LITERAL);
-            
+
         }
     }
-    
-    private final Token<GlslTokenId> tokenizeName() {
-        
-        if(stringBuilder.length() > 0)
+
+    private Token<GlslTokenId> tokenizeName() {
+
+        if (stringBuilder.length() > 0) {
             stringBuilder.delete(0, stringBuilder.length());
-        
+        }
+
         // backup everything read
-        input.backup(input.readLength()); 
-        
+        input.backup(input.readLength());
+
         // assamble token
         char c;
-        while(Character.isUnicodeIdentifierPart(c = ((char)input.read())))        
+        while (Character.isUnicodeIdentifierPart(c = ((char) input.read()))) {
             stringBuilder.append(c);
-        
-        if(stringBuilder.length() > 0)
+        }
+
+        if (stringBuilder.length() > 0) {
             input.backup(1);
-                
+        }
+
         // categorise token
         GLSLElementDescriptor[] desc = manager.getDesc(stringBuilder.toString());
-        
-        if(desc != null) {
-            
-            if(desc[0].category != null) {
-                
-                if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC) 
-                    return factory.createToken(GlslTokenId.BUILD_IN_FUNC);
 
-                if(desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR) 
+        if (desc != null) {
+            if (desc[0].category != null) {
+                if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_FUNC) {
+                    return factory.createToken(GlslTokenId.BUILD_IN_FUNC);
+                }
+                if (desc[0].category == GLSLElementDescriptor.Category.BUILD_IN_VAR) {
                     return factory.createToken(GlslTokenId.BUILD_IN_VAR);
-            
+                }
                 return factory.createToken(GlslTokenId.KEYWORD);
-                
             }
         }
-        
+
         // check if token = function name
         int tokenEnd = input.readLength();
         int character = input.read();
-        
-        while(true) {
+
+        while (true) {
             switch (character) {
                 case ' ':
                 case '\t':
@@ -322,14 +319,14 @@ public class GlslLexer implements Lexer<GlslTokenId> {
                     character = input.read();
                     break;
                 case '(':
-                    input.backup(input.readLength()-tokenEnd);
+                    input.backup(input.readLength() - tokenEnd);
                     return factory.createToken(GlslTokenId.FUNCTION);
                 default:
-                    input.backup(input.readLength()-tokenEnd);
+                    input.backup(input.readLength() - tokenEnd);
                     return factory.createToken(GlslTokenId.IDENTIFIER);
             }
         }
-        
+
     }
 
     public Object state() {
@@ -339,5 +336,4 @@ public class GlslLexer implements Lexer<GlslTokenId> {
 
     public void release() {
     }
-
 }

+ 68 - 69
jme3-glsl-support/src/net/java/nboglpack/glsleditor/lexer/GlslTokenId.java

@@ -1,8 +1,8 @@
 /*
  * GlslTokenId.java
- * 
+ *
  * Created on 19.08.2007, 18:09:00
- * 
+ *
  */
 
 package net.java.nboglpack.glsleditor.lexer;
@@ -14,77 +14,76 @@ import org.netbeans.api.lexer.TokenId;
  * @author Michael Bien
  */
 public enum GlslTokenId implements TokenId {
-    
 
- IDENTIFIER("glsl-name"),
- INTEGER_LITERAL("glsl-literal"),
- FLOAT_LITERAL("glsl-literal"),
- FUNCTION("glsl-function"),
- KEYWORD("glsl-keyword"),
- BUILD_IN_FUNC("glsl-build-in-func"),
- BUILD_IN_VAR("glsl-build-in-var"),
- COMMENT("glsl-comment"),
- ML_COMMENT("glsl-comment"),
- 
- PAREN("glsl-paren"),
- BRACE("glsl-brace"),
- BRACKET("glsl-bracket"),
- LEFT_ANGLE("glsl-angle"),
- RIGHT_ANGLE("glsl-angle"),
- 
- SEMICOLON("glsl-separator"),
- COMMA("glsl-separator"),
- DOT("glsl-separator"),
- COLON("glsl-separator"),
- 
- PERCENT("glsl-operation"),
- STAR("glsl-operation"),
- TILDE("glsl-operation"),
- QUESTION("glsl-operation"),
- BANG("glsl-operation"),
- SLASH("glsl-operation"),
- LEFT_BITSHIFT("glsl-operation"),
- RIGHT_BITSHIFT("glsl-operation"),
- PLUS("glsl-operation"),
- PLUSPLUS("glsl-operation"),
- MINUS("glsl-operation"),
- MINUSMINUS("glsl-operation"),
- AMP("glsl-operation"),
- AMPAMP("glsl-operation"),
- EQ("glsl-operation"),
- EQEQ("glsl-operation"),
- NE("glsl-operation"),
- LE("glsl-operation"),
- GE("glsl-operation"),
- BAR("glsl-operation"),
- BARBAR("glsl-operation"),
- CARET("glsl-operation"),
- CARETCARET("glsl-operation"),
- ADD_ASSIGN("glsl-operation"),
- SUB_ASSIGN("glsl-operation"),
- MUL_ASSIGN("glsl-operation"),
- DIV_ASSIGN("glsl-operation"),
- AND_ASSIGN("glsl-operation"),
- OR_ASSIGN("glsl-operation"),
- XOR_ASSIGN("glsl-operation"),
- MOD_ASSIGN("glsl-operation"),
- LEFT_BITSHIFT_ASSIGN("glsl-operation"),
- RIGHT_BITSHIFT_ASSIGN("glsl-operation"),
- 
- WHITESPACE("glsl-whitespace"),
- END_OF_LINE("glsl-end-of-line"),
- PREPROCESSOR("glsl-preprocessor"),
+    IDENTIFIER("glsl-name"),
+    INTEGER_LITERAL("glsl-literal"),
+    FLOAT_LITERAL("glsl-literal"),
+    FUNCTION("glsl-function"),
+    KEYWORD("glsl-keyword"),
+    BUILD_IN_FUNC("glsl-build-in-func"),
+    BUILD_IN_VAR("glsl-build-in-var"),
+    COMMENT("glsl-comment"),
+    ML_COMMENT("glsl-comment"),
 
- error("glsl-error");
- 
- private final String primaryCategory;
-   
- private GlslTokenId(String primaryCategory) {
-    this.primaryCategory = primaryCategory;
- }
+    PAREN("glsl-paren"),
+    BRACE("glsl-brace"),
+    BRACKET("glsl-bracket"),
+    LEFT_ANGLE("glsl-angle"),
+    RIGHT_ANGLE("glsl-angle"),
+
+    SEMICOLON("glsl-separator"),
+    COMMA("glsl-separator"),
+    DOT("glsl-separator"),
+    COLON("glsl-separator"),
+
+    PERCENT("glsl-operation"),
+    STAR("glsl-operation"),
+    TILDE("glsl-operation"),
+    QUESTION("glsl-operation"),
+    BANG("glsl-operation"),
+    SLASH("glsl-operation"),
+    LEFT_BITSHIFT("glsl-operation"),
+    RIGHT_BITSHIFT("glsl-operation"),
+    PLUS("glsl-operation"),
+    PLUSPLUS("glsl-operation"),
+    MINUS("glsl-operation"),
+    MINUSMINUS("glsl-operation"),
+    AMP("glsl-operation"),
+    AMPAMP("glsl-operation"),
+    EQ("glsl-operation"),
+    EQEQ("glsl-operation"),
+    NE("glsl-operation"),
+    LE("glsl-operation"),
+    GE("glsl-operation"),
+    BAR("glsl-operation"),
+    BARBAR("glsl-operation"),
+    CARET("glsl-operation"),
+    CARETCARET("glsl-operation"),
+    ADD_ASSIGN("glsl-operation"),
+    SUB_ASSIGN("glsl-operation"),
+    MUL_ASSIGN("glsl-operation"),
+    DIV_ASSIGN("glsl-operation"),
+    AND_ASSIGN("glsl-operation"),
+    OR_ASSIGN("glsl-operation"),
+    XOR_ASSIGN("glsl-operation"),
+    MOD_ASSIGN("glsl-operation"),
+    LEFT_BITSHIFT_ASSIGN("glsl-operation"),
+    RIGHT_BITSHIFT_ASSIGN("glsl-operation"),
+
+    WHITESPACE("glsl-whitespace"),
+    END_OF_LINE("glsl-end-of-line"),
+    PREPROCESSOR("glsl-preprocessor"),
+
+    error("glsl-error");
+
+    private final String primaryCategory;
+
+    private GlslTokenId(String primaryCategory) {
+        this.primaryCategory = primaryCategory;
+    }
 
     public String primaryCategory() {
         return primaryCategory;
     }
-  
+
 }

+ 36 - 34
jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLElementDescriptor.java

@@ -1,8 +1,8 @@
 /*
  * GLSLElementDescriptor.java
- * 
+ *
  * Created on 03.06.2007, 23:03:57
- * 
+ *
  */
 package net.java.nboglpack.glsleditor.vocabulary;
 
@@ -15,42 +15,44 @@ import javax.xml.bind.annotation.XmlType;
  * @author Michael Bien
  */
 public class GLSLElementDescriptor {
- 
- @XmlType
- @XmlEnum(String.class)
- public enum Category { BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD  }
- 
-  @XmlElement
-  public final Category category;
-  
-  @XmlElement(required = true)
-  public final String tooltip;
-  
-  @XmlElement(required = true)
-  public final String doc;
-  
-  @XmlElement(required = true)
-  public final String arguments;
-  
-  @XmlElement(required = true)
-  public final String type;
-
-    /*bean constructor, fields are directly injected*/
+
+    @XmlType
+    @XmlEnum(String.class)
+    public enum Category {
+        BUILD_IN_FUNC, BUILD_IN_VAR, USER_FUNC, JUMP, ITERATION, SELECTION, QUALIFIER, TYPE, KEYWORD
+    }
+
+    @XmlElement
+    public final Category category;
+
+    @XmlElement(required = true)
+    public final String tooltip;
+
+    @XmlElement(required = true)
+    public final String doc;
+
+    @XmlElement(required = true)
+    public final String arguments;
+
+    @XmlElement(required = true)
+    public final String type;
+
+    /**
+     * Bean constructor, fields are directly injected.
+     */
     public GLSLElementDescriptor() {
-        category    = Category.KEYWORD;
-        tooltip     = null;
-        doc         = null;
-        arguments   = null;
-        type        = null;
+        category = Category.KEYWORD;
+        tooltip = null;
+        doc = null;
+        arguments = null;
+        type = null;
     }
 
     public GLSLElementDescriptor(Category category, String tooltip, String doc, String arguments, String type) {
-        this.category  = category;
-        this.tooltip   = tooltip;
-        this.doc       = doc;
+        this.category = category;
+        this.tooltip = tooltip;
+        this.doc = doc;
         this.arguments = arguments;
-        this.type      = type;
+        this.type = type;
     }
-
-
 }

+ 9 - 12
jme3-glsl-support/src/net/java/nboglpack/glsleditor/vocabulary/GLSLVocabulary.java

@@ -1,8 +1,8 @@
 /*
  * GLSLVocabulary.java
- * 
+ *
  * Created on 03.06.2007, 23:03:57
- * 
+ *
  */
 package net.java.nboglpack.glsleditor.vocabulary;
 
@@ -16,18 +16,15 @@ import javax.xml.bind.annotation.XmlRootElement;
 @XmlRootElement
 public class GLSLVocabulary {
 
- public final HashMap<String, GLSLElementDescriptor[]> mainVocabulary;
- public final HashMap<String, GLSLElementDescriptor[]> fragmentShaderVocabulary;
- public final HashMap<String, GLSLElementDescriptor[]> vertexShaderVocabulary;
- public final HashMap<String, GLSLElementDescriptor[]> geometryShaderVocabulary;
- 
-    
+    public final HashMap<String, GLSLElementDescriptor[]> mainVocabulary;
+    public final HashMap<String, GLSLElementDescriptor[]> fragmentShaderVocabulary;
+    public final HashMap<String, GLSLElementDescriptor[]> vertexShaderVocabulary;
+    public final HashMap<String, GLSLElementDescriptor[]> geometryShaderVocabulary;
+
     public GLSLVocabulary() {
-        mainVocabulary           = new HashMap<String, GLSLElementDescriptor[]>();
-        vertexShaderVocabulary   = new HashMap<String, GLSLElementDescriptor[]>();
+        mainVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
+        vertexShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
         fragmentShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
         geometryShaderVocabulary = new HashMap<String, GLSLElementDescriptor[]>();
     }
- 
- 
 }