| 1 | package event.editor; |
|---|
| 2 | |
|---|
| 3 | import java.awt.event.*; |
|---|
| 4 | import java.util.ArrayList; |
|---|
| 5 | import java.util.Observable; |
|---|
| 6 | import javax.swing.JTable; |
|---|
| 7 | import javax.swing.event.TableModelEvent; |
|---|
| 8 | import javax.swing.event.TableModelListener; |
|---|
| 9 | import scriptbuilder.structures.events.I_EvaluationEvent; |
|---|
| 10 | import scriptbuilder.structures.events.I_ScriptEvent; |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * |
|---|
| 14 | * @author nathaniellehrer |
|---|
| 15 | */ |
|---|
| 16 | public class GenericEvaluationPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel |
|---|
| 17 | { |
|---|
| 18 | |
|---|
| 19 | private I_EvaluationEvent event; |
|---|
| 20 | private JTable dialogTable; |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Creates new form GenericEvaluation |
|---|
| 24 | */ |
|---|
| 25 | public GenericEvaluationPanel() |
|---|
| 26 | { |
|---|
| 27 | initComponents(); |
|---|
| 28 | |
|---|
| 29 | dialogTable = GenericTable.genericizeTable( |
|---|
| 30 | scrollPane, CriteriaDropdown, addButton, deleteButton, "Scale", "Criteria"); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | @Override |
|---|
| 34 | public void getEventObject(I_ScriptEvent sei) |
|---|
| 35 | { |
|---|
| 36 | if (sei instanceof I_EvaluationEvent) |
|---|
| 37 | { |
|---|
| 38 | event = (I_EvaluationEvent) sei; |
|---|
| 39 | ArrayList<String> strs = event.getExpectedActions(); |
|---|
| 40 | for (String s : strs) |
|---|
| 41 | { |
|---|
| 42 | ((MyTableModel) dialogTable.getModel()).addRow( |
|---|
| 43 | CriteriaDropdown.getItemAt(0).toString(), s); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | } |
|---|
| 47 | addButton.addActionListener(new ActionListener() |
|---|
| 48 | { |
|---|
| 49 | |
|---|
| 50 | public void actionPerformed(ActionEvent e) |
|---|
| 51 | { |
|---|
| 52 | event.addAction(""); |
|---|
| 53 | } |
|---|
| 54 | }); |
|---|
| 55 | dialogTable.getModel().addTableModelListener(new TableModelListener() |
|---|
| 56 | { |
|---|
| 57 | |
|---|
| 58 | public void tableChanged(TableModelEvent e) |
|---|
| 59 | { |
|---|
| 60 | if (e.getType() == TableModelEvent.UPDATE) |
|---|
| 61 | { |
|---|
| 62 | event.updateAction(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString()); |
|---|
| 63 | } |
|---|
| 64 | if (e.getType() == TableModelEvent.DELETE) |
|---|
| 65 | { |
|---|
| 66 | event.removeAction(e.getLastRow()); |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | }); |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | @Override |
|---|
| 73 | public void update(Observable o, Object arg) |
|---|
| 74 | { |
|---|
| 75 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | @Override |
|---|
| 79 | public boolean removeAssociatedEvent() |
|---|
| 80 | { |
|---|
| 81 | ((I_ScriptEvent)event).removeThis(); |
|---|
| 82 | event = null; |
|---|
| 83 | return true; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * This method is called from within the constructor to initialize the form. |
|---|
| 88 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 89 | * regenerated by the Form Editor. |
|---|
| 90 | */ |
|---|
| 91 | @SuppressWarnings("unchecked") |
|---|
| 92 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 93 | private void initComponents() |
|---|
| 94 | { |
|---|
| 95 | |
|---|
| 96 | addButton = new javax.swing.JButton(); |
|---|
| 97 | deleteButton = new javax.swing.JButton(); |
|---|
| 98 | scrollPane = new javax.swing.JScrollPane(); |
|---|
| 99 | txtNotes = new javax.swing.JTextArea(); |
|---|
| 100 | CriteriaDropdown = new javax.swing.JComboBox(); |
|---|
| 101 | jLabel1 = new javax.swing.JLabel(); |
|---|
| 102 | |
|---|
| 103 | addButton.setText("Add Criteria"); |
|---|
| 104 | addButton.setToolTipText("Adds a new row in the table below"); |
|---|
| 105 | |
|---|
| 106 | deleteButton.setText("Delete Selected Criteria"); |
|---|
| 107 | deleteButton.setToolTipText("Deletes the selected row in the table below"); |
|---|
| 108 | |
|---|
| 109 | scrollPane.setToolTipText(""); |
|---|
| 110 | |
|---|
| 111 | txtNotes.setColumns(20); |
|---|
| 112 | txtNotes.setRows(5); |
|---|
| 113 | scrollPane.setViewportView(txtNotes); |
|---|
| 114 | |
|---|
| 115 | CriteriaDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Yes/No", "1-5", "1-10", "Written" })); |
|---|
| 116 | CriteriaDropdown.setToolTipText("The type of criteria evaluation scale to be used"); |
|---|
| 117 | |
|---|
| 118 | jLabel1.setText("Criteria Evaluation Scale:"); |
|---|
| 119 | |
|---|
| 120 | org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
|---|
| 121 | this.setLayout(layout); |
|---|
| 122 | layout.setHorizontalGroup( |
|---|
| 123 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 124 | .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() |
|---|
| 125 | .addContainerGap() |
|---|
| 126 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) |
|---|
| 127 | .add(org.jdesktop.layout.GroupLayout.LEADING, scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 598, Short.MAX_VALUE) |
|---|
| 128 | .add(layout.createSequentialGroup() |
|---|
| 129 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 130 | .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 131 | .add(CriteriaDropdown, 0, 293, Short.MAX_VALUE)) |
|---|
| 132 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 133 | .add(addButton) |
|---|
| 134 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
|---|
| 135 | .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) |
|---|
| 136 | .add(23, 23, 23)) |
|---|
| 137 | ); |
|---|
| 138 | layout.setVerticalGroup( |
|---|
| 139 | layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
|---|
| 140 | .add(layout.createSequentialGroup() |
|---|
| 141 | .addContainerGap() |
|---|
| 142 | .add(jLabel1) |
|---|
| 143 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 144 | .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|---|
| 145 | .add(CriteriaDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
|---|
| 146 | .add(deleteButton) |
|---|
| 147 | .add(addButton)) |
|---|
| 148 | .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|---|
| 149 | .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE) |
|---|
| 150 | .addContainerGap()) |
|---|
| 151 | ); |
|---|
| 152 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 156 | private javax.swing.JComboBox CriteriaDropdown; |
|---|
| 157 | private javax.swing.JButton addButton; |
|---|
| 158 | private javax.swing.JButton deleteButton; |
|---|
| 159 | private javax.swing.JLabel jLabel1; |
|---|
| 160 | private javax.swing.JScrollPane scrollPane; |
|---|
| 161 | private javax.swing.JTextArea txtNotes; |
|---|
| 162 | // End of variables declaration//GEN-END:variables |
|---|
| 163 | |
|---|
| 164 | } |
|---|