/**
 * Class StackGui - write a description of the class here
 * 
 * @author: Xaris Xaritsis e-mail:charis_ch@usa.net
 * date: 
 */
import java.awt.*;
import java.awt.event.*;

public class StackGui extends Frame 
{
      
      public static Frame stackStatus;      
      public static Label positionPrevState[] = new Label[10];
      public static Label positionCurrState[] = new Label[10];
      public static TextField prevStateIndex[] = new TextField[10];
      public static TextField currStateIndex[] = new TextField[10];
      
    
     /**
     * Constructor for objects of class StackGui
     */
     
     public StackGui()
     {
      stackStatus = new Frame("Stack Status");
      
      GridBagLayout gridLayout = new GridBagLayout();  
      
      stackStatus.setFont(new Font("TimesRoman", Font.PLAIN, 14));
      stackStatus.setBackground(Color.darkGray);
     


      GridBagConstraints constraints = new GridBagConstraints();



       //STATE LABELS' USER INTERFACE 
       buildConstraints(constraints,1,0,41.75,6.5,GridBagConstraints.NONE);
       Label previousStateLabel = new Label("PREVIOUS STATE",Label.LEFT);
       previousStateLabel.setForeground(Color.red);
       previousStateLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
       gridLayout.setConstraints(previousStateLabel,constraints);
       stackStatus.add(previousStateLabel);
       
       buildConstraints(constraints,3,0,45.75,0,GridBagConstraints.NONE);
       Label currentStateLabel = new Label("CURRENT STATE",Label.LEFT);
       currentStateLabel.setForeground(Color.red);
       currentStateLabel.setFont(new Font("TimesRoman", Font.BOLD, 15));
       gridLayout.setConstraints(currentStateLabel,constraints);
       stackStatus.add(currentStateLabel);


       
       //PREVIOUS STATE STACK POSITION LABELS' USER INTERFACE
       buildConstraints(constraints,0,2,6.25,6.5,GridBagConstraints.NONE);
       positionPrevState[0] = new Label("POS. " + 0,Label.CENTER);
       positionPrevState[0].setForeground(Color.magenta);
       gridLayout.setConstraints(positionPrevState[0],constraints);
       stackStatus.add(positionPrevState[0]);

       for (int i=1; i<=9; i++)
        { 
         buildConstraints(constraints,0,2+i,0,6.5,GridBagConstraints.NONE);
         positionPrevState[i] = new Label("POS. " + i,Label.CENTER);
         positionPrevState[i].setForeground(Color.magenta);
         gridLayout.setConstraints(positionPrevState[i],constraints);
         stackStatus.add(positionPrevState[i]);
        }

     
        

       //PREVIOUS STATE STACK STATUS USER INTERFACE
       buildConstraints(constraints,1,2,0,0,GridBagConstraints.HORIZONTAL);
       prevStateIndex[0] = new TextField();
       prevStateIndex[0].setEditable(false);
       gridLayout.setConstraints(prevStateIndex[0],constraints);
       stackStatus.add(prevStateIndex[0]);

       for (int i=1; i<=9; i++)
        { 
         buildConstraints(constraints,1,2+i,0,0,GridBagConstraints.HORIZONTAL);
         prevStateIndex[i] = new TextField();
         prevStateIndex[i].setEditable(false);
         gridLayout.setConstraints(prevStateIndex[i],constraints);
         stackStatus.add(prevStateIndex[i]);
        }
        


       //CURRENT STATE STACK POSITION LABELS' USER INTERFACE
       buildConstraints(constraints,2,2,6.25,0,GridBagConstraints.NONE);
       positionCurrState[0] = new Label("POS. " + 0,Label.CENTER);
       positionCurrState[0].setForeground(Color.magenta);
       gridLayout.setConstraints(positionCurrState[0],constraints);
       stackStatus.add(positionCurrState[0]);

       for (int i=1; i<=9; i++)
        { 
         buildConstraints(constraints,2,2+i,0,0,GridBagConstraints.NONE);
         positionCurrState[i] = new Label("POS. " + i,Label.CENTER);
         positionCurrState[i].setForeground(Color.magenta);
         gridLayout.setConstraints(positionCurrState[i],constraints);
         stackStatus.add(positionCurrState[i]);
        }
    
              

       //CURRENT STATE STACK STATUS USER INTERFACE       
       buildConstraints(constraints,3,2,43.75,0,GridBagConstraints.HORIZONTAL);
       currStateIndex[0] = new TextField();
       currStateIndex[0].setEditable(false);
       gridLayout.setConstraints(currStateIndex[0],constraints);
       stackStatus.add(currStateIndex[0]);

       for (int i=1; i<=9; i++)
        { 
         buildConstraints(constraints,3,2+i,0,0,GridBagConstraints.HORIZONTAL);
         currStateIndex[i] = new TextField();
         currStateIndex[i].setEditable(false);
         gridLayout.setConstraints(currStateIndex[i],constraints);
         stackStatus.add(currStateIndex[i]);
        }
                     
       
             
       //W  I  N  D  O  W     S  E  T  T  I  N  G  S
       stackStatus.setLayout(gridLayout);
       stackStatus.setSize(440,440);             
       stackStatus.setLocation(340,30);
       stackStatus.setResizable(true);  
       //stackStatus.addWindowListener(new CloseWindow());
       
       stackStatus.show();       
   } 



 public  void buildConstraints(GridBagConstraints gbc,int gx, int gy, double wx, double wy, int fll) 
     {                 
       gbc.gridx = gx;
       gbc.gridy = gy;
       gbc.gridwidth = 1;
       gbc.gridheight = 1; 
       gbc.weightx = wx;
       gbc.weighty = wy;  
       gbc.anchor = GridBagConstraints.EAST;
       gbc.fill = fll; 
       //gbc.insets = new Insets(0,0,0,0);  //Oso kai h dafault value.
       //gbc.ipadx = 0;                     //         Wstoso to bazoume gia metepeita 
       //gbc.ipady = 0;                     //                                      pithanes allages.               
    }


     
}		


class CloseWindow extends WindowAdapter
  {
    public void windowClosing(WindowEvent closeWindow)
     {       
      closeWindow.getWindow().hide();
      //CalculatorGui.showStackStatus.setState(false);      
      // Einai protimotero na kanw invisible to antikeimeno para na to katastrepsw
      // Ama omws ginei invisible tha prepei na enhmerwthei kai to antistoixo MenuItem (dhl. to stackStatus)
     }
  } 


