package osa;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Tab2
{
  private MainFrame tFrame;
  private BorderLayout tBorderLayout = new BorderLayout();
  private Action aFileNewProject;
  private Action aFileOpenProject;
  private Action aFileSaveProject;
  private Action aFileSaveProjectAs;
  private Action aFileExit;
  private Action aHelpHelpTopics;
  private Action aHelpAbout;
  private JLabel ErrorLabel = new JLabel();
  private JPanel t2Panel = new JPanel();
  private BorderLayout t2BorderLayout = new BorderLayout();
  private JLabel t2TLabel = new JLabel();
  private JTextArea t2TextArea = new JTextArea();
  private JScrollPane t2ScrollPane = new JScrollPane();
  private JLabel t2BLabel = new JLabel();

  public Tab2(MainFrame pMainFrame)
  {
    tFrame=pMainFrame;
    tFrame.mPanel2.setLayout(tBorderLayout);

    aFileNewProject = new AbstractAction("New Project",new ImageIcon(Tab2.class.getResource("new.gif")))
    {{ putValue(Action.SHORT_DESCRIPTION,"New Project"); }
    // putValue(Action.MNEMONIC_KEY,new Integer(KeyEvent.VK_N));
    public void actionPerformed(ActionEvent e)
    { tFrame.FileNewProject(); }};
    aFileOpenProject = new AbstractAction("Open Project...",new ImageIcon(Tab2.class.getResource("open.gif")))
    {{ putValue(Action.SHORT_DESCRIPTION,"Open Project..."); }
    // putValue(Action.MNEMONIC_KEY,new Integer(KeyEvent.VK_O));
    public void actionPerformed(ActionEvent e)
    { tFrame.FileOpenProject(); }};
    aFileSaveProject = new AbstractAction("Save Project",new ImageIcon(Tab2.class.getResource("save.gif")))
    {{ putValue(Action.SHORT_DESCRIPTION,"Save Project"); }
    // putValue(Action.MNEMONIC_KEY,new Integer(KeyEvent.VK_S));
    public void actionPerformed(ActionEvent e)
    { tFrame.FileSaveProject(); }};
    aFileSaveProjectAs = new AbstractAction("Save Project As...",new ImageIcon(Tab2.class.getResource("saveas.gif")))
    {{ putValue(Action.SHORT_DESCRIPTION,"Save Project As..."); }
    // putValue(Action.MNEMONIC_KEY,new Integer(KeyEvent.VK_A));
    public void actionPerformed(ActionEvent e)
    { tFrame.FileSaveProjectAs(); }};
    aFileExit = new AbstractAction("Exit")
    {{ putValue(Action.SHORT_DESCRIPTION,"Exit"); }
    // putValue(Action.MNEMONIC_KEY,new Integer(KeyEvent.VK_X));
    public void actionPerformed(ActionEvent e)
    { tFrame.FileExit(); }};
    aHelpHelpTopics = new AbstractAction("Help Topics",new ImageIcon(Tab2.class.getResource("help.gif")))
    {{ putValue(Action.SHORT_DESCRIPTION,"Help Topics"); }
    // putValue(Action.MNEMONIC_KEY,new Integer(KeyEvent.VK_H));
    public void actionPerformed(ActionEvent e)
    { tFrame.HelpHelpTopics(0x2); }};
    aHelpAbout = new AbstractAction("About...")
    {{ putValue(Action.SHORT_DESCRIPTION,"About..."); }
    // putValue(Action.MNEMONIC_KEY,new Integer(KeyEvent.VK_A));
    public void actionPerformed(ActionEvent e)
    { tFrame.HelpAbout(); }};

    ErrorLabel.setFont(tFrame.mFont);
    ErrorLabel.setForeground(Color.red);
    ErrorLabel.setHorizontalAlignment(JLabel.CENTER);
    t2Panel.setLayout(t2BorderLayout);
    t2TLabel.setFont(tFrame.mFont);
    t2TLabel.setText("  ");
    t2Panel.add(t2TLabel,BorderLayout.NORTH);
    t2TextArea.setFont(tFrame.mFont);
    t2TextArea.setTabSize(0x08);
    t2TextArea.setEditable(false);
    t2TextArea.getCaret().setVisible(false);
    t2TextArea.getCaret().setSelectionVisible(true);
    t2ScrollPane.setViewportView(t2TextArea);
    t2Panel.add(t2ScrollPane,BorderLayout.CENTER);
    t2BLabel.setFont(tFrame.mFont);
    t2BLabel.setText("  ");
    t2Panel.add(t2BLabel,BorderLayout.SOUTH);
  }

  public void tDeSelect()
  { if(!tFrame.isBottomComponentActive)
    { tFrame.mMenuBar.removeAll();
      tFrame.mToolBar.removeAll(); }
    tFrame.mPanel2.removeAll();
    tFrame.validate(); }

  public void tSelect()
  { if(tFrame.reAnalyse) tFrame.Analyse();
    switch(tFrame.AnalyseReturn)
    { case 0: ErrorLabel.setText("ÑÎÑÒÎßÍÈÅ ÃÐÀÌÌÀÒÈÊÈ ÎÏÐÅÄÅËÈÒÜ ÍÅ ÓÄÀËÎÑÜ");
        tFrame.mPanel2.add(ErrorLabel,BorderLayout.NORTH); break;
      case 1: ErrorLabel.setText("Â ÃÐÀÌÌÀÒÈÊÅ ÎÁÍÀÐÓÆÅÍÛ ÑÈÍÒÀÊÑÈ×ÅÑÊÈÅ ÎØÈÁÊÈ");
        tFrame.mPanel2.add(ErrorLabel,BorderLayout.NORTH); break; }
    switch(tFrame.AnalyseReturn)
    { case 1: t2TLabel.setText("  Îøèáêè Ãðàììàòèêè:");
        if(tFrame.reListRule)
        { t2TextArea.selectAll();
          t2TextArea.replaceSelection(tFrame.ArrayListToString(tFrame.alRuleList));
          t2TextArea.setCaretPosition(0); tFrame.reListRule=false; }
        t2BLabel.setText("  Êîëè÷åñòâî Îøèáîê: "+tFrame.alRuleList.size());
        tFrame.mPanel2.add(t2Panel,BorderLayout.CENTER); break;
      case 2: case 3: case 4: t2TLabel.setText("  Ïðàâèëà Ãðàììàòèêè:");
        if(tFrame.reListRule)
        { t2TextArea.selectAll();
          t2TextArea.replaceSelection(tFrame.ArrayListToString(tFrame.alRuleList));
          t2TextArea.setCaretPosition(0); tFrame.reListRule=false; }
        t2BLabel.setText("  Êîëè÷åñòâî Ïðàâèë: "+tFrame.alRuleList.size());
        tFrame.mPanel2.add(t2Panel,BorderLayout.CENTER); break; }

    if(!tFrame.isBottomComponentActive)
    { JMenu jMenu;
      jMenu = new JMenu("File");
      jMenu.setMnemonic(KeyEvent.VK_F);
      tFrame.mMenuBar.add(jMenu);
      jMenu.add(aFileNewProject).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,Event.CTRL_MASK));
      jMenu.add(aFileOpenProject).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,Event.CTRL_MASK));
      jMenu.addSeparator();
      jMenu.add(aFileSaveProject).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,Event.CTRL_MASK));
      jMenu.add(aFileSaveProjectAs).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,Event.CTRL_MASK|Event.SHIFT_MASK));
      jMenu.addSeparator();
      jMenu.add(aFileExit).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,Event.ALT_MASK));
      jMenu = new JMenu("Help");
      jMenu.setMnemonic(KeyEvent.VK_H);
      tFrame.mMenuBar.add(jMenu);
      jMenu.add(aHelpHelpTopics).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1,0));
      jMenu.addSeparator();
      jMenu.add(aHelpAbout);//.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,Event.ALT_MASK));
      JButton jButton; Insets jInsets=new Insets(2,2,2,2);
      jButton=tFrame.mToolBar.add(aFileNewProject);
      jButton.setFocusable(false); jButton.setMargin(jInsets);
      jButton=tFrame.mToolBar.add(aFileOpenProject);
      jButton.setFocusable(false); jButton.setMargin(jInsets);
      jButton=tFrame.mToolBar.add(aFileSaveProject);
      jButton.setFocusable(false); jButton.setMargin(jInsets);
      jButton=tFrame.mToolBar.add(aFileSaveProjectAs);
      jButton.setFocusable(false); jButton.setMargin(jInsets);
    }
    tFrame.validate();
  }
}
