| 1 | package event.editor; |
|---|
| 2 | |
|---|
| 3 | import java.awt.event.*; |
|---|
| 4 | import java.util.Observable; |
|---|
| 5 | import java.util.StringTokenizer; |
|---|
| 6 | import scriptbuilder.structures.events.ScriptEventInterface; |
|---|
| 7 | import scriptbuilder.structures.events.WitnessEvent; |
|---|
| 8 | |
|---|
| 9 | /** |
|---|
| 10 | * |
|---|
| 11 | * @author nathaniellehrer |
|---|
| 12 | */ |
|---|
| 13 | public class WitnessPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel |
|---|
| 14 | { |
|---|
| 15 | |
|---|
| 16 | private ActionListener removeListener; |
|---|
| 17 | private WitnessEvent event; |
|---|
| 18 | |
|---|
| 19 | /** |
|---|
| 20 | * Creates new form WitnessPanel |
|---|
| 21 | */ |
|---|
| 22 | public WitnessPanel() |
|---|
| 23 | { |
|---|
| 24 | initComponents(); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | public void setRemoveListener(ActionListener listener) |
|---|
| 28 | { |
|---|
| 29 | removeListener = listener; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | public void getEventObject(ScriptEventInterface sei) |
|---|
| 34 | { |
|---|
| 35 | event = (WitnessEvent) sei; |
|---|
| 36 | StringTokenizer st = new StringTokenizer(event.witnessName); |
|---|
| 37 | txtFirstName.setText(st.nextToken()); |
|---|
| 38 | txtFirstName.addKeyListener(new KeyListener() |
|---|
| 39 | { |
|---|
| 40 | public void keyTyped(KeyEvent e) |
|---|
| 41 | { |
|---|
| 42 | } |
|---|
| 43 | public void keyPressed(KeyEvent e) |
|---|
| 44 | { |
|---|
| 45 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
|---|
| 46 | { |
|---|
| 47 | event.witnessName = txtFirstName.getText() + " "+txtLastName.getText(); |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | public void keyReleased(KeyEvent e) |
|---|
| 51 | { |
|---|
| 52 | } |
|---|
| 53 | }); |
|---|
| 54 | txtLastName.setText(""); |
|---|
| 55 | while (st.hasMoreTokens()) |
|---|
| 56 | { |
|---|
| 57 | txtLastName.setText(txtLastName.getText() + st.nextToken()); |
|---|
| 58 | } |
|---|
| 59 | txtLastName.addKeyListener(new KeyListener() |
|---|
| 60 | { |
|---|
| 61 | public void keyTyped(KeyEvent e) |
|---|
| 62 | { |
|---|
| 63 | } |
|---|
| 64 | public void keyPressed(KeyEvent e) |
|---|
| 65 | { |
|---|
| 66 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
|---|
| 67 | { |
|---|
| 68 | event.witnessName = txtFirstName.getText() + " "+txtLastName.getText(); |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | public void keyReleased(KeyEvent e) |
|---|
| 72 | { |
|---|
| 73 | } |
|---|
| 74 | }); |
|---|
| 75 | txtPhoneNumber.setText("" + event.witnessNum); |
|---|
| 76 | txtPhoneNumber.addKeyListener(new KeyListener() |
|---|
| 77 | { |
|---|
| 78 | public void keyTyped(KeyEvent e) |
|---|
| 79 | { |
|---|
| 80 | } |
|---|
| 81 | public void keyPressed(KeyEvent e) |
|---|
| 82 | { |
|---|
| 83 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
|---|
| 84 | { |
|---|
| 85 | event.witnessNum = txtPhoneNumber.getText(); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | public void keyReleased(KeyEvent e) |
|---|
| 89 | { |
|---|
| 90 | } |
|---|
| 91 | }); |
|---|
| 92 | txtAddress.setText(event.witnessAddress); |
|---|
| 93 | txtAddress.addKeyListener(new KeyListener() |
|---|
| 94 | { |
|---|
| 95 | public void keyTyped(KeyEvent e) |
|---|
| 96 | { |
|---|
| 97 | } |
|---|
| 98 | public void keyPressed(KeyEvent e) |
|---|
| 99 | { |
|---|
| 100 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
|---|
| 101 | { |
|---|
| 102 | event.witnessAddress = txtAddress.getText(); |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | public void keyReleased(KeyEvent e) |
|---|
| 106 | { |
|---|
| 107 | } |
|---|
| 108 | }); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | public void update(Observable o, Object arg) |
|---|
| 112 | { |
|---|
| 113 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | /** |
|---|
| 117 | * This method is called from within the constructor to initialize the form. |
|---|
| 118 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 119 | * regenerated by the Form Editor. |
|---|
| 120 | */ |
|---|
| 121 | @SuppressWarnings("unchecked") |
|---|
| 122 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 123 | private void initComponents() |
|---|
| 124 | { |
|---|
| 125 | |
|---|
| 126 | removeButton = new javax.swing.JButton(); |
|---|
| 127 | jLabel1 = new javax.swing.JLabel(); |
|---|
| 128 | txtFirstName = new javax.swing.JTextField(); |
|---|
| 129 | jLabel2 = new javax.swing.JLabel(); |
|---|
| 130 | txtLastName = new javax.swing.JTextField(); |
|---|
| 131 | jLabel3 = new javax.swing.JLabel(); |
|---|
| 132 | txtAddress = new javax.swing.JTextField(); |
|---|
| 133 | jLabel4 = new javax.swing.JLabel(); |
|---|
| 134 | txtPhoneNumber = new javax.swing.JFormattedTextField(); |
|---|
| 135 | |
|---|
| 136 | removeButton.setText("Remove"); |
|---|
| 137 | removeButton.addMouseListener(new java.awt.event.MouseAdapter() |
|---|
| 138 | { |
|---|
| 139 | public void mouseClicked(java.awt.event.MouseEvent evt) |
|---|
| 140 | { |
|---|
| 141 | removeThisProperty(evt); |
|---|
| 142 | } |
|---|
| 143 | }); |
|---|
| 144 | |
|---|
| 145 | jLabel1.setText("First Name"); |
|---|
| 146 | |
|---|
| 147 | jLabel2.setText("Last Name"); |
|---|
| 148 | |
|---|
| 149 | jLabel3.setText("Street Address"); |
|---|
| 150 | |
|---|
| 151 | jLabel4.setText("Phone Number"); |
|---|
| 152 | |
|---|
| 153 | txtPhoneNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("(###)###-####")))); |
|---|
| 154 | |
|---|
| 155 | org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
|---|
| 156 | this.setLayout(layout); |
|---|
| 157 | layout.setHorizontalGroup( |
|---|
| 158 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 159 | .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() |
|---|
| 160 | .addContainerGap() |
|---|
| 161 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) |
|---|
| 162 | .add(removeButton) |
|---|
| 163 | .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() |
|---|
| 164 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 165 | .add(jLabel3) |
|---|
| 166 | .add(jLabel1) |
|---|
| 167 | .add(jLabel2)) |
|---|
| 168 | .add(15, 15, 15) |
|---|
| 169 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 170 | .add(org.jdesktop.layout.GroupLayout.TRAILING, txtLastName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE) |
|---|
| 171 | .add(txtAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE) |
|---|
| 172 | .add(org.jdesktop.layout.GroupLayout.TRAILING, txtFirstName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE))) |
|---|
| 173 | .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() |
|---|
| 174 | .add(jLabel4) |
|---|
| 175 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 176 | .add(txtPhoneNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE))) |
|---|
| 177 | .addContainerGap()) |
|---|
| 178 | ); |
|---|
| 179 | layout.setVerticalGroup( |
|---|
| 180 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 181 | .add(layout.createSequentialGroup() |
|---|
| 182 | .addContainerGap() |
|---|
| 183 | .add(removeButton) |
|---|
| 184 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 185 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 186 | .add(txtFirstName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 187 | .add(jLabel1)) |
|---|
| 188 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 189 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 190 | .add(txtLastName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 191 | .add(jLabel2)) |
|---|
| 192 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 193 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 194 | .add(txtAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 195 | .add(jLabel3)) |
|---|
| 196 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 197 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 198 | .add(jLabel4) |
|---|
| 199 | .add(txtPhoneNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) |
|---|
| 200 | .addContainerGap(168, Short.MAX_VALUE)) |
|---|
| 201 | ); |
|---|
| 202 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 203 | |
|---|
| 204 | private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty |
|---|
| 205 | if (removeListener != null) |
|---|
| 206 | { |
|---|
| 207 | removeListener.actionPerformed(new ActionEvent(this, 0, "")); |
|---|
| 208 | } |
|---|
| 209 | }//GEN-LAST:event_removeThisProperty |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 213 | private javax.swing.JLabel jLabel1; |
|---|
| 214 | private javax.swing.JLabel jLabel2; |
|---|
| 215 | private javax.swing.JLabel jLabel3; |
|---|
| 216 | private javax.swing.JLabel jLabel4; |
|---|
| 217 | private javax.swing.JButton removeButton; |
|---|
| 218 | private javax.swing.JTextField txtAddress; |
|---|
| 219 | private javax.swing.JTextField txtFirstName; |
|---|
| 220 | private javax.swing.JTextField txtLastName; |
|---|
| 221 | private javax.swing.JFormattedTextField txtPhoneNumber; |
|---|
| 222 | // End of variables declaration//GEN-END:variables |
|---|
| 223 | |
|---|
| 224 | } |
|---|