From: Frederic D. <de...@us...> - 2004-04-02 14:14:48
|
Update of /cvsroot/fudaa/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25282/src/org/fudaa/fudaa/commun Modified Files: FudaaLib.java Added Files: FudaaProgressionAdapter.java Log Message: Maj pour matisse test --- NEW FILE: FudaaProgressionAdapter.java --- /* * @file FudaaProgressionAdapter.java * @creation 2 avr. 2004 * @modification $Date: 2004/04/02 14:02:39 $ * @license GNU General Public License 2 * @copyright (c)1998-2001 CETMEF 2 bd Gambetta F-60231 Compiegne * @mail fud...@li... */ package org.fudaa.fudaa.commun; import com.memoire.bu.BuProgressBar; import org.fudaa.dodico.commun.ProgressionInterface; /** * @author Fred Deniger * @version $Id: FudaaProgressionAdapter.java,v 1.1 2004/04/02 14:02:39 deniger Exp $ */ public class FudaaProgressionAdapter implements ProgressionInterface { BuProgressBar bar_; /** * @param _bar la barre de dest */ public FudaaProgressionAdapter(BuProgressBar _bar) { bar_=_bar; } /** * @see org.fudaa.dodico.commun.ProgressionInterface#setProgression(int) */ public void setProgression(int _v) { bar_.setValue(_v); } /** * @see org.fudaa.dodico.commun.ProgressionInterface#setDesc(java.lang.String) */ public void setDesc(String _s) {} /** * @see org.fudaa.dodico.commun.ProgressionInterface#reset() */ public void reset() {} } Index: FudaaLib.java =================================================================== RCS file: /cvsroot/fudaa/fudaa_devel/fudaa/src/org/fudaa/fudaa/commun/FudaaLib.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** FudaaLib.java 31 Mar 2004 08:17:51 -0000 1.17 --- FudaaLib.java 2 Apr 2004 14:02:38 -0000 1.18 *************** *** 8,14 **** */ package org.fudaa.fudaa.commun; import java.io.File; import java.net.MalformedURLException; - import java.util.List; import java.util.Vector; --- 8,15 ---- */ package org.fudaa.fudaa.commun; + import java.io.File; + import java.io.IOException; import java.net.MalformedURLException; import java.util.Vector; *************** *** 23,139 **** import org.fudaa.ctulu.CtuluLib; - import org.fudaa.dodico.fichiers.FileFormat; - import org.fudaa.dodico.telemac.io.SerafinFileFormat; import org.fudaa.fudaa.ressource.FudaaResource; /** * Une classe d'utilitaires inclassables. ! * ! * @version $Revision$ $Date$ by $Author$ ! * @author Bertrand Marchand */ public class FudaaLib { ! public final static boolean INFO= ! CtuluLib.DEBUG || "TRUE".equals(System.getProperty("INFO")); private FudaaLib() {} public static void info(String _s) { System.out.println("--> " + _s); } /** ! * Renvoie la chaine internationale en se servant de FudaaResource ! */ public static BuIcon getIcon(String _f) { return FudaaResource.FUDAA.getIcon(_f); } /** ! * Génère un fichier absolu au chemin de fichier principal pour le fichier ! * donné. ! * * @param _main Le fichier principal. ! * @param _file Le fichier pour lequel on recherche un chemin absolu se basant ! * sur le fichier principal. * @return Le fichier absolu obtenu. */ public static File getAbsolutePathnameTo(File _main, File _file) { ! return CtuluLib.getAbsolutePath(_main, _file.getPath()); ! // File file; ! // // Le fichier donné n'est pas relatif ! // if (_file.isAbsolute()) ! // return _file; ! // file= new File(_main.getParent() + File.separator + _file.getPath()); ! // try { ! // file= file.getCanonicalFile(); ! // } catch (IOException _exc) { ! // file= file.getAbsoluteFile(); ! // } ! // return file; } /** ! * Génère un chemin relatif au chemin de fichier principal pour le fichier ! * donné. Si les 2 fichiers sont sur des disques différents (Windows), le ! * chemin relatif est en fait un chemin absolu. ! * * <pre> ! * Exemple : _main : c:\\refonde\\cercle\\rect.prf ! * _file : c:\\users\\dupont\\geom.geo ! * return : ..\\..\\users\\dupont\\geom.geo * </pre> ! * * @param _main Le fichier principal. ! * @param _file Le fichier pour lequel on recherche un chemin relatif au ! * fichier principal. * @return Le fichier relatif. */ public static File getRelativePathnameTo(File _main, File _file) { ! File main= _main.getAbsoluteFile(); ! File file= _file.getAbsoluteFile(); ! Vector vdmain= new Vector(); ! Vector vdfile= new Vector(); File ftmp; String name; ! ftmp= main; while (ftmp.getParent() != null) { ! name= ftmp.getName(); vdmain.add(0, name); ! ftmp= ftmp.getParentFile(); } // Lettre du disque (win32) ou "" (unix) ! name= ftmp.getPath().substring(0, ftmp.getPath().length() - 1); vdmain.add(0, name); ! ftmp= file; while (ftmp.getParent() != null) { ! name= ftmp.getName(); vdfile.add(0, name); ! ftmp= ftmp.getParentFile(); } // Lettre du disque (win32) ou "" (unix) ! name= ftmp.getPath().substring(0, ftmp.getPath().length() - 1); vdfile.add(0, name); // Recherche de la racine commune ! int i= 0; ! String path= ""; while (i < vdmain.size() - 1 ! && i < vdfile.size() - 1 ! && new File((String)vdmain.get(i)).compareTo( ! new File((String)vdfile.get(i))) ! == 0) { ! path += ((String)vdmain.get(i)) + File.separator; i++; } // Nom du fichier relatif ! String rela= ""; if (i != 0) { ! for (int j= i; j < vdmain.size() - 1; j++) { rela += ".." + File.separator; } } ! for (int j= i; j < vdfile.size() - 1; j++) { ! rela += (String)vdfile.get(j) + File.separator; } ! rela += (String)vdfile.get(vdfile.size() - 1); return new File(rela); } /** ! * A partir d'un nom de fichier ou d'une url locale incorrecte, construit une ! * url locale valide. Par exemple:<br> * <code>C:\path\to\my\fic.html<\code> devient<br> * <code>file://C:\\path\\to\\my\\fic.html</code>.<br> --- 24,150 ---- import org.fudaa.ctulu.CtuluLib; import org.fudaa.fudaa.ressource.FudaaResource; /** * Une classe d'utilitaires inclassables. ! * ! * @version $Revision$ $Date$ by $Author$ ! * @author Bertrand Marchand */ public class FudaaLib { ! ! /** ! * True si les infos utilisateurs doivent etre affichees ! */ ! public final static boolean INFO = ! CtuluLib.DEBUG || "TRUE".equals(System.getProperty("INFO")); ! private FudaaLib() {} + + /** + * @param _s la chaine d'info a ecrire en sortie standard + */ public static void info(String _s) { System.out.println("--> " + _s); } + /** ! * @param _f le nom de l'icone a renvoyer ! * @return l'icone issu des ressources de fudaa ! */ public static BuIcon getIcon(String _f) { return FudaaResource.FUDAA.getIcon(_f); } + /** ! * Génère un fichier absolu au chemin de fichier principal pour le fichier donné. ! * * @param _main Le fichier principal. ! * @param _file Le fichier pour lequel on recherche un chemin absolu se basant sur le fichier ! * principal. * @return Le fichier absolu obtenu. */ public static File getAbsolutePathnameTo(File _main, File _file) { ! // return CtuluLib.getAbsolutePath(_main, _file.getPath()); ! File file; ! // Le fichier donné n'est pas relatif ! if (_file.isAbsolute()) ! return _file; ! file= new File(_main.getParent() + File.separator + _file.getPath()); ! try { ! file= file.getCanonicalFile(); ! } catch (IOException _exc) { ! file= file.getAbsoluteFile(); ! } ! return file; } + /** ! * Génère un chemin relatif au chemin de fichier principal pour le fichier donné. Si les 2 ! * fichiers sont sur des disques différents (Windows), le chemin relatif est en fait un chemin ! * absolu. ! * * <pre> ! * Exemple : _main : c:\\refonde\\cercle\\rect.prf ! * _file : c:\\users\\dupont\\geom.geo ! * return : ..\\..\\users\\dupont\\geom.geo * </pre> ! * * @param _main Le fichier principal. ! * @param _file Le fichier pour lequel on recherche un chemin relatif au fichier principal. * @return Le fichier relatif. */ public static File getRelativePathnameTo(File _main, File _file) { ! File main = _main.getAbsoluteFile(); ! File file = _file.getAbsoluteFile(); ! Vector vdmain = new Vector(); ! Vector vdfile = new Vector(); File ftmp; String name; ! ftmp = main; while (ftmp.getParent() != null) { ! name = ftmp.getName(); vdmain.add(0, name); ! ftmp = ftmp.getParentFile(); } // Lettre du disque (win32) ou "" (unix) ! name = ftmp.getPath().substring(0, ftmp.getPath().length() - 1); vdmain.add(0, name); ! ftmp = file; while (ftmp.getParent() != null) { ! name = ftmp.getName(); vdfile.add(0, name); ! ftmp = ftmp.getParentFile(); } // Lettre du disque (win32) ou "" (unix) ! name = ftmp.getPath().substring(0, ftmp.getPath().length() - 1); vdfile.add(0, name); // Recherche de la racine commune ! int i = 0; ! String path = ""; while (i < vdmain.size() - 1 ! && i < vdfile.size() - 1 ! && new File((String) vdmain.get(i)).compareTo( ! new File((String) vdfile.get(i))) ! == 0) { ! path += ((String) vdmain.get(i)) + File.separator; i++; } // Nom du fichier relatif ! String rela = ""; if (i != 0) { ! for (int j = i; j < vdmain.size() - 1; j++) { rela += ".." + File.separator; } } ! for (int j = i; j < vdfile.size() - 1; j++) { ! rela += (String) vdfile.get(j) + File.separator; } ! rela += (String) vdfile.get(vdfile.size() - 1); return new File(rela); } + /** ! * A partir d'un nom de fichier ou d'une url locale incorrecte, construit une url locale valide. ! * Par exemple: <br> * <code>C:\path\to\my\fic.html<\code> devient<br> * <code>file://C:\\path\\to\\my\\fic.html</code>.<br> *************** *** 144,293 **** */ public static String pathToUrl(String _file) { ! try{ ! return new File(_file).toURL().toString(); } ! catch(MalformedURLException e){ e.printStackTrace(); ! return "file:/"+_file; } ! /* if((!_file.startsWith("/")) && (_file.indexOf('\\')>0)){ ! String s1=FuLib.replace(_file, "\\", "\\\\"); ! return "file:/"+FuLib.replace(s1, "/", "\\\\"); ! } ! else ! return "file:/"+_file;*/ } ! ! /** ! * Transforme un tableau de chaine en une unique chaine avec des saut de ! * lignes. */ public static String arrayToString(String[] _tab) { ! int n= _tab.length; ! String r= System.getProperty("line.separator"); ! StringBuffer obj= new StringBuffer(); if (n > 0) { ! for (int i= 0; i < n; i++) obj.append(_tab[i]).append(r); } return obj.toString(); } /** * Affiche une message d'avertissement contenant les lignes de <code>_message * </code>. */ public static void showWarn( ! BuCommonInterface _impl, ! String _titre, ! String[] _message) { showWarn(_impl, _titre, arrayToString(_message)); } /** * Affiche une message d'erreur contenant les lignes de <code>_message * </code>. */ public static void showError( ! BuCommonInterface _impl, ! String _titre, ! String[] _message) { showError(_impl, _titre, arrayToString(_message)); } /** ! * Affiche une message contenant les lignes de <code>_message</code>. */ public static void showMessage( ! BuCommonInterface _impl, ! String _titre, ! String[] _message) { showMessage(_impl, _titre, arrayToString(_message)); } /** ! * Affiche une boite de dialogue d'information ayant comme titre <code>_titre</code> ! * et comme message <code>_message</code>. */ public static void showMessage( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogMessage mes= ! _impl != null ! ? new BuDialogMessage( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message) ! : new BuDialogMessage(null, null, _message); mes.setTitle(_titre); mes.activate(); } - public static void main(String[] args) { - System.out.println(pathToUrl("C:\\dede")); - } /** ! * Affiche une boite de dialogue d'avertissement ayant comme titre <code>_titre</code> ! * et comme message <code>_message</code>. */ public static void showWarn( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogWarning warn= ! _impl != null ! ? new BuDialogWarning( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message) ! : new BuDialogWarning(null, null, _message); warn.setTitle(_titre); warn.activate(); } /** ! * Affiche une boite de dialogue d'erreur ayant comme titre <code>_titre</code> ! * et comme message <code>_message</code>. */ public static void showError( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogError erreur= ! _impl == null ! ? new BuDialogError(null, null, _message) ! : new BuDialogError( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message); erreur.setTitle(_titre); erreur.activate(); } public static boolean showConfirmation( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogConfirmation conf= ! _impl != null ! ? new BuDialogConfirmation( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message) ! : new BuDialogConfirmation(null, null, _message); conf.setTitle(_titre); return isOkResponse(conf.activate()); } /** ! * Renvoie true si _r correspond a <code>JOptionPane.YES_OPTION</code> ou <code>JOptionPane.OK_OPTION</code>. */ public static boolean isOkResponse(int _r) { return (_r == JOptionPane.YES_OPTION) || (_r == JOptionPane.OK_OPTION); } /** ! * Renvoie true si _r correspond a <code>JOptionPane.CANCEL_OPTION</code> ou <code>JOptionPane.CLOSED_OPTION</code>. */ public static boolean isCancelResponse(int _r) { return (_r == JOptionPane.CANCEL_OPTION) ! || (_r == JOptionPane.CLOSED_OPTION); } - - - } --- 155,338 ---- */ public static String pathToUrl(String _file) { ! try { ! return new File(_file).toURL().toString(); } ! catch (MalformedURLException e) { e.printStackTrace(); ! return "file:/" + _file; } ! /* ! * if((!_file.startsWith("/")) && (_file.indexOf('\\')>0)){ String s1=FuLib.replace(_file, ! * "\\", "\\\\"); return "file:/"+FuLib.replace(s1, "/", "\\\\"); } else ! */ } ! ! /** ! * Transforme un tableau de chaine en une unique chaine avec des saut de lignes. ! * ! * @param _tab le tableau a transformer ! * @return la chaine */ public static String arrayToString(String[] _tab) { ! int n = _tab.length; ! String r = System.getProperty("line.separator"); ! StringBuffer obj = new StringBuffer(); if (n > 0) { ! for (int i = 0; i < n; i++) obj.append(_tab[i]).append(r); } return obj.toString(); } + /** * Affiche une message d'avertissement contenant les lignes de <code>_message * </code>. + * + * @param _impl l'implementation parente + * @param _titre le titre du message + * @param _message le contenu */ public static void showWarn( ! BuCommonInterface _impl, ! String _titre, ! String[] _message) { showWarn(_impl, _titre, arrayToString(_message)); } + /** * Affiche une message d'erreur contenant les lignes de <code>_message * </code>. + * + * @param _impl l'implementation parente + * @param _titre le titre du message + * @param _message le contenu */ public static void showError( ! BuCommonInterface _impl, ! String _titre, ! String[] _message) { showError(_impl, _titre, arrayToString(_message)); } + /** ! * Affiche une message contenant les lignes de <code>_message</code>. ! * ! * @param _impl l'implementation parente ! * @param _titre le titre du message ! * @param _message le contenu */ public static void showMessage( ! BuCommonInterface _impl, ! String _titre, ! String[] _message) { showMessage(_impl, _titre, arrayToString(_message)); } + /** ! * Affiche une boite de dialogue d'information ayant comme titre <code>_titre</code> et comme ! * message <code>_message</code>. ! * ! * @param _impl l'implementation parente ! * @param _titre le titre du message ! * @param _message le contenu */ public static void showMessage( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogMessage mes = ! _impl != null ! ? new BuDialogMessage( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message) ! : new BuDialogMessage(null, null, _message); mes.setTitle(_titre); mes.activate(); } /** ! * Affiche une boite de dialogue d'avertissement ayant comme titre <code>_titre</code> et comme ! * message <code>_message</code>. ! * ! * @param _impl l'implementation parente ! * @param _titre le titre du message ! * @param _message le contenu */ public static void showWarn( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogWarning warn = ! _impl != null ! ? new BuDialogWarning( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message) ! : new BuDialogWarning(null, null, _message); warn.setTitle(_titre); warn.activate(); } + /** ! * Affiche une boite de dialogue d'erreur ayant comme titre <code>_titre</code> et comme ! * message <code>_message</code>. ! * ! * @param _impl l'implementation parente ! * @param _titre le titre du message ! * @param _message le contenu */ public static void showError( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogError erreur = ! _impl == null ! ? new BuDialogError(null, null, _message) ! : new BuDialogError( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message); erreur.setTitle(_titre); erreur.activate(); } + + /** + * @param _impl l'implementation parente + * @param _titre le titre du message + * @param _message le contenu + * @return true si l'utilisateur a accepte + */ public static boolean showConfirmation( ! BuCommonInterface _impl, ! String _titre, ! String _message) { ! BuDialogConfirmation conf = ! _impl != null ! ? new BuDialogConfirmation( ! _impl.getImplementation(), ! _impl.getInformationsSoftware(), ! _message) ! : new BuDialogConfirmation(null, null, _message); conf.setTitle(_titre); return isOkResponse(conf.activate()); } + /** ! * @return true si _r correspond a <code>JOptionPane.YES_OPTION</code> ou <code>JOptionPane.OK_OPTION</code>. ! * @param _r l'entier a tester */ public static boolean isOkResponse(int _r) { return (_r == JOptionPane.YES_OPTION) || (_r == JOptionPane.OK_OPTION); } + /** ! * @return true si _r correspond a <code>JOptionPane.CANCEL_OPTION</code> ou <code>JOptionPane.CLOSED_OPTION</code>. ! * @param _r l'entier a tester */ public static boolean isCancelResponse(int _r) { return (_r == JOptionPane.CANCEL_OPTION) ! || (_r == JOptionPane.CLOSED_OPTION); } } |