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