Skip to content

Commit aa2f8dc

Browse files
committed
merge and mess
2 parents f462e1c + 9a5844d commit aa2f8dc

6 files changed

Lines changed: 393 additions & 153 deletions

File tree

app/src/processing/app/Editor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ public void windowGainedFocus(WindowEvent e) {
286286
}
287287

288288

289+
protected ArrayList<ToolContribution> getCoreTools() {
290+
return coreTools;
291+
}
292+
293+
289294
/**
290295
* Broken out to get modes working for GSOC, but this needs a longer-term
291296
* solution where the listeners are handled properly.
@@ -1262,11 +1267,22 @@ public void actionPerformed(ActionEvent e) {
12621267

12631268
public void showReference(String filename) {
12641269
File file = new File(mode.getReferenceFolder(), filename);
1270+
showReferenceFile(file);
1271+
}
1272+
1273+
1274+
/**
1275+
* Given the .html file, displays it in the default browser.
1276+
*
1277+
* @param file
1278+
*/
1279+
public void showReferenceFile(File file) {
12651280
try {
12661281
file = file.getCanonicalFile();
12671282
} catch (IOException e) {
12681283
e.printStackTrace();
12691284
}
1285+
12701286
// Prepend with file:// and also encode spaces & other characters
12711287
Base.openURL(file.toURI().toString());
12721288
}

app/src/processing/app/Library.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,26 @@ static protected void list(File folder, ArrayList<Library> libraries) {
514514
public ContributionType getType() {
515515
return ContributionType.LIBRARY;
516516
}
517+
518+
519+
/**
520+
* Returns the object stored in the referenceFile field, which contains an
521+
* instance of the file object representing the index file of the reference
522+
*
523+
* @return referenceFile
524+
*/
525+
public File getReferenceIndexFile() {
526+
return referenceFile;
527+
}
528+
529+
530+
/**
531+
* Tests whether the reference's index file indicated by referenceFile exists.
532+
*
533+
* @return true if and only if the file denoted by referenceFile exists; false
534+
* otherwise.
535+
*/
536+
public boolean hasReference() {
537+
return referenceFile.exists();
538+
}
517539
}
Lines changed: 174 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,182 @@
1-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2-
3-
/*
4-
Part of the Processing project - http://processing.org
5-
6-
Copyright (c) 2013 The Processing Foundation
7-
Copyright (c) 2011-12 Ben Fry and Casey Reas
8-
9-
This program is free software; you can redistribute it and/or modify
10-
it under the terms of the GNU General Public License version 2
11-
as published by the Free Software Foundation.
12-
13-
This program is distributed in the hope that it will be useful,
14-
but WITHOUT ANY WARRANTY; without even the implied warranty of
15-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16-
GNU General Public License for more details.
17-
18-
You should have received a copy of the GNU General Public License along
19-
with this program; if not, write to the Free Software Foundation, Inc.
20-
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21-
*/
22-
package processing.app.contrib;
23-
24-
import java.io.*;
25-
import java.net.URLClassLoader;
26-
//import java.net.*;
27-
import java.util.*;
28-
29-
import processing.app.Base;
30-
//import processing.app.Base;
31-
import processing.app.Editor;
32-
import processing.app.tools.Tool;
33-
34-
35-
public class ToolContribution extends LocalContribution implements Tool {
36-
private Tool tool;
37-
38-
39-
static public ToolContribution load(File folder) {
40-
try {
41-
return new ToolContribution(folder);
42-
43-
} catch (IgnorableException ig) {
44-
Base.log(ig.getMessage());
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2013 The Processing Foundation
7+
Copyright (c) 2011-12 Ben Fry and Casey Reas
8+
9+
This program is free software; you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License version 2
11+
as published by the Free Software Foundation.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License along
19+
with this program; if not, write to the Free Software Foundation, Inc.
20+
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
*/
22+
package processing.app.contrib;
23+
24+
import java.io.*;
25+
import java.net.URLClassLoader;
26+
//import java.net.*;
27+
import java.util.*;
28+
29+
import processing.app.Base;
30+
//import processing.app.Base;
31+
import processing.app.Editor;
32+
import processing.app.tools.Tool;
33+
34+
35+
public class ToolContribution extends LocalContribution implements Tool {
36+
private Tool tool;
37+
38+
private File referenceFile; // shortname/reference/index.html
39+
40+
static public ToolContribution load(File folder) {
41+
try {
42+
return new ToolContribution(folder);
43+
} catch (IgnorableException ig) {
44+
Base.log(ig.getMessage());
4545

4646
} catch (VerifyError ve) { // incompatible
4747
// avoid the excessive error spew that happens here
4848

4949
} catch (Throwable e) { // unknown error
5050
e.printStackTrace();
51-
}
52-
return null;
53-
}
54-
55-
51+
}
52+
return null;
53+
}
54+
55+
5656
private ToolContribution(File folder) throws Throwable {
57-
super(folder);
58-
59-
String className = initLoader(null);
60-
if (className != null) {
61-
Class<?> toolClass = loader.loadClass(className);
62-
tool = (Tool) toolClass.newInstance();
63-
}
64-
}
65-
66-
67-
/**
68-
* Method to close the ClassLoader so that the archives are no longer "locked" and
69-
* a tool can be removed without restart.
70-
*/
71-
public void clearClassLoader(Base base) {
72-
try {
73-
((URLClassLoader) this.loader).close();
74-
} catch (IOException e1) {
75-
e1.printStackTrace();
76-
}
77-
Iterator<Editor> editorIter = base.getEditors().iterator();
78-
while (editorIter.hasNext()) {
79-
Editor editor = editorIter.next();
80-
ArrayList<ToolContribution> contribTools = editor.contribTools;
81-
for (ToolContribution toolContrib : contribTools)
82-
if (toolContrib.getName().equals(this.name)) {
83-
try {
84-
((URLClassLoader) toolContrib.loader).close();
85-
editor.contribTools.remove(toolContrib);
86-
break;
87-
} catch (IOException e) {
88-
e.printStackTrace();
89-
}
90-
// base.getActiveEditor().rebuildToolMenu();
91-
}
92-
}
93-
}
94-
95-
96-
// static protected List<File> discover(File folder) {
97-
// File[] folders = listCandidates(folder, "tool");
98-
// if (folders == null) {
99-
// return new ArrayList<File>();
100-
// } else {
101-
// return Arrays.asList(folders);
102-
// }
103-
// }
104-
105-
106-
static public ArrayList<ToolContribution> loadAll(File toolsFolder) {
107-
File[] list = ContributionType.TOOL.listCandidates(toolsFolder);
108-
ArrayList<ToolContribution> outgoing = new ArrayList<ToolContribution>();
109-
// If toolsFolder does not exist or is inaccessible (stranger things have
110-
// happened, and are reported as bugs) list will come back null.
111-
if (list != null) {
112-
for (File folder : list) {
113-
try {
114-
ToolContribution tc = load(folder);
115-
if (tc != null) {
116-
outgoing.add(tc);
117-
}
118-
} catch (Exception e) {
119-
e.printStackTrace();
120-
}
121-
}
122-
}
123-
return outgoing;
124-
}
125-
126-
127-
// Editor editor; // used to send error messages
128-
129-
public void init(Editor editor) {
130-
// try {
131-
// this.editor = editor;
132-
tool.init(editor);
133-
// } catch (NoSuchMethodError nsme) {
134-
// editor.statusError(tool.getMenuTitle() + " is not compatible with this version of Processing");
135-
// nsme.printStackTrace();
136-
// }
137-
}
138-
139-
140-
public void run() {
141-
// try {
142-
tool.run();
143-
// } catch (NoSuchMethodError nsme) {
144-
// editor.statusError(tool.getMenuTitle() + " is not compatible with this version of Processing");
145-
// nsme.printStackTrace();
146-
// }
147-
}
148-
149-
150-
public String getMenuTitle() {
151-
return tool.getMenuTitle();
152-
}
153-
154-
155-
public ContributionType getType() {
156-
return ContributionType.TOOL;
157-
}
57+
super(folder);
58+
59+
String className = initLoader(null);
60+
if (className != null) {
61+
Class<?> toolClass = loader.loadClass(className);
62+
tool = (Tool) toolClass.newInstance();
63+
}
64+
65+
referenceFile = new File(folder, "reference/index.html");
66+
}
67+
68+
69+
/**
70+
* Method to close the ClassLoader so that the archives are no longer "locked" and
71+
* a tool can be removed without restart.
72+
*/
73+
public void clearClassLoader(Base base) {
74+
try {
75+
((URLClassLoader) this.loader).close();
76+
} catch (IOException e1) {
77+
e1.printStackTrace();
78+
}
79+
Iterator<Editor> editorIter = base.getEditors().iterator();
80+
while (editorIter.hasNext()) {
81+
Editor editor = editorIter.next();
82+
ArrayList<ToolContribution> contribTools = editor.contribTools;
83+
for (ToolContribution toolContrib : contribTools)
84+
if (toolContrib.getName().equals(this.name)) {
85+
try {
86+
((URLClassLoader) toolContrib.loader).close();
87+
editor.contribTools.remove(toolContrib);
88+
break;
89+
} catch (IOException e) {
90+
e.printStackTrace();
91+
}
92+
// base.getActiveEditor().rebuildToolMenu();
93+
}
94+
}
95+
}
96+
97+
98+
// static protected List<File> discover(File folder) {
99+
// File[] folders = listCandidates(folder, "tool");
100+
// if (folders == null) {
101+
// return new ArrayList<File>();
102+
// } else {
103+
// return Arrays.asList(folders);
104+
// }
105+
// }
106+
107+
108+
static public ArrayList<ToolContribution> loadAll(File toolsFolder) {
109+
File[] list = ContributionType.TOOL.listCandidates(toolsFolder);
110+
ArrayList<ToolContribution> outgoing = new ArrayList<ToolContribution>();
111+
// If toolsFolder does not exist or is inaccessible (stranger things have
112+
// happened, and are reported as bugs) list will come back null.
113+
if (list != null) {
114+
for (File folder : list) {
115+
try {
116+
ToolContribution tc = load(folder);
117+
if (tc != null) {
118+
outgoing.add(tc);
119+
}
120+
} catch (Exception e) {
121+
e.printStackTrace();
122+
}
123+
}
124+
}
125+
return outgoing;
126+
}
127+
128+
129+
// Editor editor; // used to send error messages
130+
131+
public void init(Editor editor) {
132+
// try {
133+
// this.editor = editor;
134+
tool.init(editor);
135+
// } catch (NoSuchMethodError nsme) {
136+
// editor.statusError(tool.getMenuTitle() + " is not compatible with this version of Processing");
137+
// nsme.printStackTrace();
138+
// }
139+
}
140+
141+
142+
public void run() {
143+
// try {
144+
tool.run();
145+
// } catch (NoSuchMethodError nsme) {
146+
// editor.statusError(tool.getMenuTitle() + " is not compatible with this version of Processing");
147+
// nsme.printStackTrace();
148+
// }
149+
}
150+
151+
152+
public String getMenuTitle() {
153+
return tool.getMenuTitle();
154+
}
155+
156+
157+
public ContributionType getType() {
158+
return ContributionType.TOOL;
159+
}
160+
161+
162+
/**
163+
* Returns the object stored in the referenceFile field, which contains an
164+
* instance of the file object representing the index file of the reference
165+
*
166+
* @return referenceFile
167+
*/
168+
public File getReferenceIndexFile() {
169+
return referenceFile;
170+
}
171+
172+
173+
/**
174+
* Tests whether the reference's index file indicated by referenceFile exists.
175+
*
176+
* @return true if and only if the file denoted by referenceFile exists; false
177+
* otherwise.
178+
*/
179+
public boolean hasReference() {
180+
return referenceFile.exists();
181+
}
158182
}

0 commit comments

Comments
 (0)