Index: lutinutil/src/java/org/codelutin/util/StringUtil.java diff -u lutinutil/src/java/org/codelutin/util/StringUtil.java:1.6 lutinutil/src/java/org/codelutin/util/StringUtil.java:1.7 --- lutinutil/src/java/org/codelutin/util/StringUtil.java:1.6 Mon Nov 8 13:39:19 2004 +++ lutinutil/src/java/org/codelutin/util/StringUtil.java Mon Dec 13 14:03:50 2004 @@ -22,20 +22,18 @@ * * @author POUSSIN Benjamin * Copyright Code Lutin -* @version $Revision: 1.6 $ +* @version $Revision: 1.7 $ * -* Mise a jour: $Date: 2004/11/08 13:39:19 $ -* par : $Author: bpoussin $ +* Mise a jour: $Date: 2004/12/13 14:03:50 $ +* par : $Author: pineau $ */ package org.codelutin.util; import java.awt.Color; import java.lang.reflect.Field; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.Date; import java.text.DateFormat; import java.text.ParseException; +import java.util.Date; /** * Classe contenant un ensemle de m?thode static utiles pour la manipulation des @@ -120,9 +118,11 @@ * @param s la couleur sous la forme de string, par exemple "red", "yellow" * ou bien en RGB "#FFAA99", et avec un canal alpha "#FFAA3366" * @return la couleur demandé si possible sinon null + * @throws IllegalAccessException + * @throws IllegalArgumentException */ - public static Color toColor(String s){ - try{ + public static Color toColor(String s) throws StringUtilException { + try { if(s.startsWith("#")){ // récuperation des valeurs hexa String hr = s.substring(1, 3); @@ -143,13 +143,21 @@ return new Color(r, g, b); } }else{ - Field f = Color.class.getField(s); - return (Color)f.get(Color.class); + Field f; + f = Color.class.getField(s); + return (Color)f.get(Color.class); } - }catch(Exception eee){ - Logger.getLogger(StringUtil.class.getName() + ".toColor").log(Level.WARNING, "Error during conversion from string to color", eee); - } - return null; + } catch (NumberFormatException e) { + throw new StringUtilException("Error during conversion from string to color", e); + } catch (SecurityException e) { + throw new StringUtilException("Error during conversion from string to color", e); + } catch (NoSuchFieldException e) { + throw new StringUtilException("Error during conversion from string to color", e); + } catch (IllegalArgumentException e) { + throw new StringUtilException("Error during conversion from string to color", e); + } catch (IllegalAccessException e) { + throw new StringUtilException("Error during conversion from string to color", e); + } } public static Date toDate(String s) throws ParseException{ Index: lutinutil/src/java/org/codelutin/util/StringUtilException.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/StringUtilException.java:1.1 --- /dev/null Mon Dec 13 14:03:55 2004 +++ lutinutil/src/java/org/codelutin/util/StringUtilException.java Mon Dec 13 14:03:50 2004 @@ -0,0 +1,21 @@ +/* + * Created on Dec 7, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.codelutin.util; + +/** + * @author pineau + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class StringUtilException extends RuntimeException { + + public StringUtilException(String message, Exception e) { + super(message, e); + } + +}