use of java.awt.event.WindowEvent in project drmips by brunonova.
the class Util method enableCloseWindowWithEscape.
/**
* Configures the given window to be closed when the Escape button is pressed.
* @param <W> A window (JFrame, JDialog, etc.).
* @param window Window to configure.
*/
public static <W extends Window & RootPaneContainer> void enableCloseWindowWithEscape(final W window) {
Action closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
}
};
window.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
window.getRootPane().getActionMap().put("close", closeAction);
}
use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class Font2DTest method main.
/// Main function
public static void main(String[] argv) {
if (argv.length > 0) {
if (argv[0].equalsIgnoreCase("-disablecandisplaycheck") || argv[0].equalsIgnoreCase("-dcdc")) {
canDisplayCheck = false;
} else {
printUsage();
}
}
UIManager.put("swing.boldMetal", Boolean.FALSE);
final JFrame f = new JFrame("Font2DTest");
final Font2DTest f2dt = new Font2DTest(f, false);
f.addWindowListener(new WindowAdapter() {
public void windowOpening(WindowEvent e) {
f2dt.repaint();
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.getContentPane().add(f2dt);
f.pack();
f.show();
}
use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class XDecoratedPeer method handleWmTakeFocus.
private void handleWmTakeFocus(XClientMessageEvent cl) {
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
focusLog.fine("WM_TAKE_FOCUS on {0}", this);
}
if (XWM.getWMID() == XWM.UNITY_COMPIZ_WM) {
// JDK-8159460
Window focusedWindow = XKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow();
Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow);
if (activeWindow != target) {
requestWindowFocus(cl.get_data(1), true);
} else {
WindowEvent we = new WindowEvent(focusedWindow, WindowEvent.WINDOW_GAINED_FOCUS);
sendEvent(we);
}
} else {
requestWindowFocus(cl.get_data(1), true);
}
}
use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class WChoicePeer method initialize.
@Override
@SuppressWarnings("deprecation")
void initialize() {
Choice opt = (Choice) target;
int itemCount = opt.getItemCount();
if (itemCount > 0) {
String[] items = new String[itemCount];
for (int i = 0; i < itemCount; i++) {
items[i] = opt.getItem(i);
}
addItems(items, 0);
if (opt.getSelectedIndex() >= 0) {
select(opt.getSelectedIndex());
}
}
Window parentWindow = SunToolkit.getContainingWindow((Component) target);
if (parentWindow != null) {
WWindowPeer wpeer = (WWindowPeer) parentWindow.getPeer();
if (wpeer != null) {
windowListener = new WindowAdapter() {
@Override
public void windowIconified(WindowEvent e) {
closeList();
}
@Override
public void windowClosing(WindowEvent e) {
closeList();
}
};
wpeer.addWindowListener(windowListener);
}
}
super.initialize();
}
use of java.awt.event.WindowEvent in project jdk8u_jdk by JetBrains.
the class ServiceDialog method initPageDialog.
/**
* Initialize "page setup" dialog
*/
void initPageDialog(int x, int y, PrintService ps, DocFlavor flavor, PrintRequestAttributeSet attributes) {
this.psCurrent = ps;
this.docFlavor = flavor;
this.asOriginal = attributes;
this.asCurrent = new HashPrintRequestAttributeSet(attributes);
if (attributes.get(DialogOnTop.class) != null) {
setAlwaysOnTop(true);
}
Container c = getContentPane();
c.setLayout(new BorderLayout());
pnlPageSetup = new PageSetupPanel();
c.add(pnlPageSetup, BorderLayout.CENTER);
pnlPageSetup.updateInfo();
JPanel pnlSouth = new JPanel(new FlowLayout(FlowLayout.TRAILING));
btnApprove = createExitButton("button.ok", this);
pnlSouth.add(btnApprove);
getRootPane().setDefaultButton(btnApprove);
btnCancel = createExitButton("button.cancel", this);
handleEscKey(btnCancel);
pnlSouth.add(btnCancel);
c.add(pnlSouth, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
dispose(CANCEL);
}
});
getAccessibleContext().setAccessibleDescription(getMsg("dialog.pstitle"));
setResizable(false);
setLocation(x, y);
pack();
}
Aggregations