mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
merge ExperimentalMode into JavaMode
This commit is contained in:
@@ -33,48 +33,12 @@ public class JavaEditor extends Editor {
|
||||
protected JavaEditor(Base base, String path, EditorState state, Mode mode) {
|
||||
super(base, path, state, mode);
|
||||
|
||||
// // hopefully these are no longer needed w/ swing
|
||||
// // (har har har.. that was wishful thinking)
|
||||
// listener = new PdeKeyListener(this, textarea);
|
||||
|
||||
jmode = (JavaMode) mode;
|
||||
}
|
||||
|
||||
|
||||
protected JEditTextArea createTextArea() {
|
||||
return new JEditTextArea(new PdeTextAreaDefaults(mode), new JavaInputHandler(this));
|
||||
/*
|
||||
return new JEditTextArea(new PdeTextAreaDefaults(mode), new PdeInputHandler()) {
|
||||
// Forwards key events directly to the input handler. This is slightly
|
||||
// faster than using a KeyListener because some Swing overhead is avoided.
|
||||
PdeKeyListener editorListener = new PdeKeyListener(JavaEditor.this, this);
|
||||
|
||||
// Moved out of JEditTextArea for 3.0a6 to remove dependency on Java Mode
|
||||
public void processKeyEvent(KeyEvent evt) {
|
||||
// this had to be added in Processing 007X, because the menu key
|
||||
// events weren't making it up to the frame.
|
||||
super.processKeyEvent(evt);
|
||||
|
||||
if (inputHandler != null) {
|
||||
switch (evt.getID()) {
|
||||
case KeyEvent.KEY_TYPED:
|
||||
if ((editorListener == null) || !editorListener.keyTyped(evt)) {
|
||||
inputHandler.keyTyped(evt);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEY_PRESSED:
|
||||
if ((editorListener == null) || !editorListener.keyPressed(evt)) {
|
||||
inputHandler.keyPressed(evt);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEY_RELEASED:
|
||||
inputHandler.keyReleased(evt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2010-11 Ben Fry and Casey Reas
|
||||
Copyright (c) 2012-15 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
@@ -23,45 +24,38 @@ package processing.mode.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.runner.Runner;
|
||||
import processing.mode.java.tweak.SketchParser;
|
||||
|
||||
|
||||
public class JavaMode extends Mode {
|
||||
// classpath for all known libraries for p5
|
||||
// (both those in the p5/libs folder and those with lib subfolders
|
||||
// found in the sketchbook)
|
||||
// static public String librariesClassPath;
|
||||
|
||||
|
||||
public Editor createEditor(Base base, String path, EditorState state) {
|
||||
return new JavaEditor(base, path, state, this);
|
||||
return new DebugEditor(base, path, state, this);
|
||||
}
|
||||
|
||||
|
||||
public JavaMode(Base base, File folder) {
|
||||
super(base, folder);
|
||||
|
||||
initLogger();
|
||||
loadPreferences();
|
||||
loadIcons();
|
||||
}
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return "Java (2.0)";
|
||||
return "Java";
|
||||
}
|
||||
|
||||
|
||||
// public EditorToolbar createToolbar(Editor editor) {
|
||||
// return new Toolbar(editor);
|
||||
// }
|
||||
|
||||
|
||||
// public Formatter createFormatter() {
|
||||
// return new AutoFormat();
|
||||
// }
|
||||
|
||||
|
||||
// public Editor createEditor(Base ibase, String path, int[] location) {
|
||||
// }
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
@@ -115,14 +109,42 @@ public class JavaMode extends Mode {
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
public Runner handleRun(Sketch sketch, RunnerListener listener) throws SketchException {
|
||||
public Runner handleRun(Sketch sketch,
|
||||
RunnerListener listener) throws SketchException {
|
||||
final DebugEditor editor = (DebugEditor)listener;
|
||||
editor.errorCheckerService.quickErrorCheck();
|
||||
if (enableTweak) {
|
||||
enableTweak = false;
|
||||
return handleTweak(sketch, listener, false);
|
||||
} else {
|
||||
return handleLaunch(sketch, listener, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Runner handlePresent(Sketch sketch,
|
||||
RunnerListener listener) throws SketchException {
|
||||
final DebugEditor editor = (DebugEditor)listener;
|
||||
editor.errorCheckerService.quickErrorCheck();
|
||||
if (enableTweak) {
|
||||
enableTweak = false;
|
||||
return handleTweak(sketch, listener, true);
|
||||
} else {
|
||||
return handleLaunch(sketch, listener, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Handles the standard Java "Run" or "Present" */
|
||||
public Runner handleLaunch(Sketch sketch, RunnerListener listener,
|
||||
final boolean present) throws SketchException {
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
if (appletClassName != null) {
|
||||
final Runner runtime = new Runner(build, listener);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
runtime.launch(false); // this blocks until finished
|
||||
runtime.launch(present); // this blocks until finished
|
||||
}
|
||||
}).start();
|
||||
return runtime;
|
||||
@@ -131,22 +153,75 @@ public class JavaMode extends Mode {
|
||||
}
|
||||
|
||||
|
||||
public Runner handlePresent(Sketch sketch, RunnerListener listener) throws SketchException {
|
||||
/** Start a sketch in tweak mode */
|
||||
public Runner handleTweak(Sketch sketch,
|
||||
RunnerListener listener,
|
||||
final boolean present) throws SketchException {
|
||||
final DebugEditor editor = (DebugEditor)listener;
|
||||
boolean launchInteractive = false;
|
||||
|
||||
if (isSketchModified(sketch)) {
|
||||
editor.deactivateRun();
|
||||
Base.showMessage("Save", "Please save the sketch before running in Tweak Mode.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// first try to build the unmodified code
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
if (appletClassName == null) {
|
||||
// unmodified build failed, so fail
|
||||
return null;
|
||||
}
|
||||
|
||||
// if compilation passed, modify the code and build again
|
||||
// save the original sketch code of the user
|
||||
editor.initBaseCode();
|
||||
// check for "// tweak" comment in the sketch
|
||||
boolean requiresTweak = SketchParser.containsTweakComment(editor.baseCode);
|
||||
// parse the saved sketch to get all (or only with "//tweak" comment) numbers
|
||||
final SketchParser parser = new SketchParser(editor.baseCode, requiresTweak);
|
||||
|
||||
// add our code to the sketch
|
||||
launchInteractive = editor.automateSketch(sketch, parser.allHandles);
|
||||
|
||||
build = new JavaBuild(sketch);
|
||||
appletClassName = build.build(false);
|
||||
|
||||
if (appletClassName != null) {
|
||||
final Runner runtime = new Runner(build, listener);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
runtime.launch(true);
|
||||
}
|
||||
}).start();
|
||||
public void run() {
|
||||
runtime.launch(present); // this blocks until finished
|
||||
// next lines are executed when the sketch quits
|
||||
editor.initEditorCode(parser.allHandles, false);
|
||||
editor.stopInteractiveMode(parser.allHandles);
|
||||
}
|
||||
}).start();
|
||||
|
||||
if (launchInteractive) {
|
||||
// replace editor code with baseCode
|
||||
editor.initEditorCode(parser.allHandles, false);
|
||||
editor.updateInterface(parser.allHandles, parser.colorBoxes);
|
||||
editor.startInteractiveMode();
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// TODO Why is this necessary? Why isn't Sketch.isModified() used?
|
||||
private boolean isSketchModified(Sketch sketch) {
|
||||
for (SketchCode sc : sketch.getCode()) {
|
||||
if (sc.isModified()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// public void handleStop() {
|
||||
// if (runtime != null) {
|
||||
// runtime.close(); // kills the window
|
||||
@@ -165,4 +240,157 @@ public class JavaMode extends Mode {
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
return build.exportApplication();
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
// Merged from ExperimentalMode
|
||||
|
||||
|
||||
void initLogger() {
|
||||
final boolean VERBOSE_LOGGING = true;
|
||||
final int LOG_SIZE = 512 * 1024; // max log file size (in bytes)
|
||||
|
||||
Logger globalLogger = Logger.getLogger("");
|
||||
//Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); // doesn't work on os x
|
||||
if (VERBOSE_LOGGING) {
|
||||
globalLogger.setLevel(Level.INFO);
|
||||
} else {
|
||||
globalLogger.setLevel(Level.WARNING);
|
||||
}
|
||||
|
||||
// enable logging to file
|
||||
try {
|
||||
// settings is writable for built-in modes, mode folder is not writable
|
||||
File logFolder = Base.getSettingsFile("debug");
|
||||
if (!logFolder.exists()) {
|
||||
logFolder.mkdir();
|
||||
}
|
||||
File logFile = new File(logFolder, "DebugMode.%g.log");
|
||||
Handler handler = new FileHandler(logFile.getAbsolutePath(), LOG_SIZE, 10, false);
|
||||
globalLogger.addHandler(handler);
|
||||
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(JavaMode.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (SecurityException ex) {
|
||||
Logger.getLogger(JavaMode.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ImageIcon classIcon, fieldIcon, methodIcon, localVarIcon;
|
||||
|
||||
protected void loadIcons(){
|
||||
String iconPath = getContentFile("data").getAbsolutePath() + File.separator + "icons";
|
||||
classIcon = new ImageIcon(iconPath + File.separator + "class_obj.png");
|
||||
methodIcon = new ImageIcon(iconPath + File.separator
|
||||
+ "methpub_obj.png");
|
||||
fieldIcon = new ImageIcon(iconPath + File.separator
|
||||
+ "field_protected_obj.png");
|
||||
localVarIcon = new ImageIcon(iconPath + File.separator
|
||||
+ "field_default_obj.png");
|
||||
// log("Icons loaded");
|
||||
}
|
||||
|
||||
|
||||
static public volatile boolean errorCheckEnabled = true;
|
||||
static public volatile boolean warningsEnabled = true;
|
||||
static public volatile boolean codeCompletionsEnabled = true;
|
||||
static public volatile boolean debugOutputEnabled = false;
|
||||
static public volatile boolean errorLogsEnabled = false;
|
||||
static public volatile boolean autoSaveEnabled = true;
|
||||
static public volatile boolean autoSavePromptEnabled = true;
|
||||
static public volatile boolean defaultAutoSaveEnabled = true;
|
||||
static public volatile boolean ccTriggerEnabled = false;
|
||||
static public volatile boolean importSuggestEnabled = true;
|
||||
static public int autoSaveInterval = 3; //in minutes
|
||||
|
||||
|
||||
/**
|
||||
* After how many typed characters, code completion is triggered
|
||||
*/
|
||||
volatile public static int codeCompletionTriggerLength = 1;
|
||||
|
||||
static public final String prefErrorCheck = "pdex.errorCheckEnabled";
|
||||
static public final String prefWarnings = "pdex.warningsEnabled";
|
||||
static public final String prefCodeCompletionEnabled = "pdex.completion";
|
||||
static public final String prefCCTriggerEnabled = "pdex.completion.trigger";
|
||||
static public final String prefDebugOP = "pdex.dbgOutput";
|
||||
static public final String prefErrorLogs = "pdex.writeErrorLogs";
|
||||
static public final String prefAutoSaveInterval = "pdex.autoSaveInterval";
|
||||
static public final String prefAutoSave = "pdex.autoSave.autoSaveEnabled";
|
||||
static public final String prefAutoSavePrompt = "pdex.autoSave.promptDisplay";
|
||||
static public final String prefDefaultAutoSave = "pdex.autoSave.autoSaveByDefault";
|
||||
static public final String prefImportSuggestEnabled = "pdex.importSuggestEnabled";
|
||||
|
||||
static volatile public boolean enableTweak = false;
|
||||
|
||||
|
||||
public void loadPreferences() {
|
||||
Base.log("Load PDEX prefs");
|
||||
ensurePrefsExist();
|
||||
errorCheckEnabled = Preferences.getBoolean(prefErrorCheck);
|
||||
warningsEnabled = Preferences.getBoolean(prefWarnings);
|
||||
codeCompletionsEnabled = Preferences.getBoolean(prefCodeCompletionEnabled);
|
||||
// DEBUG = Preferences.getBoolean(prefDebugOP);
|
||||
errorLogsEnabled = Preferences.getBoolean(prefErrorLogs);
|
||||
autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval);
|
||||
// untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave);
|
||||
autoSaveEnabled = Preferences.getBoolean(prefAutoSave);
|
||||
autoSavePromptEnabled = Preferences.getBoolean(prefAutoSavePrompt);
|
||||
defaultAutoSaveEnabled = Preferences.getBoolean(prefDefaultAutoSave);
|
||||
ccTriggerEnabled = Preferences.getBoolean(prefCCTriggerEnabled);
|
||||
importSuggestEnabled = Preferences.getBoolean(prefImportSuggestEnabled);
|
||||
}
|
||||
|
||||
|
||||
public void savePreferences() {
|
||||
Base.log("Saving PDEX prefs");
|
||||
Preferences.setBoolean(prefErrorCheck, errorCheckEnabled);
|
||||
Preferences.setBoolean(prefWarnings, warningsEnabled);
|
||||
Preferences.setBoolean(prefCodeCompletionEnabled, codeCompletionsEnabled);
|
||||
// Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
|
||||
Preferences.setInteger(prefAutoSaveInterval, autoSaveInterval);
|
||||
// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled);
|
||||
Preferences.setBoolean(prefAutoSave, autoSaveEnabled);
|
||||
Preferences.setBoolean(prefAutoSavePrompt, autoSavePromptEnabled);
|
||||
Preferences.setBoolean(prefDefaultAutoSave, defaultAutoSaveEnabled);
|
||||
Preferences.setBoolean(prefCCTriggerEnabled, ccTriggerEnabled);
|
||||
Preferences.setBoolean(prefImportSuggestEnabled, importSuggestEnabled);
|
||||
}
|
||||
|
||||
|
||||
public void ensurePrefsExist() {
|
||||
//TODO: Need to do a better job of managing prefs. Think lists.
|
||||
if (Preferences.get(prefErrorCheck) == null)
|
||||
Preferences.setBoolean(prefErrorCheck, errorCheckEnabled);
|
||||
if (Preferences.get(prefWarnings) == null)
|
||||
Preferences.setBoolean(prefWarnings, warningsEnabled);
|
||||
if (Preferences.get(prefCodeCompletionEnabled) == null)
|
||||
Preferences.setBoolean(prefCodeCompletionEnabled, codeCompletionsEnabled);
|
||||
if (Preferences.get(prefDebugOP) == null)
|
||||
// Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
if (Preferences.get(prefErrorLogs) == null)
|
||||
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
|
||||
if (Preferences.get(prefAutoSaveInterval) == null)
|
||||
Preferences.setInteger(prefAutoSaveInterval, autoSaveInterval);
|
||||
// if(Preferences.get(prefUntitledAutoSave) == null)
|
||||
// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled);
|
||||
if (Preferences.get(prefAutoSave) == null)
|
||||
Preferences.setBoolean(prefAutoSave, autoSaveEnabled);
|
||||
if (Preferences.get(prefAutoSavePrompt) == null)
|
||||
Preferences.setBoolean(prefAutoSavePrompt, autoSavePromptEnabled);
|
||||
if (Preferences.get(prefDefaultAutoSave) == null)
|
||||
Preferences.setBoolean(prefDefaultAutoSave, defaultAutoSaveEnabled);
|
||||
if (Preferences.get(prefCCTriggerEnabled) == null)
|
||||
Preferences.setBoolean(prefCCTriggerEnabled, ccTriggerEnabled);
|
||||
if (Preferences.get(prefImportSuggestEnabled) == null)
|
||||
Preferences.setBoolean(prefImportSuggestEnabled, importSuggestEnabled);
|
||||
}
|
||||
|
||||
|
||||
static public void main(String[] args) {
|
||||
processing.app.Base.main(args);
|
||||
}
|
||||
}
|
||||
@@ -78,10 +78,10 @@ import processing.app.syntax.JEditTextArea;
|
||||
import processing.app.syntax.PdeTextAreaDefaults;
|
||||
import processing.core.PApplet;
|
||||
import processing.mode.java.JavaEditor;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.pdex.ErrorBar;
|
||||
import processing.mode.java.pdex.ErrorCheckerService;
|
||||
import processing.mode.java.pdex.ErrorMessageSimplifier;
|
||||
import processing.mode.java.pdex.ExperimentalMode;
|
||||
import processing.mode.java.pdex.Problem;
|
||||
import processing.mode.java.pdex.JavaTextArea;
|
||||
import processing.mode.java.pdex.XQConsoleToggle;
|
||||
@@ -135,7 +135,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
|
||||
protected JMenuItem toggleVariableInspectorMenuItem;
|
||||
|
||||
public ExperimentalMode dmode; // the mode
|
||||
public JavaMode dmode; // the mode
|
||||
protected Debugger dbg; // the debugger
|
||||
protected VariableInspector vi; // the variable inspector frame
|
||||
|
||||
@@ -164,7 +164,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
public DebugEditor(Base base, String path, EditorState state, Mode mode) {
|
||||
super(base, path, state, mode);
|
||||
|
||||
dmode = (ExperimentalMode) mode;
|
||||
dmode = (JavaMode) mode;
|
||||
dbg = new Debugger(this);
|
||||
vi = new VariableInspector(this);
|
||||
|
||||
@@ -319,16 +319,16 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
// Added temporarily to dump error log. TODO: Remove this later
|
||||
public void internalCloseRunner(){
|
||||
if(ExperimentalMode.errorLogsEnabled) writeErrorsToFile();
|
||||
// if(autosaver != null && !viewingAutosaveBackup) {
|
||||
// log("stopping autosaver in internalCloseRunner");
|
||||
// autosaver.stop();
|
||||
// }
|
||||
public void internalCloseRunner() {
|
||||
if (JavaMode.errorLogsEnabled) {
|
||||
writeErrorsToFile();
|
||||
}
|
||||
super.internalCloseRunner();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes all error messages to a csv file.
|
||||
* For analytics purposes only.
|
||||
@@ -637,11 +637,11 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
});
|
||||
|
||||
JMenuItem enableTweak = Toolkit.newJMenuItemShift(Language.text("menu.sketch.tweak"), 'T');
|
||||
enableTweak.setSelected(ExperimentalMode.enableTweak);
|
||||
enableTweak.setSelected(JavaMode.enableTweak);
|
||||
enableTweak.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ExperimentalMode.enableTweak = true;
|
||||
JavaMode.enableTweak = true;
|
||||
handleRun();
|
||||
}
|
||||
});
|
||||
@@ -1020,6 +1020,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Access the debugger.
|
||||
*
|
||||
@@ -1029,12 +1030,13 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
return dbg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Access the mode.
|
||||
*
|
||||
* @return the mode object
|
||||
*/
|
||||
public ExperimentalMode mode() {
|
||||
public JavaMode mode() {
|
||||
return dmode;
|
||||
}
|
||||
|
||||
@@ -1063,7 +1065,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
* run/present/etc.
|
||||
*/
|
||||
protected void autoSave() {
|
||||
if (!ExperimentalMode.autoSaveEnabled)
|
||||
if (!JavaMode.autoSaveEnabled)
|
||||
return;
|
||||
|
||||
try {
|
||||
@@ -1076,7 +1078,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// }
|
||||
// else
|
||||
if (sketch.isModified() && !sketch.isUntitled()) {
|
||||
if (ExperimentalMode.autoSavePromptEnabled) {
|
||||
if (JavaMode.autoSavePromptEnabled) {
|
||||
final JDialog autoSaveDialog = new JDialog(
|
||||
base.getActiveEditor(), this.getSketch().getName(),
|
||||
true);
|
||||
@@ -1111,9 +1113,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleSave(true);
|
||||
if (dontRedisplay.isSelected()) {
|
||||
ExperimentalMode.autoSavePromptEnabled = !dontRedisplay
|
||||
.isSelected();
|
||||
ExperimentalMode.defaultAutoSaveEnabled = true;
|
||||
JavaMode.autoSavePromptEnabled = !dontRedisplay.isSelected();
|
||||
JavaMode.defaultAutoSaveEnabled = true;
|
||||
dmode.savePreferences();
|
||||
}
|
||||
autoSaveDialog.dispose();
|
||||
@@ -1126,9 +1127,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (dontRedisplay.isSelected()) {
|
||||
ExperimentalMode.autoSavePromptEnabled = !dontRedisplay
|
||||
.isSelected();
|
||||
ExperimentalMode.defaultAutoSaveEnabled = false;
|
||||
JavaMode.autoSavePromptEnabled = !dontRedisplay.isSelected();
|
||||
JavaMode.defaultAutoSaveEnabled = false;
|
||||
dmode.savePreferences();
|
||||
}
|
||||
autoSaveDialog.dispose();
|
||||
@@ -1151,8 +1151,9 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
.setLocationRelativeTo(base.getActiveEditor());
|
||||
autoSaveDialog.setVisible(true);
|
||||
|
||||
} else if (ExperimentalMode.defaultAutoSaveEnabled)
|
||||
} else if (JavaMode.defaultAutoSaveEnabled) {
|
||||
handleSave(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
statusError(e);
|
||||
@@ -1603,15 +1604,18 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
return errorTable.updateTable(tableModel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle whether the tiny red error indicator is shown near the error button
|
||||
* at the bottom of the PDE
|
||||
*/
|
||||
public void updateErrorToggle(){
|
||||
btnShowErrors.updateMarker(ExperimentalMode.errorCheckEnabled
|
||||
&& errorCheckerService.hasErrors(), errorBar.errorColor);
|
||||
btnShowErrors.updateMarker(JavaMode.errorCheckEnabled &&
|
||||
errorCheckerService.hasErrors(),
|
||||
errorBar.errorColor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle refactor operation
|
||||
*/
|
||||
@@ -1620,6 +1624,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
errorCheckerService.getASTGenerator().handleRefactor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle show usage operation
|
||||
*/
|
||||
@@ -1628,6 +1633,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
errorCheckerService.getASTGenerator().handleShowUsage();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the sketch contains java tabs. If it does, the editor ain't built
|
||||
* for it, yet. Also, user should really start looking at more powerful IDEs
|
||||
@@ -1647,17 +1653,19 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyPreferences() {
|
||||
super.applyPreferences();
|
||||
if (dmode != null) {
|
||||
dmode.loadPreferences();
|
||||
Base.log("Applying prefs");
|
||||
// trigger it once to refresh UI
|
||||
errorCheckerService.runManualErrorCheck();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void applyPreferences() {
|
||||
super.applyPreferences();
|
||||
if (dmode != null) {
|
||||
dmode.loadPreferences();
|
||||
Base.log("Applying prefs");
|
||||
// trigger it once to refresh UI
|
||||
errorCheckerService.runManualErrorCheck();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TweakMode code
|
||||
/**
|
||||
* Show warnings menu item
|
||||
|
||||
@@ -61,7 +61,7 @@ import org.netbeans.swing.outline.RowModel;
|
||||
|
||||
import com.sun.jdi.Value;
|
||||
|
||||
import processing.mode.java.pdex.ExperimentalMode;
|
||||
import processing.mode.java.JavaMode;
|
||||
|
||||
|
||||
/**
|
||||
@@ -270,7 +270,7 @@ public class VariableInspector extends JFrame {
|
||||
* null if the file wasn't found.
|
||||
*/
|
||||
protected ImageIcon[][] loadIcons(String fileName) {
|
||||
ExperimentalMode mode = editor.mode();
|
||||
JavaMode mode = editor.mode();
|
||||
File file = mode.getContentFile(fileName);
|
||||
if (!file.exists()) {
|
||||
Logger.getLogger(OutlineRenderer.class.getName()).log(Level.SEVERE, "icon file not found: {0}", file.getAbsolutePath());
|
||||
|
||||
@@ -111,6 +111,7 @@ import processing.app.Base;
|
||||
import processing.app.Library;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.Toolkit;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.preproc.PdePreprocessor;
|
||||
|
||||
@@ -818,8 +819,8 @@ public class ASTGenerator {
|
||||
public void preparePredictions(final String word, final int line, final int lineStartNonWSOffset) {
|
||||
if(predictionOngoing.get()) return;
|
||||
|
||||
if(!ExperimentalMode.codeCompletionsEnabled) return;
|
||||
if(word.length() < predictionMinLength) return;
|
||||
if (!JavaMode.codeCompletionsEnabled) return;
|
||||
if (word.length() < predictionMinLength) return;
|
||||
|
||||
predictionOngoing.set(true);
|
||||
// This method is called from TextArea.fetchPhrase, which is called via a SwingWorker instance
|
||||
|
||||
@@ -37,6 +37,7 @@ import javax.swing.text.BadLocationException;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.SketchCode;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
|
||||
/**
|
||||
@@ -129,7 +130,7 @@ public class ErrorBar extends JPanel {
|
||||
}
|
||||
|
||||
|
||||
public ErrorBar(DebugEditor editor, int height, ExperimentalMode mode) {
|
||||
public ErrorBar(DebugEditor editor, int height, JavaMode mode) {
|
||||
this.editor = editor;
|
||||
this.preferredHeight = height;
|
||||
this.errorCheckerService = editor.errorCheckerService;
|
||||
|
||||
@@ -54,6 +54,7 @@ import processing.app.Library;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.syntax.SyntaxDocument;
|
||||
import processing.core.PApplet;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.preproc.PdePreprocessor;
|
||||
|
||||
@@ -375,6 +376,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
protected void updateSketchCodeListeners() {
|
||||
for (final SketchCode sc : editor.getSketch().getCode()) {
|
||||
boolean flag = false;
|
||||
@@ -394,20 +396,23 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void checkForMissingImports() {
|
||||
if(!ExperimentalMode.importSuggestEnabled) return;
|
||||
for (Problem p : problemsList) {
|
||||
if(p.getIProblem().getID() == IProblem.UndefinedType) {
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
Base.log("Will suggest for type:" + missingClass);
|
||||
//astGenerator.suggestImports(missingClass);
|
||||
if (JavaMode.importSuggestEnabled) {
|
||||
for (Problem p : problemsList) {
|
||||
if(p.getIProblem().getID() == IProblem.UndefinedType) {
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
Base.log("Will suggest for type:" + missingClass);
|
||||
//astGenerator.suggestImports(missingClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected ASTGenerator astGenerator;
|
||||
|
||||
public ASTGenerator getASTGenerator() {
|
||||
@@ -454,7 +459,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (ExperimentalMode.errorCheckEnabled){
|
||||
if (JavaMode.errorCheckEnabled) {
|
||||
runManualErrorCheck();
|
||||
//log("doc insert update, man error check..");
|
||||
}
|
||||
@@ -462,7 +467,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
if (ExperimentalMode.errorCheckEnabled){
|
||||
if (JavaMode.errorCheckEnabled){
|
||||
runManualErrorCheck();
|
||||
//log("doc remove update, man error check..");
|
||||
}
|
||||
@@ -470,7 +475,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
if (ExperimentalMode.errorCheckEnabled){
|
||||
if (JavaMode.errorCheckEnabled){
|
||||
runManualErrorCheck();
|
||||
//log("doc changed update, man error check..");
|
||||
}
|
||||
@@ -515,7 +520,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
astGenerator.buildAST(cu);
|
||||
if(!ExperimentalMode.errorCheckEnabled){
|
||||
if (!JavaMode.errorCheckEnabled) {
|
||||
problemsList.clear();
|
||||
Base.log("Error Check disabled, so not updating UI.");
|
||||
}
|
||||
@@ -703,7 +708,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
// If warnings are disabled, skip 'em
|
||||
if (p.isWarning() && !ExperimentalMode.warningsEnabled) {
|
||||
if (p.isWarning() && !JavaMode.warningsEnabled) {
|
||||
continue;
|
||||
}
|
||||
problemsList.add(p);
|
||||
@@ -1008,30 +1013,29 @@ public class ErrorCheckerService implements Runnable {
|
||||
tempErrorLog.put(problemsList.get(i).getMessage(), problemsList
|
||||
.get(i).getIProblem());
|
||||
|
||||
if(!ExperimentalMode.importSuggestEnabled) continue;
|
||||
Problem p = problemsList.get(i);
|
||||
if(p.getIProblem().getID() == IProblem.UndefinedType) {
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
// log("Will suggest for type:" + missingClass);
|
||||
//astGenerator.suggestImports(missingClass);
|
||||
String[] si = astGenerator.getSuggestImports(missingClass);
|
||||
if(si != null && si.length > 0){
|
||||
p.setImportSuggestions(si);
|
||||
errorData[i][0] = "<html>"
|
||||
+ problemsList.get(i).getMessage()
|
||||
+ " (<font color=#0000ff><u>Import Suggestions available</u></font>)</html>";
|
||||
if (JavaMode.importSuggestEnabled) {
|
||||
Problem p = problemsList.get(i);
|
||||
if(p.getIProblem().getID() == IProblem.UndefinedType) {
|
||||
String args[] = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
// log("Will suggest for type:" + missingClass);
|
||||
//astGenerator.suggestImports(missingClass);
|
||||
String[] si = astGenerator.getSuggestImports(missingClass);
|
||||
if(si != null && si.length > 0){
|
||||
p.setImportSuggestions(si);
|
||||
errorData[i][0] = "<html>"
|
||||
+ problemsList.get(i).getMessage()
|
||||
+ " (<font color=#0000ff><u>Import Suggestions available</u></font>)</html>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DefaultTableModel tm = new DefaultTableModel(errorData,
|
||||
XQErrorTable.columnNames);
|
||||
// Update error table in the editor
|
||||
DefaultTableModel tm =
|
||||
new DefaultTableModel(errorData, XQErrorTable.columnNames);
|
||||
editor.updateTable(tm);
|
||||
|
||||
/*
|
||||
@@ -1063,10 +1067,9 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Repaints the textarea if required
|
||||
*/
|
||||
/** Repaints the textarea if required */
|
||||
public void updatePaintedThingys() {
|
||||
currentTab = editor.getSketch().getCodeIndex(
|
||||
editor.getSketch().getCurrentCode());
|
||||
@@ -1088,27 +1091,23 @@ public class ErrorCheckerService implements Runnable {
|
||||
* line or not
|
||||
*/
|
||||
public void updateEditorStatus() {
|
||||
if (editor.getStatusMode() == EditorStatus.EDIT) return;
|
||||
|
||||
if(editor.getStatusMode() == EditorStatus.EDIT) return;
|
||||
// editor.statusNotice("Position: " +
|
||||
// editor.getTextArea().getCaretLine());
|
||||
if(ExperimentalMode.errorCheckEnabled)
|
||||
synchronized (editor.errorBar.errorPoints) {
|
||||
for (ErrorMarker emarker : editor.errorBar.errorPoints) {
|
||||
if (emarker.getProblem().getLineNumber() == editor.getTextArea()
|
||||
.getCaretLine()) {
|
||||
if (emarker.getType() == ErrorMarker.Warning) {
|
||||
editor.statusMessage(emarker.getProblem().getMessage(),
|
||||
if (JavaMode.errorCheckEnabled) {
|
||||
synchronized (editor.errorBar.errorPoints) {
|
||||
for (ErrorMarker emarker : editor.errorBar.errorPoints) {
|
||||
if (emarker.getProblem().getLineNumber() == editor.getTextArea().getCaretLine()) {
|
||||
if (emarker.getType() == ErrorMarker.Warning) {
|
||||
editor.statusMessage(emarker.getProblem().getMessage(),
|
||||
DebugEditor.STATUS_INFO);
|
||||
//+ " : " + errorMsgSimplifier.getIDName(emarker.problem.getIProblem().getID()));
|
||||
//TODO: this is temporary
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
editor.statusMessage(emarker.getProblem().getMessage(),
|
||||
DebugEditor.STATUS_COMPILER_ERR);
|
||||
//+ " : " + errorMsgSimplifier.getIDName(emarker.problem.getIProblem().getID()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1123,6 +1122,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
// lastCaretLine = editor.ta.getCaretLine();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Maps offset from java code to pde code. Returns a bunch of offsets as array
|
||||
@@ -1707,7 +1707,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
}
|
||||
|
||||
public void handleErrorCheckingToggle(){
|
||||
if (!ExperimentalMode.errorCheckEnabled) {
|
||||
if (!JavaMode.errorCheckEnabled) {
|
||||
// unticked Menu Item
|
||||
// pauseThread();
|
||||
Base.log(editor.getSketch().getName()
|
||||
|
||||
@@ -1,461 +0,0 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
Copyright (c) 2012-15 The Processing Foundation
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import processing.mode.java.tweak.SketchParser;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.mode.java.*;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.runner.Runner;
|
||||
|
||||
|
||||
/**
|
||||
* Experimental Mode for Processing, combines Debug Mode and XQMode and
|
||||
* starts us working toward our next generation editor/debugger setup.
|
||||
*/
|
||||
public class ExperimentalMode extends JavaMode {
|
||||
public static final boolean VERBOSE_LOGGING = true;
|
||||
//public static final boolean VERBOSE_LOGGING = false;
|
||||
public static final int LOG_SIZE = 512 * 1024; // max log file size (in bytes)
|
||||
// public static boolean DEBUG = !true;
|
||||
|
||||
|
||||
public ExperimentalMode(Base base, File folder) {
|
||||
super(base, folder);
|
||||
|
||||
// [removed by fry 150120]
|
||||
// // use libraries folder from javamode. will make sketches using core libraries work, as well as import libraries and examples menus
|
||||
// for (Mode m : base.getModeList()) {
|
||||
// if (m.getClass() == JavaMode.class) {
|
||||
// JavaMode jMode = (JavaMode) m;
|
||||
// librariesFolder = jMode.getLibrariesFolder();
|
||||
// rebuildLibraryList();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Fetch examples and reference from java mode
|
||||
// // thx to Manindra (https://github.com/martinleopold/DebugMode/issues/4)
|
||||
// examplesFolder = Base.getContentFile("modes/java/examples");
|
||||
// // https://github.com/martinleopold/DebugMode/issues/6
|
||||
// referenceFolder = Base.getContentFile("modes/java/reference");
|
||||
|
||||
// set logging level
|
||||
Logger globalLogger = Logger.getLogger("");
|
||||
//Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME); // doesn't work on os x
|
||||
if (VERBOSE_LOGGING) {
|
||||
globalLogger.setLevel(Level.INFO);
|
||||
} else {
|
||||
globalLogger.setLevel(Level.WARNING);
|
||||
}
|
||||
|
||||
// enable logging to file
|
||||
try {
|
||||
// settings is writable for built-in modes, mode folder is not writable
|
||||
File logFolder = Base.getSettingsFile("debug");
|
||||
if (!logFolder.exists()) {
|
||||
logFolder.mkdir();
|
||||
}
|
||||
File logFile = new File(logFolder, "DebugMode.%g.log");
|
||||
Handler handler = new FileHandler(logFile.getAbsolutePath(), LOG_SIZE, 10, false);
|
||||
globalLogger.addHandler(handler);
|
||||
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ExperimentalMode.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (SecurityException ex) {
|
||||
Logger.getLogger(ExperimentalMode.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
// disable initial chattiness for now
|
||||
// // output version from manifest file
|
||||
// Package p = ExperimentalMode.class.getPackage();
|
||||
// String titleAndVersion = p.getImplementationTitle() + " (v" + p.getImplementationVersion() + ")";
|
||||
// //log(titleAndVersion);
|
||||
// Logger.getLogger(ExperimentalMode.class.getName()).log(Level.INFO, titleAndVersion);
|
||||
loadPreferences();
|
||||
loadIcons();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
//return "PDE X";
|
||||
return "Java";
|
||||
}
|
||||
|
||||
|
||||
public File[] getKeywordFiles() {
|
||||
return new File[] {
|
||||
Base.getContentFile("modes/java/keywords.txt")
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public File getContentFile(String path) {
|
||||
File file = new File(folder, path);
|
||||
if (!file.exists()) {
|
||||
// check to see if it's part of the parent Java Mode
|
||||
file = new File(Base.getContentFile("modes/java"), path);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
volatile public static boolean errorCheckEnabled = true,
|
||||
warningsEnabled = true, codeCompletionsEnabled = true,
|
||||
debugOutputEnabled = false, errorLogsEnabled = false,
|
||||
autoSaveEnabled = true, autoSavePromptEnabled = true,
|
||||
defaultAutoSaveEnabled = true, // ,untitledAutoSaveEnabled;
|
||||
ccTriggerEnabled = false, importSuggestEnabled = true;
|
||||
public static int autoSaveInterval = 3; //in minutes
|
||||
|
||||
|
||||
/**
|
||||
* After how many typed characters, code completion is triggered
|
||||
*/
|
||||
volatile public static int codeCompletionTriggerLength = 1;
|
||||
|
||||
static public final String prefErrorCheck = "pdex.errorCheckEnabled";
|
||||
static public final String prefWarnings = "pdex.warningsEnabled";
|
||||
static public final String prefCodeCompletionEnabled = "pdex.completion";
|
||||
static public final String prefCCTriggerEnabled = "pdex.completion.trigger";
|
||||
static public final String prefDebugOP = "pdex.dbgOutput";
|
||||
static public final String prefErrorLogs = "pdex.writeErrorLogs";
|
||||
static public final String prefAutoSaveInterval = "pdex.autoSaveInterval";
|
||||
static public final String prefAutoSave = "pdex.autoSave.autoSaveEnabled";
|
||||
static public final String prefAutoSavePrompt = "pdex.autoSave.promptDisplay";
|
||||
static public final String prefDefaultAutoSave = "pdex.autoSave.autoSaveByDefault";
|
||||
static public final String prefImportSuggestEnabled = "pdex.importSuggestEnabled";
|
||||
|
||||
static volatile public boolean enableTweak = false;
|
||||
|
||||
|
||||
public void loadPreferences() {
|
||||
Base.log("Load PDEX prefs");
|
||||
ensurePrefsExist();
|
||||
errorCheckEnabled = Preferences.getBoolean(prefErrorCheck);
|
||||
warningsEnabled = Preferences.getBoolean(prefWarnings);
|
||||
codeCompletionsEnabled = Preferences.getBoolean(prefCodeCompletionEnabled);
|
||||
// DEBUG = Preferences.getBoolean(prefDebugOP);
|
||||
errorLogsEnabled = Preferences.getBoolean(prefErrorLogs);
|
||||
autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval);
|
||||
// untitledAutoSaveEnabled = Preferences.getBoolean(prefUntitledAutoSave);
|
||||
autoSaveEnabled = Preferences.getBoolean(prefAutoSave);
|
||||
autoSavePromptEnabled = Preferences.getBoolean(prefAutoSavePrompt);
|
||||
defaultAutoSaveEnabled = Preferences.getBoolean(prefDefaultAutoSave);
|
||||
ccTriggerEnabled = Preferences.getBoolean(prefCCTriggerEnabled);
|
||||
importSuggestEnabled = Preferences.getBoolean(prefImportSuggestEnabled);
|
||||
}
|
||||
|
||||
|
||||
public void savePreferences() {
|
||||
Base.log("Saving PDEX prefs");
|
||||
Preferences.setBoolean(prefErrorCheck, errorCheckEnabled);
|
||||
Preferences.setBoolean(prefWarnings, warningsEnabled);
|
||||
Preferences.setBoolean(prefCodeCompletionEnabled, codeCompletionsEnabled);
|
||||
// Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
|
||||
Preferences.setInteger(prefAutoSaveInterval, autoSaveInterval);
|
||||
// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled);
|
||||
Preferences.setBoolean(prefAutoSave, autoSaveEnabled);
|
||||
Preferences.setBoolean(prefAutoSavePrompt, autoSavePromptEnabled);
|
||||
Preferences.setBoolean(prefDefaultAutoSave, defaultAutoSaveEnabled);
|
||||
Preferences.setBoolean(prefCCTriggerEnabled, ccTriggerEnabled);
|
||||
Preferences.setBoolean(prefImportSuggestEnabled, importSuggestEnabled);
|
||||
}
|
||||
|
||||
|
||||
public void ensurePrefsExist() {
|
||||
//TODO: Need to do a better job of managing prefs. Think lists.
|
||||
if (Preferences.get(prefErrorCheck) == null)
|
||||
Preferences.setBoolean(prefErrorCheck, errorCheckEnabled);
|
||||
if (Preferences.get(prefWarnings) == null)
|
||||
Preferences.setBoolean(prefWarnings, warningsEnabled);
|
||||
if (Preferences.get(prefCodeCompletionEnabled) == null)
|
||||
Preferences.setBoolean(prefCodeCompletionEnabled, codeCompletionsEnabled);
|
||||
if (Preferences.get(prefDebugOP) == null)
|
||||
// Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
if (Preferences.get(prefErrorLogs) == null)
|
||||
Preferences.setBoolean(prefErrorLogs, errorLogsEnabled);
|
||||
if (Preferences.get(prefAutoSaveInterval) == null)
|
||||
Preferences.setInteger(prefAutoSaveInterval, autoSaveInterval);
|
||||
// if(Preferences.get(prefUntitledAutoSave) == null)
|
||||
// Preferences.setBoolean(prefUntitledAutoSave,untitledAutoSaveEnabled);
|
||||
if (Preferences.get(prefAutoSave) == null)
|
||||
Preferences.setBoolean(prefAutoSave, autoSaveEnabled);
|
||||
if (Preferences.get(prefAutoSavePrompt) == null)
|
||||
Preferences.setBoolean(prefAutoSavePrompt, autoSavePromptEnabled);
|
||||
if (Preferences.get(prefDefaultAutoSave) == null)
|
||||
Preferences.setBoolean(prefDefaultAutoSave, defaultAutoSaveEnabled);
|
||||
if (Preferences.get(prefCCTriggerEnabled) == null)
|
||||
Preferences.setBoolean(prefCCTriggerEnabled, ccTriggerEnabled);
|
||||
if (Preferences.get(prefImportSuggestEnabled) == null)
|
||||
Preferences.setBoolean(prefImportSuggestEnabled, importSuggestEnabled);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new editor associated with this mode.
|
||||
*/
|
||||
@Override
|
||||
public Editor createEditor(Base base, String path, EditorState state) {
|
||||
return new DebugEditor(base, path, state, this);
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * Load a String value from theme.txt
|
||||
// *
|
||||
// * @param attribute the attribute key to load
|
||||
// * @param defaultValue the default value
|
||||
// * @return the attributes value, or the default value if the attribute
|
||||
// * couldn't be loaded
|
||||
// */
|
||||
// public String loadThemeString(String attribute, String defaultValue) {
|
||||
// String newString = theme.get(attribute);
|
||||
// if (newString != null) {
|
||||
// return newString;
|
||||
// }
|
||||
// Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error loading String: {0}", attribute);
|
||||
// return defaultValue;
|
||||
// }
|
||||
|
||||
|
||||
// /**
|
||||
// * Load a Color value from theme.txt
|
||||
// *
|
||||
// * @param attribute the attribute key to load
|
||||
// * @param defaultValue the default value
|
||||
// * @return the attributes value, or the default value if the attribute
|
||||
// * couldn't be loaded
|
||||
// */
|
||||
// public Color getThemeColor(String attribute, Color defaultValue) {
|
||||
// Color newColor = theme.getColor(attribute);
|
||||
// if (newColor != null) {
|
||||
// return newColor;
|
||||
// }
|
||||
// log("error loading color: " + attribute);
|
||||
// Logger.getLogger(ExperimentalMode.class.getName()).log(Level.WARNING, "Error loading Color: {0}", attribute);
|
||||
// return defaultValue;
|
||||
// }
|
||||
|
||||
|
||||
protected ImageIcon classIcon, fieldIcon, methodIcon, localVarIcon;
|
||||
|
||||
protected void loadIcons(){
|
||||
String iconPath = getContentFile("data").getAbsolutePath() + File.separator + "icons";
|
||||
classIcon = new ImageIcon(iconPath + File.separator + "class_obj.png");
|
||||
methodIcon = new ImageIcon(iconPath + File.separator
|
||||
+ "methpub_obj.png");
|
||||
fieldIcon = new ImageIcon(iconPath + File.separator
|
||||
+ "field_protected_obj.png");
|
||||
localVarIcon = new ImageIcon(iconPath + File.separator
|
||||
+ "field_default_obj.png");
|
||||
// log("Icons loaded");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public ClassLoader getJavaModeClassLoader() {
|
||||
for (Mode m : base.getModeList()) {
|
||||
if (m.getClass() == JavaMode.class) {
|
||||
JavaMode jMode = (JavaMode) m;
|
||||
return jMode.getClassLoader();
|
||||
}
|
||||
}
|
||||
// badness
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// /**
|
||||
// * System.out.println()
|
||||
// */
|
||||
// public static final void log(Object message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// System.out.println(message);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * System.err.println()
|
||||
// */
|
||||
// public static final void logE(Object message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// System.err.println(message);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * System.out.print
|
||||
// */
|
||||
// public static final void log2(Object message){
|
||||
// if(ExperimentalMode.DEBUG)
|
||||
// System.out.print(message);
|
||||
// }
|
||||
|
||||
|
||||
public String[] getIgnorable() {
|
||||
return new String[] {
|
||||
"applet",
|
||||
"application.macosx",
|
||||
"application.windows",
|
||||
"application.linux",
|
||||
"_autosave"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// TweakMode code
|
||||
@Override
|
||||
public Runner handleRun(Sketch sketch,
|
||||
RunnerListener listener) throws SketchException {
|
||||
final DebugEditor editor = (DebugEditor)listener;
|
||||
editor.errorCheckerService.quickErrorCheck();
|
||||
if (enableTweak) {
|
||||
enableTweak = false;
|
||||
return handleTweakPresentOrRun(sketch, listener, false);
|
||||
} else {
|
||||
// Do the usual (JavaMode style)
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
if (appletClassName != null) {
|
||||
final Runner runtime = new Runner(build, listener);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
runtime.launch(false); // this blocks until finished
|
||||
}
|
||||
}).start();
|
||||
return runtime;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Runner handlePresent(Sketch sketch,
|
||||
RunnerListener listener) throws SketchException {
|
||||
final DebugEditor editor = (DebugEditor)listener;
|
||||
editor.errorCheckerService.quickErrorCheck();
|
||||
if (enableTweak) {
|
||||
enableTweak = false;
|
||||
return handleTweakPresentOrRun(sketch, listener, true);
|
||||
} else {
|
||||
/* Do the usual (JavaMode style) */
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
if (appletClassName != null) {
|
||||
final Runner runtime = new Runner(build, listener);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
runtime.launch(true);
|
||||
}
|
||||
}).start();
|
||||
return runtime;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Runner handleTweakPresentOrRun(Sketch sketch,
|
||||
RunnerListener listener,
|
||||
boolean present) throws SketchException {
|
||||
final DebugEditor editor = (DebugEditor)listener;
|
||||
final boolean toPresent = present;
|
||||
boolean launchInteractive = false;
|
||||
|
||||
if (isSketchModified(sketch)) {
|
||||
editor.deactivateRun();
|
||||
Base.showMessage("Save", "Please save the sketch before running in Tweak Mode.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// first try to build the unmodified code
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
if (appletClassName == null) {
|
||||
// unmodified build failed, so fail
|
||||
return null;
|
||||
}
|
||||
|
||||
// if compilation passed, modify the code and build again
|
||||
// save the original sketch code of the user
|
||||
editor.initBaseCode();
|
||||
// check for "// tweak" comment in the sketch
|
||||
boolean requiresTweak = SketchParser.containsTweakComment(editor.baseCode);
|
||||
// parse the saved sketch to get all (or only with "//tweak" comment) numbers
|
||||
final SketchParser parser = new SketchParser(editor.baseCode, requiresTweak);
|
||||
|
||||
// add our code to the sketch
|
||||
launchInteractive = editor.automateSketch(sketch, parser.allHandles);
|
||||
|
||||
build = new JavaBuild(sketch);
|
||||
appletClassName = build.build(false);
|
||||
|
||||
if (appletClassName != null) {
|
||||
final Runner runtime = new Runner(build, listener);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
runtime.launch(toPresent); // this blocks until finished
|
||||
// executed when the sketch quits
|
||||
editor.initEditorCode(parser.allHandles, false);
|
||||
editor.stopInteractiveMode(parser.allHandles);
|
||||
}
|
||||
}).start();
|
||||
|
||||
if (launchInteractive) {
|
||||
// replace editor code with baseCode
|
||||
editor.initEditorCode(parser.allHandles, false);
|
||||
editor.updateInterface(parser.allHandles, parser.colorBoxes);
|
||||
editor.startInteractiveMode();
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private boolean isSketchModified(Sketch sketch) {
|
||||
for (SketchCode sc : sketch.getCode()) {
|
||||
if (sc.isModified()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static public void main(String[] args) {
|
||||
processing.app.Base.main(args);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import processing.mode.java.JavaInputHandler;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.tweak.ColorControlBox;
|
||||
import processing.mode.java.tweak.Handle;
|
||||
@@ -155,7 +156,7 @@ public class JavaTextArea extends JEditTextArea {
|
||||
* @param mode
|
||||
*/
|
||||
public void setECSandThemeforTextArea(ErrorCheckerService ecs,
|
||||
ExperimentalMode mode) {
|
||||
JavaMode mode) {
|
||||
errorCheckerService = ecs;
|
||||
getCustomPainter().setECSandTheme(ecs, mode);
|
||||
}
|
||||
@@ -245,17 +246,17 @@ public class JavaTextArea extends JEditTextArea {
|
||||
final KeyEvent evt2 = evt;
|
||||
|
||||
if (keyChar == '.') {
|
||||
if (ExperimentalMode.codeCompletionsEnabled) {
|
||||
if (JavaMode.codeCompletionsEnabled) {
|
||||
Base.log("[KeyEvent]" + KeyEvent.getKeyText(evt2.getKeyCode()) + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt2));
|
||||
}
|
||||
} else if (keyChar == ' ') { // Trigger on Ctrl-Space
|
||||
if (!Base.isMacOS() && ExperimentalMode.codeCompletionsEnabled &&
|
||||
if (!Base.isMacOS() && JavaMode.codeCompletionsEnabled &&
|
||||
(evt.isControlDown() || evt.isMetaDown())) {
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
protected Object doInBackground() throws Exception {
|
||||
// Provide completions only if it's enabled
|
||||
if (ExperimentalMode.codeCompletionsEnabled) {
|
||||
if (JavaMode.codeCompletionsEnabled) {
|
||||
getDocument().remove(getCaretPosition() - 1, 1); // Remove the typed space
|
||||
Base.log("[KeyEvent]" + evt2.getKeyChar() + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt2));
|
||||
@@ -268,7 +269,7 @@ public class JavaTextArea extends JEditTextArea {
|
||||
hideSuggestion(); // hide on spacebar
|
||||
}
|
||||
} else {
|
||||
if(ExperimentalMode.codeCompletionsEnabled) {
|
||||
if (JavaMode.codeCompletionsEnabled) {
|
||||
prepareSuggestions(evt2);
|
||||
}
|
||||
}
|
||||
@@ -280,7 +281,7 @@ public class JavaTextArea extends JEditTextArea {
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
protected Object doInBackground() throws Exception {
|
||||
// Provide completions only if it's enabled
|
||||
if (ExperimentalMode.codeCompletionsEnabled) {
|
||||
if (JavaMode.codeCompletionsEnabled) {
|
||||
Base.log("[KeyEvent]" + KeyEvent.getKeyText(evt2.getKeyCode()) + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt2));
|
||||
}
|
||||
@@ -291,16 +292,16 @@ public class JavaTextArea extends JEditTextArea {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Kickstart auto-complete suggestions
|
||||
* @param evt - KeyEvent
|
||||
*/
|
||||
private void prepareSuggestions(final KeyEvent evt){
|
||||
SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {
|
||||
protected Object doInBackground() throws Exception {
|
||||
// Provide completions only if it's enabled
|
||||
if (ExperimentalMode.codeCompletionsEnabled
|
||||
&& (ExperimentalMode.ccTriggerEnabled || suggestion.isVisible())) {
|
||||
if (JavaMode.codeCompletionsEnabled &&
|
||||
(JavaMode.ccTriggerEnabled || suggestion.isVisible())) {
|
||||
Base.log("[KeyEvent]" + evt.getKeyChar() + " |Prediction started");
|
||||
Base.log("Typing: " + fetchPhrase(evt));
|
||||
}
|
||||
@@ -310,6 +311,7 @@ public class JavaTextArea extends JEditTextArea {
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the word on which the mouse pointer is present
|
||||
* @param evt - the MouseEvent which triggered this method
|
||||
@@ -495,7 +497,7 @@ public class JavaTextArea extends JEditTextArea {
|
||||
// if (word.endsWith("."))
|
||||
// word = word.substring(0, word.length() - 1);
|
||||
int lineStartNonWSOffset = 0;
|
||||
if (word.length() >= ExperimentalMode.codeCompletionTriggerLength) {
|
||||
if (word.length() >= JavaMode.codeCompletionTriggerLength) {
|
||||
errorCheckerService.getASTGenerator()
|
||||
.preparePredictions(word, line + errorCheckerService.mainClassOffset,
|
||||
lineStartNonWSOffset);
|
||||
@@ -504,6 +506,7 @@ public class JavaTextArea extends JEditTextArea {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the total width of the gutter area.
|
||||
*
|
||||
@@ -515,10 +518,6 @@ public class JavaTextArea extends JEditTextArea {
|
||||
}
|
||||
|
||||
FontMetrics fm = painter.getFontMetrics();
|
||||
// log("fm: " + (fm == null));
|
||||
// log("editor: " + (editor == null));
|
||||
//log("BPBPBPBPB: " + (editor.breakpointMarker == null));
|
||||
|
||||
int textWidth = Math.max(fm.stringWidth(breakpointMarker),
|
||||
fm.stringWidth(currentLineMarker));
|
||||
return textWidth + 2 * gutterPadding;
|
||||
|
||||
@@ -20,6 +20,7 @@ along with this program; if not, write to the Free Software Foundation, Inc.
|
||||
|
||||
package processing.mode.java.pdex;
|
||||
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.debug.DebugEditor;
|
||||
import processing.mode.java.tweak.*;
|
||||
|
||||
@@ -41,6 +42,7 @@ import java.util.List;
|
||||
//import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
||||
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Segment;
|
||||
import javax.swing.text.Utilities;
|
||||
@@ -440,7 +442,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
* @param ecs
|
||||
* @param mode
|
||||
*/
|
||||
public void setECSandTheme(ErrorCheckerService ecs, ExperimentalMode mode) {
|
||||
public void setECSandTheme(ErrorCheckerService ecs, JavaMode mode) {
|
||||
this.errorCheckerService = ecs;
|
||||
//loadTheme(mode);
|
||||
|
||||
|
||||
@@ -240,7 +240,8 @@ public class OffsetMatcher {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
public static void main(String[] args) {
|
||||
// minDistance("c = #qwerty;", "c = 0xffqwerty;");
|
||||
OffsetMatcher a;
|
||||
@@ -261,4 +262,6 @@ public class OffsetMatcher {
|
||||
// a.getJavaOffForPdeOff(6, 3);
|
||||
// distance("c = #bb00aa;", "c = 0xffbb00aa;");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user