You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2003/02/11 16:29:07 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters PointConverter.java
jstrachan 2003/02/11 07:29:07
Modified: jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt
tree.jelly example.jelly
jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt
SwtTagLibrary.java WidgetTag.java
Added: jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters
PointConverter.java
Log:
Applied patch kindly supplied by Christiaan ten Klooster to support the setting of control size.
We now use bean utils Converter to support Point based attribtues - though SWT's Control breaks the JavaBeans naming conventions for the "size" property, so its handled specially in the WidgetTag
Revision Changes Path
1.3 +3 -1 jakarta-commons/jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt/tree.jelly
Index: tree.jelly
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt/tree.jelly,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- tree.jelly 31 Jan 2003 12:54:02 -0000 1.2
+++ tree.jelly 11 Feb 2003 15:29:06 -0000 1.3
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns="jelly:swt" xmlns:log="jelly:log">
- <shell text="Tree Demo" var="subShell" style="border, close, min, max, resize, title">
+ <shell text="Tree Demo" var="subShell" size="500,500" style="border, close, min, max, resize, title">
<gridLayout/>
@@ -31,6 +31,8 @@
</tree>
</shell>
+<!--
${subShell.pack()}
+-->
${subShell.open()}
</j:jelly>
1.4 +3 -1 jakarta-commons/jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt/example.jelly
Index: example.jelly
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/test/org/apache/commons/jelly/tags/swt/example.jelly,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- example.jelly 31 Jan 2003 17:16:16 -0000 1.3
+++ example.jelly 11 Feb 2003 15:29:06 -0000 1.4
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns="jelly:swt" xmlns:log="jelly:log">
- <shell text="This is a shell" var="shell" style="border, close, min, max, resize, title">
+ <shell text="This is a shell" var="shell" size="600,300" style="border, close, min, max, resize, title">
<menu style="bar">
<menuItem text="File" style="cascade">
<menu>
@@ -86,7 +86,9 @@
<!-- we could abstract the following away as a tag -->
+<!--
${shell.pack()}
+-->
${shell.open()}
<j:set var="display" value="${shell.display}"/>
1.6 +6 -1 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SwtTagLibrary.java 7 Feb 2003 12:53:55 -0000 1.5
+++ SwtTagLibrary.java 11 Feb 2003 15:29:06 -0000 1.6
@@ -63,6 +63,7 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -70,10 +71,13 @@
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;
+import org.apache.commons.beanutils.ConvertUtils;
+
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.Tag;
import org.apache.commons.jelly.TagLibrary;
import org.apache.commons.jelly.impl.TagFactory;
+import org.apache.commons.jelly.tags.swt.converters.PointConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -92,7 +96,8 @@
private static final Log log = LogFactory.getLog(SwtTagLibrary.class);
static {
- // we could create Converters from Strings to various SWT types
+ // register the various beanutils Converters from Strings to various SWT types
+ ConvertUtils.register( new PointConverter(), Point.class );
}
public SwtTagLibrary() {
1.7 +34 -0 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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- WidgetTag.java 1 Feb 2003 11:22:23 -0000 1.6
+++ WidgetTag.java 11 Feb 2003 15:29:06 -0000 1.7
@@ -68,9 +68,12 @@
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.tags.core.UseBeanTag;
+import org.apache.commons.jelly.tags.swt.converters.PointConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Widget;
/**
@@ -78,6 +81,7 @@
* 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>
* @version 1.1
*/
public class WidgetTag extends UseBeanTag {
@@ -163,8 +167,38 @@
if (parent != null) {
attachWidgets(parent, widget);
}
+
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 {
+
+ // special handling of size property as the Control object breaks the
+ // JavaBean naming conventions by overloading the setSize() method
+ if (bean instanceof Control) {
+ Object size = attributes.remove("size");
+ if (size != null) {
+ Point point = null;
+ if (size instanceof Point) {
+ point = (Point) size;
+ }
+ else {
+ point = PointConverter.getInstance().parse(size.toString());
+ }
+ Control control = (Control) bean;
+ control.setSize(point);
+ }
+ }
+
+ // TODO Auto-generated method stub
+ super.setBeanProperties(bean, attributes);
+ }
+
+
/**
* Provides a strategy method to allow a new child widget to be attached to
1.1 jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters/PointConverter.java
Index: PointConverter.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/swt/src/java/org/apache/commons/jelly/tags/swt/converters/PointConverter.java,v 1.1 2003/02/11 15:29:07 jstrachan Exp $
* $Revision: 1.1 $
* $Date: 2003/02/11 15:29:07 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: PointConverter.java,v 1.1 2003/02/11 15:29:07 jstrachan Exp $
*/
package org.apache.commons.jelly.tags.swt.converters;
import java.util.StringTokenizer;
import org.apache.commons.beanutils.Converter;
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>
* @version $Revision: 1.1 $
*/
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) {
StringTokenizer enum = new StringTokenizer( text, "," );
int x = 0;
int y = 0;
if ( enum.hasMoreTokens() ) {
x = parseNumber( enum.nextToken() );
}
if ( enum.hasMoreTokens() ) {
y = parseNumber( enum.nextToken() );
}
return new Point( x, y );
}
// 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