Browse Source

Merge branch 'master' into Issue#597

# Conflicts:
#	jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java
rickard 1 year ago
parent
commit
3e3733de6e

+ 26 - 16
jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java

@@ -59,7 +59,13 @@ public class EditableMaterialFile {
     private final List<String> matDefEntries = new ArrayList<>();
     private final ProjectAssetManager manager;
     private FileSystem fs;
-    public static final String[] variableTypes = new String[]{"Int", "Boolean", "Float", "Vector2", "Vector3", "Vector4", "Color", "Texture2D", "Texture3D", "TextureArray", "TextureBuffer", "TextureCubeMap"};
+    
+    // Note that these are tested with startsWith, so the ordering matters (i.e. FloatArray & Float)
+    public static final String[] variableTypes = new String[]{
+        "IntArray", "Int", "Boolean", "FloatArray", "Float", "Vector2Array",
+        "Vector3Array", "Vector4Array", "Vector2", "Vector3", "Vector4",
+        "Color", "Texture2D", "Texture3D", "TextureArray", "TextureBuffer",
+        "TextureCubeMap"};
 
     public EditableMaterialFile(FileObject material, ProjectAssetManager manager) {
         this.material = material;
@@ -188,24 +194,26 @@ public class EditableMaterialFile {
         matDef = manager.getAssetFolder().getFileObject(getMatDefName());
 
         //try to read from classpath if not in assets folder and store in a virtual filesystem folder
-        if (matDef == null || !matDef.isValid()) {
-            try {
-                fs = FileUtil.createMemoryFileSystem();
-                matDef = fs.getRoot().createData(name, "j3md");
-                try ( OutputStream out = matDef.getOutputStream()) {
-                    InputStream in = manager.getResourceAsStream(getMatDefName());
-                    if (in != null) {
-                        int input = in.read();
-                        while (input != -1) {
-                            out.write(input);
-                            input = in.read();
-                        }
-                        in.close();
+        if (matDef != null && matDef.isValid()) {
+            return;
+        }
+        
+        try {
+            fs = FileUtil.createMemoryFileSystem();
+            matDef = fs.getRoot().createData(name, "j3md");
+            try ( OutputStream out = matDef.getOutputStream()) {
+                InputStream in = manager.getResourceAsStream(getMatDefName());
+                if (in != null) {
+                    int input = in.read();
+                    while (input != -1) {
+                        out.write(input);
+                        input = in.read();
                     }
+                    in.close();
                 }
-            } catch (IOException ex) {
-                Exceptions.printStackTrace(ex);
             }
+        } catch (IOException ex) {
+            Exceptions.printStackTrace(ex);
         }
     }
 
@@ -255,6 +263,8 @@ public class EditableMaterialFile {
                                     materialParameters.put(prop.getName(), prop);
                                 }
                                 prop.setType(string);
+                                
+                                break;
                             }
                         }
                     }

+ 0 - 3
jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.form

@@ -354,9 +354,6 @@
                           <ResourceString bundle="com/jme3/gde/materials/multiview/Bundle.properties" key="MaterialEditorTopComponent.jTextField1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
                         </Property>
                       </Properties>
-                      <Events>
-                        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField1ActionPerformed"/>
-                      </Events>
                     </Component>
                   </SubComponents>
                 </Container>

+ 26 - 13
jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java

@@ -121,6 +121,32 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
         materialPreviewWidget1.showMaterial(manager, materialFileName);
 
         relativeMaterialFileName = manager.getRelativeAssetPath(materialFileName);
+        
+        jTextField1.getDocument().addDocumentListener(new DocumentListener() {
+            @Override
+            public void insertUpdate(DocumentEvent e) {
+                updateName();
+            }
+
+            @Override
+            public void removeUpdate(DocumentEvent e) {
+                updateName();
+            }
+
+            @Override
+            public void changedUpdate(DocumentEvent e) {
+                updateName();
+            }
+
+            private void updateName() {
+                if (materialFile != null) {
+                    materialFile.setName(jTextField1.getText());
+                    String string = materialFile.getUpdatedContent();
+                    jTextArea1.setText(string);
+                }
+            }
+
+        });
     }
 
     /** This method is called from within the constructor to
@@ -260,11 +286,6 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
         jToolBar3.add(jPanel1);
 
         jTextField1.setText(org.openide.util.NbBundle.getMessage(MaterialEditorTopComponent.class, "MaterialEditorTopComponent.jTextField1.text")); // NOI18N
-        jTextField1.addActionListener(new java.awt.event.ActionListener() {
-            public void actionPerformed(java.awt.event.ActionEvent evt) {
-                jTextField1ActionPerformed(evt);
-            }
-        });
         jToolBar3.add(jTextField1);
 
         jCheckBox1.setSelected(true);
@@ -354,14 +375,6 @@ public final class MaterialEditorTopComponent extends CloneableTopComponent impl
         saveImmediate = jCheckBox1.isSelected();
     }//GEN-LAST:event_jCheckBox1ActionPerformed
 
-    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
-        if (materialFile != null) {
-            materialFile.setName(jTextField1.getText());
-            String string = materialFile.getUpdatedContent();
-            jTextArea1.setText(string);
-        }
-    }//GEN-LAST:event_jTextField1ActionPerformed
-
     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
         if (materialFile != null) {
             updateProperties = true;