package org.prevayler.demos.demo2.gui;

import org.prevayler.Prevayler;
import org.prevayler.foundation.Cool;

import javax.swing.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class BankFrame extends JFrame {

	private final Prevayler _prevayler;

	public BankFrame(Prevayler prevayler) {
    		super("Bank");
    		_prevayler = prevayler;
    		
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		JDesktopPane desktop = new JDesktopPane();
		setContentPane(desktop);
		new AllAccountsFrame(prevayler, desktop);
		desktop.add(new RobustnessFrame());
		desktop.add(new MatchFrame(prevayler));
		setBounds(40,40,550,420);
		setVisible(true);

		refreshClock();
	}


    private void refreshClock() {
        Thread clockRefresher = new Thread() {
            public void run() {
                DateFormat format = DateFormat.getTimeInstance();
                while (true) {
                    StringBuffer sb = new StringBuffer(18);
                    sb.append("Bank - ");
                    setTitle(format.format(_prevayler.clock().time(), sb, new java.text.FieldPosition(DateFormat.SECOND_FIELD)).toString());
                    Cool.sleep(1000);
                }
            }
        };
        clockRefresher.setDaemon(true);
        clockRefresher.start();
    }


	private static class RobustnessFrame extends JInternalFrame {
		RobustnessFrame() {
			super("Robustness Reminder", false, false, false, true);
			setContentPane(Box.createVerticalBox());
			
			addLine(" You can kill this process at any time. ");
			addLine(" When you run the application again, ");
            addLine(" you will see that nothing was lost. ");
			
			setBackground(new java.awt.Color(204,204,204));
			setBounds(300,300,235,90);
			setVisible(true);
		}
		
		private void addLine(String line) {
			JLabel label = new JLabel(line);
			label.setAlignmentX(0.5f);
			getContentPane().add(label);
		}
	}

}

@@ -158,43 +158,8 @@
 mat;
-%0Aimport java.text.SimpleDateFormat;
 %0A%0Apu

remove unused import