}
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
Component component = dialog.getContentPane().getComponent(0);
ContentUI content = (ContentUI) contentManager.getContent(component);
content.fireSelected(false);
content.setDetached(false);
}
});
dialog.addWindowFocusListener(new WindowFocusListener() {
public void windowGainedFocus(WindowEvent e) {
ContentUI content = (ContentUI) contentManager.getContent(dialog.getContentPane().getComponent(0));
content.fireSelected(true);
}
public void windowLostFocus(WindowEvent e) {
if (dialog.getContentPane().getComponentCount() > 0) {
ContentUI content = (ContentUI) contentManager.getContent(dialog.getContentPane().getComponent(0));
content.fireSelected(false);
}
}
});
if (parentFrame == null) {
WindowFocusListener windowFocusListener = new WindowFocusListener() {
long start;
long end;
public void windowGainedFocus(WindowEvent e) {
start = System.currentTimeMillis();
}
public void windowLostFocus(WindowEvent e) {
end = System.currentTimeMillis();
long elapsed = end - start;
//System.out.println(elapsed);
if (elapsed < 100)
dialog.toFront();
dialog.removeWindowFocusListener(this);
}
};
dialog.addWindowFocusListener(windowFocusListener);
}
dialog.toFront();
dialog.setVisible(true);
SwingUtil.requestFocus(dialog);
} else if (oldValue && !newValue) {
Window window = SwingUtilities.windowForComponent(content.getComponent());
window.setVisible(false);
window.dispose();
addUIForContent(content);
tabbedContentManager.setSelectedIndex(tabbedContentManager.getTabCount() - 1);