/**
    KJF 03/20/2012 Initial coding.

    @author Kip Fiebig (KJF)
*/

import java.awt.*;
import java.io.*;
import javax.swing.*;

public class SuperQuest extends JFrame {

    int[] dataInts;

    public SuperQuest() {
        super("Super Quest Map");
        readData();
        createGui();
        setSize(750, 550);
        setLocationRelativeTo(null);
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    private void readData() {
        FileInputStream in = null;
        try {
            File file = new File("sq4");
            in = new FileInputStream(file);
            int size = (int)file.length();
            byte[] dataBytes = new byte[size];
            in.read(dataBytes);

            dataInts = new int[size];
            for (int i = 0; i < size; i++) {
                dataInts[i] = (int)dataBytes[i] & 0xff;  // & 0xff handles the negative byte values, since byte ranges from -128 to 127
            }
        }
        catch(IOException e) {
            System.out.println(e.getMessage());
        }
        finally {
            try { if (in != null) { in.close(); } } catch(IOException e2) {}
        }
    }

    private void createGui() {
        setLayout(new BorderLayout(0, 0));
        MapPanel mapPanel = new MapPanel(dataInts);
        JScrollPane scrollPane = new JScrollPane(mapPanel);
        add(BorderLayout.CENTER, scrollPane);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new SuperQuest();
            }
        });
    }
}
