r1844 - in trunk/jaxx-widgets/src/main: java/jaxx/runtime/swing/editor/config java/jaxx/runtime/swing/editor/config/model resources/i18n
Author: tchemit Date: 2010-04-14 20:38:22 +0200 (Wed, 14 Apr 2010) New Revision: 1844 Log: improve ConfigUI Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.css trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.css =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.css 2010-04-14 17:40:00 UTC (rev 1843) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.css 2010-04-14 18:38:22 UTC (rev 1844) @@ -32,7 +32,7 @@ } #descriptionPane { - columnHeaderView:{new JLabel(_("config.descrition"), SwingUtil.getUIManagerActionIcon("information"), 10)}; + columnHeaderView:{new JLabel(_("config.description"), SwingUtil.getUIManagerActionIcon("information"), 10)}; } #description { Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java 2010-04-14 17:40:00 UTC (rev 1843) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java 2010-04-14 18:38:22 UTC (rev 1844) @@ -141,38 +141,39 @@ } public void displayUI(Frame parentUI, boolean undecorated) { - final JDialog f = new JDialog(parentUI, true); - f.setTitle(_("config.title")); - f.add(ui); - if (parentUI != null) { - f.setIconImage(parentUI.getIconImage()); - } - // pour savoir si l'ui est autonome - ui.getModel().setStandalone(ui == null); - - f.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - f.addWindowListener(new WindowAdapter() { - - @Override - public void windowClosing(WindowEvent e) { - ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); - ui.getQuit().getAction().actionPerformed(myEvent); - } - }); - f.setUndecorated(undecorated); - JRootPane rootPane = f.getRootPane(); - rootPane.setDefaultButton(ui.getQuit()); - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke("ESCAPE"), "quit"); - rootPane.getActionMap().put("quit", ui.getQuit().getAction()); - f.pack(); - SwingUtil.center(ui, f); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - - f.setVisible(true); - } - }); + ui.getHandler().displayUI(parentUI,undecorated); +// final JDialog f = new JDialog(parentUI, true); +// f.setTitle(_("config.title")); +// f.add(ui); +// if (parentUI != null) { +// f.setIconImage(parentUI.getIconImage()); +// } +// // pour savoir si l'ui est autonome +// ui.getModel().setStandalone(ui == null); +// +// f.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); +// f.addWindowListener(new WindowAdapter() { +// +// @Override +// public void windowClosing(WindowEvent e) { +// ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); +// ui.getQuit().getAction().actionPerformed(myEvent); +// } +// }); +// f.setUndecorated(undecorated); +// JRootPane rootPane = f.getRootPane(); +// rootPane.setDefaultButton(ui.getQuit()); +// rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( +// KeyStroke.getKeyStroke("ESCAPE"), "quit"); +// rootPane.getActionMap().put("quit", ui.getQuit().getAction()); +// f.pack(); +// SwingUtil.center(ui, f); +// SwingUtilities.invokeLater(new Runnable() { +// @Override +// public void run() { +// +// f.setVisible(true); +// } +// }); } } Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-04-14 17:40:00 UTC (rev 1843) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-04-14 18:38:22 UTC (rev 1844) @@ -29,20 +29,10 @@ package jaxx.runtime.swing.editor.config; import jaxx.runtime.JAXXContext; -import jaxx.runtime.SwingUtil; import jaxx.runtime.context.JAXXInitialContext; -import jaxx.runtime.swing.editor.config.model.CategoryModel; import jaxx.runtime.swing.editor.config.model.ConfigUIModel; -import jaxx.runtime.swing.editor.config.model.OptionModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import static org.nuiton.i18n.I18n._; -import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; /** * La classe pour construire l'ui @@ -53,10 +43,10 @@ @Deprecated public class ConfigUIBuilder { - public static final Log log = LogFactory.getLog(ConfigUIBuilder.class); - public static final String CALLBACKS_WITH_OPTIONS = "callbacksWithOptions"; - public static final String CALLBACKS = "callbacks"; + private static final String CALLBACKS_WITH_OPTIONS = "callbacksWithOptions"; + private static final String CALLBACKS = "callbacks"; + /** * Construire l'ui de configuration (sous forme de panel) * @@ -66,14 +56,14 @@ * @return l'ui instanciate */ public static ConfigUI newConfigUI(JAXXContext parentContext, - final ConfigUIModel model, + ConfigUIModel model, String defaultCategory) { JAXXContext tx = new JAXXInitialContext().add(parentContext).add(model); - final ConfigUI ui = new ConfigUI(tx); + ConfigUI ui = new ConfigUI(tx); ui.init(defaultCategory); - + return ui; // JButton quitButton = ui.getQuit(); // // // prepare quit action @@ -163,7 +153,7 @@ // + categoryIndex); // } // ui.getCategories().setSelectedIndex(categoryIndex); - return ui; +// return ui; } /** @@ -175,115 +165,119 @@ * @param undecorated un drapeau pour savoir si on affiche les decorations * de fenetre */ - public static void showConfigUI(final ConfigUI configUI, + public static void showConfigUI(ConfigUI configUI, Frame ui, boolean undecorated) { - JDialog f = new JDialog(ui, true); - f.setTitle(_("config.title")); - f.add(configUI); - if (ui != null) { - f.setIconImage(ui.getIconImage()); - } - // pour savoir si l'ui est autonome - configUI.getModel().setStandalone(ui == null); - - f.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); - f.addWindowListener(new WindowAdapter() { - - @Override - public void windowClosing(WindowEvent e) { - ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); - configUI.getQuit().getAction().actionPerformed(myEvent); - } - }); - f.setUndecorated(undecorated); - JRootPane rootPane = f.getRootPane(); - rootPane.setDefaultButton(configUI.getQuit()); - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke("ESCAPE"), "quit"); - rootPane.getActionMap().put("quit", configUI.getQuit().getAction()); - f.pack(); - SwingUtil.center(ui, f); - f.setVisible(true); + configUI.getHandler().displayUI(ui,undecorated); +// JDialog f = new JDialog(ui, true); +// f.setTitle(_("config.title")); +// f.add(configUI); +// if (ui != null) { +// f.setIconImage(ui.getIconImage()); +// } +// // pour savoir si l'ui est autonome +// configUI.getModel().setStandalone(ui == null); +// +// f.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); +// f.addWindowListener(new WindowAdapter() { +// +// @Override +// public void windowClosing(WindowEvent e) { +// ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); +// configUI.getQuit().getAction().actionPerformed(myEvent); +// } +// }); +// f.setUndecorated(undecorated); +// JRootPane rootPane = f.getRootPane(); +// rootPane.setDefaultButton(configUI.getQuit()); +// rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( +// KeyStroke.getKeyStroke("ESCAPE"), "quit"); +// rootPane.getActionMap().put("quit", configUI.getQuit().getAction()); +// f.pack(); +// SwingUtil.center(ui, f); +// f.setVisible(true); } protected static boolean canQuitCategory(ConfigUI ui) { - boolean canContinue = true; - ConfigUIModel model = ui.getModel(); - CategoryModel categoryModel = model.getCategoryModel(); - String categoryName = _(categoryModel.getCategory()); - if (!categoryModel.isValid()) { - // the category is not valid - // get all the invalid options - - StringBuilder buffer = new StringBuilder(); - buffer.append(_("config.message.quit.invalid.category", - categoryName)); - buffer.append('\n'); - for (OptionModel m : categoryModel.getInvalidOptions()) { - buffer.append("\n- ").append(m.getKey()); - } - buffer.append('\n'); - int reponse = askUser(ui, - _("config.title.need.confirm"), - buffer.toString(), - JOptionPane.ERROR_MESSAGE, - new Object[]{ - _("config.choice.continue"), - _("config.choice.cancel")}, - 0); - - switch (reponse) { - case JOptionPane.CLOSED_OPTION: - case 1: - canContinue = false; - break; - case 0: - if (categoryModel.isModified()) { - // wil reset category - model.reset(); - } - break; - } - } else if (categoryModel.isModified()) { - - // category was modified, ask user if wants to save - - StringBuilder buffer = new StringBuilder(); - buffer.append(_("config.message.quit.valid.and.modified.category", - categoryName)).append('\n'); - for (OptionModel m : categoryModel.getModifiedOptions()) { - buffer.append("\n- ").append(m.getKey()); - } - buffer.append('\n'); - - int reponse = askUser(ui, - _("config.title.need.confirm"), buffer.toString(), - JOptionPane.WARNING_MESSAGE, - new Object[]{ - _("config.choice.save"), - _("config.choice.doNotSave"), - _("config.choice.cancel")}, - 0); - - switch (reponse) { - case JOptionPane.CLOSED_OPTION: - case 2: - canContinue = false; - break; - case 0: - // will save ui - model.saveModified(); - break; - case 1: - // wil reset ui - model.reset(); - break; - } - - } + boolean canContinue = ui.getHandler().canQuitCategory(); return canContinue; +// boolean canContinue = true; +// ConfigUIModel model = ui.getModel(); +// CategoryModel categoryModel = model.getCategoryModel(); +// String categoryName = _(categoryModel.getCategory()); +// if (!categoryModel.isValid()) { +// +// // the category is not valid +// // get all the invalid options +// +// StringBuilder buffer = new StringBuilder(); +// buffer.append(_("config.message.quit.invalid.category", +// categoryName)); +// buffer.append('\n'); +// for (OptionModel m : categoryModel.getInvalidOptions()) { +// buffer.append("\n- ").append(m.getKey()); +// } +// buffer.append('\n'); +// int reponse = askUser(ui, +// _("config.title.need.confirm"), +// buffer.toString(), +// JOptionPane.ERROR_MESSAGE, +// new Object[]{ +// _("config.choice.continue"), +// _("config.choice.cancel")}, +// 0); +// +// switch (reponse) { +// case JOptionPane.CLOSED_OPTION: +// case 1: +// canContinue = false; +// break; +// case 0: +// if (categoryModel.isModified()) { +// // wil reset category +// model.reset(); +// } +// break; +// } +// } else if (categoryModel.isModified()) { +// +// // category was modified, ask user if wants to save +// +// StringBuilder buffer = new StringBuilder(); +// buffer.append(_("config.message.quit.valid.and.modified.category", +// categoryName)).append('\n'); +// for (OptionModel m : categoryModel.getModifiedOptions()) { +// buffer.append("\n- ").append(m.getKey()); +// } +// buffer.append('\n'); +// +// int reponse = askUser(ui, +// _("config.title.need.confirm"), buffer.toString(), +// JOptionPane.WARNING_MESSAGE, +// new Object[]{ +// _("config.choice.save"), +// _("config.choice.doNotSave"), +// _("config.choice.cancel")}, +// 0); +// +// switch (reponse) { +// case JOptionPane.CLOSED_OPTION: +// case 2: +// canContinue = false; +// break; +// case 0: +// // will save ui +// model.saveModified(); +// break; +// case 1: +// // wil reset ui +// model.reset(); +// break; +// } +// +// } +// return canContinue; } public static int askUser(ConfigUI parent, @@ -292,18 +286,24 @@ int typeMessage, Object[] options, int defaultOption) { + int response = parent.getHandler().askUser(title, + message, + typeMessage, + options, + defaultOption); + return response; - int response = JOptionPane.showOptionDialog( - parent, - message, - title, - JOptionPane.DEFAULT_OPTION, - typeMessage, - null, - options, - options[defaultOption] - ); - - return response; +// int response = JOptionPane.showOptionDialog( +// parent, +// message, +// title, +// JOptionPane.DEFAULT_OPTION, +// typeMessage, +// null, +// options, +// options[defaultOption] +// ); +// +// return response; } } Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java 2010-04-14 17:40:00 UTC (rev 1843) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java 2010-04-14 18:38:22 UTC (rev 1844) @@ -27,6 +27,7 @@ */ package jaxx.runtime.swing.editor.config; +import jaxx.runtime.SwingUtil; import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.swing.editor.config.model.*; import org.apache.commons.logging.Log; @@ -36,6 +37,8 @@ import javax.swing.event.ChangeEvent; import java.awt.*; import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.ArrayList; import static org.nuiton.i18n.I18n._; @@ -123,6 +126,36 @@ ui.getCategories().invalidate(); } + public void displayUI(Frame parentUI, boolean undecorated) { + JDialog f = new JDialog(parentUI, true); + f.setTitle(_("config.title")); + f.add(ui); + if (parentUI != null) { + f.setIconImage(parentUI.getIconImage()); + } + // pour savoir si l'ui est autonome + ui.getModel().setStandalone(parentUI == null); + + f.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + f.addWindowListener(new WindowAdapter() { + + @Override + public void windowClosing(WindowEvent e) { + ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); + ui.getQuit().getAction().actionPerformed(myEvent); + } + }); + f.setUndecorated(undecorated); + JRootPane rootPane = f.getRootPane(); + rootPane.setDefaultButton(ui.getQuit()); + rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke("ESCAPE"), "quit"); + rootPane.getActionMap().put("quit", ui.getQuit().getAction()); + f.pack(); + SwingUtil.center(ui, f); + f.setVisible(true); + } + protected Action createQuitAction() { JButton button = ui.getQuit(); Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java 2010-04-14 17:40:00 UTC (rev 1843) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java 2010-04-14 18:38:22 UTC (rev 1844) @@ -135,15 +135,80 @@ * @param model the model to scan * @return the dictionnary of options for each callback to launch */ - public CallBackMap getCallBacksForSaved( - ConfigUIModel model) { + public CallBackMap getCallBacksForSaved(ConfigUIModel model) { - CallBackMap result; - result = new CallBackMap(); + CallBackMap result = getCallBacks(model,true,false); + return result; +// result = new CallBackMap(); +// +// for (CategoryModel categoryModel : model) { +// Map<CallBackEntry, List<OptionModel>> callBacks = +// getCallBacksForSaved(categoryModel); +// for (Map.Entry<CallBackEntry, List<OptionModel>> entry : +// callBacks.entrySet()) { +// CallBackEntry key = entry.getKey(); +// List<OptionModel> value = entry.getValue(); +// if (result.containsKey(key)) { +// result.get(key).addAll(value); +// } else { +// result.put(key, value); +// } +// } +// callBacks.clear(); +// } +// +// CallBackFinalizer finalizer = getFinalizer(); +// if (finalizer != null) { +// result = finalizer.finalize(result); +// } +// return result; + } + /** + * Scan a category and grab per callBack the options saved. + * + * @param category the category to scan + * @return the dictionnary of options for each callBack to launch + */ + public CallBackMap getCallBacksForSaved(CategoryModel category) { + + CallBackMap result = getCallBacks(category,true,false); + return result; +// result = new CallBackMap(); +// +// for (OptionModel optionModel : category) { +// if (optionModel.isSaved()) { +// CallBackEntry callBackEntry = getCallBack(optionModel); +// if (callBackEntry != null) { +// List<OptionModel> models = result.get(callBackEntry); +// if (models == null) { +// models = new ArrayList<OptionModel>(); +// result.put(callBackEntry, models); +// } +// models.add(optionModel); +// } +// } +// } +// return result; + } + + /** + * Scan a model and grab per callBack the options. + * + * @param model the model to scan + * @param modified {@code true} to include modified options + * @param saved {@code true} to include saved options + * @return the dictionnary of options for each callback to launch + */ + public CallBackMap getCallBacks(ConfigUIModel model, + boolean saved, + boolean modified) { + + CallBackMap result = new CallBackMap(); + for (CategoryModel categoryModel : model) { - Map<CallBackEntry, List<OptionModel>> callBacks = - getCallBacksForSaved(categoryModel); + CallBackMap callBacks = + getCallBacks(categoryModel, saved, modified); for (Map.Entry<CallBackEntry, List<OptionModel>> entry : callBacks.entrySet()) { CallBackEntry key = entry.getKey(); @@ -165,19 +230,23 @@ } /** - * Scan a category and grab per callBack the options saved. + * Scan a category and grab per callBack the options. * * @param category the category to scan + * @param modified {@code true} to include modified options + * @param saved {@code true} to include saved options * @return the dictionnary of options for each callBack to launch */ - public Map<CallBackEntry, List<OptionModel>> getCallBacksForSaved( - CategoryModel category) { + public CallBackMap getCallBacks(CategoryModel category, + boolean saved, + boolean modified) { - CallBackMap result; - result = new CallBackMap(); + CallBackMap result = new CallBackMap(); for (OptionModel optionModel : category) { - if (optionModel.isSaved()) { + if (modified && optionModel.isModified() || + saved && optionModel.isSaved()) { +// if (optionModel.isSaved()) { CallBackEntry callBackEntry = getCallBack(optionModel); if (callBackEntry != null) { List<OptionModel> models = result.get(callBackEntry); Modified: trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties =================================================================== --- trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties 2010-04-14 17:40:00 UTC (rev 1843) +++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties 2010-04-14 18:38:22 UTC (rev 1844) @@ -19,7 +19,7 @@ config.choice.save=Save config.defaultValue=Default value config.defaultValue.tip=Default value of the option -config.descrition=Description +config.description=Description config.detected.callBack=Detected actions config.error.category.already.exists=category with name '%1$s' does already exist\! config.error.category.not.found=category with name '%1$s' does not exist\! Modified: trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties =================================================================== --- trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties 2010-04-14 17:40:00 UTC (rev 1843) +++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties 2010-04-14 18:38:22 UTC (rev 1844) @@ -19,7 +19,7 @@ config.choice.save=Enregistrer config.defaultValue=Valeur par d\u00E9faut config.defaultValue.tip=Valeur par d\u00E9faut de l'option -config.descrition=Description +config.description=Description config.detected.callBack=Actions d\u00E9tect\u00E9es pour les options modifi\u00E9es config.error.category.already.exists=La cat\u00E9gorie de nom '%1$s' existe d\u00E9j\u00E0\! config.error.category.not.found=La cat\u00E9gorie de nom '%1$s' n'existe pas\!
participants (1)
-
tchemit@users.nuiton.org