/*
 * Statistics.java, 17 févr. 2006
 * 
 * This file is part of FilmZ.
 *
 * Copyright © 2006 Johan Cwiklinski
 *
 * File :               Statistics.java
 * Author's email :     johan@x-tnd.be
 * Author's Website :   http://www.x-tnd.be/
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 */

/**
 * 
 */
package be.xtnd.gui;

import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.text.MessageFormat;

import javax.swing.JLabel;
import javax.swing.JLayeredPane;

import be.xtnd.commons.gui.EscapeInternalFrame;
import be.xtnd.commons.gui.MainGui;
import be.xtnd.films.Acteur;
import be.xtnd.films.Film;
import be.xtnd.films.Genre;
import be.xtnd.films.Origine;
import be.xtnd.films.Realisateur;
import be.xtnd.films.gui.Messages;

import com.jeta.forms.components.border.TitledBorderLabel;
import com.jeta.forms.components.panel.FormPanel;
import com.jeta.forms.components.separator.TitledSeparator;
import com.jgoodies.looks.plastic.PlasticInternalFrameUI;

/**
 * Affiche les statistiques de la base de données
 * @author Johan Cwiklinski
 * @version 1.0
 */
public class Statistics extends EscapeInternalFrame{
	private static final long serialVersionUID = 4618294835296363753L;
	/** Nom de la fenêtre */
	public static final String NAME = "statistics";
	private JLabel movies, label_movies, actors, label_actors, types, label_types,
		directors, label_directors, origins, label_origins, label_db, db, label_version_db,
		version_db, label_user_db, user_db, label_driver_db, driver_db, label_driver_db_version,
		driver_db_version;
	private TitledSeparator label_title;
	private TitledBorderLabel db_title;
	private DatabaseMetaData dmd;
	
	/** Constructeur */
	public Statistics(){
		super();
		FormPanel pane = new FormPanel( "be/xtnd/gui/descriptions/stats.jfrm" );
		super.setName(NAME);
		
        putClientProperty(
                PlasticInternalFrameUI.IS_PALETTE,
                Boolean.TRUE);	        

        label_title = (TitledSeparator)pane.getComponentByName("label_title");
        label_title.setText(MessageFormat.format(Messages.getString("window.statistics.title"),
        		Messages.getString("appli.name")+" "+Messages.getString("appli.version")));
        
        db_title = (TitledBorderLabel)pane.getComponentByName("db_title");
        db_title.setText(Messages.getString("window.statistics.database.title"));
        
        label_db = pane.getLabel("label_db");
        label_db.setText(Messages.getString("window.statistics.database"));
        db = pane.getLabel("db");
        
        label_version_db = pane.getLabel("label_version_db");
        label_version_db.setText(Messages.getString("window.statistics.database.version"));
        version_db = pane.getLabel("version_db");
        
        label_user_db = pane.getLabel("label_user_db");
        label_user_db.setText(Messages.getString("window.statistics.database.user"));
        user_db = pane.getLabel("user_db");
        
        label_driver_db = pane.getLabel("label_driver_db");
        label_driver_db.setText(Messages.getString("window.statistics.database.driver"));
        driver_db = pane.getLabel("driver_db");
        
        label_driver_db_version = pane.getLabel("label_driver_db_version");
        label_driver_db_version.setText(Messages.getString("window.statistics.database.version"));
        driver_db_version = pane.getLabel("driver_db_version");
        
        try {
			dmd = FilmzMain.db.getConnection().getMetaData();
			db.setText(dmd.getDatabaseProductName());
			version_db.setText(dmd.getDatabaseProductVersion());
			user_db.setText(dmd.getUserName());
			driver_db.setText(dmd.getDriverName());
			driver_db_version.setText(dmd.getDriverVersion());
		} catch (SQLException e) {e.printStackTrace();}
		
        label_movies = pane.getLabel("label_movies");
        label_movies.setText(Messages.getString("window.statistics.movies"));
        movies = pane.getLabel("movies");      
        movies.setText(MessageFormat.format(Messages.getString("window.statistics.records"), Film.countFilms().toString()));
        
        label_actors = pane.getLabel("label_actors");
        label_actors.setText(Messages.getString("window.statistics.actors"));
        actors = pane.getLabel("actors");
        actors.setText(MessageFormat.format(Messages.getString("window.statistics.records"), new Acteur().getCount().toString()));
        
        label_types = pane.getLabel("label_types");
        label_types.setText(Messages.getString("window.statistics.types"));
        types = pane.getLabel("types");
        types.setText(MessageFormat.format(Messages.getString("window.statistics.records"), new Genre().getCount().toString()));
        
        label_directors = pane.getLabel("label_directors");
        label_directors.setText(Messages.getString("window.statistics.directors"));
        directors = pane.getLabel("directors");
        directors.setText(MessageFormat.format(Messages.getString("window.statistics.records"), new Realisateur().getCount().toString()));
        
        label_origins = pane.getLabel("label_origins");
        label_origins.setText(Messages.getString("window.statistics.origins"));
        origins = pane.getLabel("origins");
        origins.setText(MessageFormat.format(Messages.getString("window.statistics.records"), new Origine().getCount().toString()));
        
		add(pane);

		pack();

		setLocation(MainGui.centerOnDesktop(this.getSize()));
		setMinimumSize(getSize());
		setVisible(true);
		setClosable(true);
		setIconifiable(true);
		setResizable(true);
		MainGui.desktop.add(this, JLayeredPane.POPUP_LAYER);
	}
}