[Buix-commits] r1241 - in jaxx/trunk: . jaxx-compiler-swing/src/main/java/jaxx/tags/swing jaxx-example/src/main/java/jaxx/demo jaxx-runtime-swing jaxx-runtime-swing/src/main/java/jaxx/runtime/swing jaxx-swing-action jaxx-swing-action/src/main/java/org/codelutin/jaxx jaxx-swing-action/src/main/java/org/codelutin/jaxx/util jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config jaxx-swing-action/src/main/resources/i18n jaxx-util/src/main/java/org/codelutin/jaxx/util jaxx-util/src/main/java/org/codeluti
Author: tchemit Date: 2009-02-23 13:06:52 +0000 (Mon, 23 Feb 2009) New Revision: 1241 Added: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUI.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FormElement.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIFactory.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIHelper.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIProvider.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java Removed: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUI.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FormElement.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIFactory.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIHelper.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIProvider.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java Modified: jaxx/trunk/changelog.txt jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/JTextComponentHandler.java jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx jaxx/trunk/jaxx-runtime-swing/changelog.txt jaxx/trunk/jaxx-swing-action/pom.xml jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-en_GB.properties jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-fr_FR.properties jaxx/trunk/pom.xml Log: - move sources from jaxx-util to jaxx-swing-action module - delete jaxx-util module - rename jaxx.runtime.swing.Utils to jaxx.runtime.SwingUtil Modified: jaxx/trunk/changelog.txt =================================================================== --- jaxx/trunk/changelog.txt 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/changelog.txt 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,3 +1,7 @@ +1.2 ??? 2009???? + * 20090223 [chemit] - move sources from jaxx-util to jaxx-swing-action module + - delete jaxx-util module + 1.1 chemit 20090220 * 20090203 [chemit] - use i18n 0.9 (zeroConf) * 20090203 [chemit] - use lutinproject 3.4 Modified: jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/JTextComponentHandler.java =================================================================== --- jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/JTextComponentHandler.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-compiler-swing/src/main/java/jaxx/tags/swing/JTextComponentHandler.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -16,6 +16,7 @@ import javax.swing.JTextArea; import javax.swing.event.DocumentListener; import javax.swing.text.JTextComponent; +import jaxx.runtime.SwingUtil; public class JTextComponentHandler extends DefaultComponentHandler { private static final int DEFAULT_COLUMNS = 15; @@ -45,7 +46,8 @@ @Override public String getSetPropertyCode(String id, String name, String valueCode, JAXXCompiler compiler) throws CompilerException { if (name.equals("text")) { - return "jaxx.runtime.swing.Utils.setText(" + id + ", " + valueCode + ");\n"; + return SwingUtil.class.getName()+".setText(" + id + ", " + valueCode + ");\n"; + //return "jaxx.runtime.swing.Utils.setText(" + id + ", " + valueCode + ");\n"; } return super.getSetPropertyCode(id, name, valueCode, compiler); } Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx =================================================================== --- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/ValidationTableDemo.jaxx 2009-02-23 13:06:52 UTC (rev 1241) @@ -28,15 +28,15 @@ <script><![CDATA[ import static org.codelutin.i18n.I18n.n_; -import jaxx.runtime.swing.Utils; +import jaxx.runtime.SwingUtil; static boolean wasinit=false; errorTable.setDefaultRenderer(Object.class, new jaxx.runtime.validator.swing.SwingValidatorErrorTableRenderer()); -Utils.setI18nTableHeaderRenderer(errorTable, n_("validator.scope"), n_("validator.scope.tip"), n_("validator.field"), n_("validator.field.tip"), n_("validator.message"), n_("validator.message.tip")); +SwingUtil.setI18nTableHeaderRenderer(errorTable, n_("validator.scope"), n_("validator.scope.tip"), n_("validator.field"), n_("validator.field.tip"), n_("validator.message"), n_("validator.message.tip")); public void setVisible(boolean value) { if (!wasinit) { - Utils.fixTableColumnWidth(errorTable, 0, 20); + SwingUtil.fixTableColumnWidth(errorTable, 0, 20); wasinit=true; } super.setVisible(value); Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt =================================================================== --- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,3 +1,6 @@ +1.2 ??? 2009???? + * 20090223 [chemit] - rename jaxx.runtime.swing.Utils to jaxx.runtime.SwingUtil + 1.1 chemit 20090220 * 20090124 [chemit] - add a cache on context path to improve performance on NavigationTreeNode - improve I18nTableCellRenderer to display toolTipText Deleted: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Utils.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,143 +0,0 @@ -/* - * Copyright 2006 Ethan Nicholas. All rights reserved. - * Use is subject to license terms. - */ -package jaxx.runtime.swing; - -import java.util.List; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JComboBox; -import javax.swing.JTable; -import javax.swing.SwingUtilities; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.text.AbstractDocument; -import javax.swing.text.JTextComponent; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; - -/** - * - * @author tony - * @deprecatedwill remove in release 1.2, prefer use the {@link jaxx.runtime.SwingUtil} class. - * - */ -public class Utils { - private static Field numReaders; - private static Field notifyingListeners; - - @Deprecated - public static void setText(final JTextComponent c, final String text) { - try { - // AbstractDocument deadlocks if we try to acquire a write lock while a read lock is held by the current thread - // If there are any readers, dispatch an invokeLater. This should only happen in the event of circular bindings. - // Similarly, circular bindings can result in an "Attempt to mutate in notification" error, which we deal with - // by checking for the 'notifyingListeners' property. - AbstractDocument document = (AbstractDocument) c.getDocument(); - if (numReaders == null) { - numReaders = AbstractDocument.class.getDeclaredField("numReaders"); - numReaders.setAccessible(true); - } - if (notifyingListeners == null) { - notifyingListeners = AbstractDocument.class.getDeclaredField("notifyingListeners"); - notifyingListeners.setAccessible(true); - } - - if (notifyingListeners.get(document).equals(Boolean.TRUE)) { - return; - } - - if ((Integer) numReaders.get(document) > 0) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - if (!c.getText().equals(text)) { - c.setText(text); - } - } - }); - return; - } - - String oldText = c.getText(); - if (oldText == null || !oldText.equals(text)) { - c.setText(text); - } - } - catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - catch (SecurityException e) { - c.setText(text); - } - } - - /** - * Fill a combo box model with some datas, and select after all the given object - * - * @param combo the combo to fill - * @param data data ot inject in combo - * @param select the object to select in combo after reflling his model - */ - @Deprecated - public static void fillComboBox(JComboBox combo, Collection<?> data, Object select) { - if (!(combo.getModel() instanceof DefaultComboBoxModel)) { - throw new IllegalArgumentException("this method need a DefaultComboBoxModel for this model but was " + combo.getModel().getClass()); - } - DefaultComboBoxModel model = (DefaultComboBoxModel) combo.getModel(); - // evince the model - model.removeListDataListener(combo); - model.removeAllElements(); - for (Object o : data) { - model.addElement(o); - } - // attach the model - model.addListDataListener(combo); - model.setSelectedItem(select); - } - - /** - * Fill a combo box model with some datas, and select after all the given object - * - * @param combo the combo to fill - * @param data data ot inject in combo - * @param select the object to select in combo after reflling his model - * @param firstNull add a first null element - */ - @Deprecated - public static void fillComboBox(JAXXComboBox combo, Collection<?> data, Object select, boolean firstNull) { - List<Item> items = new ArrayList<Item>(); - if (firstNull) - items.add(new Item("null", " ", null, false)); - for (Object d : data){ - items.add(new Item(d.toString(), d.toString(), d, d.equals(select))); - } - combo.setItems(items); - } - @Deprecated - public static void fixTableColumnWidth(JTable table, int columnIndex, int width) { - TableColumn column = table.getColumnModel().getColumn(columnIndex); - column.setMaxWidth(width); - column.setMinWidth(width); - column.setWidth(width); - column.setPreferredWidth(width); - } - @Deprecated - public static void setTableColumnEditor(JTable table, int columnIndex, TableCellEditor editor) { - TableColumn column = table.getColumnModel().getColumn(columnIndex); - column.setCellEditor(editor); - } - @Deprecated - public static void setTableColumnRenderer(JTable table, int columnIndex, TableCellRenderer editor) { - TableColumn column = table.getColumnModel().getColumn(columnIndex); - column.setCellRenderer(editor); - } - @Deprecated - public static void setI18nTableHeaderRenderer(JTable table, String... libelles) { - table.getTableHeader().setDefaultRenderer(new I18nTableCellRenderer(table.getTableHeader().getDefaultRenderer(), libelles)); - } -} Modified: jaxx/trunk/jaxx-swing-action/pom.xml =================================================================== --- jaxx/trunk/jaxx-swing-action/pom.xml 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-swing-action/pom.xml 2009-02-23 13:06:52 UTC (rev 1241) @@ -22,12 +22,6 @@ <dependency> <groupId>${project.groupId}</groupId> - <artifactId>jaxx-util</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>${project.groupId}</groupId> <artifactId>jaxx-runtime-swing</artifactId> <version>${project.version}</version> </dependency> Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,53 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** @author chemit */ +public abstract class AbstractUIAction<H extends DialogUIHandler<?, ?>> extends javax.swing.AbstractAction { + + protected static Log log = LogFactory.getLog(AbstractUIAction.class); + + protected transient DialogUI<? extends H> ui; + + private static final long serialVersionUID = 1L; + + protected AbstractUIAction(String name, javax.swing.Icon icon, DialogUI<? extends H> ui) { + super(name, icon); + this.ui = ui; + } + + protected H getHandler() { + checkInit(); + return ui.getHandler(); + } + + protected void setUi(DialogUI<? extends H> ui) { + this.ui = ui; + } + + public DialogUI<? extends H> getUi() { + return ui; + } + + protected void checkInit() throws IllegalStateException { + /*if (ui == null) { + throw new IllegalStateException("no handler, nor ui referenced in " + this); + } */ + } + +} Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUI.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUI.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUI.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUI.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,129 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractAction; +import javax.swing.AbstractButton; +import javax.swing.ImageIcon; +import javax.swing.JDialog; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.lang.reflect.Constructor; + +/** + * A abstract dialog contract to be realised by a dialogUI (WindowEvent adapter) + * <p/> + * TODO : make jaxx authorized implementing interface for root tag :) + * + * @author chemit + */ +public abstract class DialogUI<H extends DialogUIHandler> extends JDialog implements WindowListener { + + protected static Log log = LogFactory.getLog(DialogUI.class); + + public javax.swing.AbstractAction newAction(Class<?> actionClass, Object... params) { + Constructor<?> constructor = null; + for (Constructor<?> cons : actionClass.getConstructors()) { + Class<?>[] prototype = cons.getParameterTypes(); + if (prototype.length > 0 && DialogUI.class.isAssignableFrom(prototype[0])) { + // use this constructor + constructor = cons; + break; + } + } + if (constructor == null) { + throw new IllegalStateException("could not find a matching constructor for " + actionClass); + } + + // wrap params + Object[] parameters = new Object[1 + params.length]; + parameters[0] = this; + System.arraycopy(params, 0, parameters, 1, params.length); + try { + AbstractAction action = (AbstractAction) constructor.newInstance(parameters); + if (log.isInfoEnabled()) { + log.info(action); + } + return action; + } catch (Exception e) { + throw new IllegalStateException("could not init the action " + actionClass + " for reason : " + e.getMessage()); + } + } + + private H handler; + + public abstract AbstractButton getHelp(); + + public abstract Object getObjectById(java.lang.String s); + + protected DialogUI() { + UIHelper.setQuitAction(this); + addWindowListener(this); + //TODO will be handled by jaxx with javax.help... + //getHelp().setAction(newAction(HelpAction.class)); + } + + public H getHandler() { + return handler; + } + + public void setHandler(H handler) { + this.handler = handler; + } + + protected ImageIcon createActionIcon(String name) { + return UIHelper.createActionIcon(name); + } + + public void windowOpened(WindowEvent e) { + } + + public void windowClosed(WindowEvent e) { + } + + public void windowClosing(WindowEvent e) { + } + + public void windowIconified(WindowEvent e) { + } + + public void windowDeiconified(WindowEvent e) { + } + + public void windowActivated(WindowEvent e) { + } + + public void windowDeactivated(WindowEvent e) { + } + + @Override + public synchronized void addWindowListener(WindowListener l) { + super.addWindowListener(l); + if (log.isDebugEnabled()) { + log.debug("after added (" + getWindowListeners().length + ") : " + l); + } + } + + @Override + public synchronized void removeWindowListener(WindowListener l) { + super.removeWindowListener(l); + if (log.isDebugEnabled()) { + log.debug("after removed (" + getWindowListeners().length + ") : " + l); + } + } +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUI.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,235 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import static org.codelutin.i18n.I18n._; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.ImageIcon; +import java.lang.reflect.Constructor; + +/** + * Definition of an ui, with his model, handler and ui class definitions. + * <p/> + * The class contains also a shared instace of concrete ui. + * + * @author chemit + */ +public class DialogUIDef<M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> implements java.io.Serializable { + + static protected final Log log = LogFactory.getLog(DialogUIDef.class); + + public static <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> DialogUIDef<M, U, H> newDef(Class<H> handlerClass, Class<U> uiClass, Class<M> modelClass, String showActionLibelle, String showActionTip, String uiTitle) { + DialogUIDef<M, U, H> result; + result = new DialogUIDef<M, U, H>(handlerClass, uiClass, modelClass, showActionLibelle, showActionTip, uiTitle); + return result; + } + + /** + * model class + */ + private final Class<M> modelClass; + + /** + * handler class + */ + private final Class<H> handlerClass; + + /** + * abstract ui class + */ + private final Class<U> uiClass; + + /** + * concrete lookup ui class + */ + private Class<? extends U> uiImplClass; + + /** + * shared instance of ui + */ + protected U uiInstance; + + /** + * unique name of ui def + */ + protected final String name; + + protected final String uiTitle; + protected final String showActionLibelle; + protected final String showActionTip; + + protected ImageIcon showUIActionIcon; + + + private static final long serialVersionUID = 1L; + + private DialogUIDef(Class<H> handlerClass, Class<U> uiClass, Class<M> modelClass, + String showActionLibelle, String showActionTip, String uiTitle) { + this.handlerClass = handlerClass; + this.uiClass = uiClass; + this.modelClass = modelClass; + this.showActionLibelle = showActionLibelle; + this.name = uiClass.getSimpleName().toLowerCase(); + this.showActionTip = showActionTip; + this.uiTitle = uiTitle; + } + + public Class<U> getUiClass() { + return uiClass; + } + + public Class<H> getHandlerClass() { + return handlerClass; + } + + public Class<M> getModelClass() { + return modelClass; + } + + public Class<? extends U> getUiImplClass() { + return uiImplClass; + } + + public String getUiTitle() { + return _(uiTitle); + } + + public String getShowActionLibelle() { + return _(showActionLibelle); + } + + public String getShowActionTip() { + return _(showActionTip); + } + + public ImageIcon getShowUIActionIcon() { + if (showUIActionIcon == null) { + showUIActionIcon = UIHelper.createActionIcon("show-" + name); + } + return showUIActionIcon; + } + + @SuppressWarnings({"unchecked"}) + public void setUiImplClass(Class<?> uiImplClass) { + this.uiImplClass = (Class<? extends U>) uiImplClass; + } + + @Override + public boolean equals(Object o) { + return this == o || o instanceof DialogUIDef && uiClass.equals(((DialogUIDef) o).uiClass); + } + + @Override + public int hashCode() { + return uiClass.hashCode(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()).append('<'); + sb.append(printClass("handler", handlerClass, true)); + sb.append(printClass("model", modelClass, true)); + sb.append(printClass("ui", uiClass, true)); + sb.append(printClass("uiImpl", uiImplClass, false)); + return sb.toString(); + } + + protected U getUiInstance() { + // no lazy instanciation, to control ui instanciation... + /*if (uiInstance == null) { + if (uiImplClass == null) { + throw new IllegalStateException("no concrete ui impl found in " + this); + } + synchronized (this) { + try { + uiInstance = uiImplClass.newInstance(); + } catch (Exception e) { + throw new IllegalStateException("could not instanciate ui " + this,e); + } + } + }*/ + return uiInstance; + } + + protected void setUiInstance(U uiInstance) { + this.uiInstance = uiInstance; + } + + protected U newUI() { + if (uiImplClass == null) { + throw new IllegalStateException("no concrete ui impl found in " + this); + } + try { + U result = uiImplClass.newInstance(); + log.info(result); + return result; + } catch (Exception e) { + throw new IllegalStateException("could not instanciate ui " + this, e); + } + } + + protected M newModel() { + if (modelClass == null) { + throw new IllegalStateException("no model impl found in " + this); + } + try { + M model = modelClass.newInstance(); + log.info(model); + return model; + } catch (Exception e) { + throw new IllegalStateException("could not instanciate ui " + this, e); + } + } + + protected H newHandler(U ui, M model, Object... params) { + if (handlerClass == null) { + throw new IllegalStateException("no handler impl found in " + this); + } + try { + Class[] prototype = getHandlerPrototype(params); + Object[] parameters = getHandlerParameters(ui, model, params); + H result = handlerClass.getConstructor(prototype).newInstance(parameters); + log.info(result); + return result; + } catch (Exception e) { + throw new IllegalStateException("could not instanciate ui " + this, e); + } + } + + protected Object[] getHandlerParameters(U ui, M model, Object[] params) { + Object[] result = new Object[2 + params.length]; + result[0] = ui; + result[1] = model; + System.arraycopy(params, 0, result, 2, params.length); + return result; + } + + protected Class[] getHandlerPrototype(Object[] params) { + int length = params.length; + for (Constructor<?> constructor : handlerClass.getConstructors()) { + Class<?>[] prototype = constructor.getParameterTypes(); + if (prototype.length == 2 + length && prototype[0] == uiClass && prototype[1] == modelClass) { + return prototype; + } + } + throw new IllegalStateException("could not find a matching constructor in " + handlerClass); + } + + protected String printClass(String s, Class<?> aClass, boolean notLast) { + return s + ':' + (aClass == null ? null : aClass.getSimpleName()) + (notLast ? ", " : ">"); + } +} Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,70 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.event.WindowListener; +import java.beans.PropertyChangeListener; + +/** + * DialogUI handler + * + * @author chemit + */ +public abstract class DialogUIHandler<M extends DialogUIModel, U extends DialogUI<? extends DialogUIHandler>> implements PropertyChangeListener { + + protected static Log log = LogFactory.getLog(DialogUIHandler.class); + + /** ui handled */ + private U ui; + + /** model handled */ + private M model; + + protected DialogUIHandler(U ui, M model) { + this.ui = ui; + this.model = model; + } + + public U getUi() { + return ui; + } + + public M getModel() { + return model; + } + + public void init() { + if (model == null) { + throw new IllegalStateException("no model was defined for " + this); + } + model.addPropertyChangeListener(this); + } + + public void dispose() { + model.dispose(); + for (WindowListener windowListener : getUi().getWindowListeners()) { + getUi().removeWindowListener(windowListener); + } + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + dispose(); + } +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,97 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +/** + * Abstract ui model, with property change support. + * + * @author chemit + */ +public abstract class DialogUIModel { + + static protected final Log log = LogFactory.getLog(DialogUIModel.class); + + /** support for change properties support */ + protected PropertyChangeSupport changeSupport; + + public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + if (listener == null) { + return; + } + if (changeSupport == null) { + changeSupport = new PropertyChangeSupport(this); + } + changeSupport.addPropertyChangeListener(propertyName, listener); + } + + public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { + if (listener == null) { + return; + } + if (changeSupport == null) { + changeSupport = new PropertyChangeSupport(this); + } + changeSupport.addPropertyChangeListener(listener); + } + + public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { + if (listener == null || changeSupport == null) { + return; + } + changeSupport.removePropertyChangeListener(listener); + } + + public synchronized void removePropertyChangeListeners() { + if (changeSupport == null) { + return; + } + for (PropertyChangeListener listener : getPropertyChangeListeners()) { + changeSupport.removePropertyChangeListener(listener); + } + } + + public synchronized PropertyChangeListener[] getPropertyChangeListeners() { + if (changeSupport == null) { + return new PropertyChangeListener[0]; + } + return changeSupport.getPropertyChangeListeners(); + } + + public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + if (changeSupport == null || (oldValue == null && newValue == null) || + (oldValue != null && oldValue.equals(newValue))) { + return; + } + changeSupport.firePropertyChange(propertyName, oldValue, newValue); + } + + public void dispose() { + for (PropertyChangeListener listener : changeSupport.getPropertyChangeListeners()) { + changeSupport.removePropertyChangeListener(listener); + } + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + dispose(); + } +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,84 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +/** + * A windowListenr for ui managed by {@link org.codelutin.jaxx.util.UIFactory}. + * <p/> + * To be used when all ui from factory are closed, via {@link #allWindowsClosed(java.awt.event.WindowEvent)} method. + * + * @author chemit + */ +public abstract class FactoryWindowListener extends WindowAdapter { + + /** + * method to be invoked when all ui registred in factory are really disposed. + * + * @param e event + */ + public abstract void allWindowsClosed(WindowEvent e); + + /** underlying factory of ui */ + private UIFactory factory; + + /** flag to make sure {@link #allWindowsClosed(java.awt.event.WindowEvent)} is called only once. */ + private boolean wasClosed; + + @Override + public void windowClosed(WindowEvent e) { + if (UIFactory.log.isDebugEnabled()) { + UIFactory.log.debug(this + " : " + e); + } + if (e.getWindow().isVisible()) { + // only deal with real closed and none visible windows... + return; + } + for (DialogUIDef def : factory.getDefs()) { + DialogUI ui = def.uiInstance; + if (ui != null && ui.isVisible()) { + // at least one ui visible, do not close all + return; + } + } + + if (wasClosed) { + // make sure to process only once + return; + } + if (UIFactory.log.isInfoEnabled()) { + UIFactory.log.info("closing factory listener " + this); + } + + synchronized (this) { + try { + allWindowsClosed(e); + } finally { + wasClosed = true; + factory.removeFactoryWindowListener(this); + } + } + } + + protected UIFactory getFactory() { + return factory; + } + + protected void setFactory(UIFactory factory) { + this.factory = factory; + } +} Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FormElement.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FormElement.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FormElement.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FormElement.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,29 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +/** @author chemit */ +public interface FormElement<U extends DialogUI> { + + String name(); + + int ordinal(); + + Object getValue(U ui); + + void setValue(U ui, String value); + + javax.swing.JLabel getLabel(U ui); +} Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/FormElement.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,135 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.awt.Dimension; +import java.awt.Point; +import java.awt.event.ActionEvent; + +/** @author chemit */ +public abstract class ShowUIAction<M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> extends javax.swing.AbstractAction { + + protected static Log log = LogFactory.getLog(AbstractUIAction.class); + + protected transient DialogUI<?> ui; + + private static final long serialVersionUID = 1L; + + protected DialogUIDef<M, U, H> uiDef; + + protected transient UIFactory factory; + + protected String position; + + protected boolean undecorated = true; + + protected U initUI(ActionEvent e) { + return getFactory().getUI(uiDef); + } + + public ShowUIAction(DialogUI<?> ui, DialogUIDef<M, U, H> uiDef, UIFactory factory, boolean showText) { + super(uiDef.getShowActionLibelle(), uiDef.getShowUIActionIcon()); + this.ui = ui; + this.uiDef = uiDef; + String name = (String) getValue(NAME); + putValue(DISPLAYED_MNEMONIC_INDEX_KEY, name.length() - 1); + putValue(ACCELERATOR_KEY, (int) name.charAt(name.length() - 1)); + if (!showText) { + putValue(NAME, null); + } + putValue(SHORT_DESCRIPTION, uiDef.getShowActionTip()); + this.factory = factory; + } + + public DialogUI<?> getUi() { + return ui; + } + + public DialogUIDef<M, U, H> getUiDef() { + return uiDef; + } + + public UIFactory getFactory() { + return factory; + } + + public void setUiDef(DialogUIDef<M, U, H> uiDef) { + this.uiDef = uiDef; + } + + public void setPosition(String position) { + this.position = position; + } + + public void setUndecorated(boolean undecorated) { + this.undecorated = undecorated; + } + + public void actionPerformed(java.awt.event.ActionEvent e) { + checkInit(); + U ui = initUI(e); + ui.setTitle(uiDef.getUiTitle()); + log.info(ui.getTitle()); + //TODO ui.setUndecorated(undecorated); + setPosition(this.getUi(), ui, position); + + ui.setVisible(true); + } + + protected void setPosition(javax.swing.JDialog parentUI, javax.swing.JDialog ui, String position) { + if (position == null || parentUI == null) { + return; + } + Point parentLocation = parentUI.getLocationOnScreen(); + Dimension parentSize = parentUI.getSize(); + + if (position.equals("bottom-left")) { + int top = (int) (parentLocation.getY() + parentSize.getHeight()); + int left = (int) (parentLocation.getX()); + Point newLocation = new Point(left, top); + newLocation.setLocation(left, top); + ui.setLocation(newLocation); + return; + } + if (position.equals("top-left")) { + int top = (int) (parentLocation.getY()); + int left = (int) (parentLocation.getX()); + Point newLocation = new Point(left, top); + newLocation.setLocation(left, top); + ui.setLocation(newLocation); + return; + } + if (position.equals("top-right")) { + int top = (int) (parentLocation.getY()); + int left = (int) (parentLocation.getX() + parentSize.getWidth()); + Point newLocation = new Point(left, top); + newLocation.setLocation(left, top); + ui.setLocation(newLocation); + return; + } + if (position.equals(("center"))) { + //TODO + } + } + + protected void checkInit() throws IllegalStateException { + if (factory == null) { + throw new IllegalStateException("no factory found in " + this); + } + } +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIFactory.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIFactory.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIFactory.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIFactory.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,184 @@ +/** +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.StringUtil; + +import javax.swing.event.EventListenerList; +import java.util.ArrayList; +import java.util.List; +import java.util.ServiceLoader; + +/** + * Factory for UI, using a cache and a provider to find ui implementations. + * + * @author chemit + */ +public class UIFactory { + + static protected final Log log = LogFactory.getLog(UIFactory.class); + + private final String applicationName; + + private final DialogUIDef[] defs; + + private final EventListenerList listeners; + + public UIFactory(String applicationName, DialogUIDef[] defs, FactoryWindowListener... listeners) { + this.applicationName = applicationName; + this.listeners = new EventListenerList(); + for (FactoryWindowListener listener : listeners) { + listener.setFactory(this); + addFactoryWindowListener(listener); + } + this.defs = defs; + long t0 = System.nanoTime(); + if (log.isDebugEnabled()) { + log.debug("start at " + new java.util.Date()); + } + try { + init(); + } catch (Exception e) { + log.error(e); + throw new RuntimeException(e); + } finally { + if (log.isDebugEnabled()) { + log.info("end in " + StringUtil.convertTime(t0, System.nanoTime())); + } + } + } + + public void addFactoryWindowListener(FactoryWindowListener l) { + listeners.add(FactoryWindowListener.class, l); + if (log.isDebugEnabled()) { + log.debug("after added (" + listeners.getListenerCount() + ") : " + l); + } + } + + public void removeFactoryWindowListener(FactoryWindowListener l) { + listeners.remove(FactoryWindowListener.class, l); + for (DialogUIDef def : getDefs()) { + if (def.uiInstance != null) { + def.uiInstance.removeWindowListener(l); + } + } + if (log.isDebugEnabled()) { + log.debug(" after removed (" + listeners.getListenerCount() + ") : " + l); + } + if (listeners.getListenerCount(FactoryWindowListener.class) == 0) { + // close for real factory + close(); + } + } + + public void close() { + log.info(this + " at " + new java.util.Date()); + for (DialogUIDef<?, ?, ?> def : defs) { + DialogUI<?> ui = def.uiInstance; + if (ui != null) { + ui.getHandler().dispose(); + def.uiInstance = null; + } + } + if (listeners.getListenerCount(FactoryWindowListener.class) > 0) { + log.warn("some listeners where not properly removed, force deletion..."); + for (FactoryWindowListener listener : listeners.getListeners(FactoryWindowListener.class)) { + removeFactoryWindowListener(listener); + } + } + + } + + protected void init() { + + UIProvider[] providers = detectProviders(); + + for (DialogUIDef<?, ?, ?> def : defs) { + initDef(providers, def); + if (def.getUiImplClass() == null) { + throw new IllegalStateException("could not find implementation for ui def " + def); + } + } + } + + protected void initDef(UIProvider[] providers, DialogUIDef<?, ?, ?> def) { + for (UIProvider provider : providers) { + Class<?> uiImplClass = provider.findUIImplementation(def); + if (uiImplClass != null) { + if (log.isDebugEnabled()) { + log.debug("init done for " + def); + } + // ui implementation was found + break; + } + } + } + + protected UIProvider[] detectProviders() { + long t0 = System.nanoTime(); + List<UIProvider> providers = new ArrayList<UIProvider>(); + for (UIProvider provider : ServiceLoader.load(UIProvider.class)) { + if (applicationName.equals(provider.getApplicationName())) { + if (log.isDebugEnabled()) { + log.debug("provider detected [" + provider + ']'); + } + providers.add(provider); + } + } + log.info("found " + providers.size() + " ui provider(s) in " + StringUtil.convertTime(t0, System.nanoTime()) + " : " + providers); + return providers.toArray(new UIProvider[providers.size()]); + } + + protected DialogUIDef[] getDefs() { + return defs; + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + close(); + } + + public <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> U getUI(DialogUIDef<M, U, H> uiType, Object... params) { + U ui = uiType.uiInstance; + if (ui == null) { + try { + ui = uiType.newUI(); + M model = uiType.newModel(); + H handler = uiType.newHandler(ui, model, params); + registerUI(uiType, ui, handler); + } catch (Exception e) { + throw new IllegalStateException("could not instanciate ui handler " + uiType + " for reason : " + e.getMessage(), e); + } + } + return ui; + } + + protected <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> void registerUI(DialogUIDef<M, U, H> uiType, U ui, H handler) { + ui.setHandler(handler); + handler.init(); + uiType.setUiInstance(ui); + for (FactoryWindowListener listener : listeners.getListeners(FactoryWindowListener.class)) { + if (log.isDebugEnabled()) { + log.debug("----- addFactoryWindowListener " + listener + " to " + ui); + } + ui.addWindowListener(listener); + } + } + +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIFactory.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIHelper.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIHelper.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIHelper.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIHelper.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,70 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package org.codelutin.jaxx.util; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JRootPane; +import javax.swing.KeyStroke; +import java.awt.event.ActionEvent; + +/** + * Ui helper class. + * + * @author tony + */ +public class UIHelper { + + public static ImageIcon createImageIcon(String path) { + java.net.URL imgURL = UIHelper.class.getResource("/icons/" + path); + if (imgURL != null) { + return new ImageIcon(imgURL); + } else { + throw new IllegalArgumentException("could not find icon " + path); + } + } + + /** + * Attach to <code>ui</code> an abort action,accessible by <code>ESC</code> key. + * + * @param ui ui + */ + public static void setQuitAction(final JDialog ui) { + JRootPane rootPane = ui.getRootPane(); + + Action quitAction = new AbstractAction("quit") { + private static final long serialVersionUID = -869095664995763057L; + + public void actionPerformed(ActionEvent e) { + ui.dispose(); + } + }; + rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "quit"); + rootPane.getActionMap().put("quit", quitAction); + ui.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + } + + public static ImageIcon createActionIcon(String name) { + return createImageIcon("action-" + name + ".png"); + } + +} Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIHelper.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIProvider.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIProvider.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIProvider.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIProvider.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,86 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util; + +/** @author chemit */ +public abstract class UIProvider { + + /** the name of application using this provider */ + protected String applicationName; + + /** the name of ui implementation used by this provider */ + protected String providerName; + + /** array of ui implementations */ + protected Class<?>[] implementations; + + protected UIProvider(String applicationName, String providerName, Class<?>... implementations) { + this.applicationName = applicationName; + this.providerName = providerName; + this.implementations = implementations; + } + + public String getProviderName() { + return providerName; + } + + public String getApplicationName() { + return applicationName; + } + + public Class<?>[] getImplementations() { + return implementations; + } + + public Class<?> findUIImplementation(DialogUIDef<?, ?, ?> def) { + Class<? extends DialogUI<?>> uiClass = def.getUiClass(); + for (Class<?> klass : implementations) { + if (uiClass.isAssignableFrom(klass)) { + def.setUiImplClass(klass); + return klass; + } + } + return null; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(super.toString()).append('<'); + sb.append(printClass("application", applicationName, true)); + sb.append(printClass("provider", providerName, true)); + sb.append(printClass("uis", implementations.length, false)); + return sb.toString(); + } + + protected String printClass(String s, Object aClass, boolean notLast) { + return s + ':' + (aClass == null ? null : aClass) + (notLast ? ", " : ">"); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof UIProvider)) return false; + + UIProvider that = (UIProvider) o; + return applicationName.equals(that.applicationName) && providerName.equals(that.providerName); + + } + + @Override + public int hashCode() { + return (31 * applicationName.hashCode()) + providerName.hashCode(); + } + +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/UIProvider.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,43 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util.config; + +import org.codelutin.jaxx.util.AbstractUIAction; +import org.codelutin.jaxx.util.DialogUI; +import org.codelutin.jaxx.util.UIHelper; + +import java.awt.event.ActionEvent; + +/** @author chemit */ +public class CancelAction<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends AbstractUIAction<H> { + private static final long serialVersionUID = 1L; + + public CancelAction(DialogUI<? extends H> dialogUI, boolean showLabel) { + super(null, UIHelper.createActionIcon("cancel-config"), dialogUI); + if (showLabel) { + String text = org.codelutin.i18n.I18n._("lutinui.config.cancel"); + putValue(NAME, text); + putValue(DISPLAYED_MNEMONIC_INDEX_KEY, 0); + putValue(MNEMONIC_KEY, (int) text.charAt(0)); + } + String libelle = org.codelutin.i18n.I18n._("lutinui.config.cancel.tooltip"); + putValue(SHORT_DESCRIPTION, libelle); + + } + + public void actionPerformed(ActionEvent e) { + getUi().dispose(); + } +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,105 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util.config; + +import org.codelutin.jaxx.util.DialogUI; + +import javax.swing.AbstractButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPasswordField; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + +/** + * A abstract dialog contract to be realised by a dialogUI (WindowEvent adapter) + * <p/> + * TODO : make jaxx authorized implementing interface for root tag :) + * + * @author chemit + */ +public abstract class DialogConfigUI<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends DialogUI<H> { + + public abstract AbstractButton getOk(); + + public abstract AbstractButton getReset(); + + public abstract AbstractButton getCancel(); + + public JComponent getElement(E key) { + Object id = getObjectById(key.name()); + if (id == null) { + log.error(new NullPointerException("no widget for key "+key)); + return null; + } + if (!(id instanceof JComponent)) { + throw new IllegalArgumentException(id + " is not a JComponent"); + } + return (JComponent) id; + } + + public Object getElementValue(E key) { + JComponent o = getElement(key); + if (o instanceof JPasswordField) { + return new String(((JPasswordField) o).getPassword()); + } + if (o instanceof JTextField) { + return ((JTextField) o).getText(); + } + if (o instanceof JRadioButton) { + return ((JRadioButton) o).isSelected(); + } + if (o instanceof JCheckBox) { + return ((JCheckBox) o).isSelected(); + } + + if (o instanceof JComboBox) { + return ((JComboBox) o).getSelectedItem(); + } + return ""; + } + + public void setElementValue(E key, Object value) { + JComponent o = getElement(key); + + String strValue = value == null ? "" : String.valueOf(value); + if (o instanceof JPasswordField) { + ((JPasswordField) o).setText(strValue); + } + if (o instanceof JTextField) { + ((JTextField) o).setText(strValue); + } + if (o instanceof JRadioButton) { + ((JRadioButton) o).setSelected(Boolean.valueOf(strValue.isEmpty() ? "false" : strValue)); + } + if (o instanceof JCheckBox) { + ((JCheckBox) o).setSelected(Boolean.valueOf(strValue.isEmpty() ? "false" : strValue)); + } + if (o instanceof JComboBox) { + ((JComboBox) o).setSelectedItem(value); + } + } + + public JLabel getElementLabel(E key) { + return (JLabel) getObjectById(key.name() + "Label"); + } + + public void doCheck(E key) { + getHandler().doCheck(key); + } + +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,156 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util.config; + +import org.codelutin.jaxx.util.DialogUIHandler; +import org.codelutin.util.ConverterUtil; +import org.codelutin.util.config.Config; +import org.codelutin.util.config.Property; + +import javax.swing.JComponent; +import java.awt.Color; +import java.beans.PropertyChangeEvent; +import java.util.EnumMap; +import java.util.EnumSet; + +/** + * DialogUI handler + * + * @author chemit + */ +public abstract class DialogConfigUIHandler<E extends Enum<E>, M extends DialogConfigUIModel<E, ?>, U extends DialogConfigUI<E, ?>> extends DialogUIHandler<M, U> { + + protected DialogConfigUIHandler(U ui, M model) { + super(ui, model); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (log.isDebugEnabled()) { + log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); + } + String action = evt.getPropertyName(); + + if (DialogConfigUIModel.CONFIG_PROPERTY_CHANGED.equals(action)) { + // update ui with model values, + populateUI(); + // revalidate form + doCheckAll(); + return; + } + + if (DialogConfigUIModel.MODIFIED_PROPERTY_CHANGED.equals(action)) { + Boolean newValue = (Boolean) evt.getNewValue(); + boolean modified = newValue != null && newValue; + getUi().getReset().setEnabled(modified); + getUi().getOk().setEnabled(modified && getModel().isConfigValid()); + return; + } + + if (DialogConfigUIModel.UNVALID_PROPERTY_CHANGED.equals(action)) { + updateUI(); + return; + } + + throw new IllegalStateException("unimplemented property changed : " + evt + " for " + this); + } + + public void doCheck(E key) { + Object uiValue = getUi().getElementValue(key); + DialogConfigUIModel<E, ?> model = getModel(); + Object currentValue = model.getCurrent().getProperty(key); + if (currentValue == null) { + currentValue = ""; + } else { + currentValue = String.valueOf(currentValue); + } + + model.validateProperty(key, uiValue); + model.changeModifiedState(key, uiValue, currentValue); + } + + public void doCheckAll() { + DialogConfigUIModel<E, ?> model = getModel(); + EnumSet<E> unvalids = EnumSet.noneOf(model.klass); + for (E e : model.getCheckedKeysSet()) { + Object uiValue = getUi().getElementValue(e); + if (!model.isValid(e, uiValue)) { + unvalids.add(e); + } + } + model.setUnvalids(unvalids); + unvalids.clear(); + } + + protected boolean prepareSave() { + DialogConfigUI<E, ?> ui = getUi(); + DialogConfigUIModel<E, ?> model = getModel(); + + Config<E> current = model.getCurrent(); + + if (!model.isConfigValid()) { + log.warn("do not save a unvalid config : " + model.getUnvalids()); + return false; + } + + if (!model.isModified()) { + log.warn("nothing to save"); + return false; + } + EnumSet<E> toTreate = model.getCheckedKeysSet(); + // transfert checkable values from ui to model + for (E key : model.getModifieds()) { + if (!toTreate.contains(key)) { + continue; + } + Object value = ui.getElementValue(key); + Class<?> type = ((Property) key).getType(); + Object newValue = ConverterUtil.convert(type, value); + current.setProperty(key, newValue); + } + + return true; + } + + protected void populateUI() { + U ui = getUi(); + EnumMap<E, Object> map = getModel().getCurrent().getProperties(); + for (E e : getModel().getCheckedKeysSet()) { + Object value = map.get(e); + populateUI(ui, e, value); + } + } + + protected void populateUI(U ui, E key, Object value) { + ui.setElementValue(key, value); + } + + protected void updateUI() { + EnumSet<E> unvalids = getModel().getUnvalids(); + for (E key : unvalids) { + setLabelColor(key, false); + } + for (E key : EnumSet.complementOf(unvalids)) { + setLabelColor(key, true); + } + } + + protected void setLabelColor(E key, boolean valid) { + JComponent component = getUi().getElementLabel(key); + if (component != null && component.isVisible()) { + component.setForeground(valid ? Color.black : Color.red); + } + } + +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,220 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util.config; + +import org.codelutin.jaxx.util.DialogUIModel; +import org.codelutin.util.config.Config; + +import java.util.EnumSet; + +/** + * Abstract config ui model. + * + * @author chemit + */ +public abstract class DialogConfigUIModel<E extends Enum<E>, C extends Config<E>> extends DialogUIModel { + + public static final String CONFIG_PROPERTY_CHANGED = "config"; + public static final String MODIFIED_PROPERTY_CHANGED = "modify"; + public static final String UNVALID_PROPERTY_CHANGED = "unvalid"; + + /** @return a empty config */ + protected abstract C newConfig(); + + /** + * @param key property key + * @param value value to validate + * @return <code>true</code> if given value is valid for property, <code>false>/code> otherwise + */ + protected abstract boolean isValid(E key, Object value); + + /** + * object used to init model and save model, this is an external object. + * <p/> + * The object must have bean read-write properties for each value of E + */ + protected Object src; + + /** current config used in model */ + protected C current; + + /** set of modified properties */ + protected EnumSet<E> modifieds; + + /** set of unvalid properties */ + protected EnumSet<E> unvalids; + + /** enum class */ + protected Class<E> klass; + + /** set of key not to check */ + protected EnumSet<E> uncheckedKeys; + + /** set of all keys checkable */ + protected EnumSet<E> checkedKeysSet; + + protected DialogConfigUIModel(Class<E> klass) { + this.klass = klass; + this.current = newConfig(); + this.modifieds = EnumSet.noneOf(klass); + this.unvalids = EnumSet.noneOf(klass); + } + + public EnumSet<E> getCheckedKeysSet() { + if (checkedKeysSet == null) { + if (uncheckedKeys != null) { + checkedKeysSet = EnumSet.complementOf(uncheckedKeys); + } else { + checkedKeysSet = EnumSet.allOf(klass); + } + } + return checkedKeysSet; + } + + public Object getSrc() { + return src; + } + + public C getCurrent() { + return current; + } + + public EnumSet<E> getUnivserse() { + return getCurrent().getUniverse(); + } + + public EnumSet<E> getModifieds() { + return modifieds; + } + + public EnumSet<E> getUnvalids() { + return unvalids; + } + + public boolean isModified() { + return !modifieds.isEmpty(); + } + + public boolean isConfigValid() { + return unvalids.isEmpty(); + } + + public void populate(Object src) { + this.src = src; + this.current = newConfig(); + if (src != null) { + this.current.copyFrom(src); + } + this.modifieds.clear(); + this.unvalids.clear(); + setModified(false); + firePropertyChange(CONFIG_PROPERTY_CHANGED, null, this); + } + + public void reset() { + populate(src); + } + + public void setModified(boolean modified) { + firePropertyChange(MODIFIED_PROPERTY_CHANGED, null, modified); + } + + public void setUnvalid(boolean unvalid) { + firePropertyChange(UNVALID_PROPERTY_CHANGED, null, unvalid); + } + + public void addModified(E key) { + if (!modifieds.contains(key)) { + modifieds.add(key); + log.debug(key); + } + setModified(!modifieds.isEmpty()); + } + + public void removeModified(E key) { + + if (modifieds.contains(key)) { + modifieds.remove(key); + } + setModified(!modifieds.isEmpty()); + } + + public void removeModified(EnumSet<E> keys) { + for (E key : keys) { + if (modifieds.contains(key)) { + modifieds.remove(key); + } + } + setModified(!modifieds.isEmpty()); + } + + public void setUnvalids(EnumSet<E> keys) { + for (E key : keys) { + if (!unvalids.contains(key)) { + unvalids.add(key); + } + } + for (E key : EnumSet.complementOf(keys)) { + if (unvalids.contains(key)) { + unvalids.remove(key); + } + } + setUnvalid(!unvalids.isEmpty()); + } + + + public void addUnvalid(E key) { + if (!unvalids.contains(key)) { + unvalids.add(key); + } + setUnvalid(!unvalids.isEmpty()); + } + + public void removeUnvalid(E key) { + if (unvalids.contains(key)) { + unvalids.remove(key); + } + setUnvalid(!unvalids.isEmpty()); + } + + public void save() { + current.copyTo(src, modifieds); + modifieds.clear(); + // redisplay config + firePropertyChange(CONFIG_PROPERTY_CHANGED, null, this); + } + + public void changeModifiedState(E key, Object uiValue, Object currentValue) { + if (uiValue!=null && uiValue.equals(currentValue)) { + removeModified(key); + } else { + addModified(key); + } + } + + public void clear(E key) { + log.info(key); + modifieds.remove(key); + unvalids.remove(key); + } + + protected void validateProperty(E key, Object uiValue) { + if (isValid(key, uiValue)) { + removeUnvalid(key); + } else { + addUnvalid(key); + } + } +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,43 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util.config; + +import org.codelutin.jaxx.util.AbstractUIAction; +import org.codelutin.jaxx.util.DialogUI; +import org.codelutin.jaxx.util.UIHelper; + +import java.awt.event.ActionEvent; + +/** @author chemit */ +public class ResetAction<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends AbstractUIAction<H> { + private static final long serialVersionUID = 1L; + + public ResetAction(DialogUI<? extends H> dialogUI, boolean showLabel) { + super(null, UIHelper.createActionIcon("reset-config"), dialogUI); + if (showLabel) { + String text = org.codelutin.i18n.I18n._("lutinui.config.reset"); + putValue(NAME, text); + putValue(DISPLAYED_MNEMONIC_INDEX_KEY, 0); + putValue(MNEMONIC_KEY, (int) text.charAt(0)); + } + String libelle = org.codelutin.i18n.I18n._("lutinui.config.reset.tooltip"); + putValue(SHORT_DESCRIPTION, libelle); + + } + + public void actionPerformed(ActionEvent e) { + getHandler().getModel().reset(); + } +} \ No newline at end of file Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java ___________________________________________________________________ Name: svn:mergeinfo + Copied: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java (from rev 1237, jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java) =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java (rev 0) +++ jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -0,0 +1,50 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.jaxx.util.config; + +import org.codelutin.jaxx.util.AbstractUIAction; +import org.codelutin.jaxx.util.DialogUI; +import org.codelutin.jaxx.util.UIHelper; + +import java.awt.event.ActionEvent; + +/** @author chemit */ +public class SaveAction<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends AbstractUIAction<H> { + private static final long serialVersionUID = 1L; + + public SaveAction(DialogUI<? extends H> dialogUI, boolean showLabel) { + super(null, UIHelper.createActionIcon("save-config"), dialogUI); + if (showLabel) { + String text = org.codelutin.i18n.I18n._("lutinui.config.save"); + putValue(NAME, text); + putValue(DISPLAYED_MNEMONIC_INDEX_KEY, 0); + putValue(MNEMONIC_KEY, (int) text.charAt(0)); + } + String libelle = org.codelutin.i18n.I18n._("lutinui.config.save.tooltip"); + putValue(SHORT_DESCRIPTION, libelle); + } + + public void actionPerformed(ActionEvent e) { + + if (getHandler().prepareSave()) { + + // save model to src + getHandler().getModel().save(); + + // close ui + getUi().dispose(); + } + } +} Property changes on: jaxx/trunk/jaxx-swing-action/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java ___________________________________________________________________ Name: svn:mergeinfo + Modified: jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-en_GB.properties =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-en_GB.properties 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-en_GB.properties 2009-02-23 13:06:52 UTC (rev 1241) @@ -2,3 +2,9 @@ jaxx.error.close.actions.file=Error while closing file of actions jaxx.error.load.actions.class=Error while loading actions jaxx.error.load.actions.file=Error while loading file of actions +lutinui.config.cancel=Cancel +lutinui.config.cancel.tooltip=Cancel and quit +lutinui.config.reset=Reset +lutinui.config.reset.tooltip=Reset configuration +lutinui.config.save=Save +lutinui.config.save.tooltip=Save configuration and quit Modified: jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-fr_FR.properties =================================================================== --- jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-fr_FR.properties 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-swing-action/src/main/resources/i18n/jaxx-swing-action-fr_FR.properties 2009-02-23 13:06:52 UTC (rev 1241) @@ -2,3 +2,9 @@ jaxx.error.close.actions.file=Erreur lors de la fermeture du fichier d'actions jaxx.error.load.actions.class=Erreur lors du chargement des actions jaxx.error.load.actions.file=Erreur lors du chargement du fchier d'actions +lutinui.config.cancel=Annuler +lutinui.config.cancel.tooltip=Annuler les modification et quitter +lutinui.config.reset=R\u00E9initialiser +lutinui.config.reset.tooltip=R\u00E9initialiser la configuration +lutinui.config.save=Sauver +lutinui.config.save.tooltip=Sauver la configuration et quitter Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/AbstractUIAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,53 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** @author chemit */ -public abstract class AbstractUIAction<H extends DialogUIHandler<?, ?>> extends javax.swing.AbstractAction { - - protected static Log log = LogFactory.getLog(AbstractUIAction.class); - - protected transient DialogUI<? extends H> ui; - - private static final long serialVersionUID = 1L; - - protected AbstractUIAction(String name, javax.swing.Icon icon, DialogUI<? extends H> ui) { - super(name, icon); - this.ui = ui; - } - - protected H getHandler() { - checkInit(); - return ui.getHandler(); - } - - protected void setUi(DialogUI<? extends H> ui) { - this.ui = ui; - } - - public DialogUI<? extends H> getUi() { - return ui; - } - - protected void checkInit() throws IllegalStateException { - /*if (ui == null) { - throw new IllegalStateException("no handler, nor ui referenced in " + this); - } */ - } - -} Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUI.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUI.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUI.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,129 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.AbstractAction; -import javax.swing.AbstractButton; -import javax.swing.ImageIcon; -import javax.swing.JDialog; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.lang.reflect.Constructor; - -/** - * A abstract dialog contract to be realised by a dialogUI (WindowEvent adapter) - * <p/> - * TODO : make jaxx authorized implementing interface for root tag :) - * - * @author chemit - */ -public abstract class DialogUI<H extends DialogUIHandler> extends JDialog implements WindowListener { - - protected static Log log = LogFactory.getLog(DialogUI.class); - - public javax.swing.AbstractAction newAction(Class<?> actionClass, Object... params) { - Constructor<?> constructor = null; - for (Constructor<?> cons : actionClass.getConstructors()) { - Class<?>[] prototype = cons.getParameterTypes(); - if (prototype.length > 0 && DialogUI.class.isAssignableFrom(prototype[0])) { - // use this constructor - constructor = cons; - break; - } - } - if (constructor == null) { - throw new IllegalStateException("could not find a matching constructor for " + actionClass); - } - - // wrap params - Object[] parameters = new Object[1 + params.length]; - parameters[0] = this; - System.arraycopy(params, 0, parameters, 1, params.length); - try { - AbstractAction action = (AbstractAction) constructor.newInstance(parameters); - if (log.isInfoEnabled()) { - log.info(action); - } - return action; - } catch (Exception e) { - throw new IllegalStateException("could not init the action " + actionClass + " for reason : " + e.getMessage()); - } - } - - private H handler; - - public abstract AbstractButton getHelp(); - - public abstract Object getObjectById(java.lang.String s); - - protected DialogUI() { - UIHelper.setQuitAction(this); - addWindowListener(this); - //TODO will be handled by jaxx with javax.help... - //getHelp().setAction(newAction(HelpAction.class)); - } - - public H getHandler() { - return handler; - } - - public void setHandler(H handler) { - this.handler = handler; - } - - protected ImageIcon createActionIcon(String name) { - return UIHelper.createActionIcon(name); - } - - public void windowOpened(WindowEvent e) { - } - - public void windowClosed(WindowEvent e) { - } - - public void windowClosing(WindowEvent e) { - } - - public void windowIconified(WindowEvent e) { - } - - public void windowDeiconified(WindowEvent e) { - } - - public void windowActivated(WindowEvent e) { - } - - public void windowDeactivated(WindowEvent e) { - } - - @Override - public synchronized void addWindowListener(WindowListener l) { - super.addWindowListener(l); - if (log.isDebugEnabled()) { - log.debug("after added (" + getWindowListeners().length + ") : " + l); - } - } - - @Override - public synchronized void removeWindowListener(WindowListener l) { - super.removeWindowListener(l); - if (log.isDebugEnabled()) { - log.debug("after removed (" + getWindowListeners().length + ") : " + l); - } - } -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIDef.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,235 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import static org.codelutin.i18n.I18n._; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.ImageIcon; -import java.lang.reflect.Constructor; - -/** - * Definition of an ui, with his model, handler and ui class definitions. - * <p/> - * The class contains also a shared instace of concrete ui. - * - * @author chemit - */ -public class DialogUIDef<M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> implements java.io.Serializable { - - static protected final Log log = LogFactory.getLog(DialogUIDef.class); - - public static <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> DialogUIDef<M, U, H> newDef(Class<H> handlerClass, Class<U> uiClass, Class<M> modelClass, String showActionLibelle, String showActionTip, String uiTitle) { - DialogUIDef<M, U, H> result; - result = new DialogUIDef<M, U, H>(handlerClass, uiClass, modelClass, showActionLibelle, showActionTip, uiTitle); - return result; - } - - /** - * model class - */ - private final Class<M> modelClass; - - /** - * handler class - */ - private final Class<H> handlerClass; - - /** - * abstract ui class - */ - private final Class<U> uiClass; - - /** - * concrete lookup ui class - */ - private Class<? extends U> uiImplClass; - - /** - * shared instance of ui - */ - protected U uiInstance; - - /** - * unique name of ui def - */ - protected final String name; - - protected final String uiTitle; - protected final String showActionLibelle; - protected final String showActionTip; - - protected ImageIcon showUIActionIcon; - - - private static final long serialVersionUID = 1L; - - private DialogUIDef(Class<H> handlerClass, Class<U> uiClass, Class<M> modelClass, - String showActionLibelle, String showActionTip, String uiTitle) { - this.handlerClass = handlerClass; - this.uiClass = uiClass; - this.modelClass = modelClass; - this.showActionLibelle = showActionLibelle; - this.name = uiClass.getSimpleName().toLowerCase(); - this.showActionTip = showActionTip; - this.uiTitle = uiTitle; - } - - public Class<U> getUiClass() { - return uiClass; - } - - public Class<H> getHandlerClass() { - return handlerClass; - } - - public Class<M> getModelClass() { - return modelClass; - } - - public Class<? extends U> getUiImplClass() { - return uiImplClass; - } - - public String getUiTitle() { - return _(uiTitle); - } - - public String getShowActionLibelle() { - return _(showActionLibelle); - } - - public String getShowActionTip() { - return _(showActionTip); - } - - public ImageIcon getShowUIActionIcon() { - if (showUIActionIcon == null) { - showUIActionIcon = UIHelper.createActionIcon("show-" + name); - } - return showUIActionIcon; - } - - @SuppressWarnings({"unchecked"}) - public void setUiImplClass(Class<?> uiImplClass) { - this.uiImplClass = (Class<? extends U>) uiImplClass; - } - - @Override - public boolean equals(Object o) { - return this == o || o instanceof DialogUIDef && uiClass.equals(((DialogUIDef) o).uiClass); - } - - @Override - public int hashCode() { - return uiClass.hashCode(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(super.toString()).append('<'); - sb.append(printClass("handler", handlerClass, true)); - sb.append(printClass("model", modelClass, true)); - sb.append(printClass("ui", uiClass, true)); - sb.append(printClass("uiImpl", uiImplClass, false)); - return sb.toString(); - } - - protected U getUiInstance() { - // no lazy instanciation, to control ui instanciation... - /*if (uiInstance == null) { - if (uiImplClass == null) { - throw new IllegalStateException("no concrete ui impl found in " + this); - } - synchronized (this) { - try { - uiInstance = uiImplClass.newInstance(); - } catch (Exception e) { - throw new IllegalStateException("could not instanciate ui " + this,e); - } - } - }*/ - return uiInstance; - } - - protected void setUiInstance(U uiInstance) { - this.uiInstance = uiInstance; - } - - protected U newUI() { - if (uiImplClass == null) { - throw new IllegalStateException("no concrete ui impl found in " + this); - } - try { - U result = uiImplClass.newInstance(); - log.info(result); - return result; - } catch (Exception e) { - throw new IllegalStateException("could not instanciate ui " + this, e); - } - } - - protected M newModel() { - if (modelClass == null) { - throw new IllegalStateException("no model impl found in " + this); - } - try { - M model = modelClass.newInstance(); - log.info(model); - return model; - } catch (Exception e) { - throw new IllegalStateException("could not instanciate ui " + this, e); - } - } - - protected H newHandler(U ui, M model, Object... params) { - if (handlerClass == null) { - throw new IllegalStateException("no handler impl found in " + this); - } - try { - Class[] prototype = getHandlerPrototype(params); - Object[] parameters = getHandlerParameters(ui, model, params); - H result = handlerClass.getConstructor(prototype).newInstance(parameters); - log.info(result); - return result; - } catch (Exception e) { - throw new IllegalStateException("could not instanciate ui " + this, e); - } - } - - protected Object[] getHandlerParameters(U ui, M model, Object[] params) { - Object[] result = new Object[2 + params.length]; - result[0] = ui; - result[1] = model; - System.arraycopy(params, 0, result, 2, params.length); - return result; - } - - protected Class[] getHandlerPrototype(Object[] params) { - int length = params.length; - for (Constructor<?> constructor : handlerClass.getConstructors()) { - Class<?>[] prototype = constructor.getParameterTypes(); - if (prototype.length == 2 + length && prototype[0] == uiClass && prototype[1] == modelClass) { - return prototype; - } - } - throw new IllegalStateException("could not find a matching constructor in " + handlerClass); - } - - protected String printClass(String s, Class<?> aClass, boolean notLast) { - return s + ':' + (aClass == null ? null : aClass.getSimpleName()) + (notLast ? ", " : ">"); - } -} Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIHandler.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,70 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.awt.event.WindowListener; -import java.beans.PropertyChangeListener; - -/** - * DialogUI handler - * - * @author chemit - */ -public abstract class DialogUIHandler<M extends DialogUIModel, U extends DialogUI<? extends DialogUIHandler>> implements PropertyChangeListener { - - protected static Log log = LogFactory.getLog(DialogUIHandler.class); - - /** ui handled */ - private U ui; - - /** model handled */ - private M model; - - protected DialogUIHandler(U ui, M model) { - this.ui = ui; - this.model = model; - } - - public U getUi() { - return ui; - } - - public M getModel() { - return model; - } - - public void init() { - if (model == null) { - throw new IllegalStateException("no model was defined for " + this); - } - model.addPropertyChangeListener(this); - } - - public void dispose() { - model.dispose(); - for (WindowListener windowListener : getUi().getWindowListeners()) { - getUi().removeWindowListener(windowListener); - } - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - dispose(); - } -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/DialogUIModel.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,97 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; - -/** - * Abstract ui model, with property change support. - * - * @author chemit - */ -public abstract class DialogUIModel { - - static protected final Log log = LogFactory.getLog(DialogUIModel.class); - - /** support for change properties support */ - protected PropertyChangeSupport changeSupport; - - public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - if (listener == null) { - return; - } - if (changeSupport == null) { - changeSupport = new PropertyChangeSupport(this); - } - changeSupport.addPropertyChangeListener(propertyName, listener); - } - - public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { - if (listener == null) { - return; - } - if (changeSupport == null) { - changeSupport = new PropertyChangeSupport(this); - } - changeSupport.addPropertyChangeListener(listener); - } - - public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { - if (listener == null || changeSupport == null) { - return; - } - changeSupport.removePropertyChangeListener(listener); - } - - public synchronized void removePropertyChangeListeners() { - if (changeSupport == null) { - return; - } - for (PropertyChangeListener listener : getPropertyChangeListeners()) { - changeSupport.removePropertyChangeListener(listener); - } - } - - public synchronized PropertyChangeListener[] getPropertyChangeListeners() { - if (changeSupport == null) { - return new PropertyChangeListener[0]; - } - return changeSupport.getPropertyChangeListeners(); - } - - public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - if (changeSupport == null || (oldValue == null && newValue == null) || - (oldValue != null && oldValue.equals(newValue))) { - return; - } - changeSupport.firePropertyChange(propertyName, oldValue, newValue); - } - - public void dispose() { - for (PropertyChangeListener listener : changeSupport.getPropertyChangeListeners()) { - changeSupport.removePropertyChangeListener(listener); - } - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - dispose(); - } -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FactoryWindowListener.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,84 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -/** - * A windowListenr for ui managed by {@link org.codelutin.jaxx.util.UIFactory}. - * <p/> - * To be used when all ui from factory are closed, via {@link #allWindowsClosed(java.awt.event.WindowEvent)} method. - * - * @author chemit - */ -public abstract class FactoryWindowListener extends WindowAdapter { - - /** - * method to be invoked when all ui registred in factory are really disposed. - * - * @param e event - */ - public abstract void allWindowsClosed(WindowEvent e); - - /** underlying factory of ui */ - private UIFactory factory; - - /** flag to make sure {@link #allWindowsClosed(java.awt.event.WindowEvent)} is called only once. */ - private boolean wasClosed; - - @Override - public void windowClosed(WindowEvent e) { - if (UIFactory.log.isDebugEnabled()) { - UIFactory.log.debug(this + " : " + e); - } - if (e.getWindow().isVisible()) { - // only deal with real closed and none visible windows... - return; - } - for (DialogUIDef def : factory.getDefs()) { - DialogUI ui = def.uiInstance; - if (ui != null && ui.isVisible()) { - // at least one ui visible, do not close all - return; - } - } - - if (wasClosed) { - // make sure to process only once - return; - } - if (UIFactory.log.isInfoEnabled()) { - UIFactory.log.info("closing factory listener " + this); - } - - synchronized (this) { - try { - allWindowsClosed(e); - } finally { - wasClosed = true; - factory.removeFactoryWindowListener(this); - } - } - } - - protected UIFactory getFactory() { - return factory; - } - - protected void setFactory(UIFactory factory) { - this.factory = factory; - } -} Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FormElement.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FormElement.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/FormElement.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,29 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -/** @author chemit */ -public interface FormElement<U extends DialogUI> { - - String name(); - - int ordinal(); - - Object getValue(U ui); - - void setValue(U ui, String value); - - javax.swing.JLabel getLabel(U ui); -} Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/ShowUIAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,135 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.awt.Dimension; -import java.awt.Point; -import java.awt.event.ActionEvent; - -/** @author chemit */ -public abstract class ShowUIAction<M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> extends javax.swing.AbstractAction { - - protected static Log log = LogFactory.getLog(AbstractUIAction.class); - - protected transient DialogUI<?> ui; - - private static final long serialVersionUID = 1L; - - protected DialogUIDef<M, U, H> uiDef; - - protected transient UIFactory factory; - - protected String position; - - protected boolean undecorated = true; - - protected U initUI(ActionEvent e) { - return getFactory().getUI(uiDef); - } - - public ShowUIAction(DialogUI<?> ui, DialogUIDef<M, U, H> uiDef, UIFactory factory, boolean showText) { - super(uiDef.getShowActionLibelle(), uiDef.getShowUIActionIcon()); - this.ui = ui; - this.uiDef = uiDef; - String name = (String) getValue(NAME); - putValue(DISPLAYED_MNEMONIC_INDEX_KEY, name.length() - 1); - putValue(ACCELERATOR_KEY, (int) name.charAt(name.length() - 1)); - if (!showText) { - putValue(NAME, null); - } - putValue(SHORT_DESCRIPTION, uiDef.getShowActionTip()); - this.factory = factory; - } - - public DialogUI<?> getUi() { - return ui; - } - - public DialogUIDef<M, U, H> getUiDef() { - return uiDef; - } - - public UIFactory getFactory() { - return factory; - } - - public void setUiDef(DialogUIDef<M, U, H> uiDef) { - this.uiDef = uiDef; - } - - public void setPosition(String position) { - this.position = position; - } - - public void setUndecorated(boolean undecorated) { - this.undecorated = undecorated; - } - - public void actionPerformed(java.awt.event.ActionEvent e) { - checkInit(); - U ui = initUI(e); - ui.setTitle(uiDef.getUiTitle()); - log.info(ui.getTitle()); - //TODO ui.setUndecorated(undecorated); - setPosition(this.getUi(), ui, position); - - ui.setVisible(true); - } - - protected void setPosition(javax.swing.JDialog parentUI, javax.swing.JDialog ui, String position) { - if (position == null || parentUI == null) { - return; - } - Point parentLocation = parentUI.getLocationOnScreen(); - Dimension parentSize = parentUI.getSize(); - - if (position.equals("bottom-left")) { - int top = (int) (parentLocation.getY() + parentSize.getHeight()); - int left = (int) (parentLocation.getX()); - Point newLocation = new Point(left, top); - newLocation.setLocation(left, top); - ui.setLocation(newLocation); - return; - } - if (position.equals("top-left")) { - int top = (int) (parentLocation.getY()); - int left = (int) (parentLocation.getX()); - Point newLocation = new Point(left, top); - newLocation.setLocation(left, top); - ui.setLocation(newLocation); - return; - } - if (position.equals("top-right")) { - int top = (int) (parentLocation.getY()); - int left = (int) (parentLocation.getX() + parentSize.getWidth()); - Point newLocation = new Point(left, top); - newLocation.setLocation(left, top); - ui.setLocation(newLocation); - return; - } - if (position.equals(("center"))) { - //TODO - } - } - - protected void checkInit() throws IllegalStateException { - if (factory == null) { - throw new IllegalStateException("no factory found in " + this); - } - } -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIFactory.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIFactory.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIFactory.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,184 +0,0 @@ -/** -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.util.StringUtil; - -import javax.swing.event.EventListenerList; -import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; - -/** - * Factory for UI, using a cache and a provider to find ui implementations. - * - * @author chemit - */ -public class UIFactory { - - static protected final Log log = LogFactory.getLog(UIFactory.class); - - private final String applicationName; - - private final DialogUIDef[] defs; - - private final EventListenerList listeners; - - public UIFactory(String applicationName, DialogUIDef[] defs, FactoryWindowListener... listeners) { - this.applicationName = applicationName; - this.listeners = new EventListenerList(); - for (FactoryWindowListener listener : listeners) { - listener.setFactory(this); - addFactoryWindowListener(listener); - } - this.defs = defs; - long t0 = System.nanoTime(); - if (log.isDebugEnabled()) { - log.debug("start at " + new java.util.Date()); - } - try { - init(); - } catch (Exception e) { - log.error(e); - throw new RuntimeException(e); - } finally { - if (log.isDebugEnabled()) { - log.info("end in " + StringUtil.convertTime(t0, System.nanoTime())); - } - } - } - - public void addFactoryWindowListener(FactoryWindowListener l) { - listeners.add(FactoryWindowListener.class, l); - if (log.isDebugEnabled()) { - log.debug("after added (" + listeners.getListenerCount() + ") : " + l); - } - } - - public void removeFactoryWindowListener(FactoryWindowListener l) { - listeners.remove(FactoryWindowListener.class, l); - for (DialogUIDef def : getDefs()) { - if (def.uiInstance != null) { - def.uiInstance.removeWindowListener(l); - } - } - if (log.isDebugEnabled()) { - log.debug(" after removed (" + listeners.getListenerCount() + ") : " + l); - } - if (listeners.getListenerCount(FactoryWindowListener.class) == 0) { - // close for real factory - close(); - } - } - - public void close() { - log.info(this + " at " + new java.util.Date()); - for (DialogUIDef<?, ?, ?> def : defs) { - DialogUI<?> ui = def.uiInstance; - if (ui != null) { - ui.getHandler().dispose(); - def.uiInstance = null; - } - } - if (listeners.getListenerCount(FactoryWindowListener.class) > 0) { - log.warn("some listeners where not properly removed, force deletion..."); - for (FactoryWindowListener listener : listeners.getListeners(FactoryWindowListener.class)) { - removeFactoryWindowListener(listener); - } - } - - } - - protected void init() { - - UIProvider[] providers = detectProviders(); - - for (DialogUIDef<?, ?, ?> def : defs) { - initDef(providers, def); - if (def.getUiImplClass() == null) { - throw new IllegalStateException("could not find implementation for ui def " + def); - } - } - } - - protected void initDef(UIProvider[] providers, DialogUIDef<?, ?, ?> def) { - for (UIProvider provider : providers) { - Class<?> uiImplClass = provider.findUIImplementation(def); - if (uiImplClass != null) { - if (log.isDebugEnabled()) { - log.debug("init done for " + def); - } - // ui implementation was found - break; - } - } - } - - protected UIProvider[] detectProviders() { - long t0 = System.nanoTime(); - List<UIProvider> providers = new ArrayList<UIProvider>(); - for (UIProvider provider : ServiceLoader.load(UIProvider.class)) { - if (applicationName.equals(provider.getApplicationName())) { - if (log.isDebugEnabled()) { - log.debug("provider detected [" + provider + ']'); - } - providers.add(provider); - } - } - log.info("found " + providers.size() + " ui provider(s) in " + StringUtil.convertTime(t0, System.nanoTime()) + " : " + providers); - return providers.toArray(new UIProvider[providers.size()]); - } - - protected DialogUIDef[] getDefs() { - return defs; - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - close(); - } - - public <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> U getUI(DialogUIDef<M, U, H> uiType, Object... params) { - U ui = uiType.uiInstance; - if (ui == null) { - try { - ui = uiType.newUI(); - M model = uiType.newModel(); - H handler = uiType.newHandler(ui, model, params); - registerUI(uiType, ui, handler); - } catch (Exception e) { - throw new IllegalStateException("could not instanciate ui handler " + uiType + " for reason : " + e.getMessage(), e); - } - } - return ui; - } - - protected <M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>> void registerUI(DialogUIDef<M, U, H> uiType, U ui, H handler) { - ui.setHandler(handler); - handler.init(); - uiType.setUiInstance(ui); - for (FactoryWindowListener listener : listeners.getListeners(FactoryWindowListener.class)) { - if (log.isDebugEnabled()) { - log.debug("----- addFactoryWindowListener " + listener + " to " + ui); - } - ui.addWindowListener(listener); - } - } - -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIHelper.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIHelper.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIHelper.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,70 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package org.codelutin.jaxx.util; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JRootPane; -import javax.swing.KeyStroke; -import java.awt.event.ActionEvent; - -/** - * Ui helper class. - * - * @author tony - */ -public class UIHelper { - - public static ImageIcon createImageIcon(String path) { - java.net.URL imgURL = UIHelper.class.getResource("/icons/" + path); - if (imgURL != null) { - return new ImageIcon(imgURL); - } else { - throw new IllegalArgumentException("could not find icon " + path); - } - } - - /** - * Attach to <code>ui</code> an abort action,accessible by <code>ESC</code> key. - * - * @param ui ui - */ - public static void setQuitAction(final JDialog ui) { - JRootPane rootPane = ui.getRootPane(); - - Action quitAction = new AbstractAction("quit") { - private static final long serialVersionUID = -869095664995763057L; - - public void actionPerformed(ActionEvent e) { - ui.dispose(); - } - }; - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "quit"); - rootPane.getActionMap().put("quit", quitAction); - ui.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - } - - public static ImageIcon createActionIcon(String name) { - return createImageIcon("action-" + name + ".png"); - } - -} Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIProvider.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIProvider.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/UIProvider.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,86 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util; - -/** @author chemit */ -public abstract class UIProvider { - - /** the name of application using this provider */ - protected String applicationName; - - /** the name of ui implementation used by this provider */ - protected String providerName; - - /** array of ui implementations */ - protected Class<?>[] implementations; - - protected UIProvider(String applicationName, String providerName, Class<?>... implementations) { - this.applicationName = applicationName; - this.providerName = providerName; - this.implementations = implementations; - } - - public String getProviderName() { - return providerName; - } - - public String getApplicationName() { - return applicationName; - } - - public Class<?>[] getImplementations() { - return implementations; - } - - public Class<?> findUIImplementation(DialogUIDef<?, ?, ?> def) { - Class<? extends DialogUI<?>> uiClass = def.getUiClass(); - for (Class<?> klass : implementations) { - if (uiClass.isAssignableFrom(klass)) { - def.setUiImplClass(klass); - return klass; - } - } - return null; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(super.toString()).append('<'); - sb.append(printClass("application", applicationName, true)); - sb.append(printClass("provider", providerName, true)); - sb.append(printClass("uis", implementations.length, false)); - return sb.toString(); - } - - protected String printClass(String s, Object aClass, boolean notLast) { - return s + ':' + (aClass == null ? null : aClass) + (notLast ? ", " : ">"); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UIProvider)) return false; - - UIProvider that = (UIProvider) o; - return applicationName.equals(that.applicationName) && providerName.equals(that.providerName); - - } - - @Override - public int hashCode() { - return (31 * applicationName.hashCode()) + providerName.hashCode(); - } - -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/CancelAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,43 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util.config; - -import org.codelutin.jaxx.util.AbstractUIAction; -import org.codelutin.jaxx.util.DialogUI; -import org.codelutin.jaxx.util.UIHelper; - -import java.awt.event.ActionEvent; - -/** @author chemit */ -public class CancelAction<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends AbstractUIAction<H> { - private static final long serialVersionUID = 1L; - - public CancelAction(DialogUI<? extends H> dialogUI, boolean showLabel) { - super(null, UIHelper.createActionIcon("cancel-config"), dialogUI); - if (showLabel) { - String text = org.codelutin.i18n.I18n._("lutinui.config.cancel"); - putValue(NAME, text); - putValue(DISPLAYED_MNEMONIC_INDEX_KEY, 0); - putValue(MNEMONIC_KEY, (int) text.charAt(0)); - } - String libelle = org.codelutin.i18n.I18n._("lutinui.config.cancel.tooltip"); - putValue(SHORT_DESCRIPTION, libelle); - - } - - public void actionPerformed(ActionEvent e) { - getUi().dispose(); - } -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUI.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,105 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util.config; - -import org.codelutin.jaxx.util.DialogUI; - -import javax.swing.AbstractButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JPasswordField; -import javax.swing.JRadioButton; -import javax.swing.JTextField; - -/** - * A abstract dialog contract to be realised by a dialogUI (WindowEvent adapter) - * <p/> - * TODO : make jaxx authorized implementing interface for root tag :) - * - * @author chemit - */ -public abstract class DialogConfigUI<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends DialogUI<H> { - - public abstract AbstractButton getOk(); - - public abstract AbstractButton getReset(); - - public abstract AbstractButton getCancel(); - - public JComponent getElement(E key) { - Object id = getObjectById(key.name()); - if (id == null) { - log.error(new NullPointerException("no widget for key "+key)); - return null; - } - if (!(id instanceof JComponent)) { - throw new IllegalArgumentException(id + " is not a JComponent"); - } - return (JComponent) id; - } - - public Object getElementValue(E key) { - JComponent o = getElement(key); - if (o instanceof JPasswordField) { - return new String(((JPasswordField) o).getPassword()); - } - if (o instanceof JTextField) { - return ((JTextField) o).getText(); - } - if (o instanceof JRadioButton) { - return ((JRadioButton) o).isSelected(); - } - if (o instanceof JCheckBox) { - return ((JCheckBox) o).isSelected(); - } - - if (o instanceof JComboBox) { - return ((JComboBox) o).getSelectedItem(); - } - return ""; - } - - public void setElementValue(E key, Object value) { - JComponent o = getElement(key); - - String strValue = value == null ? "" : String.valueOf(value); - if (o instanceof JPasswordField) { - ((JPasswordField) o).setText(strValue); - } - if (o instanceof JTextField) { - ((JTextField) o).setText(strValue); - } - if (o instanceof JRadioButton) { - ((JRadioButton) o).setSelected(Boolean.valueOf(strValue.isEmpty() ? "false" : strValue)); - } - if (o instanceof JCheckBox) { - ((JCheckBox) o).setSelected(Boolean.valueOf(strValue.isEmpty() ? "false" : strValue)); - } - if (o instanceof JComboBox) { - ((JComboBox) o).setSelectedItem(value); - } - } - - public JLabel getElementLabel(E key) { - return (JLabel) getObjectById(key.name() + "Label"); - } - - public void doCheck(E key) { - getHandler().doCheck(key); - } - -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIHandler.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,156 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util.config; - -import org.codelutin.jaxx.util.DialogUIHandler; -import org.codelutin.util.ConverterUtil; -import org.codelutin.util.config.Config; -import org.codelutin.util.config.Property; - -import javax.swing.JComponent; -import java.awt.Color; -import java.beans.PropertyChangeEvent; -import java.util.EnumMap; -import java.util.EnumSet; - -/** - * DialogUI handler - * - * @author chemit - */ -public abstract class DialogConfigUIHandler<E extends Enum<E>, M extends DialogConfigUIModel<E, ?>, U extends DialogConfigUI<E, ?>> extends DialogUIHandler<M, U> { - - protected DialogConfigUIHandler(U ui, M model) { - super(ui, model); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (log.isDebugEnabled()) { - log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); - } - String action = evt.getPropertyName(); - - if (DialogConfigUIModel.CONFIG_PROPERTY_CHANGED.equals(action)) { - // update ui with model values, - populateUI(); - // revalidate form - doCheckAll(); - return; - } - - if (DialogConfigUIModel.MODIFIED_PROPERTY_CHANGED.equals(action)) { - Boolean newValue = (Boolean) evt.getNewValue(); - boolean modified = newValue != null && newValue; - getUi().getReset().setEnabled(modified); - getUi().getOk().setEnabled(modified && getModel().isConfigValid()); - return; - } - - if (DialogConfigUIModel.UNVALID_PROPERTY_CHANGED.equals(action)) { - updateUI(); - return; - } - - throw new IllegalStateException("unimplemented property changed : " + evt + " for " + this); - } - - public void doCheck(E key) { - Object uiValue = getUi().getElementValue(key); - DialogConfigUIModel<E, ?> model = getModel(); - Object currentValue = model.getCurrent().getProperty(key); - if (currentValue == null) { - currentValue = ""; - } else { - currentValue = String.valueOf(currentValue); - } - - model.validateProperty(key, uiValue); - model.changeModifiedState(key, uiValue, currentValue); - } - - public void doCheckAll() { - DialogConfigUIModel<E, ?> model = getModel(); - EnumSet<E> unvalids = EnumSet.noneOf(model.klass); - for (E e : model.getCheckedKeysSet()) { - Object uiValue = getUi().getElementValue(e); - if (!model.isValid(e, uiValue)) { - unvalids.add(e); - } - } - model.setUnvalids(unvalids); - unvalids.clear(); - } - - protected boolean prepareSave() { - DialogConfigUI<E, ?> ui = getUi(); - DialogConfigUIModel<E, ?> model = getModel(); - - Config<E> current = model.getCurrent(); - - if (!model.isConfigValid()) { - log.warn("do not save a unvalid config : " + model.getUnvalids()); - return false; - } - - if (!model.isModified()) { - log.warn("nothing to save"); - return false; - } - EnumSet<E> toTreate = model.getCheckedKeysSet(); - // transfert checkable values from ui to model - for (E key : model.getModifieds()) { - if (!toTreate.contains(key)) { - continue; - } - Object value = ui.getElementValue(key); - Class<?> type = ((Property) key).getType(); - Object newValue = ConverterUtil.convert(type, value); - current.setProperty(key, newValue); - } - - return true; - } - - protected void populateUI() { - U ui = getUi(); - EnumMap<E, Object> map = getModel().getCurrent().getProperties(); - for (E e : getModel().getCheckedKeysSet()) { - Object value = map.get(e); - populateUI(ui, e, value); - } - } - - protected void populateUI(U ui, E key, Object value) { - ui.setElementValue(key, value); - } - - protected void updateUI() { - EnumSet<E> unvalids = getModel().getUnvalids(); - for (E key : unvalids) { - setLabelColor(key, false); - } - for (E key : EnumSet.complementOf(unvalids)) { - setLabelColor(key, true); - } - } - - protected void setLabelColor(E key, boolean valid) { - JComponent component = getUi().getElementLabel(key); - if (component != null && component.isVisible()) { - component.setForeground(valid ? Color.black : Color.red); - } - } - -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/DialogConfigUIModel.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,220 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util.config; - -import org.codelutin.jaxx.util.DialogUIModel; -import org.codelutin.util.config.Config; - -import java.util.EnumSet; - -/** - * Abstract config ui model. - * - * @author chemit - */ -public abstract class DialogConfigUIModel<E extends Enum<E>, C extends Config<E>> extends DialogUIModel { - - public static final String CONFIG_PROPERTY_CHANGED = "config"; - public static final String MODIFIED_PROPERTY_CHANGED = "modify"; - public static final String UNVALID_PROPERTY_CHANGED = "unvalid"; - - /** @return a empty config */ - protected abstract C newConfig(); - - /** - * @param key property key - * @param value value to validate - * @return <code>true</code> if given value is valid for property, <code>false>/code> otherwise - */ - protected abstract boolean isValid(E key, Object value); - - /** - * object used to init model and save model, this is an external object. - * <p/> - * The object must have bean read-write properties for each value of E - */ - protected Object src; - - /** current config used in model */ - protected C current; - - /** set of modified properties */ - protected EnumSet<E> modifieds; - - /** set of unvalid properties */ - protected EnumSet<E> unvalids; - - /** enum class */ - protected Class<E> klass; - - /** set of key not to check */ - protected EnumSet<E> uncheckedKeys; - - /** set of all keys checkable */ - protected EnumSet<E> checkedKeysSet; - - protected DialogConfigUIModel(Class<E> klass) { - this.klass = klass; - this.current = newConfig(); - this.modifieds = EnumSet.noneOf(klass); - this.unvalids = EnumSet.noneOf(klass); - } - - public EnumSet<E> getCheckedKeysSet() { - if (checkedKeysSet == null) { - if (uncheckedKeys != null) { - checkedKeysSet = EnumSet.complementOf(uncheckedKeys); - } else { - checkedKeysSet = EnumSet.allOf(klass); - } - } - return checkedKeysSet; - } - - public Object getSrc() { - return src; - } - - public C getCurrent() { - return current; - } - - public EnumSet<E> getUnivserse() { - return getCurrent().getUniverse(); - } - - public EnumSet<E> getModifieds() { - return modifieds; - } - - public EnumSet<E> getUnvalids() { - return unvalids; - } - - public boolean isModified() { - return !modifieds.isEmpty(); - } - - public boolean isConfigValid() { - return unvalids.isEmpty(); - } - - public void populate(Object src) { - this.src = src; - this.current = newConfig(); - if (src != null) { - this.current.copyFrom(src); - } - this.modifieds.clear(); - this.unvalids.clear(); - setModified(false); - firePropertyChange(CONFIG_PROPERTY_CHANGED, null, this); - } - - public void reset() { - populate(src); - } - - public void setModified(boolean modified) { - firePropertyChange(MODIFIED_PROPERTY_CHANGED, null, modified); - } - - public void setUnvalid(boolean unvalid) { - firePropertyChange(UNVALID_PROPERTY_CHANGED, null, unvalid); - } - - public void addModified(E key) { - if (!modifieds.contains(key)) { - modifieds.add(key); - log.debug(key); - } - setModified(!modifieds.isEmpty()); - } - - public void removeModified(E key) { - - if (modifieds.contains(key)) { - modifieds.remove(key); - } - setModified(!modifieds.isEmpty()); - } - - public void removeModified(EnumSet<E> keys) { - for (E key : keys) { - if (modifieds.contains(key)) { - modifieds.remove(key); - } - } - setModified(!modifieds.isEmpty()); - } - - public void setUnvalids(EnumSet<E> keys) { - for (E key : keys) { - if (!unvalids.contains(key)) { - unvalids.add(key); - } - } - for (E key : EnumSet.complementOf(keys)) { - if (unvalids.contains(key)) { - unvalids.remove(key); - } - } - setUnvalid(!unvalids.isEmpty()); - } - - - public void addUnvalid(E key) { - if (!unvalids.contains(key)) { - unvalids.add(key); - } - setUnvalid(!unvalids.isEmpty()); - } - - public void removeUnvalid(E key) { - if (unvalids.contains(key)) { - unvalids.remove(key); - } - setUnvalid(!unvalids.isEmpty()); - } - - public void save() { - current.copyTo(src, modifieds); - modifieds.clear(); - // redisplay config - firePropertyChange(CONFIG_PROPERTY_CHANGED, null, this); - } - - public void changeModifiedState(E key, Object uiValue, Object currentValue) { - if (uiValue!=null && uiValue.equals(currentValue)) { - removeModified(key); - } else { - addModified(key); - } - } - - public void clear(E key) { - log.info(key); - modifieds.remove(key); - unvalids.remove(key); - } - - protected void validateProperty(E key, Object uiValue) { - if (isValid(key, uiValue)) { - removeUnvalid(key); - } else { - addUnvalid(key); - } - } -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/ResetAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,43 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util.config; - -import org.codelutin.jaxx.util.AbstractUIAction; -import org.codelutin.jaxx.util.DialogUI; -import org.codelutin.jaxx.util.UIHelper; - -import java.awt.event.ActionEvent; - -/** @author chemit */ -public class ResetAction<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends AbstractUIAction<H> { - private static final long serialVersionUID = 1L; - - public ResetAction(DialogUI<? extends H> dialogUI, boolean showLabel) { - super(null, UIHelper.createActionIcon("reset-config"), dialogUI); - if (showLabel) { - String text = org.codelutin.i18n.I18n._("lutinui.config.reset"); - putValue(NAME, text); - putValue(DISPLAYED_MNEMONIC_INDEX_KEY, 0); - putValue(MNEMONIC_KEY, (int) text.charAt(0)); - } - String libelle = org.codelutin.i18n.I18n._("lutinui.config.reset.tooltip"); - putValue(SHORT_DESCRIPTION, libelle); - - } - - public void actionPerformed(ActionEvent e) { - getHandler().getModel().reset(); - } -} \ No newline at end of file Deleted: jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java =================================================================== --- jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/jaxx-util/src/main/java/org/codelutin/jaxx/util/config/SaveAction.java 2009-02-23 13:06:52 UTC (rev 1241) @@ -1,50 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.jaxx.util.config; - -import org.codelutin.jaxx.util.AbstractUIAction; -import org.codelutin.jaxx.util.DialogUI; -import org.codelutin.jaxx.util.UIHelper; - -import java.awt.event.ActionEvent; - -/** @author chemit */ -public class SaveAction<E extends Enum<E>, H extends DialogConfigUIHandler<E, ?, ?>> extends AbstractUIAction<H> { - private static final long serialVersionUID = 1L; - - public SaveAction(DialogUI<? extends H> dialogUI, boolean showLabel) { - super(null, UIHelper.createActionIcon("save-config"), dialogUI); - if (showLabel) { - String text = org.codelutin.i18n.I18n._("lutinui.config.save"); - putValue(NAME, text); - putValue(DISPLAYED_MNEMONIC_INDEX_KEY, 0); - putValue(MNEMONIC_KEY, (int) text.charAt(0)); - } - String libelle = org.codelutin.i18n.I18n._("lutinui.config.save.tooltip"); - putValue(SHORT_DESCRIPTION, libelle); - } - - public void actionPerformed(ActionEvent e) { - - if (getHandler().prepareSave()) { - - // save model to src - getHandler().getModel().save(); - - // close ui - getUi().dispose(); - } - } -} Modified: jaxx/trunk/pom.xml =================================================================== --- jaxx/trunk/pom.xml 2009-02-23 13:06:47 UTC (rev 1240) +++ jaxx/trunk/pom.xml 2009-02-23 13:06:52 UTC (rev 1241) @@ -18,7 +18,6 @@ <version>1.2-SNAPSHOT</version> <modules> - <module>jaxx-util</module> <module>jaxx-runtime-api</module> <module>jaxx-runtime-swing</module> <module>jaxx-runtime-validator</module>
participants (1)
-
tchemit@users.labs.libre-entreprise.org