ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meta...@apache.org
Subject cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui/core ActionManager.java AntAction.java AppContext.java ResourceManager.java
Date Thu, 04 Jan 2001 21:11:14 GMT
metasim     01/01/04 13:11:14

  Modified:    src/antidote/org/apache/tools/ant/gui/core
                        ActionManager.java AntAction.java AppContext.java
                        ResourceManager.java
  Log:
  Fixed resource problems, and changed mechanism by which resources are passed to
  the actions.
  
  Revision  Changes    Path
  1.3       +9 -10     jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ActionManager.java
  
  Index: ActionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ActionManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ActionManager.java	2001/01/03 14:18:20	1.2
  +++ ActionManager.java	2001/01/04 21:11:12	1.3
  @@ -63,16 +63,15 @@
    * Manager of antidote actions. Receives its configuration from the action
    * ResourceBundle.
    * 
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon Fitch 
    */
   public class ActionManager {
       /** Parameters for the Command constructor. */
       private static final Class[] COMMAND_CTOR_PARAMS = { AppContext.class };
   
  -    private  ResourceBundle _resources = 
  -        ResourceBundle.getBundle(
  -            "org.apache.tools.ant.gui.resources.action");
  +    /** Externalized resources. */
  +    private ResourceManager _resources = null;
   
       /** Array of action identifiers. */
       private String[] _actionIDs = null;
  @@ -91,22 +90,22 @@
   	 * Standard ctor.
   	 * 
   	 * @param bus Event bus to post events to.
  +     * @param resources Location of resources.
   	 */
  -    public ActionManager(EventBus bus) {
  +    public ActionManager(EventBus bus, ResourceManager resources) {
           _bus = bus;
  +        _resources = resources;
           bus.addMember(EventBus.RESPONDING, new Enabler());
   
           _mapper = new EventToActionMapper();
   
           // Configure the set of actions.
  -        String toTok = _resources.getString("actions");
  -        StringTokenizer tok = new StringTokenizer(toTok, ", ");
  -        _actionIDs = new String[tok.countTokens()];
  +        String[] names = _resources.getStringArray("actions");
  +        _actionIDs = new String[names.length];
           for(int i = 0; i < _actionIDs.length; i++) {
  -            _actionIDs[i] = tok.nextToken();
  +            _actionIDs[i] = names[i];
               AntAction action = new AntAction(_resources, _bus, _actionIDs[i]);
               _actions.put(_actionIDs[i], action);
  -                         
   
               // For each action we need to add the reverse event trigger
               // lookup.
  
  
  
  1.3       +4 -14     jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/AntAction.java
  
  Index: AntAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/AntAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AntAction.java	2001/01/03 14:18:20	1.2
  +++ AntAction.java	2001/01/04 21:11:12	1.3
  @@ -64,7 +64,7 @@
   /**
    * Class representing an action in the Antidote application. 
    * 
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon Fitch 
    */
   public class AntAction extends AbstractAction {
  @@ -79,7 +79,7 @@
       public static final String COMMAND = "command";
   
       /** Property resources. */
  -    private  ResourceBundle _resources =  null;
  +    private  ResourceManager _resources =  null;
       /** Event bus. */
       private EventBus _bus = null;
       /** Unique id. */
  @@ -100,7 +100,7 @@
        * 
        * @param id Unique id for the action
        */
  -    public AntAction(ResourceBundle resources, EventBus bus, String id) {
  +    public AntAction(ResourceManager resources, EventBus bus, String id) {
           _resources = resources;
           _bus = bus;
           _id = id;
  @@ -144,17 +144,7 @@
           // Add an icon if any (which means it'll show up on the tool bar).
           String iconName = getString("icon");
           if(iconName != null) {
  -            try {
  -                URL imageLoc = 
  -                    AntAction.class.getResource("resources/" + iconName);
  -                if(imageLoc != null) {
  -                    putValue(SMALL_ICON, new ImageIcon(imageLoc));
  -                }
  -            }
  -            catch(Exception ex) {
  -                // XXX log me.
  -                ex.printStackTrace();
  -            }
  +            putValue(SMALL_ICON, _resources.loadImageIcon(iconName));
           }
   
           _enableOn = resolveClasses(getString(ENABLE_ON));
  
  
  
  1.3       +15 -2     jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/AppContext.java
  
  Index: AppContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/AppContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AppContext.java	2001/01/03 14:18:20	1.2
  +++ AppContext.java	2001/01/04 21:11:13	1.3
  @@ -61,7 +61,7 @@
    * A container for the state information for the application. Provides
    * a centeralized place to gain access to resources and data.
    * 
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon Fitch 
    */
   public class AppContext {
  @@ -69,8 +69,12 @@
       private EventBus _eventBus = new EventBus();
       /** Application resources. */
       private ResourceManager _resources = new ResourceManager();
  +    /** The project manager. */
  +    private ProjectManager _projectManager = new ProjectManager();
       /** Application actions. */
  -    private ActionManager _actions = new ActionManager(_eventBus);
  +    private ActionManager _actions = 
  +        new ActionManager(_eventBus, new ResourceManager(
  +            "org.apache.tools.ant.gui.resources.action"));
       /** List of build listeners to register when build starts. */
       private List _buildListeners = new LinkedList();
   
  @@ -123,6 +127,15 @@
   	 */
       public Frame getParentFrame() {
           return _parentFrame;
  +    }
  +
  +    /** 
  +     * Get the project manager.
  +     * 
  +     * @return Project manager.
  +     */
  +    public ProjectManager getProjectManager() {
  +        return _projectManager;
       }
   
   	/** 
  
  
  
  1.3       +43 -10    jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java
  
  Index: ResourceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResourceManager.java	2001/01/03 14:18:20	1.2
  +++ ResourceManager.java	2001/01/04 21:11:13	1.3
  @@ -63,7 +63,7 @@
    * Singleton class for accessing various resources by the application.
    * Relies on the resource bundles for resource values.
    *
  - * @version $Revision: 1.2 $ 
  + * @version $Revision: 1.3 $ 
    * @author Simeon H.K. Fitch 
    */
   public class ResourceManager {
  @@ -77,7 +77,7 @@
   
       /** Image path. */
       private static final String IMG_PATH = 
  -        "/" + RESOURCE_PKG.replace('.', '/');
  +        File.separator + RESOURCE_PKG.replace('.', File.separatorChar);
   
       /** Resources to reference. */
       private ResourceBundle _resources = null;
  @@ -100,6 +100,16 @@
       }
   
       /** 
  +     * Get non-qualified String resource.
  +     * 
  +     * @param name Name of the resource.
  +     * @return Value of the resource.
  +     */
  +    public String getString(String name) {
  +        return getString(null, name);
  +    }
  +
  +    /** 
        * Get a string resource for the given class.
        * 
        * @param clazz Class to get resource for.
  @@ -107,7 +117,7 @@
        * @return String resource for the given class.
        */
       public String getString(Class clazz, String name) {
  -        if(clazz == null || name == null) {
  +        if(name == null) {
               return null;
           }
   
  @@ -115,6 +125,15 @@
       }
   
       /** 
  +     * Get a non-qualified array of string resources for the given class.
  +     * 
  +     * @param name Name of the string resource.
  +     * @return Array of string resources for the given class.
  +     */
  +    public String[] getStringArray(String name) {
  +        return getStringArray(null, name);
  +    }
  +    /** 
        * Get an array of string resources for the given class.
        * 
        * @param clazz Class to get resource for.
  @@ -122,7 +141,7 @@
        * @return Array of string resources for the given class.
        */
       public String[] getStringArray(Class clazz, String name) {
  -        if(clazz == null || name == null) {
  +        if(name == null) {
               return null;
           }
   
  @@ -157,7 +176,21 @@
        * @return Composite key.
        */
       private String getKey(Class clazz, String name) {
  -        return clazz.getName() + "." + name;
  +        name = name == null ? "" : name;
  +
  +        return clazz == null ? name : clazz.getName() + "." + name;
  +    }
  +
  +    /** 
  +     * Generate a localized message using the given set of arguments to 
  +     * format the message with.
  +     * 
  +     * @param name Name of the message.
  +     * @param arguments Arguments to the message.
  +     * @return The formatted message.
  +     */
  +    public String getMessage(String name, Object[] arguments) {
  +        return getMessage(null, name, arguments);
       }
   
       /** 
  @@ -165,9 +198,9 @@
        * format the message with.
        * 
        * @param clazz Class to get message resource for.
  -     * @param name 
  -     * @param arguments 
  -     * @return 
  +     * @param name Name of the message.
  +     * @param arguments Arguments to the message.
  +     * @return The formatted message.
        */
       public String getMessage(Class clazz, String name, Object[] arguments) {
           String format = getString(clazz, name);
  @@ -183,7 +216,7 @@
        * @return Image as an ImageIcon, or null if not found.
        */
       public ImageIcon getImageIcon(Class clazz, String key) {
  -        return getImageIcon(getString(clazz, key));
  +        return loadImageIcon(getString(clazz, key));
       }
   
       /** 
  @@ -193,7 +226,7 @@
        * @param fileName Image file to load.
        * @return Image as an ImageIcon, or null if not found.
        */
  -    public ImageIcon getImageIcon(String fileName) {
  +    public ImageIcon loadImageIcon(String fileName) {
           if(fileName == null) return null;
   
           ImageIcon icon = null;
  
  
  

Mime
View raw message