Skip to content

Commit

Permalink
Merge pull request #9 from ComplexRalex/update/changes
Browse files Browse the repository at this point in the history
Web browser stuff changed, and confirm dialogs added
  • Loading branch information
ComplexRalex authored Jan 12, 2022
2 parents 71e2a77 + af2a2e5 commit 133aa31
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 86 deletions.
61 changes: 51 additions & 10 deletions src/controller/ConfigurationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public class ConfigurationController implements ActionListener, KeyListener{
*/
private int autoBackupStatus;

/**
* Temporal number which determines the current status
* of the "confirm backup" switch option.
*/
private int confirmBackupStatus;

/**
* Temporal number which determines the current status
* of the "confirm export" switch option.
*/
private int confirmExportStatus;

/**
* Temporal number which determines the current status
* of the "exit dialog" switch option.
Expand Down Expand Up @@ -114,6 +126,12 @@ public void initialize(){
view.btAutoBackupON.addActionListener(this);
view.btAutoBackupOFF.addActionListener(this);

view.btConfirmBackupON.addActionListener(this);
view.btConfirmBackupOFF.addActionListener(this);

view.btConfirmExportON.addActionListener(this);
view.btConfirmExportOFF.addActionListener(this);

view.btExitDialogON.addActionListener(this);
view.btExitDialogOFF.addActionListener(this);

Expand Down Expand Up @@ -157,6 +175,26 @@ public void obtainInitialConfig(){
Component.toggleEnabledButton(view.btAutoBackupOFF, false, Colour.colorOFF);
autoBackupStatus = 0;
}

if(model.getConfirmBackupDialog()){
Component.toggleEnabledButton(view.btConfirmBackupON, false, Colour.colorON);
Component.toggleEnabledButton(view.btConfirmBackupOFF, true, Colour.getButtonColor());
confirmBackupStatus = 1;
}else{
Component.toggleEnabledButton(view.btConfirmBackupON, true, Colour.getButtonColor());
Component.toggleEnabledButton(view.btConfirmBackupOFF, false, Colour.colorOFF);
confirmBackupStatus = 0;
}

if(model.getConfirmExportDialog()){
Component.toggleEnabledButton(view.btConfirmExportON, false, Colour.colorON);
Component.toggleEnabledButton(view.btConfirmExportOFF, true, Colour.getButtonColor());
confirmExportStatus = 1;
}else{
Component.toggleEnabledButton(view.btConfirmExportON, true, Colour.getButtonColor());
Component.toggleEnabledButton(view.btConfirmExportOFF, false, Colour.colorOFF);
confirmExportStatus = 0;
}

if(model.getExitDialog()){
Component.toggleEnabledButton(view.btExitDialogON, false, Colour.colorON);
Expand Down Expand Up @@ -188,6 +226,8 @@ private boolean sameValues(){
boolean flag = true;
flag = (flag && model.getUsername().equals(view.txtUser.getText().trim()));
flag = (flag && (model.getAutoBackup() == (autoBackupStatus == 1)));
flag = (flag && (model.getConfirmBackupDialog() == (confirmBackupStatus == 1)));
flag = (flag && (model.getConfirmExportDialog() == (confirmExportStatus == 1)));
flag = (flag && (model.getExitDialog() == (exitDialogStatus == 1)));
flag = (flag && model.getConnectionTimeout() == (int)view.spConnect.getValue());
flag = (flag && model.getReadTimeout() == (int)view.spRead.getValue());
Expand Down Expand Up @@ -234,16 +274,16 @@ private void saveCurrentSettings(){
}

// Toggle enable/disable autoBackup option
switch(autoBackupStatus){
case 1: model.enableAutoBackup(true); break;
case 0: model.enableAutoBackup(false);
}
model.enableAutoBackup(autoBackupStatus == 1);

// Toggle enable/disable confirmBackup option
model.enableConfirmBackupDialog(confirmBackupStatus == 1);

// Toggle enable/disable confirmExport option
model.enableConfirmExportDialog(confirmExportStatus == 1);

// Toggle enable/disable exitDialog option
switch(exitDialogStatus){
case 1: model.enableExitDialog(true); break;
case 0: model.enableExitDialog(false);
}
model.enableExitDialog(exitDialogStatus == 1);

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

autoBackupStatus = ((value = Component.runSwitchButtonEffect(e, view.btAutoBackupON, view.btAutoBackupOFF)) != -1) ? value : autoBackupStatus;

exitDialogStatus = ((value = Component.runSwitchButtonEffect(e, view.btExitDialogON, view.btExitDialogOFF)) != -1) ? value : exitDialogStatus;
confirmBackupStatus = ((value = Component.runSwitchButtonEffect(e, view.btConfirmBackupON, view.btConfirmBackupOFF)) != -1) ? value : confirmBackupStatus;
confirmExportStatus = ((value = Component.runSwitchButtonEffect(e, view.btConfirmExportON, view.btConfirmExportOFF)) != -1) ? value : confirmExportStatus;
exitDialogStatus = ((value = Component.runSwitchButtonEffect(e, view.btExitDialogON, view.btExitDialogOFF)) != -1) ? value : exitDialogStatus;

if(source == view.btSuddenClose)
parent.suddenClose();
Expand Down
103 changes: 67 additions & 36 deletions src/controller/GeneralController.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,53 +316,84 @@ public void updateName(GameStat gs){

@Override
public void actionPerformed(ActionEvent e) {
boolean yes;
if(e.getSource() == view.btAdd){
parent.frame.setBusy(true);
parent.cEditGame.setInitialValues(null);
parent.frame.changePanel(parent.frame.pEditGame,parent.frame.pEditGame.scrollBar,0);
}else if(e.getSource() == view.btBackup){
try {
Advice.showTextAreaAdvice(
yes = true;
if(parent.mConfig.getConfirmBackupDialog()){
yes = Advice.showOptionAdvice(
parent.frame,
Language.loadMessage("g_success"),
Language.loadMessage("m_backedup"),
"Name of the backup file: "+parent.mGeneral.doBackup(), 40, 2,
Language.loadMessage("g_accept"),
Colour.getPrimaryColor()
);
} catch (IOException e1) {
String error = Log.getDetails(e1);
Log.toFile(error, Log.ERROR);
Advice.showTextAreaAdvice(
parent.frame,
Language.loadMessage("g_oops"),
Language.loadMessage("g_went_wrong")+": ",
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
Language.loadMessage("g_accept"),
Language.loadMessage("g_message"),
Language.loadMessage("m_confirm_backup"),
new String[]{
Language.loadMessage("g_accept"),
Language.loadMessage("g_cancel")
},
Colour.getPrimaryColor()
);
) == 0;
}
if(yes){
try {
Advice.showTextAreaAdvice(
parent.frame,
Language.loadMessage("g_success"),
Language.loadMessage("m_backedup"),
"Name of the backup file: "+parent.mGeneral.doBackup(), 40, 2,
Language.loadMessage("g_accept"),
Colour.getPrimaryColor()
);
} catch (IOException e1) {
String error = Log.getDetails(e1);
Log.toFile(error, Log.ERROR);
Advice.showTextAreaAdvice(
parent.frame,
Language.loadMessage("g_oops"),
Language.loadMessage("g_went_wrong")+": ",
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
Language.loadMessage("g_accept"),
Colour.getPrimaryColor()
);
}
}
}else if(e.getSource() == view.btExport){
try {
Advice.showTextAreaAdvice(
yes = true;
if(parent.mConfig.getConfirmExportDialog()){
yes = Advice.showOptionAdvice(
parent.frame,
Language.loadMessage("g_success"),
Language.loadMessage("m_exported"),
"Name of the exported file: "+parent.mGeneral.exportStats(), 40, 2,
Language.loadMessage("g_accept"),
Colour.getPrimaryColor()
);
} catch (IOException e1) {
String error = Log.getDetails(e1);
Log.toFile(error, Log.ERROR);
Advice.showTextAreaAdvice(
parent.frame,
Language.loadMessage("g_oops"),
Language.loadMessage("g_went_wrong")+": ",
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
Language.loadMessage("g_accept"),
Language.loadMessage("g_message"),
Language.loadMessage("m_confirm_export"),
new String[]{
Language.loadMessage("g_accept"),
Language.loadMessage("g_cancel")
},
Colour.getPrimaryColor()
);
) == 0;
}
if(yes){
try {
Advice.showTextAreaAdvice(
parent.frame,
Language.loadMessage("g_success"),
Language.loadMessage("m_exported"),
"Name of the exported file: "+parent.mGeneral.exportStats(), 40, 2,
Language.loadMessage("g_accept"),
Colour.getPrimaryColor()
);
} catch (IOException e1) {
String error = Log.getDetails(e1);
Log.toFile(error, Log.ERROR);
Advice.showTextAreaAdvice(
parent.frame,
Language.loadMessage("g_oops"),
Language.loadMessage("g_went_wrong")+": ",
error, Advice.EXCEPTION_WIDTH, Advice.EXCEPTION_HEIGHT,
Language.loadMessage("g_accept"),
Colour.getPrimaryColor()
);
}
}
}else if(e.getSource() == view.btHelp){
parent.frame.changePanel(parent.frame.pHelp,parent.frame.pHelp.scrollBar,0);
Expand Down
92 changes: 84 additions & 8 deletions src/model/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ public class Configuration{
*/
private boolean autoBackup;


/**
* Boolean which determines if the confirm backup dialog
* is enabled (true) or not (false).
*
* @see #getConfirmBackupDialog()
* @see #enableConfirmBackupDialog()
*/
private boolean confirmBackup;


/**
* Boolean which determines if the confirm export dialog
* is enabled (true) or not (false).
*
* @see #getConfirmExportDialog()
* @see #enableConfirmExportDialog()
*/
private boolean confirmExport;

/**
* Boolean which determines if the exit dialog is enabled
* (true) or not (false).
Expand Down Expand Up @@ -137,6 +157,8 @@ public Configuration(){
* <ul>
* <li>{@link #username} = "Username"
* <li>{@link #autoBackup} = false
* <li>{@link #confirmBackup} = true
* <li>{@link #confirmExport} = true
* <li>{@link #exitDialog} = true
* <li>{@link #theme} = {@link Colour#NIGHT_THEME}
* <li>{@link #lang} = {@link Language#available}[0] (English)
Expand All @@ -151,6 +173,8 @@ public void setDefaultValues(){
username = "Username";
autoBackup = false;
exitDialog = true;
confirmBackup = true;
confirmExport = true;
theme = Colour.NIGHT_THEME;
lang = Language.available[0];
connectionTimeout = 5000;
Expand All @@ -173,8 +197,10 @@ private HashMap<String,Object> createHashMap(){
HashMap<String,Object> hashMap = new HashMap<>();

hashMap.put("username",username);
hashMap.put("exitDialog",exitDialog);
hashMap.put("autoBackup",autoBackup);
hashMap.put("confirmBackup",confirmBackup);
hashMap.put("confirmExport",confirmExport);
hashMap.put("exitDialog",exitDialog);
hashMap.put("theme",theme);
hashMap.put("lang",lang);
hashMap.put("connectionTimeout",connectionTimeout);
Expand All @@ -196,13 +222,24 @@ private HashMap<String,Object> createHashMap(){
* @see #createHashMap()
*/
private void copyConfigData(HashMap<String,Object> hashMap){
username = (String)hashMap.get("username");
exitDialog = (boolean)hashMap.get("exitDialog");
autoBackup = (boolean)hashMap.get("autoBackup");
theme = (int)hashMap.get("theme");
lang = (String)hashMap.get("lang");
connectionTimeout = (int)hashMap.get("connectionTimeout");
readTimeout = (int)hashMap.get("readTimeout");
if(hashMap.containsKey("username") && hashMap.get("username") != null)
username = (String)hashMap.get("username");
if(hashMap.containsKey("autoBackup") && hashMap.get("autoBackup") != null)
autoBackup = (boolean)hashMap.get("autoBackup");
if(hashMap.containsKey("confirmBackup") && hashMap.get("confirmBackup") != null)
confirmBackup = (boolean)hashMap.get("confirmBackup");
if(hashMap.containsKey("confirmExport") && hashMap.get("confirmExport") != null)
confirmExport = (boolean)hashMap.get("confirmExport");
if(hashMap.containsKey("exitDialog") && hashMap.get("exitDialog") != null)
exitDialog = (boolean)hashMap.get("exitDialog");
if(hashMap.containsKey("theme") && hashMap.get("theme") != null)
theme = (int)hashMap.get("theme");
if(hashMap.containsKey("lang") && hashMap.get("lang") != null)
lang = (String)hashMap.get("lang");
if(hashMap.containsKey("connectionTimeout") && hashMap.get("connectionTimeout") != null)
connectionTimeout = (int)hashMap.get("connectionTimeout");
if(hashMap.containsKey("readTimeout") && hashMap.get("readTimeout") != null)
readTimeout = (int)hashMap.get("readTimeout");
}

/**
Expand Down Expand Up @@ -278,6 +315,45 @@ public boolean getAutoBackup(){
public void enableAutoBackup(boolean flag){
autoBackup = flag;
}

/**
* Returns if the confirm backup dialog is enabled (true) or
* not (false).
*
* @return {@link #confirmBackup}'s value
*/
public boolean getConfirmBackupDialog(){
return confirmBackup;
}

/**
* Sets if the confirm backup dialog will be enabled.
*
* @param flag New {@link #confirmBackup}'s value
*/
public void enableConfirmBackupDialog(boolean flag){
confirmBackup = flag;
}

/**
* Returns if the confirm export dialog is enabled (true) or
* not (false).
*
* @return {@link #confirmExport}'s value
*/
public boolean getConfirmExportDialog(){
return confirmExport;
}


/**
* Sets if the confirm export dialog will be enabled.
*
* @param flag New {@link #confirmExport}'s value
*/
public void enableConfirmExportDialog(boolean flag){
confirmExport = flag;
}

/**
* Returns if the exit dialog is enabled (true) or not (false).
Expand Down
2 changes: 1 addition & 1 deletion src/system/Software.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Software{
/**
* Current version of the project.
*/
public static final String VERSION = "1.1.2";
public static final String VERSION = "1.1.3";

/**
* RAWG API key.
Expand Down
6 changes: 3 additions & 3 deletions src/util/Colour.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public class Colour{
private static final Color[][] THEME_COLORS = {
{ // Light Colors
new Color(10,10,10), // Font Color
new Color(250,250,250), // (Maybe) Background Color
new Color(230,230,230), // Button Color
new Color(220,220,220) // Background Color
new Color(218,218,218), // (Maybe) Background Color
new Color(225,225,225), // Button Color
new Color(230,230,230) // Background Color
},
{ // Dark Colors
new Color(230,230,230),
Expand Down
Loading

0 comments on commit 133aa31

Please sign in to comment.