Package modele

Source Code of modele.Modele

package modele;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;

import javax.swing.event.EventListenerList;

import controller.Controller;

import modele.event.HeureChangedEvent;

public class Modele {
 
  private Seance seance = null;
  private int derniereHeure = -1;
 
  private EventListenerList listeners = null;
 
  public Modele(){
    this.listeners = new EventListenerList();
   
    this.seance = new Seance(this);
  }
 
  ////////////////////////
  // METHODE CONTROLEUR //
  ////////////////////////
 
  public void addConsoleListener(Listener l){
    this.listeners.add(Listener.class, l);
   
    l.demanderInfo();
  }
 
  public void addGUIListener(Listener l){
    this.listeners.add(Listener.class, l);
   
    l.demanderInfo();
  }
 
  public void removeListener(Listener l){
    this.listeners.remove(Listener.class, l);
  }
 
  public void fireHeureChanged(int coef, float niveau, int heure, float debit, int pm, double d, boolean vanneStockVideStatus, int diff, double hauteur){
    // Ecriture dans un fichier log
//    System.out.println(System.getProperty("user.home")+File.separator+"AppData"+File.separator+"Stade"+File.separator+"log");
    File logDirectory = new File(System.getProperty("user.home")+File.separator+"AppData"+File.separator+"Local"+File.separator+"Stade");
    File log = new File(System.getProperty("user.home")+File.separator+"AppData"+File.separator+"Local"+File.separator+"Stade"+File.separator+"log.txt");
    if(!logDirectory.exists()){
      logDirectory.mkdir();
    }
    Calendar c = Calendar.getInstance();
   
    try{
      FileWriter logWriter = new FileWriter(log, true);
     
      logWriter.write("Date : "+c.getTime()+"\r\n");
      logWriter.flush();
      logWriter.write("Coefficicent : "+coef+"\r\n");
      logWriter.flush();
      logWriter.write("Heure : "+heure+"h"+"\r\n");
      logWriter.flush();
      logWriter.write("D�bit : "+debit+"\r\n");
      logWriter.flush();
      if(d == 0){
        logWriter.write("Vanne omniFlot ferm� ( angle = "+d+"� )"+"\r\n");
      } else {
        logWriter.write("Vanne omniFlot ouverte ( angle = "+d+"� )"+"\r\n");
      }
      logWriter.flush();
      if(vanneStockVideStatus){
        logWriter.write("Vanne stockVide ferm�"+"\r\n");
      } else {
        logWriter.write("Vanne stockVode ouverte"+"\r\n");
      }
      logWriter.flush();
      logWriter.write("\r\n\r\n");
      logWriter.flush();
     
      logWriter.close();
    } catch(IOException e){
      e.printStackTrace();
    }
   
    // Notification ecouteurs
    Listener[] listenerList = (Listener[])listeners.getListeners(Listener.class);

    for(Listener listener : listenerList){
      listener.heureChanged(new HeureChangedEvent(this, coef, niveau, heure, debit, pm, d, vanneStockVideStatus, diff, hauteur));
    }
  }
   
  public void fireVerifKayakiste() {
    Listener[] listenerList = (Listener[])listeners.getListeners(Listener.class);

    for(Listener listener : listenerList){
      listener.verifKayakiste();
   
  }
 
  public void fireNouvelleSeance() {
    Listener[] listenerList = (Listener[])listeners.getListeners(Listener.class);

    for(Listener listener : listenerList){
      listener.nouvelleSeance();
   
  }
 
  public void fireFirstHourChanged(int coef, float niveau, int heure, float debit, int pm, double d, boolean vanneStockVideStatus, int diff, double hauteur) {
    Listener[] listenerList = (Listener[])listeners.getListeners(Listener.class);

    for(Listener listener : listenerList){
      listener.firstHour(new HeureChangedEvent(this, coef, niveau, heure, debit, pm, d, vanneStockVideStatus, diff, hauteur));
    }
  }
 
  ///////////////////////
  // METHODE DU MODELE //
  ///////////////////////
 
  public void quandDemarrerClick(int coef, int diff){
    // Une vue viens de valider le demarrage
    // Lancement dans la s�ance
    seance.demarrer(coef, diff);
  }
 
  public void quandDemarrerClick(int coef, int diff, int heure, int heurePM) {
    seance.demarrer(coef, diff, heure, heurePM);
  }
 
  public void quandDemarrerClickNouvelleSeance(int coef, int diff) {
    seance.demarrerNouvelleSeance(coef, diff);
  }

  public void quandDemarrerClickNouvelleSeance(int coef, int diff, int heure, int heurePM) {
    seance.demarrerNouvelleSeance(coef, diff, heure, heurePM);
  }
 
  public void afficher(){
   
  }
 
  public void notifyPlusDeKayakiste() {
    seance.notifyPlusDeKayakiste();
  }
 
  public void notifyChangeStatus() {
    seance.notifyChangeStatus();
  }
 
  public void notifyRetour() {
    seance.notifyRetour();
  }

  public void notifySuite() {
    seance.notifySuite();
  }
 
  //////////
  // MAIN //
  //////////
 
  public static void main(String[] args) {
    Modele m = new Modele();
    Controller c = new Controller(m);
    c.displayViews();
  }
}
TOP

Related Classes of modele.Modele

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.