Index: lutinutil/src/java/org/codelutin/util/StringUtil.java diff -u lutinutil/src/java/org/codelutin/util/StringUtil.java:1.4 lutinutil/src/java/org/codelutin/util/StringUtil.java:1.5 --- lutinutil/src/java/org/codelutin/util/StringUtil.java:1.4 Fri Sep 17 15:48:17 2004 +++ lutinutil/src/java/org/codelutin/util/StringUtil.java Tue Nov 2 16:51:28 2004 @@ -22,13 +22,17 @@ * * @author POUSSIN Benjamin * Copyright Code Lutin -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ * -* Mise a jour: $Date: 2004/09/17 15:48:17 $ -* par : $Author: mazelier $ +* Mise a jour: $Date: 2004/11/02 16:51:28 $ +* par : $Author: bpoussin $ */ 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; @@ -108,6 +112,44 @@ public static char toChar(String s){ //fixme a revoir return s.charAt(0) ; + } + + /** + * Essai de convertir une chaine de caractere en une couleur si possible + * si ce n'est pas possible retourne null. + * @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 + */ + public static Color toColor(String s){ + try{ + if(s.startsWith("#")){ + // récuperation des valeurs hexa + String hr = s.substring(1, 3); + String hg = s.substring(3, 5); + String hb = s.substring(5, 7); + + // conversion en entier + int r = Integer.parseInt(hr, 16); + int g = Integer.parseInt(hg, 16); + int b = Integer.parseInt(hb, 16); + + if(s.length() == 9){ + // s'il y a un canal alpha on l'utilise + String ha = s.substring(7, 9); + int a = Integer.parseInt(ha, 16); + return new Color(r, g, b, a); + }else{ + return new Color(r, g, b); + } + }else{ + Field 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; } public static Date toDate(String s) throws ParseException{ Index: lutinutil/src/java/org/codelutin/util/ArrayUtil.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/ArrayUtil.java:1.1 --- /dev/null Tue Nov 2 16:51:33 2004 +++ lutinutil/src/java/org/codelutin/util/ArrayUtil.java Tue Nov 2 16:51:28 2004 @@ -0,0 +1,52 @@ +/* *##% + * Copyright (C) 2002, 2003, 2004 Code Lutin, Cédric Pineau, + * Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * ArrayUtil.java + * + * Created: 31 oct. 2004 + * + * @author Benjamin Poussin + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2004/11/02 16:51:28 $ + * par : $Author: bpoussin $ + */ + +package org.codelutin.util; + +import java.util.ArrayList; +import java.util.List; + +public class ArrayUtil { // ArrayUtil + + /** + * Permet de convertir un tableau en une liste, le type primitif + * est encapsulé dans un objet. + */ + static public List asList(double [] a){ + ArrayList result = new ArrayList(a.length); + for(int i=0; i