| 1 | package event.editor; |
|---|
| 2 | |
|---|
| 3 | import java.awt.event.*; |
|---|
| 4 | import java.util.*; |
|---|
| 5 | import javax.swing.JTable; |
|---|
| 6 | import javax.swing.event.TableModelEvent; |
|---|
| 7 | import javax.swing.event.TableModelListener; |
|---|
| 8 | import scriptbuilder.structures.events.CMSEvaluationEvent; |
|---|
| 9 | import scriptbuilder.structures.events.I_ScriptEvent; |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * |
|---|
| 13 | * @author nathaniellehrer |
|---|
| 14 | */ |
|---|
| 15 | public class CMSEvaluationPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel |
|---|
| 16 | { |
|---|
| 17 | |
|---|
| 18 | private HashMap<String, Class> properties; |
|---|
| 19 | private JTable dialogTable; |
|---|
| 20 | private CMSEvaluationEvent event; |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Creates new form CMSEvaluation |
|---|
| 24 | */ |
|---|
| 25 | public CMSEvaluationPanel() |
|---|
| 26 | { |
|---|
| 27 | initComponents(); |
|---|
| 28 | |
|---|
| 29 | dialogTable = GenericTable.genericizeNumberedTable(jScrollPane1, addButton, deleteButton); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | @Override |
|---|
| 33 | public void getEventObject(I_ScriptEvent sei) |
|---|
| 34 | { |
|---|
| 35 | event = (CMSEvaluationEvent) sei; |
|---|
| 36 | txtID.setText(event.cmsID); |
|---|
| 37 | txtID.addKeyListener(new KeyListener() |
|---|
| 38 | { |
|---|
| 39 | |
|---|
| 40 | @Override |
|---|
| 41 | public void keyTyped(KeyEvent e) |
|---|
| 42 | { |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | @Override |
|---|
| 46 | public void keyPressed(KeyEvent e) |
|---|
| 47 | { |
|---|
| 48 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
|---|
| 49 | { |
|---|
| 50 | event.cmsID = txtID.getText(); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | @Override |
|---|
| 55 | public void keyReleased(KeyEvent e) |
|---|
| 56 | { |
|---|
| 57 | } |
|---|
| 58 | }); |
|---|
| 59 | txtLocation.setText(event.location); |
|---|
| 60 | txtLocation.addKeyListener(new KeyListener() |
|---|
| 61 | { |
|---|
| 62 | |
|---|
| 63 | @Override |
|---|
| 64 | public void keyTyped(KeyEvent e) |
|---|
| 65 | { |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | @Override |
|---|
| 69 | public void keyPressed(KeyEvent e) |
|---|
| 70 | { |
|---|
| 71 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
|---|
| 72 | { |
|---|
| 73 | event.location = txtLocation.getText(); |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | @Override |
|---|
| 78 | public void keyReleased(KeyEvent e) |
|---|
| 79 | { |
|---|
| 80 | } |
|---|
| 81 | }); |
|---|
| 82 | txtMessage.setText(""); |
|---|
| 83 | for (int i = 0; i < event.message.size(); i++) |
|---|
| 84 | { |
|---|
| 85 | ((MyTableModel) dialogTable.getModel()).addRow("" + (i + 1), event.message.get(i)); |
|---|
| 86 | } |
|---|
| 87 | for (int i = 0; i < TypeDropdown.getItemCount(); i++) |
|---|
| 88 | { |
|---|
| 89 | if (event.cmsType.equalsIgnoreCase(TypeDropdown.getItemAt(i).toString())) |
|---|
| 90 | { |
|---|
| 91 | TypeDropdown.setSelectedIndex(i); |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | TypeDropdown.addActionListener(new ActionListener() |
|---|
| 95 | { |
|---|
| 96 | |
|---|
| 97 | @Override |
|---|
| 98 | public void actionPerformed(ActionEvent e) |
|---|
| 99 | { |
|---|
| 100 | event.cmsType = TypeDropdown.getSelectedItem().toString(); |
|---|
| 101 | } |
|---|
| 102 | }); |
|---|
| 103 | addButton.addActionListener(new ActionListener() |
|---|
| 104 | { |
|---|
| 105 | |
|---|
| 106 | @Override |
|---|
| 107 | public void actionPerformed(ActionEvent e) |
|---|
| 108 | { |
|---|
| 109 | event.message.add(""); |
|---|
| 110 | } |
|---|
| 111 | }); |
|---|
| 112 | dialogTable.getModel().addTableModelListener(new TableModelListener() |
|---|
| 113 | { |
|---|
| 114 | |
|---|
| 115 | public void tableChanged(TableModelEvent e) |
|---|
| 116 | { |
|---|
| 117 | if (e.getType() == TableModelEvent.UPDATE) |
|---|
| 118 | { |
|---|
| 119 | event.message.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString()); |
|---|
| 120 | } |
|---|
| 121 | if (e.getType() == TableModelEvent.DELETE) |
|---|
| 122 | { |
|---|
| 123 | event.message.remove(e.getLastRow()); |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | }); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | @Override |
|---|
| 130 | public void update(Observable o, Object arg) |
|---|
| 131 | { |
|---|
| 132 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | @Override |
|---|
| 136 | public boolean removeAssociatedEvent() |
|---|
| 137 | { |
|---|
| 138 | event.removeThis(); |
|---|
| 139 | event = null; |
|---|
| 140 | return true; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | /** |
|---|
| 144 | * This method is called from within the constructor to initialize the form. |
|---|
| 145 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 146 | * regenerated by the Form Editor. |
|---|
| 147 | */ |
|---|
| 148 | @SuppressWarnings("unchecked") |
|---|
| 149 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 150 | private void initComponents() |
|---|
| 151 | { |
|---|
| 152 | |
|---|
| 153 | jLabel3 = new javax.swing.JLabel(); |
|---|
| 154 | txtLocation = new javax.swing.JTextField(); |
|---|
| 155 | jLabel2 = new javax.swing.JLabel(); |
|---|
| 156 | TypeDropdown = new javax.swing.JComboBox(); |
|---|
| 157 | txtID = new javax.swing.JFormattedTextField(); |
|---|
| 158 | jLabel1 = new javax.swing.JLabel(); |
|---|
| 159 | deleteButton = new javax.swing.JButton(); |
|---|
| 160 | jScrollPane1 = new javax.swing.JScrollPane(); |
|---|
| 161 | txtMessage = new javax.swing.JTextArea(); |
|---|
| 162 | addButton = new javax.swing.JButton(); |
|---|
| 163 | |
|---|
| 164 | jLabel3.setText("Location"); |
|---|
| 165 | |
|---|
| 166 | txtLocation.setToolTipText("Example: SB 55 @ WARNER AVE"); |
|---|
| 167 | |
|---|
| 168 | jLabel2.setText("Type"); |
|---|
| 169 | |
|---|
| 170 | TypeDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Update", "New", "Remove" })); |
|---|
| 171 | |
|---|
| 172 | txtID.setToolTipText("Example: 72"); |
|---|
| 173 | |
|---|
| 174 | jLabel1.setText("CMS ID"); |
|---|
| 175 | |
|---|
| 176 | deleteButton.setText("Delete Selected Message"); |
|---|
| 177 | deleteButton.setToolTipText("Deletes the selected message from the table"); |
|---|
| 178 | |
|---|
| 179 | jScrollPane1.setHorizontalScrollBar(null); |
|---|
| 180 | |
|---|
| 181 | txtMessage.setColumns(20); |
|---|
| 182 | txtMessage.setRows(5); |
|---|
| 183 | jScrollPane1.setViewportView(txtMessage); |
|---|
| 184 | |
|---|
| 185 | addButton.setText("Add Message"); |
|---|
| 186 | addButton.setToolTipText("Adds a message to the table"); |
|---|
| 187 | |
|---|
| 188 | org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
|---|
| 189 | this.setLayout(layout); |
|---|
| 190 | layout.setHorizontalGroup( |
|---|
| 191 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 192 | .add(layout.createSequentialGroup() |
|---|
| 193 | .addContainerGap() |
|---|
| 194 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 195 | .add(layout.createSequentialGroup() |
|---|
| 196 | .add(6, 6, 6) |
|---|
| 197 | .add(addButton) |
|---|
| 198 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 199 | .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 200 | .add(293, 293, 293)) |
|---|
| 201 | .add(layout.createSequentialGroup() |
|---|
| 202 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 203 | .add(jScrollPane1) |
|---|
| 204 | .add(layout.createSequentialGroup() |
|---|
| 205 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 206 | .add(jLabel1) |
|---|
| 207 | .add(jLabel3) |
|---|
| 208 | .add(jLabel2)) |
|---|
| 209 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 210 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 211 | .add(TypeDropdown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
|---|
| 212 | .add(txtLocation) |
|---|
| 213 | .add(txtID)))) |
|---|
| 214 | .addContainerGap()))) |
|---|
| 215 | ); |
|---|
| 216 | layout.setVerticalGroup( |
|---|
| 217 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 218 | .add(layout.createSequentialGroup() |
|---|
| 219 | .add(52, 52, 52) |
|---|
| 220 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 221 | .add(jLabel1) |
|---|
| 222 | .add(txtID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) |
|---|
| 223 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 224 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 225 | .add(TypeDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 226 | .add(jLabel2)) |
|---|
| 227 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 228 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 229 | .add(jLabel3) |
|---|
| 230 | .add(txtLocation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) |
|---|
| 231 | .add(31, 31, 31) |
|---|
| 232 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 233 | .add(deleteButton) |
|---|
| 234 | .add(addButton)) |
|---|
| 235 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 236 | .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE) |
|---|
| 237 | .addContainerGap()) |
|---|
| 238 | ); |
|---|
| 239 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 243 | private javax.swing.JComboBox TypeDropdown; |
|---|
| 244 | private javax.swing.JButton addButton; |
|---|
| 245 | private javax.swing.JButton deleteButton; |
|---|
| 246 | private javax.swing.JLabel jLabel1; |
|---|
| 247 | private javax.swing.JLabel jLabel2; |
|---|
| 248 | private javax.swing.JLabel jLabel3; |
|---|
| 249 | private javax.swing.JScrollPane jScrollPane1; |
|---|
| 250 | private javax.swing.JFormattedTextField txtID; |
|---|
| 251 | private javax.swing.JTextField txtLocation; |
|---|
| 252 | private javax.swing.JTextArea txtMessage; |
|---|
| 253 | // End of variables declaration//GEN-END:variables |
|---|
| 254 | |
|---|
| 255 | } |
|---|