Skip to content

Commit de481ed

Browse files
authored
Various configuration improvements (#112)
* Configuration improvements - don't delete commented out lines in config when saving - only save configuration if it actually changed * Fix parsing integers in RVConfigure * Fix config.txt indentation * Use cloning for creating original configuration objects And fix an error in an equals method. * Only enable save button if there are changes Server host and port are not using this feature yet. * Store multiple team colors and servers in config file Multiple team colors and servers can now be stored in the config file. * Fix IntegerTextField Should now work as expected * Reduce size of diff for pull request * Implement requested changes * Undo eclipse import formatting
1 parent b6e923b commit de481ed

15 files changed

+1105
-232
lines changed

NOTICE.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ This product includes software developed by the following individuals:
77
- Patrick MacAlpine
88
- Philipp Strobel
99
- Jannik Seiler
10+
- Hannes Braun

viewer/config.txt

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Graphics Settings:
1+
# Graphics Settings
22
Bloom : true
33
Phong : true
44
Shadows : true
@@ -19,26 +19,27 @@ Center Frame : true
1919
Frame Maximized : false
2020
Save Frame State : true
2121

22-
Overlay Default Visibility:
22+
# Overlay Default Visibility
2323
Server Speed : true
2424
Foul Overlay : true
2525
Field Overlay : true
2626
Number of Players : true
2727
Player IDs : true
2828

29-
Networking Settings:
29+
# Networking Settings
3030
Auto-Connect : true
3131
Auto-Connect Delay : 1000
32-
Server Hosts : localhost
33-
Server Port : 3200
32+
Default Server : localhost:3200
3433
Drawing Port : 32769
34+
# To store more servers, just insert more "Server" lines
35+
Server : localhost:3200
3536

36-
General Settings:
37+
# General Settings
3738
Record Logfiles : false
3839
Logfile Directory :
40+
# Possible values for "Look and Feel" are: "system", "darcula", "intellij", "solarized_light" and "solarized_dark"
3941
Look and Feel : system
4042

41-
Team Colors:
42-
<Right> : 0xff2626
43-
<Left> : 0x2626ff
44-
43+
# Team Colors
44+
Team Color : <Right>:0xff2626
45+
Team Color : <Left>:0x2626ff

viewer/src/main/java/config/GeneralPanel.java

+31
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import javax.swing.JLabel;
1111
import javax.swing.JPanel;
1212
import javax.swing.JTextField;
13+
import javax.swing.event.DocumentEvent;
14+
import javax.swing.event.DocumentListener;
1315
import rv.Configuration;
1416
import rv.util.swing.FileChooser;
1517
import rv.util.swing.SwingUtil;
@@ -23,12 +25,15 @@ public class GeneralPanel extends JPanel implements SaveListener
2325
JTextField logDirectoryTF;
2426
JButton openDirectoryButton;
2527

28+
private Runnable onChange;
29+
2630
public GeneralPanel(RVConfigure configProg)
2731
{
2832
super();
2933
this.configProg = configProg;
3034
this.config = configProg.config.general;
3135
configProg.listeners.add(this);
36+
onChange = configProg.updateSaveButtonState;
3237
initGUI();
3338
}
3439

@@ -53,7 +58,33 @@ JPanel initLogfilesPanel()
5358
c.ipadx = 10;
5459

5560
recordLogsCB = new JCheckBox("Record Logfiles", config.recordLogs);
61+
recordLogsCB.addChangeListener(e -> {
62+
config.recordLogs = recordLogsCB.isSelected();
63+
onChange.run();
64+
});
5665
logDirectoryTF = new JTextField(config.logfileDirectory);
66+
logDirectoryTF.getDocument().addDocumentListener(new DocumentListener() {
67+
@Override
68+
public void insertUpdate(DocumentEvent e)
69+
{
70+
config.logfileDirectory = logDirectoryTF.getText();
71+
onChange.run();
72+
}
73+
74+
@Override
75+
public void removeUpdate(DocumentEvent e)
76+
{
77+
config.logfileDirectory = logDirectoryTF.getText();
78+
onChange.run();
79+
}
80+
81+
@Override
82+
public void changedUpdate(DocumentEvent e)
83+
{
84+
config.logfileDirectory = logDirectoryTF.getText();
85+
onChange.run();
86+
}
87+
});
5788
SwingUtil.setPreferredWidth(logDirectoryTF, 150);
5889
openDirectoryButton = new JButton("...");
5990
openDirectoryButton.addActionListener(e -> {

viewer/src/main/java/config/GraphicsPanel.java

+146-17
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import javax.swing.JLabel;
2727
import javax.swing.JPanel;
2828
import javax.swing.JSpinner;
29-
import javax.swing.JTextField;
3029
import javax.swing.SpinnerNumberModel;
3130
import javax.swing.SwingConstants;
31+
import javax.swing.event.DocumentEvent;
32+
import javax.swing.event.DocumentListener;
3233
import rv.Configuration;
3334
import rv.util.swing.SwingUtil;
3435

@@ -46,8 +47,8 @@ public class GraphicsPanel extends JPanel implements SaveListener
4647
JCheckBox maximizedCB;
4748
JCheckBox centerCB;
4849
JCheckBox saveStateCB;
49-
JTextField samplesTF;
50-
JTextField shadowResTB;
50+
IntegerTextField samplesTF;
51+
IntegerTextField shadowResTB;
5152
JSpinner fpsSpinner;
5253
JSpinner fpFovSpinner;
5354
JSpinner tpFovSpinner;
@@ -58,11 +59,14 @@ public class GraphicsPanel extends JPanel implements SaveListener
5859
final JLabel shadowResLabel = new JLabel("Shadow Resolution: ", SwingConstants.RIGHT);
5960
final JLabel samplesLabel = new JLabel("Samples: ", SwingConstants.RIGHT);
6061

62+
private Runnable onChange;
63+
6164
public GraphicsPanel(RVConfigure configProg)
6265
{
6366
config = configProg.config.graphics;
6467
initGUI();
6568
configProg.listeners.add(this);
69+
onChange = configProg.updateSaveButtonState;
6670
}
6771

6872
void initGUI()
@@ -106,8 +110,34 @@ JPanel initAAPanel()
106110
c.ipadx = 10;
107111

108112
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+
});
110118
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+
});
111141
updateAAEnabled();
112142

113143
addConstrained(fsaaCB, panel, c, 0, 0);
@@ -133,10 +163,30 @@ JPanel initGeneral()
133163
c.ipadx = 10;
134164

135165
stereoCB = new JCheckBox("Stereo 3D", config.useStereo);
166+
stereoCB.addChangeListener(e -> {
167+
config.useStereo = stereoCB.isSelected();
168+
onChange.run();
169+
});
136170
vsyncCB = new JCheckBox("V-Sync", config.useVsync);
171+
vsyncCB.addChangeListener(e -> {
172+
config.useVsync = vsyncCB.isSelected();
173+
onChange.run();
174+
});
137175
fpsSpinner = createSpinner(config.targetFPS, 1, 60);
176+
fpsSpinner.addChangeListener(e -> {
177+
config.targetFPS = (Integer) fpsSpinner.getValue();
178+
onChange.run();
179+
});
138180
fpFovSpinner = createSpinner(config.firstPersonFOV, 1, 300);
181+
fpFovSpinner.addChangeListener(e -> {
182+
config.firstPersonFOV = (Integer) fpFovSpinner.getValue();
183+
onChange.run();
184+
});
139185
tpFovSpinner = createSpinner(config.thirdPersonFOV, 1, 300);
186+
tpFovSpinner.addChangeListener(e -> {
187+
config.thirdPersonFOV = (Integer) tpFovSpinner.getValue();
188+
onChange.run();
189+
});
140190

141191
int y = 0;
142192
addConstrained(stereoCB, panel, c, 0, y);
@@ -171,14 +221,42 @@ JPanel initFramePanel()
171221
c.ipadx = 10;
172222

173223
fxSpinner = createSpinner(config.frameX, -100, 10000);
224+
fxSpinner.addChangeListener(e -> {
225+
config.frameX = (Integer) fxSpinner.getValue();
226+
onChange.run();
227+
});
174228
fySpinner = createSpinner(config.frameY, -100, 10000);
229+
fySpinner.addChangeListener(e -> {
230+
config.frameY = (Integer) fySpinner.getValue();
231+
onChange.run();
232+
});
175233
fwSpinner = createSpinner(config.frameWidth, 1, 10000);
234+
fwSpinner.addChangeListener(e -> {
235+
config.frameWidth = (Integer) fwSpinner.getValue();
236+
onChange.run();
237+
});
176238
fhSpinner = createSpinner(config.frameHeight, 1, 10000);
239+
fhSpinner.addChangeListener(e -> {
240+
config.frameHeight = (Integer) fhSpinner.getValue();
241+
onChange.run();
242+
});
177243
maximizedCB = new JCheckBox("Maximized", config.isMaximized);
244+
maximizedCB.addChangeListener(e -> {
245+
config.isMaximized = maximizedCB.isSelected();
246+
onChange.run();
247+
});
178248
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+
});
180254
updateFramePositionEnabled();
181255
saveStateCB = new JCheckBox("Save Frame State", config.saveFrameState);
256+
saveStateCB.addChangeListener(e -> {
257+
config.saveFrameState = saveStateCB.isSelected();
258+
onChange.run();
259+
});
182260

183261
int y = 0;
184262
addLabel("X: ", panel, c, 0, y);
@@ -224,12 +302,50 @@ JPanel initLightingPanel()
224302
c.ipadx = 10;
225303

226304
bloomCB = new JCheckBox("Bloom", config.useBloom);
305+
bloomCB.addChangeListener(e -> {
306+
config.useBloom = bloomCB.isSelected();
307+
onChange.run();
308+
});
227309
phongCB = new JCheckBox("Phong", config.usePhong);
310+
phongCB.addChangeListener(e -> {
311+
config.usePhong = phongCB.isSelected();
312+
onChange.run();
313+
});
228314
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+
});
230320

231321
softShadowCB = new JCheckBox("Soft Shadows", config.useSoftShadows);
322+
softShadowCB.addChangeListener(e -> {
323+
config.useSoftShadows = softShadowCB.isSelected();
324+
onChange.run();
325+
});
232326
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+
});
233349
updateShadowsEnabled();
234350

235351
addConstrained(phongCB, panel, c, 0, 0);
@@ -250,6 +366,28 @@ void updateShadowsEnabled()
250366
shadowResLabel.setEnabled(shadowCB.isSelected());
251367
}
252368

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+
253391
@Override
254392
public void configSaved(RVConfigure configProg)
255393
{
@@ -261,17 +399,8 @@ public void configSaved(RVConfigure configProg)
261399
config.useStereo = stereoCB.isSelected();
262400
config.useVsync = vsyncCB.isSelected();
263401

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);
275404

276405
config.targetFPS = (Integer) fpsSpinner.getValue();
277406
config.firstPersonFOV = (Integer) fpFovSpinner.getValue();
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
package config;
22

33
import java.text.NumberFormat;
4+
import java.text.ParseException;
45
import javax.swing.JFormattedTextField;
56
import javax.swing.text.NumberFormatter;
67

78
public class IntegerTextField extends JFormattedTextField
89
{
910
public IntegerTextField(int value, int minValue, int maxValue)
1011
{
11-
super(value);
12-
NumberFormat format = NumberFormat.getInstance();
13-
NumberFormatter formatter = new NumberFormatter(format);
12+
super(new NumberFormatter(NumberFormat.getNumberInstance()));
13+
setValue(value);
14+
NumberFormatter formatter = (NumberFormatter) getFormatter();
1415
formatter.setValueClass(Integer.class);
1516
formatter.setMinimum(minValue);
1617
formatter.setMaximum(maxValue);
1718
formatter.setAllowsInvalid(false);
18-
setFormatter(formatter);
19+
}
20+
21+
public int getInt() throws ParseException
22+
{
23+
return NumberFormat.getInstance().parse(getText()).intValue();
1924
}
2025
}

0 commit comments

Comments
 (0)