You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by pr...@apache.org on 2003/09/04 03:39:35 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing GbcTag.java
proyal 2003/09/03 18:39:35
Modified: jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing
GbcTag.java
Log:
[JELLY-72] Allow <gbc> tag to inherit properties and allow insets to be
easily specified
Patch from Scott Howlett
Revision Changes Path
1.7 +73 -0 jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/GbcTag.java
Index: GbcTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/GbcTag.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- GbcTag.java 24 Jan 2003 22:53:33 -0000 1.6
+++ GbcTag.java 4 Sep 2003 01:39:34 -0000 1.7
@@ -148,5 +148,78 @@
return new GridBagConstraintBean();
}
}
+
+ protected void setBeanProperties(Object bean, Map attributes)
+ throws JellyTagException {
+
+ Insets ins = null;
+ Object insetString = attributes.get("insets");
+ if (insetString instanceof String) {
+ attributes.remove("insets");
+
+ String[] parts = ((String) insetString).split(",");
+
+ if (parts.length != 4) {
+ throw new JellyTagException(
+ "insets must be specified"
+ + "as four comma - separated integers.");
+ }
+
+ ins =
+ new Insets(
+ Integer.parseInt(parts[0].trim()),
+ Integer.parseInt(parts[1].trim()),
+ Integer.parseInt(parts[2].trim()),
+ Integer.parseInt(parts[3].trim()));
+ }
+
+ super.setBeanProperties(bean, attributes);
+
+ // set basedOn info of the bean if we have a parent gbc tag
+ // in the context of the closest gridbaglayout tag
+
+ if (bean instanceof GridBagConstraintBean) {
+ GridBagConstraintBean gbc = (GridBagConstraintBean) bean;
+
+ if (ins != null) {
+ gbc.setInsets(ins);
+ }
+
+ GridBagLayoutTag parentLayoutTag =
+ (GridBagLayoutTag) (findAncestorWithClass(GridBagLayoutTag
+ .class));
+ if (parentLayoutTag != null) {
+ GbcTag parentGbcTag =
+ (GbcTag) (findAncestorWithClass(getParent(),
+ GbcTag.class,
+ parentLayoutTag));
+ if (parentGbcTag != null) {
+ GridBagConstraints parentGbc =
+ parentGbcTag.getConstraints();
+
+ if (parentGbc != null
+ && parentGbc instanceof GridBagConstraintBean) {
+ gbc.setBasedOn((GridBagConstraintBean) parentGbc);
+ if (insetString == null) {
+ gbc.setInsets(parentGbc.insets);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public static Tag findAncestorWithClass(
+ Tag from,
+ Class tagClass,
+ Tag parent) {
+ while (from != null && from != parent) {
+ if (tagClass.isInstance(from)) {
+ return from;
+ }
+ from = from.getParent();
+ }
+ return null;
+ }
}