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:
022: package org.swingml.xml.mapper;
023:
024: import java.awt.*;
025:
026: import javax.swing.border.*;
027:
028: import org.swingml.*;
029: import org.swingml.model.*;
030: import org.swingml.xml.*;
031: import org.w3c.dom.*;
032:
033: public class JPanelMapper extends MapperUtil implements Mapper {
034:
035: public Object getModelToMap(Node aNode, Object aParent,
036: Container aContainer) {
037: JPanelModel theModel = new JPanelModel();
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 aModel, Container aContainer) {
045: JPanelModel theModel = (JPanelModel) getModelToMap(aNode,
046: aModel, aContainer);
047: this .mapModelAttributes(aNode, theModel, aModel);
048: super .iterate(aNode, theModel, aContainer);
049: }
050:
051: public void mapModelAttributes(Node aNode, Object aModel,
052: Object aParent) {
053: JPanelModel theModel = (JPanelModel) aModel;
054: super .mapCommonAttributes(theModel, aNode);
055: Node theResultNode = super .getAttribute(aNode, Constants.TITLE);
056: if (theResultNode != null) {
057: theModel.setTitle(theResultNode.getNodeValue());
058: }
059: theResultNode = super
060: .getAttribute(aNode, Constants.WINDOWTITLE);
061: if (theResultNode != null) {
062: theModel.setWindowTitle(theResultNode.getNodeValue());
063: }
064: theResultNode = super .getAttribute(aNode, Constants.LAF);
065: if (theResultNode != null) {
066: theModel.setLookAndFeel(theResultNode.getNodeValue());
067: }
068: theResultNode = super .getAttribute(aNode, Constants.EXT_LAF);
069: if (theResultNode != null) {
070: theModel.setExternalLookAndFeel(theResultNode
071: .getNodeValue());
072: }
073: theResultNode = super .getAttribute(aNode, Constants.BORDER);
074: if (theResultNode != null) {
075: theModel.setBorder(theResultNode.getNodeValue());
076: } else {
077: theModel.setBorder("");
078: }
079: theResultNode = super .getAttribute(aNode, Constants.BEVELTYPE);
080: if (theResultNode != null) {
081: int theBevelType = 0;
082: if (theResultNode.getNodeValue().equalsIgnoreCase(
083: Constants.LOWERED)) {
084: theBevelType = BevelBorder.LOWERED;
085: } else if (theResultNode.getNodeValue().equalsIgnoreCase(
086: Constants.RAISED)) {
087: theBevelType = BevelBorder.RAISED;
088: }
089: theModel.setBevelType(theBevelType);
090: }
091: theResultNode = super .getAttribute(aNode, Constants.ROWS);
092: if (theResultNode != null) {
093: try {
094: theModel.setRows(Integer.parseInt(theResultNode
095: .getNodeValue()));
096: } catch (NumberFormatException e) {
097: theModel.setRows(0);
098: }
099: }
100:
101: theResultNode = super .getAttribute(aNode, Constants.COLS);
102: if (theResultNode != null) {
103: try {
104: theModel.setCols(Integer.parseInt(theResultNode
105: .getNodeValue()));
106: } catch (NumberFormatException e) {
107: theModel.setCols(0);
108: }
109: }
110:
111: theResultNode = super
112: .getAttribute(aNode, Constants.COLLAPSABLE);
113: if (theResultNode != null) {
114: boolean collapsable = Boolean.valueOf(
115: theResultNode.getNodeValue()).booleanValue();
116: theModel.setCollapsable(collapsable);
117: }
118:
119: theResultNode = super .getAttribute(aNode, Constants.COLLAPSED);
120: if (theResultNode != null) {
121: boolean collapsed = Boolean.valueOf(
122: theResultNode.getNodeValue()).booleanValue();
123: theModel.setCollapsed(collapsed);
124: }
125:
126: theResultNode = super.getAttribute(aNode, Constants.TEXT);
127: if (theResultNode != null) {
128: theModel.setText(theResultNode.getNodeValue());
129: }
130: }
131: }
|