git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268438 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -114,6 +114,17 @@ public class ACSFactory { | |||
| } | |||
| /** | |||
| * Get an instance of the factory. | |||
| * | |||
| * @return Factory instance. | |||
| */ | |||
| public static ACSFactory getInstance() { | |||
| if(_instance == null) { | |||
| _instance = new ACSFactory(); | |||
| } | |||
| return _instance; | |||
| } | |||
| /** | |||
| * Load a project from the given XML file. | |||
| @@ -167,19 +178,33 @@ public class ACSFactory { | |||
| return (ACSProjectElement) doc.getDocumentElement(); | |||
| } | |||
| /** | |||
| * Get an instance of the factory. | |||
| * | |||
| * @return Factory instance. | |||
| */ | |||
| public static ACSFactory getInstance() { | |||
| if(_instance == null) { | |||
| _instance = new ACSFactory(); | |||
| } | |||
| return _instance; | |||
| /** | |||
| * Create a new, empty project. | |||
| * | |||
| * @return Empty project. | |||
| */ | |||
| public ACSProjectElement createProject() { | |||
| SimpleElementFactory fact = new SimpleElementFactory(); | |||
| fact.addMapping(_elementMap, ACSFactory.class.getClassLoader()); | |||
| XmlDocument doc = new XmlDocument(); | |||
| doc.setElementFactory(fact); | |||
| return (ACSProjectElement) doc.createElement("project"); | |||
| } | |||
| /** | |||
| * Create a new target. | |||
| * | |||
| * @param project Project the target is assigned to. | |||
| * @return New, unnamed target. | |||
| */ | |||
| public ACSTargetElement createTarget(ACSProjectElement project) { | |||
| ACSTargetElement retval = (ACSTargetElement) project. | |||
| getOwnerDocument().createElement("target"); | |||
| project.appendChild(retval); | |||
| return retval; | |||
| } | |||
| /** | |||
| * Test code | |||
| * | |||
| @@ -123,6 +123,8 @@ public abstract class ACSTreeNodeElement extends ACSElement | |||
| * Returns the parent <code>TreeNode</code> of the receiver. | |||
| */ | |||
| public TreeNode getParent() { | |||
| // XXX this barfs becase a different "getParent()" is in Node | |||
| // interface. Need to fix... | |||
| return (TreeNode) getParent(); | |||
| } | |||
| @@ -53,6 +53,8 @@ | |||
| */ | |||
| package org.apache.tools.ant.gui.command; | |||
| import org.apache.tools.ant.gui.core.AppContext; | |||
| import org.apache.tools.ant.gui.event.NewProjectEvent; | |||
| import org.apache.tools.ant.gui.acs.ACSProjectElement; | |||
| /** | |||
| * Command for creating a new project. | |||
| @@ -61,6 +63,10 @@ import org.apache.tools.ant.gui.core.AppContext; | |||
| * @author Simeon Fitch | |||
| */ | |||
| public class NewProjectCmd extends AbstractCommand { | |||
| /** New project count for this session. Used to create default names, | |||
| * numbered as a convenience. */ | |||
| private static int _count = 1; | |||
| /** | |||
| * Standard ctor. | |||
| * | |||
| @@ -77,17 +83,12 @@ public class NewProjectCmd extends AbstractCommand { | |||
| * | |||
| */ | |||
| public void run() { | |||
| /* | |||
| FileFilter filter = new XMLFileFilter(getContext().getResources()); | |||
| JFileChooser chooser = new JFileChooser(); | |||
| chooser.addChoosableFileFilter(filter); | |||
| int val = chooser.showOpenDialog(getContext().getParentFrame()); | |||
| if(val == JFileChooser.APPROVE_OPTION) { | |||
| File selected = chooser.getSelectedFile(); | |||
| getContext().getEventBus().postEvent( | |||
| new OpenRequestEvent(getContext(), selected)); | |||
| } | |||
| */ | |||
| ACSProjectElement project = | |||
| getContext().getProjectManager().createNew(); | |||
| project.setName(getContext().getResources(). | |||
| getString(getClass(), "defName") + " " + _count++); | |||
| getContext().getEventBus().postEvent( | |||
| new NewProjectEvent(getContext(), project)); | |||
| } | |||
| } | |||
| @@ -120,17 +120,32 @@ public class ProjectManager { | |||
| 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 @@ public class ProjectManager { | |||
| * @return Unpopulated project. | |||
| */ | |||
| public ACSProjectElement createNew() { | |||
| ACSProjectElement retval = null; | |||
| ACSProjectElement retval = ACSFactory.getInstance().createProject(); | |||
| _projects.add(retval); | |||
| return retval; | |||
| } | |||
| @@ -59,6 +59,8 @@ import javax.swing.*; | |||
| 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. | |||
| @@ -153,8 +155,12 @@ public class ProjectSelectionMenu extends JMenu { | |||
| /** 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); | |||
| } | |||
| } | |||
| @@ -168,6 +168,45 @@ public class ResourceManager { | |||
| } | |||
| } | |||
| /** | |||
| * 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"); | |||
| } | |||
| /** | |||
| * Generate a composit key from the given class and key name. | |||
| * | |||
| @@ -3,7 +3,7 @@ menus=File, Build, Projects, Help | |||
| # Declare the list of known actions. | |||
| actions=\ | |||
| open, save, saveas, close, exit, about, \ | |||
| new, open, save, saveas, close, exit, about, \ | |||
| newTarget, newTask, newProperty \ | |||
| startBuild, stopBuild | |||
| @@ -1,5 +1,7 @@ | |||
| # This is the general properties file for the Antidote application. | |||
| #debug=true | |||
| # The following four module properties configure those properties that | |||
| # should be initialized and displayed by default by the GUI. If more | |||
| # than one module is configured for a property (as indicated providing | |||
| @@ -90,6 +92,7 @@ org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.xmlString=XML Code | |||
| org.apache.tools.ant.gui.acs.ACSTaskElementBeanInfo.icon=task.gif | |||
| org.apache.tools.ant.gui.command.NewProjectCmd.defName=New Project | |||
| #---------------------------------------------------------------------------- | |||
| # About Description (NB: this is only a temporary approach). | |||
| @@ -105,8 +108,6 @@ org.apache.tools.ant.gui.About.message=\ | |||
| <table> \ | |||
| <tr><td align="right"><b>Version</b>:</td><td>{0}</td></tr> \ | |||
| <tr><td align="right"><b>Date</b>:</td><td>{1}</td></tr> \ | |||
| <tr><td align="right" valign="top"><b>Contributors</b>:</td>\ | |||
| <td>{2}</td></tr> \ | |||
| </table> \ | |||
| <hr> \ | |||
| <p>Icons Copyright © 1998 Dean S. Jones (deansjones@hotmail.com)<br> \ | |||