HTML Editor with Java and And webkit

i want to add WYSIWYG HTML editor to my Java program.
my idea is to do Something like this but not with python - with Java.

i know about couple of options and their problems :

  • HTMLEditorKit - not sophisticated enough.
  • JWebpane - fairy tale.
  • QtWebKit - not open source.
  • JWebEngine - not open source.
  • metaphaseeditor - to simple.
  • The Lobo Project - not support the contenteditable attribute.
  • JavaXPCOM - I don't Succeed to operate it on my mac OS X 10.6.
    Anyway, I just prefer not to use it because Gecko is slower then webkit.
  • That's way I chose to work with Browser Object from org.eclipse.swt.browser Package.

    For now, I have the code below:
    The code, first create a instance of the browser object.
    After this it's load HTML page with contenteditable='true' attributes on the body tag.
    If its load a page its supposed to add contenteditable='true' attributes to the body tag, and when its save the page it's supposed remove it.

    My questions are:

  • How do I grab the edited HTML code?
  • How do I know were the cursor is step on?
  • How do I know if some text is highlighted?
  • Or, in general :

  • How do I build a word possessor with Browser Object and ontenteditable='true' attributes?
  • is it possible?
  • is this the right way for WYSIWYG HTML editor in Java?
  • Any Examples out there?
    I already check the SWT Snippets - doesn't help much.
  • Thanks a lot.

    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


    I like it that you asked some very specific questions! Good job brainstorming before you get your hands dirty.

    Fortunately, there's a fairly generic solution to your problem: just run JavaScript in the browser.

    For instance:

    Browser browser = new Browser(parent, SWT.NONE);
    // Just to be sure we can use JavaScript
    browser.setJavascriptEnabled(true);
    boolean result = browser.execute("alert('Hello SWT!')");
    if (result) {
        System.out.println("script executed");
    } else {
        System.err.println("script failed to execute");
    }
    

    Of course you might want to send data from the browser back to SWT; in this case you might end up in the worst case having to parse browser.getText() . I'm not sure if there's a better way of doing this.


    你的这一个tinymc:http://tinymce.moxiecode.com/它有很好的文档,你可以将它集成到几乎任何现有的代码,因为它有一个很好的界面和大量的插件。

    链接地址: http://www.djcxy.com/p/48766.html

    上一篇: textareas中的内容设置为使用nicEdit不更新以反映用户更改

    下一篇: 带有Java和And webkit的HTML编辑器