/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOUSE. See the GNU
 * General Public License for more details.
 *
 * You should have recieved a copy of the GNU General Public License
 * along with this program; if not write to the Free Software
 * Foundation, inc., 59 Temple Place, Suite 330, Boston MA 02111-1307
 * USA
 */

package gui;

import javax.swing.*;
import java.awt.*;
import j3d.*;
import java.awt.event.*;
import javax.swing.table.*;
import java.util.*;

public class PreProcessor_Element8 extends JPanel {
  Canvas3D J3D;
  Hashtable mat;
  BorderLayout borderLayout1 = new BorderLayout();
  private JPanel jPanel1 = new JPanel();
  private GridLayout gridLayout1 = new GridLayout();
  private JLabel jLabel6 = new JLabel();
  private JTextField jTextField1 = new JTextField();
  private JLabel jLabel7 = new JLabel();
  private JTextField jTextField2 = new JTextField();
  private JLabel jLabel8 = new JLabel();
  private JTextField jTextField3 = new JTextField();
  private JButton jButton2 = new JButton();
  private JButton jButton3 = new JButton();
  private JButton jButton4 = new JButton();
  private _Node[] nodes = new _Node[8];
  private JLabel jLabel1 = new JLabel();
  private JLabel jLabel2 = new JLabel();
  private JTextField jTextField4 = new JTextField();
  private JButton jButton5 = new JButton();
  private JPanel jPanel2 = new JPanel();
  private JPanel jPanel3 = new JPanel();
  private JButton jButton1 = new JButton();
  private JPanel jPanel4 = new JPanel();
  private BorderLayout borderLayout2 = new BorderLayout();
  private BorderLayout borderLayout3 = new BorderLayout();
  private JLabel jLabel3 = new JLabel();
  private JComboBox jComboBox1 = new JComboBox();
  private JLabel jLabel4 = new JLabel();
  private JTextField jTextField5 = new JTextField();
  private JButton jButton6 = new JButton();
  private JLabel jLabel5 = new JLabel();
  private JTextField jTextField6 = new JTextField();
  private JButton jButton7 = new JButton();
  private JLabel jLabel9 = new JLabel();
  private JTextField jTextField7 = new JTextField();
  private JButton jButton8 = new JButton();
  private JLabel jLabel10 = new JLabel();
  private JTextField jTextField8 = new JTextField();
  private JButton jButton9 = new JButton();

  public PreProcessor_Element8(Canvas3D j3d, Hashtable m) {
    try {
      J3D=j3d;
      mat=m;
      jbInit();
    }catch(Exception e) { e.printStackTrace();}
  }
  private void jbInit() throws Exception {
    this.setLayout(borderLayout1);
    jPanel1.setLayout(gridLayout1);
    gridLayout1.setColumns(3);
    gridLayout1.setRows(8);
    jLabel6.setText("Node 1");
    jLabel7.setText("Node 2");
    jLabel8.setText("Node 3");
    jButton2.setText("<<");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton2_actionPerformed(e);
      }
    });
    jButton3.setText("<<");
    jButton3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton3_actionPerformed(e);
      }
    });
    jButton4.setText("<<");
    jButton4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton4_actionPerformed(e);
      }
    });
    jTextField1.setEditable(false);
    jTextField2.setEditable(false);
    jTextField3.setEditable(false);
    jLabel1.setForeground(Color.blue);
    jLabel1.setText("Solid_Iso_6");
    jLabel2.setText("Node 4");
    jButton5.setText("<<");
    jButton5.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton5_actionPerformed(e);
      }
    });
    jTextField4.setEditable(false);
    jPanel2.setLayout(borderLayout2);
    jButton1.setText("add");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton1_actionPerformed(e);
      }
    });
    jPanel4.setLayout(borderLayout3);
    jLabel3.setText("Material");
    jLabel4.setText("Node 5");
    jButton6.setText("<<");
    jButton6.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton6_actionPerformed(e);
      }
    });
    jLabel5.setText("Node 6");
    jButton7.setText("<<");
    jButton7.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton7_actionPerformed(e);
      }
    });
    jLabel9.setText("Node 7");
    jButton8.setText("<<");
    jButton8.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton8_actionPerformed(e);
      }
    });
    jLabel10.setText("Node 8");
    jButton9.setText("<<");
    jButton9.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton9_actionPerformed(e);
      }
    });
    jTextField5.setEditable(false);
    jTextField7.setEditable(false);
    jTextField6.setEditable(false);
    jTextField8.setEditable(false);
    this.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jLabel6, null);
    jPanel1.add(jTextField1, null);
    jPanel1.add(jButton2, null);
    jPanel1.add(jLabel7, null);
    jPanel1.add(jTextField2, null);
    jPanel1.add(jButton3, null);
    jPanel1.add(jLabel8, null);
    jPanel1.add(jTextField3, null);
    jPanel1.add(jButton4, null);
    jPanel1.add(jLabel2, null);
    jPanel1.add(jTextField4, null);
    jPanel1.add(jButton5, null);
    jPanel1.add(jLabel4, null);
    jPanel1.add(jTextField5, null);
    jPanel1.add(jButton6, null);
    jPanel1.add(jLabel5, null);
    jPanel1.add(jTextField6, null);
    jPanel1.add(jButton7, null);
    jPanel1.add(jLabel9, null);
    jPanel1.add(jTextField7, null);
    jPanel1.add(jButton8, null);
    jPanel1.add(jLabel10, null);
    jPanel1.add(jTextField8, null);
    jPanel1.add(jButton9, null);
    this.add(jLabel1, BorderLayout.NORTH);
    this.add(jPanel2,  BorderLayout.SOUTH);
    jPanel2.add(jPanel4, BorderLayout.NORTH);
    jPanel4.add(jLabel3, BorderLayout.WEST);
    jPanel4.add(jComboBox1, BorderLayout.CENTER);
    jPanel2.add(jPanel3, BorderLayout.CENTER);
    jPanel3.add(jButton1, null);
    for(Enumeration en = mat.keys(); en.hasMoreElements();)  jComboBox1.addItem(en.nextElement());
    this.validate();
  }


  public void error(Object st){
    JOptionPane.showMessageDialog(null,"Error: "+st,"Error!",JOptionPane.ERROR_MESSAGE);
    System.out.println("Error: "+st);
  }

  void jButton1_actionPerformed(ActionEvent e) {
    if(nodes[0]==null || nodes[1]==null || nodes[2]==null || nodes[3]==null || nodes[4]==null || nodes[5]==null || nodes[6]==null || nodes[7]==null)return;
    J3D.add3D(new _Element8(nodes[0],nodes[1],nodes[2],nodes[3],nodes[4],nodes[5],nodes[6],nodes[7],(Material)mat.get(jComboBox1.getSelectedItem()+"")));
    J3D.repaint();
  }

  void jButton2_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[0]=(_Node)obj;
      jTextField1.setText(obj.toString());
    }else{
      nodes[0]=null;
      jTextField1.setText("");
    }
  }

  void jButton3_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[1]=(_Node)obj;
      jTextField2.setText(obj.toString());
    }else{
      nodes[1]=null;
      jTextField2.setText("");
    }
  }

  void jButton4_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[2]=(_Node)obj;
      jTextField3.setText(obj.toString());
    }else{
      nodes[2]=null;
      jTextField3.setText("");
    }
  }

  void jButton5_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[3]=(_Node)obj;
      jTextField4.setText(obj.toString());
    }else{
      nodes[3]=null;
      jTextField4.setText("");
    }
  }

  void jButton6_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[4]=(_Node)obj;
      jTextField5.setText(obj.toString());
    }else{
      nodes[4]=null;
      jTextField5.setText("");
    }

  }

  void jButton7_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[5]=(_Node)obj;
      jTextField6.setText(obj.toString());
    }else{
      nodes[5]=null;
      jTextField6.setText("");
    }

  }

  void jButton8_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[6]=(_Node)obj;
      jTextField7.setText(obj.toString());
    }else{
      nodes[6]=null;
      jTextField7.setText("");
    }

  }

  void jButton9_actionPerformed(ActionEvent e) {
    Object obj = J3D.getSelectedObject3D();
    if(obj!=null && obj instanceof _Node){
      nodes[7]=(_Node)obj;
      jTextField8.setText(obj.toString());
    }else{
      nodes[7]=null;
      jTextField8.setText("");
    }

  }
}


