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