Example usage for java.awt.event WindowEvent getOppositeWindow

List of usage examples for java.awt.event WindowEvent getOppositeWindow

Introduction

In this page you can find the example usage for java.awt.event WindowEvent getOppositeWindow.

Prototype

public Window getOppositeWindow() 

Source Link

Document

Returns the other Window involved in this focus or activation change.

Usage

From source file:Main.java

protected void processWindowEvent(WindowEvent e) {
    System.out.println(e.getOppositeWindow());
    super.processWindowEvent(e); // Pass on the event
}

From source file:Main.java

public Main(final Frame owner) {
    super(owner);
    JPanel pnl = new JPanel(new BorderLayout());
    pnl.add(new JLabel("Click outside this dialog in the parent frame to close it"), BorderLayout.NORTH);
    JButton btn = new JButton("Click Me");
    btn.addActionListener(e -> JOptionPane.showMessageDialog(Main.this, "New Child Window"));
    pnl.add(btn, BorderLayout.CENTER);
    this.setContentPane(pnl);
    this.pack();//from ww w  . j  a  v  a  2  s  .com
    this.setLocationRelativeTo(owner);
    this.setAlwaysOnTop(true);
    this.addWindowFocusListener(new WindowFocusListener() {
        public void windowGainedFocus(WindowEvent e) {
        }

        public void windowLostFocus(WindowEvent e) {
            if (SwingUtilities.isDescendingFrom(e.getOppositeWindow(), Main.this)) {
                return;
            }
            Main.this.setVisible(false);
        }
    });
}

From source file:com.aw.swing.mvp.JDialogView.java

private void initializeDlg() {
    if (pst.isEmbeddedView()) {
        return;//w w  w. j a v  a2s .  co  m
    }
    JDialog dlg = (JDialog) parentContainer;

    dlg.add(viewLayout.mainPanel, BorderLayout.CENTER);

    //        SwingUtils.locateOnScreenCenter(dlg);
    SwingUtils.locateRelativeToMenu(dlg);
    dlg.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    dlg.addWindowListener(new java.awt.event.WindowAdapter() {
        // todo ver cmo se va a hacer esto en la versin Filthy
        public void windowOpened(WindowEvent e) {
            if (pst != null) {
                pst.onWindowsOpened(e);
                pst.onWindowsOpenedInternalOnlyForAWFW(e);
                if (!pst.isReadOnly()) {
                    //                        pst.setFocusToCmpOnWindowOpen();
                    //                        ActionManager.instance().getVisualMgrForActions().repaintMainDisabledActions(pst.getActionRsr());
                } else {
                    pst.configureAsReanOnly();
                    JButton btnCancel = (JButton) pst.getIpView().getComponent("btnCancel");
                    if (btnCancel != null) {
                        btnCancel.requestFocusInWindow();
                    }
                }
            }
        }

        public void windowClosing(WindowEvent e) {
            MsgDisplayer.showMessage("sw.common.closeWindowDisabled");
        }

        public void windowActivated(WindowEvent e) {
            Object oppositeWindow = e.getOppositeWindow();

            if (oppositeWindow instanceof DlgMensaje) {
                logger.debug("Ignoring Windows activated for DlgMensaje");
                return;
            }
            if (oppositeWindow instanceof JDialog) {
                JDialog dlg = (JDialog) oppositeWindow;
                if (MessageDisplayer.GENERIC_MESSAGE_TITLE.equals(dlg.getTitle())) {
                    logger.debug("Ignoring Windows activated for System Msg");
                    return;
                }
            }
            logger.debug("Windows Activated:" + pst);
            AWWindowsManager.instance().setPresenterActivated(pst);
        }
    });
}