1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17 package ch.elca.el4j.services.gui.swing.cookswing.designgridlayout;
18
19 import javax.swing.JComponent;
20
21 import ch.elca.el4j.services.gui.swing.cookswing.binding.NoAddValueHolder;
22
23 import net.java.dev.designgridlayout.IGridRow;
24 import net.java.dev.designgridlayout.IRow;
25
26 import cookxml.core.DecodeEngine;
27 import cookxml.core.interfaces.Adder;
28
29 /**
30 * This cookXML adder handles <row> elements: They get added to the parent
31 * designgridlayout.
32 *
33 * @svnLink $Revision: 3883 $;$Date: 2009-08-04 15:35:01 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/swing/src/main/java/ch/elca/el4j/services/gui/swing/cookswing/designgridlayout/RowAdder.java $
34 *
35 * @author Stefan Wismer (SWI)
36 */
37 public class RowAdder implements Adder {
38
39 /** {@inheritDoc} */
40 @SuppressWarnings("unchecked")
41 public boolean add(String parentNS, String parentTag, Object parent,
42 Object child, DecodeEngine decodeEngine) throws Exception {
43
44 if (parentTag.equals("row") && parent instanceof NoAddValueHolder) {
45
46 // create row
47 IRow row = ((NoAddValueHolder<IRow>) parent).getObject();
48 if (row instanceof IGridRow) {
49 IGridRow gridRow = (IGridRow) row;
50
51 // read span attribute
52 String spanAttr = decodeEngine.getCurrentElement().getAttribute("colspan");
53 int span = 1;
54 try {
55 span = Integer.parseInt(spanAttr);
56 } catch (NumberFormatException e) {
57 span = 1;
58 }
59
60 if (child != null) {
61 gridRow.add((JComponent) child, span);
62 } else {
63 gridRow.empty(span);
64 }
65 } else {
66 row.add((JComponent) child);
67 }
68
69 return true;
70 }
71 return false;
72 }
73
74 }