001    package net.sourceforge.mp3dings.editors.imageeditor;
002    
003    /*
004    Copyright (C) 2007 Moritz Ringler
005    This library is free software; you can redistribute it and/or
006    modify it under the terms of the GNU Lesser General Public
007    License as published by the Free Software Foundation; either
008    version 2.1 of the License, or (at your option) any later version.
009    This library is distributed in the hope that it will be useful,
010    but WITHOUT ANY WARRANTY; without even the implied warranty of
011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012    Lesser General Public License for more details.
013    You should have received a copy of the GNU Lesser General Public
014    License along with this library; if not, write to the Free Software
015    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
016    */
017    
018    import java.awt.Component;
019    import java.awt.event.ActionListener;
020    import java.awt.event.ActionEvent;
021    import java.util.ArrayList;
022    import java.util.Iterator;
023    import java.util.List;
024    import net.sourceforge.mp3dings.editors.APICImageEditor;
025    
026    public abstract class AbstractImageComponent implements ImageComponent{
027        public List aiclisteners = new ArrayList();
028    
029        public void addActionListener(ActionListener al){
030            aiclisteners.add(al);
031        }
032    
033        public void removeActionListener(ActionListener al){
034            aiclisteners.remove(al);
035        }
036    
037        public ActionListener[] getActionListeners(){
038            return (ActionListener[]) aiclisteners.toArray(new ActionListener[0]);
039        }
040    
041        /** Returns true. If your component loads synchronously you can use
042        {@link #asImageComponent} instead of extending this class.
043        **/
044        public boolean loadsAsynchronously(){
045            return true;
046        }
047    
048        protected void fireActionImageChanged(){
049            fireActionPerformed(APICImageEditor.ACTION_IMAGE_CHANGED);
050        }
051    
052        protected void fireActionPerformed(ActionEvent e){
053            Iterator it = aiclisteners.iterator();
054            while(it.hasNext()){
055                ((ActionListener) it.next()).actionPerformed(e);
056            }
057        }
058    
059        protected void fireActionPerformed(String actionCommand){
060            ActionEvent e = new ActionEvent(this, ActionEvent.RESERVED_ID_MAX + 1, actionCommand);
061            fireActionPerformed(e);
062        }
063    }