use of org.concord.energy3d.agents.QuestionnaireModel in project energy3d by concord-consortium.
the class MyEditorPane method setText.
public void setText(final String text) {
editorPane.setText(text);
if (editorPane.getDocument() instanceof HTMLDocument) {
final HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
final ElementIterator it = new ElementIterator(doc);
Element element;
while ((element = it.next()) != null) {
final AttributeSet as = element.getAttributes();
final Enumeration<?> en = as.getAttributeNames();
DefaultButtonModel buttonModel = null;
PlainDocument document = null;
String action = null;
String question = null;
String choice = null;
String key = null;
String dataName = null;
while (en.hasMoreElements()) {
final Object n = en.nextElement();
final Object v = as.getAttribute(n);
if (v instanceof DefaultButtonModel) {
buttonModel = (DefaultButtonModel) v;
} else if (v instanceof PlainDocument) {
document = (PlainDocument) v;
} else if (n.toString().equals("action")) {
action = v.toString();
} else if (n.toString().equals("question")) {
question = v.toString();
} else if (n.toString().equals("choice")) {
choice = v.toString();
} else if (n.toString().equals("key")) {
key = v.toString();
} else if (n.toString().equals("data")) {
dataName = v.toString();
}
}
if (action != null) {
final String a = action;
if (document != null) {
final String n = dataName;
final PlainDocument d = document;
document.addDocumentListener(new DocumentListener() {
@Override
public void removeUpdate(final DocumentEvent e) {
textFieldUpdated(a, n, d);
}
@Override
public void insertUpdate(final DocumentEvent e) {
textFieldUpdated(a, n, d);
}
@Override
public void changedUpdate(final DocumentEvent e) {
textFieldUpdated(a, n, d);
}
});
}
if (buttonModel != null) {
final QuestionnaireModel qm;
if (question != null && choice != null) {
boolean isKey = false;
if ("yes".equalsIgnoreCase(key) || "true".equalsIgnoreCase(key)) {
isKey = true;
}
qm = new QuestionnaireModel(question, choice, isKey);
} else {
qm = null;
}
final DefaultButtonModel bm = buttonModel;
if (buttonModel instanceof JToggleButton.ToggleButtonModel) {
buttonModel.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (qm != null) {
// fire only one for questionnaires
if (e.getStateChange() == ItemEvent.SELECTED) {
buttonActionPerformed(a, qm, bm);
}
} else {
buttonActionPerformed(a, qm, bm);
}
}
});
} else {
buttonModel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
buttonActionPerformed(a, qm, bm);
}
});
}
}
}
}
}
}
Aggregations