From b254cb226f4daa6f2658067b5b8a2e3e93d8ca99 Mon Sep 17 00:00:00 2001 From: joelmoniz Date: Tue, 18 Nov 2014 02:28:34 +0530 Subject: [PATCH] Tool and Lib References now show in Help menu Removing LocalContribWithReference.java --- app/src/processing/app/Library.java | 55 +++++++++++++++--- .../contrib/LocalContribWithReference.java | 56 ------------------- .../app/contrib/ToolContribution.java | 48 +++++++++++++++- 3 files changed, 95 insertions(+), 64 deletions(-) delete mode 100644 app/src/processing/app/contrib/LocalContribWithReference.java diff --git a/app/src/processing/app/Library.java b/app/src/processing/app/Library.java index 7d172f706..342143bc3 100644 --- a/app/src/processing/app/Library.java +++ b/app/src/processing/app/Library.java @@ -7,15 +7,13 @@ import processing.app.contrib.*; import processing.core.*; -public class Library extends LocalContribWithReference { +public class Library extends LocalContribution { static final String[] platformNames = PConstants.platformNames; //protected File folder; // /path/to/shortname protected File libraryFolder; // shortname/library protected File examplesFolder; // shortname/examples - - // Shifted to LocalContribWithReference -// protected File referenceFile; // shortname/reference/index.html is one possible path + protected File referenceFile; // shortname/reference/index.html is one possible path /** * Subfolder for grouping libraries in a menu. Basic subfolder support @@ -112,9 +110,7 @@ public class Library extends LocalContribWithReference { libraryFolder = new File(folder, "library"); examplesFolder = new File(folder, "examples"); - - // Now done in LocalContribWithReference's ctor - // referenceFile = loadReferenceIndexFile(folder); + referenceFile = new File(folder, "reference/index.html"); File exportSettings = new File(libraryFolder, "export.txt"); HashMap exportTable = Base.readSettings(exportSettings); @@ -216,6 +212,8 @@ public class Library extends LocalContribWithReference { // get the path for all .jar files in this code folder packageList = Base.packageListFromClassPath(getClassPath()); + + referenceFile = loadReferenceIndexFile(folder); } @@ -518,4 +516,47 @@ public class Library extends LocalContribWithReference { public ContributionType getType() { return ContributionType.LIBRARY; } + + + /** + * @param folder + * The file object representing the base folder of the contribution + * @return Returns a file object representing the index file of the reference + */ + protected File loadReferenceIndexFile(File folder) { + final String potentialFileList[] = { + "reference/index.html", "reference/index.htm", + "documentation/index.html", "documentation/index.htm", "docs/index.html", + "docs/index.htm", "documentation.html", "documentation.htm", + "reference.html", "reference.htm", "docs.html", "docs.htm", "readme.txt" }; + + int i = 0; + File potentialRef = new File(folder, potentialFileList[i]); + while (!potentialRef.exists() && ++i < potentialFileList.length) { + potentialRef = new File(folder, potentialFileList[i]); + } + return potentialRef; + } + + + /** + * Returns the object stored in the referenceFile field, which contains an + * instance of the file object representing the index file of the reference + * + * @return referenceFile + */ + public File getReferenceIndexFile() { + return referenceFile; + } + + + /** + * Tests whether the reference's index file indicated by referenceFile exists. + * + * @return true if and only if the file denoted by referenceFile exists; false + * otherwise. + */ + public boolean hasReference() { + return referenceFile.exists(); + } } diff --git a/app/src/processing/app/contrib/LocalContribWithReference.java b/app/src/processing/app/contrib/LocalContribWithReference.java deleted file mode 100644 index c587577b4..000000000 --- a/app/src/processing/app/contrib/LocalContribWithReference.java +++ /dev/null @@ -1,56 +0,0 @@ -package processing.app.contrib; - -import java.io.File; - -/** - * A local contribution that comes with references. - */ -public abstract class LocalContribWithReference extends LocalContribution { - - protected File referenceFile; // shortname/reference/index.html is one possible path - - public LocalContribWithReference(File folder) { - super(folder); - referenceFile = loadReferenceIndexFile(folder); - } - - /** - * @param folder - * The file object representing the base folder of the contribution - * @return Returns a file object representing the index file of the reference - */ - protected File loadReferenceIndexFile(File folder) { - final String potentialFileList[] = { - "reference/index.html", "reference/index.htm", - "documentation/index.html", "documentation/index.htm", "docs/index.html", - "docs/index.htm", "documentation.html", "documentation.htm", - "reference.html", "reference.htm", "docs.html", "docs.htm", "readme.txt" }; - - int i = 0; - File potentialRef = new File(folder, potentialFileList[i]); - while (!potentialRef.exists() && ++i < potentialFileList.length) { - potentialRef = new File(folder, potentialFileList[i]); - } - return potentialRef; - } - - /** - * Returns the object stored in the referenceFile field, which contains an - * instance of the file object representing the index file of the reference - * - * @return referenceFile - */ - public File getReferenceIndexFile() { - return referenceFile; - } - - /** - * Tests whether the reference's index file indicated by referenceFile exists. - * - * @return true if and only if the file denoted by referenceFile exists; false - * otherwise. - */ - public boolean hasReference() { - return referenceFile.exists(); - } -} diff --git a/app/src/processing/app/contrib/ToolContribution.java b/app/src/processing/app/contrib/ToolContribution.java index 1b470e4cc..aa6620b79 100644 --- a/app/src/processing/app/contrib/ToolContribution.java +++ b/app/src/processing/app/contrib/ToolContribution.java @@ -32,9 +32,10 @@ import processing.app.Editor; import processing.app.tools.Tool; -public class ToolContribution extends LocalContribWithReference implements Tool { +public class ToolContribution extends LocalContribution implements Tool { private Tool tool; + private File referenceFile; // shortname/reference/index.html is one possible path static public ToolContribution load(File folder) { try { @@ -59,6 +60,8 @@ public class ToolContribution extends LocalContribWithReference implements Tool Class toolClass = loader.loadClass(className); tool = (Tool) toolClass.newInstance(); } + + referenceFile = loadReferenceIndexFile(folder); } @@ -153,4 +156,47 @@ public class ToolContribution extends LocalContribWithReference implements Tool public ContributionType getType() { return ContributionType.TOOL; } + + + /** + * @param folder + * The file object representing the base folder of the contribution + * @return Returns a file object representing the index file of the reference + */ + protected File loadReferenceIndexFile(File folder) { + final String potentialFileList[] = { + "reference/index.html", "reference/index.htm", + "documentation/index.html", "documentation/index.htm", "docs/index.html", + "docs/index.htm", "documentation.html", "documentation.htm", + "reference.html", "reference.htm", "docs.html", "docs.htm", "readme.txt" }; + + int i = 0; + File potentialRef = new File(folder, potentialFileList[i]); + while (!potentialRef.exists() && ++i < potentialFileList.length) { + potentialRef = new File(folder, potentialFileList[i]); + } + return potentialRef; + } + + + /** + * Returns the object stored in the referenceFile field, which contains an + * instance of the file object representing the index file of the reference + * + * @return referenceFile + */ + public File getReferenceIndexFile() { + return referenceFile; + } + + + /** + * Tests whether the reference's index file indicated by referenceFile exists. + * + * @return true if and only if the file denoted by referenceFile exists; false + * otherwise. + */ + public boolean hasReference() { + return referenceFile.exists(); + } } \ No newline at end of file