wpcons/src/Team/StartUp.java


/* A simple GUI search engine that searches text files using the
 * AND, OR, and PHRASE search terms. The results are a list of files
 * that match the search terms.
 *
 * WP Consulting Group - COP2805
 * Authors: Raymond Tam
 *             Romell Martin
 *             Urban Areingdale
 *             Joyce Sullivan
 *
 * Date: February 2013
 */

package Team;

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

@SuppressWarnings("serial")
public class StartUp extends JFrame{

    private static String TITLE = "Search Engine";

    public StartUp() {

        // set the application Icon
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("images/search.png")));

        // create search buttons
        JButton submitall = new JButton("All of the search terms");
        JButton submitany = new JButton("Any of the search terms");
        JButton submitexact = new JButton("Exact phrase");

        // create the menu bar
        JMenuBar bar = new JMenuBar();
            // create the File menu
            JMenu file = new JMenu("File");
            file.setMnemonic('F');

                // create the Maintenance menu
                JMenu maintenance = new JMenu( "Index Maintenance" );
                maintenance.setMnemonic('M');
                file.add(maintenance);


                    JMenuItem add = new JMenuItem( "Add file" );
                    add.setMnemonic('A');
                    maintenance.add(add);


                    JMenuItem remove = new JMenuItem( "Remove selected files" );
                    remove.setMnemonic('R');
                    maintenance.add(remove);


                    JMenuItem rebuild = new JMenuItem( "Rebuild index" );
                    rebuild.setMnemonic('B');
                    maintenance.add(rebuild);


                JMenuItem exitapp = new JMenuItem( "Exit application" );
                exitapp.setMnemonic('X');
                file.add(exitapp);


            // create the Help menu
            JMenu help = new JMenu("Help");
            file.setMnemonic('H');

                JMenuItem team = new JMenuItem( "Team" );
                team.setMnemonic('T');
                help.add(team);

                JMenuItem about = new JMenuItem( "About" );
                about.setMnemonic('A');
                help.add(about);

        setJMenuBar(bar);
        bar.add(file);
        bar.add(help);

        // design the Search panel
        JPanel top = new JPanel();
            top.setLayout(new BorderLayout(15,15));

            JPanel header = new JPanel();
                header.setLayout(new BorderLayout());
                header.setBackground(new Color(34, 88, 104).brighter());
                JLabel title = new JLabel(TITLE, JLabel.CENTER);
                title.setFont(new Font("Sans-Serif", Font.BOLD, 22));
                title.setForeground(Color.WHITE);
                header.add(title, BorderLayout.NORTH);
                JLabel credits = new JLabel("\u00A9 Feb 2013 by WP Consulting Group", JLabel.CENTER);
                credits.setFont(new Font("Sans-Serif", Font.PLAIN, 14));
                credits.setForeground(Color.WHITE);
                header.add(credits, BorderLayout.SOUTH);
            top.add(header,BorderLayout.NORTH);        // add panel to overall panel

            JPanel search = new JPanel();
                search.add(new JLabel("Search Terms:",JLabel.LEFT));
                search.add(new JLabel("       "));
                JTextField jf1 = new JTextField(30);
                jf1.setEditable(true);
                search.add(jf1);
                search.add(new JLabel("       "));
            top.add(search,BorderLayout.CENTER);        // add panel to overall panel

            JPanel btns = new JPanel();
                btns.add(submitall);
                btns.add(new JLabel("     "));
                btns.add(submitany);
                btns.add(new JLabel("     "));
                btns.add(submitexact);
            top.add(btns, BorderLayout.SOUTH);        // add panel to overall panel
        add(top,BorderLayout.NORTH);

        // design the Search results panel
        JPanel middle = new JPanel();
            middle.setLayout(new BorderLayout());

            JPanel list = new JPanel();
                list.setLayout (new BorderLayout());
                JTextArea fileList = new JTextArea("Search results goes here",15,0);  // needs to be a text area , label will not work
                fileList.setEditable(false);
                list.add(fileList, BorderLayout.NORTH);
            middle.add(list,BorderLayout.NORTH);  // add panel to overall panel

        add(middle,BorderLayout.CENTER);

        // design the Maintenance panel
        JPanel bottom = new JPanel();
            bottom.setLayout(new BorderLayout());

            JPanel spacer = new JPanel();
                spacer.setLayout (new BorderLayout());
                JLabel index = new JLabel("Index Maintenance", JLabel.CENTER);
                index.setFont(new Font("Sans-Serif", Font.BOLD, 22));
                index.setForeground(Color.WHITE);
                spacer.add(index, BorderLayout.NORTH);
                spacer.setBackground(new Color(34, 88, 104).brighter());
            bottom.add(spacer,BorderLayout.NORTH);         // add panel to overall panel


            JPanel maintain = new JPanel();
                maintain.setLayout (new BorderLayout());
                JTextArea indexed = new JTextArea("Indexed files go here",15,0);  // needs to be a text area , label will not work
                indexed.setEditable(false);
                maintain.add(indexed, BorderLayout.NORTH);
            bottom.add(maintain,BorderLayout.CENTER);        // add panel to overall panel

             JPanel spacer2 = new JPanel();
                spacer2.add(new JLabel(""));
                spacer2.setBackground(new Color(34, 88, 104).brighter());
            bottom.add(spacer2,BorderLayout.SOUTH);        // add panel to overall panel

        add(bottom,BorderLayout.SOUTH);

     // hook up event handling
        add.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"Add file\" menu item selected.", "Add file", 1);
            }
        });

        remove.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"Remove selected files\" menu item selected.", "Remove file", 1);
            }
        });

        rebuild.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"Rebuild index\" menu item selected.", "Rebuild index", 1);
            }
        });

        team.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"Team\" menu item selected.", "Team", 1);
            }
        });

        about.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"About\" menu item selected.", "About", 1);
            }
        });

        exitapp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"Exit application\" menu item selected.", "Exit", 1);
            }
        });


        submitall.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"All of the search terms\" button clicked.", "Submit all", 1);
            }
        });

        submitany.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"Any of the search terms\" button clicked.", "Submit any", 1);
            }
        });

        submitexact.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                JOptionPane.showMessageDialog(null, "\"Exact phrase\" button clicked.", "Submit exact", 1);
                }
            });
        }

    public static void main(String[] args) {

        StartUp frame = new StartUp();
        frame.setTitle(TITLE);
        frame.setSize(700,700);
        frame.setLocation(300,50);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}