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: * Farid Ibrahim <faridibrahim@lycos.com>
021: *
022: */
023:
024: package org.swingml.xml.mapper;
025:
026: import java.awt.*;
027:
028: import org.swingml.*;
029: import org.swingml.model.*;
030: import org.swingml.xml.*;
031: import org.w3c.dom.*;
032:
033: public class JDialogMapper extends MapperUtil implements Mapper {
034:
035: public Object getModelToMap(Node aNode, Object aParent,
036: Container aContainer) {
037: JDialogModel theModel = new JDialogModel();
038: SwingMLModel theContainer = (SwingMLModel) aParent;
039: theContainer.addChild(theModel);
040: theModel.setParent(theContainer);
041: return theModel;
042: }
043:
044: public void mapModel(Node aNode, Object aParent,
045: Container aContainer) {
046: JDialogModel theModel = (JDialogModel) this .getModelToMap(
047: aNode, aParent, aContainer);
048: this .mapModelAttributes(aNode, theModel, aParent);
049: super .iterate(aNode, theModel, aContainer);
050: }
051:
052: public void mapModelAttributes(Node aNode, Object aModel,
053: Object aParent) {
054: JDialogModel theModel = (JDialogModel) aModel;
055: super .mapCommonAttributes(theModel, aNode);
056: Node theResultNode = super .getAttribute(aNode, Constants.ROWS);
057: if (theResultNode != null) {
058: try {
059: theModel.setRows(Integer.parseInt(theResultNode
060: .getNodeValue()));
061: } catch (NumberFormatException e) {
062: theModel.setRows(0);
063: }
064: }
065: theResultNode = super .getAttribute(aNode, Constants.COLS);
066: if (theResultNode != null) {
067: try {
068: theModel.setCols(Integer.parseInt(theResultNode
069: .getNodeValue()));
070: } catch (NumberFormatException e) {
071: theModel.setCols(0);
072: }
073: }
074: theResultNode = super .getAttribute(aNode, Constants.WIDTH);
075: if (theResultNode != null) {
076: try {
077: theModel.setWidth(Integer.parseInt(theResultNode
078: .getNodeValue()));
079: } catch (NumberFormatException e) {
080: theModel.setWidth(0);
081: }
082: }
083: theResultNode = super .getAttribute(aNode, Constants.HEIGHT);
084: if (theResultNode != null) {
085: try {
086: theModel.setHeight(Integer.parseInt(theResultNode
087: .getNodeValue()));
088: } catch (NumberFormatException e) {
089: theModel.setHeight(0);
090: }
091: }
092:
093: theResultNode = super .getAttribute(aNode, Constants.MODAL);
094: if (theResultNode != null) {
095: String modalValue = theResultNode.getNodeValue();
096: theModel.setModal((modalValue
097: .equalsIgnoreCase(Constants.TRUE)));
098: }
099:
100: theResultNode = super .getAttribute(aNode, Constants.STATUS_BAR);
101: if (theResultNode != null) {
102: try {
103: theModel.setShowStatusBar(Boolean.valueOf(
104: theResultNode.getNodeValue()).booleanValue());
105: } catch (NumberFormatException e) {
106: theModel.setShowStatusBar(false);
107: }
108: } else {
109: theModel.setShowStatusBar(false);
110: }
111:
112: }
113: }
|