26
26
import javax .swing .JLabel ;
27
27
import javax .swing .JPanel ;
28
28
import javax .swing .JSpinner ;
29
- import javax .swing .JTextField ;
30
29
import javax .swing .SpinnerNumberModel ;
31
30
import javax .swing .SwingConstants ;
31
+ import javax .swing .event .DocumentEvent ;
32
+ import javax .swing .event .DocumentListener ;
32
33
import rv .Configuration ;
33
34
import rv .util .swing .SwingUtil ;
34
35
@@ -46,8 +47,8 @@ public class GraphicsPanel extends JPanel implements SaveListener
46
47
JCheckBox maximizedCB ;
47
48
JCheckBox centerCB ;
48
49
JCheckBox saveStateCB ;
49
- JTextField samplesTF ;
50
- JTextField shadowResTB ;
50
+ IntegerTextField samplesTF ;
51
+ IntegerTextField shadowResTB ;
51
52
JSpinner fpsSpinner ;
52
53
JSpinner fpFovSpinner ;
53
54
JSpinner tpFovSpinner ;
@@ -58,11 +59,14 @@ public class GraphicsPanel extends JPanel implements SaveListener
58
59
final JLabel shadowResLabel = new JLabel ("Shadow Resolution: " , SwingConstants .RIGHT );
59
60
final JLabel samplesLabel = new JLabel ("Samples: " , SwingConstants .RIGHT );
60
61
62
+ private Runnable onChange ;
63
+
61
64
public GraphicsPanel (RVConfigure configProg )
62
65
{
63
66
config = configProg .config .graphics ;
64
67
initGUI ();
65
68
configProg .listeners .add (this );
69
+ onChange = configProg .updateSaveButtonState ;
66
70
}
67
71
68
72
void initGUI ()
@@ -106,8 +110,34 @@ JPanel initAAPanel()
106
110
c .ipadx = 10 ;
107
111
108
112
fsaaCB = new JCheckBox ("Enabled" , config .useFsaa );
109
- fsaaCB .addChangeListener (e -> updateAAEnabled ());
113
+ fsaaCB .addChangeListener (e -> {
114
+ updateAAEnabled ();
115
+ config .useFsaa = fsaaCB .isSelected ();
116
+ onChange .run ();
117
+ });
110
118
samplesTF = new IntegerTextField (config .fsaaSamples , 1 , Integer .MAX_VALUE );
119
+ samplesTF .getDocument ().addDocumentListener (new DocumentListener () {
120
+ @ Override
121
+ public void insertUpdate (DocumentEvent e )
122
+ {
123
+ updateFsaaSamplesConfig (false );
124
+ onChange .run ();
125
+ }
126
+
127
+ @ Override
128
+ public void removeUpdate (DocumentEvent e )
129
+ {
130
+ updateFsaaSamplesConfig (false );
131
+ onChange .run ();
132
+ }
133
+
134
+ @ Override
135
+ public void changedUpdate (DocumentEvent e )
136
+ {
137
+ updateFsaaSamplesConfig (false );
138
+ onChange .run ();
139
+ }
140
+ });
111
141
updateAAEnabled ();
112
142
113
143
addConstrained (fsaaCB , panel , c , 0 , 0 );
@@ -133,10 +163,30 @@ JPanel initGeneral()
133
163
c .ipadx = 10 ;
134
164
135
165
stereoCB = new JCheckBox ("Stereo 3D" , config .useStereo );
166
+ stereoCB .addChangeListener (e -> {
167
+ config .useStereo = stereoCB .isSelected ();
168
+ onChange .run ();
169
+ });
136
170
vsyncCB = new JCheckBox ("V-Sync" , config .useVsync );
171
+ vsyncCB .addChangeListener (e -> {
172
+ config .useVsync = vsyncCB .isSelected ();
173
+ onChange .run ();
174
+ });
137
175
fpsSpinner = createSpinner (config .targetFPS , 1 , 60 );
176
+ fpsSpinner .addChangeListener (e -> {
177
+ config .targetFPS = (Integer ) fpsSpinner .getValue ();
178
+ onChange .run ();
179
+ });
138
180
fpFovSpinner = createSpinner (config .firstPersonFOV , 1 , 300 );
181
+ fpFovSpinner .addChangeListener (e -> {
182
+ config .firstPersonFOV = (Integer ) fpFovSpinner .getValue ();
183
+ onChange .run ();
184
+ });
139
185
tpFovSpinner = createSpinner (config .thirdPersonFOV , 1 , 300 );
186
+ tpFovSpinner .addChangeListener (e -> {
187
+ config .thirdPersonFOV = (Integer ) tpFovSpinner .getValue ();
188
+ onChange .run ();
189
+ });
140
190
141
191
int y = 0 ;
142
192
addConstrained (stereoCB , panel , c , 0 , y );
@@ -171,14 +221,42 @@ JPanel initFramePanel()
171
221
c .ipadx = 10 ;
172
222
173
223
fxSpinner = createSpinner (config .frameX , -100 , 10000 );
224
+ fxSpinner .addChangeListener (e -> {
225
+ config .frameX = (Integer ) fxSpinner .getValue ();
226
+ onChange .run ();
227
+ });
174
228
fySpinner = createSpinner (config .frameY , -100 , 10000 );
229
+ fySpinner .addChangeListener (e -> {
230
+ config .frameY = (Integer ) fySpinner .getValue ();
231
+ onChange .run ();
232
+ });
175
233
fwSpinner = createSpinner (config .frameWidth , 1 , 10000 );
234
+ fwSpinner .addChangeListener (e -> {
235
+ config .frameWidth = (Integer ) fwSpinner .getValue ();
236
+ onChange .run ();
237
+ });
176
238
fhSpinner = createSpinner (config .frameHeight , 1 , 10000 );
239
+ fhSpinner .addChangeListener (e -> {
240
+ config .frameHeight = (Integer ) fhSpinner .getValue ();
241
+ onChange .run ();
242
+ });
177
243
maximizedCB = new JCheckBox ("Maximized" , config .isMaximized );
244
+ maximizedCB .addChangeListener (e -> {
245
+ config .isMaximized = maximizedCB .isSelected ();
246
+ onChange .run ();
247
+ });
178
248
centerCB = new JCheckBox ("Center Position" , config .centerFrame );
179
- centerCB .addActionListener (e -> updateFramePositionEnabled ());
249
+ centerCB .addChangeListener (e -> {
250
+ updateFramePositionEnabled ();
251
+ config .centerFrame = centerCB .isSelected ();
252
+ onChange .run ();
253
+ });
180
254
updateFramePositionEnabled ();
181
255
saveStateCB = new JCheckBox ("Save Frame State" , config .saveFrameState );
256
+ saveStateCB .addChangeListener (e -> {
257
+ config .saveFrameState = saveStateCB .isSelected ();
258
+ onChange .run ();
259
+ });
182
260
183
261
int y = 0 ;
184
262
addLabel ("X: " , panel , c , 0 , y );
@@ -224,12 +302,50 @@ JPanel initLightingPanel()
224
302
c .ipadx = 10 ;
225
303
226
304
bloomCB = new JCheckBox ("Bloom" , config .useBloom );
305
+ bloomCB .addChangeListener (e -> {
306
+ config .useBloom = bloomCB .isSelected ();
307
+ onChange .run ();
308
+ });
227
309
phongCB = new JCheckBox ("Phong" , config .usePhong );
310
+ phongCB .addChangeListener (e -> {
311
+ config .usePhong = phongCB .isSelected ();
312
+ onChange .run ();
313
+ });
228
314
shadowCB = new JCheckBox ("Shadows" , config .useShadows );
229
- shadowCB .addChangeListener (arg0 -> updateShadowsEnabled ());
315
+ shadowCB .addChangeListener (e -> {
316
+ updateShadowsEnabled ();
317
+ config .useShadows = shadowCB .isSelected ();
318
+ onChange .run ();
319
+ });
230
320
231
321
softShadowCB = new JCheckBox ("Soft Shadows" , config .useSoftShadows );
322
+ softShadowCB .addChangeListener (e -> {
323
+ config .useSoftShadows = softShadowCB .isSelected ();
324
+ onChange .run ();
325
+ });
232
326
shadowResTB = new IntegerTextField (config .shadowResolution , 1 , Integer .MAX_VALUE );
327
+ shadowResTB .getDocument ().addDocumentListener (new DocumentListener () {
328
+ @ Override
329
+ public void insertUpdate (DocumentEvent e )
330
+ {
331
+ updateShadowResolutionConfig (false );
332
+ onChange .run ();
333
+ }
334
+
335
+ @ Override
336
+ public void removeUpdate (DocumentEvent e )
337
+ {
338
+ updateShadowResolutionConfig (false );
339
+ onChange .run ();
340
+ }
341
+
342
+ @ Override
343
+ public void changedUpdate (DocumentEvent e )
344
+ {
345
+ updateShadowResolutionConfig (false );
346
+ onChange .run ();
347
+ }
348
+ });
233
349
updateShadowsEnabled ();
234
350
235
351
addConstrained (phongCB , panel , c , 0 , 0 );
@@ -250,6 +366,28 @@ void updateShadowsEnabled()
250
366
shadowResLabel .setEnabled (shadowCB .isSelected ());
251
367
}
252
368
369
+ private void updateFsaaSamplesConfig (boolean resetOnError )
370
+ {
371
+ try {
372
+ config .fsaaSamples = samplesTF .getInt ();
373
+ } catch (Exception e ) {
374
+ if (resetOnError ) {
375
+ samplesTF .setText (config .fsaaSamples + "" );
376
+ }
377
+ }
378
+ }
379
+
380
+ private void updateShadowResolutionConfig (boolean resetOnError )
381
+ {
382
+ try {
383
+ config .shadowResolution = shadowResTB .getInt ();
384
+ } catch (Exception e ) {
385
+ if (resetOnError ) {
386
+ shadowResTB .setText (config .shadowResolution + "" );
387
+ }
388
+ }
389
+ }
390
+
253
391
@ Override
254
392
public void configSaved (RVConfigure configProg )
255
393
{
@@ -261,17 +399,8 @@ public void configSaved(RVConfigure configProg)
261
399
config .useStereo = stereoCB .isSelected ();
262
400
config .useVsync = vsyncCB .isSelected ();
263
401
264
- try {
265
- config .fsaaSamples = Integer .parseInt (samplesTF .getText ());
266
- } catch (Exception e ) {
267
- samplesTF .setText (config .fsaaSamples + "" );
268
- }
269
-
270
- try {
271
- config .shadowResolution = Integer .parseInt (shadowResTB .getText ());
272
- } catch (Exception e ) {
273
- shadowResTB .setText (config .shadowResolution + "" );
274
- }
402
+ updateFsaaSamplesConfig (true );
403
+ updateShadowResolutionConfig (true );
275
404
276
405
config .targetFPS = (Integer ) fpsSpinner .getValue ();
277
406
config .firstPersonFOV = (Integer ) fpFovSpinner .getValue ();
0 commit comments