Skip to content

Commit 42a5e09

Browse files
author
Christian Lütticke
committed
processing#2 processing-java - JavaModeTESTER hinzugefügt, aufgeräumt, für Aufbau eines separaten Pfades für ENT
1 parent c72c81a commit 42a5e09

1 file changed

Lines changed: 307 additions & 0 deletions

File tree

Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
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) 2010-11 Ben Fry and Casey Reas
7+
Copyright (c) 2012-15 The Processing Foundation
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
19+
along with this program; if not, write to the Free Software Foundation,
20+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
*/
22+
23+
package processing.mode.java;
24+
25+
import java.io.BufferedReader;
26+
import java.io.File;
27+
import java.io.FileReader;
28+
import java.io.IOException;
29+
import java.util.HashMap;
30+
import java.util.HashSet;
31+
import java.util.Map;
32+
import java.util.Set;
33+
34+
import javax.swing.SwingUtilities;
35+
36+
import processing.app.*;
37+
import processing.app.ui.Editor;
38+
import processing.app.ui.EditorException;
39+
import processing.app.ui.EditorState;
40+
import processing.mode.java.runner.Runner;
41+
import processing.mode.java.tweak.SketchParser;
42+
43+
44+
public class JavaModeTESTER extends Mode {
45+
46+
public Editor createEditor(Base base, String path,
47+
EditorState state) throws EditorException {
48+
return new JavaEditor(base, path, state, this);
49+
}
50+
51+
52+
public JavaModeTESTER(Base base, File folder) {
53+
super(base, folder);
54+
55+
// initLogger();
56+
loadPreferences();
57+
}
58+
59+
60+
public String getTitle() {
61+
return "Java";
62+
}
63+
64+
65+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
66+
67+
68+
public File[] getExampleCategoryFolders() {
69+
return new File[] {
70+
new File(examplesFolder, "Basics"),
71+
new File(examplesFolder, "Topics"),
72+
new File(examplesFolder, "Demos"),
73+
new File(examplesFolder, "Books")
74+
};
75+
}
76+
77+
78+
public String getDefaultExtension() {
79+
return "pde";
80+
}
81+
82+
83+
public String[] getExtensions() {
84+
return new String[] { "pde", "java" };
85+
}
86+
87+
88+
public String[] getIgnorable() {
89+
return new String[] {
90+
"applet",
91+
"application.macosx",
92+
"application.windows",
93+
"application.linux"
94+
};
95+
}
96+
97+
98+
public Library getCoreLibrary() {
99+
if (coreLibrary == null) {
100+
File coreFolder = Platform.getContentFile("core");
101+
coreLibrary = new Library(coreFolder);
102+
}
103+
return coreLibrary;
104+
}
105+
106+
107+
108+
/** Handles the standard Java "Run" or "Present" */
109+
public Runner handleLaunch(Sketch sketch, RunnerListener listener,
110+
final boolean present) throws SketchException {
111+
JavaBuild build = new JavaBuild(sketch);
112+
// String appletClassName = build.build(false);
113+
String appletClassName = build.build(true);
114+
if (appletClassName != null) {
115+
final Runner runtime = new Runner(build, listener);
116+
new Thread(new Runnable() {
117+
public void run() {
118+
// these block until finished
119+
if (present) {
120+
runtime.present(null);
121+
} else {
122+
runtime.launch(null);
123+
}
124+
}
125+
}).start();
126+
return runtime;
127+
}
128+
return null;
129+
}
130+
131+
132+
133+
134+
135+
public boolean handleExportApplication(Sketch sketch) throws SketchException, IOException {
136+
JavaBuild build = new JavaBuild(sketch);
137+
return build.exportApplication();
138+
}
139+
140+
141+
/**
142+
* Any modes that extend JavaMode can override this method to add additional
143+
* JARs to be included in the classpath for code completion and error checking
144+
* @return searchPath: file-paths separated by File.pathSeparatorChar
145+
*/
146+
public String getSearchPath() {
147+
return getCoreLibrary().getJarPath();
148+
}
149+
150+
151+
152+
static public volatile boolean errorCheckEnabled = true;
153+
static public volatile boolean warningsEnabled = true;
154+
static public volatile boolean codeCompletionsEnabled = true;
155+
static public volatile boolean debugOutputEnabled = false;
156+
static public volatile boolean errorLogsEnabled = false;
157+
static public volatile boolean autoSaveEnabled = true;
158+
static public volatile boolean autoSavePromptEnabled = true;
159+
static public volatile boolean defaultAutoSaveEnabled = true;
160+
static public volatile boolean ccTriggerEnabled = false;
161+
static public volatile boolean importSuggestEnabled = true;
162+
static public volatile boolean inspectModeHotkeyEnabled = true;
163+
static public int autoSaveInterval = 3; //in minutes
164+
165+
166+
/**
167+
* After how many typed characters, code completion is triggered
168+
*/
169+
volatile public static int codeCompletionTriggerLength = 1;
170+
171+
static public final String prefErrorCheck = "pdex.errorCheckEnabled";
172+
static public final String prefWarnings = "pdex.warningsEnabled";
173+
static public final String prefDebugOP = "pdex.dbgOutput";
174+
static public final String prefErrorLogs = "pdex.writeErrorLogs";
175+
static public final String prefAutoSaveInterval = "pdex.autoSaveInterval";
176+
static public final String prefAutoSave = "pdex.autoSave.autoSaveEnabled";
177+
static public final String prefAutoSavePrompt = "pdex.autoSave.promptDisplay";
178+
static public final String prefDefaultAutoSave = "pdex.autoSave.autoSaveByDefault";
179+
static public final String suggestionsFileName = "suggestions.txt";
180+
181+
static public final String COMPLETION_PREF = "pdex.completion";
182+
static public final String COMPLETION_TRIGGER_PREF = "pdex.completion.trigger";
183+
static public final String SUGGEST_IMPORTS_PREF = "pdex.suggest.imports";
184+
static public final String INSPECT_MODE_HOTKEY_PREF = "pdex.inspectMode.hotkey";
185+
186+
// static volatile public boolean enableTweak = false;
187+
188+
/**
189+
* Stores the white list/black list of allowed/blacklisted imports. These are defined in
190+
* suggestions.txt in java mode folder.
191+
*/
192+
static public final Map<String, Set<String>> suggestionsMap = new HashMap<>();
193+
194+
public void loadPreferences() {
195+
Messages.log("Load PDEX prefs");
196+
ensurePrefsExist();
197+
errorCheckEnabled = Preferences.getBoolean(prefErrorCheck);
198+
warningsEnabled = Preferences.getBoolean(prefWarnings);
199+
codeCompletionsEnabled = Preferences.getBoolean(COMPLETION_PREF);
200+
// DEBUG = Preferences.getBoolean(prefDebugOP);
201+
errorLogsEnabled = Preferences.getBoolean(prefErrorLogs);
202+
autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval);
203+
// untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave);
204+
autoSaveEnabled = Preferences.getBoolean(prefAutoSave);
205+
autoSavePromptEnabled = Preferences.getBoolean(prefAutoSavePrompt);
206+
defaultAutoSaveEnabled = Preferences.getBoolean(prefDefaultAutoSave);
207+
ccTriggerEnabled = Preferences.getBoolean(COMPLETION_TRIGGER_PREF);
208+
importSuggestEnabled = Preferences.getBoolean(SUGGEST_IMPORTS_PREF);
209+
inspectModeHotkeyEnabled = Preferences.getBoolean(INSPECT_MODE_HOTKEY_PREF);
210+
loadSuggestionsMap();
211+
}
212+
213+
214+
public void savePreferences() {
215+
Messages.log("Saving PDEX prefs");
216+
Preferences.setBoolean(prefErrorCheck, errorCheckEnabled);
217+
Preferences.setBoolean(prefWarnings, warningsEnabled);
218+
Preferences.setBoolean(COMPLETION_PREF, codeCompletionsEnabled);
219+
// Preferences.setBoolean(prefDebugOP, DEBUG);
220+
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
221+
Preferences.setInteger(prefAutoSaveInterval, autoSaveInterval);
222+
// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled);
223+
Preferences.setBoolean(prefAutoSave, autoSaveEnabled);
224+
Preferences.setBoolean(prefAutoSavePrompt, autoSavePromptEnabled);
225+
Preferences.setBoolean(prefDefaultAutoSave, defaultAutoSaveEnabled);
226+
Preferences.setBoolean(COMPLETION_TRIGGER_PREF, ccTriggerEnabled);
227+
Preferences.setBoolean(SUGGEST_IMPORTS_PREF, importSuggestEnabled);
228+
Preferences.setBoolean(INSPECT_MODE_HOTKEY_PREF, inspectModeHotkeyEnabled);
229+
}
230+
231+
public void loadSuggestionsMap() {
232+
File suggestionsListFile = new File(getFolder() + File.separator
233+
+ suggestionsFileName);
234+
if (!suggestionsListFile.exists()) {
235+
Messages.loge("Suggestions file not found! "
236+
+ suggestionsListFile.getAbsolutePath());
237+
return;
238+
}
239+
240+
try {
241+
BufferedReader br = new BufferedReader(
242+
new FileReader(suggestionsListFile));
243+
while (true) {
244+
String line = br.readLine();
245+
if (line == null) {
246+
break;
247+
}
248+
line = line.trim();
249+
if (line.startsWith("#")) {
250+
continue;
251+
} else {
252+
if (line.contains("=")) {
253+
String key = line.split("=")[0];
254+
String val = line.split("=")[1];
255+
if (suggestionsMap.containsKey(key)) {
256+
suggestionsMap.get(key).add(val);
257+
} else {
258+
HashSet<String> set = new HashSet<>();
259+
set.add(val);
260+
suggestionsMap.put(key, set);
261+
}
262+
}
263+
}
264+
}
265+
br.close();
266+
} catch (IOException e) {
267+
Messages.loge("IOException while reading suggestions file:"
268+
+ suggestionsListFile.getAbsolutePath());
269+
}
270+
}
271+
272+
273+
public void ensurePrefsExist() {
274+
//TODO: Need to do a better job of managing prefs. Think lists.
275+
if (Preferences.get(prefErrorCheck) == null)
276+
Preferences.setBoolean(prefErrorCheck, errorCheckEnabled);
277+
if (Preferences.get(prefWarnings) == null)
278+
Preferences.setBoolean(prefWarnings, warningsEnabled);
279+
if (Preferences.get(COMPLETION_PREF) == null)
280+
Preferences.setBoolean(COMPLETION_PREF, codeCompletionsEnabled);
281+
if (Preferences.get(prefDebugOP) == null)
282+
// Preferences.setBoolean(prefDebugOP, DEBUG);
283+
if (Preferences.get(prefErrorLogs) == null)
284+
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
285+
if (Preferences.get(prefAutoSaveInterval) == null)
286+
Preferences.setInteger(prefAutoSaveInterval, autoSaveInterval);
287+
// if(Preferences.get(prefUntitledAutoSave) == null)
288+
// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled);
289+
if (Preferences.get(prefAutoSave) == null)
290+
Preferences.setBoolean(prefAutoSave, autoSaveEnabled);
291+
if (Preferences.get(prefAutoSavePrompt) == null)
292+
Preferences.setBoolean(prefAutoSavePrompt, autoSavePromptEnabled);
293+
if (Preferences.get(prefDefaultAutoSave) == null)
294+
Preferences.setBoolean(prefDefaultAutoSave, defaultAutoSaveEnabled);
295+
if (Preferences.get(COMPLETION_TRIGGER_PREF) == null)
296+
Preferences.setBoolean(COMPLETION_TRIGGER_PREF, ccTriggerEnabled);
297+
if (Preferences.get(SUGGEST_IMPORTS_PREF) == null)
298+
Preferences.setBoolean(SUGGEST_IMPORTS_PREF, importSuggestEnabled);
299+
if (Preferences.get(INSPECT_MODE_HOTKEY_PREF) == null)
300+
Preferences.setBoolean(INSPECT_MODE_HOTKEY_PREF, inspectModeHotkeyEnabled);
301+
}
302+
303+
304+
static public void main(String[] args) {
305+
processing.app.Base.main(args);
306+
}
307+
}

0 commit comments

Comments
 (0)