1 /*
2 * (C) 2002 David Carr david@carr.name
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 package net.sourceforge.mflow.config;
20
21 import java.awt.TextField;
22 import java.awt.event.FocusEvent;
23 import java.awt.event.FocusListener;
24 import java.awt.event.KeyEvent;
25 import java.awt.event.KeyListener;
26 import java.beans.PropertyEditor;
27 import java.util.logging.Logger;
28
29 /***
30 * A TextField which sets its value to a PropertyEditor
31 *
32 * @author <a href="mailto:david@carr.name">David Carr</a>
33 * @version $Revision: 1.4 $
34 */
35 class PropertyText extends TextField implements KeyListener, FocusListener {
36 private static final Logger log =
37 Logger.getLogger(PropertyText.class.getName());
38
39 /***
40 * Private storage for the PropertyEditor
41 */
42 private PropertyEditor editor;
43
44 /***
45 * Constructor taking a property editor, set up event listeners
46 *
47 * @param pe the PropertyEditor
48 */
49 PropertyText(PropertyEditor pe) {
50 super(pe.getAsText());
51 this.editor = pe;
52 addKeyListener(this);
53 addFocusListener(this);
54 }
55
56 /***
57 * Repaints the TextField
58 */
59 public void repaint() {
60 setText(this.editor.getAsText());
61 }
62
63 /***
64 * Updates the PropertyEditor
65 */
66 protected void updateEditor() {
67 try {
68 this.editor.setAsText(getText());
69 } catch (IllegalArgumentException ex) {
70 log.throwing(getClass().getName(), "updateEditor", ex);
71 }
72 }
73
74 /***
75 * Not used
76 *
77 * @param e the event
78 */
79 public void focusGained(FocusEvent e) {
80 //Not used
81 }
82
83 /***
84 * Updates the editor when focus is lost
85 *
86 * @param e the event
87 */
88 public void focusLost(FocusEvent e) {
89 updateEditor();
90 }
91
92 /***
93 * Updates the editor if the key was Enter
94 *
95 * @param e the key event
96 */
97 public void keyReleased(KeyEvent e) {
98 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
99 updateEditor();
100 }
101 }
102
103 /***
104 * Not used
105 *
106 * @param e the event
107 */
108 public void keyPressed(KeyEvent e) {
109 //Not used
110 }
111
112 /***
113 * Not used
114 *
115 * @param e the event
116 */
117 public void keyTyped(KeyEvent e) {
118 //Not used
119 }
120 }
This page was automatically generated by Maven