Add ui for process priority

This commit is contained in:
Rolf Aretz Lap
2017-03-19 17:38:22 +01:00
committed by Laurent Clouet
parent e7354499ad
commit d4db1670a1
3 changed files with 41 additions and 4 deletions

View File

@@ -64,7 +64,7 @@ public class Configuration {
this.static_exeDirName = "exe"; this.static_exeDirName = "exe";
this.maxUploadingJob = 1; this.maxUploadingJob = 1;
this.nbCores = -1; // ie not set this.nbCores = -1; // ie not set
this.priority = 19; this.priority = 19; // default lowest
this.computeMethod = null; this.computeMethod = null;
this.GPUDevice = null; this.GPUDevice = null;
this.userSpecifiedACacheDir = false; this.userSpecifiedACacheDir = false;

View File

@@ -50,6 +50,7 @@ public class SettingsLoader {
private String autoSignIn; private String autoSignIn;
private String ui; private String ui;
private String tileSize; private String tileSize;
private int priority;
public SettingsLoader() { public SettingsLoader() {
path = getDefaultFilePath(); path = getDefaultFilePath();
@@ -59,7 +60,7 @@ public class SettingsLoader {
path = path_; path = path_;
} }
public SettingsLoader(String login_, String password_, String proxy_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, String cacheDir_, boolean autoSignIn_, String ui_, String tileSize_) { public SettingsLoader(String login_, String password_, String proxy_, ComputeType computeMethod_, GPUDevice gpu_, int cores_, String cacheDir_, boolean autoSignIn_, String ui_, String tileSize_, int priority_) {
path = getDefaultFilePath(); path = getDefaultFilePath();
login = login_; login = login_;
password = password_; password = password_;
@@ -68,6 +69,7 @@ public class SettingsLoader {
autoSignIn = String.valueOf(autoSignIn_); autoSignIn = String.valueOf(autoSignIn_);
ui = ui_; ui = ui_;
tileSize = tileSize_; tileSize = tileSize_;
priority = priority_;
if (cores_ > 0) { if (cores_ > 0) {
cores = String.valueOf(cores_); cores = String.valueOf(cores_);
} }
@@ -98,6 +100,7 @@ public class SettingsLoader {
OutputStream output = null; OutputStream output = null;
try { try {
output = new FileOutputStream(path); output = new FileOutputStream(path);
prop.setProperty("priority", new Integer(priority).toString());
if (cacheDir != null) { if (cacheDir != null) {
prop.setProperty("cache-dir", cacheDir); prop.setProperty("cache-dir", cacheDir);
@@ -181,6 +184,7 @@ public class SettingsLoader {
this.autoSignIn = null; this.autoSignIn = null;
this.ui = null; this.ui = null;
this.tileSize = null; this.tileSize = null;
this.priority = 19; // must be the same default as Configuration
if (new File(path).exists() == false) { if (new File(path).exists() == false) {
return; return;
@@ -231,6 +235,10 @@ public class SettingsLoader {
if (prop.containsKey("tile-size")) { if (prop.containsKey("tile-size")) {
this.tileSize = prop.getProperty("tile-size"); this.tileSize = prop.getProperty("tile-size");
} }
if (prop.containsKey("priority")) {
this.priority = Integer.parseInt(prop.getProperty("priority"));
}
} }
catch (IOException io) { catch (IOException io) {
io.printStackTrace(); io.printStackTrace();
@@ -269,6 +277,9 @@ public class SettingsLoader {
config.setProxy(proxy); config.setProxy(proxy);
} }
if (config.getPriority() == 19) { // 19 is default value
config.setUsePriority(priority);
}
try { try {
if ((config.getComputeMethod() == null && computeMethod != null) || (computeMethod != null && config.getComputeMethod() != ComputeType.valueOf(computeMethod))) { if ((config.getComputeMethod() == null && computeMethod != null) || (computeMethod != null && config.getComputeMethod() != ComputeType.valueOf(computeMethod))) {
config.setComputeMethod(ComputeType.valueOf(computeMethod)); config.setComputeMethod(ComputeType.valueOf(computeMethod));
@@ -304,6 +315,6 @@ public class SettingsLoader {
@Override @Override
public String toString() { public String toString() {
return "SettingsLoader [path=" + path + ", login=" + login + ", password=" + password + ", computeMethod=" + computeMethod + ", gpu=" + gpu + ", cacheDir=" + cacheDir + "]"; return "SettingsLoader [path=" + path + ", login=" + login + ", password=" + password + ", computeMethod=" + computeMethod + ", gpu=" + gpu + ", cacheDir=" + cacheDir + "priority="+priority+"]";
} }
} }

View File

@@ -66,6 +66,7 @@ public class Settings implements Activity {
private JCheckBox useCPU; private JCheckBox useCPU;
private List<JCheckBoxGPU> useGPUs; private List<JCheckBoxGPU> useGPUs;
private JSlider cpuCores; private JSlider cpuCores;
private JSlider priority;
private JTextField proxy; private JTextField proxy;
private JCheckBox saveFile; private JCheckBox saveFile;
@@ -238,6 +239,29 @@ public class Settings implements Activity {
compute_devices_panel.add(cpuCores); compute_devices_panel.add(cpuCores);
} }
// priority
priority = new JSlider(-19, 19);
priority.setMajorTickSpacing(5);
priority.setMinorTickSpacing(1);
priority.setPaintTicks(true);
priority.setPaintLabels(true);
priority.setValue(config.getPriority());
JLabel priorityLabel = new JLabel("Priority (High <-> Low):");
compute_devices_constraints.weightx = 1.0 / gpus.size();
compute_devices_constraints.gridx = 0;
compute_devices_constraints.gridy++;
gridbag.setConstraints(priorityLabel, compute_devices_constraints);
compute_devices_panel.add(priorityLabel);
compute_devices_constraints.gridx = 1;
compute_devices_constraints.weightx = 1.0;
gridbag.setConstraints(priority, compute_devices_constraints);
compute_devices_panel.add(priority);
currentRow++; currentRow++;
constraints.gridx = 0; constraints.gridx = 0;
constraints.gridy = currentRow; constraints.gridy = currentRow;
@@ -466,6 +490,8 @@ public class Settings implements Activity {
config.setUseNbCores(cpu_cores); config.setUseNbCores(cpu_cores);
} }
config.setUsePriority(priority.getValue());
String proxyText = null; String proxyText = null;
if (proxy != null) { if (proxy != null) {
try { try {
@@ -503,7 +529,7 @@ public class Settings implements Activity {
} }
if (saveFile.isSelected()) { if (saveFile.isSelected()) {
new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, method, selected_gpu, cpu_cores, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile).saveFile(); new SettingsLoader(login.getText(), new String(password.getPassword()), proxyText, method, selected_gpu, cpu_cores, cachePath, autoSignIn.isSelected(), GuiSwing.type, tile, priority.getValue()).saveFile();
} }
else { else {
try { try {