UI type save on configuration file

This commit is contained in:
Laurent Clouet
2015-04-08 20:37:53 +01:00
parent 3226d188af
commit ca221ddc8b
4 changed files with 41 additions and 7 deletions

View File

@@ -52,6 +52,7 @@ public class Configuration {
public List<Pair<Calendar, Calendar>> requestTime;
private String extras;
private boolean autoSignIn;
private String UIType;
public Configuration(File cache_dir_, String login_, String password_) {
this.login = login_;
@@ -69,6 +70,7 @@ public class Configuration {
this.requestTime = null;
this.extras = "";
this.autoSignIn = false;
this.UIType = null;
}
public String toString() {
@@ -195,6 +197,14 @@ public class Configuration {
return this.autoSignIn;
}
public void setUIType(String ui) {
this.UIType = ui;
}
public String getUIType() {
return this.UIType;
}
public void cleanWorkingDirectory() {
this.cleanDirectory(this.workingDirectory);
this.cleanDirectory(this.storageDirectory);

View File

@@ -82,7 +82,7 @@ public class Worker {
private String extras = null;
@Option(name = "-ui", usage = "Specify the user interface to use, default 'swing', available 'oneline', 'text', 'swing' (graphical)", required = false)
private String ui_type = GuiSwing.type;
private String ui_type = null;
@Option(name = "-config", usage = "Specify the configuration file", required = false)
private String config_file = null;
@@ -261,6 +261,10 @@ public class Worker {
config.setComputeMethod(compute_method);
if (ui_type != null) {
config.setUIType(ui_type);
}
if (config_file != null) {
if (new File(config_file).exists() == false) {
System.err.println("Configuration file not found.");
@@ -273,7 +277,11 @@ public class Worker {
Log.getInstance(config).debug("client version " + config.getJarVersion());
Gui gui;
switch (ui_type) {
String type = config.getUIType();
if (type == null) {
type = "swing";
}
switch (type) {
case GuiTextOneLine.type:
if (config.getPrintLog()) {
System.out.println("OneLine UI can not be used if verbose mode is enabled");
@@ -281,6 +289,10 @@ public class Worker {
}
gui = new GuiTextOneLine();
break;
case GuiText.type:
gui = new GuiText();
break;
default:
case GuiSwing.type:
if (java.awt.GraphicsEnvironment.isHeadless()) {
System.out.println("Graphical ui can not be launch.");
@@ -289,9 +301,6 @@ public class Worker {
}
gui = new GuiSwing();
break;
default:
gui = new GuiText();
break;
}
Client cli = new Client(gui, config, server);
gui.setClient(cli);

View File

@@ -22,6 +22,7 @@ public class SettingsLoader {
private String gpu;
private String cacheDir;
private String autoSignIn;
private String ui;
public SettingsLoader() {
path = getDefaultFilePath();
@@ -31,12 +32,13 @@ public class SettingsLoader {
path = path_;
}
public SettingsLoader(String login_, String password_, ComputeType computeMethod_, GPUDevice gpu_, String cacheDir_, boolean autoSignIn_) {
public SettingsLoader(String login_, String password_, ComputeType computeMethod_, GPUDevice gpu_, String cacheDir_, boolean autoSignIn_, String ui_) {
path = getDefaultFilePath();
login = login_;
password = password_;
cacheDir = cacheDir_;
autoSignIn = String.valueOf(autoSignIn_);
ui = ui_;
if (computeMethod_ != null) {
try {
@@ -89,6 +91,10 @@ public class SettingsLoader {
prop.setProperty("auto-signin", autoSignIn);
}
if (ui != null) {
prop.setProperty("ui", ui);
}
prop.store(output, null);
}
catch (IOException io) {
@@ -113,6 +119,7 @@ public class SettingsLoader {
this.gpu = null;
this.cacheDir = null;
this.autoSignIn = null;
this.ui = null;
if (new File(path).exists() == false) {
return;
@@ -147,6 +154,10 @@ public class SettingsLoader {
if (prop.containsKey("auto-signin")) {
this.autoSignIn = prop.getProperty("auto-signin");
}
if (prop.containsKey("ui")) {
this.ui = prop.getProperty("ui");
}
}
catch (IOException io) {
io.printStackTrace();
@@ -200,6 +211,10 @@ public class SettingsLoader {
config.setCacheDir(new File(cacheDir));
}
if (config.getUIType() == null && ui != null) {
config.setUIType(ui);
}
config.setAutoSignIn(Boolean.valueOf(autoSignIn));
}

View File

@@ -303,7 +303,7 @@ public class Settings implements Activity {
}
if (saveFile.isSelected()) {
new SettingsLoader(login.getText(), new String(password.getPassword()), method, selected_gpu, cachePath, autoSignIn.isSelected()).saveFile();
new SettingsLoader(login.getText(), new String(password.getPassword()), method, selected_gpu, cachePath, autoSignIn.isSelected(), GuiSwing.type).saveFile();
}
else {
try {