diff --git a/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java b/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java index c8309af9..c9faeb04 100644 --- a/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java +++ b/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java @@ -59,7 +59,13 @@ public class EditableMaterialFile { private final List 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 @@ private void initMatDef() { 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 @@ private void checkWithMatDef() { materialParameters.put(prop.getName(), prop); } prop.setType(string); + + break; } } } diff --git a/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.form b/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.form index 351bfb28..a1f106c5 100644 --- a/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.form +++ b/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.form @@ -354,9 +354,6 @@ - - - diff --git a/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java b/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java index 9c9cf38f..c448aa80 100644 --- a/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java +++ b/jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java @@ -127,6 +127,32 @@ public void componentHidden(ComponentEvent e) { 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 @@ -266,11 +292,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { 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); @@ -360,14 +381,6 @@ private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI 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; @@ -587,19 +600,10 @@ public void setMatDefList(final String[] matDefs, String selected) { jComboBox1.addItem(""); List matDefList = Arrays.asList(matDefs); Collections.sort(matDefList); - String[] sortedMatDefs = matDefList.toArray(String[]::new); - for (String string : sortedMatDefs) { - jComboBox1.addItem(string); + for (String matDef : matDefList) { + jComboBox1.addItem(matDef); } -// jComboBox1.addItem("Common/MatDefs/Light/Lighting.j3md"); -// jComboBox1.addItem("Common/MatDefs/Misc/Unshaded.j3md"); -// jComboBox1.addItem("Common/MatDefs/Misc/Particle.j3md"); -// jComboBox1.addItem("Common/MatDefs/Misc/Sky.j3md"); -// jComboBox1.addItem("Common/MatDefs/Gui/Gui.j3md"); -// jComboBox1.addItem("Common/MatDefs/Terrain/TerrainLighting.j3md"); -// jComboBox1.addItem("Common/MatDefs/Terrain/Terrain.j3md"); -// jComboBox1.addItem("Common/MatDefs/Misc/ShowNormals.j3md"); jComboBox1.setSelectedItem(selected); materialFile = prop; }