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 javax.swing.border.*;
029:
030: import org.swingml.*;
031: import org.swingml.model.*;
032: import org.swingml.xml.*;
033: import org.w3c.dom.*;
034:
035: public class JDesktopPaneMapper extends MapperUtil implements Mapper {
036: public Object getModelToMap(Node aNode, Object aParent,
037: Container aContainer) {
038: JDesktopPaneModel theModel = new JDesktopPaneModel();
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 aModel, Container aContainer) {
046: JDesktopPaneModel theModel = (JDesktopPaneModel) getModelToMap(
047: aNode, aModel, aContainer);
048: this .mapModelAttributes(aNode, theModel, aModel);
049: super .iterate(aNode, theModel, aContainer);
050: }
051:
052: public void mapModelAttributes(Node aNode, Object aModel,
053: Object aParent) {
054: JDesktopPaneModel theModel = (JDesktopPaneModel) aModel;
055: super .mapCommonAttributes(theModel, aNode);
056: Node theResultNode = super .getAttribute(aNode, Constants.TITLE);
057: if (theResultNode != null) {
058: theModel.setTitle(theResultNode.getNodeValue());
059: }
060: theResultNode = super .getAttribute(aNode, Constants.LAF);
061: if (theResultNode != null) {
062: theModel.setLookAndFeel(theResultNode.getNodeValue());
063: }
064: theResultNode = super .getAttribute(aNode, Constants.EXT_LAF);
065: if (theResultNode != null) {
066: theModel.setExternalLookAndFeel(theResultNode
067: .getNodeValue());
068: }
069: theResultNode = super .getAttribute(aNode, Constants.BORDER);
070: if (theResultNode != null) {
071: theModel.setBorder(theResultNode.getNodeValue());
072: } else {
073: theModel.setBorder("");
074: }
075: theResultNode = super .getAttribute(aNode, Constants.BEVELTYPE);
076: if (theResultNode != null) {
077: int theBevelType = 0;
078: if (theResultNode.getNodeValue().equalsIgnoreCase(
079: Constants.LOWERED)) {
080: theBevelType = BevelBorder.LOWERED;
081: } else if (theResultNode.getNodeValue().equalsIgnoreCase(
082: Constants.RAISED)) {
083: theBevelType = BevelBorder.RAISED;
084: }
085: theModel.setBevelType(theBevelType);
086: }
087: theResultNode = super .getAttribute(aNode, Constants.ROWS);
088: if (theResultNode != null) {
089: try {
090: theModel.setRows(Integer.parseInt(theResultNode
091: .getNodeValue()));
092: } catch (NumberFormatException e) {
093: theModel.setRows(0);
094: }
095: }
096: theResultNode = super .getAttribute(aNode, Constants.COLS);
097: if (theResultNode != null) {
098: try {
099: theModel.setCols(Integer.parseInt(theResultNode
100: .getNodeValue()));
101: } catch (NumberFormatException e) {
102: theModel.setCols(0);
103: }
104: }
105: }
106: }
|