I've spent more than 12 hrs trying to figure out how to get the CTRL+SPACE to work on the code editor with customer list of data.
- Code: Select all
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import com.jidesoft.editor.CodeEditor;
import com.jidesoft.editor.ListDataCodeEditorIntelliHints;
import com.jidesoft.editor.caret.CaretEvent;
import com.jidesoft.editor.caret.CaretListener;
public class HintsProvider {
public static Object[] loadHints(String text, int caretPosition) {
List<String> values = new ArrayList<String>();
String temp = text.substring(0, caretPosition - 1);
temp = temp.substring(temp.lastIndexOf("\n") + 1).trim();
try {
Class clazz = Class.forName(temp);
for (Method method : clazz.getMethods()) {
values.add(method.getName());
}
} catch (ClassNotFoundException e) {
}
return values.toArray();
}
public static void main(String[] args) {
final CodeEditor ce = new CodeEditor();
@SuppressWarnings("unchecked")
final ListDataCodeEditorIntelliHints hints = new ListDataCodeEditorIntelliHints(
ce, new ArrayList<String>());
ce.getCaretModel().addCaretListener(new CaretListener() {
@Override
public void caretUpdated(CaretEvent caretEvent) {
try {
hints.setCompletionList(HintsProvider.loadHints(
ce.getText(), ce.getCaretPosition()));
System.out.println(hints.getCompletionList());
} catch (Exception e) {
}
}
});
JFrame frame = new JFrame();
frame.getContentPane().add(ce);
frame.pack();
frame.setVisible(true);
}
}
Could you please let me know whats wrong with this code?