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: * Bram Stieperaere <bramez@users.sourceforge.net>
022: *
023: */
024:
025: package org.swingml.xml.mapper;
026:
027: import java.awt.*;
028:
029: import javax.swing.*;
030:
031: import org.swingml.*;
032: import org.swingml.model.*;
033: import org.swingml.xml.*;
034: import org.w3c.dom.*;
035:
036: public class JSliderMapper extends MapperUtil implements Mapper {
037:
038: public Object getModelToMap(Node aNode, Object aParent,
039: Container aContainer) {
040: SwingMLModel theContainer = (SwingMLModel) aParent;
041: JSliderModel theModel = new JSliderModel();
042: theModel.setParent(theContainer);
043: theContainer.addChild(theModel);
044: return theModel;
045: }
046:
047: public void mapModel(Node aNode, Object aParent,
048: Container aContainer) {
049: JSliderModel theModel = (JSliderModel) getModelToMap(aNode,
050: 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: JSliderModel theModel = (JSliderModel) aModel;
058: super .mapCommonAttributes(theModel, aNode);
059: Node theResultNode = super .getAttribute(aNode, Constants.VALUE);
060: if (theResultNode != null) {
061: try {
062: int theValue = Integer.parseInt(theResultNode
063: .getNodeValue());
064: theModel.setValue(theValue);
065: } catch (NumberFormatException e) {
066: }
067: }
068: theResultNode = super .getAttribute(aNode, Constants.ENABLED);
069: if (theResultNode != null) {
070: if (theResultNode.getNodeValue().equals(Constants.FALSE)) {
071: theModel.setEnabled(false);
072: }
073: }
074: theResultNode = super .getAttribute(aNode, Constants.MINIMUM);
075: if (theResultNode != null) {
076: try {
077: int theMinimum = Integer.parseInt(theResultNode
078: .getNodeValue());
079: theModel.setMinimum(theMinimum);
080: } catch (NumberFormatException e) {
081: }
082: }
083: theResultNode = super .getAttribute(aNode, Constants.MAXIMUM);
084: if (theResultNode != null) {
085: try {
086: int theMaximum = Integer.parseInt(theResultNode
087: .getNodeValue());
088: theModel.setMaximum(theMaximum);
089: } catch (NumberFormatException e) {
090: }
091: }
092: theResultNode = super.getAttribute(aNode, Constants.TYPE);
093: if (theResultNode != null) {
094: if (theResultNode.getNodeValue().equalsIgnoreCase(
095: Constants.HORIZONTAL)) {
096: theModel.setType(JSlider.HORIZONTAL);
097: }
098: if (theResultNode.getNodeValue().equalsIgnoreCase(
099: Constants.VERTICAL)) {
100: theModel.setType(JSlider.VERTICAL);
101: }
102: }
103: }
104:
105: }
|