Author: tchemit Date: 2013-03-15 01:18:32 +0100 (Fri, 15 Mar 2013) New Revision: 2626 Url: http://nuiton.org/projects/jaxx/repository/revisions/2626 Log: fixes #2597: [ConfigUI] Make possible to use ui not in a frame Modified: trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHandler.java Modified: trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHandler.java =================================================================== --- trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHandler.java 2013-03-15 00:18:16 UTC (rev 2625) +++ trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHandler.java 2013-03-15 00:18:32 UTC (rev 2626) @@ -48,6 +48,7 @@ import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; +import java.awt.Container; import java.awt.Frame; import java.awt.Window; import java.awt.event.ActionEvent; @@ -75,6 +76,8 @@ private final ConfigUI ui; + private Container topContainer; + public ConfigUIHandler(ConfigUI ui) { this.ui = ui; } @@ -116,8 +119,8 @@ for (CategoryModel categoryModel : model) { String category = categoryModel.getCategory(); String categoryLabel = _(categoryModel.getCategoryLabel()); - ConfigCategoryUI p = new ConfigCategoryUI(new - JAXXInitialContext().add(ui).add(categoryModel)); + ConfigCategoryUI p = new ConfigCategoryUI( + new JAXXInitialContext().add(ui).add(categoryModel)); p.getCategoryLabel().setText(categoryLabel); p.setName(category); categories.addTab(_(category), null, p, categoryLabel); @@ -133,7 +136,7 @@ } public void destroy() { - if (log.isDebugEnabled() ) { + if (log.isDebugEnabled()) { log.debug("destroy ui " + ui.getName()); } JAXXUtil.destroy(ui); @@ -195,9 +198,24 @@ return; } - final Window parentWindow = ui.getParentContainer(Window.class); + Window parentWindow; + final Container parentContainer; + if (topContainer == null) { + + // no top container given, still use the parent frame + + parentWindow = ui.getParentContainer(Window.class); + parentContainer = parentWindow; + + } else { + + // use only given topContainer + parentWindow = null; + parentContainer = topContainer; + } + ConfigUIModel model = ui.getModel(); if (!model.isSaved() || model.isStandalone()) { @@ -220,25 +238,30 @@ // init callBackUI JAXXInitialContext context = new JAXXInitialContext(). - add("parent", parentWindow). add(ui). add(CALLBACKS_WITH_OPTIONS, forSaved). add(CALLBACKS, new ArrayList<CallBackEntry>(forSaved.keySet())). add(new ConfigCallBackUIHandler()); + if (topContainer == null) { + + // still add parent window (to close ui) + context.setContextValue(parentWindow, "parent"); + } + ConfigCallBackUI lastUI = new ConfigCallBackUI(context); lastUI.init(); ui.setVisible(false); - parentWindow.remove(ui); - parentWindow.add(lastUI); + parentContainer.remove(ui); + parentContainer.add(lastUI); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - parentWindow.validate(); + parentContainer.validate(); } }); } @@ -250,9 +273,12 @@ destroy(); - // close the config ui - parentWindow.dispose(); + if (parentWindow != null) { + // close the config ui + parentWindow.dispose(); + } + Runnable runnable = model.getCloseAction(); if (runnable != null) { log.info("execute close action"); @@ -356,4 +382,9 @@ return response; } + + public void setTopContainer(Container topContainer) { + this.topContainer = topContainer; + } + }