Add basic code completion to editor
parent
f34e03fd0c
commit
cc72fcaade
Binary file not shown.
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Apocalypse Laboratories
|
||||
* Open Source License
|
||||
*
|
||||
* Source code can be used for any purpose, as long as:
|
||||
* - Compiled binaries are rebranded and trademarks are not
|
||||
* visible by the end user at any time, except to give
|
||||
* credit to Apocalypse Laboratories, such as by showing
|
||||
* "Based on <product> by Apocalypse Laboratories" or a
|
||||
* similar notice;
|
||||
* - You do not use the code for evil;
|
||||
* - Rebranded compiled applications have significant
|
||||
* differences in functionality;
|
||||
* - and you provide your modified source code for download,
|
||||
* under the terms of the GNU LGPL v3 or a comparable
|
||||
* license.
|
||||
*
|
||||
* Compiled binaries cannot be redistributed or mirrored,
|
||||
* unless:
|
||||
* - You have written permission from Apocalypse Laboratories;
|
||||
* - Downloads are not available from Apocalypse Laboratories,
|
||||
* not even behind a paywall or other blocking mechanism;
|
||||
* - or you have received a multi-computer license, in which
|
||||
* case you should take measures to prevent unauthorized
|
||||
* downloads, such as preventing download access from the
|
||||
* Internet.
|
||||
*/
|
||||
package net.apocalypselabs.symat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import org.fife.ui.autocomplete.BasicCompletion;
|
||||
import org.fife.ui.autocomplete.Completion;
|
||||
import org.fife.ui.autocomplete.CompletionProvider;
|
||||
import org.fife.ui.autocomplete.DefaultCompletionProvider;
|
||||
import org.fife.ui.autocomplete.FunctionCompletion;
|
||||
import org.fife.ui.autocomplete.MarkupTagCompletion;
|
||||
import org.fife.ui.autocomplete.ShorthandCompletion;
|
||||
import org.fife.ui.autocomplete.VariableCompletion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Skylar
|
||||
*/
|
||||
public class CodeCompleter {
|
||||
|
||||
private final CompletionProvider provider;
|
||||
private final String lang;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param language Either js or py.
|
||||
*/
|
||||
public CodeCompleter(String language) {
|
||||
lang = language;
|
||||
provider = makeCompletions();
|
||||
}
|
||||
|
||||
public CompletionProvider getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
private CompletionProvider makeCompletions() {
|
||||
DefaultCompletionProvider provider = new DefaultCompletionProvider();
|
||||
try {
|
||||
String[] files = {"functions", "constants"};
|
||||
for (String fileid : files) {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
CodeEditor.class.getResourceAsStream("resources/" + lang + fileid + ".txt")));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
switch (fileid) {
|
||||
case "functions":
|
||||
String[] args = line.split("\\|");
|
||||
if (args.length == 2) {
|
||||
provider.addCompletion(new BasicCompletion(provider, args[0], args[1]));
|
||||
} else if (args.length == 3) {
|
||||
provider.addCompletion(new BasicCompletion(provider, args[0], args[1], args[2]));
|
||||
} else {
|
||||
provider.addCompletion(new BasicCompletion(provider, args[0]));
|
||||
}
|
||||
break;
|
||||
case "constants":
|
||||
provider.addCompletion(new VariableCompletion(provider, line, "double"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Debug.printerr(ex.getMessage());
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
E
|
||||
PI
|
||||
LN2
|
||||
LN10
|
||||
LOG2E
|
||||
LOG10E
|
||||
SQRT1_2
|
||||
SQRT2
|
@ -0,0 +1,30 @@
|
||||
notify|return nothing|Display a message in a box.
|
||||
ask|return String|Ask a question in a box. Supply question text.
|
||||
D|return String|Find the derivative of the function passed with respect to the second argument.
|
||||
rad|return double|Convert a given number in degrees to radians.
|
||||
deg|return double|Convert a given number in radians to degrees.
|
||||
subs|return double|Solve an equation for the second argument.
|
||||
plot|return nothing|Graph the given function.
|
||||
graph|alias of plot|Graph the given function.
|
||||
plotname|return nothing or String|Gets or sets the title of the graph window.
|
||||
plotclr|return nothing|Clear the graph and its history.
|
||||
clearplot|alias of plotclr|Clear the graph and its history.
|
||||
plotscale|return nothing|Scale the plot to the given factor.
|
||||
drawdot|return nothing|Places a red dot at the given coordinates.
|
||||
abs|return double|
|
||||
asin|return double|
|
||||
acos|return double|
|
||||
atan|return double|
|
||||
ceil|return double|
|
||||
exp|return double|
|
||||
floor|return double|
|
||||
log|return double|
|
||||
max|return double|Returns the highest number given.
|
||||
min|return double|Returns the lowest number given.
|
||||
pow|return double|
|
||||
random|return double|Gives a random number between 0.0 and 1.0.
|
||||
round|return double|
|
||||
sin|return double|
|
||||
cos|return double|
|
||||
tan|return double|
|
||||
print|return nothing|Prints the supplied text to the output.
|
@ -0,0 +1,2 @@
|
||||
e
|
||||
pi
|
@ -0,0 +1,29 @@
|
||||
_.notify|return nothing|Display a message in a box.
|
||||
_.ask|return String|Ask a question in a box. Supply question text.
|
||||
_.D|return String|Find the derivative of the function passed with respect to the second argument.
|
||||
radians|return double|Convert a given number in degrees to radians.
|
||||
degrees|return double|Convert a given number in radians to degrees.
|
||||
_.subs|return double|Solve an equation for the second argument.
|
||||
_.plot|return nothing|Graph the given function.
|
||||
_.graph|alias of plot|Graph the given function.
|
||||
_.plotname|return nothing or String|Gets or sets the title of the graph window.
|
||||
_.plotclr|return nothing|Clear the graph and its history.
|
||||
_.clearplot|alias of plotclr|Clear the graph and its history.
|
||||
_.plotscale|return nothing|Scale the plot to the given factor.
|
||||
_.drawdot|return nothing|Places a red dot at the given coordinates.
|
||||
fabs|return double|
|
||||
asin|return double|
|
||||
acos|return double|
|
||||
atan|return double|
|
||||
ceil|return double|
|
||||
exp|return double|
|
||||
floor|return double|
|
||||
log|return double|
|
||||
max|return double|Returns the highest number given.
|
||||
min|return double|Returns the lowest number given.
|
||||
pow|return double|
|
||||
round|return double|
|
||||
sin|return double|
|
||||
cos|return double|
|
||||
tan|return double|
|
||||
print|return nothing|Prints the supplied text to the output.
|
Loading…
Reference in New Issue