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

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

Revision 1, 9.8 KB checked in by bmcguffin, 9 years ago (diff)

2017/07/18: Uploaded entire prototype to SVN repo.

RevLine 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.Observable;
5import scriptbuilder.structures.events.ScriptEventInterface;
6import scriptbuilder.structures.events.UnitEvent;
7
8/**
9 *
10 * @author nathaniellehrer
11 */
12public class UnitPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel
13{
14
15    private ActionListener removeListener;
16    private UnitEvent event;
17
18    /**
19     * Creates new form UnitPanel
20     */
21    public UnitPanel()
22    {
23        initComponents();
24
25        txtUnitNumber.addFocusListener(new FocusListener()
26        {
27
28            public void focusGained(FocusEvent e)
29            {
30                help.setText("Unit number is formatted as #-#\t\tExample: 5-5");
31            }
32
33            public void focusLost(FocusEvent e)
34            {
35                help.setText("");
36            }
37
38        });
39    }
40
41    public void setRemoveListener(ActionListener listener)
42    {
43        removeListener = listener;
44    }
45
46    public void getEventObject(ScriptEventInterface sei)
47    {
48        event = (UnitEvent) sei;
49        txtUnitNumber.setText(event.unitNum);
50        for (int i = 0; i < ActiveDropdown.getItemCount(); i++)
51        {
52            if (event.unitActive.equalsIgnoreCase((String) ActiveDropdown.getItemAt(i)))
53            {
54                ActiveDropdown.setSelectedIndex(i);
55            }
56        }
57        txtUnitNumber.addKeyListener(new KeyListener()
58        {
59            public void keyTyped(KeyEvent e)
60            {
61            }
62            public void keyPressed(KeyEvent e)
63            {
64                if (e.getKeyCode() == KeyEvent.VK_ENTER)
65                {
66                    event.unitNum = txtUnitNumber.getText();
67                }
68            }
69            public void keyReleased(KeyEvent e)
70            {
71            }
72        });
73        ActiveDropdown.addActionListener(new ActionListener()
74        {
75
76            public void actionPerformed(ActionEvent e)
77            {
78                event.unitActive = ActiveDropdown.getSelectedItem().toString();
79            }
80        });
81        for (int i = 0; i < PrimaryDropdown.getItemCount(); i++)
82        {
83            if (event.unitPrimary.equalsIgnoreCase((String) PrimaryDropdown.getItemAt(i)))
84            {
85                PrimaryDropdown.setSelectedIndex(i);
86            }
87        }
88        PrimaryDropdown.addActionListener(new ActionListener()
89        {
90
91            public void actionPerformed(ActionEvent e)
92            {
93                event.unitPrimary = PrimaryDropdown.getSelectedItem().toString();
94            }
95        });
96        boolean containsItem = false;
97        for (int i = 0; i < StatusDropdown.getItemCount() && !containsItem; i++)
98        {
99            if (event.unitStatus.equalsIgnoreCase((String) StatusDropdown.getItemAt(i)))
100            {
101                StatusDropdown.setSelectedIndex(i);
102                containsItem = true;
103            }
104        }
105        if (!containsItem)
106        {
107            StatusDropdown.addItem(event.unitStatus);
108            StatusDropdown.setSelectedItem(StatusDropdown.getItemCount() - 1);
109        }
110        StatusDropdown.addActionListener(new ActionListener()
111        {
112
113            public void actionPerformed(ActionEvent e)
114            {
115                event.unitStatus = StatusDropdown.getSelectedItem().toString();
116            }
117        });
118    }
119
120    public void update(Observable o, Object arg)
121    {
122        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
123    }
124
125    /**
126     * This method is called from within the constructor to initialize the form.
127     * WARNING: Do NOT modify this code. The content of this method is always
128     * regenerated by the Form Editor.
129     */
130    @SuppressWarnings("unchecked")
131    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
132    private void initComponents()
133    {
134
135        jLabel1 = new javax.swing.JLabel();
136        txtUnitNumber = new javax.swing.JFormattedTextField();
137        removeButton = new javax.swing.JButton();
138        jLabel2 = new javax.swing.JLabel();
139        StatusDropdown = new javax.swing.JComboBox();
140        jLabel3 = new javax.swing.JLabel();
141        PrimaryDropdown = new javax.swing.JComboBox();
142        jLabel4 = new javax.swing.JLabel();
143        ActiveDropdown = new javax.swing.JComboBox();
144        help = new javax.swing.JLabel();
145
146        jLabel1.setText("Unit Number");
147
148        txtUnitNumber.setText("  -  ");
149        txtUnitNumber.setToolTipText("");
150
151        removeButton.setText("Remove");
152        removeButton.addMouseListener(new java.awt.event.MouseAdapter()
153        {
154            public void mouseClicked(java.awt.event.MouseEvent evt)
155            {
156                removeThisProperty(evt);
157            }
158        });
159
160        jLabel2.setText("Status");
161
162        StatusDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1098", "1097", "ENRT" }));
163
164        jLabel3.setText("Primary");
165
166        PrimaryDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" }));
167
168        jLabel4.setText("Active");
169
170        ActiveDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" }));
171
172        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
173        this.setLayout(layout);
174        layout.setHorizontalGroup(
175            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
176            .add(layout.createSequentialGroup()
177                .addContainerGap()
178                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
179                    .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton)
180                    .add(org.jdesktop.layout.GroupLayout.TRAILING, help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
181                    .add(layout.createSequentialGroup()
182                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
183                            .add(jLabel1)
184                            .add(jLabel2))
185                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
186                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
187                            .add(StatusDropdown, 0, 475, Short.MAX_VALUE)
188                            .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)))
189                    .add(layout.createSequentialGroup()
190                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
191                            .add(jLabel3)
192                            .add(jLabel4))
193                        .add(43, 43, 43)
194                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
195                            .add(ActiveDropdown, 0, 475, Short.MAX_VALUE)
196                            .add(PrimaryDropdown, 0, 475, Short.MAX_VALUE))))
197                .addContainerGap())
198        );
199        layout.setVerticalGroup(
200            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
201            .add(layout.createSequentialGroup()
202                .addContainerGap()
203                .add(removeButton)
204                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
205                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
206                    .add(jLabel1)
207                    .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
208                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
209                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
210                    .add(jLabel2)
211                    .add(StatusDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
212                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
213                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
214                    .add(jLabel3)
215                    .add(PrimaryDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
216                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
217                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
218                    .add(jLabel4)
219                    .add(ActiveDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
220                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 128, Short.MAX_VALUE)
221                .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
222                .addContainerGap())
223        );
224    }// </editor-fold>//GEN-END:initComponents
225
226    private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty
227        if (removeListener != null)
228        {
229            removeListener.actionPerformed(new ActionEvent(this, 0, ""));
230        }
231    }//GEN-LAST:event_removeThisProperty
232
233
234    // Variables declaration - do not modify//GEN-BEGIN:variables
235    private javax.swing.JComboBox ActiveDropdown;
236    private javax.swing.JComboBox PrimaryDropdown;
237    private javax.swing.JComboBox StatusDropdown;
238    private javax.swing.JLabel help;
239    private javax.swing.JLabel jLabel1;
240    private javax.swing.JLabel jLabel2;
241    private javax.swing.JLabel jLabel3;
242    private javax.swing.JLabel jLabel4;
243    private javax.swing.JButton removeButton;
244    private javax.swing.JFormattedTextField txtUnitNumber;
245    // End of variables declaration//GEN-END:variables
246
247}
Note: See TracBrowser for help on using the repository browser.