下面列出了java.awt.Window#addWindowListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private synchronized void addClientWindowListeners() {
Component client = getClientComponent();
if (client == null) {
return;
}
Window window = getComponentWindow(client);
if (window == null) {
return;
}
window.addComponentListener(this);
window.addWindowListener(this);
clientWindowListened = window;
}
private synchronized void addClientWindowListeners() {
Component client = getClientComponent();
if (client == null) {
return;
}
Window window = getComponentWindow(client);
if (window == null) {
return;
}
window.addComponentListener(this);
window.addWindowListener(this);
clientWindowListened = window;
}
/**
* Hide the window
*/
public void hideWindow() {
Window frame = lifecycleManager.getWindow(id);
if (!connected) {
frame.addWindowListener(this);
connected = true;
// Catch up, just in case someone ignored the warning and made another
// toggle for the window.
putValue(SELECTED_KEY, false);
}
frame.setVisible(false);
}
private synchronized void addClientWindowListeners() {
Component client = getClientComponent();
if (client == null) {
return;
}
Window window = getComponentWindow(client);
if (window == null) {
return;
}
window.addComponentListener(this);
window.addWindowListener(this);
clientWindowListened = window;
}
@Override
public void addNotify() {
super.addNotify();
Window window = SwingUtilities.getWindowAncestor(this);
if (window != null) {
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
updateFromUI();
}
});
}
}
@Override
public void addNotify () {
super.addNotify ();
//show progress for initialize method
final Window w = findWindowParent ();
if (w != null) {
w.addWindowListener (new WindowAdapter (){
@Override
public void windowOpened (WindowEvent e) {
final WindowAdapter waa = this;
setWaitingState (true);
Utilities.startAsWorkerThread (PluginManagerUI.this,
new Runnable () {
@Override
public void run () {
try {
initTask.waitFinished ();
w.removeWindowListener (waa);
} finally {
setWaitingState (false);
}
}
},
NbBundle.getMessage (PluginManagerUI.class, "UnitTab_InitAndCheckingForUpdates"),
Utilities.getTimeOfInitialization ());
}
});
}
HelpCtx.setHelpIDString (this, PluginManagerUI.class.getName ());
tpTabs.addChangeListener (new ChangeListener () {
@Override
public void stateChanged (ChangeEvent evt) {
HelpCtx.setHelpIDString (PluginManagerUI.this, getHelpCtx ().getHelpID ());
}
});
}
public synchronized void putTaskWindow(Window win, TaskThreadGroup grp) {
ArrayList<Window> vec;
if ((vec = windowMap.get(grp)) == null) {
vec = new ArrayList<Window>();
windowMap.put(grp, vec);
}
vec.add(win);
win.addWindowListener(winListener);
super.put(win, grp);
}
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
Window parentWindow = SwingUtilities.getWindowAncestor(BufferedCanvasComponent.this);
if (lastParentWindow != parentWindow) {
if (lastParentWindow != null) lastParentWindow.removeWindowListener(VisibilityHandler.this);
if (parentWindow != null) parentWindow.addWindowListener(VisibilityHandler.this);
lastParentWindow = parentWindow;
}
}
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
if (isShowing()) BufferedCanvasComponent.this.shown();
else BufferedCanvasComponent.this.hidden();
}
}
/**
* Toggle window visibility.
*/
public void toggleWindow() {
Window frame = lifecycleManager.getWindow(id);
if (!connected) {
frame.addWindowListener(this);
connected = true;
// Catch up, just in case someone ignored the warning and made another
// toggle for the window.
putValue(SELECTED_KEY, frame.isVisible());
}
frame.setVisible(!frame.isVisible());
}
/**
* Executes the specified action when the specified window has been closed.
*
* @param window The window to which the action is attached.
* @param action The action to execute.
*/
public static void addWindowClosedListener(final Window window, final Runnable action) {
checkNotNull(window);
checkNotNull(action);
window.addWindowListener(
new WindowAdapter() {
@Override
public void windowClosed(final WindowEvent e) {
action.run();
}
});
}
/**
* Move/Resize a window at the preferred position and size.
*
* @param window The window.
*/
public void restoreWindowPosition(Window window) {
if (window == null) {
return;
}
window.addWindowListener(this);
if (getBoolean(null, ConfigurationValueBoolean.RESTORE_WINDOW) &&
(getPreferences() != null)) {
try {
if (!getPreferences().nodeExists(PROPERTY_WINDOW)) {
return;
}
Preferences node = getPreferences().node(PROPERTY_WINDOW);
if (!node.nodeExists(window.getName())) {
return;
}
node = node.node(window.getName());
window.setLocation(
node.getInt(PROPERTY_WINDOW_X, 0),
node.getInt(PROPERTY_WINDOW_Y, 0));
boolean restoreSize = true;
if (window instanceof Versionned) {
Integer version = ((Versionned) window).getVersion();
if (version != null) {
int storedVersion = node.getInt(PROPERTY_WINDOW_VERSION, 1);
if (version.intValue() > storedVersion) {
restoreSize = false;
}
}
}
if (restoreSize) {
window.setSize(
node.getInt(PROPERTY_WINDOW_W, 1000),
node.getInt(PROPERTY_WINDOW_H, 700));
}
} catch (BackingStoreException e) {
//
}
}
}
private synchronized void addClientWindowListeners() {
Component client = getClientComponent();
if (client == null) {
return;
}
Window window = getComponentWindow(client);
if (window == null) {
return;
}
window.addComponentListener(this);
window.addWindowListener(this);
clientWindowListened = window;
}
/**
* @param toEdit model to edit
* @return model editor.
*/
public Window getEditor(Object toEdit) {
Window dlg = openDialogs.get(toEdit);
if (dlg == null) {
dlg = getEditor();
if (dlg == null)
return null;
openDialogs.put(toEdit, dlg);
((View<Object>) dlg).setModel(toEdit);
((View<Object>) dlg).refresh();
dlg.addWindowListener(new DialogWindowListener());
if (dlg instanceof Editor) {
Editor<T> editor = (Editor<T>) dlg;
editor.addEditorListener(new EditorListener() {
public void modelChanged(EditorEvent e) {
refresh();
}
});
}
}
((View<T>) dlg).refresh();
return dlg;
}
private synchronized void addClientWindowListeners() {
Component client = getClientComponent();
if (client == null) {
return;
}
Window window = getComponentWindow(client);
if (window == null) {
return;
}
window.addComponentListener(this);
window.addWindowListener(this);
clientWindowListened = window;
}
public static void packLater(final Window win, final Component parent) {
win.pack();
win.setLocationRelativeTo(parent);
win.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
win.pack();
win.setLocationRelativeTo(parent);
}
});
}
private synchronized void addClientWindowListeners() {
Component client = getClientComponent();
if (client == null) {
return;
}
Window window = getComponentWindow(client);
if (window == null) {
return;
}
window.addComponentListener(this);
window.addWindowListener(this);
clientWindowListened = window;
}
private synchronized void addClientWindowListeners() {
Component client = getClientComponent();
if (client == null) {
return;
}
Window window = getComponentWindow(client);
if (window == null) {
return;
}
window.addComponentListener(this);
window.addWindowListener(this);
clientWindowListened = window;
}
/**
* Adds a Window into the next free position
*
* @param window
* The window
* @return true if the Window could be displayed immediately
*/
public synchronized boolean addWindow(Window window) {
if (window == null) {
throw new IllegalArgumentException("window must not be null!");
}
// Don't trigger in iconified mode
if (RapidMinerGUI.getMainFrame().getExtendedState() == Frame.ICONIFIED) {
bubbleStack.add(window);
return false;
}
int pos = getNextPosition(window);
int yOffset = windowYOffset.get(pos - 1);
if (!fitsScreen(window, yOffset)) {
// Lets store the bubble for later
bubbleStack.add(window);
return false;
}
// Allow a window only one time
if (windowPosition.containsKey(window)) {
return false;
}
// Remember the position of the window
windowPosition.put(window, pos);
// Great job Java there are two remove methods
freeSpaces.remove(pos);
// Remember size if it's a new window
if (pos >= windowYOffset.size()) {
this.windowYOffset.set(pos, yOffset + window.getHeight() + DEFAULT_BOTTOM_MARGIN);
}
window.addWindowListener(closeListener);
window.setVisible(true);
recalculateWindowPosition(window, pos);
return true;
}
@Override
public Window onCreatePrimaryWindow(Globals globals) {
WindowTogglers wt = globals.get(WindowTogglers.class);
PushUrlAction pua = new PushUrlAction(globals);
ScreenshotAction ssa = new ScreenshotAction(globals);
UpdateAppAction uaa = new UpdateAppAction(globals);
PlayProfileDao dao = globals.get(DatabaseManager.class).get(
PlayProfileDao.class);
dao.subscribe(new DatasetListenerProxy(uaa));
dao.subscribe(new DatasetListenerProxy(wt));
BridgeManager bridgeManager = globals.get(BridgeManager.class);
bridgeManager.addBridgeListener(ssa);
bridgeManager.addBridgeListener(pua);
ProfilesMenuBuilder pmb = new ProfilesMenuBuilder();
Traits traits = globals.get(Traits.class);
wt.grants.setEnabled(!traits.isMaxed() || traits.isTrial());
MenuBarBuilder mbb = new MenuBarBuilder()
.withLocalizer(Messages.getLocalizer())
.withMenus("filemenu", "marketmenu", "devicemenu", "viewmenu",
"helpmenu")
.addItem("filemenu/share", wt.share)
.addItem("filemenu/importapps", new ImportAppAction(globals))
.addSeparator("filemenu/---1")
.addItem("filemenu/quit", new QuitAction(globals))
.add("marketmenu/profiles", pmb.assemble(globals))
.addItem("marketmenu/update", uaa)
.addSeparator("marketmenu/---1")
.addCheckbox("marketmenu/manualdownload", wt.manualdownload)
.addCheckbox("marketmenu/importurls", wt.marketimport)
.addItem("devicemenu/pushurl", pua)
.addItem("devicemenu/screenshot", ssa)
.addCheckbox("viewmenu/myapps", wt.myApps)
.addCheckbox("viewmenu/qrtool", wt.qrtool)
.addCheckbox("viewmenu/transfers", wt.transfers)
.addItem("helpmenu/handbook", new BrowseAction(Bookmarks.HANDBOOK))
.addItem("helpmenu/support", new BrowseAction(Bookmarks.SUPPORT))
.addItem("helpmenu/featurelist",
new BrowseAction(Bookmarks.FEATURELIST))
.addSeparator("helpmenu/---1")
.addCheckbox("helpmenu/grants", wt.grants);
Window ret = new WindowBuilder(
new PlayStoreViewBuilder().withBorder(new EmptyBorder(10, 10, 10, 10)))
.withTitle(Messages.getString("MainLifecycle.title")).withMenu(mbb)
.withSize(1200, 768).withIcons("/icons/appicon.png").build(globals);
ret.addWindowListener(new PostWindowSetup(globals));
return ret;
}
private WindowStateAdapter(@Nonnull Window window) {
myWindowState.applyFrom(window);
window.addComponentListener(this);
window.addWindowListener(this);
window.addWindowStateListener(this);
}