dion 2004/09/12 08:34:32
Modified: jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing
SwingTagLibrary.java ComponentTag.java
jelly/jelly-tags/swing/xdocs changes.xml
jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing
swingTags.jelly TestSwingTags.java
jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/converters
DebugGraphicsConverter.java
jelly/jelly-tags/swing project.xml
Log:
- open up new release for work
- apply jelly-10
Revision Changes Path
1.29 +0 -1
jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java
Index: SwingTagLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/SwingTagLibrary.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- SwingTagLibrary.java 9 Sep 2004 12:16:57 -0000 1.28
+++ SwingTagLibrary.java 12 Sep 2004 15:34:32 -0000 1.29
@@ -61,7 +61,6 @@
ConvertUtils.register( new DimensionConverter(), Dimension.class );
ConvertUtils.register( new PointConverter(), Point.class );
ConvertUtils.register( new ColorConverter(), java.awt.Color.class );
- DebugGraphicsConverter.register();
}
public SwingTagLibrary() {
1.22 +42 -69
jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ComponentTag.java
Index: ComponentTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ComponentTag.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ComponentTag.java 9 Sep 2004 12:16:57 -0000 1.21
+++ ComponentTag.java 12 Sep 2004 15:34:32 -0000 1.22
@@ -22,26 +22,29 @@
import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.Point;
-import java.awt.Color;
import java.awt.Window;
-import java.awt.event.WindowListener;
-import java.awt.event.KeyListener;
import java.awt.event.FocusListener;
+import java.awt.event.KeyListener;
+import java.awt.event.WindowListener;
import java.lang.reflect.InvocationTargetException;
-import java.util.Iterator;
import java.util.Map;
-import javax.swing.*;
+import javax.swing.Action;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.RootPaneContainer;
import javax.swing.border.Border;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
-
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.tags.core.UseBeanTag;
-
+import org.apache.commons.jelly.tags.swing.converters.DebugGraphicsConverter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -62,7 +65,13 @@
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(ComponentTag.class);
-
+
+ /** This is a converter that might normally be used through the
+ * BeanUtils product. However, it only applies to one Component
+ * property and not to all ints, so it's not registered with BeanUtils.
+ */
+ private static final DebugGraphicsConverter debugGraphicsConverter = new
DebugGraphicsConverter();
+
/** the factory of widgets */
private Factory factory;
@@ -316,18 +325,14 @@
}
/**
- * Patch to handle wierd properties that don't quite match the Java Beans
contract
+ * Handles wierd properties that don't quite match the Java Beans contract
*/
protected void setBeanProperties(Object bean, Map attributes) throws
JellyTagException {
- for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- String name = (String) entry.getKey();
- Object value = entry.getValue();
-
- // ### special hacks for properties that don't introspect properly
+
Component component = getComponent();
if (component != null) {
- if (name.equals("location")) {
+ if (attributes.containsKey("location")) {
+ Object value = attributes.get("location");
Point p = null;
if (value instanceof Point) {
p = (Point) value;
@@ -339,8 +344,11 @@
Point.class);
}
component.setLocation(p);
+ addIgnoreProperty("location");
}
- else if (name.equals("size")) {
+
+ if (attributes.containsKey("size")) {
+ Object value = attributes.get("size");
Dimension d = null;
if (value instanceof Dimension) {
d = (Dimension) value;
@@ -352,65 +360,30 @@
Dimension.class);
}
component.setSize(d);
+ addIgnoreProperty("size");
}
- else if (
- name.equalsIgnoreCase("background")
- || name.equalsIgnoreCase("foreground")) {
- Color c = null;
- if (value instanceof Color) {
- c = (Color) value;
- }
- else if (value != null) {
- c =
- (Color) ConvertUtils.convert(
- value.toString(),
- Color.class);
- }
-
- if (name.equalsIgnoreCase("background")) {
- component.setBackground(c);
- }
- else {
- component.setForeground(c);
+
+ if (attributes.containsKey("debugGraphicsOptions")) {
+ try {
+ Object o =
debugGraphicsConverter.convert(attributes.get("debugGraphicsOptions"));
+ attributes.put("debugGraphicsOptions", o);
+ } catch (IllegalArgumentException e) {
+ throw new JellyTagException(e);
}
}
- else if (
- name.equalsIgnoreCase("debugGraphicsOption")
- || name.equalsIgnoreCase("debugGraphics")
- || name.equalsIgnoreCase("debug")) {
-
- Integer v = null;
- if (!(value instanceof Integer))
- v =
- (Integer) ConvertUtils.convert(
- value.toString(),
- Integer.class);
- else
- v = (Integer) value;
- if (!(component instanceof JComponent))
- throw new IllegalArgumentException("DebugGraphics can only
be set on a JComponent subclass.");
- ((JComponent) component).setDebugGraphicsOptions(
- v.intValue());
- }
- else {
+
+ if (attributes.containsKey("debugGraphics")) {
try {
- BeanUtils.setProperty(component, name, value);
- } catch (IllegalAccessException e) {
- throw new JellyTagException(e);
- } catch (InvocationTargetException e) {
+ Object o =
debugGraphicsConverter.convert(attributes.get("debugGraphics"));
+ attributes.put("debugGraphicsOptions", o);
+ } catch (IllegalArgumentException e) {
throw new JellyTagException(e);
}
+
+ addIgnoreProperty("debugGraphics");
}
- }
- else {
- try {
- BeanUtils.setProperty(bean, name, value);
- } catch (IllegalAccessException e) {
- throw new JellyTagException(e);
- } catch (InvocationTargetException e) {
- throw new JellyTagException(e);
- }
- }
+
+ super.setBeanProperties(bean, attributes);
}
}
1.10 +5 -1 jakarta-commons/jelly/jelly-tags/swing/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swing/xdocs/changes.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- changes.xml 8 Sep 2004 06:41:17 -0000 1.9
+++ changes.xml 12 Sep 2004 15:34:32 -0000 1.10
@@ -24,7 +24,11 @@
<author email="[EMAIL PROTECTED]">dIon Gillard</author>
</properties>
<body>
- <release version="1.0-SNAPSHOT" date="in CVS">
+ <release version="1.1-SNAPSHOT" date="in CVS">
+ <action dev="dion" type="fix" issue="JELLY-10" due-to="Hans Gilde">JellySwing
should be strict on the attribute names it uses.</action>
+ </release>
+
+ <release version="1.0" date="2004-09-12">
<action dev="dion" type="add" issue="JELLY-133" due-to="Hans
Gilde">ComponentTag methods should throw JellyTagException.</action>
<action dev="dion" type="add" issue="JELLY-132" due-to="Hans
Gilde">ButtonGroup tag is broken.</action>
<action dev="dion" type="add" issue="JELLY-114">Action tag ignores enabled
property.</action>
1.4 +12 -4
jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/swingTags.jelly
Index: swingTags.jelly
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/swingTags.jelly,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- swingTags.jelly 8 Sep 2004 06:39:00 -0000 1.3
+++ swingTags.jelly 12 Sep 2004 15:34:32 -0000 1.4
@@ -2,12 +2,12 @@
<j:jelly
xmlns:j="jelly:core"
xmlns="jelly:swing">
-
- <!--for the basic component addembly-->
+
+ <!--for the basic component assembly-->
<j:if test="${test.simple}">
<frame name="frame" var="frame" size="100,100" location="200,200">
- <panel name="panel">
- <button name="button" background="#112233" foreground="#445566"/>
+ <panel name="panel" debugGraphics="log|flash">
+ <button name="button" background="#112233" foreground="#445566"
debugGraphicsOptions="buffered"/>
</panel>
</frame>
</j:if>
@@ -68,4 +68,12 @@
</frame>
</j:if>
+ <!--tries to set a bean property that doesn't exist-->
+ <j:if test="${test.invalidProperty}">
+ <frame name="frame" var="frame" size="100,100" location="200,200" foo="bar">
+ <panel name="panel">
+ </panel>
+ </frame>
+ </j:if>
+
</j:jelly>
1.10 +25 -0
jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/TestSwingTags.java
Index: TestSwingTags.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/test/org/apache/commons/jelly/swing/TestSwingTags.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestSwingTags.java 9 Sep 2004 12:16:59 -0000 1.9
+++ TestSwingTags.java 12 Sep 2004 15:34:32 -0000 1.10
@@ -23,8 +23,10 @@
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
+import java.io.UnsupportedEncodingException;
import javax.swing.ButtonGroup;
+import javax.swing.DebugGraphics;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
@@ -33,6 +35,7 @@
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.Script;
+import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.core.BaseJellyTest;
/** Tests many swing tags for basic functionality.
@@ -68,6 +71,8 @@
assertNotNull(button);
assertEquals(new Color(0x11,0x22,0x33), button.getBackground());
assertEquals(new Color(0x44,0x55,0x66), button.getForeground());
+ assertEquals(DebugGraphics.FLASH_OPTION|DebugGraphics.LOG_OPTION,
panel.getDebugGraphicsOptions());
+ assertEquals(DebugGraphics.BUFFERED_OPTION,
button.getDebugGraphicsOptions());
}
/** Tests the GridbagLayout tags, making sure that the constraints are
@@ -139,6 +144,16 @@
assertNotNull(bg.getSelection());
}
+ public void testInvalidBeanProperty() throws Exception {
+ if (!isAWTAvailable()) return;
+ try {
+ runSwingScript("test.invalidProperty");
+ } catch (Exception e) {
+ //success
+ return;
+ }
+ fail("Should have thrown an exception due to an invalid bean property.");
+ }
protected void runSwingScript(String testName) throws Exception {
setUpScript("swingTags.jelly");
@@ -173,5 +188,15 @@
*/
private boolean isAWTAvailable() {
return !Boolean.getBoolean("java.awt.headless");
+ }
+ /* (non-Javadoc)
+ * @see org.apache.commons.jelly.core.BaseJellyTest#getXMLOutput()
+ */
+ protected XMLOutput getXMLOutput() {
+ try {
+ return XMLOutput.createXMLOutput(System.out);
+ } catch (UnsupportedEncodingException e) {
+ return null;
+ }
}
}
1.6 +12 -0
jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/converters/DebugGraphicsConverter.java
Index: DebugGraphicsConverter.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/converters/DebugGraphicsConverter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DebugGraphicsConverter.java 8 Sep 2004 04:51:13 -0000 1.5
+++ DebugGraphicsConverter.java 12 Sep 2004 15:34:32 -0000 1.6
@@ -39,7 +39,19 @@
java.lang.Integer.class);
}
+ /** Part of the Converter interface.
+ * @see org.apache.commons.beanutils.Converter#convert(java.lang.Class,
java.lang.Object)
+ */
public Object convert(Class type, Object value) {
+ return convert(value);
+ }
+
+ /** This is not part of the converter interface, it's for use by
+ * classes that don't use DebugGraphicsConverter through BeanUtils.
+ * @param from
+ * @return
+ */
+ public Object convert(Object value) {
if (value != null) {
int result = 0;
StringTokenizer stok =
1.22 +1 -1 jakarta-commons/jelly/jelly-tags/swing/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swing/project.xml,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- project.xml 12 Sep 2004 14:56:30 -0000 1.21
+++ project.xml 12 Sep 2004 15:34:32 -0000 1.22
@@ -18,7 +18,7 @@
<extend>${basedir}/../tag-project.xml</extend>
<id>commons-jelly-tags-swing</id>
<name>JellySwing</name>
- <currentVersion>1.0</currentVersion>
+ <currentVersion>1.1-SNAPSHOT</currentVersion>
<package>org.apache.commons.jelly.tags.swing</package>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]