/*******************************************************************************
* Copyright (c)                                                                *
*           2005   Tristan Allwood,                                            *
*           2005   Daniel Burke,                                               *
*           2005   Marc Hull,                                                  *
*           2005   Ekaterina Itskova,                                          *
*           2005   Steve Zymler                                                *
*                                                                              *
* Permission is hereby granted, free of charge, to any person obtaining a      *
* copy of this software and associated documentation files (the                *
* "Software"), to deal in the Software without restriction, including          *
* without limitation the rights to use, copy, modify, merge, publish,          *
* distribute, sublicense, and/or sell copies of the Software, and to           *
* permit persons to whom the Software is furnished to do so, subject to        *
* the following conditions:                                                    *
*                                                                              *
* The above copyright notice and this permission notice shall be included      *
* in all copies or substantial portions of the Software.                       *
*                                                                              *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS      *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF                   *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.       *
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY         *
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,         *
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE            *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                       *
*******************************************************************************/
/*
 * Created on 26-Nov-2004 by toa02
 *
 */
package uk.ac.ic.doc.kevlar.experiment.tris.swing;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * @author toa02
 * 
 */
public class SwingTest {

    public static void main(String[] args) {

        final CustomTextBox tb = new CustomTextBox();
        tb.setText("Hello\nWorld");

        tb.setVisible(true);
        for (int i = 3; i < 30; i++) {
            tb.setCaretPosition(tb.getText().length());
            tb.processKeyEvent(new KeyEvent(tb, KeyEvent.KEY_TYPED, System
                    .currentTimeMillis(), 0, KeyEvent.VK_UNDEFINED, 'a'));
            tb.append(i + "\n");
        }
        tb.select(0,tb.getText().length());
        final BufferedImage bi = new BufferedImage(100, 200,
                BufferedImage.TYPE_3BYTE_BGR);

        final Graphics2D g2 = (Graphics2D) bi.getGraphics();
        g2.setBackground(Color.WHITE);
        g2.clearRect(0, 0, 100, 200);
        g2.translate(0, -100);
        g2.rotate(-0.1);
        tb.setSize(tb.getPreferredSize());
        tb.paint(g2);

        // * Below here, is swing code just to see my efforts */

        JFrame jf = new JFrame("Hello World");

        JPanel jp = new JPanel() {

            private static final long serialVersionUID = 3905237935690102324L;

            protected void paintComponent(java.awt.Graphics g) {
                super.paintComponent(g);
                g.drawImage(bi, 0, 0, null);
            }

        };

        JPanel rhs = new JPanel();

        {
            rhs.setLayout(new GridLayout(2, 1));
            final JTextArea jb2 = new JTextArea("Hello World");
            JButton jb = new JButton("Hello") {

                protected void processKeyEvent(KeyEvent e) {
                    System.out.println(e.getSource());
                    System.out.println(e.getID());
                    System.out.println(e.getKeyChar());
                    System.out.println(e.getKeyCode());
                    System.out.println(e.getModifiers());
                    jb2.getCaret().setBlinkRate(0);
                    tb.paint(g2);
                    super.processKeyEvent(e);
                }

            };
            
            
            rhs.add(jb);
            rhs.add(tb);
 
        }
        
        

        jf.setLayout(new GridLayout(1, 2));

        jp.setBackground(Color.RED);
        jp.setPreferredSize(new Dimension(100, 200));
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.add(jp);
        jf.add(rhs);
        jf.pack();
        jf.setVisible(true);
        jf.validate();
    }
}
