//----------------------------------------------------------------------
//----------------------------------------------------------------------
//
//		--------------------
//		 Editeur A S C I I:
//		--------------------
//
//----------------------------------------------------------------------
//----------------------------------------------------------------------

import		java.io.*;
import		java.awt.*;
import		java.awt.event.*;

//----------------------------------------------------------------------
//----------------------------------------------------------------------

/**
 *	Editeur simple de fichiers textes.
 */
public
class		Editor			extends		Panel
					implements	ActionListener
	{
// debut de classe
//----------------------------------------------------------------------

static
void		a			(String s)
	{
	System.out.println(s);
	}

static
String		fName			= "Editor.java";

public
String		getFName		()
	{
	return	fName;
	}

public
void		setFName		(String p)
	{
	fName = new String(p);
	}

public
void		lecture			()
					throws		Exception
	{
	BufferedReader	theIn	= new BufferedReader
		(new InputStreamReader
		 (new FileInputStream(fName)));

	String	l	= theIn.readLine();
	while	(l != null)
		{
		theText.append(l+"\n");
		l	= theIn.readLine();
		}

	
	theIn.close();
	}

public
void		ecriture		()
					throws		Exception
	{
	PrintStream	theOut	= new PrintStream
		(new BufferedOutputStream
		 (new FileOutputStream(fName)));

	theOut.println(theText.getText());
	
	theOut.flush();
	theOut.close();
	}

TextArea	theText;
TextField	theName;
Panel		theButtons;
Button		bRead;
Button		bSave;
Button		bReset;

		Editor			()
	{
	super();

	theText		= new TextArea(20, 20);
	theName		= new TextField(50);
	theButtons	= new Panel();
	bRead		= new Button("read");
	bSave		= new Button("save");
	bReset		= new Button("reset");
	bRead	.addActionListener(this);
	bSave	.addActionListener(this);
	bReset	.addActionListener(this);
	theButtons.add(bRead);
	theButtons.add(bSave);
	theButtons.add(bReset);

	this.setLayout(new BorderLayout());
	this.add(theName,	BorderLayout.NORTH);
	this.add(theButtons,	BorderLayout.SOUTH);
	this.add(theText,	BorderLayout.CENTER);
	}
		
public
void		actionPerformed		(ActionEvent evt)
	{
	a("I've been clicked !");
	if	(evt.getSource().equals(bRead)	)	a("\tI'm bRead...");
	if	(evt.getSource().equals(bSave)	)	a("\tI'm bSave...");
	if	(evt.getSource().equals(bReset)	)	a("\tI'm bReset...");
	}
		
/**
 *	Point d'entr&eacute;e: pour les tests uniquement !
 */
static
public
void		main			(String[] args)
					throws		Exception
	{
	a(" ");
	a("--------------------------------");
	a(" Petit editeur de textes ascii: ");
	a("--------------------------------");

	a("\nB.M.G. version 2014 Hiver ");

	Editor		theEditor	= new Editor();
	
	Frame		theFrame	= new Frame("test edition de textes");
	theFrame.add(theEditor);
	
	theFrame.setSize(400, 400);
	theFrame.validate();
	theFrame.setVisible(true);

	theEditor	.theName	.setText("Editor.java");
	theEditor	.lecture();
	}

//----------------------------------------------------------------------
// fin de classe
	}

//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------
//----------------------------------------------------------------------

