001: /*
002: * SwingML Copyright (C) 2002 SwingML Team
003: *
004: * This library is free software; you can redistribute it and/or modify it under
005: * the terms of the GNU Lesser General Public License as published by the Free
006: * Software Foundation; either version 2 of the License, or (at your option) any
007: * later version.
008: *
009: * This library is distributed in the hope that it will be useful, but WITHOUT
010: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012: * details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with this library; if not, write to the Free Software Foundation, Inc.,
016: * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: * Authors: Ezequiel Cuellar <ecuellar@crosslogic.com>
019: *
020: */
021:
022: package org.swingml.xml.mapper;
023:
024: import java.awt.*;
025: import java.util.*;
026:
027: import javax.swing.*;
028:
029: import org.swingml.*;
030: import org.swingml.component.*;
031: import org.swingml.model.*;
032: import org.swingml.xml.*;
033: import org.w3c.dom.*;
034:
035: public class TableColumnMapper extends MapperUtil implements Mapper {
036:
037: public Object getModelToMap(Node node, Object parent,
038: Container aContainer) {
039: TableColumnModel theModel = new TableColumnModel();
040: SwingMLModel theContainer = (SwingMLModel) parent;
041: theContainer.addChild(theModel);
042: theModel.setParent(theContainer);
043: return theModel;
044: }
045:
046: public void mapModel(Node node, Object parent, Container aContainer) {
047: TableColumnModel m = (TableColumnModel) this .getModelToMap(
048: node, parent, aContainer);
049: this .mapModelAttributes(node, m, parent);
050: iterate(node, m, aContainer);
051: }
052:
053: public void mapModelAttributes(Node node, Object model,
054: Object parent) {
055: TableColumnModel m = (TableColumnModel) model;
056: super .mapCommonAttributes(m, node);
057: Node n = super .getAttribute(node, Constants.ITEMS);
058: if (n != null) {
059: Vector theItems = new Vector();
060: StringTokenizer theTokens = new StringTokenizer(n
061: .getNodeValue(), ",");
062: while (theTokens.hasMoreTokens()) {
063: theItems.addElement(theTokens.nextToken());
064: }
065: m.setItems(theItems);
066: }
067: n = super .getAttribute(node, Constants.TYPE);
068: if (n != null) {
069: String theType = n.getNodeValue();
070: if (theType.equalsIgnoreCase(Constants.BOOLEAN)) {
071: m.setType(new Boolean(false));
072: }
073: if (theType.equalsIgnoreCase(Constants.COMBO)) {
074: m.setType(new JComboBox());
075: }
076: if (theType.equalsIgnoreCase(Constants.COLOR)) {
077: m.setType(new ColorComponent(0));
078: }
079: if (theType.equalsIgnoreCase(Constants.STRING)) {
080: m.setType(new String());
081: }
082: } else {
083: m.setType(new String());
084: }
085:
086: n = super .getAttribute(node, Constants.ALIGN);
087: if (n != null) {
088: m.setAlignment(n.getNodeValue());
089: }
090:
091: n = super .getAttribute(node, Constants.WIDTH);
092: if (n != null) {
093: m.setWidth(Integer.parseInt(n.getNodeValue()));
094: }
095:
096: n = super .getAttribute(node, Constants.HIDDEN);
097: if (n != null) {
098: m.setHidden(new Boolean(n.getNodeValue()).booleanValue());
099: }
100:
101: n = super .getAttribute(node, Constants.COLUMN_ORDER);
102: if (n != null) {
103: try {
104: m.setColumnOrder(Integer.parseInt(n.getNodeValue()));
105: } catch (NumberFormatException nfe) {
106:
107: }
108: }
109:
110: }
111: }
|