java中ace_java – 在WT中使用ACE

更新3

下面的最终工作代码.你需要来自src文件夹的ace.js!它不适用于lib,你需要从他们的网站预先打包的版本.

WText *editor = new WText(root());

editor->setText("function(){\n hello.abc();\n}\n");

editor->setInline(false);

上面的代码可以设置ACE窗口的内容.

MyClass::MyClass(const WEnvironment& env)

: WApplication(env)

{

wApp->require("ace-builds/src/ace.js");

// A WContainerWidget is rendered as a div

WContainerWidget *editor = new WContainerWidget(root());

editor->resize(500, 500);

std::string editor_ref = editor->jsRef(); // is a text string that will be the element when executed in JS

std::string command =

editor_ref + ".editor = ace.edit(" + editor_ref + ");" +

editor_ref + ".editor.setTheme(\"ace/theme/monokai\");" +

editor_ref + ".editor.getSession().setMode(\"ace/mode/javascript\");";

editor->doJavaScript(command);

JSignal <:string> *jsignal = new JSignal<:string>(editor, "textChanged");

jsignal->connect(this, &MyClass::textChanged);

WPushButton *b = new WPushButton("Save", root());

command = "function(object, event) {" +

jsignal->createCall(editor_ref + ".editor.getValue()") +

";}";

b->clicked().connect(command);

}

void MyClass::textChanged(std::string incoming)

{

}

更新2

这是我的项目看起来像atm,仍然在右上角有一个带有红色“Loading …”消息的白色屏幕.以下更多说明.

MyClass::MyClass(const WEnvironment& env)

: WApplication(env)

{

wApp->require("lib/ace/ace.js");

// A WContainerWidget is rendered as a div

WContainerWidget *editor = new WContainerWidget(root());

editor->resize(500, 500);

std::string editor_ref = editor->jsRef(); // is a text string that will be the element when executed in JS

std::string command =

editor_ref + ".editor = ace.edit(" + editor_ref + ");" +

editor_ref + ".editor.setTheme(\"ace/theme/monokai\");" +

editor_ref + ".editor.getSession().setMode(\"ace/mode/javascript\");";

editor->doJavaScript(command);

JSignal <:string> *jsignal = new JSignal<:string>(editor, "textChanged");

jsignal->connect(this, &MyClass::textChanged);

WPushButton *b = new WPushButton("Save", root());

command = "function(object, event) {" +

jsignal->createCall(editor_ref + ".editor.getValue()") +

";}";

b->clicked().connect(command);

}

void MyClass::textChanged(std::string incoming)

{

}

当用于编辑器时,“command”变量等于以下内容 – > doJavaScript(命令)

"Wt3_3_0.$('oy4ycjy').editor = ace.edit(Wt3_3_0.$('oy4ycjy'));Wt3_3_0.$('oy4ycjy').editor.setTheme('ace/theme/monokai');Wt3_3_0.$('oy4ycjy').editor.getSession().setMode('ace/mode/javascript');"

当用于b-> clicked()时,“command”变量等于以下变量.connect(command);

"function(object, event) {Wt.emit('oy4ycjy','textChanged',Wt3_3_0.$('oy4ycjy').editor.getValue());;}"

更新1

将建议的代码添加到我的构造函数中,但页面不会从纯白色屏幕更改.我在这个WT项目中没有做任何其他事情,只有这个代码正在运行.

wApp->require("lib/ace/ace.js");

// A WContainerWidget is rendered as a div

WContainerWidget *editor = new WContainerWidget(root());

std::string editor_ref = editor->jsRef(); // is a text string that will be the element when executed in JS

editor->doJavaScript(

editor_ref + ".editor = ace.edit('" + editor_ref + "');" +

editor_ref + ".editor.setTheme('ace/theme/monokai');" +

editor_ref + ".editor.getSession().setMode('ace/mode/javascript');"

);

editor_ref的值是“Wt3_3_0.$(‘oumvrgm’)”减去引号.

还尝试添加下面的代码,页面仍然消失.

JSignal <:string> *jsignal = new JSignal<:string>(editor, "textChanged");

jsignal->connect(this, &MyClass::textChanged);

WPushButton *b = new WPushButton("Save", root());

b->clicked().connect("function(object, event) {" +

jsignal->createCall(editor->jsRef() + ".editor.getValue()") +

";}");

我也发现了评论

editor_ref + ".editor = ace.edit('" + editor_ref + "');" +

使按钮显示,但屏幕右上方有一个红色的“正在加载…”注释,因此WT正在等待某些事情.

我现在将textChanged视为无效功能.

原始邮政

所以,我的问题是这个.如何在WT http://www.webtoolkit.eu/wt中获得ACE http://ace.ajax.org/#nav=about.更具体地说,WT Wt :: WTextArea或Wt :: WTabWidget中的ACE,文本区域将是首选.我一直试图这样做几天,并没有取得多大成功.

我已经能够在HTML页面中嵌入ACE没有问题,因为他们的网站说“只需将其复制并粘贴到您的页面中”,这真的很简单.但是,我需要通过WT本地加载到容器中.我将他们的回购从GIT下载到我的机器并尝试使用

require("lib/ace/ace.js");

doJavaScript(...);

各种命令都没有成功……我在Java和HTML方面的表现并不像C那么强,所以如果涉及大量的Java / HTML,我会尽可能详细地询问.在此先感谢您的配偶!

解决方法:

也许这会让你朝着正确的方向前进:

wApp->require("lib/ace/ace.js")

// A WContainerWidget is rendered as a div

WContainerWidget *editor = new WContainerWidget(parent);

// editor->jsRef() is a text string that will be the element when executed in JS

editor->doJavaScript(

editor->jsRef() + ".editor = ace.edit(" + editor->jsRef() + ");" +

editor->jsRef() + ".editor.setTheme('ace/theme/monokai');" +

editor->jsRef() + ".editor.getSession().setMode('ace/mode/javascript');"

);

这应该装饰编辑器. Wt不会自动将修改发送到服务器的div,因此您可以通过JSignal手动执行此操作(从JS发送信号到C):

JSignal <:string> *jsignal = new JSignal<:string>(editor, "textChanged");

jsignal->connect(this, MyClass::textChanged);

WPushButton *b = new WPushButton("Save", parent);

b->clicked().connect("function(object, event) {" +

jsignal->createCall(editor->jsRef() + ".editor.getValue()") +

";}");

(以上代码未经过测试,因此您可能需要稍微调整一下)

我已经在早期的JWt(java)项目中集成了CodeMirror,如下所示:

import eu.webtoolkit.jwt.WApplication;

import eu.webtoolkit.jwt.WContainerWidget;

import eu.webtoolkit.jwt.WTextArea;

public class CodeMirrorTextArea extends WContainerWidget {

private WTextArea textArea;

public CodeMirrorTextArea(WContainerWidget parent) {

super(parent);

textArea = new WTextArea(this);

WApplication app = WApplication.getInstance();

app.require(app.resolveRelativeUrl("codemirror-2.32/lib/codemirror.js"));

app.require(app.resolveRelativeUrl("codemirror-2.32/mode/groovy/groovy.js"));

//TODO:

//We save the editor state to the text area on each key stroke,

//it appears to be not a performance issue,

//however it might very well become one when editing larger fragments of code.

//A better solution would be to save this state to the text area only when

//the form is submitted, currently this is not yet possible in Wt???.

String js =

"var e = " + textArea.getJsRef() + ";" +

"var cm = CodeMirror.fromTextArea(e, {" +

" onKeyEvent : function (editor, event) {" +

" editor.save();" +

" }," +

" lineNumbers: true" +

" });" +

"var self = " + getJsRef() + ";" +

"self.cm = cm;";

this.doJavaScript(js);

}

public CodeMirrorTextArea() {

this(null);

}

public void setText(String text) {

textArea.setText(text);

}

public String getText() {

return textArea.getText();

}

public void setMarker(int line, String htmlMarker) {

String js =

"var self = " + getJsRef() + ";" +

"self.cm.setMarker(" + line + ", " + jsStringLiteral(htmlMarker +

"%N%") + ");";

this.doJavaScript(js);

}

public void clearMarker(int line) {

String js =

"var self = " + getJsRef() + ";" +

"self.cm.clearMarker(" + line + ");";

this.doJavaScript(js);

}

}

标签:html,java,c,ajax,wt

来源: https://codeday.me/bug/20190929/1831118.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
课程目录 1001_RocketMQ_简介[免费观看]17:13 2002_RocketMQ_核心概念详解[免费观看]36:44 3003_RocketMQ_集群构建模型详解(一)27:47 4004_RocketMQ_集群构建模型详解(二)23:36 5005_RocketMQ_双主模式集群环境搭建39:05 6006_RocketMQ_控制台使用讲解10:41) 7007_RocketMQ_Broker配置文件详解20:38 8008_RocketMQ_helloworld示例讲解34:29 9009_RocketMQ_整体架构概述详解15:36 10010_RocketMQ_Producer_API详解24:49 11011_RocketMQ_Producer_顺序消费机制详解24:37 12012_RocketMQ_Producer_事务消息机制详解38:15 13013_RocketMQ_Consumer_Push和Pull模式及使用详解28:21 14014_RocketMQ_Consumer_配置参数详解06:45 15015_RocketMQ_Consumer_重试策略详解33:08 16016_RocketMQ_Consumer_幂等去重策略详解33:48 17017_RocketMQ_消息模式及使用讲解14:12 18018_RocketMQ_双主双从集群环境搭建与使用详解40:30 19019_RocketMQ_FilterServer机制及使用详解35:31 20020_RocketMQ_管理员命令16:37 JAVA-ACE-架构师系列视频课程- RocketMQ(下)订单实战视频课程 适用人群: 高级java工程师、java架构师 共23课时共9小时33分钟更新时间:2017-04-05 课程目标 RocketMQ(下)订单实战主要讲解rmq的分布式实战项目,围绕着订单模块等进行讲解,实现补偿等 课程目录 101_rocketmq_实战项目介绍[免费观看]22:54 202_rocketMQ实战项目设计(一)26:36 303_rocketMQ实战项目设计(二)18:39 404_rocketMQ实战-环境搭建(一)27:03 505_rocketMQ实战-环境搭建(二)28:24 606_rocketMQ实战-生产者与spring结合30:20 707_rocketMQ实战-消费者与spring结合25:47 808_rocketMQ实战-数据库模型设计28:18 909_rocketMQ实战-数据库DAO代码生成27:26 1010_rocketMQ实战-远程RPC接口设计与实现(一)29:29 1111_rocketMQ实战-远程RPC接口设计与实现(二)24:03 1212_rocketMQ实战-远程RPC接口设计与实现(三)16:44 1313_rocketMQ实战-下单流程(一)21:57 1414_rocketMQ实战-下单流程(二)22:51 1515_rocketMQ实战-下单流程(三)33:20 1616_rocketMQ实战-下单流程(四)27:47 1717_rocketMQ实战-下单流程(五)23:25 1818_rocketMQ实战-下单流程(六)17:48 1919_rocketMQ实战-下单流程(七)26:56 2020_rocketMQ实战-下单流程(八)-商品库存25:43 2121_rocketMQ实战-下单流程(九)-商品库存28:47 2222_rocketMQ实战-下单流程(十)-支付模块11:11 2323_rocketMQ实战-整体联调27:44

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值