package event.editor; import java.awt.event.*; import javax.swing.*; import java.util.*; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import scriptbuilder.structures.events.*; /** * * @author nathaniellehrer */ public class CHPRadioPanel extends javax.swing.JPanel implements ScriptEventEditorPanel { private ActionListener removeListener; private CHPRadioEvent event; private JTable dialogTable; /** * Creates new form CHPRadioPanel */ public CHPRadioPanel() { initComponents(); HashMap buttonMap = new HashMap(); buttonMap.put(addDispatchButton, "Dispatch"); buttonMap.put(addFieldButton, "Field"); dialogTable = GenericTable.genericizeTable(jScrollPane1, buttonMap, deleteSelectedButton); } public void getEventObject(I_ScriptEvent sei) { event = (CHPRadioEvent) sei; audioText.setText(event.radioFile); audioText.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { event.radioFile = audioText.getText(); } } public void keyReleased(KeyEvent e) { } }); for (int i = 0; i < event.lines.size(); i++) { ((MyTableModel) dialogTable.getModel()).addRow(event.roles.get(i), event.lines.get(i)); } addDispatchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int i = event.roles.size(); event.roles.add("Dispatch"); event.lines.add(""); } }); addFieldButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int i = event.roles.size(); event.roles.add("Field"); event.lines.add(""); } }); dialogTable.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.UPDATE) { event.roles.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 0).toString()); event.lines.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString()); } if(e.getType() == TableModelEvent.DELETE) { event.roles.remove(e.getLastRow()); event.lines.remove(e.getLastRow()); } } }); } 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() { jLabel4 = new javax.swing.JLabel(); audioText = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); addDispatchButton = new javax.swing.JButton(); deleteSelectedButton = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); addFieldButton = new javax.swing.JButton(); jLabel4.setText("Radio File"); audioText.setToolTipText("The radio audio file"); jButton2.setText("Browse"); jButton2.setToolTipText("Browse for the radio audio file"); jButton2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { browse(evt); } }); addDispatchButton.setText("Add Dispatch"); addDispatchButton.setToolTipText("Adds a row for dialog by the dispatch operator in the table"); deleteSelectedButton.setText("Delete Selected"); deleteSelectedButton.setToolTipText("Deletes the selected row from the table"); addFieldButton.setText("Add Field"); addFieldButton.setToolTipText("Adds a row for dialog by the field operator in the table"); addFieldButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addFieldButtonActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 730, Short.MAX_VALUE) .add(layout.createSequentialGroup() .add(addDispatchButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(3, 3, 3) .add(addFieldButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)) .add(layout.createSequentialGroup() .add(jLabel4) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(audioText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE) .add(18, 18, 18) .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(audioText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(jLabel4) .add(jButton2)) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(addDispatchButton) .add(addFieldButton) .add(deleteSelectedButton)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE) .addContainerGap()) ); }// //GEN-END:initComponents private void browse(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browse JFileChooser browser = new JFileChooser(); int returnVal = browser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { audioText.setText(browser.getSelectedFile().getPath()); } }//GEN-LAST:event_browse private void addFieldButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFieldButtonActionPerformed // TODO add your handling code here: }//GEN-LAST:event_addFieldButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addDispatchButton; private javax.swing.JButton addFieldButton; private javax.swing.JTextField audioText; private javax.swing.JButton deleteSelectedButton; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }