metasim 01/01/11 11:24:59
Modified: src/antidote/org/apache/tools/ant/gui/core
ProjectManager.java ProjectSelectionMenu.java
ResourceManager.java
Log:
Added initial support for creating a new, empty project.
Revision Changes Path
1.3 +24 -8
jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ProjectManager.java
Index: ProjectManager.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ProjectManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProjectManager.java 2001/01/08 19:43:31 1.2
+++ ProjectManager.java 2001/01/11 19:24:48 1.3
@@ -71,7 +71,7 @@
*
* XXX need to add property change listeners support.
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @author Simeon Fitch
*/
public class ProjectManager {
@@ -120,17 +120,32 @@
location = project.getLocation();
}
if(location == null) {
- // xxx Fix me.
- throw new IOException("xxx need a file name xxx");
+ // This shouldn't happen.
+ throw new IOException("Logic error: Save location mising.");
}
Writer out = null;
try {
- URLConnection connection = location.openConnection();
- connection.setDoInput(false);
- connection.setDoOutput(true);
- out = new OutputStreamWriter(connection.getOutputStream());
+ // XXX for some reason the URLConnection for protocol type "file"
+ // doesn't support output (at least that is what the exception
+ // says. I don't know if I'm doing something wrong or not, but
+ // since we need to handle files differently (which is fine
+ // right now since files are all we really support anyway.
+ if(location.getProtocol().equals("file")) {
+ out = new FileWriter(location.getFile());
+ }
+ else {
+ // XXX This is here for future support of FTP/HTTP and
+ // the like. JDBC will have to be dealt with differently.
+ URLConnection connection = location.openConnection();
+ connection.setDoInput(false);
+ connection.setDoOutput(true);
+ out = new OutputStreamWriter(connection.getOutputStream());
+ }
+
+ // Persist the project.
project.write(out);
+ out.flush();
project.setLocation(location);
}
finally {
@@ -170,7 +185,8 @@
* @return Unpopulated project.
*/
public ACSProjectElement createNew() {
- ACSProjectElement retval = null;
+ ACSProjectElement retval = ACSFactory.getInstance().createProject();
+ _projects.add(retval);
return retval;
}
1.2 +7 -1
jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ProjectSelectionMenu.java
Index: ProjectSelectionMenu.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/core/ProjectSelectionMenu.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProjectSelectionMenu.java 2001/01/10 20:46:54 1.1
+++ ProjectSelectionMenu.java 2001/01/11 19:24:49 1.2
@@ -59,11 +59,13 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
+import java.beans.PropertyChangeEvent;
+
/**
* Specialization of JMenu providing selectability of the currently
* open projects.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Simeon Fitch
*/
public class ProjectSelectionMenu extends JMenu {
@@ -153,8 +155,12 @@
/** Filter for project related events. */
private static class Filter implements BusFilter {
public boolean accept(EventObject event) {
+ // We want events related to projects.
return event instanceof ProjectSelectedEvent ||
- event instanceof ProjectClosedEvent;
+ event instanceof ProjectClosedEvent ||
+ (event instanceof PropertyChangeEvent &&
+ ((PropertyChangeEvent)event).getSource()
+ instanceof ACSProjectElement);
}
}
1.4 +40 -1
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResourceManager.java 2001/01/04 21:11:13 1.3
+++ ResourceManager.java 2001/01/11 19:24:51 1.4
@@ -63,7 +63,7 @@
* Singleton class for accessing various resources by the application.
* Relies on the resource bundles for resource values.
*
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
* @author Simeon H.K. Fitch
*/
public class ResourceManager {
@@ -166,6 +166,45 @@
}
return retval;
}
+ }
+
+ /**
+ * Get the boolean resource for the given name. Case
+ * insensitive values of "yes" or "true" evaluate to TRUE.
+ * All others, including undefined resources evaluate to FALSE.
+ *
+ * @param name Name of the boolean resource.
+ * @return True if defined as true, false otherwise.
+ */
+ public boolean getBoolean(String name) {
+ return getBoolean(null, name);
+ }
+
+ /**
+ * Get the boolean resource for the given class. Case
+ * insensitive values of "yes" or "true" evaluate to TRUE.
+ * All others, including undefined resources evaluate to FALSE.
+ *
+ * @param clazz Class to get resource for.
+ * @param name Name of the boolean resource.
+ * @return True if defined as true, false otherwise.
+ */
+ public boolean getBoolean(Class clazz, String name) {
+ if(name == null) {
+ return false;
+ }
+
+ String key = getKey(clazz, name);
+
+ String value = "";
+ try {
+ value = _resources.getString(key);
+ }
+ catch(MissingResourceException ex) {
+ // Ignore missing resources as they imply false.
+ }
+
+ return value.equalsIgnoreCase("true") ||
value.equalsIgnoreCase("yes");
}
/**