Example usage for java.awt Frame addWindowFocusListener

List of usage examples for java.awt Frame addWindowFocusListener

Introduction

In this page you can find the example usage for java.awt Frame addWindowFocusListener.

Prototype

public synchronized void addWindowFocusListener(WindowFocusListener l) 

Source Link

Document

Adds the specified window focus listener to receive window events from this window.

Usage

From source file:org.freeplane.main.application.MapViewDockingWindows.java

public void focusMapViewLater(final MapView mapView) {
    Timer timer = new Timer(40, new ActionListener() {
        int retryCount = 5;

        public void actionPerformed(final ActionEvent event) {
            final Timer eventTimer = (Timer) event.getSource();
            focusMapLater(mapView, eventTimer);
        }/*from   w w w. j  av a2  s  . c om*/

        private void focusMapLater(final MapView mapView, final Timer eventTimer) {
            if (mapView.isShowing()
                    && Controller.getCurrentController().getMapViewManager().getMapViewComponent() == mapView) {
                final NodeView selected = mapView.getSelected();
                if (selected != null) {
                    final Frame frame = JOptionPane.getFrameForComponent(mapView);
                    if (frame.isFocused())
                        selected.requestFocusInWindow();
                    else
                        frame.addWindowFocusListener(new WindowAdapter() {
                            @Override
                            public void windowGainedFocus(WindowEvent e) {
                                frame.removeWindowFocusListener(this);
                                selected.requestFocusInWindow();
                                retryCount = 2;
                                eventTimer.start();
                            }
                        });
                }
            }
            if (retryCount > 1) {
                retryCount--;
                eventTimer.start();
            }
        }
    });
    timer.setRepeats(false);
    timer.start();
}