Browse Source

Fixed resource problems, and changed mechanism by which resources are passed to

the actions.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268403 13f79535-47bb-0310-9956-ffa450edef68
master
metasim 24 years ago
parent
commit
1cf34e1094
9 changed files with 122 additions and 45 deletions
  1. +22
    -5
      src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java
  2. +26
    -1
      src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java
  3. +8
    -9
      src/antidote/org/apache/tools/ant/gui/core/ActionManager.java
  4. +3
    -13
      src/antidote/org/apache/tools/ant/gui/core/AntAction.java
  5. +14
    -1
      src/antidote/org/apache/tools/ant/gui/core/AppContext.java
  6. +42
    -9
      src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java
  7. +1
    -1
      src/antidote/org/apache/tools/ant/gui/modules/console/BuildConsole.java
  8. +1
    -1
      src/antidote/org/apache/tools/ant/gui/modules/console/LogLevelEnum.java
  9. +5
    -5
      src/antidote/org/apache/tools/ant/gui/resources/antidote.properties

+ 22
- 5
src/antidote/org/apache/tools/ant/gui/acs/ACSFactory.java View File

@@ -54,8 +54,9 @@
package org.apache.tools.ant.gui.acs; package org.apache.tools.ant.gui.acs;


import javax.xml.parsers.*; import javax.xml.parsers.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.File;
import java.net.URL;
import org.w3c.dom.*; import org.w3c.dom.*;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.sun.xml.parser.Parser; import com.sun.xml.parser.Parser;
@@ -113,14 +114,26 @@ public class ACSFactory {


} }



/** /**
* Load a project from the given XML file. * Load a project from the given XML file.
* XXX fix me. * XXX fix me.
* *
* @param f File to load.
* @return
* @param location Location of the file.
* @return Loaded project.
*/ */
public ACSProjectElement load(File f) throws IOException, SAXException {
public ACSProjectElement load(File location) throws IOException {
return load(new URL("file", null, location.getPath()));
}

/**
* Load a project from the given XML file.
* XXX fix me.
*
* @param location Location of the file.
* @return Loaded project.
*/
public ACSProjectElement load(URL location) throws IOException {
XmlDocument doc = null; XmlDocument doc = null;


try { try {
@@ -137,7 +150,7 @@ public class ACSFactory {
parser.setEntityResolver(new Resolver()); parser.setEntityResolver(new Resolver());
//parser.setErrorHandler(); //parser.setErrorHandler();


sax.parse(f, null);
sax.parse(location.openStream(), null);


doc = builder.getDocument(); doc = builder.getDocument();


@@ -146,6 +159,10 @@ public class ACSFactory {
ex.printStackTrace(); ex.printStackTrace();
throw new IOException(ex.getMessage()); throw new IOException(ex.getMessage());
} }
catch(SAXException ex) {
ex.printStackTrace();
throw new IOException(ex.getMessage());
}


return (ACSProjectElement) doc.getDocumentElement(); return (ACSProjectElement) doc.getDocumentElement();
} }


+ 26
- 1
src/antidote/org/apache/tools/ant/gui/acs/ACSProjectElement.java View File

@@ -54,6 +54,7 @@
package org.apache.tools.ant.gui.acs; package org.apache.tools.ant.gui.acs;


import com.sun.xml.tree.ElementNode; import com.sun.xml.tree.ElementNode;
import java.net.URL;


/** /**
* Class representing a project element in the build file. * Class representing a project element in the build file.
@@ -66,7 +67,10 @@ public class ACSProjectElement extends ACSNamedElement {
public static final String DEFAULT = "default"; public static final String DEFAULT = "default";
/** The 'basdir' property name. */ /** The 'basdir' property name. */
public static final String BASEDIR = "basedir"; public static final String BASEDIR = "basedir";

/** Property name of the persistence location. */
public static final String LOCATION = "location";
/** The location where this project is persisted. */
private URL _location = null;


/** /**
* Default ctor. * Default ctor.
@@ -124,4 +128,25 @@ public class ACSProjectElement extends ACSNamedElement {
firePropertyChange(BASEDIR, old, baseDir); firePropertyChange(BASEDIR, old, baseDir);
} }


/**
* Get the location where this project is persisted.
*
* @return Saved location, or null if not persisted.
*/
public URL getLocation() {
return _location;
}

/**
* Set the loction where the project is persisted.
*
* @param location Location of project.
*/
public void setLocation(URL location) {
URL old = _location;
_location = location;
firePropertyChange(LOCATION, old, _location);
}


} }

+ 8
- 9
src/antidote/org/apache/tools/ant/gui/core/ActionManager.java View File

@@ -70,9 +70,8 @@ public class ActionManager {
/** Parameters for the Command constructor. */ /** Parameters for the Command constructor. */
private static final Class[] COMMAND_CTOR_PARAMS = { AppContext.class }; 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. */ /** Array of action identifiers. */
private String[] _actionIDs = null; private String[] _actionIDs = null;
@@ -91,22 +90,22 @@ public class ActionManager {
* Standard ctor. * Standard ctor.
* *
* @param bus Event bus to post events to. * @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; _bus = bus;
_resources = resources;
bus.addMember(EventBus.RESPONDING, new Enabler()); bus.addMember(EventBus.RESPONDING, new Enabler());


_mapper = new EventToActionMapper(); _mapper = new EventToActionMapper();


// Configure the set of actions. // 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++) { for(int i = 0; i < _actionIDs.length; i++) {
_actionIDs[i] = tok.nextToken();
_actionIDs[i] = names[i];
AntAction action = new AntAction(_resources, _bus, _actionIDs[i]); AntAction action = new AntAction(_resources, _bus, _actionIDs[i]);
_actions.put(_actionIDs[i], action); _actions.put(_actionIDs[i], action);


// For each action we need to add the reverse event trigger // For each action we need to add the reverse event trigger
// lookup. // lookup.


+ 3
- 13
src/antidote/org/apache/tools/ant/gui/core/AntAction.java View File

@@ -79,7 +79,7 @@ public class AntAction extends AbstractAction {
public static final String COMMAND = "command"; public static final String COMMAND = "command";


/** Property resources. */ /** Property resources. */
private ResourceBundle _resources = null;
private ResourceManager _resources = null;
/** Event bus. */ /** Event bus. */
private EventBus _bus = null; private EventBus _bus = null;
/** Unique id. */ /** Unique id. */
@@ -100,7 +100,7 @@ public class AntAction extends AbstractAction {
* *
* @param id Unique id for the action * @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; _resources = resources;
_bus = bus; _bus = bus;
_id = id; _id = id;
@@ -144,17 +144,7 @@ public class AntAction extends AbstractAction {
// Add an icon if any (which means it'll show up on the tool bar). // Add an icon if any (which means it'll show up on the tool bar).
String iconName = getString("icon"); String iconName = getString("icon");
if(iconName != null) { 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)); _enableOn = resolveClasses(getString(ENABLE_ON));


+ 14
- 1
src/antidote/org/apache/tools/ant/gui/core/AppContext.java View File

@@ -69,8 +69,12 @@ public class AppContext {
private EventBus _eventBus = new EventBus(); private EventBus _eventBus = new EventBus();
/** Application resources. */ /** Application resources. */
private ResourceManager _resources = new ResourceManager(); private ResourceManager _resources = new ResourceManager();
/** The project manager. */
private ProjectManager _projectManager = new ProjectManager();
/** Application actions. */ /** 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. */ /** List of build listeners to register when build starts. */
private List _buildListeners = new LinkedList(); private List _buildListeners = new LinkedList();


@@ -125,6 +129,15 @@ public class AppContext {
return _parentFrame; return _parentFrame;
} }


/**
* Get the project manager.
*
* @return Project manager.
*/
public ProjectManager getProjectManager() {
return _projectManager;
}

/** /**
* Get the current project. * Get the current project.
* *


+ 42
- 9
src/antidote/org/apache/tools/ant/gui/core/ResourceManager.java View File

@@ -77,7 +77,7 @@ public class ResourceManager {


/** Image path. */ /** Image path. */
private static final String IMG_PATH = private static final String IMG_PATH =
"/" + RESOURCE_PKG.replace('.', '/');
File.separator + RESOURCE_PKG.replace('.', File.separatorChar);


/** Resources to reference. */ /** Resources to reference. */
private ResourceBundle _resources = null; private ResourceBundle _resources = null;
@@ -99,6 +99,16 @@ public class ResourceManager {
_resources = ResourceBundle.getBundle(propName); _resources = ResourceBundle.getBundle(propName);
} }


/**
* 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. * Get a string resource for the given class.
* *
@@ -107,13 +117,22 @@ public class ResourceManager {
* @return String resource for the given class. * @return String resource for the given class.
*/ */
public String getString(Class clazz, String name) { public String getString(Class clazz, String name) {
if(clazz == null || name == null) {
if(name == null) {
return null; return null;
} }


return _resources.getString(getKey(clazz, name)); return _resources.getString(getKey(clazz, name));
} }


/**
* 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. * Get an array of string resources for the given class.
* *
@@ -122,7 +141,7 @@ public class ResourceManager {
* @return Array of string resources for the given class. * @return Array of string resources for the given class.
*/ */
public String[] getStringArray(Class clazz, String name) { public String[] getStringArray(Class clazz, String name) {
if(clazz == null || name == null) {
if(name == null) {
return null; return null;
} }


@@ -157,7 +176,21 @@ public class ResourceManager {
* @return Composite key. * @return Composite key.
*/ */
private String getKey(Class clazz, String name) { 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 @@ public class ResourceManager {
* format the message with. * format the message with.
* *
* @param clazz Class to get message resource for. * @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) { public String getMessage(Class clazz, String name, Object[] arguments) {
String format = getString(clazz, name); String format = getString(clazz, name);
@@ -183,7 +216,7 @@ public class ResourceManager {
* @return Image as an ImageIcon, or null if not found. * @return Image as an ImageIcon, or null if not found.
*/ */
public ImageIcon getImageIcon(Class clazz, String key) { public ImageIcon getImageIcon(Class clazz, String key) {
return getImageIcon(getString(clazz, key));
return loadImageIcon(getString(clazz, key));
} }


/** /**
@@ -193,7 +226,7 @@ public class ResourceManager {
* @param fileName Image file to load. * @param fileName Image file to load.
* @return Image as an ImageIcon, or null if not found. * @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; if(fileName == null) return null;


ImageIcon icon = null; ImageIcon icon = null;


+ 1
- 1
src/antidote/org/apache/tools/ant/gui/modules/console/BuildConsole.java View File

@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
package org.apache.tools.ant.gui.modules;
package org.apache.tools.ant.gui.modules.console;


import org.apache.tools.ant.gui.core.AntModule; import org.apache.tools.ant.gui.core.AntModule;
import org.apache.tools.ant.gui.core.AppContext; import org.apache.tools.ant.gui.core.AppContext;


+ 1
- 1
src/antidote/org/apache/tools/ant/gui/modules/console/LogLevelEnum.java View File

@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
package org.apache.tools.ant.gui.modules;
package org.apache.tools.ant.gui.modules.console;


/** /**
* Enumeration class of the different log levels. * Enumeration class of the different log levels.


+ 5
- 5
src/antidote/org/apache/tools/ant/gui/resources/antidote.properties View File

@@ -22,17 +22,17 @@ org.apache.tools.ant.gui.Antidote.bottom.modules=\
org.apache.tools.ant.gui.Antidote.top.modules=\ org.apache.tools.ant.gui.Antidote.top.modules=\
org.apache.tools.ant.gui.modules.TargetMonitor org.apache.tools.ant.gui.modules.TargetMonitor


org.apache.tools.ant.gui.modules.PropertyEditor.name=Properties
org.apache.tools.ant.gui.modules.edit.PropertyEditor.name=Properties


org.apache.tools.ant.gui.modules.ElementNavigator.name=Project
org.apache.tools.ant.gui.modules.ElementNavigator.popupActions=\
org.apache.tools.ant.gui.modules.edit.ElementNavigator.name=Project
org.apache.tools.ant.gui.modules.edit.ElementNavigator.popupActions=\
newTarget, newTask, newProperty newTarget, newTask, newProperty


org.apache.tools.ant.gui.modules.TargetMonitor.name=Selected Target(s) org.apache.tools.ant.gui.modules.TargetMonitor.name=Selected Target(s)
org.apache.tools.ant.gui.modules.TargetMonitor.defText=[none] org.apache.tools.ant.gui.modules.TargetMonitor.defText=[none]


org.apache.tools.ant.gui.modules.Console.name=Console
org.apache.tools.ant.gui.modules.Console.logLevel=Log message level:
org.apache.tools.ant.gui.modules.console.BuildConsole.name=Console
org.apache.tools.ant.gui.modules.console.BuildConsole.logLevel=Log message level:


org.apache.tools.ant.gui.core.XMLFileFilter.description=XML Files org.apache.tools.ant.gui.core.XMLFileFilter.description=XML Files




Loading…
Cancel
Save