source: tmcsimulator-scriptbuilder/trunk/src/event/editor/GenericEvaluationPanel.java @ 89

Revision 89, 6.4 KB checked in by bmcguffin, 9 years ago (diff)

Added dropdown menu item to ScriptBuilderFrame?: "Delete Incident". When clicked, user may select an existing incident to delete. Program will prompt user to confirm the deletion, then remove the incident from the script and refresh the display.

Added button to individual event editor window: "Remove this event". When clicked, the currently displayed event will be removed from the timeslice it is in. The display will be refreshed accordingly. NOTE: This still has some bugs, namely that the last remaining event in a timeslice fails to be deleted.

Restructured Interface ScriptEventEditorPanel? to include a removeAssociatedEvent method, which calls a new method in I_ScriptEvent called removeThis, which causes the event to be removed from its timeslice.

Editor.Java previously contained several classes and enums, none of which were set to private scope. Moved these extra classes to their own files to decrease clutter in Editor.java and increase readability of all files.

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