Comments (7)
I have an Open Source project using auto complete feature.
https://sourceforge.net/projects/cash-flow
Unzip CashFlow.zip, and the complete source tree can be found within src.zip file.
Everything line is parsed against a list of regular expression possibilities.
Autocomplete if cursor is at end of line. A select token types are subject to auto-complete, using case-insensitive comparison order.
I do not use the canned auto-complete classes but rather I implement what I need based on the base abstract classes or at the interface level. Look at PureCompletion.java, TokenCompletion.java and CFCompletionProvider.java
One important tip I can give is that a list of source strings that participates in auto-completion has to be sorted in unique case insensitive order. If s1 and s2 have the same case insensitive order, then you need to compare them again case sensitively and return their case sensitively ordering. If you just use the naive case insensitive ordering then your app might behave badly when doing auto-completion. Some part of auto-complete code requires the list to be sorted in a unique order; other parts need the list to be case insensitive. I have my code to do this case insensitive unique comparison, because this was a very critical piece of code.
My source code is Apache 2.0 licensed.
My copy of the auto-complete source has a few fixes that were not integrated into the main branch; they were previously published as pull request number 36.
from autocomplete.
@Vatolino, can you point to the specific example that does not work for you?
from autocomplete.
no autocomplete pop up
`public class CodeEditor extends JFrame {
public CodeEditor() {
JPanel contentPane = new JPanel(new BorderLayout());
RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
textArea.setCodeFoldingEnabled(true);
contentPane.add(new RTextScrollPane(textArea));
// A CompletionProvider is what knows of all possible completions, and
// analyzes the contents of the text area at the caret position to
// determine what completion choices should be presented. Most instances
// of CompletionProvider (such as DefaultCompletionProvider) are designed
// so that they can be shared among multiple text components.
CompletionProvider provider = createCompletionProvider();
// An AutoCompletion acts as a "middle-man" between a text component
// and a CompletionProvider. It manages any options associated with
// the auto-completion (the popup trigger key, whether to display a
// documentation window along with completion choices, etc.). Unlike
// CompletionProviders, instances of AutoCompletion cannot be shared
// among multiple text components.
AutoCompletion ac = new AutoCompletion(provider);
ac.setListCellRenderer(new CompletionCellRenderer());
ac.setShowDescWindow(true);
ac.setParameterAssistanceEnabled(true);
ac.install(textArea);
ToolTipManager.sharedInstance().registerComponent(textArea);
setContentPane(contentPane);
setTitle("AutoComplete Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
}
/**
* Create a simple provider that adds some Java-related completions.
*/
private CompletionProvider createCompletionProvider() {
// A DefaultCompletionProvider is the simplest concrete implementation
// of CompletionProvider. This provider has no understanding of
// language semantics. It simply checks the text entered up to the
// caret position for a match against known completions. This is all
// that is needed in the majority of cases.
DefaultCompletionProvider provider = new DefaultCompletionProvider();
// Add completions for all Java keywords. A BasicCompletion is just
// a straightforward word completion.
provider.addCompletion(new BasicCompletion(provider, "abstract"));
provider.addCompletion(new BasicCompletion(provider, "assert"));
provider.addCompletion(new BasicCompletion(provider, "break"));
provider.addCompletion(new BasicCompletion(provider, "case"));
// ... etc ...
provider.addCompletion(new BasicCompletion(provider, "transient"));
provider.addCompletion(new BasicCompletion(provider, "try"));
provider.addCompletion(new BasicCompletion(provider, "void"));
provider.addCompletion(new BasicCompletion(provider, "volatile"));
provider.addCompletion(new BasicCompletion(provider, "while"));
provider.addCompletion(new BasicCompletion(provider, "public"));
provider.addCompletion(new BasicCompletion(provider, "private"));
provider.addCompletion(new BasicCompletion(provider, "protected"));
provider.addCompletion(new BasicCompletion(provider, "static"));
provider.addCompletion(new BasicCompletion(provider, "final"));
// Add a couple of "shorthand" completions. These completions don't
// require the input text to be the same thing as the replacement text.
provider.addCompletion(new ShorthandCompletion(provider, "sysout",
"System.out.println(", "System.out.println("));
provider.addCompletion(new ShorthandCompletion(provider, "syserr",
"System.err.println(", "System.err.println("));
return provider;
}
public static void main(String[] args) {
// Instantiate GUI on the EDT.
SwingUtilities.invokeLater(() -> {
try {
String laf = UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(laf);
} catch (Exception e) { /* Never happens */ }
new CodeEditor().setVisible(true);
});
}
}`
from autocomplete.
Note that by default, you need to type Ctrl+Space for the completion popup to appear. Are you doing that?
from autocomplete.
No I didn't do that, I'll try later, is there a way to make it automatically pop up? That's what I really want
from autocomplete.
To have it automatically pop up is a two step process:
First, enable it via AutoCompletion.setAutoCompleteEnabled(true)
. Call this on the AutoCompletion instance you create, before setting everything else up.
Then, what keys trigger the completion popup to automatically display is a property of the CompletionProvider
. e.g. should it only appear when the user types ".", or should it appear whenever any letter is typed, or something else? This is configurable since determining a set of possible code completions can be an expensive operation, so it should be set conservatively if possible. Any CompletionProvider
extending CompletionProviderBase
(e.g. any DefaultCompletionProvider
) can have this configured via the setAutoActivationRules(boolean letters, String others)
method.
from autocomplete.
Closing as a solution was provided.
from autocomplete.
Related Issues (20)
- Less then symbol "<" HOT 3
- why it is not working ,i use the example "AutoCompleteDemo" HOT 1
- isAutoActivateOkay() checks wrong character HOT 3
- CompletionProvider works but doesn't update HOT 1
- Popup to display actions on current token
- Long load in production, short under Eclipse HOT 3
- AutoCompletion shows non-matching completions when using custom completion HOT 1
- JavaFX - AutoComplete pop up showing, but buggy HOT 1
- RTextArea.read() stops auto code completion from popping up HOT 2
- AutoCompleteDescWindow doesn't hide itself well when showDescWindow is toggled (On Ubuntu only?)
- Customize suggestion format HOT 1
- Add JSON schema based auto-completion support
- EmptyIcon should be resizable
- Unstable compareTo between FunctionCompletion and AbstractCompletion HOT 1
- Question: How to use markup completion
- Facing 2 bugs in autocompletion with RSyntaxArea HOT 3
- Hint popups don't get dismissed
- No pop-up for completion with a standard JTextArea with Java 8 or 17 HOT 3
- Parameter Autocompletion Causes Rendering Problems HOT 3
- hideOnNoText doesn't seems to work properly : the popup will always reappear with arrow keys HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autocomplete.