You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/09/08 06:51:32 UTC

cvs commit: jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters PointConverter.java ColorConverter.java

dion        2004/09/07 21:51:32

  Modified:    jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt
                        ImageTag.java DialogTag.java WidgetTag.java
                        SwtTagLibrary.java
               jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters
                        PointConverter.java ColorConverter.java
  Log:
  detab
  
  Revision  Changes    Path
  1.6       +9 -9      jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/ImageTag.java
  
  Index: ImageTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/ImageTag.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ImageTag.java	7 Sep 2004 02:41:40 -0000	1.5
  +++ ImageTag.java	8 Sep 2004 04:51:31 -0000	1.6
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -31,7 +31,7 @@
    * This creates an image on the parent Widget.
    *
    * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
  - * @version CVS $Id$
  + * @version CVS ImageTag.java,v 1.5 2004/09/07 02:41:40 dion Exp
    */
   public class ImageTag extends TagSupport {
   
  @@ -59,7 +59,7 @@
       public String getResource() {
           return resource;
       }
  -	
  +
       /**
        * Sets the variable name
        */
  @@ -74,7 +74,7 @@
       public String getVar() {
         return this.var;
       }
  -	
  +
       /**
        * Sets the src.
        * @param src The src to set
  @@ -127,9 +127,9 @@
           } else {
               throw new JellyTagException("Either an image location or a resource must be specified");
           }
  -									     
  +
           setWidgetImage(parent, image);
  -	    
  +
           // store the image as a context variable if specified
           if (var != null) {
               context.setVariable(var, image);
  @@ -151,7 +151,7 @@
               getClass().getClassLoader().getResourceAsStream(getResource());
           return new Image(display, stream);
       }
  -	
  +
       /**
        * Add image to a widget
        * @param parent
  
  
  
  1.2       +40 -40    jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/DialogTag.java
  
  Index: DialogTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/DialogTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DialogTag.java	5 Sep 2004 15:40:27 -0000	1.1
  +++ DialogTag.java	8 Sep 2004 04:51:31 -0000	1.2
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -25,48 +25,48 @@
   
   /**
    * This tag creates an SWT dialog.
  - *  
  + *
    * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
  - * 
  + *
    */
   public class DialogTag extends WidgetTag {
   
  -	/**
  -	 * @param widgetClass
  -	 * @param style
  -	 */
  -	public DialogTag(Class widgetClass, int style) {
  -		super(widgetClass, style);
  -	}
  -
  -	/**
  -	 * @param widgetClass
  -	 */
  -	public DialogTag(Class widgetClass) {
  -		super(widgetClass);
  -	}
  -
  -	// Implementation methods
  -	//-------------------------------------------------------------------------                    
  -
  -	/**
  -	 * Factory method to create a new dialog
  -	 */
  -	protected Object newInstance(Class theClass, Map attributes, XMLOutput output)
  -		throws JellyTagException {
  -		int style = getStyle(attributes);
  -
  -		// now lets call the constructor with the parent
  -		Widget parent = getParentWidget();
  -
  -		boolean isParentShell = parent instanceof Shell;
  -		if (parent == null || !isParentShell) {
  -			throw new JellyTagException("This tag must be nested within a Shell");
  -		}
  +    /**
  +     * @param widgetClass
  +     * @param style
  +     */
  +    public DialogTag(Class widgetClass, int style) {
  +        super(widgetClass, style);
  +    }
  +
  +    /**
  +     * @param widgetClass
  +     */
  +    public DialogTag(Class widgetClass) {
  +        super(widgetClass);
  +    }
  +
  +    // Implementation methods
  +    //-------------------------------------------------------------------------
  +
  +    /**
  +     * Factory method to create a new dialog
  +     */
  +    protected Object newInstance(Class theClass, Map attributes, XMLOutput output)
  +        throws JellyTagException {
  +        int style = getStyle(attributes);
  +
  +        // now lets call the constructor with the parent
  +        Widget parent = getParentWidget();
  +
  +        boolean isParentShell = parent instanceof Shell;
  +        if (parent == null || !isParentShell) {
  +            throw new JellyTagException("This tag must be nested within a Shell");
  +        }
   
  -		Dialog dialog = (Dialog) createWidget(theClass, parent, style);
  +        Dialog dialog = (Dialog) createWidget(theClass, parent, style);
   
  -		return dialog;
  -	}
  +        return dialog;
  +    }
   
   }
  
  
  
  1.14      +16 -16    jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/WidgetTag.java
  
  Index: WidgetTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/WidgetTag.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- WidgetTag.java	5 Sep 2004 15:19:26 -0000	1.13
  +++ WidgetTag.java	8 Sep 2004 04:51:31 -0000	1.14
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -34,12 +34,12 @@
   import org.eclipse.swt.widgets.Control;
   import org.eclipse.swt.widgets.Widget;
   
  -/** 
  +/**
    * This tag creates an SWT widget based on the parent tag, optionally declaring
    * this widget as a variable if the <i>var</i> attribute is specified.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a> 
  + * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
    * @version 1.1
    */
   public class WidgetTag extends UseBeanTag {
  @@ -64,7 +64,7 @@
       }
   
       // Properties
  -    //-------------------------------------------------------------------------                    
  +    //-------------------------------------------------------------------------
   
       /**
        * @return the visible widget, if there is one.
  @@ -112,7 +112,7 @@
       }
   
       // Implementation methods
  -    //-------------------------------------------------------------------------                    
  +    //-------------------------------------------------------------------------
   
       /**
        * Factory method to create a new widget
  @@ -132,7 +132,7 @@
           return widget;
       }
   
  -    /* 
  +    /*
        * @see org.apache.commons.jelly.tags.core.UseBeanTag#setBeanProperties(java.lang.Object, java.util.Map)
        */
       protected void setBeanProperties(Object bean, Map attributes) throws JellyTagException {
  @@ -146,15 +146,15 @@
               setSize(control, size);
   
               // Special handling of color property as the Control object breaks the
  -            // JavaBean naming conventions by overloading the setBackground() or setForeground() method 	
  +            // JavaBean naming conventions by overloading the setBackground() or setForeground() method
               Object colorValue = attributes.remove("background");
  -            Color background = 
  -                (colorValue instanceof Color) 
  +            Color background =
  +                (colorValue instanceof Color)
                       ? (Color) colorValue : getColor(control, colorValue);
               control.setBackground(background);
   
               colorValue = attributes.remove("foreground");
  -            Color foreground = 
  +            Color foreground =
                   (colorValue instanceof Color)
                       ? (Color) colorValue : getColor(control, colorValue);
               control.setForeground(foreground);
  @@ -164,7 +164,7 @@
       }
   
       /**
  -     * Get a color for the control  		
  +     * Get a color for the control
        * @param control
        * @param colorValue
        */
  @@ -183,7 +183,7 @@
       }
   
       /**
  -     * set the size of the control 		
  +     * set the size of the control
        * @param control
        * @param size
        */
  @@ -203,7 +203,7 @@
       /**
        * Provides a strategy method to allow a new child widget to be attached to
        * its parent
  -     * 
  +     *
        * @param parent is the parent widget which is never null
        * @param widget is the new child widget to be attached to the parent
        */
  @@ -218,7 +218,7 @@
       /**
        * Factory method to create an instance of the given Widget class with
        * the given parent and SWT style
  -     * 
  +     *
        * @param theClass is the type of widget to create
        * @param parent is the parent widget
        * @param style the SWT style code
  
  
  
  1.15      +44 -44    jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/SwtTagLibrary.java
  
  Index: SwtTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/SwtTagLibrary.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SwtTagLibrary.java	5 Sep 2004 15:45:57 -0000	1.14
  +++ SwtTagLibrary.java	8 Sep 2004 04:51:31 -0000	1.15
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -72,7 +72,7 @@
   import org.eclipse.swt.widgets.TreeItem;
   import org.xml.sax.Attributes;
   
  -/** 
  +/**
    * A Jelly custom tag library that creates SWT user interfaces
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  @@ -84,11 +84,11 @@
       private static final Log log = LogFactory.getLog(SwtTagLibrary.class);
   
       static {
  -        // register the various beanutils Converters from Strings to various SWT types 
  +        // register the various beanutils Converters from Strings to various SWT types
           ConvertUtils.register( new PointConverter(), Point.class );
           ConvertUtils.register( new ColorConverter(), Color.class );
       }
  -        
  +
       public SwtTagLibrary() {
           // widgets
           registerWidgetTag( "button", Button.class, SWT.BORDER | SWT.PUSH | SWT.CENTER );
  @@ -96,12 +96,12 @@
           registerWidgetTag( "caret", Caret.class );
           registerWidgetTag( "combo", Combo.class, SWT.DROP_DOWN );
           registerWidgetTag( "composite", Composite.class );
  -	 	registerWidgetTag( "scrolledComposite", ScrolledComposite.class, SWT.H_SCROLL | SWT.V_SCROLL);
  +         registerWidgetTag( "scrolledComposite", ScrolledComposite.class, SWT.H_SCROLL | SWT.V_SCROLL);
           registerWidgetTag( "coolBar", CoolBar.class, SWT.VERTICAL );
           registerWidgetTag( "coolItem", CoolItem.class );
           registerWidgetTag( "decorations", Decorations.class );
           registerWidgetTag( "group", Group.class );
  -        registerWidgetTag( "label", Label.class, SWT.HORIZONTAL | SWT.SHADOW_IN ); 
  +        registerWidgetTag( "label", Label.class, SWT.HORIZONTAL | SWT.SHADOW_IN );
           registerWidgetTag( "list", List.class );
           registerMenuTag( "menu", SWT.DEFAULT );
           registerMenuTag( "menuBar", SWT.BAR );
  @@ -131,7 +131,7 @@
           registerWidgetTag( "tableTree", TableTree.class );
           registerWidgetTag( "tableTreeItem", TableTreeItem.class );
   
  -        // layouts        
  +        // layouts
           registerLayoutTag("fillLayout", FillLayout.class);
           registerLayoutTag("gridLayout", GridLayout.class);
           registerLayoutTag("rowLayout", RowLayout.class);
  @@ -140,16 +140,16 @@
           registerLayoutDataTag( "gridData", GridData.class );
           registerLayoutDataTag( "rowData", RowData.class );
   
  -        // dialogs        
  -		registerDialogTag( "colorDialog", ColorDialog.class );
  -		registerDialogTag( "directoryDialog", DirectoryDialog.class );
  -		registerDialogTag( "fileDialog", FileDialog.class );
  -		registerDialogTag( "fontDialog", FontDialog.class );
  -        
  +        // dialogs
  +        registerDialogTag( "colorDialog", ColorDialog.class );
  +        registerDialogTag( "directoryDialog", DirectoryDialog.class );
  +        registerDialogTag( "fileDialog", FileDialog.class );
  +        registerDialogTag( "fontDialog", FontDialog.class );
  +
           // events
           registerTag("onEvent", OnEventTag.class);
   
  -        // other tags                    
  +        // other tags
           registerTag("color", ColorTag.class);
           registerTag("colour", FontTag.class);
           registerTag("font", FontTag.class);
  @@ -200,7 +200,7 @@
       protected void registerWidgetTag(String name, Class widgetClass) {
           registerWidgetTag(name, widgetClass, SWT.NULL);
       }
  -    
  +
       /**
        * Register a widget tag for the given name
        */
  @@ -218,31 +218,31 @@
               }
           );
       }
  -   
  -	/**
  -	 * Register a registerDialogTag tag for the given name
  -	 */
  -	protected void registerDialogTag(String name, Class widgetClass) {
  -		registerDialogTag(name, widgetClass, SWT.NULL);
  -	}
  -	 
  -	/**
  -	   * Register a dialog tag for the given name
  -	   */
  -	protected void registerDialogTag(String name, final Class widgetClass, final int style) {
  -		  registerTagFactory(
  -			  name,
  -			  new TagFactory() {
  -				  /**
  -				   * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
  -				   */
  -				  public Tag createTag(String name, Attributes attributes)
  -					  throws JellyException {
  -					  return new DialogTag(widgetClass, style);
  -				  }
  -			  }
  -		  );
  -	  }
  +
  +    /**
  +     * Register a registerDialogTag tag for the given name
  +     */
  +    protected void registerDialogTag(String name, Class widgetClass) {
  +        registerDialogTag(name, widgetClass, SWT.NULL);
  +    }
  +
  +    /**
  +       * Register a dialog tag for the given name
  +       */
  +    protected void registerDialogTag(String name, final Class widgetClass, final int style) {
  +          registerTagFactory(
  +              name,
  +              new TagFactory() {
  +                  /**
  +                   * @see org.apache.commons.jelly.impl.TagFactory#createTag(java.lang.String, org.xml.sax.Attributes)
  +                   */
  +                  public Tag createTag(String name, Attributes attributes)
  +                      throws JellyException {
  +                      return new DialogTag(widgetClass, style);
  +                  }
  +              }
  +          );
  +      }
   
       /**
        * Register a menu tag for the given name and style
  @@ -261,7 +261,7 @@
               }
           );
       }
  -    
   
  - 
  +
  +
   }
  
  
  
  1.6       +25 -25    jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters/PointConverter.java
  
  Index: PointConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters/PointConverter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PointConverter.java	7 Sep 2004 02:08:26 -0000	1.5
  +++ PointConverter.java	8 Sep 2004 04:51:32 -0000	1.6
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -21,7 +21,7 @@
   
   import org.eclipse.swt.graphics.Point;
   
  -/** 
  +/**
    * A Converter that turns Strings in the form "x, y" into Point objects
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  @@ -29,18 +29,18 @@
    */
   public class PointConverter implements Converter {
   
  -	private static final PointConverter instance = new PointConverter();
  -	 
  -	public static PointConverter getInstance() {
  -	    return instance;
  -	}
  -
  -	/**
  -	 * Parsers a String in the form "x, y" into an SWT Point class
  -	 * @param text
  -	 * @return Point
  -	 */
  -	public Point parse(String text) {
  +    private static final PointConverter instance = new PointConverter();
  +
  +    public static PointConverter getInstance() {
  +        return instance;
  +    }
  +
  +    /**
  +     * Parsers a String in the form "x, y" into an SWT Point class
  +     * @param text
  +     * @return Point
  +     */
  +    public Point parse(String text) {
           StringTokenizer items = new StringTokenizer( text, "," );
           int x = 0;
           int y = 0;
  @@ -49,11 +49,11 @@
           }
           if ( items.hasMoreTokens() ) {
               y = parseNumber( items.nextToken() );
  -        }           
  +        }
           return new Point( x, y );
  -	}
  -	
  -	// Converter interface	
  +    }
  +
  +    // Converter interface
       //-------------------------------------------------------------------------
       public Object convert(Class type, Object value) {
           Object answer = null;
  @@ -61,15 +61,15 @@
               String text = value.toString();
               answer = parse(text);
           }
  -        
  +
           System.out.println("Converting value: " + value + " into: " + answer);
  -        
  +
           return answer;
       }
  -    
  +
       protected int parseNumber(String text) {
           text = text.trim();
           return Integer.parseInt(text.trim());
       }
  -    
  +
   }
  
  
  
  1.5       +93 -93    jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters/ColorConverter.java
  
  Index: ColorConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters/ColorConverter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ColorConverter.java	7 Sep 2004 02:07:40 -0000	1.4
  +++ ColorConverter.java	8 Sep 2004 04:51:32 -0000	1.5
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -20,101 +20,101 @@
   import org.apache.commons.beanutils.Converter;
   import org.eclipse.swt.graphics.RGB;
   
  -/** 
  - * A Converter that converts Strings in the form "#uuuuuu" or "x,y,z" into a RGB object 
  +/**
  + * A Converter that converts Strings in the form "#uuuuuu" or "x,y,z" into a RGB object
    *
    * @author <a href="mailto:ckl@dacelo.nl">Christiaan ten Klooster</a>
    * @version $Revision$
    */
   public class ColorConverter implements Converter {
   
  -	private static final ColorConverter instance = new ColorConverter();
  +    private static final ColorConverter instance = new ColorConverter();
   
  -	private static String usageText =
  -		"Color value should be in the form of '#xxxxxx' or 'x,y,z'";
  +    private static String usageText =
  +        "Color value should be in the form of '#xxxxxx' or 'x,y,z'";
   
  -	public static ColorConverter getInstance() {
  -		return instance;
  -	}
  -
  -	/**
  -	 * Parsers a String in the form "x, y, z" into an SWT RGB class
  -	 * @param value
  -	 * @return RGB
  -	 */
  -	protected RGB parseRGB(String value) {
  -		StringTokenizer items = new StringTokenizer(value, ",");
  -		int red = 0;
  -		int green = 0;
  -		int blue = 0;
  -		if (items.hasMoreTokens()) {
  -			red = parseNumber(items.nextToken());
  -		}
  -		if (items.hasMoreTokens()) {
  -			green = parseNumber(items.nextToken());
  -		}
  -		if (items.hasMoreTokens()) {
  -			blue = parseNumber(items.nextToken());
  -		}
  -		return new RGB(red, green, blue);
  -	}
  -
  -	/**
  -	 * Parsers a String in the form "#xxxxxx" into an SWT RGB class
  -	 * @param value
  -	 * @return RGB
  -	 */
  -	protected RGB parseHtml(String value) {
  -		if (value.length() != 7) {
  -			throw new IllegalArgumentException(usageText);
  -		}
  -		int colorValue = 0;
  -		try {
  -			colorValue = Integer.parseInt(value.substring(1), 16);
  -			java.awt.Color swingColor = new java.awt.Color(colorValue);
  -			return new RGB(
  -				swingColor.getRed(),
  -				swingColor.getGreen(),
  -				swingColor.getBlue());
  -		} catch (NumberFormatException ex) {
  -			throw new IllegalArgumentException(
  -				value + "is not a valid Html color\n " + ex);
  -		}
  -	}
  -
  -	/**
  -	 * Parse a String
  -	 */
  -	public RGB parse(String value) {
  -		if (value.length() <= 1) {
  -			throw new IllegalArgumentException(usageText);
  -		}
  -
  -		if (value.charAt(0) == '#') {
  -			return parseHtml(value);
  -		} else if (value.indexOf(',') != -1) {
  -			return parseRGB(value);
  -		} else {
  -			throw new IllegalArgumentException(usageText);
  -		}
  -	}
  -
  -	// Converter interface	
  -	//-------------------------------------------------------------------------
  -	public Object convert(Class type, Object value) {
  -		Object answer = null;
  -		if (value != null) {
  -			String text = value.toString();
  -			answer = parse(text);
  -		}
  -
  -		System.out.println("Converting value: " + value + " into: " + answer);
  -
  -		return answer;
  -	}
  -
  -	protected int parseNumber(String text) {
  -		text = text.trim();
  -		return Integer.parseInt(text.trim());
  -	}
  +    public static ColorConverter getInstance() {
  +        return instance;
  +    }
  +
  +    /**
  +     * Parsers a String in the form "x, y, z" into an SWT RGB class
  +     * @param value
  +     * @return RGB
  +     */
  +    protected RGB parseRGB(String value) {
  +        StringTokenizer items = new StringTokenizer(value, ",");
  +        int red = 0;
  +        int green = 0;
  +        int blue = 0;
  +        if (items.hasMoreTokens()) {
  +            red = parseNumber(items.nextToken());
  +        }
  +        if (items.hasMoreTokens()) {
  +            green = parseNumber(items.nextToken());
  +        }
  +        if (items.hasMoreTokens()) {
  +            blue = parseNumber(items.nextToken());
  +        }
  +        return new RGB(red, green, blue);
  +    }
  +
  +    /**
  +     * Parsers a String in the form "#xxxxxx" into an SWT RGB class
  +     * @param value
  +     * @return RGB
  +     */
  +    protected RGB parseHtml(String value) {
  +        if (value.length() != 7) {
  +            throw new IllegalArgumentException(usageText);
  +        }
  +        int colorValue = 0;
  +        try {
  +            colorValue = Integer.parseInt(value.substring(1), 16);
  +            java.awt.Color swingColor = new java.awt.Color(colorValue);
  +            return new RGB(
  +                swingColor.getRed(),
  +                swingColor.getGreen(),
  +                swingColor.getBlue());
  +        } catch (NumberFormatException ex) {
  +            throw new IllegalArgumentException(
  +                value + "is not a valid Html color\n " + ex);
  +        }
  +    }
  +
  +    /**
  +     * Parse a String
  +     */
  +    public RGB parse(String value) {
  +        if (value.length() <= 1) {
  +            throw new IllegalArgumentException(usageText);
  +        }
  +
  +        if (value.charAt(0) == '#') {
  +            return parseHtml(value);
  +        } else if (value.indexOf(',') != -1) {
  +            return parseRGB(value);
  +        } else {
  +            throw new IllegalArgumentException(usageText);
  +        }
  +    }
  +
  +    // Converter interface
  +    //-------------------------------------------------------------------------
  +    public Object convert(Class type, Object value) {
  +        Object answer = null;
  +        if (value != null) {
  +            String text = value.toString();
  +            answer = parse(text);
  +        }
  +
  +        System.out.println("Converting value: " + value + " into: " + answer);
  +
  +        return answer;
  +    }
  +
  +    protected int parseNumber(String text) {
  +        text = text.trim();
  +        return Integer.parseInt(text.trim());
  +    }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org