source: tmcsimulator-scriptbuilder/trunk/src/event/editor/TelephonePanel.java @ 187

Revision 187, 9.1 KB checked in by jdalbey, 6 years ago (diff)

TelephonePanel?.java deleted "Remove" button as it's function is not performed by the "Remove this event" button.

Line 
1package event.editor;
2
3import java.awt.event.*;
4import javax.swing.*;
5import java.util.*;
6import javax.swing.event.TableModelEvent;
7import javax.swing.event.TableModelListener;
8import javax.swing.table.*;
9import scriptbuilder.structures.events.*;
10
11/**
12 *
13 * @author nathaniellehrer
14 */
15public class TelephonePanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel
16{
17
18    private ActionListener removeListener;
19    private JTable dialogTable;
20    private TelephoneEvent event;
21    HashMap<JButton, String> buttonMap;
22
23    /**
24     * Creates new form TelephonePanel
25     */
26    public TelephonePanel()
27    {
28        initComponents();
29        buttonMap = new HashMap<JButton, String>();
30        buttonMap.put(addInstructorButton, "Instructor");
31        buttonMap.put(addStudentButton, "Student");
32        dialogTable = GenericTable.genericizeTable(jScrollPane1, buttonMap, deleteSelectedButton);
33    }
34
35    public void getEventObject(I_ScriptEvent sei)
36    {
37        event = (TelephoneEvent) sei;
38
39        for (int i = 0; i < event.roles.size(); i++)
40        {
41            ((MyTableModel) dialogTable.getModel()).addRow(event.roles.get(i), event.lines.get(i));
42            if (!event.roles.get(i).equals("Student"))
43            {
44                txtInstructorRole.setText(event.roles.get(i));
45            }
46        }
47        txtInstructorRole.addKeyListener(new KeyListener()
48        {
49            public void keyTyped(KeyEvent e)
50            {
51            }
52
53            public void keyPressed(KeyEvent e)
54            {
55                //this needs to be changed to add the instructor role when a new line is created
56                if (e.getKeyCode() == KeyEvent.VK_ENTER)
57                {
58                    buttonMap.put(addInstructorButton, txtInstructorRole.getText());
59                }
60            }
61
62            public void keyReleased(KeyEvent e)
63            {
64            }
65        });
66        buttonMap.put(addInstructorButton, txtInstructorRole.getText());
67        addInstructorButton.addActionListener(new ActionListener()
68        {
69
70            public void actionPerformed(ActionEvent e)
71            {
72                //this listener was not working as exprected, replaced with netbeans auto generated
73//                int i = event.roles.size();
74//                event.roles.add(txtInstructorRole.getText());
75//                event.lines.add("");
76            }
77        });
78        addStudentButton.addActionListener(new ActionListener()
79        {
80            public void actionPerformed(ActionEvent e)
81            {
82                int i = event.roles.size();
83                event.roles.add("Student");
84                event.lines.add("");
85            }
86        });
87        dialogTable.getModel().addTableModelListener(new TableModelListener()
88        {
89
90            public void tableChanged(TableModelEvent e)
91            {
92                if (e.getType() == TableModelEvent.UPDATE)
93                {
94                    event.roles.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 0).toString());
95                    event.lines.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString());
96                }
97                if(e.getType() == TableModelEvent.DELETE)
98                {
99                    event.roles.remove(e.getLastRow());
100                    event.lines.remove(e.getLastRow());
101                    System.out.println("deleted table row");
102                }
103            }
104        });
105
106    }
107
108    public void update(Observable o, Object arg)
109    {
110        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
111    }
112   
113    /** Implementation of remove this event action */
114    @Override
115    public boolean removeAssociatedEvent()
116    {
117        ((I_ScriptEvent)event).removeThis();
118        event = null;
119        return true;
120    }
121
122    @Override
123    public void uponClose()
124    {
125        //No change is necessary here; this panel saves its state continually
126    }
127
128    /**
129     * This method is called from within the constructor to initialize the form.
130     * WARNING: Do NOT modify this code. The content of this method is always
131     * regenerated by the Form Editor.
132     */
133    @SuppressWarnings("unchecked")
134    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
135    private void initComponents() {
136
137        addStudentButton = new javax.swing.JButton();
138        jScrollPane1 = new javax.swing.JScrollPane();
139        deleteSelectedButton = new javax.swing.JButton();
140        addInstructorButton = new javax.swing.JButton();
141        txtInstructorRole = new javax.swing.JTextField();
142        jLabel1 = new javax.swing.JLabel();
143
144        addStudentButton.setText("Add Student Line");
145        addStudentButton.setToolTipText("Adds a row for student dialog in the table");
146
147        jScrollPane1.setHorizontalScrollBar(null);
148
149        deleteSelectedButton.setText("Delete Selected Line");
150        deleteSelectedButton.setToolTipText("Deletes the selected row in the table");
151
152        addInstructorButton.setText("Add Instructor Line");
153        addInstructorButton.setToolTipText("Adds a row for instructor dialog in the table");
154        addInstructorButton.addActionListener(new java.awt.event.ActionListener() {
155            public void actionPerformed(java.awt.event.ActionEvent evt) {
156                addInstructorButtonActionPerformed(evt);
157            }
158        });
159
160        txtInstructorRole.setToolTipText("Specifies the role the instructor plays");
161
162        jLabel1.setText("Role of instructor:");
163
164        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
165        this.setLayout(layout);
166        layout.setHorizontalGroup(
167            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
168            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
169                .addContainerGap()
170                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
171                    .add(layout.createSequentialGroup()
172                        .add(addInstructorButton)
173                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
174                        .add(addStudentButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
175                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
176                        .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
177                        .addContainerGap(133, Short.MAX_VALUE))
178                    .add(layout.createSequentialGroup()
179                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
180                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
181                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
182                                .add(jLabel1)
183                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
184                                .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)))
185                        .add(26, 26, 26))))
186        );
187        layout.setVerticalGroup(
188            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
189            .add(layout.createSequentialGroup()
190                .add(49, 49, 49)
191                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
192                    .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
193                    .add(jLabel1))
194                .add(18, 18, 18)
195                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
196                    .add(addInstructorButton)
197                    .add(addStudentButton)
198                    .add(deleteSelectedButton))
199                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
200                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
201                .addContainerGap())
202        );
203    }// </editor-fold>//GEN-END:initComponents
204
205    private void addInstructorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addInstructorButtonActionPerformed
206        // TODO add your handling code here:
207        buttonMap.put(addInstructorButton, txtInstructorRole.getText());
208        int i = event.roles.size();
209        event.roles.add(txtInstructorRole.getText());
210        event.lines.add("");
211    }//GEN-LAST:event_addInstructorButtonActionPerformed
212
213
214    // Variables declaration - do not modify//GEN-BEGIN:variables
215    private javax.swing.JButton addInstructorButton;
216    private javax.swing.JButton addStudentButton;
217    private javax.swing.JButton deleteSelectedButton;
218    private javax.swing.JLabel jLabel1;
219    private javax.swing.JScrollPane jScrollPane1;
220    private javax.swing.JTextField txtInstructorRole;
221    // End of variables declaration//GEN-END:variables
222
223}
Note: See TracBrowser for help on using the repository browser.