Skip to content

Commit

Permalink
'#1341 Corrects autoCalcSpinner to accept "default" as an alternate
Browse files Browse the repository at this point in the history
string for "auto" as is used for parameter num threads for LocalConfig.
  • Loading branch information
patrickdalla committed Jul 1, 2024
1 parent b3ef5c9 commit 18711ab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
6 changes: 3 additions & 3 deletions iped-app/src/main/java/iped/app/home/config/ConfigPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void createFormComponentInstances() {
// Create JSpinner to change the number of Threads and a button to set the
// default thread value
spinnerThreads = new JSpinner();
spinnerThreads.setModel(new AutoCalcSpinnerModel(spinnerThreads));
spinnerThreads.setModel(new AutoCalcSpinnerModel(spinnerThreads, LocalConfig.DEFAULT_VAL));
((JSpinner.DefaultEditor) spinnerThreads.getEditor()).getTextField().setEditable(false);
buttonSetDefaultThread = getNewIconButton(ICON_SET_DEFAULT);
buttonSetDefaultThread.setToolTipText(Messages.get("Home.DefaultThreadValue"));
Expand Down Expand Up @@ -414,7 +414,7 @@ private void updateLocaleConfigComponentsState() {
private void updateLocalConfigComponentsState() {
defaultConfigurationManager.reloadConfigurable(LocalConfig.class);
LocalConfig localConfig = defaultConfigurationManager.findObject(LocalConfig.class);
spinnerThreads.setValue(localConfig.getNumThreads());
spinnerThreads.setValue(localConfig.getPropertie().getProperty(LocalConfig.NUM_THREADS));
textFieldIndexTemp.setText((localConfig.getPropertie().getProperty(LocalConfig.IPED_TEMP) == null) ? "Default" : localConfig.getPropertie().getProperty(LocalConfig.IPED_TEMP));
checkBoxIndexTempOnSSD.setSelected(localConfig.isIndexTempOnSSD());
File hashDbFile = localConfig.getHashDbFile();
Expand Down Expand Up @@ -470,7 +470,7 @@ private void saveConfiguration() {
// Set changes on LocalConfig Configurable class
localConfig.setIndexTempOnSSD(checkBoxIndexTempOnSSD.isSelected());
localConfig.getPropertie().setProperty(LocalConfig.IPED_TEMP, textFieldIndexTemp.getText());
localConfig.setNumThreads((Integer) spinnerThreads.getValue());
localConfig.setNumThreads(spinnerThreads.getValue());
localConfig.getPropertie().setProperty(LocalConfig.HASH_DB, textFieldHashesDB.getText());
localConfig.getPropertie().enableOrDisablePropertie(CasePathManager.getInstance().getLocalConfigFile(), LocalConfig.HASH_DB, !isEnableHashDB);
// Save LocalConfig modifications to file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public class AutoCalcSpinnerModel extends AbstractSpinnerModel {
ArrayList<ChangeListener> listeners = new ArrayList<ChangeListener>();
private boolean isInternalChage;

String autoString = "auto";

public AutoCalcSpinnerModel(JSpinner spinner, String autoString) {
this(spinner);
this.autoString = autoString;
}

public AutoCalcSpinnerModel(JSpinner spinner) {
this.spinner = spinner;
DefaultEditor c = new DefaultEditor(spinner);
Expand All @@ -38,7 +45,7 @@ public String valueToString(Object value) throws ParseException {
@Override
public Object stringToValue(String text) throws ParseException {
if (text.equals("0") || text.trim().equals("")) {
return "auto";
return autoString;
}
return text;
}
Expand All @@ -52,7 +59,7 @@ public Object stringToValue(String text) throws ParseException {
@Override
public Object getValue() {
if (value == 0) {
return "auto";
return autoString;
} else {
return value;
}
Expand All @@ -61,7 +68,7 @@ public Object getValue() {
@Override
public void setValue(Object value) {
boolean valid = true;
if (value.toString().equals("auto")) {
if (value.toString().equals(autoString)) {
this.value = 0;
} else {
if (value instanceof String) {
Expand Down
16 changes: 15 additions & 1 deletion iped-engine/src/main/java/iped/engine/config/LocalConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class LocalConfig extends AbstractPropertiesConfigurable {

public static final String OUTPUT_ON_SSD = "outputOnSSD";

private static final String DEFAULT_VAL = "default";
public static final String DEFAULT_VAL = "default";

public static final DirectoryStream.Filter<Path> filter = new Filter<Path>() {
@Override
Expand Down Expand Up @@ -166,6 +166,20 @@ public int getNumThreads() {
return numThreads;
}

public void setNumThreads(Object numThreads) {
if (numThreads instanceof Integer) {
setNumThreads(((Integer) numThreads).intValue());
return;
} else {
if (numThreads instanceof String) {
if (numThreads.equals(DEFAULT_VAL)) {
properties.setProperty(NUM_THREADS, DEFAULT_VAL);
return;
}
}
}
}

public void setNumThreads(int numThreads){
this.numThreads = numThreads;
String stringValue = (numThreads == Runtime.getRuntime().availableProcessors()) ? DEFAULT_VAL : String.valueOf(numThreads);
Expand Down

0 comments on commit 18711ab

Please sign in to comment.