Stack (@Nullable Window window) { Stack stack = ourStacks.get(window); if (stack == null) { stack = new Stack(window); ourStacks.put(window, stack); if (window != null) { window.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { ourStacks.remove(window); } }); } } return stack; }