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