diff --git a/app/src/processing/app/Library.java b/app/src/processing/app/Library.java index 9f78ebef7..7d172f706 100644 --- a/app/src/processing/app/Library.java +++ b/app/src/processing/app/Library.java @@ -7,13 +7,15 @@ import processing.app.contrib.*; import processing.core.*; -public class Library extends LocalContribution { +public class Library extends LocalContribWithReference { static final String[] platformNames = PConstants.platformNames; //protected File folder; // /path/to/shortname protected File libraryFolder; // shortname/library protected File examplesFolder; // shortname/examples - protected File referenceFile; // shortname/reference/index.html is one possible path + + // Shifted to LocalContribWithReference +// protected File referenceFile; // shortname/reference/index.html is one possible path /** * Subfolder for grouping libraries in a menu. Basic subfolder support @@ -110,7 +112,9 @@ public class Library extends LocalContribution { libraryFolder = new File(folder, "library"); examplesFolder = new File(folder, "examples"); - referenceFile = loadReferenceIndexFile(folder); + + // Now done in LocalContribWithReference's ctor + // referenceFile = loadReferenceIndexFile(folder); File exportSettings = new File(libraryFolder, "export.txt"); HashMap exportTable = Base.readSettings(exportSettings); @@ -284,32 +288,6 @@ public class Library extends LocalContribution { } - private 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; - } - - - public boolean hasReference() { - return referenceFile.exists(); - } - - - public File getReferenceIndexFile() { - return referenceFile; - } - - public String getGroup() { return group; } diff --git a/app/src/processing/app/contrib/LocalContribWithReference.java b/app/src/processing/app/contrib/LocalContribWithReference.java new file mode 100644 index 000000000..c587577b4 --- /dev/null +++ b/app/src/processing/app/contrib/LocalContribWithReference.java @@ -0,0 +1,56 @@ +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 10d7ade93..1b470e4cc 100644 --- a/app/src/processing/app/contrib/ToolContribution.java +++ b/app/src/processing/app/contrib/ToolContribution.java @@ -32,11 +32,10 @@ import processing.app.Editor; import processing.app.tools.Tool; -public class ToolContribution extends LocalContribution implements Tool { +public class ToolContribution extends LocalContribWithReference implements Tool { private Tool tool; - protected File referenceFile; // shortname/reference/index.html is one possible path - + static public ToolContribution load(File folder) { try { return new ToolContribution(folder); @@ -54,7 +53,6 @@ public class ToolContribution extends LocalContribution implements Tool { private ToolContribution(File folder) throws Exception { super(folder); - referenceFile = loadReferenceIndexFile(); String className = initLoader(null); if (className != null) { @@ -155,29 +153,4 @@ public class ToolContribution extends LocalContribution implements Tool { public ContributionType getType() { return ContributionType.TOOL; } - - public File loadReferenceIndexFile() { - 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; - } - - - public File getReferenceIndexFile() { - return referenceFile; - } - - - public boolean hasReference() { - return referenceFile.exists(); - } } \ No newline at end of file diff --git a/app/src/processing/mode/java/JavaEditor.java b/app/src/processing/mode/java/JavaEditor.java index ae8f3a400..37d064d95 100644 --- a/app/src/processing/mode/java/JavaEditor.java +++ b/app/src/processing/mode/java/JavaEditor.java @@ -286,6 +286,19 @@ public class JavaEditor extends Editor { //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + /** + * Populates the JMenu with JMenuItems, one for each Library that has a + * reference accompanying it. The JMenuItems open the index.htm/index.html + * file of the reference in the user's default browser, or the readme.txt in + * the user's default text editor. + * + * @param libsList + * A list of the Libraries to be added + * @param subMenu + * The JMenu to which the JMenuItems corresponding to the Libraries + * are to be added + * @return true if and only if any JMenuItems were added; false otherwise + */ private boolean addLibReferencesToSubMenu(ArrayList libsList, JMenu subMenu) { boolean isItemAdded = false; Iterator iter = libsList.iterator(); @@ -308,6 +321,20 @@ public class JavaEditor extends Editor { } + /** + * + * Populates the JMenu with JMenuItems, one for each Tool that has a reference + * accompanying it. The JMenuItems open the index.htm/index.html file of the + * reference in the user's default browser, or the readme.txt in the user's + * default text editor. + * + * @param toolsList + * A list of Tools to be added + * @param subMenu + * The JMenu to which the JMenuItems corresponding to the Tools are + * to be added + * @return true if and only if any JMenuItems were added; false otherwise + */ private boolean addToolReferencesToSubMenu(ArrayList toolsList, JMenu subMenu) { boolean isItemAdded = false; Iterator iter = toolsList.iterator();