250 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
		
		
			
		
	
	
			250 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//  Generated by StarUML(tm) Java Add-In
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//  @ Project : Untitled
							 | 
						||
| 
								 | 
							
								//  @ File Name : IHM_Acteur.java
							 | 
						||
| 
								 | 
							
								//  @ Date : 20/01/2008
							 | 
						||
| 
								 | 
							
								//  @ Author : 
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								package IHM;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import Documents.Element;
							 | 
						||
| 
								 | 
							
								import java.io.*;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								public  class IHM_Acteur {
							 | 
						||
| 
								 | 
							
								        public Gestion.Fabrique gestionnaire =  Gestion.Fabrique.getInstance();
							 | 
						||
| 
								 | 
							
								          
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
									public void AfficherDoc()  {
							 | 
						||
| 
								 | 
							
								            int ref = 0;
							 | 
						||
| 
								 | 
							
								            System.out.println("Entrez le numero du document à afficher:");
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								            try {ref = new Integer(bfr.readLine());}
							 | 
						||
| 
								 | 
							
								            catch(IOException e) {e.printStackTrace();}
							 | 
						||
| 
								 | 
							
								            try{System.out.println(gestionnaire.getElement(ref).afficher());}
							 | 
						||
| 
								 | 
							
								            catch(IndexOutOfBoundsException e) {System.out.println("Element inexistant!");}
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									public Documents.Element getDocument() {
							 | 
						||
| 
								 | 
							
								            int ref = 0;
							 | 
						||
| 
								 | 
							
								            System.out.println("Entrez le numero du document dans lequel ajouter l'element:");
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								            try {ref = new Integer(bfr.readLine());}
							 | 
						||
| 
								 | 
							
								            catch(IOException e) {e.printStackTrace();}
							 | 
						||
| 
								 | 
							
								            try{return gestionnaire.getElement(ref);}
							 | 
						||
| 
								 | 
							
								            catch(IndexOutOfBoundsException e) {System.out.println("Element inexistant!");}
							 | 
						||
| 
								 | 
							
								            return null;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
									public  void listeDocuments() {
							 | 
						||
| 
								 | 
							
								            for(int i = 1; i < gestionnaire.documents.size();i++)
							 | 
						||
| 
								 | 
							
								            {
							 | 
						||
| 
								 | 
							
								                Element e = gestionnaire.getElement(i);        
							 | 
						||
| 
								 | 
							
								                if(e instanceof Documents.Section)
							 | 
						||
| 
								 | 
							
								                {
							 | 
						||
| 
								 | 
							
								                    if(e.getNiveau() == 0)
							 | 
						||
| 
								 | 
							
								                       System.out.println(e.afficher());
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								            try{new BufferedReader(new InputStreamReader(System.in)).readLine();}
							 | 
						||
| 
								 | 
							
								            catch(IOException e) {}
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								        public void noter() {
							 | 
						||
| 
								 | 
							
								            int ref = 0;
							 | 
						||
| 
								 | 
							
								            System.out.println("Entrez le numero du document à noter:");
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								            try {ref = new Integer(bfr.readLine());}
							 | 
						||
| 
								 | 
							
								            catch(IOException e) {e.printStackTrace();}
							 | 
						||
| 
								 | 
							
								            try{
							 | 
						||
| 
								 | 
							
								                Element el = gestionnaire.getElement(ref);
							 | 
						||
| 
								 | 
							
								                System.out.println("Entrez la note:");
							 | 
						||
| 
								 | 
							
								                try {int note = new Integer(bfr.readLine());
							 | 
						||
| 
								 | 
							
								                    el.setCoeff(note);
							 | 
						||
| 
								 | 
							
								                    }
							 | 
						||
| 
								 | 
							
								                catch(IOException e) {System.out.println("La note entrée n'est pas correcte!");}
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								            catch(IndexOutOfBoundsException e) {System.out.println("Element inexistant!");
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								            
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public void annoter() {
							 | 
						||
| 
								 | 
							
									    int ref = 0;
							 | 
						||
| 
								 | 
							
								            System.out.println("Entrez le numero du document à noter:");
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								            try {ref = new Integer(bfr.readLine());}
							 | 
						||
| 
								 | 
							
								            catch(IOException e) {e.printStackTrace();}
							 | 
						||
| 
								 | 
							
								            try{
							 | 
						||
| 
								 | 
							
								                Element el = gestionnaire.getElement(ref);
							 | 
						||
| 
								 | 
							
								                System.out.println("Entrez l'annotation:");
							 | 
						||
| 
								 | 
							
								                try {
							 | 
						||
| 
								 | 
							
								                    String annot = bfr.readLine();
							 | 
						||
| 
								 | 
							
								                    el.setAnnotation(annot);
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								                catch(IOException e) {System.out.println("Entrée incorrecte!");}
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								            catch(IndexOutOfBoundsException e) {System.out.println("Element inexistant!");
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								        public void creerDocument() {
							 | 
						||
| 
								 | 
							
								         System.out.println("Entrez le titre du document :");
							 | 
						||
| 
								 | 
							
								         BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								         String titre="";
							 | 
						||
| 
								 | 
							
								            try {
							 | 
						||
| 
								 | 
							
								                      /** Lecture d'une ligne : */
							 | 
						||
| 
								 | 
							
								                titre = bfr.readLine();
							 | 
						||
| 
								 | 
							
								                this.gestionnaire.CreateElem(titre);
							 | 
						||
| 
								 | 
							
								            } catch( IOException e ) {System.out.println("Titre incorrect");} 
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									public void modifierDocument(int ref) {
							 | 
						||
| 
								 | 
							
									//Redacteur
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								        public int identifier() {
							 | 
						||
| 
								 | 
							
								            int rep = 1;
							 | 
						||
| 
								 | 
							
								            System.out.println("Pour vous logguer en tant que redacteur, entrez votre code de 3 lettres: (FIN pour quitter) ");
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								            String code="";
							 | 
						||
| 
								 | 
							
								            try {
							 | 
						||
| 
								 | 
							
								                      /** Lecture d'une ligne : */
							 | 
						||
| 
								 | 
							
								                code = bfr.readLine();
							 | 
						||
| 
								 | 
							
								            } catch( IOException e ) {e.printStackTrace();} 
							 | 
						||
| 
								 | 
							
								            if(code.equals("RED"))
							 | 
						||
| 
								 | 
							
								            {rep = 2;}
							 | 
						||
| 
								 | 
							
								            else if (code.equals("FIN"))
							 | 
						||
| 
								 | 
							
								            {rep = 3;}
							 | 
						||
| 
								 | 
							
								            return rep;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public static void main(String[] args){
							 | 
						||
| 
								 | 
							
								           IHM_Acteur ihm = new IHM_Acteur();
							 | 
						||
| 
								 | 
							
								           int type = ihm.identifier();
							 | 
						||
| 
								 | 
							
								            while(type != 3)
							 | 
						||
| 
								 | 
							
								            {
							 | 
						||
| 
								 | 
							
								                if(type == 1)
							 | 
						||
| 
								 | 
							
								                { ihmLecteur(ihm);}
							 | 
						||
| 
								 | 
							
								                else
							 | 
						||
| 
								 | 
							
								                {ihmRedacteur(ihm);}
							 | 
						||
| 
								 | 
							
								                type= ihm.identifier();
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public static void ihmLecteur(IHM_Acteur ihm) 
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            String ligne = "";
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            while(!(ligne.equals("FIN")))
							 | 
						||
| 
								 | 
							
								            {
							 | 
						||
| 
								 | 
							
								                menuLec();
							 | 
						||
| 
								 | 
							
								                try {
							 | 
						||
| 
								 | 
							
								                System.out.println("Entrez votre choix: ");
							 | 
						||
| 
								 | 
							
								                ligne = bfr.readLine();
							 | 
						||
| 
								 | 
							
								                }catch( IOException e ) {e.printStackTrace();} 
							 | 
						||
| 
								 | 
							
								                
							 | 
						||
| 
								 | 
							
								                int choix = new Integer(ligne);
							 | 
						||
| 
								 | 
							
								                switch(choix) {
							 | 
						||
| 
								 | 
							
								                    case 1: ihm.listeDocuments(); break;
							 | 
						||
| 
								 | 
							
								                    case 2: ihm.AfficherDoc(); break;
							 | 
						||
| 
								 | 
							
								                    case 3: ihm.annoter(); break;
							 | 
						||
| 
								 | 
							
								                    case 4: ihm.noter(); break;
							 | 
						||
| 
								 | 
							
								                    case 5: ligne = "FIN"; break;
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public void creerElement(IHM_Acteur ihm)
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            String ligne ="";
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								             menuElem();
							 | 
						||
| 
								 | 
							
								             try {
							 | 
						||
| 
								 | 
							
								                System.out.println("Entrez votre choix: ");
							 | 
						||
| 
								 | 
							
								                ligne = bfr.readLine();
							 | 
						||
| 
								 | 
							
								                }catch( IOException e ) {e.printStackTrace();} 
							 | 
						||
| 
								 | 
							
								                
							 | 
						||
| 
								 | 
							
								                int choix = new Integer(ligne);
							 | 
						||
| 
								 | 
							
								                switch(choix) {
							 | 
						||
| 
								 | 
							
								                    case 1: ihm.listeDocuments(); break;
							 | 
						||
| 
								 | 
							
								                    case 2: ihm.creerSection(); break;
							 | 
						||
| 
								 | 
							
								                    case 3: ihm.creerTexte(); break;
							 | 
						||
| 
								 | 
							
								                    case 4: //ihm.creerImage(); break;
							 | 
						||
| 
								 | 
							
								                    case 5: ligne = "FIN"; break;
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								            
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public static void ihmRedacteur(IHM_Acteur ihm)
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								             String ligne = "";
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								            while(!ligne.equals("FIN"))
							 | 
						||
| 
								 | 
							
								            {
							 | 
						||
| 
								 | 
							
								                menuRed();
							 | 
						||
| 
								 | 
							
								                try {
							 | 
						||
| 
								 | 
							
								                System.out.println("Entrez votre choix: (FIN pour quitter)");
							 | 
						||
| 
								 | 
							
								                ligne = bfr.readLine();
							 | 
						||
| 
								 | 
							
								                int choix = new Integer(ligne);
							 | 
						||
| 
								 | 
							
								                switch(choix) {
							 | 
						||
| 
								 | 
							
								                    case 1: ihm.listeDocuments(); break;
							 | 
						||
| 
								 | 
							
								                    case 2: ihm.AfficherDoc(); break;
							 | 
						||
| 
								 | 
							
								                    case 3: ihm.creerDocument(); break;
							 | 
						||
| 
								 | 
							
								                    case 4: ihm.creerElement(ihm); break;
							 | 
						||
| 
								 | 
							
								                    case 5: ihm.modifierDocument(choix); break;
							 | 
						||
| 
								 | 
							
								                    case 6: ligne = "FIN"; break;
							 | 
						||
| 
								 | 
							
								                }
							 | 
						||
| 
								 | 
							
								                }catch( IOException e ) {e.printStackTrace();} 
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public void creerSection() {
							 | 
						||
| 
								 | 
							
								            Documents.Section el = (Documents.Section) this.getDocument();
							 | 
						||
| 
								 | 
							
								            System.out.println("Entrez le titre de la section à ajouter:");
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								            try{String titre = bfr.readLine();
							 | 
						||
| 
								 | 
							
								            Documents.Section sec= this.gestionnaire.CreateElem(titre);
							 | 
						||
| 
								 | 
							
								            if(sec == null)
							 | 
						||
| 
								 | 
							
								            {return;}
							 | 
						||
| 
								 | 
							
								            el.addElement(sec);}
							 | 
						||
| 
								 | 
							
								            catch(IOException e) {System.out.println("Pas bien!");}
							 | 
						||
| 
								 | 
							
								            
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public void creerTexte() {
							 | 
						||
| 
								 | 
							
								            Documents.Section el = (Documents.Section) this.getDocument();
							 | 
						||
| 
								 | 
							
								            System.out.println("Entrez l'auteur du texte:");
							 | 
						||
| 
								 | 
							
								            BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
							 | 
						||
| 
								 | 
							
								            try{String auteur = bfr.readLine();
							 | 
						||
| 
								 | 
							
								                System.out.println("Saisissez le texte:");
							 | 
						||
| 
								 | 
							
								                String texte = bfr.readLine();
							 | 
						||
| 
								 | 
							
								            Documents.Texte txt= this.gestionnaire.CreateElem(texte, auteur);
							 | 
						||
| 
								 | 
							
								            if(txt == null)
							 | 
						||
| 
								 | 
							
								            {return;}
							 | 
						||
| 
								 | 
							
								            el.addElement(txt);}
							 | 
						||
| 
								 | 
							
								            catch(IOException e) {System.out.println("Pas bien!");}
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public static void menuLec() {
							 | 
						||
| 
								 | 
							
								           System.out.println("1: Lister les documents");        
							 | 
						||
| 
								 | 
							
								           System.out.println("2: Afficher un document");
							 | 
						||
| 
								 | 
							
								           System.out.println("3: Annoter un document");
							 | 
						||
| 
								 | 
							
								           System.out.println("4: Noter un document");
							 | 
						||
| 
								 | 
							
								           System.out.println("5: Se déconnecter");
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								         public static void menuRed() {
							 | 
						||
| 
								 | 
							
								           System.out.println("1: Lister les documents");        
							 | 
						||
| 
								 | 
							
								           System.out.println("2: Afficher un document");
							 | 
						||
| 
								 | 
							
								           System.out.println("3: Créer un document");
							 | 
						||
| 
								 | 
							
								           System.out.println("4: Créer un element et l'ajouter");
							 | 
						||
| 
								 | 
							
								           System.out.println("5: Modifier un element");
							 | 
						||
| 
								 | 
							
								           System.out.println("6: Se déconnecter");
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        public static void menuElem() {
							 | 
						||
| 
								 | 
							
								           System.out.println("1: Lister les documents");        
							 | 
						||
| 
								 | 
							
								           System.out.println("2: Créer et ajouter une section");
							 | 
						||
| 
								 | 
							
								           System.out.println("3: Créer et ajouter un texte");
							 | 
						||
| 
								 | 
							
								           System.out.println("4: Créer et ajouter une image");
							 | 
						||
| 
								 | 
							
								           System.out.println("5: Revenir au menu");
							 | 
						||
| 
								 | 
							
								        
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								}
							 |