package event.editor; import java.awt.event.*; import java.util.Observable; import java.util.StringTokenizer; import scriptbuilder.structures.events.ScriptEventInterface; import scriptbuilder.structures.events.WitnessEvent; /** * * @author nathaniellehrer */ public class WitnessPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel { private ActionListener removeListener; private WitnessEvent event; /** * Creates new form WitnessPanel */ public WitnessPanel() { initComponents(); } public void setRemoveListener(ActionListener listener) { removeListener = listener; } public void getEventObject(ScriptEventInterface sei) { event = (WitnessEvent) sei; StringTokenizer st = new StringTokenizer(event.witnessName); txtFirstName.setText(st.nextToken()); txtFirstName.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { event.witnessName = txtFirstName.getText() + " "+txtLastName.getText(); } } public void keyReleased(KeyEvent e) { } }); txtLastName.setText(""); while (st.hasMoreTokens()) { txtLastName.setText(txtLastName.getText() + st.nextToken()); } txtLastName.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { event.witnessName = txtFirstName.getText() + " "+txtLastName.getText(); } } public void keyReleased(KeyEvent e) { } }); txtPhoneNumber.setText("" + event.witnessNum); txtPhoneNumber.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { event.witnessNum = txtPhoneNumber.getText(); } } public void keyReleased(KeyEvent e) { } }); txtAddress.setText(event.witnessAddress); txtAddress.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { event.witnessAddress = txtAddress.getText(); } } public void keyReleased(KeyEvent e) { } }); } public void update(Observable o, Object arg) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { removeButton = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); txtFirstName = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); txtLastName = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txtAddress = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); txtPhoneNumber = new javax.swing.JFormattedTextField(); removeButton.setText("Remove"); removeButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { removeThisProperty(evt); } }); jLabel1.setText("First Name"); jLabel2.setText("Last Name"); jLabel3.setText("Street Address"); jLabel4.setText("Phone Number"); txtPhoneNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("(###)###-####")))); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(removeButton) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel3) .add(jLabel1) .add(jLabel2)) .add(15, 15, 15) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtLastName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE) .add(txtAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtFirstName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE))) .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup() .add(jLabel4) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(txtPhoneNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(removeButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(txtFirstName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel1)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(txtLastName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel2)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(txtAddress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel3)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel4) .add(txtPhoneNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addContainerGap(168, Short.MAX_VALUE)) ); }// //GEN-END:initComponents private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty if (removeListener != null) { removeListener.actionPerformed(new ActionEvent(this, 0, "")); } }//GEN-LAST:event_removeThisProperty // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JButton removeButton; private javax.swing.JTextField txtAddress; private javax.swing.JTextField txtFirstName; private javax.swing.JTextField txtLastName; private javax.swing.JFormattedTextField txtPhoneNumber; // End of variables declaration//GEN-END:variables }