mirror of
https://github.com/paulscherrerinstitute/ch.psi.imagej.hdf5.git
synced 2025-04-20 05:00:03 +02:00
Cleanup HDF5Config
This commit is contained in:
parent
580c543a5d
commit
d5ed374538
7
pom.xml
7
pom.xml
@ -39,6 +39,13 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -12,30 +12,21 @@ public class HDF5Config implements PlugIn {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(HDF5Config.class.getName());
|
||||
|
||||
public static String GROUP_VARS_BY_NAME = "HDF5.groupVarsByName";
|
||||
public static String SHOW_UNMATCHED_DATASET_NAMES = "HDF5.showUnmatchedDataSetNames";
|
||||
public static String GROUP_VARS_BY_NAME_FORMAT_GROUP = "HDF5.groupVarsByNameFormatGroup";
|
||||
public static String GROUP_VARS_BY_NAME_FORMAT = "HDF5.groupVarsByNameFormat";
|
||||
public static String DOLLAR_REGEXP_FOR_GROUPING = "HDF5.dollarRegexpForGrouping";
|
||||
private static final String GROUP_VARS_BY_NAME = "HDF5.groupVarsByName";
|
||||
private static final String SHOW_UNMATCHED_DATASET_NAMES = "HDF5.showUnmatchedDataSetNames";
|
||||
private static final String GROUP_VARS_BY_NAME_FORMAT_GROUP = "HDF5.groupVarsByNameFormatGroup";
|
||||
private static final String GROUP_VARS_BY_NAME_FORMAT = "HDF5.groupVarsByNameFormat";
|
||||
private static final String DOLLAR_REGEXP_FOR_GROUPING = "HDF5.dollarRegexpForGrouping";
|
||||
|
||||
// Getting preference or default values
|
||||
private boolean groupVarsByName = Prefs.get(GROUP_VARS_BY_NAME, true);
|
||||
private boolean showUnmatchedDataSetNames = Prefs.get(SHOW_UNMATCHED_DATASET_NAMES, true);
|
||||
private String groupVarsByNameFormatGroup = Prefs.get(GROUP_VARS_BY_NAME_FORMAT_GROUP, "/hints");
|
||||
private String groupVarsByNameFormat = Prefs.get(GROUP_VARS_BY_NAME_FORMAT, "/t$T/channel$C");
|
||||
private String dollarRegexpForGrouping = Prefs.get(DOLLAR_REGEXP_FOR_GROUPING, "[0-9]+");
|
||||
|
||||
|
||||
public void run(String arg) {
|
||||
// set default values
|
||||
setDefaultsIfNoValueExists();
|
||||
// read ImageJ Preferences
|
||||
boolean groupVarsByName = Boolean.getBoolean(getDefaultValue(GROUP_VARS_BY_NAME));
|
||||
groupVarsByName = Prefs.get(GROUP_VARS_BY_NAME, groupVarsByName);
|
||||
|
||||
boolean showUnmatchedDataSetNames = Boolean.getBoolean(getDefaultValue(SHOW_UNMATCHED_DATASET_NAMES));
|
||||
showUnmatchedDataSetNames = Prefs.get(SHOW_UNMATCHED_DATASET_NAMES, showUnmatchedDataSetNames);
|
||||
|
||||
String groupVarsByNameFormatGroup = getDefaultValue(GROUP_VARS_BY_NAME_FORMAT_GROUP);
|
||||
groupVarsByNameFormatGroup = Prefs.get(GROUP_VARS_BY_NAME_FORMAT_GROUP, groupVarsByNameFormatGroup);
|
||||
|
||||
String groupVarsByNameFormat = getDefaultValue(GROUP_VARS_BY_NAME_FORMAT);
|
||||
groupVarsByNameFormat = Prefs.get(GROUP_VARS_BY_NAME_FORMAT, groupVarsByNameFormat);
|
||||
|
||||
String dollarRegexpForGrouping = getDefaultValue(DOLLAR_REGEXP_FOR_GROUPING);
|
||||
dollarRegexpForGrouping = Prefs.get(DOLLAR_REGEXP_FOR_GROUPING, dollarRegexpForGrouping);
|
||||
|
||||
GenericDialog configDiag = new GenericDialog("HDF5 Preferences");
|
||||
configDiag.addMessage("Reader:");
|
||||
@ -43,45 +34,19 @@ public class HDF5Config implements PlugIn {
|
||||
configDiag.addCheckbox("Show unmatched data set names in a separate list", showUnmatchedDataSetNames);
|
||||
configDiag.addStringField("HDF5 group containing pattern " + "for data set grouping: ", groupVarsByNameFormatGroup, 15);
|
||||
configDiag.addStringField("Pattern for grouping (if no attributes" + " are found): ", groupVarsByNameFormat, 15);
|
||||
// configDiag.addStringField("$ regexp (ignored because only numbers" +
|
||||
// " work right now): ",
|
||||
// dollarRegexpForGrouping,15);
|
||||
configDiag.addMessage("Writer:");
|
||||
|
||||
String yesLabel = "Save";
|
||||
String noLabel = "Reset";
|
||||
configDiag.enableYesNoCancel(yesLabel, noLabel);
|
||||
configDiag.showDialog();
|
||||
|
||||
if (configDiag.wasCanceled()) {
|
||||
// do nothing
|
||||
return;
|
||||
}
|
||||
if (!configDiag.wasOKed()) {
|
||||
// reset button was pressed
|
||||
logger.info("reset button was pressed");
|
||||
// reset all and return a new dialog
|
||||
configDiag.setVisible(false);
|
||||
this.run(arg);
|
||||
return;
|
||||
}
|
||||
// get parameters check if they are correct
|
||||
|
||||
// Get parameters check if they are correct
|
||||
groupVarsByName = configDiag.getNextBoolean();
|
||||
logger.info("groupVarsByName: " + Boolean.toString(groupVarsByName));
|
||||
|
||||
showUnmatchedDataSetNames = configDiag.getNextBoolean();
|
||||
logger.info("showUnmatchedDataSetNames: " + Boolean.toString(showUnmatchedDataSetNames));
|
||||
|
||||
groupVarsByNameFormatGroup = configDiag.getNextString();
|
||||
logger.info("groupVarsByNameFormatGroup: " + groupVarsByNameFormatGroup);
|
||||
|
||||
groupVarsByNameFormat = configDiag.getNextString();
|
||||
logger.info("groupVarsByNameFormat: " + groupVarsByNameFormat);
|
||||
|
||||
// dollarRegexpForGrouping = configDiag.getNextString();
|
||||
// logger.info("dollarRegexpForGrouping: " +
|
||||
// dollarRegexpForGrouping);
|
||||
|
||||
try {
|
||||
String[] formatTokens = HDF5GroupedVarnames.parseFormatString(groupVarsByNameFormat, dollarRegexpForGrouping);
|
||||
@ -97,62 +62,32 @@ public class HDF5Config implements PlugIn {
|
||||
this.run(arg);
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Saving...");
|
||||
|
||||
// all OK and "Save" was pressed, so save it...
|
||||
// All OK and "Save" was pressed, so save it...
|
||||
Prefs.set(GROUP_VARS_BY_NAME, groupVarsByName);
|
||||
Prefs.set(SHOW_UNMATCHED_DATASET_NAMES, showUnmatchedDataSetNames);
|
||||
Prefs.set(GROUP_VARS_BY_NAME_FORMAT_GROUP, groupVarsByNameFormatGroup);
|
||||
Prefs.set(GROUP_VARS_BY_NAME_FORMAT, groupVarsByNameFormat);
|
||||
//
|
||||
// ignore the $ regexp for now, because only numbers work
|
||||
//
|
||||
Prefs.set(DOLLAR_REGEXP_FOR_GROUPING, dollarRegexpForGrouping);
|
||||
|
||||
}
|
||||
|
||||
public static void setDefaultsIfNoValueExists() {
|
||||
boolean groupVarsByName = Boolean.getBoolean(getDefaultValue(GROUP_VARS_BY_NAME));
|
||||
groupVarsByName = Prefs.get(GROUP_VARS_BY_NAME, groupVarsByName);
|
||||
Prefs.set(GROUP_VARS_BY_NAME, groupVarsByName);
|
||||
|
||||
boolean showUnmatchedDataSetNames = Boolean.getBoolean(getDefaultValue(SHOW_UNMATCHED_DATASET_NAMES));
|
||||
showUnmatchedDataSetNames = Prefs.get(SHOW_UNMATCHED_DATASET_NAMES, showUnmatchedDataSetNames);
|
||||
Prefs.set(SHOW_UNMATCHED_DATASET_NAMES, showUnmatchedDataSetNames);
|
||||
|
||||
String groupVarsByNameFormatGroup = getDefaultValue(GROUP_VARS_BY_NAME_FORMAT_GROUP);
|
||||
groupVarsByNameFormatGroup = Prefs.get(GROUP_VARS_BY_NAME_FORMAT_GROUP, groupVarsByNameFormatGroup);
|
||||
Prefs.set(GROUP_VARS_BY_NAME_FORMAT_GROUP, groupVarsByNameFormatGroup);
|
||||
|
||||
String groupVarsByNameFormat = getDefaultValue(GROUP_VARS_BY_NAME_FORMAT);
|
||||
groupVarsByNameFormat = Prefs.get(GROUP_VARS_BY_NAME_FORMAT, groupVarsByNameFormat);
|
||||
Prefs.set(GROUP_VARS_BY_NAME_FORMAT, groupVarsByNameFormat);
|
||||
|
||||
String dollarRegexpForGrouping = getDefaultValue(DOLLAR_REGEXP_FOR_GROUPING);
|
||||
dollarRegexpForGrouping = Prefs.get(DOLLAR_REGEXP_FOR_GROUPING, dollarRegexpForGrouping);
|
||||
Prefs.set(DOLLAR_REGEXP_FOR_GROUPING, dollarRegexpForGrouping);
|
||||
public boolean isGroupVarsByName() {
|
||||
return groupVarsByName;
|
||||
}
|
||||
|
||||
public static String getDefaultValue(String key) {
|
||||
if (key.equals(GROUP_VARS_BY_NAME)) {
|
||||
boolean groupVarsByName = true; // default
|
||||
return Boolean.toString(groupVarsByName);
|
||||
} else if (key.equals(SHOW_UNMATCHED_DATASET_NAMES)) {
|
||||
boolean showUnmatchedDataSetNames = true; // default
|
||||
return Boolean.toString(showUnmatchedDataSetNames);
|
||||
} else if (key.equals(GROUP_VARS_BY_NAME_FORMAT_GROUP)) {
|
||||
String groupVarsByNameFormatGroup = "/hints"; // default
|
||||
public boolean isShowUnmatchedDataSetNames() {
|
||||
return showUnmatchedDataSetNames;
|
||||
}
|
||||
public String getGroupVarsByNameFormatGroup() {
|
||||
return groupVarsByNameFormatGroup;
|
||||
} else if (key.equals(GROUP_VARS_BY_NAME_FORMAT)) {
|
||||
String groupVarsByNameFormat = "/t$T/channel$C"; // default
|
||||
}
|
||||
public String getGroupVarsByNameFormat() {
|
||||
return groupVarsByNameFormat;
|
||||
} else if (key.equals(DOLLAR_REGEXP_FOR_GROUPING)) {
|
||||
String dollarRegexpForGrouping = "[0-9]+"; // default
|
||||
}
|
||||
public String getDollarRegexpForGrouping() {
|
||||
return dollarRegexpForGrouping;
|
||||
} else {
|
||||
logger.info("No default value for key: " + key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package ch.psi.imagej.hdf5;
|
||||
*/
|
||||
|
||||
import ij.IJ;
|
||||
import ij.Prefs;
|
||||
import ij.ImagePlus;
|
||||
import ij.CompositeImage;
|
||||
import ij.ImageStack;
|
||||
@ -100,14 +99,12 @@ public class HDF5Reader implements PlugIn {
|
||||
/*-------------------------------------------------------------------
|
||||
* read HDF5_Config prefs
|
||||
*-------------------------------------------------------------------*/
|
||||
boolean groupVarsByName = Boolean.getBoolean(HDF5Config.getDefaultValue(HDF5Config.GROUP_VARS_BY_NAME));
|
||||
groupVarsByName = Prefs.get(HDF5Config.GROUP_VARS_BY_NAME, groupVarsByName);
|
||||
HDF5Config config = new HDF5Config();
|
||||
boolean groupVarsByName = config.isGroupVarsByName();
|
||||
boolean showUnmatchedDataSetNames = config.isShowUnmatchedDataSetNames();
|
||||
String groupVarsByNameFormatGroup = config.getGroupVarsByNameFormatGroup();
|
||||
String dollarRegexpForGrouping = config.getDollarRegexpForGrouping();
|
||||
|
||||
boolean showUnmatchedDataSetNames = Boolean.getBoolean(HDF5Config.getDefaultValue(HDF5Config.SHOW_UNMATCHED_DATASET_NAMES));
|
||||
showUnmatchedDataSetNames = Prefs.get(HDF5Config.SHOW_UNMATCHED_DATASET_NAMES, showUnmatchedDataSetNames);
|
||||
|
||||
String groupVarsByNameFormatGroup = HDF5Config.getDefaultValue(HDF5Config.GROUP_VARS_BY_NAME_FORMAT_GROUP);
|
||||
groupVarsByNameFormatGroup = Prefs.get(HDF5Config.GROUP_VARS_BY_NAME_FORMAT_GROUP, groupVarsByNameFormatGroup);
|
||||
|
||||
// TODO: try to read attribute containing format String
|
||||
String groupVarsByNameFormat = null;
|
||||
@ -159,17 +156,14 @@ public class HDF5Reader implements PlugIn {
|
||||
logger.info("File has format string for grouping: " + groupVarsByNameFormat);
|
||||
} else {
|
||||
logger.info("File has no format string for grouping" + ", using default");
|
||||
groupVarsByNameFormat = HDF5Config.getDefaultValue(HDF5Config.GROUP_VARS_BY_NAME_FORMAT);
|
||||
groupVarsByNameFormat = Prefs.get(HDF5Config.GROUP_VARS_BY_NAME_FORMAT, groupVarsByNameFormat);
|
||||
groupVarsByNameFormat = config.getGroupVarsByNameFormat();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Error occured read format string " + "for grouping, using default");
|
||||
groupVarsByNameFormat = HDF5Config.getDefaultValue(HDF5Config.GROUP_VARS_BY_NAME_FORMAT);
|
||||
groupVarsByNameFormat = Prefs.get(HDF5Config.GROUP_VARS_BY_NAME_FORMAT, groupVarsByNameFormat);
|
||||
groupVarsByNameFormat = config.getGroupVarsByNameFormat();
|
||||
}
|
||||
|
||||
String dollarRegexpForGrouping = HDF5Config.getDefaultValue(HDF5Config.DOLLAR_REGEXP_FOR_GROUPING);
|
||||
dollarRegexpForGrouping = Prefs.get(HDF5Config.DOLLAR_REGEXP_FOR_GROUPING, dollarRegexpForGrouping);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------
|
||||
* init the frame and channel ranges
|
||||
|
50
src/test/java/ch/psi/imagej/hdf5/HDF5ConfigTest.java
Normal file
50
src/test/java/ch/psi/imagej/hdf5/HDF5ConfigTest.java
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2014 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but without any
|
||||
* warranty; without even the implied warranty of merchantability or fitness for
|
||||
* a particular purpose. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package ch.psi.imagej.hdf5;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class HDF5ConfigTest {
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
HDF5Config config = new HDF5Config();
|
||||
config.run("");
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user