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

class MessagesPanel extends JPanel implements FocusListener{
	
	///JTextPane messagesList=new JTextPane();
	private JScrollPane scroll;
	
	private String messages=new String();
	
	private JTextBackdrop messagesList = new JTextBackdrop("");
	
	private PanneauJeu jeuPan;
	
	private short nbrLignes=0;
	
	public MessagesPanel(PanneauJeu pj){
		Font police=pj.getPolice();
		jeuPan=pj;
		
		setLayout(null);
		
		
		scroll = new JScrollPane(messagesList);
		scroll.setBounds(0,0,640,160);
		add(scroll);
		
		
		
		//retour à ligne automatique
		messagesList.setLineWrap(true);
		
		//pas de coupure des mots
		messagesList.setWrapStyleWord(true);
		
		messagesList.setEditable(false);
		messagesList.addFocusListener(this);
		
		
		messagesList.setBackground(new Color(200,200,200)); 
		messagesList.setFont(police);
	}
	
	
	
	public void remplissageMessages(String mess,boolean langMess){
		//System.out.println(messagesList.getDocument().getLength ());
		
		
		
		nbrLignes++;
		//System.out.println("NBRE LIGNE "+nbrLignes);
		
		if(nbrLignes>100){messagesList.setText("");nbrLignes=0;}
		
		
		
		if(jeuPan.lang && langMess){
			messagesList.append(mess+"\n");
			
			//scrolling automatique
			try { 
	        messagesList.scrollRectToVisible(messagesList.modelToView(messagesList.getDocument().getLength ())); 
			} catch (javax.swing.text.BadLocationException err) { }
		}
		
		if(!jeuPan.lang && !langMess){
			messagesList.append(mess+"\n");
			
			//scrolling automatique
			try { 
	        messagesList.scrollRectToVisible(messagesList.modelToView(messagesList.getDocument().getLength ())); 
			} catch (javax.swing.text.BadLocationException err) { }
		}
		
			
		
		
		
	}
	
	
	public void focusGained(FocusEvent e){
		//System.out.println("focus messages");
		jeuPan.requestFocus();
	}
	
	public void focusLost(FocusEvent e){
		
	}	
	
}


