1 package org.apache.ojb.tools.mapping.reversedb2.propertyEditors; 2 3 17 18 27 public class PropertyEditorJTextField extends javax.swing.JTextField 28 implements PropertyEditorComponentInterface, 29 java.beans.PropertyChangeListener , 30 java.awt.event.KeyListener , 31 java.awt.event.FocusListener , 32 java.awt.event.ActionListener 33 34 { 35 private String editorKey; 36 private PropertyEditorTarget aTarget; 37 38 40 public PropertyEditorJTextField() 41 { 42 super(); 43 this.addKeyListener(this); 44 this.addActionListener(this); 45 this.addFocusListener(this); 46 } 47 48 public String getEditorKey() 49 { 50 return editorKey; 51 } 52 53 public void setEditorKey(String newKey) 54 { 55 editorKey = newKey; 56 setEditorTarget(this.aTarget); 57 } 58 59 public void setValue(String key, Object value) 60 { 61 if (editorKey != null && editorKey.equals(key)) 62 { 63 setValue(value); 64 } 65 } 66 67 public void setValue(Object value) 68 { 69 if (value == null) 70 { 71 setText(""); 72 } 73 else 74 { 75 setText(value.toString()); 76 } 77 } 78 79 public void setEditorTarget(PropertyEditorTarget paTarget) 80 { 81 if (aTarget != null) aTarget.removePropertyChangeListener(this); 82 if (paTarget != null) 83 { 84 aTarget = paTarget; 85 aTarget.addPropertyChangeListener(editorKey, this); 86 setValue(aTarget.getAttribute(editorKey)); 87 } 88 89 } 90 91 96 public void propertyChange(java.beans.PropertyChangeEvent evt) 97 { 98 if (evt.getPropertyName().equals(this.editorKey)) 99 { 100 this.setValue(evt.getNewValue()); 101 } 102 } 103 104 public void actionPerformed(java.awt.event.ActionEvent evt) 105 { 106 if (this.aTarget != null) 107 this.aTarget.setAttribute(this.editorKey, getText()); 108 } 109 110 public void focusLost(java.awt.event.FocusEvent evt) 111 { 112 if (this.aTarget != null) 113 this.aTarget.setAttribute(this.editorKey, getText()); 114 } 115 public void keyPressed(java.awt.event.KeyEvent evt) 116 { 117 if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE && aTarget != null) 118 { 119 setValue(aTarget.getAttribute(this.editorKey)); 120 } 121 } 122 123 126 public void focusGained(java.awt.event.FocusEvent e) 127 { 128 } 129 130 135 public void keyReleased(java.awt.event.KeyEvent e) 136 { 137 } 138 139 144 public void keyTyped(java.awt.event.KeyEvent e) 145 { 146 } 147 148 } 149 | Popular Tags |