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.*; 42 43 import javax.swing.*; 44 45 import org.ungoverned.oscar.installer.BooleanProperty; 46 import org.ungoverned.oscar.installer.Property; 47 import org.ungoverned.oscar.installer.StringProperty; 48 49 public class BooleanStringEditor extends JPanel 50 { 51 private Property m_prop = null; 52 private JCheckBox m_includeButton = null; 53 private JTextField m_textField = null; 54 55 public BooleanStringEditor(Property prop) 56 { 57 if ((prop instanceof BooleanProperty) && (prop instanceof StringProperty)) 58 { 59 m_prop = prop; 60 } 61 else 62 { 63 throw new IllegalArgumentException ( 64 "Property must implement both boolean and string property interfaces."); 65 } 66 init(); 67 } 68 69 public Property getProperty() 70 { 71 return m_prop; 72 } 73 74 public void setEnabled(boolean b) 75 { 76 m_includeButton.setEnabled(b); 77 m_textField.setEnabled(b && m_includeButton.isSelected()); 78 } 79 80 protected void init() 81 { 82 GridBagLayout grid = new GridBagLayout (); 84 GridBagConstraints gbc = new GridBagConstraints (); 85 gbc.insets = new Insets (0, 2, 0, 2); 86 setLayout(grid); 87 88 gbc.gridx = 0; 90 gbc.gridy = 0; 91 gbc.gridheight = 1; 92 gbc.gridwidth = 1; 93 gbc.anchor = GridBagConstraints.WEST; 94 m_includeButton = new JCheckBox(""); 95 grid.setConstraints(m_includeButton, gbc); 96 add(m_includeButton); 97 98 gbc.gridx = 1; 100 gbc.gridy = 0; 101 gbc.gridheight = 1; 102 gbc.gridwidth = 3; 103 gbc.anchor = GridBagConstraints.WEST; 104 m_textField = new JTextField(30); 105 m_textField.setText(((StringProperty) m_prop).getStringValue()); 106 grid.setConstraints(m_textField, gbc); 107 add(m_textField); 108 m_textField.setEnabled(false); 109 110 m_includeButton.addActionListener(new ActionListener() { 112 public void actionPerformed(ActionEvent event) 113 { 114 if (m_includeButton.isSelected()) 115 { 116 ((BooleanProperty) m_prop).setBooleanValue(true); 117 m_textField.setEnabled(true); 118 } 119 else 120 { 121 ((BooleanProperty) m_prop).setBooleanValue(false); 122 m_textField.setEnabled(false); 123 } 124 } 125 }); 126 127 m_textField.addFocusListener(new FocusListener() { 129 public void focusGained(FocusEvent event) 130 { 131 } 132 public void focusLost(FocusEvent event) 133 { 134 if (!event.isTemporary()) 135 { 136 ((StringProperty) m_prop).setStringValue(m_textField.getText()); 137 } 138 } 139 }); 140 141 if (((BooleanProperty) m_prop).getBooleanValue()) 144 { 145 m_includeButton.doClick(); 146 } 147 } 148 } | Popular Tags |