package relative;

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

/**
 * Test frame to demonstrate and validate the functions of the RelativeLayout
 * layout manager.
 */
public class RelativeTestFrame extends JFrame
{
    public static void main(String[] args)
    {
        RelativeTestFrame frame = new RelativeTestFrame();
        frame.setVisible(true);
    }

    public RelativeTestFrame()
    {
        super("Relative Layout Test - Why Me?");

        RelativeLayout THE_LAYOUT = new RelativeLayout(this);

        setMinimumSize(new java.awt.Dimension(600, 450));
        setExtendedState(getExtendedState()|JFrame.MAXIMIZED_BOTH);
        setLayout(THE_LAYOUT);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Container panel = getContentPane();

        JMenu fileMenu = new JMenu("Menu");
        THE_LAYOUT.registerForFontSizeChanges(fileMenu);

        JMenuItem newItem = new JMenuItem("Menu Item A");
        THE_LAYOUT.registerForFontSizeChanges(newItem);
        fileMenu.add(newItem);

        newItem = new JMenuItem("Menu Item B");
        THE_LAYOUT.registerForFontSizeChanges(newItem);
        fileMenu.add(newItem);

        JMenuBar mainMenu = new JMenuBar();
        mainMenu.add(Box.createHorizontalGlue());
        mainMenu.add(fileMenu);
        panel.add(mainMenu, new RelativePlacement(0, 0, 1000, 40));

        JTabbedPane mainTabs = new JTabbedPane();
        THE_LAYOUT.registerForFontSizeChanges(mainTabs);
        panel.add(mainTabs, new RelativePlacement(0, 40, 1000, 960));

        JPanel subPanel = new JPanel();
        subPanel.setLayout(new RelativeLayout(null));
        mainTabs.addTab("A Tab", subPanel);

        DefaultListModel pluginList = new DefaultListModel();
        pluginList.addElement("List Item A");
        pluginList.addElement("List Item B");
        JList pluginListC = new JList(pluginList);
        subPanel.add(pluginListC, new RelativePlacement(10, 10, 150, 300));
        THE_LAYOUT.registerForFontSizeChanges(pluginListC);

        JButton button = new JButton("Button");
        THE_LAYOUT.registerForFontSizeChanges(button);
        subPanel.add(button, new RelativePlacement(10, 310, 150, 50));

        JLabel helpPane = new JLabel();
        THE_LAYOUT.registerForFontSizeChanges(helpPane, 1.2f);

        JScrollPane scrolly = new JScrollPane(helpPane);
        subPanel.add(scrolly, new RelativePlacement(420, 10, 570, 980));
        helpPane.setText("<html><body>"
            + "<b><u>Scaling HTML content</u></b><br>"
            + "The quick brown fox jumped over the lazy dog.<br>"
            + "The quick brown fox jumped over the lazy dog.<br>"
            + "The quick brown fox jumped over the lazy dog.<br>"
            + "The quick brown fox jumped over the lazy dog.<br>"
            + "The quick brown fox jumped over the lazy dog.<br>"
            + "The quick brown fox jumped over the lazy dog.<br>"
            + "The quick brown fox jumped over the lazy dog.<br>"
            + "</body></html>");
    }
}
