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

source: tmcsimulator-scriptbuilder/trunk/src/event/editor/CMSEvaluationPanel.java @ 130

Revision 130, 8.3 KB checked in by bmcguffin, 9 years ago (diff)

Changed implementation of save function for event editor panels. Instead of updating their model objects whenever the enter key is pressed, panels are now notified when the window is closed and update their information then.

RevLine 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.*;
5import javax.swing.JTable;
6import javax.swing.event.TableModelEvent;
7import javax.swing.event.TableModelListener;
8import scriptbuilder.structures.events.CMSEvaluationEvent;
9import scriptbuilder.structures.events.I_ScriptEvent;
10
11/**
12 *
13 * @author nathaniellehrer
14 */
15public class CMSEvaluationPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel
16{
17
18    private HashMap<String, Class> properties;
19    private JTable dialogTable;
20    private CMSEvaluationEvent event;
21
22    /**
23     * Creates new form CMSEvaluation
24     */
25    public CMSEvaluationPanel()
26    {
27        initComponents();
28
29        dialogTable = GenericTable.genericizeNumberedTable(jScrollPane1, addButton, deleteButton);
30    }
31
32    @Override
33    public void getEventObject(I_ScriptEvent sei)
34    {
35        event = (CMSEvaluationEvent) sei;
36        txtID.setText(event.cmsID);
37       
38        txtLocation.setText(event.location);
39       
40        txtMessage.setText("");
41        for (int i = 0; i < event.message.size(); i++)
42        {
43            ((MyTableModel) dialogTable.getModel()).addRow("" + (i + 1), event.message.get(i));
44        }
45        for (int i = 0; i < TypeDropdown.getItemCount(); i++)
46        {
47            if (event.cmsType.equalsIgnoreCase(TypeDropdown.getItemAt(i).toString()))
48            {
49                TypeDropdown.setSelectedIndex(i);
50            }
51        }
52       
53        addButton.addActionListener(new ActionListener()
54        {
55
56            @Override
57            public void actionPerformed(ActionEvent e)
58            {
59                event.message.add("");
60            }
61        });
62        dialogTable.getModel().addTableModelListener(new TableModelListener()
63        {
64
65            public void tableChanged(TableModelEvent e)
66            {
67                if (e.getType() == TableModelEvent.UPDATE)
68                {
69                    event.message.set(e.getLastRow(), dialogTable.getModel().getValueAt(e.getLastRow(), 1).toString());
70                }
71                if (e.getType() == TableModelEvent.DELETE)
72                {
73                    event.message.remove(e.getLastRow());
74                }
75            }
76        });
77    }
78
79    @Override
80    public void update(Observable o, Object arg)
81    {
82        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
83    }
84   
85    @Override
86    public boolean removeAssociatedEvent()
87    {
88        event.removeThis();
89        event = null;
90        return true;
91    }
92
93    @Override
94    public void uponClose()
95    {
96        event.cmsID = txtID.getText();
97        event.location = txtLocation.getText();
98        event.cmsType = TypeDropdown.getSelectedItem().toString();
99    }
100
101    /**
102     * This method is called from within the constructor to initialize the form.
103     * WARNING: Do NOT modify this code. The content of this method is always
104     * regenerated by the Form Editor.
105     */
106    @SuppressWarnings("unchecked")
107    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
108    private void initComponents()
109    {
110
111        jLabel3 = new javax.swing.JLabel();
112        txtLocation = new javax.swing.JTextField();
113        jLabel2 = new javax.swing.JLabel();
114        TypeDropdown = new javax.swing.JComboBox();
115        txtID = new javax.swing.JFormattedTextField();
116        jLabel1 = new javax.swing.JLabel();
117        deleteButton = new javax.swing.JButton();
118        jScrollPane1 = new javax.swing.JScrollPane();
119        txtMessage = new javax.swing.JTextArea();
120        addButton = new javax.swing.JButton();
121
122        jLabel3.setText("Location");
123
124        txtLocation.setToolTipText("Example: SB 55 @ WARNER AVE");
125
126        jLabel2.setText("Type");
127
128        TypeDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Update", "New", "Remove" }));
129
130        txtID.setToolTipText("Example: 72");
131
132        jLabel1.setText("CMS ID");
133
134        deleteButton.setText("Delete Selected Message");
135        deleteButton.setToolTipText("Deletes the selected message from the table");
136
137        jScrollPane1.setHorizontalScrollBar(null);
138
139        txtMessage.setColumns(20);
140        txtMessage.setRows(5);
141        jScrollPane1.setViewportView(txtMessage);
142
143        addButton.setText("Add Message");
144        addButton.setToolTipText("Adds a message to the table");
145
146        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
147        this.setLayout(layout);
148        layout.setHorizontalGroup(
149            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
150            .add(layout.createSequentialGroup()
151                .addContainerGap()
152                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
153                    .add(layout.createSequentialGroup()
154                        .add(6, 6, 6)
155                        .add(addButton)
156                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
157                        .add(deleteButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
158                        .add(293, 293, 293))
159                    .add(layout.createSequentialGroup()
160                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
161                            .add(jScrollPane1)
162                            .add(layout.createSequentialGroup()
163                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
164                                    .add(jLabel1)
165                                    .add(jLabel3)
166                                    .add(jLabel2))
167                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
168                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
169                                    .add(TypeDropdown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
170                                    .add(txtLocation)
171                                    .add(txtID))))
172                        .addContainerGap())))
173        );
174        layout.setVerticalGroup(
175            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
176            .add(layout.createSequentialGroup()
177                .add(52, 52, 52)
178                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
179                    .add(jLabel1)
180                    .add(txtID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
181                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
182                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
183                    .add(TypeDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
184                    .add(jLabel2))
185                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
186                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
187                    .add(jLabel3)
188                    .add(txtLocation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
189                .add(31, 31, 31)
190                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
191                    .add(deleteButton)
192                    .add(addButton))
193                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
194                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
195                .addContainerGap())
196        );
197    }// </editor-fold>//GEN-END:initComponents
198
199
200    // Variables declaration - do not modify//GEN-BEGIN:variables
201    private javax.swing.JComboBox TypeDropdown;
202    private javax.swing.JButton addButton;
203    private javax.swing.JButton deleteButton;
204    private javax.swing.JLabel jLabel1;
205    private javax.swing.JLabel jLabel2;
206    private javax.swing.JLabel jLabel3;
207    private javax.swing.JScrollPane jScrollPane1;
208    private javax.swing.JFormattedTextField txtID;
209    private javax.swing.JTextField txtLocation;
210    private javax.swing.JTextArea txtMessage;
211    // End of variables declaration//GEN-END:variables
212
213}
Note: See TracBrowser for help on using the repository browser.