1 36 package org.ungoverned.oscar.installer.editor; 37 38 import java.awt.GridBagConstraints ; 39 import java.awt.GridBagLayout ; 40 import java.awt.Insets ; 41 import java.awt.event.FocusEvent ; 42 import java.awt.event.FocusListener ; 43 44 import javax.swing.JPanel ; 45 import javax.swing.JTextField ; 46 47 import org.ungoverned.oscar.installer.Property; 48 import org.ungoverned.oscar.installer.StringProperty; 49 50 public class StringEditor extends JPanel 51 { 52 private StringProperty m_prop = null; 53 private JTextField m_textField = null; 54 55 public StringEditor(StringProperty prop) 56 { 57 m_prop = prop; 58 init(); 59 } 60 61 public Property getProperty() 62 { 63 return m_prop; 64 } 65 66 public void setEnabled(boolean b) 67 { 68 m_textField.setEnabled(b); 69 } 70 71 protected void init() 72 { 73 GridBagLayout grid = new GridBagLayout (); 75 GridBagConstraints gbc = new GridBagConstraints (); 76 gbc.insets = new Insets (0, 2, 0, 2); 77 setLayout(grid); 78 79 gbc.gridx = 0; 81 gbc.gridy = 0; 82 gbc.gridheight = 1; 83 gbc.gridwidth = 2; 84 gbc.anchor = GridBagConstraints.WEST; 85 m_textField = new JTextField (20); 86 m_textField.setText(m_prop.getStringValue()); 87 grid.setConstraints(m_textField, gbc); 88 add(m_textField); 89 90 m_textField.addFocusListener(new FocusListener () { 92 public void focusGained(FocusEvent event) 93 { 94 } 95 public void focusLost(FocusEvent event) 96 { 97 if (!event.isTemporary()) 98 { 99 m_prop.setStringValue(m_textField.getText()); 100 } 101 } 102 }); 103 } 104 } 105 | Popular Tags |