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

Revision 7, 9.0 KB checked in by bmcguffin, 9 years ago (diff)

Renamed Interfaces in structures.events package from "*Interface" to "I_*"

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