Search in sources :

Example 41 with WindowEvent

use of java.awt.event.WindowEvent in project jmonkeyengine by jMonkeyEngine.

the class TestAwtPanels method createWindowForPanel.

private static void createWindowForPanel(AwtPanel panel, int location) {
    JFrame frame = new JFrame("Render Display " + location);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(panel, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            if (++panelsClosed == 2) {
                app.stop();
            }
        }
    });
    frame.pack();
    frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
    frame.setVisible(true);
}
Also used : BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 42 with WindowEvent

use of java.awt.event.WindowEvent in project lwjgl by LWJGL.

the class DemoBox method initialize.

/**
	 * @return
	 */
public boolean initialize() {
    setTitle("LWJGL - Demo Box");
    setSize(640, 480);
    setLayout(new GridBagLayout());
    // Setup selection panel
    // =================================
    selectionPanel = new Panel();
    selectionPanel.setLayout(new BorderLayout());
    selectionPanel.add(new Label("Demo", Label.CENTER), BorderLayout.NORTH);
    Button fullScreen = new Button("Fullscreen");
    fullScreen.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            toggleFullscreen();
        }
    });
    selectionPanel.add(fullScreen, BorderLayout.SOUTH);
    final List demos = new List();
    for (Enumeration e = selectableDemos.keys(); e.hasMoreElements(); ) {
        demos.add(e.nextElement().toString());
    }
    selectionPanel.add(demos, BorderLayout.CENTER);
    demos.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent event) {
            demoSelected(event.getItemSelectable().getSelectedObjects()[0].toString());
        }
    });
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.weightx = 0.05;
    gbc.weighty = 1.0;
    add(selectionPanel, gbc);
    // =================================
    try {
        demoCanvas = new DemoBoxGLCanvas(this);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.weightx = 0.95;
        gbc.weighty = 1.0;
        add(demoCanvas, gbc);
    } catch (LWJGLException le) {
        le.printStackTrace();
        return false;
    }
    // ---------------------------------
    addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent e) {
            demoCanvas.destroyCanvas();
            dispose();
            System.exit(0);
        }
    });
    //demoSelected(demos.getSelectedItem());
    return true;
}
Also used : ItemEvent(java.awt.event.ItemEvent) GridBagConstraints(java.awt.GridBagConstraints) Enumeration(java.util.Enumeration) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) Label(java.awt.Label) WindowAdapter(java.awt.event.WindowAdapter) Panel(java.awt.Panel) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) Button(java.awt.Button) WindowEvent(java.awt.event.WindowEvent) List(java.awt.List) ItemListener(java.awt.event.ItemListener) LWJGLException(org.lwjgl.LWJGLException)

Example 43 with WindowEvent

use of java.awt.event.WindowEvent in project intellij-community by JetBrains.

the class IdeFrameImpl method setupCloseAction.

private void setupCloseAction() {
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        public void windowClosing(@NotNull final WindowEvent e) {
            if (isTemporaryDisposed())
                return;
            final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            if (openProjects.length > 1 || openProjects.length == 1 && SystemInfo.isMacSystemMenu) {
                if (myProject != null && myProject.isOpen()) {
                    ProjectUtil.closeAndDispose(myProject);
                }
                ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed();
                WelcomeFrame.showIfNoProjectOpened();
            } else {
                ApplicationManagerEx.getApplicationEx().exit();
            }
        }
    });
}
Also used : WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Example 44 with WindowEvent

use of java.awt.event.WindowEvent in project intellij-community by JetBrains.

the class IdePopupManager method dispatch.

public boolean dispatch(@NotNull final AWTEvent e) {
    LOG.assertTrue(isPopupActive());
    if (e.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
        ApplicationManager.getApplication().invokeLater(() -> {
            if (!isPopupActive())
                return;
            boolean shouldCloseAllPopup = false;
            Window focused = ((WindowEvent) e).getOppositeWindow();
            if (focused == null) {
                focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
            }
            if (focused == null) {
                shouldCloseAllPopup = true;
            }
            Component ultimateParentForFocusedComponent = UIUtil.findUltimateParent(focused);
            Window sourceWindow = ((WindowEvent) e).getWindow();
            Component ultimateParentForEventWindow = UIUtil.findUltimateParent(sourceWindow);
            if (!shouldCloseAllPopup && ultimateParentForEventWindow == null || ultimateParentForFocusedComponent == null) {
                shouldCloseAllPopup = true;
            }
            if (!shouldCloseAllPopup && ultimateParentForEventWindow instanceof IdeFrameEx) {
                IdeFrameEx ultimateParentWindowForEvent = ((IdeFrameEx) ultimateParentForEventWindow);
                if (ultimateParentWindowForEvent.isInFullScreen() && !ultimateParentForFocusedComponent.equals(ultimateParentForEventWindow)) {
                    shouldCloseAllPopup = true;
                }
            }
            if (!shouldCloseAllPopup && isPopupWindow(sourceWindow) && sourceWindow.getParent() == ((WindowEvent) e).getOppositeWindow()) {
                shouldCloseAllPopup = true;
            }
            if (shouldCloseAllPopup) {
                closeAllPopups();
            }
        });
    }
    if (e instanceof KeyEvent || e instanceof MouseEvent) {
        for (int i = myDispatchStack.size() - 1; (i >= 0 && i < myDispatchStack.size()); i--) {
            final boolean dispatched = myDispatchStack.get(i).dispatch(e);
            if (dispatched)
                return true;
        }
    }
    return false;
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) WindowEvent(java.awt.event.WindowEvent) IdeFrameEx(com.intellij.openapi.wm.ex.IdeFrameEx)

Example 45 with WindowEvent

use of java.awt.event.WindowEvent in project aima-java by aimacode.

the class MonteCarloLocalizationApp method constructBasicApplicationFrame.

/**
	 * Creates the {@code JFrame} for the application. A window listener is registered. 
	 * @return the main frame of the application.
	 */
public JFrame constructBasicApplicationFrame() {
    JFrame frame = app.constructApplicationFrame();
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            robotGui.saveSettings(settingsGui);
            if (settingsFile != null)
                settingsGui.saveSettings(settingsFile);
            robotGui.destructRobot();
        }
    });
    return frame;
}
Also used : JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter)

Aggregations

WindowEvent (java.awt.event.WindowEvent)201 WindowAdapter (java.awt.event.WindowAdapter)140 JPanel (javax.swing.JPanel)44 JButton (javax.swing.JButton)40 JFrame (javax.swing.JFrame)40 BorderLayout (java.awt.BorderLayout)36 ActionEvent (java.awt.event.ActionEvent)34 Dimension (java.awt.Dimension)32 JLabel (javax.swing.JLabel)30 JScrollPane (javax.swing.JScrollPane)26 ActionListener (java.awt.event.ActionListener)25 GridBagConstraints (java.awt.GridBagConstraints)19 GridBagLayout (java.awt.GridBagLayout)19 FlowLayout (java.awt.FlowLayout)18 Frame (java.awt.Frame)15 Insets (java.awt.Insets)15 JDialog (javax.swing.JDialog)13 JTextArea (javax.swing.JTextArea)13 Container (java.awt.Container)12 WindowListener (java.awt.event.WindowListener)10