001: /*
002: * SwingML Copyright (C) 2002 Robert Morris.
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: Robert Morris <robertj@morris.net> Ezequiel Cuellar
019: * <ecuellar@crosslogic.com>
020: *
021: */
022:
023: package org.swingml.xml.mapper;
024:
025: import java.awt.*;
026:
027: import org.swingml.*;
028: import org.swingml.model.*;
029: import org.swingml.system.*;
030: import org.swingml.xml.*;
031: import org.w3c.dom.*;
032:
033: public class JSplitPaneMapper extends MapperUtil implements Mapper {
034:
035: /**
036: * @see org.swingml.xml.Mapper#getModelToMap(Node, Object)
037: */
038: public Object getModelToMap(Node aNode, Object aParent,
039: Container aContainer) {
040: JSplitPaneModel theModel = new JSplitPaneModel();
041: SwingMLModel theContainer = (SwingMLModel) aParent;
042: theContainer.addChild(theModel);
043: theModel.setParent(theContainer);
044: return theModel;
045: }
046:
047: /**
048: * @see org.swingml.xml.Mapper#mapModel(Node, Object)
049: */
050: public void mapModel(Node aNode, Object aParent,
051: Container aContainer) {
052: JSplitPaneModel theModel = (JSplitPaneModel) this
053: .getModelToMap(aNode, aParent, aContainer);
054: this .mapModelAttributes(aNode, theModel, aParent);
055: super .iterate(aNode, theModel, aContainer);
056: }
057:
058: /**
059: * @see org.swingml.xml.Mapper#mapModelAttributes(Node, Object,
060: * Object)
061: */
062: public void mapModelAttributes(Node aNode, Object aModel,
063: Object aParent) {
064: JSplitPaneModel theModel = (JSplitPaneModel) aModel;
065: super .mapCommonAttributes(theModel, aNode);
066: Node theResultNode = super .getAttribute(aNode, Constants.TYPE);
067: if (theResultNode != null) {
068: theModel.setType(theResultNode.getNodeValue());
069: }
070:
071: theResultNode = super .getAttribute(aNode, Constants.SIZE);
072: if (theResultNode != null) {
073: try {
074: theModel.setSize(new Integer(theResultNode
075: .getNodeValue()).intValue());
076: } catch (NumberFormatException e) {
077: SwingMLLogger
078: .getInstance()
079: .log(
080: "Syntax Error: The SPLITTER ["
081: + theModel.getName()
082: + "] must only have a number in the SIZE attribute.");
083: theModel.setSize(10);
084: } catch (Exception e) {
085: SwingMLLogger.getInstance().log(ILogCapable.ERROR, e);
086: }
087: }
088:
089: theResultNode = super .getAttribute(aNode, Constants.EXPANDABLE);
090: if (theResultNode != null) {
091: boolean expandable = Boolean.valueOf(
092: theResultNode.getNodeValue().toString())
093: .booleanValue();
094: theModel.setExpandable(expandable);
095: }
096:
097: theResultNode = super .getAttribute(aNode, Constants.LOCATION);
098: if (theResultNode != null) {
099: Object theNewLocation = null;
100: StringBuffer theValue = new StringBuffer(theResultNode
101: .getNodeValue());
102: if (theValue.length() == 0) {
103: theNewLocation = new Double(25);
104: } else {
105: if (theValue.indexOf("%") < 0) {
106: try {
107: theNewLocation = new Integer(theValue
108: .toString());
109: } catch (NumberFormatException e) {
110: SwingMLLogger
111: .getInstance()
112: .log(
113: "Syntax Error: Only a numeric theValue can be placed in the LOCATION attribute of the Split Pane ["
114: + theModel.getName()
115: + "] tag.");
116: theNewLocation = new Double(25);
117: }
118: } else {
119: int percentIdx = theValue.indexOf("%");
120:
121: try {
122: theNewLocation = new Double(theValue.replace(
123: percentIdx, percentIdx + "%".length(),
124: "").toString());
125: } catch (NumberFormatException e) {
126: SwingMLLogger
127: .getInstance()
128: .log(
129: "Syntax Error: Only a numeric theValue can be placed in the LOCATION attribute of the Split Pane ["
130: + theModel.getName()
131: + "] tag.");
132: theNewLocation = new Double(25);
133: }
134: }
135: }
136: theModel.setLocation(theNewLocation);
137: }
138: }
139: } // public class JSplitPaneMapper extends MapperUtil implements Mapper
|