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;
        JPanel header;

        header = new JPanel(new BorderLayout());

        button = new JButton("Generate BibTeX file");
        button.addActionListener(this);
        button.setActionCommand(GENERATE);
        header.add(new JLabel("[Search bar]"), BorderLayout.CENTER);
        header.add(button, BorderLayout.LINE_END);
        header.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK));
        this.add(header, BorderLayout.NORTH);

        pane = new FieldsForm(this.app);
        this.add(pane, BorderLayout.EAST);

        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("References were loaded succesfully.");
        this.infoLabel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.BLACK));
        this.add(this.infoLabel, BorderLayout.SOUTH);
    }

    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("");
        }
        
    }
}

@@ -104,24 +104,97 @@
 ax.swing.*;%0A
+import javax.swing.border.Border;%0Aimport javax.swing.border.EmptyBorder;%0A
 import ryhma
@@ -1309,25 +1309,134 @@
     
-header.setBorder(
+this.add(header, BorderLayout.NORTH);%0A%0A        /* add border and padding to the header panel */%0A        Border bottomBorder = 
 Bord
@@ -1470,24 +1470,40 @@
 (0, 0, 1, 0,
+%0A               
  Color.BLACK
@@ -1495,33 +1495,32 @@
     Color.BLACK)
-)
 ;%0A        this.a
@@ -1517,43 +1517,118 @@
     
-this.add(header, BorderLayout.NORTH
+header.setBorder(BorderFactory.createCompoundBorder(bottomBorder,%0A                new EmptyBorder(4, 4, 4, 4))
 );%0A%0A

Add some padding.