001: /*
002: * SwingML
003: * Copyright (C) 2002 Robert J. Morris.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the
017: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
018: * Boston, MA 02111-1307, USA.
019: *
020: * Authors:
021: * Robert J. Morris <robertj@morris.net>
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.w3c.dom.*;
033:
034: /**
035: * @author rmorris <mailto:robertj@morris.net>
036: *
037: */
038: public class GridBagPanelMapper extends GridBagBaseMapper {
039: /**
040: * @see org.swingml.xml.Mapper#getModelToMap(Node, Object)
041: */
042: public Object getModelToMap(Node aNode, Object aParent,
043: Container aContainer) {
044: GridBagPanelModel theModel = new GridBagPanelModel();
045: SwingMLModel theContainer = (SwingMLModel) aParent;
046: theContainer.addChild(theModel);
047: theModel.setParent(theContainer);
048: return theModel;
049: }
050:
051: /**
052: * @see org.swingml.xml.Mapper#mapModel(Node, Object)
053: */
054: public void mapModel(Node aNode, Object aParent,
055: Container aContainer) {
056: GridBagPanelModel theModel = (GridBagPanelModel) this
057: .getModelToMap(aNode, aParent, aContainer);
058: this .mapModelAttributes(aNode, theModel, aParent);
059: super .iterate(aNode, theModel, aContainer);
060: }
061:
062: /**
063: * @see org.swingml.xml.Mapper#mapModelAttributes(Node, Object, Object)
064: */
065: public void mapModelAttributes(Node aNode, Object aModel,
066: Object aParent) {
067: super .mapModelAttributes(aNode, aModel, aParent);
068: GridBagPanelModel theGridBagPanelModel = (GridBagPanelModel) aModel;
069: Node theResultNode = null;
070: theResultNode = super .getAttribute(aNode, Constants.BEVELTYPE);
071: if (theResultNode != null) {
072: int theBevelType = 0;
073: if (theResultNode.getNodeValue().equalsIgnoreCase(
074: Constants.LOWERED)) {
075: theBevelType = BevelBorder.LOWERED;
076: } else if (theResultNode.getNodeValue().equalsIgnoreCase(
077: Constants.RAISED)) {
078: theBevelType = BevelBorder.RAISED;
079: }
080: theGridBagPanelModel.setBevelType(theBevelType);
081: }
082: theResultNode = super .getAttribute(aNode, Constants.TITLE);
083: if (theResultNode != null) {
084: theGridBagPanelModel.setTitle(theResultNode.getNodeValue());
085: }
086: theResultNode = super .getAttribute(aNode, Constants.BORDER);
087: if (theResultNode != null) {
088: theGridBagPanelModel
089: .setBorder(theResultNode.getNodeValue());
090: } else {
091: theGridBagPanelModel.setBorder("");
092: }
093: theResultNode = super
094: .getAttribute(aNode, Constants.ORIENTATION);
095: if (theResultNode != null) {
096: theGridBagPanelModel.setOrientation(theResultNode
097: .getNodeValue());
098: }
099: }
100: }
|