/*
 * 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 java.awt.event.*;
import java.io.*;
import java.util.*;
import j3d.*;
import javax.swing.event.*;
import java.awt.image.*;
/**
 * Insert the type's description here.
 *
 * @author: Yuriy Mikhaylovskiy
 */

public class PostProcessor extends JPanel {
  String project;
  public static final String ver = "Post Processor (2004.07.17)";
  Hashtable db_node = new Hashtable();
  Hashtable db_node_tmp = new Hashtable();
  Hashtable db_element = new Hashtable();
  Hashtable db_element_type = new Hashtable();
  Hashtable db_displacements = new Hashtable();
  Hashtable db_strains = new Hashtable();
  Hashtable db_stresses = new Hashtable();
  DefaultListModel model_show = new DefaultListModel();
  DefaultListModel model_hide = new DefaultListModel();
  JList Show_list = new JList(model_show);
  JList Hide_list = new JList(model_hide);
  String[][] db_graph_tmp;
  String db_graph_inf;
  String[] st_result = { "DISPLACEMENTS (I)","DISPLACEMENTS (X)","DISPLACEMENTS (Y)","DISPLACEMENTS (Z)","STRAINS (I)","STRAINS (X)","STRAINS (Y)","STRAINS (Z)","STRAINS (XY)","STRAINS (YZ)","STRAINS (XZ)","STRESSES (I)","STRESSES (X)","STRESSES (Y)","STRESSES (Z)","STRESSES (XY)","STRESSES (YZ)","STRESSES (XZ)" };
  //xx yy zz xy yz xz
  float maxdx,maxdy,maxdz,maxdi,maxex,maxey,maxez,maxexy,maxeyz,maxexz,maxsx,maxsy,maxsz,maxsxy,maxsyz,maxsxz,maxei,maxsi,
  mindx,mindy,mindz,minex,miney,minez,minexy,mineyz,minexz,minsx,minsy,minsz,minsxy,minsyz,minsxz;
  ImageIcon img_new = new ImageIcon(PostProcessor.class.getResource("new.gif"));
  ImageIcon img_open = new ImageIcon(PostProcessor.class.getResource("open.gif"));
  ImageIcon img_add = new ImageIcon(PostProcessor.class.getResource("add.gif"));
  ImageIcon img_save = new ImageIcon(PostProcessor.class.getResource("save.gif"));
  ImageIcon img_saveall = new ImageIcon(PostProcessor.class.getResource("saveall.gif"));
//  ImageIcon img_zooma = new ImageIcon(PostProcessor.class.getResource("zooma.gif"));
  ImageIcon img_zoomin = new ImageIcon(PostProcessor.class.getResource("zoomin.gif"));
  ImageIcon img_zoomout = new ImageIcon(PostProcessor.class.getResource("zoomout.gif"));
  ImageIcon img_view_top = new ImageIcon(PostProcessor.class.getResource("view_top.gif"));
  ImageIcon img_view_bottom = new ImageIcon(PostProcessor.class.getResource("view_bottom.gif"));
  ImageIcon img_view_left = new ImageIcon(PostProcessor.class.getResource("view_left.gif"));
  ImageIcon img_view_right = new ImageIcon(PostProcessor.class.getResource("view_right.gif"));
  ImageIcon img_view_front = new ImageIcon(PostProcessor.class.getResource("view_front.gif"));
  ImageIcon img_view_back = new ImageIcon(PostProcessor.class.getResource("view_back.gif"));
  ImageIcon img_view_sw = new ImageIcon(PostProcessor.class.getResource("view_sw.gif"));
  ImageIcon img_view_se = new ImageIcon(PostProcessor.class.getResource("view_se.gif"));
  ImageIcon img_view_ne = new ImageIcon(PostProcessor.class.getResource("view_ne.gif"));
  ImageIcon img_view_nw = new ImageIcon(PostProcessor.class.getResource("view_nw.gif"));
  BorderLayout borderLayout1 = new BorderLayout();
  JTextField tf_deformed = new JTextField();
  JPanel jPanel7 = new JPanel();
  JButton b_viewbottom = new JButton();
  JCheckBox cb_conturfill = new JCheckBox();
  JButton b_viewtop = new JButton();
  JPanel jPanel5 = new JPanel();
  JButton b_zoomout = new JButton();
  JButton b_zoomin = new JButton();
  JPanel jPanel3 = new JPanel();
//  JButton jButton5 = new JButton();
  JCheckBox cb_element = new JCheckBox();
  JCheckBox cb_deformed = new JCheckBox();
  JComboBox cb_result = new JComboBox(st_result);
  JCheckBox cb_node = new JCheckBox();
  JScrollPane jScrollPane1 = new JScrollPane();
  JList time_step = new JList();
  JButton b_open = new JButton();
  JCheckBox cb_mesh = new JCheckBox();
  GridLayout gridLayout1 = new GridLayout();
  JButton b_viewleft = new JButton();
  JButton b_saveall = new JButton();
  JToolBar jToolBar1 = new JToolBar();
  JButton b_save = new JButton();
  JLabel jLabel3 = new JLabel();
  Canvas3D J3D = new Canvas3D();
  JLabel jLabel2 = new JLabel();
  BorderLayout borderLayout5 = new BorderLayout();
  JLabel jLabel1 = new JLabel();
  BorderLayout borderLayout4 = new BorderLayout();
  BorderLayout borderLayout3 = new BorderLayout();
  JCheckBox cb_gradient = new JCheckBox();
  JButton b_viewright = new JButton();
  JButton b_viewsw = new JButton();
  JButton b_viewse = new JButton();
  JButton b_viewne = new JButton();
  JButton b_viewnw = new JButton();
  JButton b_viewfront = new JButton();
  JButton b_viewback = new JButton();
  JButton b_elements = new JButton();
  JCheckBox cb_gradientresult = new JCheckBox();


  public PostProcessor() {
    try { jbInit(); }catch(Exception e) { e.printStackTrace();}
  }
  private void jbInit() throws Exception {
    jPanel7.setLayout(borderLayout5);
    tf_deformed.setText("1");
    tf_deformed.setPreferredSize(new Dimension(30, 21));
    tf_deformed.setMinimumSize(new Dimension(30, 21));
    this.setLayout(borderLayout1);
    //J3D.GRADIENTCOLOR=0;
    J3D.GRIDMODE=false;
    J3D.GRAPHICSMODE=J3D.GRAPHICSMODE_SURFACE;
    b_viewbottom.setToolTipText("Bottom View");
    b_viewbottom.setIcon(img_view_bottom);
    b_viewbottom.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewbottom_actionPerformed(e);
      }
    });
    cb_conturfill.setSelected(true);
    cb_conturfill.setText("Contour fill");
    b_viewtop.setToolTipText("Top View");
    b_viewtop.setIcon(img_view_top);
    b_viewtop.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewtop_actionPerformed(e);
      }
    });
    jPanel5.setLayout(gridLayout1);
    b_zoomout.setToolTipText("Zoom out");
    b_zoomout.setIcon(img_zoomout);
    b_zoomout.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_zoomout_actionPerformed(e);
      }
    });
    b_zoomin.setToolTipText("Zoom in");
    b_zoomin.setIcon(img_zoomin);
    b_zoomin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_zoomin_actionPerformed(e);
      }
    });
    jPanel3.setLayout(borderLayout3);
//    jButton5.setIcon(img_zooma);
    cb_element.setText("Elements label");
    cb_deformed.setSelected(true);
    cb_deformed.setText("Deformed");
    cb_node.setText("Nodes label");
    jScrollPane1.setPreferredSize(new Dimension(26, 132));
    time_step.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(ListSelectionEvent e) {
        draw();
      }
    });
    b_open.setToolTipText("Open *.res");
    b_open.setIcon(img_open);
    b_open.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_open_actionPerformed(e);
      }
    });
    cb_mesh.setSelected(true);
    cb_mesh.setText("Mesh");
    gridLayout1.setRows(12);
    b_viewleft.setToolTipText("Left View");
    b_viewleft.setIcon(img_view_left);
    b_viewleft.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewleft_actionPerformed(e);
      }
    });
    b_saveall.setToolTipText("Save images");
    b_saveall.setIcon(img_saveall);
    b_saveall.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_saveall_actionPerformed(e);
      }
    });
    jToolBar1.setFloatable(false);
    b_save.setToolTipText("Save image");
    b_save.setIcon(img_save);
    b_save.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_save_actionPerformed(e);
      }
    });
    jLabel3.setText("Time step");
    J3D.setBackground(Color.white);
    J3D.setBackground(Color.white);
    jLabel2.setText("Result");
    jLabel1.setText("Show");
    cb_gradient.setText("Gradient");
    b_viewright.setToolTipText("Right View");
    b_viewright.setIcon(img_view_right);
    b_viewright.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewright_actionPerformed(e);
      }
    });
    b_viewsw.setToolTipText("SW Isometric View");
    b_viewsw.setIcon(img_view_sw);
    b_viewsw.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewsw_actionPerformed(e);
      }
    });
    b_viewse.setToolTipText("SE Isometric View");
    b_viewse.setIcon(img_view_se);
    b_viewse.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewse_actionPerformed(e);
      }
    });
    b_viewne.setToolTipText("NE Isometric View");
    b_viewne.setIcon(img_view_ne);
    b_viewne.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewne_actionPerformed(e);
      }
    });
    b_viewnw.setToolTipText("NW Isometric View");
    b_viewnw.setIcon(img_view_nw);
    b_viewnw.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewnw_actionPerformed(e);
      }
    });
    b_viewfront.setToolTipText("Front View");
    b_viewfront.setIcon(img_view_front);
    b_viewfront.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewfront_actionPerformed(e);
      }
    });
    b_viewback.setToolTipText("Back View");
    b_viewback.setIcon(img_view_back);
    b_viewback.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_viewback_actionPerformed(e);
      }
    });
    b_elements.setText("Elements");
    b_elements.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        b_elements_actionPerformed(e);
      }
    });
    cb_gradientresult.setSelected(true);
    cb_gradientresult.setText("Gradient Result");
    this.add(J3D, BorderLayout.CENTER);
    this.add(jToolBar1, BorderLayout.NORTH);
    jToolBar1.add(b_open, null);
    jToolBar1.add(b_save, null);
    jToolBar1.add(b_saveall, null);
    jToolBar1.addSeparator();
//    jToolBar1.add(jButton5, null);
    jToolBar1.add(b_zoomin, null);
    jToolBar1.add(b_zoomout, null);
    jToolBar1.addSeparator();
    jToolBar1.add(b_viewtop, null);
    jToolBar1.add(b_viewbottom, null);
    jToolBar1.add(b_viewleft, null);
    jToolBar1.add(b_viewright, null);
    jToolBar1.add(b_viewfront, null);
    jToolBar1.add(b_viewback, null);
    jToolBar1.addSeparator();
    jToolBar1.add(b_viewsw, null);
    jToolBar1.add(b_viewse, null);
    jToolBar1.add(b_viewne, null);
    jToolBar1.add(b_viewnw, null);
    this.add(jPanel3, BorderLayout.WEST);
    jPanel3.add(jPanel5, BorderLayout.NORTH);
    jPanel5.add(jLabel1, null);
    jPanel5.add(cb_mesh, null);
    jPanel5.add(jPanel7, null);
    jPanel7.add(cb_deformed, BorderLayout.CENTER);
    jPanel7.add(tf_deformed, BorderLayout.EAST);
    jPanel5.add(cb_conturfill, null);
    jPanel5.add(cb_gradient, null);
    jPanel5.add(cb_node, null);
    jPanel5.add(cb_element, null);
    jPanel5.add(cb_gradientresult, null);
    jPanel5.add(b_elements, null);
    jPanel5.add(jLabel2, null);
    jPanel5.add(cb_result, null);
    jPanel5.add(jLabel3, null);
    jPanel3.add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(time_step, null);
  }

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


  public void load(String st){
    try{
      //Rod_2 "Type100" ElemType Linear "MeshType100"
      //Beam_2 "Type110" ElemType Linear "MeshType110"
      //Beam_Spring_2,Contact_Line "Type120" ElemType Linear "MeshType120"
      //Contact_Triangle "Type420" ElemType Triangle "MeshType420"
      //Shell_C0_3 "Type210" ElemType Triangle "MeshType210"
      //Shell_BT_4 "Type300" ElemType Quadrilateral "MeshType300"
      //Solid_Iso_6 "Type500" ElemType Hexahedra "MeshType500"
      J3D.remove_all();
      time_step.removeAll();
      maxdx=maxdy=maxdz=maxdi=maxex=maxey=maxez=maxexy=maxeyz=maxexz=maxsx=maxsy=maxsz=maxsxy=maxsyz=maxsxz=maxei=maxsi=Float.MIN_VALUE;
      mindx=mindy=mindz=minex=miney=minez=minexy=mineyz=minexz=minsx=minsy=minsz=minsxy=minsyz=minsxz=Float.MIN_VALUE;
      db_node = new Hashtable();
      db_element = new Hashtable();
      db_element_type = new Hashtable();
      db_displacements = new Hashtable();
      db_strains = new Hashtable();
      db_stresses = new Hashtable();
      model_show.removeAllElements();
      model_hide.removeAllElements();
      DefaultListModel model = new DefaultListModel();
      String st_msh = st.substring(0,st.length()-3)+"msh";
      String st_dat = st;
      RandomAccessFile in = new RandomAccessFile(st_msh, "r");
      String dat;
      System.out.print("\nLoading mesh ...");
      while((dat=in.readLine())!=null){
        if(dat.startsWith("COORDINATES")){
          _Point p3d;
          while(!(dat=in.readLine()).startsWith("END")){
            StringTokenizer st_t = new StringTokenizer(dat);
            String index = st_t.nextToken();
            p3d = toPoint3d(dat);
            db_node.put(index,p3d);
          }
        }else if(dat.startsWith("ELEMENTS")){
          while(!(dat=in.readLine()).startsWith("END")){
            StringTokenizer st_t = new StringTokenizer(dat);
            String index = st_t.nextToken();
            int[] arr = toArrayInt(dat);
            db_element.put(index,arr);
            if(arr.length==2){
              J3D.add3D(new _Line((_Point)db_node.get(arr[0]+""),(_Point)db_node.get(arr[1]+""),Color.black));
            }else if(arr.length==3){
              J3D.add3D(new _Triangle((_Point)db_node.get(arr[0]+""),(_Point)db_node.get(arr[1]+""),(_Point)db_node.get(arr[2]+""),null,Color.black));
            }else if(arr.length==4){
              J3D.add3D(new _Quad((_Point)db_node.get(arr[0]+""),(_Point)db_node.get(arr[1]+""),(_Point)db_node.get(arr[2]+""),(_Point)db_node.get(arr[3]+""),null,Color.black));
            }else  if(arr.length==8){
              J3D.add3D(new _Quad((_Point)db_node.get(arr[0]+""),(_Point)db_node.get(arr[1]+""),(_Point)db_node.get(arr[2]+""),(_Point)db_node.get(arr[3]+""),null,Color.black));
              J3D.add3D(new _Quad((_Point)db_node.get(arr[4]+""),(_Point)db_node.get(arr[5]+""),(_Point)db_node.get(arr[6]+""),(_Point)db_node.get(arr[7]+""),null,Color.black));
              J3D.add3D(new _Quad((_Point)db_node.get(arr[0]+""),(_Point)db_node.get(arr[1]+""),(_Point)db_node.get(arr[5]+""),(_Point)db_node.get(arr[4]+""),null,Color.black));
              J3D.add3D(new _Quad((_Point)db_node.get(arr[1]+""),(_Point)db_node.get(arr[2]+""),(_Point)db_node.get(arr[6]+""),(_Point)db_node.get(arr[5]+""),null,Color.black));
              J3D.add3D(new _Quad((_Point)db_node.get(arr[2]+""),(_Point)db_node.get(arr[3]+""),(_Point)db_node.get(arr[7]+""),(_Point)db_node.get(arr[6]+""),null,Color.black));
              J3D.add3D(new _Quad((_Point)db_node.get(arr[0]+""),(_Point)db_node.get(arr[3]+""),(_Point)db_node.get(arr[7]+""),(_Point)db_node.get(arr[4]+""),null,Color.black));
            }
            model_show.addElement(index);
          }
        }
      }
      in.close();
      in = new RandomAccessFile(st_dat, "r");
      System.out.print("... OK\nLoading data ...");
      dat=in.readLine();
      while(dat!=null){
        message(dat);
        //System.out.println(dat);
        if(dat.toUpperCase().startsWith("GAUSSPOINTS")){
          StringTokenizer st_t = new StringTokenizer(dat,"\"");
          st_t.nextToken();
          String et = st_t.nextToken();
          dat=in.readLine();
          st_t = new StringTokenizer(dat,":");
          st_t.nextToken();
          int np = Integer.parseInt(st_t.nextToken().trim());
          db_element_type.put(et,""+np);
          while(!(dat=in.readLine()).toUpperCase().startsWith("END")){  }
        }else if(dat.indexOf("DISPLACEMENTS")!=-1){
          StringTokenizer st_t = new StringTokenizer(dat.trim());
          st_t.nextToken();
          st_t.nextToken();
          String step = st_t.nextToken();
          model.addElement(step);
          Hashtable v = new Hashtable();
          while((dat=in.readLine())!=null && dat.indexOf("LOCAL")==-1 && dat.indexOf("GLOBAL")==-1){
            st_t = new StringTokenizer(dat);
            String key = st_t.nextToken();
            _Point p = toPoint3d(dat);
            mindx=Math.min(mindx,p.x);
            mindy=Math.min(mindy,p.y);
            mindz=Math.min(mindz,p.z);
            maxdx=Math.max(maxdx,p.x);
            maxdy=Math.max(maxdy,p.y);
            maxdz=Math.max(maxdz,p.z);
            maxdi=Math.max(maxdi,(float)Math.sqrt(p.x*p.x+p.y*p.y+p.z*p.z));
            v.put(key,p);
          }
          db_displacements.put(step,v);
        }else if(dat.indexOf("STRESSES")!=-1){
          StringTokenizer st_t = new StringTokenizer(dat.trim());
          st_t.nextToken();
          st_t.nextToken();
          String step = st_t.nextToken();
          Hashtable v = (Hashtable)db_stresses.get(step);
          if(v==null) v = new Hashtable();
          while((dat=in.readLine())!=null  && dat.indexOf("LOCAL")==-1 && dat.indexOf("GLOBAL")==-1 && dat.indexOf("DISPLACEMENTS")==-1){
            st_t = new StringTokenizer(dat);
            if(st_t.countTokens()==7){
              long pos = in.getFilePointer();
              String dat1=in.readLine();
              StringTokenizer st_t1=null;
              if(dat1!=null) st_t1 = new StringTokenizer(dat1);
              if(dat1==null || st_t1.countTokens()==7 || dat1.indexOf("LOCAL")!=-1 || dat1.indexOf("GLOBAL")!=-1 || dat1.indexOf("DISPLACEMENTS")!=-1){
                in.seek(pos);
              }else{
                dat+=" "+dat1+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine();
              }
            }
            String key = st_t.nextToken();
            float[] arr = toArrayFloat(dat);
            if(arr.length==1){
              minsx=Math.min(minsx,arr[0]);
              maxsx=Math.max(maxsx,arr[0]);
              maxsi=Math.max(maxsi,Math.abs(arr[0]));
            }else if(arr.length==6){
              minsx=Math.min(minsx,arr[0]);
              minsy=Math.min(minsy,arr[1]);
              minsz=Math.min(minsz,arr[2]);
              minsxy=Math.min(minsxy,arr[3]);
              minsyz=Math.min(minsyz,arr[4]);
              minsxz=Math.min(minsxz,arr[5]);
              maxsx=Math.max(maxsx,arr[0]);
              maxsy=Math.max(maxsy,arr[1]);
              maxsz=Math.max(maxsz,arr[2]);
              maxsxy=Math.max(maxsxy,arr[3]);
              maxsyz=Math.max(maxsyz,arr[4]);
              maxsxz=Math.max(maxsxz,arr[5]);
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+6*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
            }else{
              minsx=Math.min(minsx,(arr[0]+arr[6]+arr[12]+arr[18]+arr[24]+arr[30]+arr[36]+arr[42])/8);
              minsy=Math.min(minsy,(arr[1]+arr[7]+arr[13]+arr[19]+arr[25]+arr[31]+arr[37]+arr[43])/8);
              minsz=Math.min(minsz,(arr[2]+arr[8]+arr[14]+arr[20]+arr[26]+arr[32]+arr[38]+arr[44])/8);
              minsxy=Math.min(minsxy,(arr[3]+arr[9]+arr[15]+arr[21]+arr[27]+arr[33]+arr[39]+arr[45])/8);
              minsyz=Math.min(minsyz,(arr[4]+arr[10]+arr[16]+arr[22]+arr[28]+arr[34]+arr[40]+arr[46])/8);
              minsxz=Math.min(minsxz,(arr[5]+arr[11]+arr[17]+arr[23]+arr[29]+arr[35]+arr[41]+arr[47])/8);
              maxsx=Math.max(maxsx,(arr[0]+arr[6]+arr[12]+arr[18]+arr[24]+arr[30]+arr[36]+arr[42])/8);
              maxsy=Math.max(maxsy,(arr[1]+arr[7]+arr[13]+arr[19]+arr[25]+arr[31]+arr[37]+arr[43])/8);
              maxsz=Math.max(maxsz,(arr[2]+arr[8]+arr[14]+arr[20]+arr[26]+arr[32]+arr[38]+arr[44])/8);
              maxsxy=Math.max(maxsxy,(arr[3]+arr[9]+arr[15]+arr[21]+arr[27]+arr[33]+arr[39]+arr[45])/8);
              maxsyz=Math.max(maxsyz,(arr[4]+arr[10]+arr[16]+arr[22]+arr[28]+arr[34]+arr[40]+arr[46])/8);
              maxsxz=Math.max(maxsxz,(arr[5]+arr[11]+arr[17]+arr[23]+arr[29]+arr[35]+arr[41]+arr[47])/8);
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+6*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[6]-arr[7],2)+Math.pow(arr[7]-arr[8],2)+Math.pow(arr[8]-arr[6],2)+6*(arr[9]*arr[9]+arr[10]*arr[10]+arr[11]*arr[11])));
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[12]-arr[13],2)+Math.pow(arr[13]-arr[14],2)+Math.pow(arr[14]-arr[12],2)+6*(arr[15]*arr[15]+arr[16]*arr[16]+arr[17]*arr[17])));
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[18]-arr[19],2)+Math.pow(arr[19]-arr[20],2)+Math.pow(arr[20]-arr[18],2)+6*(arr[21]*arr[21]+arr[22]*arr[22]+arr[23]*arr[23])));
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[24]-arr[25],2)+Math.pow(arr[25]-arr[26],2)+Math.pow(arr[26]-arr[24],2)+6*(arr[27]*arr[27]+arr[28]*arr[28]+arr[29]*arr[29])));
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[30]-arr[31],2)+Math.pow(arr[31]-arr[32],2)+Math.pow(arr[32]-arr[30],2)+6*(arr[33]*arr[33]+arr[34]*arr[34]+arr[35]*arr[35])));
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[36]-arr[37],2)+Math.pow(arr[36]-arr[38],2)+Math.pow(arr[38]-arr[36],2)+6*(arr[39]*arr[39]+arr[40]*arr[40]+arr[41]*arr[41])));
              maxsi=(float)Math.max(maxsi,Math.sqrt(2)/2*Math.sqrt(Math.pow(arr[42]-arr[43],2)+Math.pow(arr[43]-arr[44],2)+Math.pow(arr[44]-arr[42],2)+6*(arr[45]*arr[45]+arr[46]*arr[46]+arr[47]*arr[47])));
            }
            v.put(key,arr);
          }
          db_stresses.put(step,v);
        }else if(dat.indexOf("STRAINS")!=-1){
          StringTokenizer st_t = new StringTokenizer(dat.trim());
          st_t.nextToken();
          st_t.nextToken();
          String step = st_t.nextToken();
          Hashtable v = (Hashtable)db_strains.get(step);
          if(v==null) v = new Hashtable();
          while((dat=in.readLine())!=null  && dat.indexOf("LOCAL")==-1 && dat.indexOf("GLOBAL")==-1 && dat.indexOf("DISPLACEMENTS")==-1){
            st_t = new StringTokenizer(dat);
            if(st_t.countTokens()==7){
              long pos = in.getFilePointer();
              String dat1=in.readLine();
              StringTokenizer st_t1=null;
              if(dat1!=null) st_t1 = new StringTokenizer(dat1);
              if(dat1==null || st_t1.countTokens()==7 || dat1.indexOf("LOCAL")!=-1 || dat1.indexOf("GLOBAL")!=-1 || dat1.indexOf("DISPLACEMENTS")!=-1){
                in.seek(pos);
              }else{
                dat+=" "+dat1+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine()+" "+in.readLine();
              }
            }
            String key = st_t.nextToken();
            float[] arr = toArrayFloat(dat);
            if(arr.length==1){
              minex=Math.min(minex,arr[0]);
              maxex=Math.max(maxex,arr[0]);
              maxei=Math.max(maxei,Math.abs(arr[0]));
            }else if(arr.length==6){
              minex=Math.min(minex,arr[0]);
              miney=Math.min(miney,arr[1]);
              minez=Math.min(minez,arr[2]);
              minexy=Math.min(minexy,arr[3]);
              mineyz=Math.min(mineyz,arr[4]);
              minexz=Math.min(minexz,arr[5]);
              maxex=Math.max(maxex,arr[0]);
              maxey=Math.max(maxey,arr[1]);
              maxez=Math.max(maxez,arr[2]);
              maxexy=Math.max(maxexy,arr[3]);
              maxeyz=Math.max(maxeyz,arr[4]);
              maxexz=Math.max(maxexz,arr[5]);
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+1.5*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
            }else{
              minex=Math.min(minex,(arr[0]+arr[6]+arr[12]+arr[18]+arr[24]+arr[30]+arr[36]+arr[42])/8);
              miney=Math.min(miney,(arr[1]+arr[7]+arr[13]+arr[19]+arr[25]+arr[31]+arr[37]+arr[43])/8);
              minez=Math.min(minez,(arr[2]+arr[8]+arr[14]+arr[20]+arr[26]+arr[32]+arr[38]+arr[44])/8);
              minexy=Math.min(minexy,(arr[3]+arr[9]+arr[15]+arr[21]+arr[27]+arr[33]+arr[39]+arr[45])/8);
              mineyz=Math.min(mineyz,(arr[4]+arr[10]+arr[16]+arr[22]+arr[28]+arr[34]+arr[40]+arr[46])/8);
              minexz=Math.min(minexz,(arr[5]+arr[11]+arr[17]+arr[23]+arr[29]+arr[35]+arr[41]+arr[47])/8);
              maxex=Math.max(maxex,(arr[0]+arr[6]+arr[12]+arr[18]+arr[24]+arr[30]+arr[36]+arr[42])/8);
              maxey=Math.max(maxey,(arr[1]+arr[7]+arr[13]+arr[19]+arr[25]+arr[31]+arr[37]+arr[43])/8);
              maxez=Math.max(maxez,(arr[2]+arr[8]+arr[14]+arr[20]+arr[26]+arr[32]+arr[38]+arr[44])/8);
              maxexy=Math.max(maxexy,(arr[3]+arr[9]+arr[15]+arr[21]+arr[27]+arr[33]+arr[39]+arr[45])/8);
              maxeyz=Math.max(maxeyz,(arr[4]+arr[10]+arr[16]+arr[22]+arr[28]+arr[34]+arr[40]+arr[46])/8);
              maxexz=Math.max(maxexz,(arr[5]+arr[11]+arr[17]+arr[23]+arr[29]+arr[35]+arr[41]+arr[47])/8);
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[0]-arr[1],2)+Math.pow(arr[1]-arr[2],2)+Math.pow(arr[2]-arr[0],2)+1.5*(arr[3]*arr[3]+arr[4]*arr[4]+arr[5]*arr[5])));
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[6]-arr[7],2)+Math.pow(arr[7]-arr[8],2)+Math.pow(arr[8]-arr[6],2)+1.5*(arr[9]*arr[9]+arr[10]*arr[10]+arr[11]*arr[11])));
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[12]-arr[13],2)+Math.pow(arr[13]-arr[14],2)+Math.pow(arr[14]-arr[12],2)+1.5*(arr[15]*arr[15]+arr[16]*arr[16]+arr[17]*arr[17])));
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[18]-arr[19],2)+Math.pow(arr[19]-arr[20],2)+Math.pow(arr[20]-arr[18],2)+1.5*(arr[21]*arr[21]+arr[22]*arr[22]+arr[23]*arr[23])));
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[24]-arr[25],2)+Math.pow(arr[25]-arr[26],2)+Math.pow(arr[26]-arr[24],2)+1.5*(arr[27]*arr[27]+arr[28]*arr[28]+arr[29]*arr[29])));
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[30]-arr[31],2)+Math.pow(arr[31]-arr[32],2)+Math.pow(arr[32]-arr[30],2)+1.5*(arr[33]*arr[33]+arr[34]*arr[34]+arr[35]*arr[35])));
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[36]-arr[37],2)+Math.pow(arr[36]-arr[38],2)+Math.pow(arr[38]-arr[36],2)+1.5*(arr[39]*arr[39]+arr[40]*arr[40]+arr[41]*arr[41])));
              maxei=(float)Math.max(maxei,Math.sqrt(2)/3*Math.sqrt(Math.pow(arr[42]-arr[43],2)+Math.pow(arr[43]-arr[44],2)+Math.pow(arr[44]-arr[42],2)+1.5*(arr[45]*arr[45]+arr[46]*arr[46]+arr[47]*arr[47])));
            }
            v.put(key,arr);
          }
          db_strains.put(step,v);
        }else dat=in.readLine();
      }
      in.close();
      System.out.print("... OK\n");
      message(ver+"   "+project);
      try{
        time_step.setModel(model);
      } catch(Exception e2){}
      J3D.repaint();
    } catch(Exception e1) {error(e1);}

  }

  public _Point toPoint3d(String st)throws Exception{
    StringTokenizer st_t = new StringTokenizer(st);
    st_t.nextToken();
    return new _Point(new Float(st_t.nextToken()).floatValue(),new Float(st_t.nextToken()).floatValue(),new Float(st_t.nextToken()).floatValue(),Color.red);
  }
  public int[] toArrayInt(String st)throws Exception{
    StringTokenizer st_t = new StringTokenizer(st);
    int[] arr = new int[st_t.countTokens()-1];
    st_t.nextToken();
    for(int i=0; i<arr.length; i++){
      arr[i]= Integer.parseInt(st_t.nextToken());
    }
    return arr;
  }
  public float[] toArrayFloat(String st)throws Exception{
    StringTokenizer st_t = new StringTokenizer(st);
    float[] arr = new float[st_t.countTokens()-1];
    st_t.nextToken();
    for(int i=0; i<arr.length; i++){
      arr[i]= Float.parseFloat(st_t.nextToken());
    }
    return arr;
  }
  public void message(Object obj){
    Frame f = getFrame(this);
    f.setTitle(""+obj);
  }

  public Color getGradient(float min, float val, float max){
    int d = Math.round(val/(max-min)*17);
    if(0==d)return new Color(0,0,150);
    if(1==d)return new Color(0,0,190);
    if(2==d)return new Color(0,0,220);
    if(3==d)return new Color(0,0,255);
    if(4==d)return new Color(0,150,255);
    if(5==d)return new Color(0,200,255);
    if(6==d)return new Color(0,255,255);
    if(7==d)return new Color(0,255,200);
    if(8==d)return new Color(0,255,0);
    if(9==d)return new Color(200,255,0);
    if(10==d)return new Color(255,255,0);
    if(11==d)return new Color(255,200,0);
    if(12==d)return new Color(255,150,0);
    if(13==d)return new Color(255,0,0);
    if(14==d)return new Color(220,0,0);
    if(15==d)return new Color(205,0,0);
    return new Color(180,0,0);
  }
  public void draw(){
    J3D.GRAPHICSMODE=j3d.Canvas3D.GRAPHICSMODE_SURFACE;
    if(cb_gradient.isSelected()) J3D.RENDERMODE=J3D.RENDERMODE_RENDER; else J3D.RENDERMODE=J3D.RENDERMODE_SHADE;
    if(!cb_mesh.isSelected() && cb_conturfill.isSelected())J3D.GRAPHICSMODE=j3d.Canvas3D.GRAPHICSMODE_SOLID;
    if(cb_mesh.isSelected() && !cb_conturfill.isSelected())J3D.GRAPHICSMODE=j3d.Canvas3D.GRAPHICSMODE_WIREFRAME;
    if(!cb_mesh.isSelected() && !cb_conturfill.isSelected())J3D.GRAPHICSMODE=-1;
    float kd = 1;
    if(cb_deformed.isSelected())
      try{kd=Float.parseFloat(tf_deformed.getText());}catch(Exception e){error("Factor of deformation - "+e);}
      else kd=0;
    J3D.remove_all();
    Hashtable db_element_hide = new Hashtable();
    for(int i=0; i<model_hide.size(); i++) db_element_hide.put(model_hide.elementAt(i)+"","");
    String time = time_step.getSelectedValue()+"";
    //Show nodes
    if(cb_node.isSelected()){
        Hashtable db_node_tmp = (Hashtable)db_displacements.get(time);
        for(Enumeration en = db_node_tmp.keys(); en.hasMoreElements();){
          String key = en.nextElement()+"";
          _Point p1 = (_Point)db_node.get(key);
          _Point p2 = (_Point)db_node_tmp.get(key);
          J3D.add3D(new _OrientedText(key,(p1.x+p2.x*kd),(p1.y+p2.y*kd),(p1.z+p2.z*kd)));
        }
    }
    //Show elements
    if(cb_element.isSelected()){
      Hashtable db_node_tmp = (Hashtable)db_displacements.get(time);
      Hashtable db_stresses_tmp = (Hashtable)db_stresses.get(time);
      for(Enumeration en = db_stresses_tmp.keys(); en.hasMoreElements();){
        String key = en.nextElement()+"";
        if(db_element_hide.containsKey(key))continue;
        int[] arr = (int[])db_element.get(key);
        float x=0,y=0,z=0;
        for(int i=0; i<arr.length; i++){
          _Point p = (_Point)db_node.get(arr[i]+"");
          _Point pt = (_Point)db_node_tmp.get(arr[i]+"");
          x+=p.x+pt.x*kd;
          y+=p.y+pt.y*kd;
          z+=p.z+pt.z*kd;
        }
        x/=arr.length;
        y/=arr.length;
        z/=arr.length;
        J3D.add3D(new _OrientedText(key,x,y,z));
      }
    }
    //DISPLACEMENTS (I)
    if(cb_result.getSelectedIndex()==0){
      Hashtable db_node_tmp = (Hashtable)db_displacements.get(time);
      Hashtable db_stresses_tmp = (Hashtable)db_stresses.get(time);
      for(Enumeration en = db_stresses_tmp.keys(); en.hasMoreElements();){
        String key = en.nextElement()+"";
        if(db_element_hide.containsKey(key))continue;
        int[] arr = (int[])db_element.get(key);
        if(arr.length==2){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          J3D.add3D(new _Line(x1,y1,z1,x2,y2,z2,getGradient(0,(float)(Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z)+Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z))/2,maxdi)));
          J3D.add3D(new _Point(x1,y1,z1,getGradient(0,(float)Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z),maxdi)));
          J3D.add3D(new _Point(x2,y2,z2,getGradient(0,(float)Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z),maxdi)));
        }else if(arr.length==3){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          J3D.add3D(new _Triangle(x1,y1,z1,getGradient(0,(float)Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z),maxdi),
                                x2,y2,z2,getGradient(0,(float)Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z),maxdi),
                                x3,y3,z3,getGradient(0,(float)Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z),maxdi),
                                getGradient(0,(float)(Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z)+Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z)+Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z))/3,maxdi),Color.black));
        }else if(arr.length==4){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p14 = (_Point)db_node.get(arr[3]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          _Point p24 = (_Point)db_node_tmp.get(arr[3]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float x4=p14.x+p24.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float y4=p14.y+p24.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float z4=p14.z+p24.z*kd;
          J3D.add3D(new _Quad(x1,y1,z1,getGradient(0,(float)Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z),maxdi),
                            x2,y2,z2,getGradient(0,(float)Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z),maxdi),
                            x3,y3,z3,getGradient(0,(float)Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z),maxdi),
                            x4,y4,z4,getGradient(0,(float)Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z),maxdi),
                            getGradient(0,(float)(Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z)+Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z)+Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z)+Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z))/4,maxdi),Color.black));
        }else if(arr.length==8){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p14 = (_Point)db_node.get(arr[3]+"");
          _Point p15 = (_Point)db_node.get(arr[4]+"");
          _Point p16 = (_Point)db_node.get(arr[5]+"");
          _Point p17 = (_Point)db_node.get(arr[6]+"");
          _Point p18 = (_Point)db_node.get(arr[7]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          _Point p24 = (_Point)db_node_tmp.get(arr[3]+"");
          _Point p25 = (_Point)db_node_tmp.get(arr[4]+"");
          _Point p26 = (_Point)db_node_tmp.get(arr[5]+"");
          _Point p27 = (_Point)db_node_tmp.get(arr[6]+"");
          _Point p28 = (_Point)db_node_tmp.get(arr[7]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float x4=p14.x+p24.x*kd;
          float x5=p15.x+p25.x*kd;
          float x6=p16.x+p26.x*kd;
          float x7=p17.x+p27.x*kd;
          float x8=p18.x+p28.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float y4=p14.y+p24.y*kd;
          float y5=p15.y+p25.y*kd;
          float y6=p16.y+p26.y*kd;
          float y7=p17.y+p27.y*kd;
          float y8=p18.y+p28.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float z4=p14.z+p24.z*kd;
          float z5=p15.z+p25.z*kd;
          float z6=p16.z+p26.z*kd;
          float z7=p17.z+p27.z*kd;
          float z8=p18.z+p28.z*kd;
          J3D.add3D(new _Quad(x1,y1,z1,getGradient(0,(float)Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z),maxdi),
                            x2,y2,z2,getGradient(0,(float)Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z),maxdi),
                            x3,y3,z3,getGradient(0,(float)Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z),maxdi),
                            x4,y4,z4,getGradient(0,(float)Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z),maxdi),
                            getGradient(0,(float)(Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z)+Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z)+Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z)+Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z))/4,maxdi),Color.black));
          J3D.add3D(new _Quad(x5,y5,z5,getGradient(0,(float)Math.sqrt(p25.x*p25.x+p25.y*p25.y+p25.z*p25.z),maxdi),
                            x6,y6,z6,getGradient(0,(float)Math.sqrt(p26.x*p26.x+p26.y*p26.y+p26.z*p26.z),maxdi),
                            x7,y7,z7,getGradient(0,(float)Math.sqrt(p27.x*p27.x+p27.y*p27.y+p27.z*p27.z),maxdi),
                            x8,y8,z8,getGradient(0,(float)Math.sqrt(p28.x*p28.x+p28.y*p28.y+p28.z*p28.z),maxdi),
                            getGradient(0,(float)(Math.sqrt(p25.x*p25.x+p25.y*p25.y+p25.z*p25.z)+Math.sqrt(p26.x*p26.x+p26.y*p26.y+p26.z*p26.z)+Math.sqrt(p27.x*p27.x+p27.y*p27.y+p27.z*p27.z)+Math.sqrt(p28.x*p28.x+p28.y*p28.y+p28.z*p28.z))/4,maxdi),Color.black));
          J3D.add3D(new _Quad(x1,y1,z1,getGradient(0,(float)Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z),maxdi),
                            x2,y2,z2,getGradient(0,(float)Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z),maxdi),
                            x6,y6,z6,getGradient(0,(float)Math.sqrt(p26.x*p26.x+p26.y*p26.y+p26.z*p26.z),maxdi),
                            x5,y5,z5,getGradient(0,(float)Math.sqrt(p25.x*p25.x+p25.y*p25.y+p25.z*p25.z),maxdi),
                            getGradient(0,(float)(Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z)+Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z)+Math.sqrt(p26.x*p26.x+p26.y*p26.y+p26.z*p26.z)+Math.sqrt(p25.x*p25.x+p25.y*p25.y+p25.z*p25.z))/4,maxdi),Color.black));
          J3D.add3D(new _Quad(x4,y4,z4,getGradient(0,(float)Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z),maxdi),
                            x3,y3,z3,getGradient(0,(float)Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z),maxdi),
                            x7,y7,z7,getGradient(0,(float)Math.sqrt(p27.x*p27.x+p27.y*p27.y+p27.z*p27.z),maxdi),
                            x8,y8,z8,getGradient(0,(float)Math.sqrt(p28.x*p28.x+p28.y*p28.y+p28.z*p28.z),maxdi),
                            getGradient(0,(float)(Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z)+Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z)+Math.sqrt(p27.x*p27.x+p27.y*p27.y+p27.z*p27.z)+Math.sqrt(p28.x*p28.x+p28.y*p28.y+p28.z*p28.z))/4,maxdi),Color.black));
          J3D.add3D(new _Quad(x2,y2,z2,getGradient(0,(float)Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z),maxdi),
                            x3,y3,z3,getGradient(0,(float)Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z),maxdi),
                            x7,y7,z7,getGradient(0,(float)Math.sqrt(p27.x*p27.x+p27.y*p27.y+p27.z*p27.z),maxdi),
                            x6,y6,z6,getGradient(0,(float)Math.sqrt(p26.x*p26.x+p26.y*p26.y+p26.z*p26.z),maxdi),
                            getGradient(0,(float)(Math.sqrt(p22.x*p22.x+p22.y*p22.y+p22.z*p22.z)+Math.sqrt(p23.x*p23.x+p23.y*p23.y+p23.z*p23.z)+Math.sqrt(p27.x*p27.x+p27.y*p27.y+p27.z*p27.z)+Math.sqrt(p26.x*p26.x+p26.y*p26.y+p26.z*p26.z))/4,maxdi),Color.black));
          J3D.add3D(new _Quad(x1,y1,z1,getGradient(0,(float)Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z),maxdi),
                            x4,y4,z4,getGradient(0,(float)Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z),maxdi),
                            x8,y8,z8,getGradient(0,(float)Math.sqrt(p28.x*p28.x+p28.y*p28.y+p28.z*p28.z),maxdi),
                            x5,y5,z5,getGradient(0,(float)Math.sqrt(p25.x*p25.x+p25.y*p25.y+p25.z*p25.z),maxdi),
                            getGradient(0,(float)(Math.sqrt(p21.x*p21.x+p21.y*p21.y+p21.z*p21.z)+Math.sqrt(p24.x*p24.x+p24.y*p24.y+p24.z*p24.z)+Math.sqrt(p28.x*p28.x+p28.y*p28.y+p28.z*p28.z)+Math.sqrt(p25.x*p25.x+p25.y*p25.y+p25.z*p25.z))/4,maxdi),Color.black));
        }
      }
    //STRAINS
    }else if(cb_result.getSelectedIndex()==4){
      Hashtable db_node_tmp = (Hashtable)db_displacements.get(time);
      Hashtable db_strains_tmp = (Hashtable)db_strains.get(time);
      for(Enumeration en = db_strains_tmp.keys(); en.hasMoreElements();){
        String key = en.nextElement()+"";
        if(db_element_hide.containsKey(key))continue;
        int[] arr = (int[])db_element.get(key);
        if(arr.length==2){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float[] ee = (float[])db_strains_tmp.get(key);
          J3D.add3D(new _Line(x1,y1,z1,x2,y2,z2,getGradient(0,ee[0],maxei)));
        }else if(arr.length==3){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float[] ee = (float[])db_strains_tmp.get(key);
          J3D.add3D(new _Triangle(x1,y1,z1,x2,y2,z2,x3,y3,z3,getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+1.5*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5]))),maxei),Color.black));
        }else if(arr.length==4){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p14 = (_Point)db_node.get(arr[3]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          _Point p24 = (_Point)db_node_tmp.get(arr[3]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float x4=p14.x+p24.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float y4=p14.y+p24.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float z4=p14.z+p24.z*kd;
          float[] ee = (float[])db_strains_tmp.get(key);
          J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,this.getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+1.5*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5]))),maxei),Color.black));
        }else if(arr.length==8){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p14 = (_Point)db_node.get(arr[3]+"");
          _Point p15 = (_Point)db_node.get(arr[4]+"");
          _Point p16 = (_Point)db_node.get(arr[5]+"");
          _Point p17 = (_Point)db_node.get(arr[6]+"");
          _Point p18 = (_Point)db_node.get(arr[7]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          _Point p24 = (_Point)db_node_tmp.get(arr[3]+"");
          _Point p25 = (_Point)db_node_tmp.get(arr[4]+"");
          _Point p26 = (_Point)db_node_tmp.get(arr[5]+"");
          _Point p27 = (_Point)db_node_tmp.get(arr[6]+"");
          _Point p28 = (_Point)db_node_tmp.get(arr[7]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float x4=p14.x+p24.x*kd;
          float x5=p15.x+p25.x*kd;
          float x6=p16.x+p26.x*kd;
          float x7=p17.x+p27.x*kd;
          float x8=p18.x+p28.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float y4=p14.y+p24.y*kd;
          float y5=p15.y+p25.y*kd;
          float y6=p16.y+p26.y*kd;
          float y7=p17.y+p27.y*kd;
          float y8=p18.y+p28.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float z4=p14.z+p24.z*kd;
          float z5=p15.z+p25.z*kd;
          float z6=p16.z+p26.z*kd;
          float z7=p17.z+p27.z*kd;
          float z8=p18.z+p28.z*kd;
          float[] ee = (float[])db_strains_tmp.get(key);
          if(ee.length==6){
            float ss = (float)(Math.sqrt(2)/3*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+1.5*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5])));
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,this.getGradient(0,ss,maxei),Color.black));
            J3D.add3D(new _Quad(x5,y5,z5,x6,y6,z6,x7,y7,z7,x8,y8,z8,this.getGradient(0,ss,maxei),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x6,y6,z6,x5,y5,z5,this.getGradient(0,ss,maxei),Color.black));
            J3D.add3D(new _Quad(x4,y4,z4,x3,y3,z3,x7,y7,z7,x8,y8,z8,this.getGradient(0,ss,maxei),Color.black));
            J3D.add3D(new _Quad(x2,y2,z2,x3,y3,z3,x7,y7,z7,x6,y6,z6,this.getGradient(0,ss,maxei),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x4,y4,z4,x8,y8,z8,x5,y5,z5,this.getGradient(0,ss,maxei),Color.black));
          }else{
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,this.getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow((ee[0]+ee[6]+ee[12]+ee[18])/4-(ee[1]+ee[7]+ee[13]+ee[19])/4,2)+Math.pow((ee[1]+ee[7]+ee[13]+ee[19])/4-(ee[2]+ee[8]+ee[14]+ee[20])/4,2)+Math.pow((ee[2]+ee[8]+ee[14]+ee[20])/4-(ee[0]+ee[6]+ee[12]+ee[18])/4,2)+1.5*((ee[3]+ee[9]+ee[15]+ee[21])/4*(ee[3]+ee[9]+ee[15]+ee[21])/4+(ee[4]+ee[10]+ee[16]+ee[22])/4*(ee[4]+ee[10]+ee[16]+ee[22])/4+(ee[5]+ee[11]+ee[17]+ee[23])/4*(ee[5]+ee[11]+ee[17]+ee[23])/4))),maxei),Color.black));
            J3D.add3D(new _Quad(x5,y5,z5,x6,y6,z6,x7,y7,z7,x8,y8,z8,this.getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow((ee[24]+ee[30]+ee[36]+ee[42])/4-(ee[25]+ee[31]+ee[37]+ee[43])/4,2)+Math.pow((ee[25]+ee[31]+ee[37]+ee[43])/4-(ee[26]+ee[32]+ee[38]+ee[44])/4,2)+Math.pow((ee[26]+ee[32]+ee[38]+ee[44])/4-(ee[24]+ee[30]+ee[36]+ee[42])/4,2)+1.5*((ee[27]+ee[33]+ee[39]+ee[45])/4*(ee[27]+ee[33]+ee[39]+ee[45])/4+(ee[28]+ee[34]+ee[40]+ee[46])/4*(ee[28]+ee[34]+ee[40]+ee[46])/4+(ee[29]+ee[35]+ee[41]+ee[47])/4*(ee[29]+ee[35]+ee[41]+ee[47])/4))),maxei),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x6,y6,z6,x5,y5,z5,this.getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow((ee[0]+ee[6]+ee[30]+ee[24])/4-(ee[1]+ee[7]+ee[31]+ee[25])/4,2)+Math.pow((ee[1]+ee[7]+ee[31]+ee[25])/4-(ee[2]+ee[8]+ee[32]+ee[26])/4,2)+Math.pow((ee[2]+ee[8]+ee[32]+ee[26])/4-(ee[0]+ee[6]+ee[30]+ee[24])/4,2)+1.5*((ee[3]+ee[9]+ee[33]+ee[27])/4*(ee[3]+ee[9]+ee[33]+ee[27])/4+(ee[4]+ee[10]+ee[34]+ee[28])/4*(ee[4]+ee[10]+ee[34]+ee[28])/4+(ee[5]+ee[11]+ee[35]+ee[29])/4*(ee[5]+ee[11]+ee[35]+ee[29])/4))),maxei),Color.black));
            J3D.add3D(new _Quad(x4,y4,z4,x3,y3,z3,x7,y7,z7,x8,y8,z8,this.getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow((ee[18]+ee[12]+ee[36]+ee[42])/4-(ee[19]+ee[13]+ee[37]+ee[43])/4,2)+Math.pow((ee[19]+ee[13]+ee[37]+ee[43])/4-(ee[20]+ee[14]+ee[38]+ee[44])/4,2)+Math.pow((ee[20]+ee[14]+ee[38]+ee[44])/4-(ee[18]+ee[12]+ee[36]+ee[42])/4,2)+1.5*((ee[21]+ee[15]+ee[39]+ee[45])/4*(ee[21]+ee[15]+ee[39]+ee[45])/4+(ee[22]+ee[16]+ee[40]+ee[46])/4*(ee[22]+ee[16]+ee[40]+ee[46])/4+(ee[23]+ee[17]+ee[41]+ee[47])/4*(ee[23]+ee[17]+ee[41]+ee[47])/4))),maxei),Color.black));
            J3D.add3D(new _Quad(x2,y2,z2,x3,y3,z3,x7,y7,z7,x6,y6,z6,this.getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow((ee[6]+ee[12]+ee[30]+ee[36])/4-(ee[7]+ee[13]+ee[31]+ee[37])/4,2)+Math.pow((ee[7]+ee[13]+ee[31]+ee[37])/4-(ee[8]+ee[14]+ee[32]+ee[38])/4,2)+Math.pow((ee[8]+ee[14]+ee[32]+ee[38])/4-(ee[6]+ee[12]+ee[30]+ee[36])/4,2)+1.5*((ee[9]+ee[15]+ee[33]+ee[39])/4*(ee[9]+ee[15]+ee[33]+ee[39])/4+(ee[10]+ee[16]+ee[34]+ee[40])/4*(ee[10]+ee[16]+ee[34]+ee[40])/4+(ee[11]+ee[17]+ee[35]+ee[41])/4*(ee[11]+ee[17]+ee[35]+ee[41])/4))),maxei),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x4,y4,z4,x8,y8,z8,x5,y5,z5,this.getGradient(0,(float)(Math.sqrt(2)/3*Math.sqrt(Math.pow((ee[0]+ee[18]+ee[24]+ee[42])/4-(ee[1]+ee[19]+ee[25]+ee[43])/4,2)+Math.pow((ee[1]+ee[19]+ee[25]+ee[43])/4-(ee[2]+ee[20]+ee[26]+ee[44])/4,2)+Math.pow((ee[2]+ee[20]+ee[26]+ee[44])/4-(ee[0]+ee[18]+ee[24]+ee[42])/4,2)+1.5*((ee[3]+ee[21]+ee[27]+ee[45])/4*(ee[3]+ee[21]+ee[27]+ee[45])/4+(ee[4]+ee[22]+ee[28]+ee[46])/4*(ee[4]+ee[22]+ee[28]+ee[46])/4+(ee[5]+ee[23]+ee[29]+ee[47])/4*(ee[5]+ee[23]+ee[29]+ee[47])/4))),maxei),Color.black));
          }
        }
      }
    //STRESSES
    }else if(cb_result.getSelectedIndex()==11){
      Hashtable db_node_tmp = (Hashtable)db_displacements.get(time);
      Hashtable db_stresses_tmp = (Hashtable)db_stresses.get(time);
      for(Enumeration en = db_stresses_tmp.keys(); en.hasMoreElements();){
        String key = en.nextElement()+"";
        if(db_element_hide.containsKey(key))continue;
        int[] arr = (int[])db_element.get(key);
        if(arr.length==2){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float[] ee = (float[])db_stresses_tmp.get(key);
          J3D.add3D(new _Line(x1,y1,z1,x2,y2,z2,getGradient(0,ee[0],maxsi)));
        }else if(arr.length==3){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float[] ee = (float[])db_stresses_tmp.get(key);
          J3D.add3D(new _Triangle(x1,y1,z1,x2,y2,z2,x3,y3,z3,getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+6*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5]))),maxsi),Color.black));
        }else if(arr.length==4){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p14 = (_Point)db_node.get(arr[3]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          _Point p24 = (_Point)db_node_tmp.get(arr[3]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float x4=p14.x+p24.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float y4=p14.y+p24.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float z4=p14.z+p24.z*kd;
          float[] ee = (float[])db_stresses_tmp.get(key);
          J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,this.getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+6*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5]))),maxsi),Color.black));
        }else if(arr.length==8){
          _Point p11 = (_Point)db_node.get(arr[0]+"");
          _Point p12 = (_Point)db_node.get(arr[1]+"");
          _Point p13 = (_Point)db_node.get(arr[2]+"");
          _Point p14 = (_Point)db_node.get(arr[3]+"");
          _Point p15 = (_Point)db_node.get(arr[4]+"");
          _Point p16 = (_Point)db_node.get(arr[5]+"");
          _Point p17 = (_Point)db_node.get(arr[6]+"");
          _Point p18 = (_Point)db_node.get(arr[7]+"");
          _Point p21 = (_Point)db_node_tmp.get(arr[0]+"");
          _Point p22 = (_Point)db_node_tmp.get(arr[1]+"");
          _Point p23 = (_Point)db_node_tmp.get(arr[2]+"");
          _Point p24 = (_Point)db_node_tmp.get(arr[3]+"");
          _Point p25 = (_Point)db_node_tmp.get(arr[4]+"");
          _Point p26 = (_Point)db_node_tmp.get(arr[5]+"");
          _Point p27 = (_Point)db_node_tmp.get(arr[6]+"");
          _Point p28 = (_Point)db_node_tmp.get(arr[7]+"");
          float x1=p11.x+p21.x*kd;
          float x2=p12.x+p22.x*kd;
          float x3=p13.x+p23.x*kd;
          float x4=p14.x+p24.x*kd;
          float x5=p15.x+p25.x*kd;
          float x6=p16.x+p26.x*kd;
          float x7=p17.x+p27.x*kd;
          float x8=p18.x+p28.x*kd;
          float y1=p11.y+p21.y*kd;
          float y2=p12.y+p22.y*kd;
          float y3=p13.y+p23.y*kd;
          float y4=p14.y+p24.y*kd;
          float y5=p15.y+p25.y*kd;
          float y6=p16.y+p26.y*kd;
          float y7=p17.y+p27.y*kd;
          float y8=p18.y+p28.y*kd;
          float z1=p11.z+p21.z*kd;
          float z2=p12.z+p22.z*kd;
          float z3=p13.z+p23.z*kd;
          float z4=p14.z+p24.z*kd;
          float z5=p15.z+p25.z*kd;
          float z6=p16.z+p26.z*kd;
          float z7=p17.z+p27.z*kd;
          float z8=p18.z+p28.z*kd;
          float[] ee = (float[])db_stresses_tmp.get(key);
          if(ee.length==6){
            float ss = (float)(Math.sqrt(2)/2*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+6*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5])));
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,this.getGradient(0,ss,maxsi),Color.black));
            J3D.add3D(new _Quad(x5,y5,z5,x6,y6,z6,x7,y7,z7,x8,y8,z8,this.getGradient(0,ss,maxsi),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x6,y6,z6,x5,y5,z5,this.getGradient(0,ss,maxsi),Color.black));
            J3D.add3D(new _Quad(x4,y4,z4,x3,y3,z3,x7,y7,z7,x8,y8,z8,this.getGradient(0,ss,maxsi),Color.black));
            J3D.add3D(new _Quad(x2,y2,z2,x3,y3,z3,x7,y7,z7,x6,y6,z6,this.getGradient(0,ss,maxsi),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x4,y4,z4,x8,y8,z8,x5,y5,z5,this.getGradient(0,ss,maxsi),Color.black));
          }else{
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,this.getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow((ee[0]+ee[6]+ee[12]+ee[18])/4-(ee[1]+ee[7]+ee[13]+ee[19])/4,2)+Math.pow((ee[1]+ee[7]+ee[13]+ee[19])/4-(ee[2]+ee[8]+ee[14]+ee[20])/4,2)+Math.pow((ee[2]+ee[8]+ee[14]+ee[20])/4-(ee[0]+ee[6]+ee[12]+ee[18])/4,2)+6*((ee[3]+ee[9]+ee[15]+ee[21])/4*(ee[3]+ee[9]+ee[15]+ee[21])/4+(ee[4]+ee[10]+ee[16]+ee[22])/4*(ee[4]+ee[10]+ee[16]+ee[22])/4+(ee[5]+ee[11]+ee[17]+ee[23])/4*(ee[5]+ee[11]+ee[17]+ee[23])/4))),maxsi),Color.black));
            J3D.add3D(new _Quad(x5,y5,z5,x6,y6,z6,x7,y7,z7,x8,y8,z8,this.getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow((ee[24]+ee[30]+ee[36]+ee[42])/4-(ee[25]+ee[31]+ee[37]+ee[43])/4,2)+Math.pow((ee[25]+ee[31]+ee[37]+ee[43])/4-(ee[26]+ee[32]+ee[38]+ee[44])/4,2)+Math.pow((ee[26]+ee[32]+ee[38]+ee[44])/4-(ee[24]+ee[30]+ee[36]+ee[42])/4,2)+6*((ee[27]+ee[33]+ee[39]+ee[45])/4*(ee[27]+ee[33]+ee[39]+ee[45])/4+(ee[28]+ee[34]+ee[40]+ee[46])/4*(ee[28]+ee[34]+ee[40]+ee[46])/4+(ee[29]+ee[35]+ee[41]+ee[47])/4*(ee[29]+ee[35]+ee[41]+ee[47])/4))),maxsi),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x2,y2,z2,x6,y6,z6,x5,y5,z5,this.getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow((ee[0]+ee[6]+ee[30]+ee[24])/4-(ee[1]+ee[7]+ee[31]+ee[25])/4,2)+Math.pow((ee[1]+ee[7]+ee[31]+ee[25])/4-(ee[2]+ee[8]+ee[32]+ee[26])/4,2)+Math.pow((ee[2]+ee[8]+ee[32]+ee[26])/4-(ee[0]+ee[6]+ee[30]+ee[24])/4,2)+6*((ee[3]+ee[9]+ee[33]+ee[27])/4*(ee[3]+ee[9]+ee[33]+ee[27])/4+(ee[4]+ee[10]+ee[34]+ee[28])/4*(ee[4]+ee[10]+ee[34]+ee[28])/4+(ee[5]+ee[11]+ee[35]+ee[29])/4*(ee[5]+ee[11]+ee[35]+ee[29])/4))),maxsi),Color.black));
            J3D.add3D(new _Quad(x4,y4,z4,x3,y3,z3,x7,y7,z7,x8,y8,z8,this.getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow((ee[18]+ee[12]+ee[36]+ee[42])/4-(ee[19]+ee[13]+ee[37]+ee[43])/4,2)+Math.pow((ee[19]+ee[13]+ee[37]+ee[43])/4-(ee[20]+ee[14]+ee[38]+ee[44])/4,2)+Math.pow((ee[20]+ee[14]+ee[38]+ee[44])/4-(ee[18]+ee[12]+ee[36]+ee[42])/4,2)+6*((ee[21]+ee[15]+ee[39]+ee[45])/4*(ee[21]+ee[15]+ee[39]+ee[45])/4+(ee[22]+ee[16]+ee[40]+ee[46])/4*(ee[22]+ee[16]+ee[40]+ee[46])/4+(ee[23]+ee[17]+ee[41]+ee[47])/4*(ee[23]+ee[17]+ee[41]+ee[47])/4))),maxsi),Color.black));
            J3D.add3D(new _Quad(x2,y2,z2,x3,y3,z3,x7,y7,z7,x6,y6,z6,this.getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow((ee[6]+ee[12]+ee[30]+ee[36])/4-(ee[7]+ee[13]+ee[31]+ee[37])/4,2)+Math.pow((ee[7]+ee[13]+ee[31]+ee[37])/4-(ee[8]+ee[14]+ee[32]+ee[38])/4,2)+Math.pow((ee[8]+ee[14]+ee[32]+ee[38])/4-(ee[6]+ee[12]+ee[30]+ee[36])/4,2)+6*((ee[9]+ee[15]+ee[33]+ee[39])/4*(ee[9]+ee[15]+ee[33]+ee[39])/4+(ee[10]+ee[16]+ee[34]+ee[40])/4*(ee[10]+ee[16]+ee[34]+ee[40])/4+(ee[11]+ee[17]+ee[35]+ee[41])/4*(ee[11]+ee[17]+ee[35]+ee[41])/4))),maxsi),Color.black));
            J3D.add3D(new _Quad(x1,y1,z1,x4,y4,z4,x8,y8,z8,x5,y5,z5,this.getGradient(0,(float)(Math.sqrt(2)/2*Math.sqrt(Math.pow((ee[0]+ee[18]+ee[24]+ee[42])/4-(ee[1]+ee[19]+ee[25]+ee[43])/4,2)+Math.pow((ee[1]+ee[19]+ee[25]+ee[43])/4-(ee[2]+ee[20]+ee[26]+ee[44])/4,2)+Math.pow((ee[2]+ee[20]+ee[26]+ee[44])/4-(ee[0]+ee[18]+ee[24]+ee[42])/4,2)+6*((ee[3]+ee[21]+ee[27]+ee[45])/4*(ee[3]+ee[21]+ee[27]+ee[45])/4+(ee[4]+ee[22]+ee[28]+ee[46])/4*(ee[4]+ee[22]+ee[28]+ee[46])/4+(ee[5]+ee[23]+ee[29]+ee[47])/4*(ee[5]+ee[23]+ee[29]+ee[47])/4))),maxsi),Color.black));
          }
        }
      }
    }
    if(cb_gradientresult.isSelected()){
      BufferedImage image = (BufferedImage)createImage(130,230);
      Graphics g = image.getGraphics();
      float min = 0;
      float max = 0;
      if(cb_result.getSelectedIndex()==0){max=maxdi; min=0;}
      else if(cb_result.getSelectedIndex()==4){max=maxei; min=0;}
      else if(cb_result.getSelectedIndex()==11){max=maxsi; min=0;}
      g.setColor(Color.white);
      g.fillRect(0,0,image.getWidth(),image.getHeight());
      g.setColor(Color.black);
      g.drawRect(0,0,image.getWidth()-1,image.getHeight()-1);
      g.drawString(cb_result.getSelectedItem()+"",5,15);
      for(int i=0; i<17; i++){
        g.setColor(getGradient(min,(max-min)/17*i,max));
        g.fillRect(5,i*12+25,7,7);
        g.setColor(Color.black);
        g.drawString(""+max/17*i,16,i*12+8+25);
      }
      J3D.add3D(new _BgImage(image,J3D.getWidth()-150,20));
    }
    J3D.view_repaint();
  }
  public static Frame getFrame(Component component){
    for(; component != null && !(component instanceof Frame); component = component.getParent());
    return (Frame)component;
  }
  void b_open_actionPerformed(ActionEvent e) {
    try {
      FileDialog fd = new FileDialog(getFrame(this),"Open result",FileDialog.LOAD);
      fd.setDirectory(".");
      fd.setFile("*.res");
      fd.show();
      project=fd.getDirectory()+fd.getFile();
      if(fd.getFile()!=null){
        load(project);
      }
    } catch(Exception e1) {error(e1);}
  }


  void db_graph_preparation(int Y, String nd_el) {
      String info=null;
      String[][] arr = new String[time_step.getModel().getSize()][2];
      switch(Y){
        case 0://DISPLACEMENTS (I)
        info="#The results are from node: "+nd_el+"\n#X: time   Y: displacement in direction (I)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_displacements.get(arr[i][0]);
          _Point p3d = (_Point)ht.get(nd_el);
          arr[i][1]=Math.sqrt(p3d.x*p3d.x+p3d.y*p3d.y+p3d.z*p3d.z)+"";
        }
        break;
        case 1://DISPLACEMENTS (X)
        info="#The results are from node: "+nd_el+"\n#X: time   Y: displacement in direction (X)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_displacements.get(arr[i][0]);
          _Point p3d = (_Point)ht.get(nd_el);
          arr[i][1]=p3d.x+"";
        }
        break;
        case 2://DISPLACEMENTS (Y)
        info="#The results are from node: "+nd_el+"\n#X: time   Y: displacement in direction (Y)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_displacements.get(arr[i][0]);
          _Point p3d = (_Point)ht.get(nd_el);
          arr[i][1]=p3d.y+"";
        }
        break;
        case 3://DISPLACEMENTS (Z)
        info="#The results are from node: "+nd_el+"\n#X: time   Y: displacement in direction (Z)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_displacements.get(arr[i][0]);
          _Point p3d = (_Point)ht.get(nd_el);
          arr[i][1]=p3d.z+"";
        }
        break;
        case 4://STRAINS (I)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: strain in direction (I)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_strains.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{
            arr[i][1]=(Math.sqrt(2)/3*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+1.5*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5])))+"";
          }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 5://STRAINS (X)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: strain in direction (X)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_strains.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[0]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 6://STRAINS (Y)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: strain in direction (Y)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_strains.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[1]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 7://STRAINS (Z)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: strain in direction (Z)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_strains.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[2]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 8://STRAINS (XY)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: strain in direction (XY)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_strains.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[3]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 9://STRAINS (YZ)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: strain in direction (YZ)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_strains.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[4]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 10://STRAINS (XZ)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: strain in direction (XZ)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_strains.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[5]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 11://STRESSES (I)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: stress in direction (I)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_stresses.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{
            arr[i][1]=(Math.sqrt(2)/2*Math.sqrt(Math.pow(ee[0]-ee[1],2)+Math.pow(ee[1]-ee[2],2)+Math.pow(ee[2]-ee[0],2)+6*(ee[3]*ee[3]+ee[4]*ee[4]+ee[5]*ee[5])))+"";
          }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 12://STRESSES (X)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: stress in direction (X)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_stresses.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[0]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 13://STRESSES (Y)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: stress in direction (Y)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_stresses.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[1]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 14://STRESSES (Z)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: stress in direction (Z)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_stresses.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[2]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 15://STRESSES (XY)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: stress in direction (XY)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_stresses.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[3]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 16://STRESSES (YZ)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: stress in direction (YZ)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_stresses.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[4]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        case 17://STRESSES (XZ)
        info="#The results are from element: "+nd_el+"\n#X: time   Y: stress in direction (XZ)";
        for(int i=0; i<arr.length; i++){
          arr[i][0]=time_step.getModel().getElementAt(i)+"";
          Hashtable ht = (Hashtable)db_stresses.get(arr[i][0]);
          float[] ee = (float[])ht.get(nd_el);
          try{ arr[i][1]=ee[5]+""; }catch(Exception e1){arr[i][1]="";}
        }
        break;
        default: break;
      }
      db_graph_tmp=arr;
      db_graph_inf=info;
  }


  void b_save_actionPerformed(ActionEvent e) {
    try {
      FileDialog fd = new FileDialog(getFrame(this),"Save Image",FileDialog.SAVE);
      fd.setDirectory(".");
      fd.setFile("*.jpg");
      fd.show();
      if(fd.getFile()!=null){
        System.out.println("Save Image: "+fd.getDirectory()+fd.getFile());
        J3D.save_Image(fd.getDirectory()+fd.getFile());
      }
    } catch(Exception e1) {error(e1);}
  }
  void time_step_valueChanged(ListSelectionEvent e) {

  }

  void b_zoomin_actionPerformed(ActionEvent e) {
    J3D.view_scale(1.2f);
  }

  void b_zoomout_actionPerformed(ActionEvent e) {
    J3D.view_scale(0.8f);
  }

  void b_viewtop_actionPerformed(ActionEvent e) {
    J3D.view_top();
  }

  void b_viewbottom_actionPerformed(ActionEvent e) {
    J3D.view_bottom();
  }

  void b_viewsw_actionPerformed(ActionEvent e) {
    J3D.view_sw();
  }

  void b_viewse_actionPerformed(ActionEvent e) {
    J3D.view_se();
  }

  void b_viewne_actionPerformed(ActionEvent e) {
    J3D.view_ne();
  }

  void b_viewnw_actionPerformed(ActionEvent e) {
    J3D.view_nw();
  }

  void b_viewleft_actionPerformed(ActionEvent e) {
    J3D.view_left();
  }

  void b_viewright_actionPerformed(ActionEvent e) {
    J3D.view_right();
  }

  void b_viewfront_actionPerformed(ActionEvent e) {
    J3D.view_front();
  }

  void b_viewback_actionPerformed(ActionEvent e) {
    J3D.view_back();
  }

  void b_saveall_actionPerformed(ActionEvent e) {
    try{
      String file = JOptionPane.showInputDialog(null,"Save all as:","Save all",JOptionPane.PLAIN_MESSAGE);
      if(file==null)return;
      File f = new File(file);
      if(f.exists()){
        error("File '"+file+"' exists!");
        return;
      }
      f.mkdir();
      for(int i=0; i<time_step.getModel().getSize(); i++){
        time_step.setSelectedIndex(i);
        message("Save result to image: "+file+File.separator+time_step.getSelectedValue()+".jpg");
        J3D.save_Image(file+File.separator+time_step.getSelectedValue());
      }
      message(ver+"   "+project);
    } catch(Exception e1) {error(e1);}
  }

  void b_elements_actionPerformed(ActionEvent e) {
    JPanel p = new JPanel(new GridLayout(1,2));
    JPanel p1 = new JPanel(new BorderLayout());
    JPanel p2 = new JPanel(new BorderLayout());
    p.add(p1);
    p.add(p2);
    p1.add(new JLabel("Show"),BorderLayout.NORTH);
    p2.add(new JLabel("Hide"),BorderLayout.NORTH);
    JScrollPane sp1 = new JScrollPane();
    JScrollPane sp2 = new JScrollPane();
    sp1.getViewport().add(Show_list);
    sp2.getViewport().add(Hide_list);
    JButton showadd = new JButton("<<<");
    showadd.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        int[] ind = Hide_list.getSelectedIndices();
        Object[] val = Hide_list.getSelectedValues();
        for(int i=0; i<ind.length; i++){
          model_show.addElement(val[i]);
        }
        for(int i=ind.length-1; i>-1; i--){
          model_hide.removeElementAt(ind[i]);
        }
      }
    });
    JButton hideadd = new JButton(">>>");
    hideadd.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        int[] ind = Show_list.getSelectedIndices();
        Object[] val = Show_list.getSelectedValues();
        for(int i=0; i<ind.length; i++){
          model_hide.addElement(val[i]);
        }
        for(int i=ind.length-1; i>-1; i--){
          model_show.removeElementAt(ind[i]);
        }
      }
    });
    p1.add(sp1,BorderLayout.CENTER);
    p2.add(sp2,BorderLayout.CENTER);
    p1.add(hideadd,BorderLayout.SOUTH);
    p2.add(showadd,BorderLayout.SOUTH);
    JOptionPane.showMessageDialog(this,p,"Elements show/hide",JOptionPane.PLAIN_MESSAGE,null);
  }
  public void sort(Vector v){
    for(int i=0; i<v.size(); i++){
      String st1 = v.elementAt(i)+"";
      for(int j=i; j<v.size(); j++){
        String st2 = v.elementAt(j)+"";
        if(st1.compareTo(st2)>1){
          v.setElementAt(st2,i);
          v.setElementAt(st1,j);
        }
      }
    }
  }

  public void exit(){
    System.out.println("PostProcessor finalize.");
  }


}
