@@ -64,21 +64,21 @@ public class EditInjuryEntryDialog extends JDialog {
64
64
65
65
private Injury injury ;
66
66
67
- private JButton btnClose ;
68
- private JButton btnOK ;
69
- private JTextArea txtDays ;
67
+ private JButton btnClose ;
68
+ private JButton btnOK ;
69
+ private JTextArea txtDays ;
70
70
private JComboBox <BodyLocationChoice > ddLocation ;
71
- private JComboBox <InjuryTypeChoice > ddType ;
72
- private JTextArea txtFluff ;
73
- private JTextArea txtHits ;
74
- private JComboBox <String > ddPermanent ;
75
- private JComboBox <String > ddWorkedOn ;
76
- private JComboBox <String > ddExtended ;
77
- private JPanel panBtn ;
78
- private JPanel panMain ;
79
-
80
- private BodyLocationChoice [] locations ;
81
- private InjuryTypeChoice [] types ;
71
+ private JComboBox <InjuryTypeChoice > ddType ;
72
+ private JTextArea txtFluff ;
73
+ private JTextArea txtHits ;
74
+ private JComboBox <String > ddPermanent ;
75
+ private JComboBox <String > ddWorkedOn ;
76
+ private JComboBox <String > ddExtended ;
77
+ private JPanel panBtn ;
78
+ private JPanel panMain ;
79
+
80
+ private BodyLocationChoice [] locations ;
81
+ private InjuryTypeChoice [] types ;
82
82
private FilterableComboBoxModel <InjuryTypeChoice > ddTypeModel ;
83
83
84
84
public EditInjuryEntryDialog (final JFrame frame , final boolean modal , final Injury injury ) {
@@ -109,7 +109,7 @@ private void initComponents() {
109
109
110
110
types = InjuryType .getAllTypes ().stream ().map (InjuryTypeChoice ::new ).toArray (InjuryTypeChoice []::new );
111
111
112
- ddType = new JComboBox <>(types );
112
+ ddType = new JComboBox <>(types );
113
113
ddTypeModel = new FilterableComboBoxModel <>(ddType .getModel ());
114
114
ddTypeModel .setFilter (it -> {
115
115
BodyLocation loc = ((BodyLocationChoice ) Objects .requireNonNull (ddLocation .getSelectedItem ())).loc ;
@@ -124,17 +124,17 @@ private void initComponents() {
124
124
}
125
125
}
126
126
127
- txtDays = new JTextArea ();
127
+ txtDays = new JTextArea ();
128
128
txtFluff = new JTextArea ();
129
- txtHits = new JTextArea ();
129
+ txtHits = new JTextArea ();
130
130
String [] tf = { "True" , "False" };
131
131
ddPermanent = new JComboBox <>(tf );
132
- ddWorkedOn = new JComboBox <>(tf );
133
- ddExtended = new JComboBox <>(tf );
134
- btnOK = new JButton ();
135
- btnClose = new JButton ();
136
- panBtn = new JPanel ();
137
- panMain = new JPanel ();
132
+ ddWorkedOn = new JComboBox <>(tf );
133
+ ddExtended = new JComboBox <>(tf );
134
+ btnOK = new JButton ();
135
+ btnClose = new JButton ();
136
+ panBtn = new JPanel ();
137
+ panMain = new JPanel ();
138
138
139
139
final ResourceBundle resourceMap = ResourceBundle .getBundle ("mekhq.resources.EditInjuryEntryDialog" ,
140
140
MekHQ .getMHQOptions ().getLocale ());
@@ -154,14 +154,14 @@ private void initComponents() {
154
154
BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 )));
155
155
txtDays .setPreferredSize (new Dimension (250 , 75 ));
156
156
txtDays .setMinimumSize (new Dimension (250 , 75 ));
157
- gridBagConstraints = new GridBagConstraints ();
158
- gridBagConstraints .gridx = 0 ;
159
- gridBagConstraints .gridy = 0 ;
157
+ gridBagConstraints = new GridBagConstraints ();
158
+ gridBagConstraints .gridx = 0 ;
159
+ gridBagConstraints .gridy = 0 ;
160
160
gridBagConstraints .weightx = 1.0 ;
161
161
gridBagConstraints .weighty = 1.0 ;
162
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
163
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
164
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
162
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
163
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
164
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
165
165
panMain .add (txtDays , gridBagConstraints );
166
166
167
167
ddLocation .setName ("ddLocation" );
@@ -173,21 +173,21 @@ private void initComponents() {
173
173
ddLocation .addActionListener (evt -> {
174
174
ddTypeModel .updateFilter ();
175
175
176
- BodyLocation loc = ((BodyLocationChoice ) Objects .requireNonNull (ddLocation .getSelectedItem ())).loc ;
177
- InjuryType type = ((InjuryTypeChoice ) Objects .requireNonNull (ddType .getSelectedItem ())).type ;
176
+ BodyLocation loc = ((BodyLocationChoice ) Objects .requireNonNull (ddLocation .getSelectedItem ())).loc ;
177
+ InjuryType type = ((InjuryTypeChoice ) Objects .requireNonNull (ddType .getSelectedItem ())).type ;
178
178
if (!type .isValidInLocation (loc )) {
179
179
ddType .setSelectedItem (ddTypeModel .getElementAt (0 ));
180
180
}
181
181
});
182
182
183
- gridBagConstraints = new GridBagConstraints ();
184
- gridBagConstraints .gridx = 1 ;
185
- gridBagConstraints .gridy = 0 ;
183
+ gridBagConstraints = new GridBagConstraints ();
184
+ gridBagConstraints .gridx = 1 ;
185
+ gridBagConstraints .gridy = 0 ;
186
186
gridBagConstraints .weightx = 1.0 ;
187
187
gridBagConstraints .weighty = 1.0 ;
188
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
189
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
190
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
188
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
189
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
190
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
191
191
panMain .add (ddLocation , gridBagConstraints );
192
192
193
193
ddType .setName ("ddType" );
@@ -196,14 +196,14 @@ private void initComponents() {
196
196
BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 )));
197
197
ddType .setPreferredSize (new Dimension (250 , 75 ));
198
198
ddType .setMinimumSize (new Dimension (250 , 75 ));
199
- gridBagConstraints = new GridBagConstraints ();
200
- gridBagConstraints .gridx = 2 ;
201
- gridBagConstraints .gridy = 0 ;
199
+ gridBagConstraints = new GridBagConstraints ();
200
+ gridBagConstraints .gridx = 2 ;
201
+ gridBagConstraints .gridy = 0 ;
202
202
gridBagConstraints .weightx = 1.0 ;
203
203
gridBagConstraints .weighty = 1.0 ;
204
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
205
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
206
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
204
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
205
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
206
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
207
207
panMain .add (ddType , gridBagConstraints );
208
208
209
209
txtFluff .setText (injury .getFluff ());
@@ -215,14 +215,14 @@ private void initComponents() {
215
215
BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 )));
216
216
txtFluff .setPreferredSize (new Dimension (250 , 75 ));
217
217
txtFluff .setMinimumSize (new Dimension (250 , 75 ));
218
- gridBagConstraints = new GridBagConstraints ();
219
- gridBagConstraints .gridx = 3 ;
220
- gridBagConstraints .gridy = 0 ;
218
+ gridBagConstraints = new GridBagConstraints ();
219
+ gridBagConstraints .gridx = 3 ;
220
+ gridBagConstraints .gridy = 0 ;
221
221
gridBagConstraints .weightx = 1.0 ;
222
222
gridBagConstraints .weighty = 1.0 ;
223
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
224
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
225
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
223
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
224
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
225
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
226
226
panMain .add (txtFluff , gridBagConstraints );
227
227
228
228
txtHits .setText (Integer .toString (injury .getHits ()));
@@ -234,14 +234,14 @@ private void initComponents() {
234
234
BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 )));
235
235
txtHits .setPreferredSize (new Dimension (250 , 75 ));
236
236
txtHits .setMinimumSize (new Dimension (250 , 75 ));
237
- gridBagConstraints = new GridBagConstraints ();
238
- gridBagConstraints .gridx = 0 ;
239
- gridBagConstraints .gridy = 1 ;
237
+ gridBagConstraints = new GridBagConstraints ();
238
+ gridBagConstraints .gridx = 0 ;
239
+ gridBagConstraints .gridy = 1 ;
240
240
gridBagConstraints .weightx = 1.0 ;
241
241
gridBagConstraints .weighty = 1.0 ;
242
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
243
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
244
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
242
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
243
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
244
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
245
245
panMain .add (txtHits , gridBagConstraints );
246
246
247
247
ddPermanent .setSelectedIndex (injury .isPermanent () ? 0 : 1 );
@@ -251,14 +251,14 @@ private void initComponents() {
251
251
BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 )));
252
252
ddPermanent .setPreferredSize (new Dimension (250 , 75 ));
253
253
ddPermanent .setMinimumSize (new Dimension (250 , 75 ));
254
- gridBagConstraints = new GridBagConstraints ();
255
- gridBagConstraints .gridx = 1 ;
256
- gridBagConstraints .gridy = 1 ;
254
+ gridBagConstraints = new GridBagConstraints ();
255
+ gridBagConstraints .gridx = 1 ;
256
+ gridBagConstraints .gridy = 1 ;
257
257
gridBagConstraints .weightx = 1.0 ;
258
258
gridBagConstraints .weighty = 1.0 ;
259
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
260
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
261
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
259
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
260
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
261
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
262
262
panMain .add (ddPermanent , gridBagConstraints );
263
263
264
264
ddWorkedOn .setSelectedIndex (injury .isWorkedOn () ? 0 : 1 );
@@ -268,14 +268,14 @@ private void initComponents() {
268
268
BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 )));
269
269
ddWorkedOn .setPreferredSize (new Dimension (250 , 75 ));
270
270
ddWorkedOn .setMinimumSize (new Dimension (250 , 75 ));
271
- gridBagConstraints = new GridBagConstraints ();
272
- gridBagConstraints .gridx = 2 ;
273
- gridBagConstraints .gridy = 1 ;
271
+ gridBagConstraints = new GridBagConstraints ();
272
+ gridBagConstraints .gridx = 2 ;
273
+ gridBagConstraints .gridy = 1 ;
274
274
gridBagConstraints .weightx = 1.0 ;
275
275
gridBagConstraints .weighty = 1.0 ;
276
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
277
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
278
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
276
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
277
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
278
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
279
279
panMain .add (ddWorkedOn , gridBagConstraints );
280
280
281
281
ddExtended .setSelectedIndex (injury .getExtended () ? 0 : 1 );
@@ -285,14 +285,14 @@ private void initComponents() {
285
285
BorderFactory .createEmptyBorder (5 , 5 , 5 , 5 )));
286
286
ddExtended .setPreferredSize (new Dimension (250 , 75 ));
287
287
ddExtended .setMinimumSize (new Dimension (250 , 75 ));
288
- gridBagConstraints = new GridBagConstraints ();
289
- gridBagConstraints .gridx = 3 ;
290
- gridBagConstraints .gridy = 1 ;
288
+ gridBagConstraints = new GridBagConstraints ();
289
+ gridBagConstraints .gridx = 3 ;
290
+ gridBagConstraints .gridy = 1 ;
291
291
gridBagConstraints .weightx = 1.0 ;
292
292
gridBagConstraints .weighty = 1.0 ;
293
- gridBagConstraints .fill = GridBagConstraints .BOTH ;
294
- gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
295
- gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
293
+ gridBagConstraints .fill = GridBagConstraints .BOTH ;
294
+ gridBagConstraints .anchor = GridBagConstraints .NORTHWEST ;
295
+ gridBagConstraints .insets = new Insets (5 , 5 , 5 , 5 );
296
296
panMain .add (ddExtended , gridBagConstraints );
297
297
298
298
btnOK .setText (resourceMap .getString ("btnOkay.text" ));
@@ -328,16 +328,20 @@ private void setUserPreferences() {
328
328
}
329
329
330
330
private void btnOKActionPerformed (ActionEvent evt ) {
331
- injury .setTime (Integer .parseInt (txtDays .getText ()));
332
- injury .setHits (Integer .parseInt (txtHits .getText ()));
333
- injury .setFluff (txtFluff .getText ());
334
- injury .setLocation (((BodyLocationChoice ) Objects .requireNonNull (ddLocation .getSelectedItem ())).loc );
335
- injury .setType (((InjuryTypeChoice ) Objects .requireNonNull (ddType .getSelectedItem ())).type );
336
- injury .setPermanent (ddPermanent .getSelectedIndex () == 0 );
337
- injury .setWorkedOn (ddWorkedOn .getSelectedIndex () == 0 );
338
- injury .setExtended (ddExtended .getSelectedIndex () == 0 );
339
- injury .setUUID (UUID .randomUUID ());
340
- this .setVisible (false );
331
+ try {
332
+ injury .setTime (Integer .parseInt (txtDays .getText ()));
333
+ injury .setHits (Integer .parseInt (txtHits .getText ()));
334
+ injury .setFluff (txtFluff .getText ());
335
+ injury .setLocation (((BodyLocationChoice ) Objects .requireNonNull (ddLocation .getSelectedItem ())).loc );
336
+ injury .setType (((InjuryTypeChoice ) Objects .requireNonNull (ddType .getSelectedItem ())).type );
337
+ injury .setPermanent (ddPermanent .getSelectedIndex () == 0 );
338
+ injury .setWorkedOn (ddWorkedOn .getSelectedIndex () == 0 );
339
+ injury .setExtended (ddExtended .getSelectedIndex () == 0 );
340
+ injury .setUUID (UUID .randomUUID ());
341
+ this .dispose ();
342
+ } catch (Exception ex ) {
343
+ logger .info ("Failed to update injury entry" , ex );
344
+ }
341
345
}
342
346
343
347
private void btnCloseActionPerformed (ActionEvent evt ) {
0 commit comments