Warning: Can't use blame annotator:
svn blame failed on trunk/src/event/editor/TelephonePanel.java: ("Can't find a temporary directory: Internal error", 20014)

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

Revision 145, 10.7 KB checked in by sdanthin, 6 years ago (diff)

Move from Git to Svn (LARGE COMMIT)

RevLine 
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                }
102            }
103        });
104
105    }
106
107    public void update(Observable o, Object arg)
108    {
109        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
110    }
111   
112    @Override
113    public boolean removeAssociatedEvent()
114    {
115        ((I_ScriptEvent)event).removeThis();
116        event = null;
117        return true;
118    }
119
120    @Override
121    public void uponClose()
122    {
123        //No change is necessary here; this panel saves its state continually
124    }
125
126    /**
127     * This method is called from within the constructor to initialize the form.
128     * WARNING: Do NOT modify this code. The content of this method is always
129     * regenerated by the Form Editor.
130     */
131    @SuppressWarnings("unchecked")
132    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
133    private void initComponents() {
134
135        addStudentButton = new javax.swing.JButton();
136        jScrollPane1 = new javax.swing.JScrollPane();
137        deleteSelectedButton = new javax.swing.JButton();
138        addInstructorButton = new javax.swing.JButton();
139        txtInstructorRole = new javax.swing.JTextField();
140        jLabel1 = new javax.swing.JLabel();
141        removeButton = new javax.swing.JButton();
142
143        addStudentButton.setText("Add Student Line");
144        addStudentButton.setToolTipText("Adds a row for student dialog in the table");
145
146        jScrollPane1.setHorizontalScrollBar(null);
147
148        deleteSelectedButton.setText("Delete Selected Line");
149        deleteSelectedButton.setToolTipText("Deletes the selected row in the table");
150        deleteSelectedButton.addActionListener(new java.awt.event.ActionListener() {
151            public void actionPerformed(java.awt.event.ActionEvent evt) {
152                deleteSelectedButtonActionPerformed(evt);
153            }
154        });
155
156        addInstructorButton.setText("Add Instructor Line");
157        addInstructorButton.setToolTipText("Adds a row for instructor dialog in the table");
158        addInstructorButton.addActionListener(new java.awt.event.ActionListener() {
159            public void actionPerformed(java.awt.event.ActionEvent evt) {
160                addInstructorButtonActionPerformed(evt);
161            }
162        });
163
164        txtInstructorRole.setToolTipText("Specifies the role the instructor plays");
165
166        jLabel1.setText("Role of instructor:");
167
168        removeButton.setText("Remove");
169        removeButton.setToolTipText("Removes this property");
170        removeButton.addMouseListener(new java.awt.event.MouseAdapter() {
171            public void mouseClicked(java.awt.event.MouseEvent evt) {
172                removeThisProperty(evt);
173            }
174        });
175        removeButton.addActionListener(new java.awt.event.ActionListener() {
176            public void actionPerformed(java.awt.event.ActionEvent evt) {
177                removeButtonActionPerformed(evt);
178            }
179        });
180
181        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
182        this.setLayout(layout);
183        layout.setHorizontalGroup(
184            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
185            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
186                .addContainerGap()
187                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
188                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
189                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
190                        .add(jLabel1)
191                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
192                        .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE))
193                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
194                        .add(addInstructorButton)
195                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
196                        .add(addStudentButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
197                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
198                        .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
199                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 86, Short.MAX_VALUE))
200                    .add(removeButton))
201                .add(26, 26, 26))
202        );
203        layout.setVerticalGroup(
204            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
205            .add(layout.createSequentialGroup()
206                .addContainerGap()
207                .add(removeButton)
208                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
209                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
210                    .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
211                    .add(jLabel1))
212                .add(18, 18, 18)
213                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
214                    .add(addInstructorButton)
215                    .add(addStudentButton)
216                    .add(deleteSelectedButton))
217                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
218                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
219                .addContainerGap())
220        );
221    }// </editor-fold>//GEN-END:initComponents
222
223    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
224        //linked to remove button - removes the current buton
225        if (removeListener != null)
226        {
227            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
228        }
229    }//GEN-LAST:event_removeThisProperty
230
231    private void addInstructorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addInstructorButtonActionPerformed
232        // TODO add your handling code here:
233        buttonMap.put(addInstructorButton, txtInstructorRole.getText());
234        int i = event.roles.size();
235        event.roles.add(txtInstructorRole.getText());
236        event.lines.add("");
237    }//GEN-LAST:event_addInstructorButtonActionPerformed
238
239    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
240        // TODO add your handling code here:
241    }//GEN-LAST:event_removeButtonActionPerformed
242
243    private void deleteSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteSelectedButtonActionPerformed
244        // TODO add your handling code here:
245    }//GEN-LAST:event_deleteSelectedButtonActionPerformed
246
247
248    // Variables declaration - do not modify//GEN-BEGIN:variables
249    private javax.swing.JButton addInstructorButton;
250    private javax.swing.JButton addStudentButton;
251    private javax.swing.JButton deleteSelectedButton;
252    private javax.swing.JLabel jLabel1;
253    private javax.swing.JScrollPane jScrollPane1;
254    private javax.swing.JButton removeButton;
255    private javax.swing.JTextField txtInstructorRole;
256    // End of variables declaration//GEN-END:variables
257
258}
Note: See TracBrowser for help on using the repository browser.