Index: lutinutil/src/java/org/codelutin/util/FileUtil.java diff -u lutinutil/src/java/org/codelutin/util/FileUtil.java:1.9 lutinutil/src/java/org/codelutin/util/FileUtil.java:1.10 --- lutinutil/src/java/org/codelutin/util/FileUtil.java:1.9 Fri Aug 11 09:18:06 2006 +++ lutinutil/src/java/org/codelutin/util/FileUtil.java Tue Aug 22 15:38:32 2006 @@ -23,9 +23,9 @@ * Created: 22 nov. 2004 * * @author Benjamin Poussin - * @version $Revision: 1.9 $ + * @version $Revision: 1.10 $ * - * Mise a jour: $Date: 2006/08/11 09:18:06 $ + * Mise a jour: $Date: 2006/08/22 15:38:32 $ * par : $Author: bpoussin $ */ @@ -36,7 +36,6 @@ import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -47,12 +46,79 @@ import java.util.LinkedList; import java.util.List; +import javax.swing.JFileChooser; + +import org.apache.commons.logging.LogFactory; + public class FileUtil { // FileUtil + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private org.apache.commons.logging.Log log = LogFactory.getLog(FileUtil.class); + /** Encoding par defaut utilisé si non spécifié */ static public String ENCODING = "ISO-8859-1"; + static protected File currentDirectory = new File("."); + + static public void setCurrentDirectory(File dir){ + currentDirectory = dir; + } + + /** + * Retourne le nom du fichier entre dans la boite de dialogue. + * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne null. + */ + static public String getFile(){ + try{ + JFileChooser chooser = new JFileChooser(currentDirectory); + chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + int returnVal = chooser.showDialog(null, null); + if(returnVal == JFileChooser.APPROVE_OPTION) { + File theFile = chooser.getSelectedFile(); + if(theFile != null) { + currentDirectory = theFile; + return theFile.getAbsolutePath(); + } + } + else + return null; + } + catch(Exception eee){ + log.warn("Erreur:", eee); + } + return null; + } /** + * Retourne le nom du repertoire entre dans la boite de dialogue. + * Si le bouton annuler est utilisé, ou qu'il y a une erreur retourne + * null. + */ + static public String getDirectory() { + try{ + JFileChooser chooser = new JFileChooser(currentDirectory); + chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int returnVal = chooser.showDialog(null, null); + if(returnVal == JFileChooser.APPROVE_OPTION) { + File theFile = chooser.getSelectedFile(); + if(theFile != null) { + currentDirectory = theFile; + if(theFile.isDirectory()) { + return theFile.getAbsolutePath(); + } + } + } + else{ + return null; + } + } catch(Exception eee){ + log.warn("Erreur:", eee); + } + return null; + } + + /** * Retourne un Reader utilisant l'encoding par defaut {@link #ENCODING} * * @param file Index: lutinutil/src/java/org/codelutin/util/ListenerSet.java diff -u lutinutil/src/java/org/codelutin/util/ListenerSet.java:1.7 lutinutil/src/java/org/codelutin/util/ListenerSet.java:1.8 --- lutinutil/src/java/org/codelutin/util/ListenerSet.java:1.7 Wed Jan 4 13:26:32 2006 +++ lutinutil/src/java/org/codelutin/util/ListenerSet.java Tue Aug 22 15:38:32 2006 @@ -22,9 +22,9 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * - * Mise a jour: $Date: 2006/01/04 13:26:32 $ + * Mise a jour: $Date: 2006/08/22 15:38:32 $ * par : $Author: bpoussin $ */ package org.codelutin.util; @@ -66,12 +66,12 @@ * * @see org.codelutin.util.CategorisedListenerSet */ -public class ListenerSet { // ListenerSet +public class ListenerSet implements Iterable { // ListenerSet /** DOCUMENTME Description of the Field */ - protected Class listenerClass = null; + protected Class listenerClass = null; /** DOCUMENTME Description of the Field */ - protected HashSet listeners = new HashSet(); + protected HashSet> listeners = new HashSet>(); /** DOCUMENTME Constructor for the ListenerSet object */ public ListenerSet() { } @@ -82,7 +82,7 @@ * * @param listenerClass DOCUMENTME Description of the Parameter */ - public ListenerSet(Class listenerClass) { + public ListenerSet(Class listenerClass) { this.listenerClass = listenerClass; } @@ -97,12 +97,12 @@ * si l'objet n'est pas du type passé en argument du constructeur * une IllegalArgumentException est levée. */ - public void add(Object l) { + public void add(T l) { if (l == null) { return; } if (listenerClass == null || listenerClass.isInstance(l)) { - TransparenteWeakReference ref = new TransparenteWeakReference(l); + TransparenteWeakReference ref = new TransparenteWeakReference(l); listeners.add(ref); } else { throw new IllegalArgumentException("Listener object (" @@ -116,7 +116,7 @@ * * @param ls The feature to be added to the All attribute */ - public void addAll(ListenerSet ls) { + public void addAll(ListenerSet ls) { if (listenerClass == null || (ls.listenerClass != null && listenerClass.isAssignableFrom(ls.listenerClass))) { listeners.addAll(ls.listeners); @@ -165,8 +165,8 @@ * * @return DOCUMENTME Description of the Return Value */ - public Iterator iterator() { - return new ReferenceIterator(listeners.iterator()); + public Iterator iterator() { + return new ReferenceIterator(listeners.iterator()); } /** @@ -174,8 +174,8 @@ * * @param l DOCUMENTME Description of the Parameter */ - public void remove(Object l) { - TransparenteWeakReference ref = new TransparenteWeakReference(l); + public void remove(T l) { + TransparenteWeakReference ref = new TransparenteWeakReference(l); listeners.remove(ref); } @@ -189,18 +189,18 @@ } /** Iterator qui supprime les references vides lors du parcours */ - static class ReferenceIterator implements Iterator { + static class ReferenceIterator implements Iterator { /** DOCUMENTME Description of the Field */ - protected Iterator iter = null; + protected Iterator> iter = null; /** DOCUMENTME Description of the Field */ - protected Object nextObject = null; + protected T nextObject = null; /** * Un iterator contenant des References * * @param iter DOCUMENTME Description of the Parameter */ - public ReferenceIterator(Iterator iter) { + public ReferenceIterator(Iterator> iter) { this.iter = iter; findNext(); } @@ -208,8 +208,8 @@ /** DOCUMENTME Method */ protected void findNext() { while (iter.hasNext() && nextObject == null) { - Reference ref = (Reference)iter.next(); - Object o = ref.get(); + Reference ref = iter.next(); + T o = ref.get(); if (o != null) { nextObject = o; } else { @@ -232,8 +232,8 @@ * * @return DOCUMENTME Description of the Return Value */ - public Object next() { - Object result = nextObject; + public T next() { + T result = nextObject; nextObject = null; findNext(); return result;