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: package org.swingml.xml.mapper;
022:
023: import java.awt.*;
024:
025: import org.swingml.*;
026: import org.swingml.model.*;
027: import org.swingml.xml.*;
028: import org.w3c.dom.*;
029:
030: public class JTextAreaMapper extends MapperUtil implements Mapper {
031:
032: public Object getModelToMap(Node aNode, Object aParent,
033: Container aContainer) {
034: SwingMLModel theContainer = (SwingMLModel) aParent;
035: JTextAreaModel theModel = new JTextAreaModel();
036: theContainer.addChild(theModel);
037: theModel.setParent(theContainer);
038: return theModel;
039: }
040:
041: public void mapModel(Node aNode, Object aParent,
042: Container aContainer) {
043: JTextAreaModel theModel = (JTextAreaModel) this .getModelToMap(
044: aNode, aParent, aContainer);
045: this .mapModelAttributes(aNode, theModel, aParent);
046: super .iterate(aNode, theModel, aContainer);
047: }
048:
049: public void mapModelAttributes(Node aNode, Object aModel,
050: Object aParent) {
051: JTextAreaModel m = (JTextAreaModel) aModel;
052: super .mapCommonAttributes(m, aNode);
053: Node n = super .getAttribute(aNode, Constants.COLS);
054: if (n != null) {
055: try {
056: m.setCols(Integer.parseInt(n.getNodeValue()));
057: } catch (NumberFormatException e) {
058: m.setCols(0);
059: }
060: }
061: n = super .getAttribute(aNode, Constants.ROWS);
062: if (n != null) {
063: try {
064: m.setRows(Integer.parseInt(n.getNodeValue()));
065: } catch (NumberFormatException e) {
066: m.setRows(0);
067: }
068: }
069: n = super .getAttribute(aNode, Constants.LINE_WRAP);
070: if (n != null) {
071: String s = n.getNodeValue();
072: if (s != null) {
073: if ("true".equals(s.toLowerCase())) {
074: m.setLineWrap(true);
075: } else {
076: m.setLineWrap(false);
077: }
078:
079: }
080: }
081: n = super .getAttribute(aNode, Constants.EDITABLE);
082: if (n != null) {
083: String s = n.getNodeValue();
084: if (s != null) {
085: boolean editable = Boolean.valueOf(s).booleanValue();
086: m.setEditable(editable);
087: }
088: }
089: n = super .getAttribute(aNode, Constants.WORD_WRAP);
090: if (n != null) {
091: try {
092: String nv = n.getNodeValue().toLowerCase();
093: if ("true".equals(nv)) {
094: m.setWrapStyleWord(true);
095: } else {
096: m.setWrapStyleWord(false);
097: }
098: } catch (Exception x) {
099: /* this is a throw away exception, let the value remain unset */
100: }
101: }
102: NodeList theNodes = aNode.getChildNodes();
103: for (int i = 0; i < theNodes.getLength(); i++) {
104: n = theNodes.item(i);
105: if (n.getNodeName().equalsIgnoreCase(Constants.TEXT)) {
106: Node firstChild = n.getFirstChild();
107: if (firstChild != null) {
108: m.setText(firstChild.getNodeValue());
109: }
110: }
111: }
112: }
113: }
|