Browse Source

Towards #181 - Add a base panel which will be used by all New Geometry Dialogs

MeFisto94 6 years ago
parent
commit
4dee6a4fe6

+ 131 - 0
jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AbstractNewGeometryPanel.form

@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
+  <AuxValues>
+    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+  </AuxValues>
+
+  <Layout>
+    <DimensionLayout dim="0">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Group type="102" attributes="0">
+              <EmptySpace max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="0" attributes="0">
+                  <Group type="102" attributes="0">
+                      <Group type="103" groupAlignment="0" attributes="0">
+                          <Component id="lblGeomName" alignment="0" min="-2" max="-2" attributes="0"/>
+                          <Component id="lblMatDef" alignment="0" min="-2" max="-2" attributes="0"/>
+                      </Group>
+                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
+                      <Group type="103" groupAlignment="0" attributes="0">
+                          <Group type="102" attributes="0">
+                              <Component id="inMatDef" min="-2" max="-2" attributes="0"/>
+                              <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
+                          </Group>
+                          <Component id="inGeomName" max="32767" attributes="0"/>
+                      </Group>
+                  </Group>
+                  <Group type="102" attributes="0">
+                      <Group type="103" groupAlignment="0" attributes="0">
+                          <Component id="lblDefaultColor" min="-2" max="-2" attributes="0"/>
+                          <Component id="inRandomColor" alignment="0" min="-2" max="-2" attributes="0"/>
+                      </Group>
+                      <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
+                  </Group>
+              </Group>
+              <EmptySpace max="-2" attributes="0"/>
+          </Group>
+      </Group>
+    </DimensionLayout>
+    <DimensionLayout dim="1">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <Group type="102" alignment="0" attributes="0">
+              <EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="3" attributes="0">
+                  <Component id="lblGeomName" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="inGeomName" alignment="3" min="-2" max="-2" attributes="0"/>
+              </Group>
+              <EmptySpace type="unrelated" max="-2" attributes="0"/>
+              <Group type="103" groupAlignment="3" attributes="0">
+                  <Component id="lblMatDef" alignment="3" min="-2" max="-2" attributes="0"/>
+                  <Component id="inMatDef" alignment="3" min="-2" max="-2" attributes="0"/>
+              </Group>
+              <EmptySpace type="unrelated" max="-2" attributes="0"/>
+              <Component id="lblDefaultColor" min="-2" max="-2" attributes="0"/>
+              <EmptySpace pref="18" max="32767" attributes="0"/>
+              <Component id="inRandomColor" min="-2" max="-2" attributes="0"/>
+              <EmptySpace max="-2" attributes="0"/>
+          </Group>
+      </Group>
+    </DimensionLayout>
+  </Layout>
+  <SubComponents>
+    <Component class="javax.swing.JTextField" name="inGeomName">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties" key="AbstractNewGeometryPanel.inGeomName.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JLabel" name="lblGeomName">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties" key="AbstractNewGeometryPanel.lblGeomName.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+      <AuxValues>
+        <AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="AbstractNewGeometryPanel_lblMeshName"/>
+      </AuxValues>
+    </Component>
+    <Component class="javax.swing.JLabel" name="lblMatDef">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties" key="AbstractNewGeometryPanel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+        <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties" key="AbstractNewGeometryPanel.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+        <Property name="name" type="java.lang.String" value="" noResource="true"/>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JComboBox" name="inMatDef">
+      <Properties>
+        <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
+          <StringArray count="3">
+            <StringItem index="0" value="Common/MatDefs/Misc/Unshaded.j3md"/>
+            <StringItem index="1" value="Common/MatDefs/Light/Lighting.j3md"/>
+            <StringItem index="2" value="Common/MatDefs/Light/PBRLighting.j3md"/>
+          </StringArray>
+        </Property>
+      </Properties>
+      <AuxValues>
+        <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
+      </AuxValues>
+    </Component>
+    <Component class="javax.swing.JLabel" name="lblDefaultColor">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties" key="AbstractNewGeometryPanel.lblDefaultColor.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+    <Component class="javax.swing.JCheckBox" name="inRandomColor">
+      <Properties>
+        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties" key="AbstractNewGeometryPanel.inRandomColor.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+        <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+          <ResourceString bundle="com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties" key="AbstractNewGeometryPanel.inRandomColor.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+        </Property>
+      </Properties>
+    </Component>
+  </SubComponents>
+</Form>

+ 164 - 0
jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/AbstractNewGeometryPanel.java

@@ -0,0 +1,164 @@
+/*
+ *  Copyright (c) 2019- jMonkeyEngine
+ *  All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ * 
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.gde.core.sceneexplorer.nodes.actions.impl;
+
+import com.jme3.gde.core.assets.ProjectAssetManager;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.scene.Geometry;
+
+/**
+ * This is the base Panel to be used within every "New Geometry/Primitive" dialogue
+ * as it will provide basic elements like MeshName, Material Color, etc.
+ * 
+ * @author MeFisto94
+ */
+public class AbstractNewGeometryPanel extends javax.swing.JPanel {
+
+    /**
+     * Creates new form AbstractNewGeometryPanel
+     */
+    public AbstractNewGeometryPanel() {
+        initComponents();
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    @SuppressWarnings("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        inGeomName = new javax.swing.JTextField();
+        lblGeomName = new javax.swing.JLabel();
+        lblMatDef = new javax.swing.JLabel();
+        inMatDef = new javax.swing.JComboBox<>();
+        lblDefaultColor = new javax.swing.JLabel();
+        inRandomColor = new javax.swing.JCheckBox();
+
+        inGeomName.setText(org.openide.util.NbBundle.getMessage(AbstractNewGeometryPanel.class, "AbstractNewGeometryPanel.inGeomName.text")); // NOI18N
+
+        org.openide.awt.Mnemonics.setLocalizedText(lblGeomName, org.openide.util.NbBundle.getMessage(AbstractNewGeometryPanel.class, "AbstractNewGeometryPanel.lblGeomName.text")); // NOI18N
+
+        org.openide.awt.Mnemonics.setLocalizedText(lblMatDef, org.openide.util.NbBundle.getMessage(AbstractNewGeometryPanel.class, "AbstractNewGeometryPanel.text")); // NOI18N
+        lblMatDef.setToolTipText(org.openide.util.NbBundle.getMessage(AbstractNewGeometryPanel.class, "AbstractNewGeometryPanel.toolTipText")); // NOI18N
+        lblMatDef.setName(""); // NOI18N
+
+        inMatDef.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Common/MatDefs/Misc/Unshaded.j3md", "Common/MatDefs/Light/Lighting.j3md", "Common/MatDefs/Light/PBRLighting.j3md" }));
+
+        org.openide.awt.Mnemonics.setLocalizedText(lblDefaultColor, org.openide.util.NbBundle.getMessage(AbstractNewGeometryPanel.class, "AbstractNewGeometryPanel.lblDefaultColor.text")); // NOI18N
+
+        org.openide.awt.Mnemonics.setLocalizedText(inRandomColor, org.openide.util.NbBundle.getMessage(AbstractNewGeometryPanel.class, "AbstractNewGeometryPanel.inRandomColor.text")); // NOI18N
+        inRandomColor.setToolTipText(org.openide.util.NbBundle.getMessage(AbstractNewGeometryPanel.class, "AbstractNewGeometryPanel.inRandomColor.toolTipText")); // NOI18N
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+        this.setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                    .addGroup(layout.createSequentialGroup()
+                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                            .addComponent(lblGeomName)
+                            .addComponent(lblMatDef))
+                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                            .addGroup(layout.createSequentialGroup()
+                                .addComponent(inMatDef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+                                .addGap(0, 0, Short.MAX_VALUE))
+                            .addComponent(inGeomName)))
+                    .addGroup(layout.createSequentialGroup()
+                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                            .addComponent(lblDefaultColor)
+                            .addComponent(inRandomColor))
+                        .addGap(0, 0, Short.MAX_VALUE)))
+                .addContainerGap())
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addGap(8, 8, 8)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(lblGeomName)
+                    .addComponent(inGeomName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+                    .addComponent(lblMatDef)
+                    .addComponent(inMatDef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                .addComponent(lblDefaultColor)
+                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
+                .addComponent(inRandomColor)
+                .addContainerGap())
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JTextField inGeomName;
+    private javax.swing.JComboBox<String> inMatDef;
+    private javax.swing.JCheckBox inRandomColor;
+    private javax.swing.JLabel lblDefaultColor;
+    private javax.swing.JLabel lblGeomName;
+    private javax.swing.JLabel lblMatDef;
+    // End of variables declaration//GEN-END:variables
+
+
+    public void handleGeometry(ProjectAssetManager assetManager, Geometry geom) {
+        geom.setName(inGeomName.getText());
+        ColorRGBA col;
+        
+        if (inRandomColor.isSelected()) {
+            col = ColorRGBA.randomColor();
+        } else {
+            // @TODO: Add a Color Picker Dialog and preserve the state
+            col = ColorRGBA.Red;
+        }
+        
+        Material mat = new Material(assetManager, inMatDef.getSelectedItem().toString());
+        switch (inMatDef.getSelectedItem().toString()) {
+            case "Common/MatDefs/Misc/Unshaded.j3md":
+                mat.setColor("Color", col);
+                break;
+            case "Common/MatDefs/Light/Lighting.j3md":
+                mat.setColor("Diffuse", col);
+                break;
+            case "Common/MatDefs/Light/PBRLighting.j3md":
+                mat.setColor("BaseColor", col);
+                break;
+        }
+        geom.setMaterial(mat);
+    }
+}

+ 7 - 0
jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/impl/Bundle.properties

@@ -58,3 +58,10 @@ NewGeometrySettingsTopComponent.quadFlipCoordCheckBox.text=
 NewGeometrySettingsTopComponent.linePanel.TabConstraints.tabTitle=Line
 NewGeometrySettingsTopComponent.lineStartLabel.text=start
 NewGeometrySettingsTopComponent.lineEndLabel.text=end
+AbstractNewGeometryPanel.toolTipText=The Geometry will be created with a default baked in Material, which can be changed later on by attaching a j3m file.\nThus only the common engine MatDefs are listed here.
+AbstractNewGeometryPanel.text=Material Definition
+AbstractNewGeometryPanel.inGeomName.text=My Geometry
+AbstractNewGeometryPanel.lblGeomName.text=Geometry Name
+AbstractNewGeometryPanel.inRandomColor.text=Use Random Color?
+AbstractNewGeometryPanel.inRandomColor.toolTipText=Overrides the specified Default Color
+AbstractNewGeometryPanel.lblDefaultColor.text=Default Color