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

Revision 1, 8.6 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 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 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(ScriptEventInterface 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                if (e.getKeyCode() == KeyEvent.VK_ENTER)
56                {
57                    buttonMap.put(addInstructorButton, txtInstructorRole.getText());
58                }
59            }
60
61            public void keyReleased(KeyEvent e)
62            {
63            }
64        });
65        buttonMap.put(addInstructorButton, txtInstructorRole.getText());
66        addInstructorButton.addActionListener(new ActionListener()
67        {
68
69            public void actionPerformed(ActionEvent e)
70            {
71                int i = event.roles.size();
72                event.roles.add(txtInstructorRole.getText());
73                event.lines.add("");
74            }
75        });
76        addStudentButton.addActionListener(new ActionListener()
77        {
78            public void actionPerformed(ActionEvent e)
79            {
80                int i = event.roles.size();
81                event.roles.add("Student");
82                event.lines.add("");
83            }
84        });
85        dialogTable.getModel().addTableModelListener(new TableModelListener()
86        {
87
88            public void tableChanged(TableModelEvent e)
89            {
90                if (e.getType() == TableModelEvent.UPDATE)
91                {
92                    event.roles.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 0).toString());
93                    event.lines.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString());
94                }
95                if(e.getType() == TableModelEvent.DELETE)
96                {
97                    event.roles.remove(e.getLastRow());
98                    event.lines.remove(e.getLastRow());
99                }
100            }
101        });
102
103    }
104
105    public void update(Observable o, Object arg)
106    {
107        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
108    }
109
110    /**
111     * This method is called from within the constructor to initialize the form.
112     * WARNING: Do NOT modify this code. The content of this method is always
113     * regenerated by the Form Editor.
114     */
115    @SuppressWarnings("unchecked")
116    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
117    private void initComponents()
118    {
119
120        addStudentButton = new javax.swing.JButton();
121        jScrollPane1 = new javax.swing.JScrollPane();
122        deleteSelectedButton = new javax.swing.JButton();
123        addInstructorButton = new javax.swing.JButton();
124        txtInstructorRole = new javax.swing.JTextField();
125        jLabel1 = new javax.swing.JLabel();
126        removeButton = new javax.swing.JButton();
127
128        addStudentButton.setText("Add Student Line");
129        addStudentButton.setToolTipText("Adds a row for student dialog in the table");
130
131        jScrollPane1.setHorizontalScrollBar(null);
132
133        deleteSelectedButton.setText("Delete Selected Line");
134        deleteSelectedButton.setToolTipText("Deletes the selected row in the table");
135
136        addInstructorButton.setText("Add Instructor Line");
137        addInstructorButton.setToolTipText("Adds a row for instructor dialog in the table");
138
139        txtInstructorRole.setToolTipText("Specifies the role the instructor plays");
140
141        jLabel1.setText("Role of instructor:");
142
143        removeButton.setText("Remove");
144        removeButton.setToolTipText("Removes this property");
145        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
146        {
147            public void mouseClicked(java.awt.event.MouseEvent evt)
148            {
149                removeThisProperty(evt);
150            }
151        });
152
153        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
154        this.setLayout(layout);
155        layout.setHorizontalGroup(
156            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
157            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
158                .addContainerGap()
159                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
160                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
161                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
162                        .add(jLabel1)
163                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
164                        .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE))
165                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
166                        .add(addInstructorButton)
167                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
168                        .add(addStudentButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
169                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
170                        .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
171                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 86, Short.MAX_VALUE))
172                    .add(removeButton))
173                .add(26, 26, 26))
174        );
175        layout.setVerticalGroup(
176            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
177            .add(layout.createSequentialGroup()
178                .addContainerGap()
179                .add(removeButton)
180                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
181                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
182                    .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
183                    .add(jLabel1))
184                .add(18, 18, 18)
185                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
186                    .add(addInstructorButton)
187                    .add(addStudentButton)
188                    .add(deleteSelectedButton))
189                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
190                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
191                .addContainerGap())
192        );
193    }// </editor-fold>//GEN-END:initComponents
194
195    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
196        if (removeListener != null)
197        {
198            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
199        }
200    }//GEN-LAST:event_removeThisProperty
201
202
203    // Variables declaration - do not modify//GEN-BEGIN:variables
204    private javax.swing.JButton addInstructorButton;
205    private javax.swing.JButton addStudentButton;
206    private javax.swing.JButton deleteSelectedButton;
207    private javax.swing.JLabel jLabel1;
208    private javax.swing.JScrollPane jScrollPane1;
209    private javax.swing.JButton removeButton;
210    private javax.swing.JTextField txtInstructorRole;
211    // End of variables declaration//GEN-END:variables
212
213}
Note: See TracBrowser for help on using the repository browser.