Example usage for java.awt.event WindowListener windowClosing

List of usage examples for java.awt.event WindowListener windowClosing

Introduction

In this page you can find the example usage for java.awt.event WindowListener windowClosing.

Prototype

public void windowClosing(WindowEvent e);

Source Link

Document

Invoked when the user attempts to close the window from the window's system menu.

Usage

From source file:Main.java

/**
 * Attaches a key event listener to given component, disposing of the given window
 * upon pressing escape within the context.
 * /*  ww w. ja  va 2s  .  c o m*/
 * @param context
 * @param button
 */
public static void simulateExitOnEscape(Component context, JFrame window) {
    context.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                for (WindowListener wl : window.getWindowListeners()) {
                    wl.windowClosing(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
                }

                if (window != null)
                    window.dispose();
            }
        }
    });
}

From source file:fi.smaa.jsmaa.gui.JSMAAMainFrame.java

public void quit() {
    for (WindowListener w : getWindowListeners()) {
        w.windowClosing(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    }/*from   w  w w .ja v a  2  s  .  c  om*/
}

From source file:gui.DownloadManagerGUI.java

@Override
public void actionPerformed(ActionEvent e) {
    JMenuItem clicked = (JMenuItem) e.getSource();

    if (clicked == exportDataItem) {
        //    addNewDownloadDialog.setVisible(true);
    } else if (clicked == importDataItem) {
        //    addNewDownloadDialog.setVisible(true);
    } else if (clicked == exitItem) {
        WindowListener[] listeners = getWindowListeners();
        for (WindowListener listener : listeners)
            listener.windowClosing(new WindowEvent(DownloadManagerGUI.this, 0));
    } else if (clicked == prefsItem) {
        preferenceDialog.setVisible(true);
    } else if (clicked == newDownloadItem) {
        addNewDownloadDialog.setVisible(true);
        addNewDownloadDialog.onPaste();/*from w ww.  ja va 2  s .c  o  m*/
    } else if (clicked == openItem) {
        downloadPanel.actionOpenFile();
    } else if (clicked == openFolderItem) {
        downloadPanel.actionOpenFolder();
    } else if (clicked == resumeItem) {
        downloadPanel.actionResume();
    } else if (clicked == pauseItem) {
        downloadPanel.actionPause();
        mainToolbar.setStateOfButtonsControl(false, false, false, false, false, true); // canceled
    } else if (clicked == pauseAllItem) {
        int action = JOptionPane.showConfirmDialog(DownloadManagerGUI.this,
                "Do you realy want to pause all downloads?", "Confirm pause all", JOptionPane.OK_CANCEL_OPTION); ////***********
        if (action == JOptionPane.OK_OPTION) {
            downloadPanel.actionPauseAll();
        }
    } else if (clicked == clearItem) {
        downloadPanel.actionClear();
    } else if (clicked == clearAllCompletedItem) {
        downloadPanel.actionClearAllCompleted();
    } else if (clicked == reJoinItem) {
        downloadPanel.actionReJoinFileParts();
    } else if (clicked == reDownloadItem) {
        downloadPanel.actionReDownload();
    } else if (clicked == moveToQueueItem) {
        //        mainToolbarListener.preferencesEventOccured();
    } else if (clicked == removeFromQueueItem) {
        //        mainToolbarListener.preferencesEventOccured();
    } else if (clicked == propertiesItem) {
        downloadPanel.actionProperties();
    } else if (clicked == aboutItem) {
        if (!aboutDialog.isVisible())
            aboutDialog.setVisible(true);
    }
}