protected void setBeanProperties()

in jelly-tags/swing/src/main/java/org/apache/commons/jelly/tags/swing/GbcTag.java [115:173]


    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 = StringUtils.split((String) insetString, ",");

            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);
                        }
                    }
                }
            }
        }
    }