mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 02:45:36 +01:00
Added new class LocalContribWithReference for contribs with reference
And added some documentation for the new functions
This commit is contained in:
@@ -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<String,String> 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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<Library> libsList, JMenu subMenu) {
|
||||
boolean isItemAdded = false;
|
||||
Iterator<Library> 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<ToolContribution> toolsList, JMenu subMenu) {
|
||||
boolean isItemAdded = false;
|
||||
Iterator<ToolContribution> iter = toolsList.iterator();
|
||||
|
||||
Reference in New Issue
Block a user