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

Revision 1, 6.3 KB checked in by bmcguffin, 9 years ago (diff)

2017/07/18: Uploaded entire prototype to SVN repo.

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.EvaluationEventInterface;
10import scriptbuilder.structures.events.ScriptEventInterface;
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 EvaluationEventInterface 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(ScriptEventInterface sei)
40    {
41        if (sei instanceof EvaluationEventInterface)
42        {
43            event = (EvaluationEventInterface) 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    /**
83     * This method is called from within the constructor to initialize the form.
84     * WARNING: Do NOT modify this code. The content of this method is always
85     * regenerated by the Form Editor.
86     */
87    @SuppressWarnings("unchecked")
88    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
89    private void initComponents()
90    {
91
92        addButton = new javax.swing.JButton();
93        deleteButton = new javax.swing.JButton();
94        scrollPane = new javax.swing.JScrollPane();
95        txtNotes = new javax.swing.JTextArea();
96        CriteriaDropdown = new javax.swing.JComboBox();
97        jLabel1 = new javax.swing.JLabel();
98
99        addButton.setText("Add Criteria");
100        addButton.setToolTipText("Adds a new row in the table below");
101
102        deleteButton.setText("Delete Selected Criteria");
103        deleteButton.setToolTipText("Deletes the selected row in the table below");
104
105        scrollPane.setToolTipText("");
106
107        txtNotes.setColumns(20);
108        txtNotes.setRows(5);
109        scrollPane.setViewportView(txtNotes);
110
111        CriteriaDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Yes/No", "1-5", "1-10", "Written" }));
112        CriteriaDropdown.setToolTipText("The type of criteria evaluation scale to be used");
113
114        jLabel1.setText("Criteria Evaluation Scale:");
115
116        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
117        this.setLayout(layout);
118        layout.setHorizontalGroup(
119            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
120            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
121                .addContainerGap()
122                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
123                    .add(org.jdesktop.layout.GroupLayout.LEADING, scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 598, Short.MAX_VALUE)
124                    .add(layout.createSequentialGroup()
125                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
126                            .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
127                            .add(CriteriaDropdown, 0, 293, Short.MAX_VALUE))
128                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
129                        .add(addButton)
130                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
131                        .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
132                .add(23, 23, 23))
133        );
134        layout.setVerticalGroup(
135            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
136            .add(layout.createSequentialGroup()
137                .addContainerGap()
138                .add(jLabel1)
139                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
140                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
141                    .add(CriteriaDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
142                    .add(deleteButton)
143                    .add(addButton))
144                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
145                .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
146                .addContainerGap())
147        );
148    }// </editor-fold>//GEN-END:initComponents
149
150
151    // Variables declaration - do not modify//GEN-BEGIN:variables
152    private javax.swing.JComboBox CriteriaDropdown;
153    private javax.swing.JButton addButton;
154    private javax.swing.JButton deleteButton;
155    private javax.swing.JLabel jLabel1;
156    private javax.swing.JScrollPane scrollPane;
157    private javax.swing.JTextArea txtNotes;
158    // End of variables declaration//GEN-END:variables
159
160}
Note: See TracBrowser for help on using the repository browser.