RSyntaxArea " - " Valid Char

Questions on using RText should go here.

Moderator: robert

RSyntaxArea " - " Valid Char

Postby Azlan » Thu Apr 11, 2013 5:01 pm

How would you go about in a DefaultCompletionProvider, letting " - " be a valid char.
I've read about this code before:

java code:

protected boolean isValidChar(char ch) {
return super.isValidChar(ch) || ch=='.';
}


The only problem is, I don't know exactly where to put it. I can't alter the source code, because I'm using a Jar file to implement RSyntaxTextArea. If I do have to alter the source, is there another way to implement RSyntaxArea than the jar?
Thanks
Azlan
 
Posts: 14
Joined: Thu Apr 11, 2013 4:54 pm

Re: RSyntaxArea " - " Valid Char

Postby robert » Fri Apr 12, 2013 4:07 am

You'd have to install and use your own custom CompletionProvider class, that extended DefaultCompletionProvider, and overrode that method:

java code:

public class MyCompletionProvider extends DefaultCompletionProvider {

...

@Override
protected boolean isValidChar(char ch) {
return super.isValidChar(ch) || ch=='-';
}

}


Then use it like so:

java code:

AutoCompletion ac = new AutoCompletion(new MyCompletionProvider());
ac.install(textArea);
User avatar
robert
 
Posts: 794
Joined: Sat May 10, 2008 5:16 pm

Re: RSyntaxArea " - " Valid Char

Postby Azlan » Sun Apr 14, 2013 9:53 pm

It's still not working.

I'm not sure, but I have the completion provider installed and everything. It works, only when i press the '-' char, the autocomplete stops.
Here's my code:

java code:

import org.fife.ui.autocomplete.*;

public class MyCompletionProvider extends DefaultCompletionProvider {

static CompletionProvider createCompletionProvider() {

DefaultCompletionProvider provider = new DefaultCompletionProvider();
provider.setAutoActivationRules(true,null);

provider.addCompletion(new BasicCompletion(provider, "this-is"));

return provider;
}

@Override
protected boolean isValidChar(char ch) {
return super.isValidChar(ch) || ch=='-';
}

}


It works fine, but the '-' char doesn't. I'll go ahead and give you the code to my AutoCompletion, since maybe it's there.

java code:

CompletionProvider completionProvidercss = MyCompletionProvider.createCompletionProvider();
/*It has to be final/constant */ final AutoCompletion accss = new AutoCompletion(completionProvidercss);
accss.setAutoActivationEnabled(true);
accss.install(txt);


Please note, that they are in separate files
Azlan
 
Posts: 14
Joined: Thu Apr 11, 2013 4:54 pm

Re: RSyntaxArea " - " Valid Char

Postby robert » Tue May 07, 2013 3:39 am

Your MyCompletionProvider subclass is returning a regular DefaultCompletionProvider, that doesn't have isValidChar() overridden. It (presumably) needs to return an instance of MyCompletionProvider.

Here's an example program that demonstrates using a DefaultCompletionProvider subclass working:

java code:

import java.awt.BorderLayout;
import javax.swing.*;
import org.fife.ui.autocomplete.*;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;

class AcTest extends JFrame {

public AcTest() {

JPanel contentPane = new JPanel(new BorderLayout());
RSyntaxTextArea textArea = new RSyntaxTextArea(25, 40);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);

CompletionProvider provider = createCompletionProvider();
AutoCompletion ac = new AutoCompletion(provider);
ac.install(textArea);
contentPane.add(new RTextScrollPane(textArea, true));

setContentPane(contentPane);
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);

}

private CompletionProvider createCompletionProvider() {
DefaultCompletionProvider cp = new DefaultCompletionProvider() {
protected boolean isValidChar(char ch) {
return super.isValidChar(ch) || ch=='-';
}
};
cp.addCompletion(new BasicCompletion(cp, "this-is"));
cp.addCompletion(new BasicCompletion(cp, "thisother"));
return cp;
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new AcTest().setVisible(true);
}
});
}
}
User avatar
robert
 
Posts: 794
Joined: Sat May 10, 2008 5:16 pm

Re: RSyntaxArea " - " Valid Char

Postby Azlan » Tue May 07, 2013 4:51 am

Thanks a lot! It works.
Azlan
 
Posts: 14
Joined: Thu Apr 11, 2013 4:54 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 0 guests

cron