Skip to content

Commit 133aa31

Browse files
authored
Merge pull request #9 from ComplexRalex/update/changes
Web browser stuff changed, and confirm dialogs added
2 parents 71e2a77 + af2a2e5 commit 133aa31

9 files changed

+267
-86
lines changed

src/controller/ConfigurationController.java

+51-10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ public class ConfigurationController implements ActionListener, KeyListener{
7575
*/
7676
private int autoBackupStatus;
7777

78+
/**
79+
* Temporal number which determines the current status
80+
* of the "confirm backup" switch option.
81+
*/
82+
private int confirmBackupStatus;
83+
84+
/**
85+
* Temporal number which determines the current status
86+
* of the "confirm export" switch option.
87+
*/
88+
private int confirmExportStatus;
89+
7890
/**
7991
* Temporal number which determines the current status
8092
* of the "exit dialog" switch option.
@@ -114,6 +126,12 @@ public void initialize(){
114126
view.btAutoBackupON.addActionListener(this);
115127
view.btAutoBackupOFF.addActionListener(this);
116128

129+
view.btConfirmBackupON.addActionListener(this);
130+
view.btConfirmBackupOFF.addActionListener(this);
131+
132+
view.btConfirmExportON.addActionListener(this);
133+
view.btConfirmExportOFF.addActionListener(this);
134+
117135
view.btExitDialogON.addActionListener(this);
118136
view.btExitDialogOFF.addActionListener(this);
119137

@@ -157,6 +175,26 @@ public void obtainInitialConfig(){
157175
Component.toggleEnabledButton(view.btAutoBackupOFF, false, Colour.colorOFF);
158176
autoBackupStatus = 0;
159177
}
178+
179+
if(model.getConfirmBackupDialog()){
180+
Component.toggleEnabledButton(view.btConfirmBackupON, false, Colour.colorON);
181+
Component.toggleEnabledButton(view.btConfirmBackupOFF, true, Colour.getButtonColor());
182+
confirmBackupStatus = 1;
183+
}else{
184+
Component.toggleEnabledButton(view.btConfirmBackupON, true, Colour.getButtonColor());
185+
Component.toggleEnabledButton(view.btConfirmBackupOFF, false, Colour.colorOFF);
186+
confirmBackupStatus = 0;
187+
}
188+
189+
if(model.getConfirmExportDialog()){
190+
Component.toggleEnabledButton(view.btConfirmExportON, false, Colour.colorON);
191+
Component.toggleEnabledButton(view.btConfirmExportOFF, true, Colour.getButtonColor());
192+
confirmExportStatus = 1;
193+
}else{
194+
Component.toggleEnabledButton(view.btConfirmExportON, true, Colour.getButtonColor());
195+
Component.toggleEnabledButton(view.btConfirmExportOFF, false, Colour.colorOFF);
196+
confirmExportStatus = 0;
197+
}
160198

161199
if(model.getExitDialog()){
162200
Component.toggleEnabledButton(view.btExitDialogON, false, Colour.colorON);
@@ -188,6 +226,8 @@ private boolean sameValues(){
188226
boolean flag = true;
189227
flag = (flag && model.getUsername().equals(view.txtUser.getText().trim()));
190228
flag = (flag && (model.getAutoBackup() == (autoBackupStatus == 1)));
229+
flag = (flag && (model.getConfirmBackupDialog() == (confirmBackupStatus == 1)));
230+
flag = (flag && (model.getConfirmExportDialog() == (confirmExportStatus == 1)));
191231
flag = (flag && (model.getExitDialog() == (exitDialogStatus == 1)));
192232
flag = (flag && model.getConnectionTimeout() == (int)view.spConnect.getValue());
193233
flag = (flag && model.getReadTimeout() == (int)view.spRead.getValue());
@@ -234,16 +274,16 @@ private void saveCurrentSettings(){
234274
}
235275

236276
// Toggle enable/disable autoBackup option
237-
switch(autoBackupStatus){
238-
case 1: model.enableAutoBackup(true); break;
239-
case 0: model.enableAutoBackup(false);
240-
}
277+
model.enableAutoBackup(autoBackupStatus == 1);
278+
279+
// Toggle enable/disable confirmBackup option
280+
model.enableConfirmBackupDialog(confirmBackupStatus == 1);
281+
282+
// Toggle enable/disable confirmExport option
283+
model.enableConfirmExportDialog(confirmExportStatus == 1);
241284

242285
// Toggle enable/disable exitDialog option
243-
switch(exitDialogStatus){
244-
case 1: model.enableExitDialog(true); break;
245-
case 0: model.enableExitDialog(false);
246-
}
286+
model.enableExitDialog(exitDialogStatus == 1);
247287

248288
// Change to selected theme
249289
for(int i = 0; i < view.btTheme.length; i++){
@@ -292,8 +332,9 @@ public void actionPerformed(ActionEvent e) {
292332
int value;
293333

294334
autoBackupStatus = ((value = Component.runSwitchButtonEffect(e, view.btAutoBackupON, view.btAutoBackupOFF)) != -1) ? value : autoBackupStatus;
295-
296-
exitDialogStatus = ((value = Component.runSwitchButtonEffect(e, view.btExitDialogON, view.btExitDialogOFF)) != -1) ? value : exitDialogStatus;
335+
confirmBackupStatus = ((value = Component.runSwitchButtonEffect(e, view.btConfirmBackupON, view.btConfirmBackupOFF)) != -1) ? value : confirmBackupStatus;
336+
confirmExportStatus = ((value = Component.runSwitchButtonEffect(e, view.btConfirmExportON, view.btConfirmExportOFF)) != -1) ? value : confirmExportStatus;
337+
exitDialogStatus = ((value = Component.runSwitchButtonEffect(e, view.btExitDialogON, view.btExitDialogOFF)) != -1) ? value : exitDialogStatus;
297338

298339
if(source == view.btSuddenClose)
299340
parent.suddenClose();

src/controller/GeneralController.java

+67-36
Original file line numberDiff line numberDiff line change
@@ -316,53 +316,84 @@ public void updateName(GameStat gs){
316316

317317
@Override
318318
public void actionPerformed(ActionEvent e) {
319+
boolean yes;
319320
if(e.getSource() == view.btAdd){
320321
parent.frame.setBusy(true);
321322
parent.cEditGame.setInitialValues(null);
322323
parent.frame.changePanel(parent.frame.pEditGame,parent.frame.pEditGame.scrollBar,0);
323324
}else if(e.getSource() == view.btBackup){
324-
try {
325-
Advice.showTextAreaAdvice(
325+
yes = true;
326+
if(parent.mConfig.getConfirmBackupDialog()){
327+
yes = Advice.showOptionAdvice(
326328
parent.frame,
327-
Language.loadMessage("g_success"),
328-
Language.loadMessage("m_backedup"),
329-
"Name of the backup file: "+parent.mGeneral.doBackup(), 40, 2,
330-
Language.loadMessage("g_accept"),
331-
Colour.getPrimaryColor()
332-
);
333-
} catch (IOException e1) {
334-
String error = Log.getDetails(e1);
335-
Log.toFile(error, Log.ERROR);
336-
Advice.showTextAreaAdvice(
337-
parent.frame,
338-
Language.loadMessage("g_oops"),
339-
Language.loadMessage("g_went_wrong")+": ",
340-
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
341-
Language.loadMessage("g_accept"),
329+
Language.loadMessage("g_message"),
330+
Language.loadMessage("m_confirm_backup"),
331+
new String[]{
332+
Language.loadMessage("g_accept"),
333+
Language.loadMessage("g_cancel")
334+
},
342335
Colour.getPrimaryColor()
343-
);
336+
) == 0;
337+
}
338+
if(yes){
339+
try {
340+
Advice.showTextAreaAdvice(
341+
parent.frame,
342+
Language.loadMessage("g_success"),
343+
Language.loadMessage("m_backedup"),
344+
"Name of the backup file: "+parent.mGeneral.doBackup(), 40, 2,
345+
Language.loadMessage("g_accept"),
346+
Colour.getPrimaryColor()
347+
);
348+
} catch (IOException e1) {
349+
String error = Log.getDetails(e1);
350+
Log.toFile(error, Log.ERROR);
351+
Advice.showTextAreaAdvice(
352+
parent.frame,
353+
Language.loadMessage("g_oops"),
354+
Language.loadMessage("g_went_wrong")+": ",
355+
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
356+
Language.loadMessage("g_accept"),
357+
Colour.getPrimaryColor()
358+
);
359+
}
344360
}
345361
}else if(e.getSource() == view.btExport){
346-
try {
347-
Advice.showTextAreaAdvice(
362+
yes = true;
363+
if(parent.mConfig.getConfirmExportDialog()){
364+
yes = Advice.showOptionAdvice(
348365
parent.frame,
349-
Language.loadMessage("g_success"),
350-
Language.loadMessage("m_exported"),
351-
"Name of the exported file: "+parent.mGeneral.exportStats(), 40, 2,
352-
Language.loadMessage("g_accept"),
353-
Colour.getPrimaryColor()
354-
);
355-
} catch (IOException e1) {
356-
String error = Log.getDetails(e1);
357-
Log.toFile(error, Log.ERROR);
358-
Advice.showTextAreaAdvice(
359-
parent.frame,
360-
Language.loadMessage("g_oops"),
361-
Language.loadMessage("g_went_wrong")+": ",
362-
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
363-
Language.loadMessage("g_accept"),
366+
Language.loadMessage("g_message"),
367+
Language.loadMessage("m_confirm_export"),
368+
new String[]{
369+
Language.loadMessage("g_accept"),
370+
Language.loadMessage("g_cancel")
371+
},
364372
Colour.getPrimaryColor()
365-
);
373+
) == 0;
374+
}
375+
if(yes){
376+
try {
377+
Advice.showTextAreaAdvice(
378+
parent.frame,
379+
Language.loadMessage("g_success"),
380+
Language.loadMessage("m_exported"),
381+
"Name of the exported file: "+parent.mGeneral.exportStats(), 40, 2,
382+
Language.loadMessage("g_accept"),
383+
Colour.getPrimaryColor()
384+
);
385+
} catch (IOException e1) {
386+
String error = Log.getDetails(e1);
387+
Log.toFile(error, Log.ERROR);
388+
Advice.showTextAreaAdvice(
389+
parent.frame,
390+
Language.loadMessage("g_oops"),
391+
Language.loadMessage("g_went_wrong")+": ",
392+
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
393+
Language.loadMessage("g_accept"),
394+
Colour.getPrimaryColor()
395+
);
396+
}
366397
}
367398
}else if(e.getSource() == view.btHelp){
368399
parent.frame.changePanel(parent.frame.pHelp,parent.frame.pHelp.scrollBar,0);

src/model/Configuration.java

+84-8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ public class Configuration{
7676
*/
7777
private boolean autoBackup;
7878

79+
80+
/**
81+
* Boolean which determines if the confirm backup dialog
82+
* is enabled (true) or not (false).
83+
*
84+
* @see #getConfirmBackupDialog()
85+
* @see #enableConfirmBackupDialog()
86+
*/
87+
private boolean confirmBackup;
88+
89+
90+
/**
91+
* Boolean which determines if the confirm export dialog
92+
* is enabled (true) or not (false).
93+
*
94+
* @see #getConfirmExportDialog()
95+
* @see #enableConfirmExportDialog()
96+
*/
97+
private boolean confirmExport;
98+
7999
/**
80100
* Boolean which determines if the exit dialog is enabled
81101
* (true) or not (false).
@@ -137,6 +157,8 @@ public Configuration(){
137157
* <ul>
138158
* <li>{@link #username} = "Username"
139159
* <li>{@link #autoBackup} = false
160+
* <li>{@link #confirmBackup} = true
161+
* <li>{@link #confirmExport} = true
140162
* <li>{@link #exitDialog} = true
141163
* <li>{@link #theme} = {@link Colour#NIGHT_THEME}
142164
* <li>{@link #lang} = {@link Language#available}[0] (English)
@@ -151,6 +173,8 @@ public void setDefaultValues(){
151173
username = "Username";
152174
autoBackup = false;
153175
exitDialog = true;
176+
confirmBackup = true;
177+
confirmExport = true;
154178
theme = Colour.NIGHT_THEME;
155179
lang = Language.available[0];
156180
connectionTimeout = 5000;
@@ -173,8 +197,10 @@ private HashMap<String,Object> createHashMap(){
173197
HashMap<String,Object> hashMap = new HashMap<>();
174198

175199
hashMap.put("username",username);
176-
hashMap.put("exitDialog",exitDialog);
177200
hashMap.put("autoBackup",autoBackup);
201+
hashMap.put("confirmBackup",confirmBackup);
202+
hashMap.put("confirmExport",confirmExport);
203+
hashMap.put("exitDialog",exitDialog);
178204
hashMap.put("theme",theme);
179205
hashMap.put("lang",lang);
180206
hashMap.put("connectionTimeout",connectionTimeout);
@@ -196,13 +222,24 @@ private HashMap<String,Object> createHashMap(){
196222
* @see #createHashMap()
197223
*/
198224
private void copyConfigData(HashMap<String,Object> hashMap){
199-
username = (String)hashMap.get("username");
200-
exitDialog = (boolean)hashMap.get("exitDialog");
201-
autoBackup = (boolean)hashMap.get("autoBackup");
202-
theme = (int)hashMap.get("theme");
203-
lang = (String)hashMap.get("lang");
204-
connectionTimeout = (int)hashMap.get("connectionTimeout");
205-
readTimeout = (int)hashMap.get("readTimeout");
225+
if(hashMap.containsKey("username") && hashMap.get("username") != null)
226+
username = (String)hashMap.get("username");
227+
if(hashMap.containsKey("autoBackup") && hashMap.get("autoBackup") != null)
228+
autoBackup = (boolean)hashMap.get("autoBackup");
229+
if(hashMap.containsKey("confirmBackup") && hashMap.get("confirmBackup") != null)
230+
confirmBackup = (boolean)hashMap.get("confirmBackup");
231+
if(hashMap.containsKey("confirmExport") && hashMap.get("confirmExport") != null)
232+
confirmExport = (boolean)hashMap.get("confirmExport");
233+
if(hashMap.containsKey("exitDialog") && hashMap.get("exitDialog") != null)
234+
exitDialog = (boolean)hashMap.get("exitDialog");
235+
if(hashMap.containsKey("theme") && hashMap.get("theme") != null)
236+
theme = (int)hashMap.get("theme");
237+
if(hashMap.containsKey("lang") && hashMap.get("lang") != null)
238+
lang = (String)hashMap.get("lang");
239+
if(hashMap.containsKey("connectionTimeout") && hashMap.get("connectionTimeout") != null)
240+
connectionTimeout = (int)hashMap.get("connectionTimeout");
241+
if(hashMap.containsKey("readTimeout") && hashMap.get("readTimeout") != null)
242+
readTimeout = (int)hashMap.get("readTimeout");
206243
}
207244

208245
/**
@@ -278,6 +315,45 @@ public boolean getAutoBackup(){
278315
public void enableAutoBackup(boolean flag){
279316
autoBackup = flag;
280317
}
318+
319+
/**
320+
* Returns if the confirm backup dialog is enabled (true) or
321+
* not (false).
322+
*
323+
* @return {@link #confirmBackup}'s value
324+
*/
325+
public boolean getConfirmBackupDialog(){
326+
return confirmBackup;
327+
}
328+
329+
/**
330+
* Sets if the confirm backup dialog will be enabled.
331+
*
332+
* @param flag New {@link #confirmBackup}'s value
333+
*/
334+
public void enableConfirmBackupDialog(boolean flag){
335+
confirmBackup = flag;
336+
}
337+
338+
/**
339+
* Returns if the confirm export dialog is enabled (true) or
340+
* not (false).
341+
*
342+
* @return {@link #confirmExport}'s value
343+
*/
344+
public boolean getConfirmExportDialog(){
345+
return confirmExport;
346+
}
347+
348+
349+
/**
350+
* Sets if the confirm export dialog will be enabled.
351+
*
352+
* @param flag New {@link #confirmExport}'s value
353+
*/
354+
public void enableConfirmExportDialog(boolean flag){
355+
confirmExport = flag;
356+
}
281357

282358
/**
283359
* Returns if the exit dialog is enabled (true) or not (false).

src/system/Software.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class Software{
4141
/**
4242
* Current version of the project.
4343
*/
44-
public static final String VERSION = "1.1.2";
44+
public static final String VERSION = "1.1.3";
4545

4646
/**
4747
* RAWG API key.

src/util/Colour.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public class Colour{
9898
private static final Color[][] THEME_COLORS = {
9999
{ // Light Colors
100100
new Color(10,10,10), // Font Color
101-
new Color(250,250,250), // (Maybe) Background Color
102-
new Color(230,230,230), // Button Color
103-
new Color(220,220,220) // Background Color
101+
new Color(218,218,218), // (Maybe) Background Color
102+
new Color(225,225,225), // Button Color
103+
new Color(230,230,230) // Background Color
104104
},
105105
{ // Dark Colors
106106
new Color(230,230,230),

0 commit comments

Comments
 (0)