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: * Alessandro Dibella <alessandro.dibella@fuurou.org>
022: *
023: */
024:
025: package org.swingml.xml.mapper;
026:
027: import java.awt.*;
028:
029: import org.swingml.*;
030: import org.swingml.model.*;
031: import org.swingml.xml.*;
032: import org.w3c.dom.*;
033:
034: public class JFrameMapper extends MapperUtil implements Mapper {
035:
036: public Object getModelToMap(Node aNode, Object aParent,
037: Container aContainer) {
038: JFrameModel theModel = new JFrameModel();
039: SwingMLModel theContainer = (SwingMLModel) aParent;
040: theContainer.addChild(theModel);
041: theModel.setParent(theContainer);
042: return theModel;
043: }
044:
045: public void mapModel(Node aNode, Object aParent,
046: Container aContainer) {
047: JFrameModel theModel = (JFrameModel) this .getModelToMap(aNode,
048: aParent, aContainer);
049: this .mapModelAttributes(aNode, theModel, aParent);
050: super .iterate(aNode, theModel, aContainer);
051: }
052:
053: public void mapModelAttributes(Node aNode, Object aModel,
054: Object aParent) {
055: JFrameModel theModel = (JFrameModel) aModel;
056: super .mapCommonAttributes(theModel, aNode);
057: Node theResultNode = super .getAttribute(aNode, Constants.ROWS);
058: if (theResultNode != null) {
059: try {
060: theModel.setRows(Integer.parseInt(theResultNode
061: .getNodeValue()));
062: } catch (NumberFormatException e) {
063: theModel.setRows(0);
064: }
065: }
066: theResultNode = super .getAttribute(aNode, Constants.COLS);
067: if (theResultNode != null) {
068: try {
069: theModel.setCols(Integer.parseInt(theResultNode
070: .getNodeValue()));
071: } catch (NumberFormatException e) {
072: theModel.setCols(0);
073: }
074: }
075: theResultNode = super .getAttribute(aNode, Constants.WIDTH);
076: if (theResultNode != null) {
077: try {
078: theModel.setWidth(Integer.parseInt(theResultNode
079: .getNodeValue()));
080: } catch (NumberFormatException e) {
081: theModel.setWidth(0);
082: }
083: }
084: theResultNode = super .getAttribute(aNode, Constants.HEIGHT);
085: if (theResultNode != null) {
086: try {
087: theModel.setHeight(Integer.parseInt(theResultNode
088: .getNodeValue()));
089: } catch (NumberFormatException e) {
090: theModel.setHeight(0);
091: }
092: }
093: theResultNode = super .getAttribute(aNode, Constants.STATUS_BAR);
094: if (theResultNode != null) {
095: try {
096: theModel.setShowStatusBar(Boolean.valueOf(
097: theResultNode.getNodeValue()).booleanValue());
098: } catch (NumberFormatException e) {
099: theModel.setShowStatusBar(true);
100: }
101: } else {
102: theModel.setShowStatusBar(true);
103: }
104:
105: theResultNode = super .getAttribute(aNode, Constants.POST_STATE);
106: if (null != theResultNode) {
107: theModel.setPostState(theResultNode.getNodeValue()
108: .equalsIgnoreCase(Constants.TRUE));
109: } else {
110: theModel.setPostState(false);
111: }
112:
113: theResultNode = super .getAttribute(aNode, Constants.XOPEN);
114: if (theResultNode != null) {
115: try {
116: theModel.setXOpen(Integer.parseInt(theResultNode
117: .getNodeValue()));
118: } catch (NumberFormatException e) {
119: theModel.setXOpen(0);
120: }
121: }
122: theResultNode = super .getAttribute(aNode, Constants.YOPEN);
123: if (theResultNode != null) {
124: try {
125: theModel.setYOpen(Integer.parseInt(theResultNode
126: .getNodeValue()));
127: } catch (NumberFormatException e) {
128: theModel.setYOpen(0);
129: }
130: }
131:
132: theResultNode = super .getAttribute(aNode, Constants.MAXIMUM);
133: if (theResultNode != null) {
134: try {
135: theModel.setMaximize(Boolean.valueOf(
136: theResultNode.getNodeValue()).booleanValue());
137: } catch (NumberFormatException e) {
138: theModel.setMaximize(false);
139: }
140: } else {
141: theModel.setMaximize(false);
142: }
143: }
144: }
|