Java Code Examples for java.awt.Window#addWindowListener()

The following examples show how to use java.awt.Window#addWindowListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputContext.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: WindowChoreographer.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: InputContext.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: InputContext.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: SwingUtils.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
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);
		}
	});
}
 
Example 6
Source File: InputContext.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: PageableTable.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 8
Source File: InputContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: Configuration.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
      //
    }
  }
}
 
Example 10
Source File: SwingComponents.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
        }
      });
}
 
Example 11
Source File: WindowToggleAction.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example 12
Source File: BufferedCanvasComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example 13
Source File: WindowTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: PluginManagerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 ());
        }
    });
}
 
Example 15
Source File: TableCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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();
            }
        });
    }
}
 
Example 16
Source File: InputContext.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 17
Source File: WindowToggleAction.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: InputContext.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 19
Source File: MainLifecycle.java    From raccoon4 with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 20
Source File: WindowStateAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
private WindowStateAdapter(@Nonnull Window window) {
  myWindowState.applyFrom(window);
  window.addComponentListener(this);
  window.addWindowListener(this);
  window.addWindowStateListener(this);
}