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

Revision 130, 7.6 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.

Line 
1package event.editor;
2
3import java.awt.event.*;
4import java.util.Observable;
5import scriptbuilder.structures.events.I_ScriptEvent;
6import scriptbuilder.structures.events.TowEvent;
7
8/**
9 *
10 * @author nathaniellehrer
11 */
12public class TowPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel
13{
14
15    private ActionListener removeListener;
16    private TowEvent event;
17
18    /**
19     * Creates new form TowPanel
20     */
21    public TowPanel()
22    {
23        initComponents();
24
25        txtConfirmationNumber.addFocusListener(new FocusListener()
26        {
27
28            public void focusGained(FocusEvent e)
29            {
30                help.setText("Confirmation number is formated as a telephone number. Example: (555)555-5555");
31            }
32
33            public void focusLost(FocusEvent e)
34            {
35                help.setText("");
36            }
37
38        });
39
40        txtPublicNumber.addFocusListener(new FocusListener()
41        {
42
43            public void focusGained(FocusEvent e)
44            {
45                help.setText("Public number is formated as a telephone number. Example: (555)555-5555");
46            }
47
48            public void focusLost(FocusEvent e)
49            {
50                help.setText("");
51            }
52
53        });
54
55    }
56
57    @Override
58    public void getEventObject(I_ScriptEvent sei)
59    {
60        event = (TowEvent) sei;
61        txtCompany.setText(event.towCompany);
62
63        txtBeat.setText(event.towBeat);
64
65        txtConfirmationNumber.setText("" + event.towConfNum);
66
67        txtPublicNumber.setText("" + event.towPubNum);
68
69    }
70
71    @Override
72    public void update(Observable o, Object arg)
73    {
74        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
75    }
76
77    @Override
78    public boolean removeAssociatedEvent()
79    {
80        event.removeThis();
81        event = null;
82        return true;
83    }
84
85    @Override
86    public void uponClose()
87    {
88        event.towCompany = txtCompany.getText();
89        event.towBeat = txtBeat.getText();
90        event.towConfNum = txtConfirmationNumber.getText();
91        event.towPubNum = txtPublicNumber.getText();
92    }
93
94    /**
95     * This method is called from within the constructor to initialize the form.
96     * WARNING: Do NOT modify this code. The content of this method is always
97     * regenerated by the Form Editor.
98     */
99    @SuppressWarnings("unchecked")
100    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
101    private void initComponents()
102    {
103
104        jLabel1 = new javax.swing.JLabel();
105        txtCompany = new javax.swing.JTextField();
106        jLabel2 = new javax.swing.JLabel();
107        txtConfirmationNumber = new javax.swing.JFormattedTextField();
108        jLabel3 = new javax.swing.JLabel();
109        txtPublicNumber = new javax.swing.JFormattedTextField();
110        jLabel4 = new javax.swing.JLabel();
111        txtBeat = new javax.swing.JTextField();
112        help = new javax.swing.JLabel();
113
114        jLabel1.setText("Company");
115
116        jLabel2.setText("Confirmation Number");
117
118        try
119        {
120            txtConfirmationNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)###-####")));
121        } catch (java.text.ParseException ex)
122        {
123            ex.printStackTrace();
124        }
125
126        jLabel3.setText("Public Number");
127
128        try
129        {
130            txtPublicNumber.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(###)###-####")));
131        } catch (java.text.ParseException ex)
132        {
133            ex.printStackTrace();
134        }
135
136        jLabel4.setText("Beat");
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(help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
146                    .add(layout.createSequentialGroup()
147                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
148                            .add(jLabel1)
149                            .add(jLabel2)
150                            .add(jLabel3)
151                            .add(jLabel4))
152                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
153                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
154                            .add(txtBeat, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
155                            .add(txtCompany, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
156                            .add(txtConfirmationNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
157                            .add(txtPublicNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE))))
158                .addContainerGap())
159        );
160        layout.setVerticalGroup(
161            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
162            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
163                .add(47, 47, 47)
164                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
165                    .add(jLabel1)
166                    .add(txtCompany, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
167                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
168                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
169                    .add(jLabel2)
170                    .add(txtConfirmationNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
171                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
172                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
173                    .add(jLabel3)
174                    .add(txtPublicNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
175                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
176                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
177                    .add(jLabel4)
178                    .add(txtBeat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
179                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 72, Short.MAX_VALUE)
180                .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
181                .addContainerGap())
182        );
183    }// </editor-fold>//GEN-END:initComponents
184
185
186    // Variables declaration - do not modify//GEN-BEGIN:variables
187    private javax.swing.JLabel help;
188    private javax.swing.JLabel jLabel1;
189    private javax.swing.JLabel jLabel2;
190    private javax.swing.JLabel jLabel3;
191    private javax.swing.JLabel jLabel4;
192    private javax.swing.JTextField txtBeat;
193    private javax.swing.JTextField txtCompany;
194    private javax.swing.JFormattedTextField txtConfirmationNumber;
195    private javax.swing.JFormattedTextField txtPublicNumber;
196    // End of variables declaration//GEN-END:variables
197
198}
Note: See TracBrowser for help on using the repository browser.