package net.katsuster.semu.ui;

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

import net.katsuster.semu.arm.*;

public class MainApplet extends JApplet {
    private static final SystemPane spane = new SystemPane();

    private Emulator emu;

    class Emulator extends Thread {
        private ARMv5 cpu;
        private Bus64 bus;
        private RAM ramMain;

        public Emulator() {
            //do nothing
        }

        @Override
        public void run() {
            String kimage = "http://www2.katsuster.net/~katsuhiro/contents/java/Image-3.14.16";
            String initram = "http://www2.katsuster.net/~katsuhiro/contents/java/initramfs.gz";
            String cmdline = "console=ttyAMA0 mem=64M lpj=0 root=/dev/ram init=/bin/sh debug printk.time=1\0";

            cpu = new ARMv5();
            bus = new Bus64();
            ramMain = new RAM(64 * 1024 * 1024); //64MB

            Main.addVersatileCores(cpu, bus, ramMain);
            Main.bootFromURL(cpu, ramMain, kimage, initram, cmdline);
        }

        public void halt() {
            cpu.halt();
        }
    }

    @Override
    public void init() {
        SystemPane.out.println("init");

        super.init();

        ButtonListener listenButton = new ButtonListener();

        JMenuBar menuBar = new JMenuBar();
        JMenu menuSystem = new JMenu("System");
        JMenuItem itemReset = new JMenuItem("Reset");
        JMenuItem itemClear = new JMenuItem("Clear Log");
        setJMenuBar(menuBar);
        menuBar.add(menuSystem);
        menuSystem.add(itemReset);
        menuSystem.addSeparator();
        menuSystem.add(itemClear);
        menuSystem.setMnemonic(KeyEvent.VK_S);
        itemReset.setActionCommand("reset");
        itemReset.addActionListener(listenButton);
        itemReset.setMnemonic(KeyEvent.VK_R);
        itemClear.setActionCommand("clear");
        itemClear.addActionListener(listenButton);
        itemClear.setMnemonic(KeyEvent.VK_C);

        JPanel panel = new JPanel(new BorderLayout(), true);
        JPanel panelEast = new JPanel(new FlowLayout(), true);
        JButton btnReset = new JButton("Reset");
        JButton btnClear = new JButton("Clear");

        btnReset.addActionListener(listenButton);
        btnReset.setActionCommand("reset");
        btnClear.addActionListener(listenButton);
        btnClear.setActionCommand("clear");

        setLayout(new BorderLayout());
        add(panel);
        panel.add("Center", spane);
        panel.add("East", panelEast);
        panelEast.add(btnReset);
        panelEast.add(btnClear);
    }

    @Override
    public void start() {
        SystemPane.out.println("start");

        super.start();

        spane.clear();

        emu = new Emulator();
        emu.start();
    }

    @Override
    public void stop() {
        SystemPane.out.println("stop");

        super.stop();

        try {
            emu.halt();
            emu.join();
        } catch (InterruptedException e) {
            e.printStackTrace(System.err);
        }
    }

    @Override
    public void destroy() {
        SystemPane.out.println("destroy");

        super.destroy();
    }

    class ButtonListener implements ActionListener {
        public ButtonListener() {
            //do nothing
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("reset")) {
                stop();
                start();
            }
            if (e.getActionCommand().equals("clear")) {
                spane.clear();
            }
        }
    }
}

@@ -1259,32 +1259,348 @@
 uper.init();%0D%0A%0D%0A
+        if (getParameter(%22proxyHost%22) != null &&%0D%0A                getParameter(%22proxyPort%22) != null) %7B%0D%0A            System.setProperty(%22proxySet%22, %22true%22);%0D%0A            System.setProperty(%22proxyHost%22, getParameter(%22proxyHost%22));%0D%0A            System.setProperty(%22proxyPort%22, getParameter(%22proxyPort%22));%0D%0A        %7D%0D%0A%0D%0A
         ButtonLi

enable to set proxy for applet viewer.