/**
 * File: BigramDisplay.java
 * @author A.Kurd <alan.kurd@trincoll.edu>
 * 
 * Description: Implements a Java 1.1 version of a GUI tool for displaying Bigram data collected in BigramCount.java.
 * Credits: This program is modelled after the frequency test of the CryptoToolJ program by Ralph Morelli.
 *
 * Copyright: This program is in the public domain. You can do whatever you want with
 *  it as long as I get credit for my work and as long as you offer your changes to me
 *  so I can possible add them to the "official" version.
 */
package analyzers;             // Analyzer plugins belong to this package

import hcrypto.analyzer.*;     // This is where Analyzer is
import java.awt.TextArea;
import hcrypto.cipher.*;
import java.awt.*;
import java.awt.event.*;   

import java.io.*;
import java.util.*;
import java.awt.datatransfer.*;

public class BigramDisplay extends Frame implements WindowListener,  Analyzer{

   public  Frame  frame;		//frame to display the collected data
   public  BigramCount bc= new BigramCount(); 	//instance of BigramCount to collect the data to be displayed
   public  String output = "";		//string where the output is collected
   private TextArea text;     // Pointers to the text to be analyzed
   private TextArea display;  // And the window where results are displayed
    static final int HIST_WIDTH = Histogram.WIDTH;
    static final int HIST_HEIGHT = Histogram.HEIGHT;
	static final int WIN_WIDTH = HIST_WIDTH + 50;
	static final int WIN_HEIGHT = HIST_HEIGHT + 200;

   public  void BigramDisplay(String text){
   }//BigramDisplay

/*Necessary for the Analyzer package*/

   public void setup(TextArea text, TextArea display) { 
      this.text = text;
      this.display = display;
   }

/*First method called for this class*/

   public void run() {
      display.append("Bigram Analysis Called" + "\n");  //tells user they've called this class to display Brigram Data
      bc.count(text.getText());			 //calculates Bigram frequency from BigramCount
      frame();				 //displays the data
   }

/*This is the method to display the information collected in the string output.
  It outputs the top 40 bigrams in 8 rows of 5 columns.*/

   public  void frame(){   
      
      frame = new Frame ("Bigram");
      frame.addWindowListener(this);
      frame.setResizable(true);
      frame.setSize(400, 200);
      frame.setLocation(5, 10);
      frame.setVisible(true);

      for (int k=0; k < 40; k++){
         if (k%5 == 0)
            output = output + "" + "\n";
         if (bc.tabulate [k] [0] > 0)
            output = output + "\t"+ (bc.tabulate [k] [0] + "-" + (char)bc.tabulate [k] [1] + "" + (char)bc.tabulate [k] [2] + "" + " ");}//for

      display = new TextArea (output);
      frame.add(display);
      frame.show();
   }//frame
    public void windowClosing(WindowEvent e) {
        frame.dispose();
    }
    public void windowActivated(WindowEvent e) {}	
    public void windowDeactivated(WindowEvent e) {}
    public void windowClosed(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}   
}//BigramDisplay Class