01: /* SwingML
02: * Copyright (C) 2002 SwingML Team
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Ezequiel Cuellar <ecuellar@crosslogic.com>
21: * Marcelo W. Lopez Cremona <marcelo_java@argentina.com>
22: *
23: */
24:
25: package org.swingml.xml.mapper;
26:
27: import java.awt.*;
28:
29: import javax.swing.*;
30:
31: import org.swingml.*;
32: import org.swingml.model.*;
33: import org.swingml.xml.*;
34: import org.w3c.dom.*;
35:
36: public class JListMapper extends MapperUtil implements Mapper {
37:
38: public Object getModelToMap(Node aNode, Object aParent,
39: Container aContainer) {
40: JListModel theModel = new JListModel();
41: SwingMLModel theContainer = (SwingMLModel) aParent;
42: theContainer.addChild(theModel);
43: theModel.setParent(theContainer);
44: return theModel;
45: }
46:
47: public void mapModel(Node aNode, Object aParent,
48: Container aContainer) {
49: JListModel theModel = (JListModel) this .getModelToMap(aNode,
50: aParent, aContainer);
51: this .mapModelAttributes(aNode, theModel, aParent);
52: super .iterate(aNode, theModel, aContainer);
53: }
54:
55: public void mapModelAttributes(Node aNode, Object aModel,
56: Object aParent) {
57: JListModel theModel = (JListModel) aModel;
58:
59: super .mapCommonAttributes(theModel, aNode);
60:
61: Node theResultNode = super .getAttribute(aNode, Constants.MODE);
62: if (theResultNode != null) {
63: if (theResultNode.getNodeValue().equalsIgnoreCase(
64: Constants.SINGLE)) {
65: theModel.setMode(ListSelectionModel.SINGLE_SELECTION);
66: } else if (theResultNode.getNodeValue().equalsIgnoreCase(
67: Constants.MULTIPLE)) {
68: theModel
69: .setMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
70: }
71: }
72:
73: theResultNode = super .getAttribute(aNode, Constants.POST_STYLE);
74: if (theResultNode != null) {
75: theModel.setPostStyle(theResultNode.getNodeValue());
76: }
77:
78: theResultNode = super .getAttribute(aNode, Constants.DNDENABLED);
79: if (theResultNode != null) {
80: if (theResultNode.getNodeValue().equalsIgnoreCase(
81: Constants.TRUE)) {
82: theModel.setDndEnabled(true);
83: }
84: }
85:
86: theResultNode = super .getAttribute(aNode,
87: Constants.VISIBLE_ROW_COUNT);
88: if (theResultNode != null) {
89: int rowCount = Integer.parseInt(theResultNode
90: .getNodeValue());
91: if (rowCount < 1) {
92: rowCount = 1;
93: }
94: theModel.setVisibleRowCount(rowCount);
95: }
96:
97: }
98: }
|