01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.client.awt.ui;
22:
23: import java.awt.TextComponent;
24: import java.awt.event.FocusEvent;
25: import java.awt.event.FocusListener;
26: import java.util.HashMap;
27: import java.util.Map;
28: import org.onemind.swingweb.client.core.AbstractClient;
29: import org.onemind.swingweb.client.dom.DomNode;
30:
31: public class TextComponentUIHandler extends ComponentUIHandler
32: implements FocusListener {
33:
34: private Map _texts = new HashMap();
35:
36: public TextComponentUIHandler(AbstractClient client) {
37: super (client);
38: }
39:
40: /**
41: * {@inheritDoc}
42: */
43: protected void registerListeners(Object com) {
44: TextComponent txtCom = (TextComponent) com;
45: txtCom.addFocusListener(this );
46: super .registerListeners(com);
47: }
48:
49: public Object updateUI(Object com, DomNode element) {
50: String str = element.getAttribute("text");
51: TextComponent txtCom = (TextComponent) com;
52: txtCom.setText(str);
53: return txtCom;
54: }
55:
56: public void focusGained(FocusEvent e) {
57: TextComponent txtCom = (TextComponent) e.getSource();
58: _texts.put(txtCom, txtCom.getText());
59: }
60:
61: public void focusLost(FocusEvent e) {
62: TextComponent txtCom = (TextComponent) e.getSource();
63: String origText = (String) _texts.get(txtCom);
64: String text = txtCom.getText();
65: if (!origText.equals(text)) {
66: postEvent(txtCom, null, text, false);
67: }
68: }
69: }
|