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

Revision 89, 8.7 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 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(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                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    @Override
111    public boolean removeAssociatedEvent()
112    {
113        ((I_ScriptEvent)event).removeThis();
114        event = null;
115        return true;
116    }
117
118    /**
119     * This method is called from within the constructor to initialize the form.
120     * WARNING: Do NOT modify this code. The content of this method is always
121     * regenerated by the Form Editor.
122     */
123    @SuppressWarnings("unchecked")
124    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
125    private void initComponents()
126    {
127
128        addStudentButton = new javax.swing.JButton();
129        jScrollPane1 = new javax.swing.JScrollPane();
130        deleteSelectedButton = new javax.swing.JButton();
131        addInstructorButton = new javax.swing.JButton();
132        txtInstructorRole = new javax.swing.JTextField();
133        jLabel1 = new javax.swing.JLabel();
134        removeButton = new javax.swing.JButton();
135
136        addStudentButton.setText("Add Student Line");
137        addStudentButton.setToolTipText("Adds a row for student dialog in the table");
138
139        jScrollPane1.setHorizontalScrollBar(null);
140
141        deleteSelectedButton.setText("Delete Selected Line");
142        deleteSelectedButton.setToolTipText("Deletes the selected row in the table");
143
144        addInstructorButton.setText("Add Instructor Line");
145        addInstructorButton.setToolTipText("Adds a row for instructor dialog in the table");
146
147        txtInstructorRole.setToolTipText("Specifies the role the instructor plays");
148
149        jLabel1.setText("Role of instructor:");
150
151        removeButton.setText("Remove");
152        removeButton.setToolTipText("Removes this property");
153        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
154        {
155            public void mouseClicked(java.awt.event.MouseEvent evt)
156            {
157                removeThisProperty(evt);
158            }
159        });
160
161        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
162        this.setLayout(layout);
163        layout.setHorizontalGroup(
164            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
165            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
166                .addContainerGap()
167                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
168                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 602, Short.MAX_VALUE)
169                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
170                        .add(jLabel1)
171                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
172                        .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE))
173                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
174                        .add(addInstructorButton)
175                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
176                        .add(addStudentButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
177                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
178                        .add(deleteSelectedButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
179                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 86, Short.MAX_VALUE))
180                    .add(removeButton))
181                .add(26, 26, 26))
182        );
183        layout.setVerticalGroup(
184            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
185            .add(layout.createSequentialGroup()
186                .addContainerGap()
187                .add(removeButton)
188                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
189                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
190                    .add(txtInstructorRole, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
191                    .add(jLabel1))
192                .add(18, 18, 18)
193                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
194                    .add(addInstructorButton)
195                    .add(addStudentButton)
196                    .add(deleteSelectedButton))
197                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
198                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
199                .addContainerGap())
200        );
201    }// </editor-fold>//GEN-END:initComponents
202
203    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
204        if (removeListener != null)
205        {
206            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
207        }
208    }//GEN-LAST:event_removeThisProperty
209
210
211    // Variables declaration - do not modify//GEN-BEGIN:variables
212    private javax.swing.JButton addInstructorButton;
213    private javax.swing.JButton addStudentButton;
214    private javax.swing.JButton deleteSelectedButton;
215    private javax.swing.JLabel jLabel1;
216    private javax.swing.JScrollPane jScrollPane1;
217    private javax.swing.JButton removeButton;
218    private javax.swing.JTextField txtInstructorRole;
219    // End of variables declaration//GEN-END:variables
220
221}
Note: See TracBrowser for help on using the repository browser.