Double focus in Writer?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
martin.illguth
Posts: 1
Joined: Mon Jul 22, 2013 3:12 pm

Double focus in Writer?

Post by martin.illguth »

Hello there,

we`ve got a project-management-software written in Java which embedds the OOoBean.
We have embedded the OOoBean into the top Panel of a JInternalFrame.
The top panels is called the writerPanel and contains only the OOoBean.
The bottom panel is called the optionsPanel and holds all custom controlls.
http://s7.directupload.net/images/130722/o2cfja6w.jpg
http://s7.directupload.net/images/130722/o2cfja6w.jpg
We encounter two major problems at the moment:
1. Double – Cursor/Focus – Bug
At the moment there are two cursors displaying when clicking inside the OOoBean:
The document has one focus and the currently active java component also has a focus.
The problem now is when you want to write something into a JTextfield in the lower optionsPanel while the document has focus, the entered text will be appended into the document and not the JTextfield (although it has a selection and blinking cursor). The OOoBean won`t lose its focus, no matter what.
As a workaround i added a ChangeListener to all input components inside the optionsPanel which performs a OOoBean.releaseSystemWindow() followed by a OOoBean.aquireSystemWindow(). But even this does not guarantee the focus in the optionsPanel will be the „active“ one.
I also tried MouseListeners on the optionsPanel to make use of the mouseEnter-Events but unfortunately the the event is fired way too often and the mouseLeave-Event on the writerPanel which contains the OOoBean does not always fire/get these events…
Any suggestions how to fix this?

2. Timeout – OpenOffice
From time to time (especially if you want to copy & paste something from an application outside the embedded OOoBean into the document) the connection to the OpenOffice is lost. I know there are three timeouts which are set to
OOoBean.setOOoStartTimeout(180000) //Default: 60000
OOoBean.setOOoCallTimeout(30000) //Default: 10000
OOoBean.setOOoCheckcycle(300) //Default: 100
in our application but altering them does not really seem to help in any way.
Any suggestions how to fix this?

Additional informations on the future of the project are also welcome:
1. Roadmap OOoBean
What is the upcoming roadmap for the OOoBean? Will there be future development or is it going to be abandoned? When will the next version be released? Do you guys think i need to look for alternatives? (LibreOffice, NOA, etc…)

2. Roadmap OpenOffice
What is the roadmap for OpenOffice? Will there be future development or is it going to be abandoned? When will the next version be released? (i know there are some informations about OpenOffice 4.0 but i couldn`t find any release date announcements)

I attached a simple file which shows at least the first problem. (You need a working OOoBean-Integration for it to work)
The second one is hard to reconstruct and only happens from time to time.

Additional informations:
Java-Version: JRE 1.7_21
OpenOffice-Version: 3.4.1
OpenOffice-Install-Path: „C:\sw\OpenOffice.org 3\“ (without the quotes; exists on each client)
OS: WinXP (32/64Bit) and Win7 (32/64Bit)

I know this informations are a bit generous so i will try to provide any further informations as needed.

With best regards,
Martin Illguth
fpvolquind
Posts: 1
Joined: Fri Dec 15, 2017 3:19 pm

Re: Double focus in Writer?

Post by fpvolquind »

I know this thread is really old, but I recently stumbled on the same problem, and lost some 2-3 days "working" on it (more like :crazy: ).
Also, this still happens as of LibreOffice 5.3.
The solution I used is this:
- add a simple FocusListener to every text component you want to monitor:

Code: Select all

    private FocusListener focusListener = new FocusListener() {
                @Override
                public void focusGained(FocusEvent e) {
                    parentComponent.grabTheFocus();
                }

                @Override
                public void focusLost(FocusEvent e) {
                    //nop
                }
            };
- on the JPanel that holds the OOOBean (I'm using a separate class extending JPanel), make it implement XMouseClickHandler, add the required methods, plus a releaseTheFocus method:

Code: Select all

    @Override
    public boolean mouseReleased(com.sun.star.awt.MouseEvent e) {
        //System.out.println("Mouse released (" + e.X + ", " + e.Y + ")");
        this.getParent().requestFocus(); //you need this so any field that previously had the focus loses it
        hasFocus=true;
        return false;
    }

    @Override
    public boolean mousePressed(com.sun.star.awt.MouseEvent e) {
        //System.out.println("Mouse pressed (" + e.X + ", " + e.Y + ")");
        return false;    // send event on, or use true not to send
    }

    @SuppressWarnings("deprecation")
    public void releaseTheFocus() {
        if(hasFocus) {
            try {
                oob.releaseSystemWindow();
                oob.aquireSystemWindow();
            } catch (Exception ex) {
                //   ¯\_(ツ)_/¯
            }
            hasFocus=false;
        }
    }

- now, on the component/container/whatever that holds all together, implement the method grabTheFocus which will call the OOB panel's releaseTheFocus.
- the hasFocus flag is there because every time releaseTheFocus() is called, the OOOBean flickers, and it was getting annoying.

Hope someone finds this useful.
LibreOffice 5.4 on Windows 7
Post Reply