Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java tools & IDE's > OpenOffice Java API


Автор: firedrago 30.9.2005, 22:43
Всем привет!

вот решил я в мой клиент для emaila OpenOfficeовский Writer вставить, что б можно было без проблем на HTMLные письма отвечать,
начал разбираться, нашел пару примеров, но как сделать например отключение загрузки/записи файла, отключение других функций, которые доступны по
shortcutам я не нашел. может кто-то уже это делал?

если кто хочет с этим зверьком поигратся то вот пару линков и пример как вставить Writer в SWT, любителям AWT я думаю переделать этот пример будет не сложно.

Все идеи и советы приветствуются!

http://development.openoffice.org/
http://api.openoffice.org/DevelopersGuide/DevelopersGuide.html
http://api.openoffice.org/docs/DevelopersGuide/OfficeBean/OfficeBean.htm
https://vheissu.mersenne.com/OO/examples/examples.html#Java_examples


Jarы лежат в ....OpenOffice 1.9.xxx/program/classes/
Код

package ooswtviewer;

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Panel;

import javax.swing.JRootPane;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
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 OOoSwtSnippet {

    private static final String OFFICE_DOCUMENT = "file:///C:\\1.html";
    private static final String NEW_WRITTER_DOCUMENT = "private:factory/swriter";

    public static void main(String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());

        Composite composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.EMBEDDED);

        try {
            System.setProperty("sun.awt.noerasebackground", "true");
        } catch (NoSuchMethodError error) {
        }

        /* Create and setting up frame */
        Frame frame = SWT_AWT.new_Frame(composite);
        Panel panel = new Panel(new BorderLayout()) {
            private static final long serialVersionUID = -4125271782073546973L;

            public void update(java.awt.Graphics g) {
                paint(g);
            }
        };
        frame.add(panel);
        JRootPane root = new JRootPane();
        panel.add(root);
        java.awt.Container contentPane = root.getContentPane();

        shell.setSize(800, 600);
        final OOoSwtViewer viewer = new OOoSwtViewer();
        contentPane.add(viewer);

         
        try {
//            viewer.setDocument(NEW_WRITTER_DOCUMENT);
            viewer.setDocument(OFFICE_DOCUMENT);
        } catch (Exception e) {
            e.printStackTrace();
        }

        shell.open();
        shell.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                try {
                    viewer.close();
                } catch (RuntimeException exception) {
                    exception.printStackTrace();
                }
            }

        });
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}


Код

package ooswtviewer;

import java.awt.Panel;
import java.io.IOException;

import com.sun.star.comp.beans.NoConnectionException;
import com.sun.star.comp.beans.OOoBean;
import com.sun.star.comp.beans.SystemWindowException;
import com.sun.star.frame.XDesktop;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.util.CloseVetoException;

public class OOoSwtViewer extends Panel {

    public final String SWRITER = "private:factory/swriter";

    private static final long serialVersionUID = -1408623115735065822L;

    private OOoBean aBean;

    public OOoSwtViewer() {
        super();
        aBean = new OOoBean();
        setLayout(new java.awt.BorderLayout());
        add(aBean, java.awt.BorderLayout.CENTER);
        
//        aBean.setToolBarVisible(false);
//        aBean.setStandardBarVisible(false);
        aBean.setAllBarsVisible(false);
        aBean.setMenuBarVisible(false);
        aBean.setStatusBarVisible(false);
        
        /*
            //...load some document into the bean...
            OfficeDocument doc = bean.getDocument();
            XTextDocument xTextDocument = doc.queryInterface(new Type(XTextDocument.class));
            //...do something with the document...
         */

    }

    public void setDocument(String url) throws IllegalArgumentException, CloseVetoException, NoConnectionException, IOException, SystemWindowException {
        aBean.loadFromURL(url, null);
        aBean.aquireSystemWindow();
    }

    /**
     * closes the bean viewer and tries to terminate OOo.
     */
    public void terminate() throws NoConnectionException {
        setVisible(false);
        XDesktop xDesktop = null;
        xDesktop = aBean.getOOoDesktop();
        aBean.stopOOoConnection();
        if (xDesktop != null)
            xDesktop.terminate();
    }

    /**
     * closes the bean viewer, leaves OOo running.
     */
    public void close() {
        setVisible(false);
        aBean.stopOOoConnection();
    }
}

Автор: firedrago 29.10.2005, 15:06
вот сделали под лицензией LGPL
http://ubion.ion.ag/plonesoftwarecenter/003officeintegrationeditor
http://ubion.ion.ag/website_bilder/officeIntegrationEditorScreenshot.gif

и http://ubion.ion.ag/plonesoftwarecenter/004niceofficeaccess
пример использования
http://ubion.ion.ag/website_bilder/noaExampleScreenshot.gif

Автор: GSMD 31.10.2005, 14:07
Может, пригодится:
http://www.linuxjournal.com/article/8550
http://www.linuxjournal.com/article/8608

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)