Package kartoMNT

Source Code of kartoMNT.MNTLoader

/**
* Fonction de chargement d'un document Karto
*
* @author HEIT Sylvestre & Coustillac Laurent
*
*
* Programme kartoMNT : g�n�ration de MNT � partir d'une carte de lignes de niveaux
* Copyright (C) 2002  HEIT Sylvestre & Coustillac Laurent
*
* Ce programme est libre, vous pouvez le redistribuer et/ou le modifier selon les termes de la Licence
*Publique G�n�rale GNU publi�e par la Free Software Foundation (version 2).
*
*Ce programme est distribu� car potentiellement utile, mais SANS AUCUNE GARANTIE, ni explicite ni implicite,
*y compris les garanties de commercialisation ou d'adaptation dans un but sp�cifique. Reportez-vous � la
*Licence Publique G�n�rale GNU pour plus de d�tails.
*
*Vous devez avoir re�u une copie de la Licence Publique G�n�rale GNU en m�me temps que ce programme ; si
*ce n'est pas le cas, �crivez � la
*Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, �tats-Unis.
*/
package kartoMNT;

import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import java.util.zip.*;
import java.awt.Frame;
import java.util.StringTokenizer;

import kartoMNT.karto.outils.MsgInfo;

public class KartoLoader
    {
        public static void load(Frame frame,DocumentKartoContainer container,String name,ActionImportImage importIm)
        {
      // Nouveau doc: c'est juste la carte
            BufferedImage bufim=BufferedImageIO.load(name);
            boolean fail=false;
            if(bufim==null){
              fail=true;
            } else {
                DocumentKartoContainer container2=container.nextDocumentKartoContainer();
                DocumentKarto c=new DocumentKarto(container2,frame);
                 c.setCarte(bufim);
                 c.setCarteFileName(name);
                c.setName(name);
        container2.addDocument(c,name);
        //c.setFileName(null);
            }
     
      try {
                if(fail){ // Cas on l'on veut importer tout un document Karto
          FileInputStream fis=new FileInputStream(name);
                    DataInputStream dis = new DataInputStream (fis);
        DocumentKartoContainer container2=container.nextDocumentKartoContainer();
                    DocumentKarto c=new DocumentKarto(container2,frame);
                    c.setFileName(name);
                    c.read(dis);

                    if(c.getCarte()==null){
      if(importIm!=null){
          MsgInfo msg=new MsgInfo(frame,MsgInfo.INFO,MsgInfo.OUI|MsgInfo.NON,c.getCarteFileName()+"\n"+ResourceManager.get("imNotFound1"));
                            if(msg.reponse()==MsgInfo.OUI)
                              importIm.actionPerformed(null);
                        }else{
                            MsgInfo msg=new MsgInfo(frame,MsgInfo.INFO,MsgInfo.OUI|MsgInfo.NON,c.getCarteFileName()+"\n"+ResourceManager.get("imNotFound2"));
                        }
                    }

                    dis.close();
                    container2.addDocument(c,name);
                }

            }catch (FileNotFoundException ex){
                    MsgInfo msg=new MsgInfo(frame,MsgInfo.INFO,MsgInfo.OK,name+"\n"+ResourceManager.get("fileNotFound"));
            }
            catch (IOException ex)
                {
                    MsgInfo msg=new MsgInfo(frame,MsgInfo.WARN,MsgInfo.OK,name+"\n"+ResourceManager.get("readError")+"\n"+ex.getMessage());
                }
            catch (DocumentKartoException ex)
                {
                    MsgInfo msg=new MsgInfo(frame,MsgInfo.INFO,MsgInfo.OK,name+"\n"+ResourceManager.get("badFormat"));
                }

        }

  /**
* Une classe pour charger un DocumentKarto d'un fichier .karto
*/
  public static DocumentKarto loadDocumentKarto(String name){
     
      DocumentKarto c=null;
      // Nouveau doc: c'est juste la carte
            BufferedImage bufim=BufferedImageIO.load(name);
            boolean fail=false;
            if(bufim==null){
              fail=true;
            } else {
               
    c=new DocumentKarto(null,null);
                 c.setCarte(bufim);
                 c.setCarteFileName(name);
                c.setName(name);       
            }

      try {
                if(fail){ // Cas on l'on veut importer tout un document Karto
        FileInputStream fis=new FileInputStream(name);
                    DataInputStream dis = new DataInputStream (fis);
       
                    c=new DocumentKarto(null,null);
                    c.setFileName(name);
                    c.read(dis);

                    if(c.getCarte()==null){
      // if(importIm!=null){
//           MsgInfo msg=new MsgInfo(null,MsgInfo.INFO,MsgInfo.OUI|MsgInfo.NON,c.getCarteFileName()+"\n"+ResourceManager.get("imNotFound1"));
//                             if(msg.reponse()==MsgInfo.OUI)
//                               importIm.actionPerformed(null);
//                         }else{

      //MsgInfo msg=new MsgInfo(null,MsgInfo.INFO,MsgInfo.OUI|MsgInfo.NON,c.getCarteFileName()+"\n"+ResourceManager.get("imNotFound2"));
      JOptionPane.showMessageDialog(null,c.getCarteFileName()+"\n"+ResourceManager.get("imNotFound2"),"Erreur",JOptionPane.WARNING_MESSAGE)

          //}
                    }

                    dis.close();
                   
                }

            }catch (FileNotFoundException ex){
    //MsgInfo msg=new MsgInfo(null,MsgInfo.INFO,MsgInfo.OK,name+"\n"+ResourceManager.get("fileNotFound"));
    JOptionPane.showMessageDialog(null,name+"\n"+ResourceManager.get("fileNotFound"),"Erreur",JOptionPane.WARNING_MESSAGE)
            }
            catch (IOException ex)
                {
                    //MsgInfo msg=new MsgInfo(null,MsgInfo.WARN,MsgInfo.OK,name+"\n"+ResourceManager.get("readError")+"\n"+ex.getMessage());
        JOptionPane.showMessageDialog(null,name+"\n"+ResourceManager.get("readError")+"\n"+ex.getMessage(),"Erreur",JOptionPane.WARNING_MESSAGE)
                }
            catch (DocumentKartoException ex)
                {
                    //MsgInfo msg=new MsgInfo(null,MsgInfo.INFO,MsgInfo.OK,name+"\n"+ResourceManager.get("badFormat"));
        JOptionPane.showMessageDialog(null,name+"\n"+ResourceManager.get("badFormat"),"Erreur",JOptionPane.WARNING_MESSAGE);
                }
      return c;
  }
   



};



/**
* Une classe pour charger les MNT
*/
class MNTLoader {
       
    static void load(Frame frame,DocumentMNTContainer container,String name,MntFormat format){
  try {
     
      DocumentMNTContainer container2=container.nextDocumentMNTContainer();
           
        DocumentMNT doct = new DocumentMNT(container2);
        doct.setFileName(name);
           
        
       MNT mnt = format.importMNT(name);
           
        doct.setMNT(mnt);
         
        container2.addDocument(doct,name);

  }catch (FileNotFoundException ex){
      MsgInfo msg=new MsgInfo(frame,MsgInfo.INFO,MsgInfo.OK,name+"\n"+ResourceManager.get("fileNotFound"));
  }
  catch (IOException ex)
      {
    MsgInfo msg=new MsgInfo(frame,MsgInfo.INFO,MsgInfo.OK,name+"\n"+ResourceManager.get("readError")+"\n"+ex.getMessage());
      }
           
    }
       
       
};

TOP

Related Classes of kartoMNT.MNTLoader

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.