01: /* SwingML
02: * Copyright (C) 2002 Hamdi Mohs Yusof.
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 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
16: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17: * Boston, MA 02111-1307, USA.
18: *
19: * Authors:
20: * Hamdi Mohs Yusof <hamdi@medical-online.net>
21: *
22: */
23:
24: package org.swingml.component;
25:
26: import java.awt.event.FocusEvent;
27: import java.awt.event.FocusListener;
28:
29: import javax.swing.JPasswordField;
30: import javax.swing.event.DocumentEvent;
31: import javax.swing.event.DocumentListener;
32:
33: import org.swingml.Constants;
34: import org.swingml.XMLTranslatable;
35: import org.swingml.event.EventHandler;
36: import org.swingml.model.JPasswordModel;
37:
38: public class JPasswordComponent extends JPasswordField implements
39: XMLTranslatable, DocumentListener, FocusListener {
40: private JPasswordModel model = null;
41: private EventHandler eventHandler = EventHandler.getInstance();
42:
43: public JPasswordComponent(JPasswordModel aModel) {
44: this .model = aModel;
45: super .setName(aModel.getName());
46: super .setText(aModel.getText());
47: super .setColumns(Integer.parseInt(aModel.getCols()));
48: super .getDocument().addDocumentListener(this );
49: super .addFocusListener(this );
50: super .setToolTipText(aModel.getTooltip());
51: }
52:
53: public JPasswordModel getModel() {
54: return this .model;
55: }
56:
57: public void removeUpdate(DocumentEvent aEvt) {
58: this .eventHandler.handleEvent(this .getModel(),
59: Constants.REMOVE_UPDATE, this );
60: }
61:
62: public void insertUpdate(DocumentEvent aEvt) {
63: this .eventHandler.handleEvent(this .getModel(),
64: Constants.INSERT_UPDATE, this );
65: }
66:
67: public void changedUpdate(DocumentEvent aEvt) {
68: this .eventHandler.handleEvent(this .getModel(),
69: Constants.CHANGED_UPDATE, this );
70: }
71:
72: public void focusGained(FocusEvent aEvt) {
73: this .eventHandler.handleEvent(this .getModel(),
74: Constants.FOCUS_GAINED, this );
75: }
76:
77: public void focusLost(FocusEvent aEvt) {
78: this .eventHandler.handleEvent(this .getModel(),
79: Constants.FOCUS_LOST, this );
80: }
81:
82: public String getXMLValue() {
83: String theValue = new String(super.getPassword());
84: return theValue;
85: }
86: }
|