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

/**
 * Fenetre affichant le resultat 
 * @author Delphine Dard, Aout 2001
 */
public class ResultatFrame extends Frame 
    implements ActionListener{

    /** partie pour les calculs */
    public Ccd ccd;
    /** L'image 41*41 obtenue */
    public CCDImage ccdImage;    
    /** le graphe de la ligne 21 */
    public CCDGraphe ccdGraphe;
    /** les infos prises en compte */
    public CCDInfosCanvas ccdInfosCanvas;

    JPanel panel;
    JLabel messages;
    JPanel panelGraphe;


    /**
     * Constructeur
     */
    public ResultatFrame(){
	super("Resultats");
	setBackground(Color.white);
	setLayout(new BorderLayout());

	ccd = new Ccd(this);
	
	ccdImage = new CCDImage();
	ccdGraphe = new CCDGraphe();	
	ccdInfosCanvas = new CCDInfosCanvas(ccd);

	messages = new JLabel(" ", JLabel.CENTER);

	JPanel topPanel = new JPanel();
	topPanel.setBackground(Color.white);
	topPanel.setLayout(new BorderLayout());

	panel = new JPanel();
	placeComposants();
	topPanel.add("Center",panel);

	Panel boutons = new Panel();
	boutons.setLayout(new FlowLayout());
	JButton ok = new JButton("Ok"); 
	ok.addActionListener(this);
	boutons.add(ok);

	
	topPanel.add("South", boutons);
	Border matte = BorderFactory.createMatteBorder(10, 0, 0, 0, Color.white);
	topPanel.setBorder(matte);

	add("Center", topPanel);
    }

    /**
     * action lorsqu'on clique Ok
     */
    public void actionPerformed(ActionEvent e){
	if (e.getActionCommand() == "Ok") {
	    dispose();
	}
    }
    

    /**
     * Affichage
     */
    public void paint(Graphics g){
	ccdImage.repaint();
	ccdGraphe.repaint();
	ccdInfosCanvas.repaint();
	pack();
    }

    /**
     * Transmet de nouvelles valeurs et reaffiche
     * @param magnitude la magnitude
     * @param seeing le seeing
     * @param diametre le diametre
     * @param integration le temps d'integration
     * @param focale la focale
     * @param gain le gain
     * @param jour le nombre de jours depuis la nouvelle lune
     */

    public void newValeur(float magnitude,
			  float seeing,
			  float diametre,
			  float integration,
			  float focale,
			  float gain,
			  int jour) {
	ccd.setValeur(magnitude,
		      seeing,
		      diametre,
		      integration,
		      focale,
		      gain,
 		      jour);
	int[] pix = ccd.intensitePixels();
	int[] ligne = ccd.getLigne21();
	ccdImage.setNewImage(pix);
	ccdGraphe.setNewGraphe(ligne);

	repaint();
    }

    /**
     * Message affiché lorsque la focale est trop grande
     */
    public void tailleFocaleMessage(){    
	String string = "Attention ! La focale est trop longue !";
	string = string + " La taille des pixels sur le ciel est trop grande par rapport au seeing !";
	JOptionPane.showMessageDialog((Component)this, string);
    }

    /**
     * Message affiché lorsque l'image est saturée
     */       
    public void saturationMessage(){
	JOptionPane.showMessageDialog((Component)this, "Attention ! Image saturée !");
    }

    /**
     * place les différents composants dans la fenetre
     */
    public void placeComposants(){
	JPanel panelImage = new JPanel(new GridLayout(1,1));
	panelImage.setBackground(Color.white);
 	panelImage.add(ccdImage);
	panelImage.setPreferredSize(new Dimension(275, ccdImage.bordY*2+41*4+20)); 
	panelImage.setMinimumSize(new Dimension(275, ccdImage.bordY*2+41*4+20)); 
	panelImage.setAlignmentX(CENTER_ALIGNMENT);
	panelImage.setAlignmentY(CENTER_ALIGNMENT);

	JPanel panelInfos = new JPanel(new GridLayout(1,1));
	panelInfos.setBackground(Color.white);
 	panelInfos.add(ccdInfosCanvas);
	panelInfos.setPreferredSize(new Dimension(250, 75)); 
	panelInfos.setMinimumSize(new Dimension(250, 75)); 
	panelInfos.setAlignmentX(CENTER_ALIGNMENT);
	panelInfos.setAlignmentY(CENTER_ALIGNMENT);

	panelGraphe = new JPanel(new GridLayout(1,1));
	panelGraphe.setBackground(Color.white);
	panelGraphe.add(ccdGraphe);
	panelGraphe.setPreferredSize(new Dimension(275, ccdGraphe.coordonneeOx+40)); 
	panelGraphe.setMinimumSize(new Dimension(275, ccdGraphe.coordonneeOx+40)); 
	panelGraphe.setAlignmentX(CENTER_ALIGNMENT);
	panelGraphe.setAlignmentY(CENTER_ALIGNMENT);

	panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	panel.setBackground(Color.white);
	panel.add(panelGraphe);
	panel.add(panelImage);
	panel.add(Box.createRigidArea(new Dimension(0,10)));
	panel.add(panelInfos);
	panel.add(Box.createRigidArea(new Dimension(0,10)));

    }

    public static void main(String args[]) {
	ResultatFrame res = new ResultatFrame();
	res.setSize(700,500);
	res.show();
    }

}
