package com.yaka;

import javax.swing.*;

public class Main {
    private static void usage() {
        System.err.println("Usage: layouts.jar LAYOUT");
        System.err.println("Where LAYOUT is one of: box, border, grid, flow, composite.");
        System.exit(1);
    }

    public static void main(String[] args) {
        if (args.length != 1)
            usage();

        LayoutExample layout;

        switch (args[0].toLowerCase()) {
            case "box":  layout = new BoxLayoutExample(); break;
            case "border": layout = new BorderLayoutExample(); break;
            case "grid": layout = new GridLayoutExample(); break;
            case "flow": layout = new FlowLayoutExample(); break;
            case "composite": layout = new CompositeLayoutExample(); break;
            default: usage(); return;
        }

        final JPanel panel = layout.getContent();
        final String title = layout.getName();

        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame(title);
            frame.setContentPane(panel);
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.pack();
        });
    }
}
