Template Completion

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Template Completion

Postby John » Mon Dec 10, 2012 3:46 pm

Hi,

I'm trying to add a template completion into a provider, but so far without success. I downloaded version 2.0.5 of auto-complete and rsyntaxtextarea.

I already saw this post: http://fifesoft.com/blog/?p=533.

In fact, this is the example that i'm trying to run to test the Template Completion.

Can anyone give me another example?

java code:

/* Constructor - OCLEditorPanel extends JPanel */

public OCLEditorPanel ()
{
RSyntaxTextArea textArea = new RSyntaxTextArea(5, 30);
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
textArea.setAntiAliasingEnabled(true);
textArea.setCodeFoldingEnabled(false);
textArea.setForeground(Color.BLACK);
textArea.setBackground(new Color(255, 255, 255));
textArea.setCurrentLineHighlightColor(ColorPalette.getInstance().getColor(ThemeColor.GREEN_LIGHTEST));

setFont(textArea,new Font("Consolas", Font.PLAIN, 11));

Theme theme;
try {
theme = Theme.load(getClass().getResourceAsStream("/br/ufes/inf/nemo/move/ui/ocl/eclipse.xml"));
theme.apply(textArea);
} catch (IOException e) {
e.printStackTrace();
}

OCLTokenMaker tm = new OCLTokenMaker();
((RSyntaxDocument)textArea.getDocument()).setSyntaxStyle(tm);

DefaultCompletionProvider provider = new DefaultCompletionProvider();
// testing the Template Completion...
provider.addCompletion(new TemplateCompletion(provider, "for", "for-loop", "for (int ${i} = 0; ${i} < ${array}.length; ${i}++) {${cursor}"));

AutoCompletion ac = new AutoCompletion(provider);
ac.install(textArea);
ac.setAutoActivationEnabled(true);
ac.setShowDescWindow(true);
setLayout(new BorderLayout(0, 0));

RTextScrollPane scrollPane = new RTextScrollPane(textArea);
scrollPane.getGutter().setLineNumberColor(Color.GRAY);
scrollPane.getTextArea().setRows(5);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

setPreferredSize(new Dimension(400, 100));
add(scrollPane);
}
John
 

Re: Template Completion

Postby robert » Wed Dec 12, 2012 4:52 am

Another good example is found in the Java language support. See in particular the JavaShorthandComletionCache class, where the template completions are all created. To actually see it in action, you'll have to check out the RSTALanguageSupport project from SVN, as well as its sister projects RSyntaxTextArea and AutoComplete, since it's dependent on them.
User avatar
robert
 
Posts: 779
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron