| 1 | package event.editor; |
|---|
| 2 | |
|---|
| 3 | import java.awt.event.*; |
|---|
| 4 | import javax.swing.*; |
|---|
| 5 | import java.util.*; |
|---|
| 6 | import javax.swing.event.TableModelEvent; |
|---|
| 7 | import javax.swing.event.TableModelListener; |
|---|
| 8 | import scriptbuilder.structures.events.*; |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * |
|---|
| 12 | * @author nathaniellehrer |
|---|
| 13 | */ |
|---|
| 14 | public class CHPRadioPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel |
|---|
| 15 | { |
|---|
| 16 | |
|---|
| 17 | private ActionListener removeListener; |
|---|
| 18 | private CHPRadioEvent event; |
|---|
| 19 | private JTable dialogTable; |
|---|
| 20 | |
|---|
| 21 | /** |
|---|
| 22 | * Creates new form CHPRadioPanel |
|---|
| 23 | */ |
|---|
| 24 | public CHPRadioPanel() |
|---|
| 25 | { |
|---|
| 26 | initComponents(); |
|---|
| 27 | HashMap<JButton, String> buttonMap = new HashMap<JButton, String>(); |
|---|
| 28 | buttonMap.put(addDispatchButton, "Dispatch"); |
|---|
| 29 | buttonMap.put(addFieldButton, "Field"); |
|---|
| 30 | dialogTable = GenericTable.genericizeTable(jScrollPane1, buttonMap, deleteSelectedButton); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | @Override |
|---|
| 34 | public void getEventObject(I_ScriptEvent sei) |
|---|
| 35 | { |
|---|
| 36 | event = (CHPRadioEvent) sei; |
|---|
| 37 | audioText.setText(event.radioFile); |
|---|
| 38 | |
|---|
| 39 | for (int i = 0; i < event.lines.size(); i++) |
|---|
| 40 | { |
|---|
| 41 | ((MyTableModel) dialogTable.getModel()).addRow(event.roles.get(i), event.lines.get(i)); |
|---|
| 42 | } |
|---|
| 43 | addDispatchButton.addActionListener(new ActionListener() |
|---|
| 44 | { |
|---|
| 45 | |
|---|
| 46 | public void actionPerformed(ActionEvent e) |
|---|
| 47 | { |
|---|
| 48 | int i = event.roles.size(); |
|---|
| 49 | event.roles.add("Dispatch"); |
|---|
| 50 | event.lines.add(""); |
|---|
| 51 | } |
|---|
| 52 | }); |
|---|
| 53 | addFieldButton.addActionListener(new ActionListener() |
|---|
| 54 | { |
|---|
| 55 | |
|---|
| 56 | public void actionPerformed(ActionEvent e) |
|---|
| 57 | { |
|---|
| 58 | int i = event.roles.size(); |
|---|
| 59 | event.roles.add("Field"); |
|---|
| 60 | event.lines.add(""); |
|---|
| 61 | } |
|---|
| 62 | }); |
|---|
| 63 | dialogTable.getModel().addTableModelListener(new TableModelListener() |
|---|
| 64 | { |
|---|
| 65 | |
|---|
| 66 | public void tableChanged(TableModelEvent e) |
|---|
| 67 | { |
|---|
| 68 | if (e.getType() == TableModelEvent.UPDATE) |
|---|
| 69 | { |
|---|
| 70 | event.roles.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 0).toString()); |
|---|
| 71 | event.lines.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString()); |
|---|
| 72 | } |
|---|
| 73 | if (e.getType() == TableModelEvent.DELETE) |
|---|
| 74 | { |
|---|
| 75 | event.roles.remove(e.getLastRow()); |
|---|
| 76 | event.lines.remove(e.getLastRow()); |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | }); |
|---|
| 80 | |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | public void update(Observable o, Object arg) |
|---|
| 84 | { |
|---|
| 85 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | @Override |
|---|
| 89 | public boolean removeAssociatedEvent() |
|---|
| 90 | { |
|---|
| 91 | ((I_ScriptEvent) event).removeThis(); |
|---|
| 92 | event = null; |
|---|
| 93 | return true; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | @Override |
|---|
| 97 | public void uponClose() |
|---|
| 98 | { |
|---|
| 99 | if (event != null) |
|---|
| 100 | { |
|---|
| 101 | event.radioFile = audioText.getText(); |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * This method is called from within the constructor to initialize the form. |
|---|
| 107 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 108 | * regenerated by the Form Editor. |
|---|
| 109 | */ |
|---|
| 110 | @SuppressWarnings("unchecked") |
|---|
| 111 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 112 | private void initComponents() { |
|---|
| 113 | |
|---|
| 114 | jLabel4 = new javax.swing.JLabel(); |
|---|
| 115 | audioText = new javax.swing.JTextField(); |
|---|
| 116 | addDispatchButton = new javax.swing.JButton(); |
|---|
| 117 | deleteSelectedButton = new javax.swing.JButton(); |
|---|
| 118 | jScrollPane1 = new javax.swing.JScrollPane(); |
|---|
| 119 | addFieldButton = new javax.swing.JButton(); |
|---|
| 120 | |
|---|
| 121 | jLabel4.setText("Radio File"); |
|---|
| 122 | |
|---|
| 123 | audioText.setToolTipText("The radio audio file"); |
|---|
| 124 | audioText.setEnabled(false); |
|---|
| 125 | |
|---|
| 126 | addDispatchButton.setText("Add Dispatch"); |
|---|
| 127 | addDispatchButton.setToolTipText("Adds a row for dialog by the dispatch operator in the table"); |
|---|
| 128 | |
|---|
| 129 | deleteSelectedButton.setText("Delete Selected"); |
|---|
| 130 | deleteSelectedButton.setToolTipText("Deletes the selected row from the table"); |
|---|
| 131 | |
|---|
| 132 | addFieldButton.setText("Add Field"); |
|---|
| 133 | addFieldButton.setToolTipText("Adds a row for dialog by the field operator in the table"); |
|---|
| 134 | addFieldButton.addActionListener(new java.awt.event.ActionListener() { |
|---|
| 135 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
|---|
| 136 | addFieldButtonActionPerformed(evt); |
|---|
| 137 | } |
|---|
| 138 | }); |
|---|
| 139 | |
|---|
| 140 | org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
|---|
| 141 | this.setLayout(layout); |
|---|
| 142 | layout.setHorizontalGroup( |
|---|
| 143 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 144 | .add(layout.createSequentialGroup() |
|---|
| 145 | .addContainerGap() |
|---|
| 146 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 147 | .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 730, Short.MAX_VALUE) |
|---|
| 148 | .add(layout.createSequentialGroup() |
|---|
| 149 | .add(addDispatchButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 150 | .add(3, 3, 3) |
|---|
| 151 | .add(addFieldButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 130, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 152 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 153 | .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 154 | .add(0, 331, Short.MAX_VALUE)) |
|---|
| 155 | .add(layout.createSequentialGroup() |
|---|
| 156 | .add(jLabel4) |
|---|
| 157 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 158 | .add(audioText))) |
|---|
| 159 | .addContainerGap()) |
|---|
| 160 | ); |
|---|
| 161 | layout.setVerticalGroup( |
|---|
| 162 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 163 | .add(layout.createSequentialGroup() |
|---|
| 164 | .addContainerGap() |
|---|
| 165 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 166 | .add(audioText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 167 | .add(jLabel4)) |
|---|
| 168 | .add(18, 18, 18) |
|---|
| 169 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 170 | .add(addDispatchButton) |
|---|
| 171 | .add(addFieldButton) |
|---|
| 172 | .add(deleteSelectedButton)) |
|---|
| 173 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 174 | .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 347, Short.MAX_VALUE) |
|---|
| 175 | .addContainerGap()) |
|---|
| 176 | ); |
|---|
| 177 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 178 | |
|---|
| 179 | private void addFieldButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addFieldButtonActionPerformed |
|---|
| 180 | // TODO add your handling code here: |
|---|
| 181 | }//GEN-LAST:event_addFieldButtonActionPerformed |
|---|
| 182 | |
|---|
| 183 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 184 | private javax.swing.JButton addDispatchButton; |
|---|
| 185 | private javax.swing.JButton addFieldButton; |
|---|
| 186 | private javax.swing.JTextField audioText; |
|---|
| 187 | private javax.swing.JButton deleteSelectedButton; |
|---|
| 188 | private javax.swing.JLabel jLabel4; |
|---|
| 189 | private javax.swing.JScrollPane jScrollPane1; |
|---|
| 190 | // End of variables declaration//GEN-END:variables |
|---|
| 191 | |
|---|
| 192 | } |
|---|