我想将WYSIWYG
HTML编辑器添加到我的
Java程序中.
我的想法是做像 this这样的事情
但不是用python – 用Java.
我的想法是做像 this这样的事情
但不是用python – 用Java.
我知道几个选项及其问题:
> HTMLEditorKit – 不够复杂.
> JWebpane – 童话故事.
> QtWebKit – 不是开源的.
> JWebEngine – 不是开源的.
> Metaphaseeditor – 简单.
> Lobo项目 – 不支持contenteditable属性.
> JavaxpcOM – 我不成功在我的Mac OS X 10.6上运行它.
无论如何,我只是不想使用它,因为Gecko比webkit慢.
这是我选择合作的方式
Browser Object来自org.eclipse.swt.browser包.
现在,我有以下代码:
代码,首先创建一个浏览器对象的实例.
在此之后,它会在body标签上加载带有contenteditable =’true’属性的HTML页面.
如果它加载一个页面,它应该为body标签添加contenteditable =’true’属性,当它保存页面时,它应该删除它.
我的问题是:
>如何获取已编辑的HTML代码?
>我如何知道光标是否踩到了?
>我如何知道某些文字是否突出显示?
或者,一般来说:
>
如何使用browser Object和ontenteditable =’true’属性构建word拥有者?
>有可能吗?
>这是Java中WYSIWYG HTML编辑器的正确方法吗?
>那里有任何例子吗?
我已经检查过SWT Snippets – 没什么用.
非常感谢.
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.display;
import org.eclipse.swt.widgets.Shell;
public class editor {
public static void main(String [] args) {
String html = "<html><title>Editor</title>"
+ "<body contenteditable='true'>"
+ " <h2>All the Page is ditable!!!!!</h2>"
+ "<p>Heres a typical paragraph element</p>"
+ "<ol><li>and Now a list</li>"
+ "<li>with only</li>"
+ "<li>three items</li>"
+ "</ol></body></html>";
display display = new display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final browser browser;
try {
browser = new browser(shell,SWT.BORDER);
}
catch (SWTError e) {
System.out.println(e.getMessage());
display.dispose();
return;
}
Composite comp = new Composite(shell,SWT.NONE);
comp.setLayout(new FillLayout(SWT.ALL));
browser.setText(html);
shell.open();
while (!shell.isdisposed()) {
if (!display.readAnddispatch())
display.sleep();
}
display.dispose();
}
}
解决方法
DJ Native Swing项目有几个HTML编辑器,使用SWT浏览器实现(这是一个实现细节):
http://djproject.sourceforge.net/ns