package io.measures.passage;

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

/**
 * Runner
 * @author Dietrich Featherston
 */
public class Runner {

    public Runner(final Sketch s) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new SketchFrame(s).setVisible(true);
            }
        });
    }

    private static final void usage(String[] args) {
        System.out.println("usage: " + args[0] + " [sketchname]");
    }

    public static void main(String[] args) throws Exception {
        if(args.length != 2) usage(args);
        String className = args[1];
        Class<? extends Sketch> c = (Class<Sketch>)Class.forName(className);
        Sketch s = c.newInstance();
        new Runner(s);
    }

    private class SketchFrame extends JFrame {
        SketchFrame(final Sketch s) {
            super("passage");
            Dimension d = new Dimension(s.getTargetWidth(), s.getTargetHeight());
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setPreferredSize(d);
            getContentPane().setSize(d);
            getContentPane().add(s, BorderLayout.CENTER);
            pack();
            setVisible(true);
            s.init();
            setMinimumSize(d);
            setResizable(false);
        }
    }
}

@@ -1207,13 +1207,24 @@
     
-pack(
+setMinimumSize(d
 );%0A 
@@ -1237,28 +1237,55 @@
      set
-Visible(true
+Size(d);%0A            setPreferredSize(d
 );%0A     
@@ -1295,14 +1295,12 @@
     
-s.init
+pack
 ();%0A
@@ -1310,37 +1310,58 @@
          set
-MinimumSize(d
+Visible(true);%0A            s.init(
 );%0A         

support larger-than-screen sizes