diff --git a/pom.xml b/pom.xml
index 812bbc7..8f978f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
turboTranscriber
turboTranscriber
- 0.0.1-SNAPSHOT
+ 0.0.4
jar
-
+
org.jdom
@@ -100,9 +73,9 @@
3.0.3
- org.springframework.boot
- spring-boot-maven-plugin
- 2.1.7.RELEASE
+ com.fifesoft
+ autocomplete
+ 3.0.2
\ No newline at end of file
diff --git a/src/main/java/ch/blandolt/turboTranscriber/core/TurboTranscribeCore.java b/src/main/java/ch/blandolt/turboTranscriber/core/TurboTranscribeCore.java
index ef7a83e..b8e40c2 100644
--- a/src/main/java/ch/blandolt/turboTranscriber/core/TurboTranscribeCore.java
+++ b/src/main/java/ch/blandolt/turboTranscriber/core/TurboTranscribeCore.java
@@ -432,6 +432,8 @@ private void refreshGUI() {
gui.createThumbnails();
gui.refreshEnabledComponents();
+ gui.refreshCodeCompletion();
+
// TODO: more?
}
diff --git a/src/main/java/ch/blandolt/turboTranscriber/gui/MainGUI.java b/src/main/java/ch/blandolt/turboTranscriber/gui/MainGUI.java
index 09f62af..ef98f0a 100644
--- a/src/main/java/ch/blandolt/turboTranscriber/gui/MainGUI.java
+++ b/src/main/java/ch/blandolt/turboTranscriber/gui/MainGUI.java
@@ -5,6 +5,11 @@
import ch.blandolt.turboTranscriber.util.Loggable;
import ch.blandolt.turboTranscriber.util.Settings;
import ch.blandolt.turboTranscriber.util.rsyntax.RawTokenMaker;
+import ch.blandolt.turboTranscriber.util.rsyntax.TTCompletionProvider;
+import ch.blandolt.turboTranscriber.util.rsyntax.WeightedCompletion;
+import org.fife.ui.autocomplete.AutoCompletion;
+import org.fife.ui.autocomplete.BasicCompletion;
+import org.fife.ui.autocomplete.DefaultCompletionProvider;
import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rtextarea.RTextScrollPane;
@@ -17,7 +22,7 @@
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
+import java.util.*;
import java.util.List;
/**
@@ -79,6 +84,8 @@ public class MainGUI extends JFrame implements Loggable, WindowListener, Docume
private BufferedImage loadedImage;
private float imageScaling = 0.4f;
+ private DefaultCompletionProvider provider = null;
+
/**
* Constructor of the GUI.
*
@@ -192,6 +199,7 @@ private void setUpMainWindow() {
// TODO: ensure loading in jars (might not work, not sure)
String path = "theme_light.xml";
+ // TODO: make dark theme more contrastive
//String path = "theme_dark.xml";
Log.log(getClass());
InputStream in = getClass().getClassLoader().getResourceAsStream(path);
@@ -200,7 +208,6 @@ private void setUpMainWindow() {
} catch (IOException ioe) { // Never happens
ioe.printStackTrace();
}
- //transcriptionSyntaxTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
Font prev = transcriptionSyntaxTextArea.getFont();
transcriptionSyntaxTextArea.setBracketMatchingEnabled(true);
transcriptionSyntaxTextArea.setPaintMatchedBracketPair(true);
@@ -210,6 +217,8 @@ private void setUpMainWindow() {
transcriptionSyntaxTextArea.setFont(new Font(prev.getName(), prev.getStyle(), prev.getSize()+4));
// TODO make font size a setting
+ setUpCodeCompletion();
+
xmlScroller = new RTextScrollPane(xmlArea);
styledScroller = new JScrollPane(new JLabel("Imagine nice HTML here."));
splitterXMLStuff = new JSplitPane(JSplitPane.VERTICAL_SPLIT, xmlScroller, styledScroller);
@@ -238,6 +247,41 @@ private void setUpMainWindow() {
logPane.add(logScroller, BorderLayout.CENTER);
}
+ private void setUpCodeCompletion() {
+ provider = new TTCompletionProvider();
+ provider.setAutoActivationRules(true, "({[;");
+ AutoCompletion ac = new AutoCompletion(provider);
+ ac.setAutoActivationEnabled(true);
+ ac.install(transcriptionSyntaxTextArea);
+ }
+
+ public void refreshCodeCompletion() {
+ List tokens = getCompletionTokens();
+ HashMap types = new HashMap<>();
+ for (String token: tokens){
+ if (token.equals(""))
+ continue;
+ if (types.containsKey(token)){
+ Integer v2 = types.get(token)+1;
+ types.put(token, v2);
+ } else {
+ types.put(token, Integer.valueOf(1));
+ }
+ }
+ provider.clear();
+ for (Map.Entry entry: types.entrySet()){
+ // TODO: get weighted completion to work
+ //provider.addCompletion(new WeightedCompletion(provider, entry.getKey(), entry.getValue()));
+ provider.addCompletion(new BasicCompletion(provider, entry.getKey(), entry.getValue().toString()));
+ }
+ }
+
+ private List getCompletionTokens() {
+ String s = transcriptionSyntaxTextArea.getText();
+ s = s.replaceAll("\n", " ");
+ return Arrays.asList(s.split(" "));
+ }
+
private void handle_listeners() {
// TODO: Add all necessary listeners
diff --git a/src/main/java/ch/blandolt/turboTranscriber/util/rsyntax/TTCompletionProvider.java b/src/main/java/ch/blandolt/turboTranscriber/util/rsyntax/TTCompletionProvider.java
new file mode 100644
index 0000000..46a1a29
--- /dev/null
+++ b/src/main/java/ch/blandolt/turboTranscriber/util/rsyntax/TTCompletionProvider.java
@@ -0,0 +1,11 @@
+package ch.blandolt.turboTranscriber.util.rsyntax;
+
+import org.fife.ui.autocomplete.DefaultCompletionProvider;
+
+public class TTCompletionProvider extends DefaultCompletionProvider {
+
+ @Override
+ protected boolean isValidChar(char ch) {
+ return super.isValidChar(ch) || ch=='{' || ch== '(' || ch=='[' || ch==';';
+ }
+}
diff --git a/src/main/java/ch/blandolt/turboTranscriber/util/rsyntax/WeightedCompletion.java b/src/main/java/ch/blandolt/turboTranscriber/util/rsyntax/WeightedCompletion.java
new file mode 100644
index 0000000..980de19
--- /dev/null
+++ b/src/main/java/ch/blandolt/turboTranscriber/util/rsyntax/WeightedCompletion.java
@@ -0,0 +1,52 @@
+package ch.blandolt.turboTranscriber.util.rsyntax;
+
+import org.fife.ui.autocomplete.BasicCompletion;
+import org.fife.ui.autocomplete.Completion;
+import org.fife.ui.autocomplete.CompletionProvider;
+
+public class WeightedCompletion extends BasicCompletion {
+
+ private int weight = 1;
+
+ public WeightedCompletion(CompletionProvider provider, String replacementText) {
+ this(provider, replacementText, 1);
+ }
+
+ public WeightedCompletion(CompletionProvider provider, String replacementText, int weight) {
+ super(provider, replacementText, "("+weight+") ");
+ this.weight = weight;
+ }
+
+ public WeightedCompletion(CompletionProvider provider, String replacementText, String shortDesc) {
+ this(provider, replacementText, shortDesc, 1);
+ }
+
+ public WeightedCompletion(CompletionProvider provider, String replacementText, String shortDesc, int weight) {
+ super(provider, replacementText, "("+weight+") "+shortDesc);
+ this.weight = weight;
+ }
+
+ public WeightedCompletion(CompletionProvider provider, String replacementText, String shortDesc, String summary) {
+ this(provider, replacementText, shortDesc, summary, 1);
+ }
+
+ public WeightedCompletion(CompletionProvider provider, String replacementText, String shortDesc, String summary, int weight) {
+ super(provider, replacementText, "("+weight+") "+shortDesc, summary);
+ this.weight = weight;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ @Override
+ public int compareTo(Completion other){
+ if (other instanceof WeightedCompletion){
+ WeightedCompletion wc = (WeightedCompletion)other;
+ return -1*Integer.valueOf(getWeight()).compareTo(Integer.valueOf(wc.getWeight()));
+ } else {
+ return super.compareTo(other);
+ }
+
+ }
+}