package ryhma57.gui;

import java.awt.*;
import java.awt.event.*;

import java.util.EnumMap;
import javax.swing.*;
import ryhma57.backend.BibtexReferenceField;

public class Window extends JFrame implements ActionListener {

    static final String GENERATE = "generate";
    static final String CLEAR_LABEL = "clearLabel";
    
    private Application app;
    private JLabel infoLabel;
    private ListView listView;

    public Window(Application app) {
        this.app = app;
        this.setTitle("Application");
        /* set some default size so that window isn't 0x0 size */
        /*XXX we could load window geometry from config file */
        this.setSize(600, 480);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        this.createComponents();
    }

    private void createComponents() {
        JButton button;
        JScrollPane scrollPane;
        JPanel pane, aligner;
        pane = new FieldsForm(this.app);
        this.add(pane, BorderLayout.NORTH);

        this.listView = new ListView(this.app);
        aligner = new JPanel();
        aligner.setLayout(new BorderLayout());
        aligner.add(this.listView, BorderLayout.PAGE_START);
        scrollPane = new JScrollPane(aligner);
        this.add(scrollPane, BorderLayout.CENTER);

        this.infoLabel = new JLabel("");
        this.add(this.infoLabel, BorderLayout.SOUTH);

        button = new JButton("Generate BibTeX file");
        button.addActionListener(this);
        button.setActionCommand(GENERATE);

        this.add(button, BorderLayout.WEST);
    }

    public ListView getListView() {
        return this.listView;
    }

    public void setErrorMessage(String error) {
        Timer timer;

        this.infoLabel.setText("The reference was saved");
        timer = new Timer(10000, this);
        timer.start();
        timer.setActionCommand(CLEAR_LABEL);
    }

    @Override
    public void actionPerformed(ActionEvent event) {
        if (event.getActionCommand().equals(GENERATE)) {
            this.app.generateBibTex();
            JOptionPane.showMessageDialog(this,
                    "BibTex file was generated.");
        } else if (event.getActionCommand().equals(CLEAR_LABEL)) {
            this.infoLabel.setText("");
        }
        
    }
}

@@ -893,16 +893,478 @@
 ligner;%0A
+        JPanel header;%0A%0A        header = new JPanel(new BorderLayout());%0A%0A        button = new JButton(%22Generate BibTeX file%22);%0A        button.addActionListener(this);%0A        button.setActionCommand(GENERATE);%0A        header.add(new JLabel(%22%5BSearch bar%5D%22), BorderLayout.CENTER);%0A        header.add(button, BorderLayout.LINE_END);%0A        header.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));%0A        this.add(header, BorderLayout.NORTH);%0A%0A
         
@@ -1424,37 +1424,36 @@
 e, BorderLayout.
-NORTH
+EAST
 );%0A%0A        this
@@ -1764,16 +1764,51 @@
 JLabel(%22
+References were loaded succesfully.
 %22);%0A    
@@ -1811,25 +1811,16 @@
         
-this.add(
 this.inf
@@ -1829,170 +1829,78 @@
 abel
-, 
+.set
 Border
-Layout.SOUTH);%0A%0A        button = new JButton(%22Generate BibTeX file%22);%0A        button.addActionListener(this);%0A        button.setActionCommand(GENERATE
+(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.BLACK)
 );%0A
-%0A
     
@@ -1908,30 +1908,38 @@
    this.add(
-button
+this.infoLabel
 , BorderLayo
@@ -1945,12 +1945,13 @@
 out.
-WEST
+SOUTH
 );%0A 

Make the gui more or less usable.