Example usage for java.awt.event WindowEvent WINDOW_CLOSING

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

Introduction

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

Prototype

int WINDOW_CLOSING

To view the source code for java.awt.event WindowEvent WINDOW_CLOSING.

Click Source Link

Document

The "window is closing" event.

Usage

From source file:org.zaproxy.zap.extension.ascan.ScanProgressDialog.java

private JButton getCloseButton() {
    // Note that on Linux dialogs dont get close buttons on the frame decoration
    if (closeButton == null) {
        closeButton = new JButton(Constant.messages.getString("all.button.close"));
        closeButton.addActionListener(new ActionListener() {
            @Override/*  w w  w.j  av  a 2  s. c om*/
            public void actionPerformed(ActionEvent e) {
                dispatchEvent(new WindowEvent(ScanProgressDialog.this, WindowEvent.WINDOW_CLOSING));
            }
        });
    }
    return closeButton;
}

From source file:org.parosproxy.paros.view.FindDialog.java

/**
 * This method initializes btnCancel   //from w w  w .java 2s .c o  m
 *    
 * @return javax.swing.JButton   
 */
private JButton getBtnCancel() {
    if (btnCancel == null) {
        btnCancel = new JButton();
        btnCancel.setText(Constant.messages.getString("edit.find.button.cancel"));
        btnCancel.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {

                FindDialog.this.discard();
                FindDialog.this.dispatchEvent(new WindowEvent(FindDialog.this, WindowEvent.WINDOW_CLOSING));
            }
        });

    }
    return btnCancel;
}

From source file:Forms.CreateGearForm.java

private void lintSpec(final GearSpec spec) {
    LintGearSpecWorker worker = new LintGearSpecWorker(spec) {
        @Override// w  w  w  .  j  a v  a2s .c o  m
        protected void done() {
            super.done();

            if (result.getPassed()) {
                if (saveSpec(spec)) {
                    JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel);
                    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
                }
            } else {
                showLintErrorDialog(result);
            }
        }
    };
    worker.execute();
}

From source file:org.apache.tika.gui.TikaGUI.java

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if ("openfile".equals(command)) {
        int rv = chooser.showOpenDialog(this);
        if (rv == JFileChooser.APPROVE_OPTION) {
            openFile(chooser.getSelectedFile());
        }/* w  w w . j a v  a  2s.c o  m*/
    } else if ("openurl".equals(command)) {
        Object rv = JOptionPane.showInputDialog(this, "Enter the URL of the resource to be parsed:", "Open URL",
                JOptionPane.PLAIN_MESSAGE, null, null, "");
        if (rv != null && rv.toString().length() > 0) {
            try {
                openURL(new URL(rv.toString().trim()));
            } catch (MalformedURLException exception) {
                JOptionPane.showMessageDialog(this, "The given string is not a valid URL", "Invalid URL",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } else if ("html".equals(command)) {
        layout.show(cards, command);
    } else if ("text".equals(command)) {
        layout.show(cards, command);
    } else if ("main".equals(command)) {
        layout.show(cards, command);
    } else if ("xhtml".equals(command)) {
        layout.show(cards, command);
    } else if ("metadata".equals(command)) {
        layout.show(cards, command);
    } else if ("json".equals(command)) {
        layout.show(cards, command);
    } else if ("about".equals(command)) {
        textDialog("About Apache Tika", TikaGUI.class.getResource("about.html"));
    } else if ("exit".equals(command)) {
        Toolkit.getDefaultToolkit().getSystemEventQueue()
                .postEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    }
}

From source file:LoginUI.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) throws ParseException {
    HashMap<String, String> userpw = getUserInfo();
    String inputuser = jTextField1.getText();
    char[] inputpw = jTextField2.getPassword();
    String pw = new String(inputpw);
    //wrong username
    if (!userpw.containsKey(inputuser)) {
        JOptionPane.showMessageDialog(null, "Username does not exist!", "Failed", JOptionPane.ERROR_MESSAGE);
    }/*w  w w . j  a v  a2 s  .  co m*/

    // wrong password
    else if (!userpw.get(inputuser).equals(pw)) {
        JOptionPane.showMessageDialog(null, "Incorrect Password", "Failed", JOptionPane.ERROR_MESSAGE);
    }

    else {
        MainGUI main = new MainGUI(inputuser);
        JOptionPane.showMessageDialog(null, "Login Successful!", "Success!", JOptionPane.INFORMATION_MESSAGE);
        WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);

        main.setVisible(true);
    }
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.LinkUnlinkWindow.java

@Override
protected void processWindowEvent(final WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        actuallyLinkUnlink();/*w  ww  .  j a v a2s.  c o  m*/
        LinkUnlinkWindow.this.dispose();
    }
}

From source file:org.barcelonamedia.uima.tools.docanalyzer.DBAnnotationViewerDialog.java

/**
 * Create an AnnotationViewer Dialog/*from   ww  w .j  av  a  2 s.  c o m*/
 * 
 * @param aParentFrame
 *          frame containing this panel
 * @param aTitle
 *          title to display for the dialog
 * @param aInputDir
 *          directory containing input files (in XCAS foramt) to read
 * @param aStyleMapFile
 *          filename of style map to be used to view files in HTML
 * @param aPerformanceStats
 *          string representaiton of performance statistics, optional.
 * @param aTypeSystem
 *          the CAS Type System to which the XCAS files must conform.
 * @param aTypesToDisplay
 *          array of types that should be highlighted in the viewer. This can be set to the output
 *          types of the Analysis Engine. A value of null means to display all types.
 */
/*public DBAnnotationViewerDialog(JFrame aParentFrame, String aDialogTitle, DBPrefsMediator med,
  File aStyleMapFile, String aPerformanceStats, TypeSystem aTypeSystem,
  final String[] aTypesToDisplay, String interactiveTempFN, boolean javaViewerRBisSelected,
  boolean javaViewerUCRBisSelected, boolean xmlRBisSelected, CAS cas) {
  super(aParentFrame, aDialogTitle);
  // create the AnnotationViewGenerator (for HTML view generation)
  this.med1 = med;
  this.cas = cas;
  annotationViewGenerator = new AnnotationViewGenerator(tempDir);
        
  launchThatViewer(med.getOutputDir(), interactiveTempFN, aTypeSystem, aTypesToDisplay,
    javaViewerRBisSelected, javaViewerUCRBisSelected, xmlRBisSelected, aStyleMapFile,
    tempDir);
}*/

public DBAnnotationViewerDialog(JFrame aParentFrame, String aDialogTitle, DBPrefsMediator med,
        File aStyleMapFile, String aPerformanceStats, TypeSystem aTypeSystem, final String[] aTypesToDisplay,
        boolean generatedStyleMap, CAS cas) {

    super(aParentFrame, aDialogTitle);

    this.xmiDAO = med.getXmiDAO();

    this.med1 = med;
    this.cas = cas;

    styleMapFile = aStyleMapFile;
    final String performanceStats = aPerformanceStats;
    typeSystem = aTypeSystem;
    typesToDisplay = aTypesToDisplay;

    // create the AnnotationViewGenerator (for HTML view generation)
    annotationViewGenerator = new AnnotationViewGenerator(tempDir);

    // create StyleMapEditor dialog
    styleMapEditor = new StyleMapEditor(aParentFrame, cas);
    JPanel resultsTitlePanel = new JPanel();
    resultsTitlePanel.setLayout(new BoxLayout(resultsTitlePanel, BoxLayout.Y_AXIS));

    resultsTitlePanel.add(new JLabel("These are the Analyzed Documents."));
    resultsTitlePanel.add(new JLabel("Select viewer type and double-click file to open."));

    try {

        String[] documents = this.xmiDAO.getXMIList();
        analyzedResultsList = new JList(documents);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.getViewport().add(analyzedResultsList, null);

        JPanel southernPanel = new JPanel();
        southernPanel.setLayout(new BoxLayout(southernPanel, BoxLayout.Y_AXIS));

        JPanel controlsPanel = new JPanel();
        controlsPanel.setLayout(new SpringLayout());

        Caption displayFormatLabel = new Caption("Results Display Format:");
        controlsPanel.add(displayFormatLabel);

        JPanel displayFormatPanel = new JPanel();
        displayFormatPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        displayFormatPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        javaViewerRB = new JRadioButton("Java Viewer");
        javaViewerUCRB = new JRadioButton("JV user colors");
        htmlRB = new JRadioButton("HTML");
        xmlRB = new JRadioButton("XML");

        ButtonGroup displayFormatButtonGroup = new ButtonGroup();
        displayFormatButtonGroup.add(javaViewerRB);
        displayFormatButtonGroup.add(javaViewerUCRB);
        displayFormatButtonGroup.add(htmlRB);
        displayFormatButtonGroup.add(xmlRB);

        // select the appropraite viewer button according to user's prefs
        javaViewerRB.setSelected(true); // default, overriden below

        if ("Java Viewer".equals(med.getViewType())) {
            javaViewerRB.setSelected(true);
        } else if ("JV User Colors".equals(med.getViewType())) {
            javaViewerUCRB.setSelected(true);
        } else if ("HTML".equals(med.getViewType())) {
            htmlRB.setSelected(true);
        } else if ("XML".equals(med.getViewType())) {
            xmlRB.setSelected(true);
        }

        displayFormatPanel.add(javaViewerRB);
        displayFormatPanel.add(javaViewerUCRB);
        displayFormatPanel.add(htmlRB);
        displayFormatPanel.add(xmlRB);

        controlsPanel.add(displayFormatPanel);

        SpringUtilities.makeCompactGrid(controlsPanel, 1, 2, // rows, cols
                4, 4, // initX, initY
                0, 0); // xPad, yPad

        JButton editStyleMapButton = new JButton("Edit Style Map");

        // event for the editStyleMapButton button
        editStyleMapButton.addActionListener(this);

        southernPanel.add(controlsPanel);

        // southernPanel.add( new JSeparator() );

        JPanel buttonsPanel = new JPanel();
        buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

        // APL: edit style map feature disabled for SDK
        buttonsPanel.add(editStyleMapButton);

        if (performanceStats != null) {
            JButton perfStatsButton = new JButton("Performance Stats");
            perfStatsButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    JOptionPane.showMessageDialog((Component) ae.getSource(), performanceStats, null,
                            JOptionPane.PLAIN_MESSAGE);
                }
            });
            buttonsPanel.add(perfStatsButton);
        }

        JButton closeButton = new JButton("Close");
        buttonsPanel.add(closeButton);

        southernPanel.add(buttonsPanel);

        // add list and panel container to Dialog
        getContentPane().add(resultsTitlePanel, BorderLayout.NORTH);
        getContentPane().add(scrollPane, BorderLayout.CENTER);
        getContentPane().add(southernPanel, BorderLayout.SOUTH);

        // event for the closeButton button
        closeButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                DBAnnotationViewerDialog.this.setVisible(false);
            }
        });

        // event for analyzedResultsDialog window closing
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLF(); // set default look and feel
        analyzedResultsList.setCellRenderer(new MyListCellRenderer());

        // doubleclicking on document shows the annotated result
        MouseListener mouseListener = new ListMouseAdapter();
        // styleMapFile, analyzedResultsList,
        // inputDirPath,typeSystem , typesToDisplay ,
        // javaViewerRB , javaViewerUCRB ,xmlRB ,
        // viewerDirectory , this);

        // add mouse Listener to the list
        analyzedResultsList.addMouseListener(mouseListener);
    } catch (DAOException e) {

        displayError(e.getMessage());

        this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    }
}

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * On any menu item click.// www. j av  a 2s  . c o m
 */
@Override
public void actionPerformed(ActionEvent arg0) {
    State.print(arg0.getActionCommand());
    switch (arg0.getActionCommand()) {
    case "new": //Try to save work, open new show
        try {
            newShow();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        break;
    case "open": //Try to save work, get new show
        openShow();
        break;
    case "save":
        Main.save();
        break;
    case "saveas":
        try {
            saveAs();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        break;
    case "printpage":
        try {
            desktop.setCursor(new Cursor(Cursor.WAIT_CURSOR));
            desktop.printCurrentPageToPdf();
            desktop.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        } catch (IOException e) {
            e.printStackTrace();
        }
        break;
    case "printshow":
        try {
            desktop.setCursor(new Cursor(Cursor.WAIT_CURSOR));
            desktop.printAllPagesToPdf();
            desktop.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        } catch (IOException e) {
            e.printStackTrace();
        }
        break;
    case "printdotsheets":
        try {
            desktop.setCursor(new Cursor(Cursor.WAIT_CURSOR));
            new DotSheetMaker().printDotSheets();
            desktop.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        break;
    case "togglegrid":
        Main.getState().getSettings().setShowGrid(!Main.getState().getSettings().shouldShowGrid());
        ((JMenu) getComponent(2)).getMenuComponent(0)
                .setForeground(Main.getState().getSettings().shouldShowGrid() ? Color.BLACK : Color.RED);
        break;
    case "togglenames":
        Main.getState().getSettings().setShowNames(!Main.getState().getSettings().shouldShowNames());
        ((JMenu) getComponent(2)).getMenuComponent(1)
                .setForeground(Main.getState().getSettings().shouldShowNames() ? Color.BLACK : Color.RED);
        break;
    case "toggletext":
        Main.getState().getSettings().setShowText(!Main.getState().getSettings().shouldShowText());
        ((JMenu) getComponent(2)).getMenuComponent(2)
                .setForeground(Main.getState().getSettings().shouldShowText() ? Color.BLACK : Color.RED);
        break;
    case "colordots":
        Main.getState().getSettings().setColorDots(!Main.getState().getSettings().shouldColorDots());
        ((JMenu) getComponent(2)).getMenuComponent(3)
                .setForeground(Main.getState().getSettings().shouldColorDots() ? Color.BLACK : Color.RED);
        break;
    case "changehash":
        Main.getState().getSettings().setCollegeHashes(!Main.getState().getSettings().useCollegeHashes());
        ((JMenuItem) (((JMenu) getComponent(2)).getMenuComponent(4)))
                .setText(Main.getState().getSettings().useCollegeHashes() ? "Change to High School Hashes"
                        : "Change to College Hashes");
        try {
            desktop.getImage();
        } catch (IOException e) {
            e.printStackTrace();
        }
        desktop.getDotDataFrame().updatePosition();
        break;
    case "fontsize":
        changeFontSize();
        break;
    case "play":
        play();
        break;
    case "undo":
        Main.getState().undo();
        desktop.getIO().clearActivePoints();
        desktop.getDotDataFrame().updateAll(desktop.getActivePoints());
        break;
    case "redo":
        Main.getState().redo();
        desktop.getIO().clearActivePoints();
        desktop.getDotDataFrame().updateAll(desktop.getActivePoints());
        break;
    case "help":
        help();
        break;
    case "about":
        about();
        break;
    case "quit":
    default:
        gr.dispatchEvent(new WindowEvent(gr, WindowEvent.WINDOW_CLOSING));
    }
    desktop.getIO().fixControl();
}

From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java

private JMenu createMenuFile() {
    final JMenu menuFile = new JMenu(Messages.getString("Menu.file")); //$NON-NLS-1$

    final JMenuItem menuFileOpen = new JMenuItem(Messages.getString("Menu.fileOpen")); //$NON-NLS-1$
    menuFileOpen.setMnemonic(KeyEvent.VK_O);
    menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_MASK));
    menuFileOpen.addActionListener(new ActionListener() {
        @Override/*from  w  w w.  ja  v a2s .  c  o  m*/
        public void actionPerformed(final ActionEvent e) {
            openFile();
        }
    });
    menuFile.add(menuFileOpen);
    menuFile.add(menuFileRecent);

    final JMenuItem menuFileReload = new JMenuItem(Messages.getString("Menu.fileReload")); //$NON-NLS-1$
    menuFileReload.setMnemonic(KeyEvent.VK_R);
    menuFileReload.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
    menuFileReload.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            reloadDefinition();
        }
    });
    menuFile.add(menuFileReload);

    final JMenuItem menuFileClose = new JMenuItem(Messages.getString("Menu.fileClose")); //$NON-NLS-1$
    menuFileClose.setMnemonic(KeyEvent.VK_C);
    menuFileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    menuFileClose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            closeSource();
        }
    });
    menuFile.add(menuFileClose);

    menuFile.addSeparator();

    final JMenuItem menuFileProperties = new JMenuItem(Messages.getString("Menu.properties")); //$NON-NLS-1$
    menuFileProperties.setMnemonic(KeyEvent.VK_P);
    menuFileProperties.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK));
    menuFileProperties.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPropertiesDialog();
        }
    });
    menuFile.add(menuFileProperties);

    menuFile.addSeparator();

    final JMenuItem menuFileExport = createMenuFileExport();
    menuFile.add(menuFileExport);

    menuFile.addSeparator();

    final JMenuItem menuFilePreferences = new JMenuItem(Messages.getString("Menu.preferences")); //$NON-NLS-1$
    menuFilePreferences.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPreferencesDialog();
        }
    });
    menuFile.add(menuFilePreferences);

    menuFile.addSeparator();

    final JMenuItem menuFileExit = new JMenuItem(Messages.getString("Menu.exit")); //$NON-NLS-1$
    menuFileExit.setMnemonic(KeyEvent.VK_E);
    menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
    menuFileExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            for (Frame frame : getFrames()) {
                if (frame.isActive()) {
                    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
                }
            }
        }
    });
    menuFile.add(menuFileExit);

    menuFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(final MenuEvent e) {
            menuFileReload.setEnabled(isSourceOpen() && currentSource.canReopen());
            menuFileClose.setEnabled(isSourceOpen());
            menuFileProperties.setEnabled(isDefinitionOpen());
            menuFileExport.setEnabled(isDefinitionOpen());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });

    return menuFile;
}

From source file:pcgen.gui2.tools.Utility.java

/**
 * Add a keyboard shortcut to allow ESC to close the dialog.
 *
 * @param dialog The dialog to be updated.
 *///from   w ww  .  ja  va 2 s. co m
public static void installEscapeCloseOperation(final JDialog dialog) {
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey);
    Action dispatchClosing = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
}