什么是JavaFX相当于JSyntaxPane用于编写代码编辑器? [英] What is JavaFX equivalent of JSyntaxPane for making a code editor?

查看:457
本文介绍了什么是JavaFX相当于JSyntaxPane用于编写代码编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前在Swing中,我使用 JSyntaxPane 来制作一个小的Java源代码编辑器。为了实践,我决定在JavaFX中重做整个项目并添加对更多语言的支持。最好尽可能多。

Previously in Swing, I have used the JSyntaxPane for making a tiny Java source editor. For practice, I decided to redo the entire project in JavaFX and adding support for more languages. Preferably, as many as I can.

然而,似乎与 JSyntaxPane 没有任何相似之处。

However, there seems to be nothing similar to JSyntaxPane.

一些研究让我 Tom Schindl 博客,他用适当的语法高亮显示了源代码查看器。遗憾的是没有编辑支持。

A bit of research led me to Tom Schindl's blog where he has made a source code viewer with proper syntax highlighting. No editing support, sadly.

然后有 JewelSea 博客但是从截图看起来就像是SO的类型和预览方法。在代码编辑器中不是所需的东西。

Then there is JewelSea's blog but from the screenshot it look's like SO's type-and-preview method. Not something desired in a code editor.

再次,从 JFXperience 我发现在JavaFX 8中可以使用突出显示和缩进和编辑面板/节点它还允许将Swing嵌入Java中。

Again, from JFXperience I found that highlighting and indenting and editing panel / node will be available in JavaFX 8 and it will also allow embedding Swing into Java.

到那时,我的其他选择是什么?

I知道JavaFX可以与JavaScript互操作,所以我有没有办法使用一些JavaScript库来实现同样的目标?

推荐答案

我目前正通过 Ace Editor > WebEngine 。这是 Kitchen Sink 演示。

I am currently using Ace Editor in my open source project via the WebEngine. Here is the Kitchen Sink demo.

更新

从当前JDK版本开始,JS / FX交互的一种可能方法:

A possible approach to JS/FX interaction as of current JDK version:


  • 编写JS app / widget部分,单独测试它。如果您只打算嵌入编辑器小部件,那么它可能是一个空白的网页,其中包含< div> ,这是您的编辑。

  • 然后一个'从JS获取文本'方案的计划可能是这样的:'从Java调用JS函数,它将从编辑器元素获取文本并使用作为String参数传递的文本回调Java部分方法'。

  • 学习Java-JS绑定 - 即 WebView来自Javascript的回调

  • 嵌入FirebugLite以从 WebView 调试JS。对我有用的唯一版本是:

  • Write the JS app/widget part, test it standalone. If you only intending to embed an editor widget, then it could be an empty web page with a <div> which is your editor.
  • Then a plan for a 'get text from JS' scenario might be like this: 'call the JS function from Java, it will get the text from the editor element and call back the Java part with text passed as String argument for a method'.
  • Learn the Java-JS binding - i.e. WebView callback from Javascript
  • Embed FirebugLite to debug your JS from the WebView. The only version which worked for me was:

< script src ='http://getfirebug.com/releases/lite/1.2/ firebug-lite-compressed.js'>

一些一般性建议 - 尝试避免JS-to-Java调用的复杂性。我向JavaFX团队提交了一些错误,因为一些简单的事情,比如覆盖一个方法对我来说不起作用。避免将Java对象传递给JS - 虽然理论上可行,但我总是遇到应用程序崩溃。所以现在我传递JSON并将其转换为双方的对象。

Some general advices - try to avoid complexity in JS-to-Java calls. I filed a couple of bugs to the JavaFX team because some simple things like overriding a method didn't work for me. Avoid passing Java objects to JS - though it is theoretically possible, I always ended up with application crashes. So now I am passing JSON and convert it to objects on both sides.

你可以查看一个AngularJS / JavaFX应用程序的工作示例。它处于pre-alpha状态,因此它甚至可能无法在您的计算机上启动,但可以看作是AngularJS桌面应用程序的概念证明。

You may have a look at a working example here of an AngularJS/JavaFX application. It's in a pre-alpha state, so it may not even launch on your machine, but can be seen as proof of concept of an AngularJS desktop app.

这篇关于什么是JavaFX相当于JSyntaxPane用于编写代码编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆