You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by ni...@apache.org on 2001/06/21 18:26:21 UTC

cvs commit: jakarta-ant-antidote/src/java/org/apache/tools/ant/gui Antidote.java

nickdavis    01/06/21 09:26:21

  Modified:    src/java/org/apache/tools/ant/gui Antidote.java
  Log:
  add listener for startup and shutdown event which will init and un-init
  the modules
  
  Revision  Changes    Path
  1.3       +77 -5     jakarta-ant-antidote/src/java/org/apache/tools/ant/gui/Antidote.java
  
  Index: Antidote.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-antidote/src/java/org/apache/tools/ant/gui/Antidote.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Antidote.java	2001/06/04 18:56:05	1.2
  +++ Antidote.java	2001/06/21 16:26:17	1.3
  @@ -52,22 +52,40 @@
    * <http://www.apache.org/>.
    */
   package org.apache.tools.ant.gui;
  +
   import org.apache.tools.ant.gui.core.*;
  -import javax.swing.*;
  +
  +import org.apache.tools.ant.gui.event.AppStartupEvent;
  +import org.apache.tools.ant.gui.event.AppShutdownEvent;
  +import org.apache.tools.ant.gui.event.BusMember;
  +import org.apache.tools.ant.gui.event.BusFilter;
  +import org.apache.tools.ant.gui.event.EventBus;
  +
   import java.awt.BorderLayout;
   import java.awt.Dimension;
  +
   import java.lang.reflect.Constructor;
   
  +import javax.swing.*;
  +
  +import java.util.EventObject;
  +import java.util.LinkedList;
  +import java.util.List;
  +
   /**
    * The root class for the Ant GUI. Assembles all the graphical components
    * based on the configuration files.
    * 
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon Fitch 
    */
   public class Antidote extends JComponent {
       /** Source of application state data. */
       private AppContext _context = null;
  +    /** List of our modules */
  +    private LinkedList _modules = new LinkedList();
  +    /** The main menu bar */
  +    private JMenuBar _menu;
   
   	/** 
   	 * Default ctor.
  @@ -103,6 +121,10 @@
           populateModules("hidden");
           
           setPreferredSize(new Dimension(640, 480));
  +        
  +        // Listen for startup and shutdown events
  +        _context.getEventBus().addMember(
  +            EventBus.MONITORING, new EventListener());
       }
   
   
  @@ -116,14 +138,16 @@
           String[] classNames = _context.getResources().
               getStringArray(getClass(), prefix + ".modules");
   
  -        AntModule[] modules = new AntModule[classNames.length];
  +        AntModule modules[] = new AntModule[classNames.length];
   
           for(int i = 0; i < classNames.length; i++) {
               try {
                   Class type = Class.forName(classNames[i]);
   
  -                modules[i] = (AntModule) type.newInstance();
  -                modules[i].contextualize(_context);
  +                AntModule newModule = (AntModule) type.newInstance();
  +                newModule.contextualize(_context);
  +                modules[i] = newModule;
  +                _modules.add(newModule);
               }
               catch(Exception ex) {
                   // XXX log me.
  @@ -144,6 +168,54 @@
           }
           else {
               return new JLabel("I shouldn't be here...");
  +        }
  +    }
  +
  +    /** Sets the main menu bar*/
  +    public void setJMenuBar(JMenuBar menu) {
  +        _menu = menu;
  +    }
  +    
  +    /** Listener for initalizing modules */
  +    private class EventListener implements BusMember {
  +        /** Event filter. */
  +        private final Filter _filter = new Filter();
  +        
  +        /** 
  +         * Get the filter to that is used to determine if an event should
  +         * to to the member.
  +         * 
  +         * @return Filter to use.
  +         */
  +        public BusFilter getBusFilter() {
  +            return _filter;
  +        }
  +
  +        /** 
  +         * Called when an event is to be posed to the member.
  +         * 
  +         * @param event Event to post.
  +         * @return true if event should be propogated, false if
  +         * it should be cancelled.
  +         */
  +        public boolean eventPosted(EventObject event) {
  +            if (event instanceof AppStartupEvent) {
  +                for(int i = 0; i < _modules.size(); i++) {
  +                    AntModule module = (AntModule) _modules.get(i);
  +                    module.insertInto(_menu);
  +                }
  +            }
  +            if (event instanceof AppShutdownEvent) {
  +            }
  +            return true;
  +        }
  +    }
  +
  +    /** Filter for startup and shutdown events. */
  +    private static class Filter implements BusFilter {
  +        public boolean accept(EventObject event) {
  +            return (event instanceof AppStartupEvent ||
  +                event instanceof AppShutdownEvent );
           }
       }
   }