/* Program: Questionnaire
 * Author: Rytis Umbrasas
 * School: Vilnius Lyceum
 * IDE: NetBeans 4.1
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

class application extends JFrame{
    
    public Container container;
    private GridBagLayout layout;
    public GridBagConstraints constraints;
    public static login loginScreen;
    public static test questionnaire;
    public static QuestionAdministrator admin;
    public static configuration conf;
    
    public application(){
        super("Questionnaire");
        
        container = getContentPane();
        layout = new GridBagLayout();
        container.setLayout(layout);
        constraints = new GridBagConstraints();
        constraints.weightx = 1;
        constraints.weighty = 1;
        
    }
    
    public void setupBorderLayout(){
    /* Sets up a BorderLayout, which overrides default GridBagLayout */
        BorderLayout optlayout = new BorderLayout(1, 1);
        container = getContentPane();
        container.setLayout(optlayout);
    }
    
    public void addComponent(Component component, int column, int row, int width, int height) {
    /* Adds a component to a GridBagLayout */
        
        constraints.gridx = column;
        constraints.gridy = row;
        constraints.gridwidth = width;
        constraints.gridheight = height;
        
        layout.setConstraints(component, constraints);
        container.add(component);
        
        show();
        repaint();
    }
    
    public void removeComponent(Component component){
    /* Removes component from a GridBagLayout */
        
        layout.removeLayoutComponent(component);
        container.remove(component);
        
        show();
        repaint();
    }
    
    public void removeAllComponents(){
    /* Removes all components from a GridBagLayout */    
        container.removeAll();
        
        show();
        repaint();
    }
    
    public static void main(String[] args) throws IOException{
        
        /* Initializes configuration class */
        conf = new configuration();
        
        /* Cheks whether to launch respondent or administrator part of the program */
        if (args.length != 0){
            if (args[0].compareTo("AdminPanel") == 0){
                admin = new QuestionAdministrator();
                admin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
            else{
                loginScreen = new login();
                loginScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        }
        else{
            loginScreen = new login();
            loginScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }
}