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: * Ezequiel Cuellar <ecuellar@crosslogic.com>
021: * Marcelo W. Lopez Cremona <marcelo_java@argentina.com>
022: *
023: */
024:
025: package org.swingml.xml.mapper;
026:
027: import java.awt.*;
028:
029: import javax.swing.border.*;
030:
031: import org.swingml.*;
032: import org.swingml.model.*;
033: import org.swingml.xml.*;
034: import org.w3c.dom.*;
035:
036: public class ButtonGroupMapper extends MapperUtil implements Mapper {
037:
038: public Object getModelToMap(Node aNode, Object aParent,
039: Container aContainer) {
040: ButtonGroupModel theModel = new ButtonGroupModel();
041: SwingMLModel theContainer = (SwingMLModel) aParent;
042: theContainer.addChild(theModel);
043: theModel.setParent(theContainer);
044: return theModel;
045: }
046:
047: public void mapModel(Node aNode, Object aParent,
048: Container aContainer) {
049: ButtonGroupModel theModel = (ButtonGroupModel) this
050: .getModelToMap(aNode, aParent, aContainer);
051: this .mapModelAttributes(aNode, theModel, aParent);
052: super .iterate(aNode, theModel, aContainer);
053: }
054:
055: public void mapModelAttributes(Node aNode, Object aModel,
056: Object aParent) {
057: ButtonGroupModel theButtonModel = (ButtonGroupModel) aModel;
058: super .mapCommonAttributes(theButtonModel, aNode);
059:
060: Node theResultNode = null;
061:
062: theResultNode = super .getAttribute(aNode, Constants.BORDER);
063: if (theResultNode != null) {
064: theButtonModel.setBorder(theResultNode.getNodeValue());
065: } else {
066: theButtonModel.setBorder("");
067: }
068:
069: theResultNode = super .getAttribute(aNode, Constants.BEVELTYPE);
070: if (theResultNode != null) {
071: int bevelType = 0;
072: if (theResultNode.getNodeValue().equalsIgnoreCase(
073: Constants.LOWERED)) {
074: bevelType = BevelBorder.LOWERED;
075: } else if (theResultNode.getNodeValue().equalsIgnoreCase(
076: Constants.RAISED)) {
077: bevelType = BevelBorder.RAISED;
078: }
079: theButtonModel.setBevelType(bevelType);
080: }
081:
082: theResultNode = super .getAttribute(aNode, Constants.ROWS);
083: if (theResultNode != null) {
084: try {
085: theButtonModel.setRows(Integer.parseInt(theResultNode
086: .getNodeValue()));
087: } catch (NumberFormatException e) {
088: theButtonModel.setRows(0);
089: }
090: }
091:
092: theResultNode = super .getAttribute(aNode, Constants.COLS);
093: if (theResultNode != null) {
094: try {
095: theButtonModel.setCols(Integer.parseInt(theResultNode
096: .getNodeValue()));
097: } catch (NumberFormatException e) {
098: theButtonModel.setCols(0);
099: }
100: }
101:
102: theResultNode = super .getAttribute(aNode, Constants.ENABLED);
103: if (theResultNode != null) {
104: theButtonModel.setEnabled(new Boolean(theResultNode
105: .getNodeValue()).booleanValue());
106: }
107: }
108:
109: }
|