Stencil based editor component for Java/Swing?

457 Views Asked by At

I'm looking for a stencil based text editor for my swing application. (SWT component would be OK too)

If you don't know what a "stencil based" editor is, have a look on the stencil based editor in Alice: enter image description here

So you just drop the stencil of the block you want to add to your code, like a if or a loop, and can only add compatible expressions in the "holes" in the stencil.

(I need it for an end user programming tool so auto complete is not enough to get the user started fast.)

The source code of an old Alice version is online on github, but the code is undocumented and pretty huge so that would be my last resort.

2

There are 2 best solutions below

0
On BEST ANSWER

Recently I stumbled upon some projects using and creating such editors:

For C/C++ programmers Scratch would be a good point to start but for Java developers there's openblocks. There doesn't seem to be a real name convention yet but you definitly find more projects by the terms "visual programming" and "block editor" than "stencil based editor".

2
On

Swing's StyledDocument has just two levels of styles: paragraph and character level, but they are set based, so you have a kind of nesting. I would use the HTMLEditorKit (nested HTML), a read-only JTextPane, and caret position based contextual insertion. Having an XML schema of possible document structure and using that to insert <div class='myX'> and such. So at the caret position have a stack of nested elements.