Author: tchemit Date: 2008-04-16 20:57:35 +0000 (Wed, 16 Apr 2008) New Revision: 529 Added: trunk/jaxx/src/main/java/jaxx/DialogUI.java trunk/jaxx/src/main/java/jaxx/DialogUIHandler.java trunk/jaxx/src/main/java/jaxx/DialogUIModel.java Modified: trunk/jaxx/changelog Log: add methods Modified: trunk/jaxx/changelog =================================================================== --- trunk/jaxx/changelog 2008-04-16 20:56:45 UTC (rev 528) +++ trunk/jaxx/changelog 2008-04-16 20:57:35 UTC (rev 529) @@ -1,3 +1,5 @@ +ver-1-0-6 chemit add dialogUI mini-framework 04-2008 + ver-1-0-5 chemit clean code, migrate to java 1.5 01-2008 ver-1-0-4 chemit initial import from project jaxx-1.0.3-beta2 (svn:sourceforce rev 48) 01-2008 Added: trunk/jaxx/src/main/java/jaxx/DialogUI.java =================================================================== --- trunk/jaxx/src/main/java/jaxx/DialogUI.java (rev 0) +++ trunk/jaxx/src/main/java/jaxx/DialogUI.java 2008-04-16 20:57:35 UTC (rev 529) @@ -0,0 +1,79 @@ +/** + * ##% 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 jaxx; + +import jaxx.runtime.UIHelper; + +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; + +/** + * 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 { + + private H handler; + + public abstract AbstractButton getHelp(); + + //TODO will be handled by jaxx with javax.help... + protected abstract AbstractAction createHelpAction(); + + protected DialogUI() { + UIHelper.setQuitAction(this); + addWindowListener(this); + } + + 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) { + } +} \ No newline at end of file Added: trunk/jaxx/src/main/java/jaxx/DialogUIHandler.java =================================================================== --- trunk/jaxx/src/main/java/jaxx/DialogUIHandler.java (rev 0) +++ trunk/jaxx/src/main/java/jaxx/DialogUIHandler.java 2008-04-16 20:57:35 UTC (rev 529) @@ -0,0 +1,60 @@ +/** + * ##% 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 jaxx; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +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.removePropertyChangeListener(this); + } +} \ No newline at end of file Added: trunk/jaxx/src/main/java/jaxx/DialogUIModel.java =================================================================== --- trunk/jaxx/src/main/java/jaxx/DialogUIModel.java (rev 0) +++ trunk/jaxx/src/main/java/jaxx/DialogUIModel.java 2008-04-16 20:57:35 UTC (rev 529) @@ -0,0 +1,85 @@ +/** + * ##% 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 jaxx; + +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); + } +} \ No newline at end of file