开发者

Implement editor in Java

开发者 https://www.devze.com 2023-02-06 11:18 出处:网络
I need to implement editor for three custom languages ( intellisense, search & repla开发者_如何学Pythonce, syntax highlighting, region like in C# visual studio ) in Java. What is the best class fo

I need to implement editor for three custom languages ( intellisense, search & repla开发者_如何学Pythonce, syntax highlighting, region like in C# visual studio ) in Java. What is the best class for this ( JEditor, JPanel or some other ) ?


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.


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:

  • http://www.antonioshome.net/kitchen/netbeans/nbms-standalone.php

... 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.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消