/**
* @see org.swingml.xml.Mapper#mapModelAttributes(Node, Object, Object)
*/
public void mapModelAttributes(Node aNode, Object aModel, Object aParent) {
GridBagBaseModel theBaseModel = (GridBagBaseModel) aModel;
Node theResultNode = null;
final String PERCENT_SYMBOL = "%";
theResultNode = super.getAttribute(aNode, Constants.NAME);
if (theResultNode != null) {
theBaseModel.setName(theResultNode.getNodeValue());
}
theResultNode = super.getAttribute(aNode, Constants.PADDING);
if (theResultNode != null) {
theBaseModel.setPadding(new Integer(theResultNode.getNodeValue()).intValue());
}
theResultNode = super.getAttribute(aNode, Constants.IPADX);
if (theResultNode != null) {
theBaseModel.setIpadx(new Integer(theResultNode.getNodeValue()).intValue());
}
theResultNode = super.getAttribute(aNode, Constants.IPADY);
if (theResultNode != null) {
theBaseModel.setIpady(new Integer(theResultNode.getNodeValue()).intValue());
}
theResultNode = super.getAttribute(aNode, Constants.FILL);
if (theResultNode != null) {
int theFill = GridBagConstraints.NONE; // (None|Horizontal|Vertical|Both)
String theFillValue = theResultNode.getNodeValue();
if (theFillValue.equalsIgnoreCase(Constants.HORIZONTAL)) {
theFill = GridBagConstraints.HORIZONTAL;
} else if (theFillValue.equalsIgnoreCase(Constants.VERTICAL)) {
theFill = GridBagConstraints.VERTICAL;
} else if (theFillValue.equalsIgnoreCase(Constants.BOTH)) {
theFill = GridBagConstraints.BOTH;
}
theBaseModel.setFill(theFill);
}
theResultNode = super.getAttribute(aNode, Constants.ANCHOR);
if (theResultNode != null) {
int theAnchor = GridBagConstraints.CENTER;
String theAnchorValue = theResultNode.getNodeValue();
if (theAnchorValue.equalsIgnoreCase(Constants.NORTH)) {
theAnchor = GridBagConstraints.NORTH;
} else if (theAnchorValue.equalsIgnoreCase(Constants.SOUTH)) {
theAnchor = GridBagConstraints.SOUTH;
} else if (theAnchorValue.equalsIgnoreCase(Constants.CENTER)) {
theAnchor = GridBagConstraints.CENTER;
} else if (theAnchorValue.equalsIgnoreCase(Constants.EAST)) {
theAnchor = GridBagConstraints.EAST;
} else if (theAnchorValue.equalsIgnoreCase(Constants.WEST)) {
theAnchor = GridBagConstraints.WEST;
} else if (theAnchorValue.equalsIgnoreCase(Constants.NORTHWEST)) {
theAnchor = GridBagConstraints.NORTHWEST;
} else if (theAnchorValue.equalsIgnoreCase(Constants.NORTHEAST)) {
theAnchor = GridBagConstraints.NORTHEAST;
} else if (theAnchorValue.equalsIgnoreCase(Constants.SOUTHWEST)) {
theAnchor = GridBagConstraints.SOUTHWEST;
} else if (theAnchorValue.equalsIgnoreCase(Constants.SOUTHEAST)) {
theAnchor = GridBagConstraints.SOUTHEAST;
}
theBaseModel.setAnchor(theAnchor);
}
theResultNode = super.getAttribute(aNode, Constants.WEIGHTX);
if (theResultNode != null) {
double theWeightx = 0;
StringBuffer theNodeValue = new StringBuffer(theResultNode.getNodeValue());
int thePercentIdx = theNodeValue.indexOf(PERCENT_SYMBOL);
if (theNodeValue.length() == 0 || thePercentIdx < 0) {
theWeightx = 0;
} else {
try {
theWeightx = new Double(theNodeValue.replace(thePercentIdx, thePercentIdx + PERCENT_SYMBOL.length(), "").toString()).doubleValue();
if (theWeightx <= 100 && theWeightx >= 0) {
theWeightx *= 0.01;
} else {
theWeightx = 0;
}
} catch (Exception e) {
SwingMLLogger.getInstance().log("Syntax Error: A non-numeric value was specified for theWeightx");
theWeightx = 0;
}
}
theBaseModel.setWeightx(theWeightx);
}
theResultNode = super.getAttribute(aNode, Constants.WEIGHTY);
if (theResultNode != null) {
double theWeighty = 0;
StringBuffer theNodeValue = new StringBuffer(theResultNode.getNodeValue());
int thePercentIdx = theNodeValue.indexOf(PERCENT_SYMBOL);
if (theNodeValue.length() == 0 || thePercentIdx < 0) {
theWeighty = 0;
} else {
try {
theWeighty = new Double(theNodeValue.replace(thePercentIdx, thePercentIdx + PERCENT_SYMBOL.length(), "").toString()).doubleValue();
if (theWeighty <= 100 && theWeighty >= 0) {
theWeighty *= 0.01;
} else {
theWeighty = 0;
}
} catch (Exception e) {
SwingMLLogger.getInstance().log("Syntax Error: A non-numeric value was specified for weighty");
theWeighty = 0;
}
}
theBaseModel.setWeighty(theWeighty);
}
theResultNode = super.getAttribute(aNode, Constants.GRIDHEIGHT);
if (theResultNode != null) {
int theGridHeight = 0;
try {
theGridHeight = new Integer(theResultNode.getNodeValue()).intValue();
} catch (Exception e) {
SwingMLLogger.getInstance().log("Syntax Error: A non-numeric value was specified for gridheight");
theGridHeight = 0;
} finally {
theBaseModel.setGridHeight(theGridHeight);
}
}
theResultNode = super.getAttribute(aNode, Constants.GRIDWIDTH);
if (theResultNode != null) {
int theGridWidth = 0;
try {
theGridWidth = new Integer(theResultNode.getNodeValue()).intValue();
} catch (Exception e) {
SwingMLLogger.getInstance().log("Syntax Error: A non-numeric value was specified for gridwidth");
theGridWidth = 0;
} finally {
theBaseModel.setGridWidth(theGridWidth);
}
}
}