Example usage for java.awt Frame removeWindowFocusListener

List of usage examples for java.awt Frame removeWindowFocusListener

Introduction

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

Prototype

public synchronized void removeWindowFocusListener(WindowFocusListener l) 

Source Link

Document

Removes the specified window focus listener so that it no longer receives 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  a va2s. c o  m

        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();
}