下面列出了java.awt.event.MouseAdapter#java.awt.event.WindowEvent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setupUI() {
frame = new JFrame("Gradle");
JPanel mainPanel = new JPanel(new BorderLayout());
frame.getContentPane().add(mainPanel);
mainPanel.add(singlePaneUIInstance.getComponent());
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
singlePaneUIInstance.aboutToShow();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
close();
}
});
frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
frame.setLocationByPlatform(true);
}
/**
* Show font selection dialog.
*
* @param parent Dialog's Parent component.
* @return OK_OPTION, CANCEL_OPTION or ERROR_OPTION
*
* @see #OK_OPTION
* @see #CANCEL_OPTION
* @see #ERROR_OPTION
**/
public int showDialog(Component parent) {
dialogResultValue = ERROR_OPTION;
JDialog dialog = createDialog(parent);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
dialogResultValue = CANCEL_OPTION;
}
});
dialog.setVisible(true);
dialog.dispose();
dialog = null;
return dialogResultValue;
}
/**
* Processes window events occurring on this component.
* Hides the window or disposes of it, as specified by the setting
* of the <code>defaultCloseOperation</code> property.
*
* @param e the window event
* @see #setDefaultCloseOperation
* @see java.awt.Window#processWindowEvent
*/
protected void processWindowEvent(final WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
switch (defaultCloseOperation) {
case HIDE_ON_CLOSE:
setVisible(false);
break;
case DISPOSE_ON_CLOSE:
dispose();
break;
case EXIT_ON_CLOSE:
// This needs to match the checkExit call in
// setDefaultCloseOperation
System.exit(0);
break;
case DO_NOTHING_ON_CLOSE:
default:
}
}
}
private static boolean trackEvent(int eventID, Component comp, Runnable action, int time, boolean printEvent) {
EventListener listener = null;
switch (eventID) {
case WindowEvent.WINDOW_GAINED_FOCUS:
listener = wgfListener;
break;
case FocusEvent.FOCUS_GAINED:
listener = fgListener;
break;
case ActionEvent.ACTION_PERFORMED:
listener = apListener;
break;
}
listener.listen(comp, printEvent);
action.run();
return Util.waitForCondition(listener.getNotifier(), time);
}
/**
* Show measurment form
*/
public void showMeasurementForm() {
if (_frmMeasure == null) {
_frmMeasure = new FrmMeasurement((JFrame) SwingUtilities.getWindowAncestor(this), false);
_frmMeasure.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
_currentLayoutMap.getMapFrame().getMapView().setDrawIdentiferShape(false);
//repaint();
repaintOld();
}
});
_frmMeasure.setLocationRelativeTo(this);
_frmMeasure.setVisible(true);
} else if (!_frmMeasure.isVisible()) {
_frmMeasure.setVisible(true);
}
}
@CalledOnlyBy(AmidstThread.EDT)
private JFrame createFrame() {
JFrame frame = new JFrame("Profile Selector");
frame.setIconImages(metadata.getIcons());
frame.getContentPane().setLayout(new MigLayout());
frame.add(createTitleLabel(), "h 20!,w :400:, growx, pushx, wrap");
frame.add(createScrollPanel(), getScrollPaneLayoutString());
frame.pack();
frame.addKeyListener(profileSelectPanel.createKeyListener());
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
application.exitGracefully();
}
});
frame.setLocation(200, 200);
frame.setVisible(true);
return frame;
}
/**
* Creates a new instance
*
* @param parent the parent frame
* @param circuitComponent the component used to select the inputs and outputs
*/
public NumberingWizard(JFrame parent, CircuitComponent circuitComponent) {
super(parent, Lang.get("msg_numberingWizard"), false);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.circuitComponent = circuitComponent;
label = new JLabel();
label.setFont(Screen.getInstance().getFont(1.5f));
int b = Screen.getInstance().getFontSize();
label.setBorder(BorderFactory.createEmptyBorder(b, b, b, b));
setPinNumber(999);
getContentPane().add(label);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent windowEvent) {
circuitComponent.deactivateWizard();
}
});
pack();
pinNumber = 1;
setPinNumber(pinNumber);
setLocation(parent.getLocation());
}
@Override public void actionPerformed(ActionEvent e) {
Component root;
Container parent = SwingUtilities.getUnwrappedParent((Component) e.getSource());
if (parent instanceof JPopupMenu) {
JPopupMenu popup = (JPopupMenu) parent;
root = SwingUtilities.getRoot(popup.getInvoker());
} else if (parent instanceof JToolBar) {
JToolBar toolbar = (JToolBar) parent;
if (((BasicToolBarUI) toolbar.getUI()).isFloating()) {
root = SwingUtilities.getWindowAncestor(toolbar).getOwner();
} else {
root = SwingUtilities.getRoot(toolbar);
}
} else {
root = SwingUtilities.getRoot(parent);
}
if (root instanceof Window) {
Window window = (Window) root;
window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
}
}
private void setupCloseAction() {
myJFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
myJFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(@Nonnull final WindowEvent e) {
if (isTemporaryDisposed()) return;
final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
if (openProjects.length > 1 || openProjects.length == 1 && TopApplicationMenuUtil.isMacSystemMenu) {
if (myProject != null && myProject.isOpen()) {
ProjectUtil.closeAndDispose(myProject);
}
ApplicationManager.getApplication().getMessageBus().syncPublisher(AppLifecycleListener.TOPIC).projectFrameClosed();
WelcomeFrame.showIfNoProjectOpened();
}
else {
Application.get().exit();
}
}
});
}
private void loadComparisonPNG( String fileName ) {
try {
BufferedImage image =
javax.imageio.ImageIO.read(new File(fileName));
JFrame f = new JFrame( "Comparison PNG" );
ImagePanel ip = new ImagePanel( image );
f.setResizable( false );
f.getContentPane().add( ip );
f.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
( (JFrame) e.getSource() ).dispose();
}
});
f.pack();
f.show();
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Load PNG File; See Stack Trace", true );
ex.printStackTrace();
}
}
@Override
public void run() {
JFrame jframe = new JFrame(windowLabel == null
? getResourceString("editpad.name")
: windowLabel);
Runnable closer = () -> {
jframe.setVisible(false);
jframe.dispose();
closeMark.run();
};
jframe.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closer.run();
}
});
jframe.setLocationRelativeTo(null);
jframe.setLayout(new BorderLayout());
JTextArea textArea = new JTextArea(initialText);
textArea.setFont(new Font("monospaced", Font.PLAIN, 13));
jframe.add(new JScrollPane(textArea), BorderLayout.CENTER);
jframe.add(buttons(closer, textArea), BorderLayout.SOUTH);
jframe.setSize(800, 600);
jframe.setVisible(true);
}
private void stop() {
JFrame jf = MainWindowManager.mainWindowManager().getMainWindow();
WindowEvent wev = new WindowEvent(jf, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
writeAck("Shutting down");
}
private void initGUI(Point location) {
this.setLocation(location);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TargetFileListFrame.this.dispose();
}
});
this.add(new Panel().add(list));
this.pack();
this.setVisible(true);
}
public void windowOpened(WindowEvent e) {
shown = true;
synchronized(this) {
//System.err.println("window opened");
notifyAll();
((JFrame) e.getSource()).removeWindowListener(this);
}
}
/**
* Sets up the related {@link SettingsTabs} and buttons for the Studio settings. This uses {@link #getDefaultStudioHandler()}
* and {@link SettingsItems#INSTANCE} for initialization.
*
* Selects the specified selected tab.
*
* @param initialSelectedTab
* A key of a preferences group to identify the initial selected tab.
*/
public SettingsDialog(String initialSelectedTab) {
this(getDefaultStudioHandler(), SettingsItems.INSTANCE, initialSelectedTab);
// add listener to remove parameter handler when dialog is closed
addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
parameterHandler.getParameters().getParameterTypes().stream()
.flatMap(pt -> pt.getConditions().stream()).forEach(pc -> pc.setParameterHandler(null));
}
});
}
public void init() {
robot = Util.createRobot();
kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent event) {
System.out.println("--> " + event);
}
}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
}
@Override
public boolean filterEvent(Window window, int eventId) {
switch (eventId) {
case WindowEvent.WINDOW_OPENED:
return true;
default:
return false;
}
}
private void initGUI(Point location) {
this.setLocation(location);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
TargetFileListFrame.this.dispose();
}
});
this.add(new Panel().add(list));
this.pack();
this.setVisible(true);
}
/**
* Viewer has been closed so allow it to be garbage collected.
*/
// public void internalFrameClosed(InternalFrameEvent evt)
public void windowClosed(WindowEvent evt)
{
// removeViewer((HtmlViewerSheet)evt.getInternalFrame());
removeViewer((HtmlViewerSheet)evt.getWindow());
// super.internalFrameClosed(evt);
}
@Override
public boolean filterEvent(Window window, int eventId) {
switch (eventId) {
case WindowEvent.WINDOW_OPENED:
return true;
default:
return false;
}
}
public void windowClosing(WindowEvent we) {
done = true;
Window w = (Window)we.getSource();
if (setNullOnDispose) {
w.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
}
w.dispose();
}
public void windowClosing( WindowEvent e ) {
//Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
//may not be called
Dialog dialog = (Dialog)project2Dialog.get( project );
if ( dialog != null ) {
dialog.setVisible(false);
dialog.dispose();
}
}
public void init() {
robot = Util.createRobot();
kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent event) {
System.out.println("--> " + event);
}
}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
}
public static void postEvent(AppContext appContext, AWTEvent event) {
if (event == null) {
throw new NullPointerException();
}
AWTAccessor.SequencedEventAccessor sea = AWTAccessor.getSequencedEventAccessor();
if (sea != null && sea.isSequencedEvent(event)) {
AWTEvent nested = sea.getNested(event);
if (nested.getID() == WindowEvent.WINDOW_LOST_FOCUS &&
nested instanceof TimedWindowEvent)
{
TimedWindowEvent twe = (TimedWindowEvent)nested;
((SunToolkit)Toolkit.getDefaultToolkit()).
setWindowDeactivationTime((Window)twe.getSource(), twe.getWhen());
}
}
// All events posted via this method are system-generated.
// Placing the following call here reduces considerably the
// number of places throughout the toolkit that would
// otherwise have to be modified to precisely identify
// system-generated events.
setSystemGenerated(event);
AppContext eventContext = targetToAppContext(event.getSource());
if (eventContext != null && !eventContext.equals(appContext)) {
throw new RuntimeException("Event posted on wrong app context : " + event);
}
PostEventQueue postEventQueue =
(PostEventQueue)appContext.get(POST_EVENT_QUEUE_KEY);
if (postEventQueue != null) {
postEventQueue.postEvent(event);
}
}
private void thisWindowClosing(WindowEvent e) {
countdownSystemStop();
stopCountdown();
Lizzie.board.unregisterBoardStateChangeObserver(boardStateChangeObserver);
OptionSetting.ByoYomiSetting byoYomiSetting = Lizzie.optionSetting.getByoYomiSetting();
byoYomiSetting.setByoYomiTime((Integer) spinnerCountdownTime.getValue());
byoYomiSetting.setStopThinkingWhenCountingDown(checkBoxStopThinkingWhenCountDown.isSelected());
}
private final Runnable makeGUI() {
return new Runnable() { public void run() {
JScrollPane jsp = new JScrollPane(table);
jsp.setPreferredSize(new Dimension(500, 500));
table.addMouseListener(listener);
JLabel label = new JLabel("Double-click any to repair file path:");
JLabel label2 = new JLabel("(Any listed with identical parent folder will be fixed as well.)");
JPanel plabel = new JPanel();
BoxLayout pbl = new BoxLayout(plabel, BoxLayout.Y_AXIS);
plabel.setLayout(pbl);
//plabel.setBorder(new LineBorder(Color.black, 1, true));
plabel.setMinimumSize(new Dimension(400, 40));
plabel.add(label);
plabel.add(label2);
JPanel all = new JPanel();
BoxLayout bl = new BoxLayout(all, BoxLayout.Y_AXIS);
all.setLayout(bl);
all.add(plabel);
all.add(jsp);
frame.getContentPane().add(all);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
synchronized (projects) {
if (data.vpath.size() > 0 ) {
Utils.logAll("WARNING: Some images remain associated to inexistent file paths.");
}
projects.remove(project);
}
}
});
frame.pack();
ij.gui.GUI.center(frame);
frame.setVisible(true);
}};
}
@Override
public void windowClosing (WindowEvent e) {
//Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
//may not be called
Dialog dialog = project2Dialog.get( project );
if ( dialog != null ) {
dialog.setVisible(false);
dialog.dispose();
}
}
/**
* {@inheritDoc}
*/
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public void windowClosed(WindowEvent e) {
}
/**
* Recycles the passed in <code>HeavyWeightPopup</code>.
*/
private static void recycleHeavyWeightPopup(HeavyWeightPopup popup) {
synchronized (HeavyWeightPopup.class) {
List<HeavyWeightPopup> cache;
Window window = SwingUtilities.getWindowAncestor(
popup.getComponent());
Map<Window, List<HeavyWeightPopup>> heavyPopupCache = getHeavyWeightPopupCache();
if (window instanceof Popup.DefaultFrame ||
!window.isVisible()) {
// If the Window isn't visible, we don't cache it as we
// likely won't ever get a windowClosed event to clean up.
// We also don't cache DefaultFrames as this indicates
// there wasn't a valid Window parent, and thus we don't
// know when to clean up.
popup._dispose();
return;
} else if (heavyPopupCache.containsKey(window)) {
cache = heavyPopupCache.get(window);
} else {
cache = new ArrayList<HeavyWeightPopup>();
heavyPopupCache.put(window, cache);
// Clean up if the Window is closed
final Window w = window;
w.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
List<HeavyWeightPopup> popups;
synchronized(HeavyWeightPopup.class) {
Map<Window, List<HeavyWeightPopup>> heavyPopupCache2 =
getHeavyWeightPopupCache();
popups = heavyPopupCache2.remove(w);
}
if (popups != null) {
for (int counter = popups.size() - 1;
counter >= 0; counter--) {
popups.get(counter)._dispose();
}
}
}
});
}
if(cache.size() < MAX_CACHE_SIZE) {
cache.add(popup);
} else {
popup._dispose();
}
}
}