001: package net.xoetrope.xui.data;
002:
003: import java.awt.Component;
004: import net.xoetrope.xui.XProjectManager;
005: import net.xoetrope.xui.XTextHolder;
006: import net.xoetrope.xml.XmlElement;
007:
008: /**
009: * <p>Bind an XLabel to a data model value/node. The binding allows a model node to
010: * linked to a UI component so that it can be refreshed when new data is written
011: * to the model. For a label component the source and destination area synonymous.
012: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003<br>
013: * License: see license.txt
014: * @version $Revision: 1.21 $
015: */
016: public class XLabelBinding implements XDataBinding {
017: protected XTextHolder comp;
018: protected XModel model;
019: protected String srcPath;
020:
021: /**
022: * Construct a new data binding
023: * @param c the component to be bound
024: * @param dataElement the name of the data in the model
025: */
026: public XLabelBinding(Component c, String dataElement,
027: XModel srcModel) {
028: srcPath = dataElement;
029: model = srcModel;
030: model.setTagName("data");
031: comp = (XTextHolder) c;
032: }
033:
034: /**
035: * Updates the TextComponent with the value obtained from the data model.
036: */
037: public void get() {
038: comp.setText((String) model.get());
039: }
040:
041: /**
042: * Updates the data model with the value retrieved from the TextComponent.
043: */
044: public void set() {
045: model.set(comp.getText());
046: ((Component) comp).repaint();
047: }
048:
049: /**
050: * Gets the component on which this binding operates
051: * @return the bound component
052: */
053: public Component getComponent() {
054: return (Component) comp;
055: }
056:
057: /**
058: * Gets the name of the model node
059: * @return the name
060: */
061: public String getName() {
062: return model.getAttribValueAsString(XBaseModel.ID_ATTRIBUTE);
063: }
064:
065: /**
066: * Get the model component to which this object binds
067: * @return
068: */
069: public String getSourcePath() {
070: return srcPath;
071: }
072:
073: /**
074: * Get the model component to which this object binds
075: * @return
076: */
077: public String getOutputPath() {
078: return srcPath;
079: }
080:
081: /**
082: * Set the model path for the source data
083: */
084: public void setSourcePath(String newPath) {
085: srcPath = newPath;
086: }
087:
088: /**
089: * Set the model path for the output/state data
090: */
091: public void setOutputPath(String newPath) {
092: srcPath = newPath;
093: }
094:
095: /**
096: * Set the source node for data in the model
097: * @param newNode the path of the data in the model
098: */
099: public void setSource(XModel newNode) {
100: model = newNode;
101: }
102:
103: /**
104: * Update the output node used by this adapter. The output node is used to
105: * store selection data and state.
106: * @param newNode the new model for saving the output data
107: */
108: public void setOutput(XModel newNode) {
109: model = newNode;
110: }
111: }
|