staves = new ArrayList<>(system.getStaves());
for (Part part : system.getParts()) {
staves.removeAll(part.getStaves());
diff --git a/src/main/org/audiveris/omr/RunSmallStaffCheck.java b/src/main/org/audiveris/omr/RunSmallStaffCheck.java
index c74e9bde5..644adfc66 100644
--- a/src/main/org/audiveris/omr/RunSmallStaffCheck.java
+++ b/src/main/org/audiveris/omr/RunSmallStaffCheck.java
@@ -41,11 +41,9 @@
public class RunSmallStaffCheck
extends RunClass
{
- //~ Static fields/initializers -----------------------------------------------------------------
private static final Logger logger = LoggerFactory.getLogger(RunSmallStaffCheck.class);
- //~ Constructors -------------------------------------------------------------------------------
/**
* Creates a new {@code RunSmallStaffCheck} object.
*
@@ -58,7 +56,6 @@ public RunSmallStaffCheck (Book book,
super(book, sheetIds);
}
- //~ Methods ------------------------------------------------------------------------------------
@Override
public void process ()
{
diff --git a/src/main/org/audiveris/omr/WellKnowns.java b/src/main/org/audiveris/omr/WellKnowns.java
index f2236b8ad..896abd78f 100644
--- a/src/main/org/audiveris/omr/WellKnowns.java
+++ b/src/main/org/audiveris/omr/WellKnowns.java
@@ -39,6 +39,8 @@
import java.util.Locale;
import java.util.jar.JarFile;
+import javax.swing.filechooser.FileSystemView;
+
/**
* Class {@code WellKnowns} gathers top public static final data to be shared within
* Audiveris application.
@@ -50,7 +52,6 @@
*/
public abstract class WellKnowns
{
- //~ Static fields/initializers -----------------------------------------------------------------
//----------//
// IDENTITY //
@@ -97,8 +98,8 @@ public abstract class WellKnowns
public static final String OS_ARCH = System.getProperty("os.arch");
/** Are we using Windows on 64 bit architecture?. */
- public static final boolean WINDOWS_64 = WINDOWS
- && (System.getenv("ProgramFiles(x86)") != null);
+ public static final boolean WINDOWS_64 = WINDOWS && (System.getenv(
+ "ProgramFiles(x86)") != null);
/** File character encoding. */
public static final String FILE_ENCODING = getFileEncoding();
@@ -129,12 +130,8 @@ public abstract class WellKnowns
public static final boolean RUNNING_FROM_JAR = runningFromJar();
/** The uri where read-only resources are stored. */
- public static final URI RES_URI = RUNNING_FROM_JAR
- ? toURI(WellKnowns.class.getClassLoader().getResource("res"))
- : Paths.get("res").toUri();
-
- /** The folder where Tesseract OCR material is stored. */
- public static final Path OCR_FOLDER = getOcrFolder();
+ public static final URI RES_URI = RUNNING_FROM_JAR ? toURI(
+ WellKnowns.class.getClassLoader().getResource("res")) : Paths.get("res").toUri();
//-------------// read-write area
// USER CONFIG // Configuration files the user can edit on his own
@@ -143,9 +140,6 @@ public abstract class WellKnowns
/** The folder where global configuration data is stored. */
public static final Path CONFIG_FOLDER = getFolder(FolderKind.CONFIG);
- /** The folder where plugin scripts are found. */
- public static final Path PLUGINS_FOLDER = CONFIG_FOLDER.resolve("plugins");
-
//-----------// read-write area
// USER DATA // User-specific data, except configuration stuff
//-----------//
@@ -165,14 +159,11 @@ public abstract class WellKnowns
*/
public static final Path EXAMPLES_FOLDER = DATA_FOLDER.resolve("examples");
- /** The folder where temporary data can be stored. */
- public static final Path TEMP_FOLDER = DATA_FOLDER.resolve("temp");
-
/** The folder where training material is stored. */
- public static final Path TRAIN_FOLDER = DATA_FOLDER.resolve("train");
+ public static final Path TRAIN_FOLDER = CONFIG_FOLDER.resolve("train");
/** The default base for output folders. */
- public static final Path DEFAULT_BASE_FOLDER = DATA_FOLDER.resolve("output");
+ public static final Path DEFAULT_BASE_FOLDER = DATA_FOLDER; // BHT: skip "output"
//----------//
// USER LOG //
@@ -181,6 +172,9 @@ public abstract class WellKnowns
/** The folder where log files are stored. */
public static final Path LOG_FOLDER = getFolder(FolderKind.LOG);
+ /** The folder where temporary data can be stored. */
+ public static final Path TEMP_FOLDER = LOG_FOLDER.resolve("temp");
+
static {
/** Logging configuration. */
LogUtil.initialize(CONFIG_FOLDER, RES_URI);
@@ -205,26 +199,18 @@ public abstract class WellKnowns
disableMediaLib();
}
- private static final String ocrNotFoundMsg = "Tesseract data could not be found. "
- + "Try setting the TESSDATA_PREFIX environment variable to the parent folder of \"tessdata\".";
-
- //~ Enumerations -------------------------------------------------------------------------------
private static enum FolderKind
{
- //~ Enumeration constant initializers ------------------------------------------------------
-
- CONFIG,
DATA,
+ CONFIG,
LOG;
}
- //~ Constructors -------------------------------------------------------------------------------
/** Not meant to be instantiated. */
private WellKnowns ()
{
}
- //~ Methods ------------------------------------------------------------------------------------
//--------------//
// ensureLoaded //
//--------------//
@@ -319,7 +305,9 @@ private static Path getFolder (FolderKind kind)
} else if (LINUX) {
return getFolderForLinux(kind);
} else {
- throw new RuntimeException("Platform unknown");
+ printError("Platform unknown: " + kind);
+
+ return null;
}
}
@@ -335,10 +323,10 @@ private static Path getFolderForLinux (FolderKind kind)
final Path audiverisPath = Paths.get(xdg + TOOL_PREFIX);
switch (kind) {
- case CONFIG:
+ case DATA:
return audiverisPath;
- case DATA:
+ case CONFIG:
return audiverisPath;
default:
@@ -351,16 +339,18 @@ private static Path getFolderForLinux (FolderKind kind)
final String home = System.getenv("HOME");
if (home == null) {
- throw new RuntimeException("HOME environment variable is not set");
+ printError("HOME environment variable is not set");
+
+ return null;
}
switch (kind) {
- case CONFIG:
- return Paths.get(home + "/.config" + TOOL_PREFIX);
-
case DATA:
return Paths.get(home + "/.local/share" + TOOL_PREFIX);
+ case CONFIG:
+ return Paths.get(home + "/.config" + TOOL_PREFIX);
+
default:
case LOG:
return Paths.get(home + "/.cache" + TOOL_PREFIX + "/log");
@@ -375,16 +365,18 @@ private static Path getFolderForMac (FolderKind kind)
final String home = System.getenv("HOME");
if (home == null) {
- throw new RuntimeException("HOME environment variable is not set");
+ printError("HOME environment variable is not set");
+
+ return null;
}
switch (kind) {
- case CONFIG:
- return Paths.get(home + "/Library/Application Support/" + TOOL_PREFIX);
-
case DATA:
return Paths.get(home + "/Library/" + TOOL_PREFIX + "/data");
+ case CONFIG:
+ return Paths.get(home + "/Library/Application Support/" + TOOL_PREFIX);
+
default:
case LOG:
return Paths.get(home + "/Library/" + TOOL_PREFIX + "/log");
@@ -396,21 +388,27 @@ private static Path getFolderForMac (FolderKind kind)
//---------------------//
private static Path getFolderForWindows (FolderKind kind)
{
+ // User Application Data
final String appdata = System.getenv("APPDATA");
if (appdata == null) {
- throw new RuntimeException("APPDATA environment variable is not set");
+ printError("APPDATA environment variable is not set");
+
+ return null;
}
final Path audiverisPath = Paths.get(appdata + TOOL_PREFIX);
+ // User Documents
+ final String userDocs = FileSystemView.getFileSystemView().getDefaultDirectory().getPath();
+
switch (kind) {
+ case DATA:
+ return Paths.get(userDocs + "/" + TOOL_NAME);
+
case CONFIG:
return audiverisPath.resolve("config");
- case DATA:
- return audiverisPath.resolve("data");
-
default:
case LOG:
return audiverisPath.resolve("log");
@@ -435,60 +433,13 @@ private static JarFile getJarFile ()
return jarFile;
}
- } catch (Exception ex) {
+ } catch (IOException ex) {
System.out.print("Error getting jar file " + ex);
}
return null;
}
- //--------------//
- // getOcrFolder //
- //--------------//
- private static Path getOcrFolder ()
- {
- // common Macintosh TESSDATA locations
- final String[] macOcrLocations = {
- "/opt/local/share", // Macports
- "/usr/local/opt/tesseract/share" // Homebrew
- };
-
- // common Linux TESSDATA locations
- final String[] linuxOcrLocations = {
- "/usr/share/tesseract-ocr", // Debian, Ubuntu and derivatives
- "/usr/share", // OpenSUSE
- "/usr/share/tesseract" // Fedora
- };
-
- // First, try to use TESSDATA_PREFIX environment variable
- // which might denote a Tesseract installation
- final String TESSDATA_PREFIX = "TESSDATA_PREFIX";
- final String tessPrefix = System.getenv(TESSDATA_PREFIX);
-
- if (tessPrefix != null) {
- Path dir = Paths.get(tessPrefix);
-
- if (Files.isDirectory(dir)) {
- return dir;
- }
- }
-
- // Fallback to default directory on Windows
- if (WINDOWS) {
- final String pf32 = OS_ARCH.equals("x86") ? "ProgramFiles" : "ProgramFiles(x86)";
-
- return Paths.get(System.getenv(pf32)).resolve("tesseract-ocr");
-
- // scan common locations on Mac and Linux
- } else if (LINUX) {
- return scanOcrLocations(linuxOcrLocations);
- } else if (MAC_OS_X) {
- return scanOcrLocations(macOcrLocations);
- }
-
- throw new InstallationException(ocrNotFoundMsg);
- }
-
//-----------------//
// logDeclaredData //
//-----------------//
@@ -497,10 +448,10 @@ private static void logDeclaredData ()
// Note: Logger initialization has been differed until now
final Logger logger = LoggerFactory.getLogger(WellKnowns.class);
- if (logger.isDebugEnabled()) {
+ if (logger.isTraceEnabled()) {
for (Field field : WellKnowns.class.getDeclaredFields()) {
try {
- logger.debug("{}= {}", field.getName(), field.get(null));
+ logger.trace("{}= {}", field.getName(), field.get(null));
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}
@@ -508,6 +459,19 @@ private static void logDeclaredData ()
}
}
+ //------------//
+ // printError //
+ //------------//
+ /**
+ * Fallback solution, since we cannot reliably use exception in static initializer.
+ *
+ * @param msg the error message
+ */
+ private static void printError (String msg)
+ {
+ System.err.println("*** INIT_ERROR occurred in class WellKnowns: " + msg);
+ }
+
//----------------//
// runningFromJar //
//----------------//
@@ -516,55 +480,21 @@ private static boolean runningFromJar ()
return CLASS_CONTAINER.toString().toLowerCase().endsWith(".jar");
}
- //------------------//
- // scanOcrLocations //
- //------------------//
- private static Path scanOcrLocations (String[] locations)
- {
- for (String loc : locations) {
- final Path path = Paths.get(loc);
-
- if (Files.exists(path.resolve("tessdata"))) {
- return path;
- }
- }
-
- throw new InstallationException(ocrNotFoundMsg);
- }
-
//-------------//
// xdgProperty //
//-------------//
private static String xdgProperty (FolderKind kind)
{
switch (kind) {
- case CONFIG:
- return "XDG_CONFIG_HOME";
-
case DATA:
return "XDG_DATA_HOME";
+ case CONFIG:
+ return "XDG_CONFIG_HOME";
+
default:
case LOG:
return "XDG_CACHE_HOME";
}
}
-
- //~ Inner Classes ------------------------------------------------------------------------------
- //-----------------------//
- // InstallationException //
- //-----------------------//
- /**
- * Exception used to signal an installation error.
- */
- public static class InstallationException
- extends RuntimeException
- {
- //~ Constructors ---------------------------------------------------------------------------
-
- public InstallationException (String message)
- {
- super(message);
- }
- }
}
diff --git a/src/main/org/audiveris/omr/check/Check.java b/src/main/org/audiveris/omr/check/Check.java
index b5fb9d5b9..793d85341 100644
--- a/src/main/org/audiveris/omr/check/Check.java
+++ b/src/main/org/audiveris/omr/check/Check.java
@@ -32,9 +32,10 @@
* Class {@code Check} encapsulates the definition of a check,
* which can later be used on a whole population of objects.
*
- * Checks are generally gathered in {@link CheckSuite} instances.
+ * Checks are generally gathered in {@link CheckSuite} instances.
*
- * The strategy is the following:
+ * The strategy is the following:
+ *
* - A successful individual check may eventually result in an interpretation checked object (if
* the suite of checks ends with an acceptable grade).
* - Any failed individual check triggers the immediate end of the containing suite but records
@@ -42,16 +43,13 @@
*
*
* @param precise type of the objects to be checked
- *
* @author Hervé Bitteur
*/
public abstract class Check
{
- //~ Static fields/initializers -----------------------------------------------------------------
private static final Logger logger = LoggerFactory.getLogger(Check.class);
- //~ Instance fields ----------------------------------------------------------------------------
/**
* Specifies the Failure to be assigned to the Checkable object,
* when the result of this individual check is not acceptable.
@@ -73,7 +71,6 @@ public abstract class Check
/** Covariant: higher is better, contravariant: lower is better. */
private final boolean covariant;
- //~ Constructors -------------------------------------------------------------------------------
/**
* Creates a new Check object.
*
@@ -121,7 +118,6 @@ protected Check (String name,
this(name, description, new NamedDouble(low), new NamedDouble(high), covariant, redResult);
}
- //~ Methods ------------------------------------------------------------------------------------
//----------------//
// getDescription //
//----------------//
@@ -298,7 +294,6 @@ public String toString ()
* proper data value from the given object passed as a parameter.
*
* @param obj the object to be checked
- *
* @return the data value relevant for the check
*/
protected abstract double getValue (C obj);
@@ -316,7 +311,6 @@ private void verifyRange ()
}
}
- //~ Inner Classes ------------------------------------------------------------------------------
//-------//
// Grade //
//-------//
@@ -326,7 +320,6 @@ private void verifyRange ()
public static class Grade
extends Constant.Double
{
- //~ Constructors ---------------------------------------------------------------------------
/**
* Specific constructor, where 'unit' and 'name' are assigned later
diff --git a/src/main/org/audiveris/omr/check/CheckBoard.java b/src/main/org/audiveris/omr/check/CheckBoard.java
index c61efe6ef..d03de0bf0 100644
--- a/src/main/org/audiveris/omr/check/CheckBoard.java
+++ b/src/main/org/audiveris/omr/check/CheckBoard.java
@@ -38,22 +38,17 @@
* information.
*
* @param The {@link Checkable} entity type to be checked
- *
* @author Hervé Bitteur
*/
public class CheckBoard
extends Board
{
- //~ Static fields/initializers -----------------------------------------------------------------
private static final Logger logger = LoggerFactory.getLogger(CheckBoard.class);
- //~ Instance fields ----------------------------------------------------------------------------
- //
- /** For display of check suite results */
+ /** For display of check suite results. */
private final CheckPanel checkPanel;
- //~ Constructors -------------------------------------------------------------------------------
/**
* Create a Check Board.
*
@@ -76,7 +71,7 @@ public CheckBoard (String name,
false, // Count
false, // Vip
false); // Dump
- checkPanel = new CheckPanel(suite);
+ checkPanel = new CheckPanel<>(suite);
if (suite != null) {
defineLayout(suite.getName());
@@ -86,7 +81,6 @@ public CheckBoard (String name,
tellObject(null);
}
- //~ Methods ------------------------------------------------------------------------------------
//------------//
// applySuite //
//------------//
@@ -109,7 +103,6 @@ public synchronized void applySuite (CheckSuite suite,
tellObject(object);
}
- //
//---------//
// onEvent //
//---------//
diff --git a/src/main/org/audiveris/omr/check/CheckPanel.java b/src/main/org/audiveris/omr/check/CheckPanel.java
index 80f70fd45..f47b30a9a 100644
--- a/src/main/org/audiveris/omr/check/CheckPanel.java
+++ b/src/main/org/audiveris/omr/check/CheckPanel.java
@@ -52,12 +52,10 @@
*
* @param the subtype of Checkable objects used in the homogeneous collection of checks of the
* suite
- *
* @author Hervé Bitteur
*/
public class CheckPanel
{
- //~ Static fields/initializers -----------------------------------------------------------------
private static final Logger logger = LoggerFactory.getLogger(CheckPanel.class);
@@ -75,27 +73,24 @@ public class CheckPanel
private static final int FIELD_WIDTH = 4;
- //~ Instance fields ----------------------------------------------------------------------------
- //
- /** The related check suite (the model) */
+ /** The related check suite (the model). */
private CheckSuite suite;
- /** The swing component that includes all the fields */
+ /** The swing component that includes all the fields. */
private Panel component;
- /** The field for global result */
+ /** The field for global result. */
private final JTextField globalField;
- /** Matrix of all value fields */
+ /** Matrix of all value fields. */
private JTextField[][] values;
- /** Matrix of all bound fields */
+ /** Matrix of all bound fields. */
private JTextField[][] bounds;
- /** Last object checked */
+ /** Last object checked. */
private C checkable;
- //~ Constructors -------------------------------------------------------------------------------
/**
* Create a check panel for a given suite.
*
@@ -111,7 +106,6 @@ public CheckPanel (CheckSuite suite)
setSuite(suite);
}
- //~ Methods ------------------------------------------------------------------------------------
//--------------//
// getComponent //
//--------------//
@@ -324,7 +318,7 @@ private void createBoundFields ()
field.setText(textOf(constant.getValue()));
field.setToolTipText(
"" + constant.getName() + "
" + constant.getDescription()
- + "");
+ + "