Damir
Damir

Reputation: 56199

Implement editor in Java

I need to implement editor for three custom languages ( intellisense, search & replace, syntax highlighting, region like in C# visual studio ) in Java. What is the best class for this ( JEditor, JPanel or some other ) ?

Upvotes: 0

Views: 877

Answers (5)

Puce
Puce

Reputation: 38132

Or have a look at the NetBeans Platform if you're familiar with Swing. It's a Swing-based RCP. The NetBeans IDE itself is build on the NetBeans Platform and you can reuse its modules such as the editor:

http://platform.netbeans.org/tutorials/nbm-htmleditor.html

http://platform.netbeans.org/tutorials/60/nbm-xmleditor.html

Upvotes: 1

Michael Borgwardt
Michael Borgwardt

Reputation: 346290

Take a look at Xtext. It's a framework on top of the eclipse platform that autogenerates much of the infrastructure (like syntax highlighting and autocomplete) from the language grammar - basically you get a pretty powerful editor in minutes rather than months of work.

Upvotes: 4

Riduidel
Riduidel

Reputation: 22292

Short reply It is a hard job involving far more than one Swing component

Medium reply Long ago, jEdit text editor component was available as a separate component. I suggest you spend five minutes for a quick google search. it could lead to interesting results in that direction.

Long reply Most of the features you are looking for (intellisense, syntax highlight) will require you a grammar, or at least a very good language tokenizer allowing you to recognize key elements. This in turn imply a very efficient document model (in the sense that it will be both feature rich, fat both in time and small in memory). You'll have no choice other thatn writing your own. Concerning search & replace, once you have your Document, you'll have to match tokens from the text box with elements of your Document. In a typical syntax tree, elements consdiered in the same document flow may span over multiple nodes. Typically

for(int index=0; index<size; index++) {
     println(index);
}

spans over at least ten nodes. And if you want to search for this construct, you'll have to map text position to tree nodes, which may not be trivial.

Upvotes: 1

miku
miku

Reputation: 188024

Take a look at Eclipses Rich Client Platform or the NetBeans Platform. Both contain a large set of classes and widgets for desktop applications, including customizable editors.

Here's a blogpost about building a custom editor with the latter toolkit:

... the NetBeans Platform contains a library called "The NetBeans Editor Library". This is, as far as I know, one of the most powerful open-sourced Swing text libraries out there, fully compliant with the Swing Text API.

Upvotes: 3

Mihai Toader
Mihai Toader

Reputation: 12243

Are you sure you want to implement this from scratch ?

You should probably use some framework that adds some language support. I would recommend looking at eclipse plugins or intellij idea (community edition) plugins.

Upvotes: 2

Related Questions