AddAttributeDialog.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package com.jme3.gde.materialdefinition.dialog;
  6. import com.jme3.gde.materialdefinition.editor.Diagram;
  7. import com.jme3.scene.VertexBuffer;
  8. import java.awt.Point;
  9. import javax.swing.DefaultComboBoxModel;
  10. /**
  11. *
  12. * @author Nehon
  13. */
  14. @SuppressWarnings({"unchecked", "rawtypes"})
  15. public class AddAttributeDialog extends javax.swing.JDialog {
  16. private Diagram diagram;
  17. private Point clickPosition;
  18. /**
  19. * Creates new form AddMaterialParameter
  20. */
  21. public AddAttributeDialog(java.awt.Frame parent, boolean modal, Diagram diagram, Point clickPosition) {
  22. super(parent, modal);
  23. initComponents();
  24. DefaultComboBoxModel model = new DefaultComboBoxModel();
  25. for (VertexBuffer.Type attr : VertexBuffer.Type.values()) {
  26. model.addElement("in" + attr.name());
  27. }
  28. this.diagram = diagram;
  29. this.clickPosition = clickPosition;
  30. nameField.setModel(model);
  31. updateType();
  32. }
  33. /**
  34. * This method is called from within the constructor to initialize the form.
  35. * WARNING: Do NOT modify this code. The content of this method is always
  36. * regenerated by the Form Editor.
  37. */
  38. @SuppressWarnings("unchecked")
  39. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  40. private void initComponents() {
  41. jButton1 = new javax.swing.JButton();
  42. jButton2 = new javax.swing.JButton();
  43. jLabel1 = new javax.swing.JLabel();
  44. nameField = new javax.swing.JComboBox();
  45. jLabel2 = new javax.swing.JLabel();
  46. typeField = new javax.swing.JTextField();
  47. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  48. setTitle(org.openide.util.NbBundle.getMessage(AddAttributeDialog.class, "AddAttributeDialog.title")); // NOI18N
  49. setModal(true);
  50. org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(AddAttributeDialog.class, "AddAttributeDialog.jButton1.text")); // NOI18N
  51. jButton1.addActionListener(new java.awt.event.ActionListener() {
  52. public void actionPerformed(java.awt.event.ActionEvent evt) {
  53. jButton1ActionPerformed(evt);
  54. }
  55. });
  56. org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(AddAttributeDialog.class, "AddAttributeDialog.jButton2.text")); // NOI18N
  57. jButton2.addActionListener(new java.awt.event.ActionListener() {
  58. public void actionPerformed(java.awt.event.ActionEvent evt) {
  59. jButton2ActionPerformed(evt);
  60. }
  61. });
  62. jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
  63. org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AddAttributeDialog.class, "AddAttributeDialog.jLabel1.text")); // NOI18N
  64. nameField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
  65. nameField.addActionListener(new java.awt.event.ActionListener() {
  66. public void actionPerformed(java.awt.event.ActionEvent evt) {
  67. nameFieldActionPerformed(evt);
  68. }
  69. });
  70. org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(AddAttributeDialog.class, "AddAttributeDialog.jLabel2.text")); // NOI18N
  71. typeField.setText(org.openide.util.NbBundle.getMessage(AddAttributeDialog.class, "AddAttributeDialog.typeField.text")); // NOI18N
  72. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  73. getContentPane().setLayout(layout);
  74. layout.setHorizontalGroup(
  75. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  76. .addGroup(layout.createSequentialGroup()
  77. .addContainerGap()
  78. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  79. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  80. .addComponent(jButton2)
  81. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  82. .addComponent(jButton1))
  83. .addGroup(layout.createSequentialGroup()
  84. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  85. .addComponent(jLabel2)
  86. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
  87. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  88. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89. .addComponent(nameField, 0, 253, Short.MAX_VALUE)
  90. .addComponent(typeField))))
  91. .addContainerGap())
  92. );
  93. layout.setVerticalGroup(
  94. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  96. .addContainerGap()
  97. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  98. .addComponent(jLabel1)
  99. .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  100. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  101. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  102. .addComponent(jLabel2)
  103. .addComponent(typeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  104. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  105. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  106. .addComponent(jButton1)
  107. .addComponent(jButton2))
  108. .addContainerGap())
  109. );
  110. pack();
  111. }// </editor-fold>//GEN-END:initComponents
  112. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  113. setVisible(false);
  114. }//GEN-LAST:event_jButton2ActionPerformed
  115. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  116. diagram.addAttribute((String) nameField.getSelectedItem(), typeField.getText(), clickPosition);
  117. setVisible(false);
  118. }//GEN-LAST:event_jButton1ActionPerformed
  119. private void nameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameFieldActionPerformed
  120. updateType();
  121. }
  122. private void updateType() {
  123. VertexBuffer.Type attr = VertexBuffer.Type.valueOf(((String) nameField.getSelectedItem()).replaceFirst("in", ""));
  124. switch (attr) {
  125. case BoneWeight:
  126. case BindPoseNormal:
  127. case Binormal:
  128. case Normal:
  129. typeField.setText("vec3");
  130. break;
  131. case Size:
  132. typeField.setText("float");
  133. break;
  134. case Position:
  135. case BindPosePosition:
  136. case BindPoseTangent:
  137. case Tangent:
  138. case Color:
  139. typeField.setText("vec4");
  140. break;
  141. case InterleavedData:
  142. typeField.setText("int");
  143. break;
  144. case Index:
  145. typeField.setText("uint");
  146. break;
  147. case BoneIndex:
  148. typeField.setText("uvec4");
  149. break;
  150. case TexCoord:
  151. case TexCoord2:
  152. case TexCoord3:
  153. case TexCoord4:
  154. case TexCoord5:
  155. case TexCoord6:
  156. case TexCoord7:
  157. case TexCoord8:
  158. typeField.setText("vec2");
  159. break;
  160. }
  161. }//GEN-LAST:event_nameFieldActionPerformed
  162. // Variables declaration - do not modify//GEN-BEGIN:variables
  163. private javax.swing.JButton jButton1;
  164. private javax.swing.JButton jButton2;
  165. private javax.swing.JLabel jLabel1;
  166. private javax.swing.JLabel jLabel2;
  167. private javax.swing.JComboBox nameField;
  168. private javax.swing.JTextField typeField;
  169. // End of variables declaration//GEN-END:variables
  170. }