Package gui.testSetup

Source Code of gui.testSetup.SetupEditor

package gui.testSetup;

import common.Constants;
import gui.testSetup.components.TestConfSetting;
import gui.testSetup.components.PageDescriptionViewer;
import gui.testSetup.components.PageInputEditor;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import testGenerator.Controller;

/**
*
* @author William Whitney
*/
public class SetupEditor extends JFrame
{
    private static final long serialVersionUID = 1L;

    private final TestConfSetting currPage;
    private static final Dimension k_windowSize = new Dimension(600, 500);
    private JPanel panel;
    private final PageDescriptionViewer pageDescriptionViewer;
    private final PageInputEditor pageInputEditor;
    private final Controller control;

    /**
     * Default constructor.
     * @param control
     * @param enumPageType
     */
    public SetupEditor(Controller control, TestConfSetting enumPageType)
    {
        this.control = control;
        this.currPage = enumPageType;

        pageDescriptionViewer = new PageDescriptionViewer(currPage.getDescription());
        pageInputEditor = new PageInputEditor(currPage);
        pageInputEditor.setValue(this.control.getSetupInfo(currPage));

        //Setup frame
        this.setupFrame();

        //Get The title
        panel.add(this.getPageTitleBar(), BorderLayout.NORTH);

        //Add Input Editor
        panel.add(this.pageInputEditor, BorderLayout.CENTER);

        //Add button bar
        this.panel.add(getButtonBar(), BorderLayout.SOUTH);

        this.setVisible(true);

    }

    private void setupFrame()
    {
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        //Set size
        this.setMinimumSize(k_windowSize);
        this.setMaximumSize(k_windowSize);
        this.setPreferredSize(k_windowSize);

        //Set title
        this.setTitle(currPage.getTitle() + " Editor");

        //Create panel
        this.panel = new JPanel();
        this.panel.setLayout(new BorderLayout());
        this.setContentPane(panel);

    }

    /**
     * Show UI.
     */
    public void showUI()
    {
    }

    private JPanel getButtonBar()
    {
        JPanel btnPanel = new JPanel();
        btnPanel.setLayout(new FlowLayout());

        //Cancel button
        JButton cancel = new JButton("Cancel");
        cancel.addActionListener(new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                dispose();
            }
        });
        btnPanel.add(cancel);

        //Save btn
        JButton save = new JButton("Save");
        save.addActionListener(new ActionListener()
        {

            @Override
            public void actionPerformed(ActionEvent e)
            {
                control.setTestConf(currPage, pageInputEditor.getValue());
                dispose();
            }
        });
        btnPanel.add(save);
        return btnPanel;
    }

    /**
     * Returns a JPanel that is the title bar.
     * @return JPanel that has page title and other related info
     */
    public final JPanel getPageTitleBar()
    {
        JPanel titlePanel = new JPanel();
        titlePanel.setLayout(new BorderLayout());

        //North
        JLabel pageTitle = new JLabel(currPage.getTitle());
        pageTitle.setFont(Constants.getHeadingFont());
        titlePanel.add(pageTitle, BorderLayout.NORTH);

        //Center
        titlePanel.add(pageDescriptionViewer, BorderLayout.CENTER);

        //South
        titlePanel.add(new JLabel("  "), BorderLayout.SOUTH);

        return titlePanel;
    }
}
TOP

Related Classes of gui.testSetup.SetupEditor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.