/*
 * FullGui.java
 *
 * Created on February 16, 2008, 10:28 PM
 */


package ArchivesUI;
 
import com.Ostermiller.Syntax.*;
import FrequencyListPopulations.ReadFromTextFile;
import java.awt.Color;
import java.awt.event.*;
import java.awt.PopupMenu;
import javax.swing.*;
//Graph imports below
import java.io.*;
import org.jgraph.JGraph;
import org.jgraph.graph.*;
import org.jgraph.util.*;
import org.jgraph.*;
import java.awt.geom.*;
import java.awt.*;
import javax.swing.*;        
import org.jgrapht.graph.*;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.GraphConstants;
import java.awt.*;
import org.jgrapht.ListenableGraph;
import org.jgrapht.ext.JGraphModelAdapter;
import org.jgrapht.graph.ListenableDirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import java.awt.Color;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
import org.jgraph.JGraph;
import org.jgraph.graph.DefaultGraphCell;
import org.jgraph.graph.GraphConstants;
import ArchivesUI.Edge;
import ArchivesUI.Vert;
import org.jgrapht.ListenableGraph;
import org.jgrapht.ext.JGraphModelAdapter;
import org.jgrapht.graph.ListenableDirectedGraph;
import org.jgrapht.graph.DefaultEdge;

/**
 *
 * @author  Robin Hood
 */
public class FullGui extends javax.swing.JFrame {
    
    /** Creates new form FullGui */
    public FullGui() {
        initComponents();
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        unit_list = new java.awt.List();
        jSeparator1 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        tabs = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        /*
        * Uses Syntax Highlighting via HighlightedDocument class
        * as well as creates a MouseListener in order to obtain
        * selected text info based on a right click.
        *
        */
        LanguageSelection sel = new LanguageSelection();
        HighlightedDocument document = sel.getDocument();
        code_view = new javax.swing.JTextPane(document);
        jScrollPane3 = new javax.swing.JScrollPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel11 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        query_field4 = new javax.swing.JTextField();
        jButton7 = new javax.swing.JButton();
        jSeparator7 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        unit_data_text_area2 = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel10 = new javax.swing.JLabel();
        archives_menu_bar = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Hamlet -alpha-");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel5.setBackground(new java.awt.Color(255, 255, 153));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setText("Units");

        //for testing purposes

        /*
        for(int i = 0; i < 100; i++){
            unit_list.add("This is list number"+i);
        }
        * */
        unit_list.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                unit_listMouseClicked(evt);
            }
        });
        unit_list.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                unit_listActionPerformed(evt);
            }
        });

        jButton1.setText("Update Units");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(unit_list, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(2, 2, 2)
                .addComponent(unit_list, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        String defaultText = (
            "/**\n" +
            " * Simple common test program.\n" +
            " */\n" +
            "public class HelloWorld {\n" +
            "    public static void main(String[] args) {\n" +
            "        // Display the greeting.\n" +
            "        System.out.println(\"Hello World!\");\n" +
            "    }\n" +
            "}\n"
        );

        code_view.setText(defaultText);
        jScrollPane1.setViewportView(code_view);

        tabs.addTab("Code View", jScrollPane1);
        tabs.addTab("Full Graph View", jScrollPane3);
        tabs.addTab("Regional Graph View", jScrollPane2);

        jPanel11.setBackground(new java.awt.Color(153, 255, 153));

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setText("Query");

        jButton7.setText("Go!");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE))
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jButton7)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(query_field4, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(query_field4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel1)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel9.setBackground(new java.awt.Color(204, 255, 204));

        unit_data_text_area2.setColumns(20);
        unit_data_text_area2.setEditable(false);
        unit_data_text_area2.setRows(5);
        jScrollPane5.setViewportView(unit_data_text_area2);

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel9.setText("Unit Data");

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel9)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(213, 213, 213))
        );

        jLabel10.setFont(new java.awt.Font("Edwardian Script ITC", 1, 48));
        jLabel10.setText("Hamlet...");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabs, javax.swing.GroupLayout.PREFERRED_SIZE, 814, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tabs, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 726, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)))
                .addContainerGap())
        );

        jMenu1.setText("File");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Load Graph Data");
        jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem1MouseClicked(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        archives_menu_bar.add(jMenu1);

        jMenu2.setText("Edit");
        archives_menu_bar.add(jMenu2);

        jMenu3.setText("Tools");
        archives_menu_bar.add(jMenu3);

        setJMenuBar(archives_menu_bar);
        archives_menu_bar.add(sel.createStyleMenu());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleName("Hamlet");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void unit_listActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unit_listActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_unit_listActionPerformed

    private void unit_listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_unit_listMouseClicked
          
    //System.out.println(unit_list.getSelectedItem());
    unit_data_text_area2.setForeground(Color.RED);
    unit_data_text_area2.setText(unit_list.getSelectedItem());
        /*
        //creates a popup popup based on what you have selected
        
        JPopupMenu popup = new JPopupMenu();
        
        String test2 = "This is another test"; //longest text
        JMenuItem menuItem = new JMenuItem(unit_list.getSelectedItem());
        
        //CHECK FOR NULL STRINGS LATER IN CODE VIEW

        Integer unitListXLoc = (int)(unit_list.getAlignmentX());
        
        int popupStartingXLoc = test2.length();  //longest string
       // menuItem.setBounds(unitListXLoc, evt.getY(), 50, 50);
        //menuItem.addActionListener(equal_to);
   
        popup.add(menuItem);
         
        //shows the popup popup to the left of the units list (notice the x loc)
        
        popup.show(evt.getComponent(), unitListXLoc-(test2.length()*5)-38, evt.getY());    
       
      
        update_units_button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                update_units_buttonActionPerformed(evt);
            }
        });
        
        */
        
    }//GEN-LAST:event_unit_listMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try{
            showGraph();
        }
        catch(Exception e){
            System.out.println("the following error occured/n"+e.toString());
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        unit_list.removeAll();
        unit_list.add(code_view.getText());
    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        try{
            if(query_field4.getText().compareToIgnoreCase("")==0){
                jLabel1.setText("Please Enter a Term");
            }
            else{
                currentNode = query_field4.getText();
                jLabel1.setText("Looking for "+currentNode);
                
                
                showDetail();
            }
        }
        catch(Exception e){
            System.out.println("the following error occured/n"+e.toString());
        }
       
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jMenuItem1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem1MouseClicked
        try{
            showGraph();
        }
        catch(Exception e){
            System.out.println("the following error occured/n"+e.toString());
        }
    }//GEN-LAST:event_jMenuItem1MouseClicked
    
    /**
     * Code to position verts
     * @param vertex object to be positioned
     * @param x x coordinate
     * @param y y coordinate
     */
        
    private void positionVertexAt( Object vertex, int x, int y, int w, int h) {
        DefaultGraphCell cell = m_jgAdapter.getVertexCell( vertex );
        Map              attr = cell.getAttributes(  );
        Rectangle2D  b  = GraphConstants.getBounds(attr);
        GraphConstants.setBounds( attr, new Rectangle( x, y ,w,h));
        Map cellAttr = new HashMap(  );
        cellAttr.put( cell, attr );
        jScrollPane3.repaint();
        
    }
    
    public void showDetail(){
        ArrayList<Edge> edges2 = new ArrayList<Edge>();
        ArrayList<Vert> vertArr2 = new ArrayList<Vert>();
        int ver = -1;
        for(int z=0;z<vertArr.size();z++){
           if(vertArr.get(z).getName().compareToIgnoreCase(currentNode)==0){
               ver = z;
               vertArr2.add(vertArr.get(ver));
           }
        }
        
        for(int z=0;z<edges.size();z++){
            //System.out.println("destination -->"+edges.get(z).getDest()+"  edges 2 loop iterator--> "+z+" source--> "+edges.get(z).getSource());
            if(edges.get(z).getDest()== ver){ 
                edges2.add(edges.get(z));
                vertArr2.add( vertArr.get(edges.get(z).getSource()));
                
            }
            else if(edges.get(z).getSource()== ver){
                edges2.add(edges.get(z));
                vertArr2.add( vertArr.get(edges.get(z).getDest()));
            }
            
        }
        
        
         ListenableGraph g2 = new ListenableDirectedGraph( DefaultEdge.class );

        // create a visualization using JGraph, via an adapter
       
        m_jgAdapter = new JGraphModelAdapter( g2 );

        JGraph jgraph2 = new JGraph( m_jgAdapter );
        
        // add sample data 
        for(int x=0;x<vertArr2.size();x++){
            
            g2.addVertex( vertArr2.get(x) ); 
        }
        
        for(int y=0;y<edges2.size();y++){
           
           Edge tmp = edges2.get(y); 
           g2.addEdge(vertArr.get(tmp.getSource()), vertArr.get(tmp.getDest()));
        }

        // position vertices nicely within JGraph component
      
        Random rand2 = new Random();
        int hpos2, vpos2;
        /**
        //display in seperate tab
        for(int x =0;x<vertArr2.size();x++){
            
            hpos2 = rand2.nextInt(jScrollPane2.getWidth());
            vpos2 = rand2.nextInt(jScrollPane2.getHeight());
            positionVertexAt( vertArr2.get(x),hpos2, vpos2,vertArr2.get(x).getName().length()*8,25 );
        
        }
        jScrollPane2.getViewport().add(jgraph2);
        */
        
        //to display on main form in side
        for(int x =0;x<vertArr2.size();x++){
            
            hpos2 = rand2.nextInt(jScrollPane5.getWidth());
            vpos2 = rand2.nextInt(jScrollPane5.getHeight());
            positionVertexAt( vertArr2.get(x),hpos2, vpos2,30,20);
        
        }
        jScrollPane5.getViewport().add(jgraph2);
        
        
    }
    
    
    public void showGraph() throws FileNotFoundException {
 
        File fle = new File("graph_verticies.txt");
        Scanner scn = new Scanner(fle);
    
        //loading data from file
        String input,vname;
        int vtype,vnum;
        
        int cnt = 0;
        while(scn.hasNext()){
            
            input = scn.next();

            input = input.substring(input.indexOf(',')+1, input.length());
            vtype = Integer.valueOf(input.substring(0, input.indexOf(','))).intValue();

            input = input.substring(input.indexOf(',')+1, input.length());
            vnum = Integer.valueOf(input.substring(0, input.indexOf(','))).intValue();
            vname = input.substring(input.indexOf(',')+1, input.length());
            Vert v = new Vert(vtype, vname);
            vertArr.add(v);
            Vert temp =  (Vert) vertArr.get(cnt);
            cnt++;
           
        }
        
        
        
        
        
        
        
        

        
        String output;
        int tpe,src,dest;
        fle = new File("graph_edges.txt");
        scn = new Scanner(fle);
        cnt = 0;
        while(scn.hasNext()){
            input = scn.next();
            output = input.substring(input.indexOf(',')+1, input.length());
            tpe = Integer.valueOf(output.substring(0, output.indexOf(','))).intValue();
            output = output.substring(output.indexOf(',')+1, output.length());
            src = Integer.valueOf(output.substring(0, output.indexOf(','))).intValue();
            output = output.substring(output.indexOf(',')+1, output.length());
            dest = Integer.valueOf(output).intValue();
            Edge edg = new Edge(tpe,src,dest);
            edges.add(edg);
            cnt++;
        }
        
        
 
        
        
        
        
        
       
                
        // create a JGraphT graph
        ListenableGraph g = new ListenableDirectedGraph( DefaultEdge.class );

        // create a visualization using JGraph, via an adapter
       
        m_jgAdapter = new JGraphModelAdapter( g );

        JGraph jgraph = new JGraph( m_jgAdapter );
        
        // add sample data 
        for(int x=0;x<vertArr.size();x++){

            g.addVertex( vertArr.get(x) ); 
        }

        for(int y=0;y<edges.size();y++){
           Edge tmp = (Edge) edges.get(y); 
           g.addEdge(vertArr.get(tmp.getSource()), vertArr.get(tmp.getDest()));
        }

        // position vertices nicely within JGraph component
      
        Random rand = new Random();
        int hpos, vpos;
        for(int x =0;x<vertArr.size();x++){
            hpos = rand.nextInt(4000);
            vpos = rand.nextInt(2000);
            positionVertexAt( vertArr.get(x),hpos, vpos,70,25 );
        
        }
        
       
        jScrollPane3.getViewport().add(jgraph);
        
        
        
        
      
       
        
        
    }
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FullGui().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar archives_menu_bar;
    private javax.swing.JTextPane code_view;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JTextField query_field4;
    private javax.swing.JTabbedPane tabs;
    private javax.swing.JTextArea unit_data_text_area2;
    private java.awt.List unit_list;
    // End of variables declaration//GEN-END:variables
    private JGraphModelAdapter m_jgAdapter;
    ArrayList<Edge> edges = new ArrayList<Edge>();
    ArrayList<Vert> vertArr = new ArrayList<Vert>();
    String currentNode = "measure_value";
   
}
