001: /*
002: * Created on Mar 21, 2005
003: *
004: */
005: package org.swingml.xml.mapper;
006:
007: import java.awt.*;
008:
009: import javax.swing.JFormattedTextField.*;
010:
011: import org.swingml.*;
012: import org.swingml.component.*;
013: import org.swingml.formatter.*;
014: import org.swingml.model.*;
015: import org.swingml.xml.*;
016: import org.w3c.dom.*;
017:
018: /**
019: * @author ybxdde
020: *
021: */
022: public class JFormattedTextFieldMapper extends MapperUtil implements
023: Mapper {
024:
025: public Object getModelToMap(Node aNode, Object aParent,
026: Container aContainer) {
027: JFormattedTextFieldModel theModel = new JFormattedTextFieldModel();
028: SwingMLModel theContainer = (SwingMLModel) aParent;
029: theContainer.addChild(theModel);
030: theModel.setParent(theContainer);
031: return theModel;
032: }
033:
034: public void mapModel(Node aNode, Object aParent,
035: Container aContainer) {
036: JFormattedTextFieldModel theModel = (JFormattedTextFieldModel) getModelToMap(
037: aNode, aParent, aContainer);
038: this .mapModelAttributes(aNode, theModel, aParent);
039: super .iterate(aNode, theModel, aContainer);
040: }
041:
042: public void mapModelAttributes(Node aNode, Object aModel,
043: Object aParent) {
044: JFormattedTextFieldModel theModel = (JFormattedTextFieldModel) aModel;
045: super .mapCommonAttributes(theModel, aNode);
046: Node theResultNode = super .getAttribute(aNode, Constants.COLS);
047: if (theResultNode != null) {
048: theModel.setCols(theResultNode.getNodeValue());
049: }
050: theResultNode = super .getAttribute(aNode, Constants.EDITABLE);
051: if (theResultNode != null) {
052: if (theResultNode.getNodeValue().equalsIgnoreCase(
053: Constants.FALSE)) {
054: theModel.setEditable(false);
055: }
056: }
057: theResultNode = super .getAttribute(aNode, Constants.ENABLED);
058: if (theResultNode != null) {
059: theModel.setEnabled(theResultNode.getNodeValue()
060: .equalsIgnoreCase(Constants.TRUE));
061: }
062:
063: theResultNode = super .getAttribute(aNode, Constants.PATTERN);
064: if (theResultNode != null) {
065: theModel.setPattern(theResultNode.getNodeValue());
066: }
067:
068: theResultNode = super .getAttribute(aNode, Constants.FORMATTER);
069: if (theResultNode != null) {
070: // Get the formatter
071: ISwingMLFormatter formatter = AbstractFormatterComponent
072: .getFormatterByName(theResultNode.getNodeValue());
073:
074: // Does it allow null/empty values?
075: boolean nullable = false;
076: Node nullableNode = super .getAttribute(aNode,
077: Constants.NULLABLE);
078: if (nullableNode != null) {
079: nullable = nullableNode.getNodeValue()
080: .equalsIgnoreCase(Constants.TRUE);
081: }
082: formatter.setNullable(nullable);
083:
084: // Find the pattern to match
085: String nullablePattern = null;
086: Node nullablePatternNode = super .getAttribute(aNode,
087: Constants.NULLABLE_PATTERN);
088: if (nullablePatternNode != null) {
089: nullablePattern = nullablePatternNode.getNodeValue();
090: }
091: formatter.setNullPattern(nullablePattern);
092:
093: // set it on the model
094: theModel.setFormatter((AbstractFormatter) formatter);
095: }
096:
097: theResultNode = super
098: .getAttribute(aNode, Constants.PLACEHOLDER);
099: if (theResultNode != null) {
100: theModel.setPlaceholder(theResultNode.getNodeValue());
101: }
102: theResultNode = super .getAttribute(aNode,
103: Constants.PLACEHOLDCHAR);
104: if (theResultNode != null) {
105: if (theResultNode.getNodeValue().length() == 1) {
106: theModel
107: .setPlaceholdChar((theResultNode.getNodeValue())
108: .charAt(0));
109: }
110: }
111: theResultNode = super .getAttribute(aNode, Constants.OVERWRITE);
112: if (theResultNode != null) {
113: theModel.setOverwrite((new Boolean(theResultNode
114: .getNodeValue())).booleanValue());
115: }
116:
117: theResultNode = getAttribute(aNode, Constants.RETURNBUTTON);
118: if (null != theResultNode) {
119: theModel.setReturnButton(theResultNode.getNodeValue());
120: }
121:
122: theResultNode = getAttribute(aNode, Constants.AUTO_SELECT);
123: if (null != theResultNode) {
124: theModel.setAutoSelect((new Boolean(theResultNode
125: .getNodeValue())).booleanValue());
126: }
127: }
128: }
|