Browse Source

Added save and saveas action implementation.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268196 13f79535-47bb-0310-9956-ffa450edef68
master
metasim 24 years ago
parent
commit
7fadc50ca4
10 changed files with 448 additions and 21 deletions
  1. +27
    -7
      src/antidote/TODO
  2. +10
    -2
      src/antidote/org/apache/tools/ant/gui/About.java
  3. +6
    -0
      src/antidote/org/apache/tools/ant/gui/EventResponder.java
  4. +22
    -1
      src/antidote/org/apache/tools/ant/gui/ProjectProxy.java
  5. +100
    -0
      src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java
  6. +1
    -2
      src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java
  7. +76
    -0
      src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java
  8. +174
    -0
      src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java
  9. +22
    -5
      src/antidote/org/apache/tools/ant/gui/resources/action.properties
  10. +10
    -4
      src/antidote/org/apache/tools/ant/gui/resources/antidote.properties

+ 27
- 7
src/antidote/TODO View File

@@ -1,7 +1,34 @@
TODO List:
* Dispatch tree node change events when the properties editor changes a
node value. This will make sure that the node gets displayed correctly in
the project navigator.

* Implement a custom tree node renderer with better icons.

* Implement a build progress reporter.

* Add "syntax" colorization to the console window, with a preferences
editor for setting up the styles.

* Rework EventResponder to remove hard coded command translation.

* Figure out an approach to gracefully stopping a running build.

* Add error handler for SAX parser to better report loading errors.

* Create an error dialog that is able to display a stack backtrace if
desired.

* Add support to ActionManager to handle toggle actions in tool bar. Also
need a better way of detecting the selected state of the action button.

* Project properties viewer, including the ability to view
dependencies (local and cascading).

* Acquire or implement a logging facility.

(pending Ant 2.0)
* Need Ant API access to:
- Tasks within a Target
- The topo sorted task list to get flattened dependencies
@@ -12,10 +39,3 @@ TODO List:
* Better define the data model architecture, and how it interfaces
with the Ant data model.

* Project properties viewer, including the ability to view
dependencies (local and cascading).

* Acquire or implement a logging facility.

* Build launching capability.


+ 10
- 2
src/antidote/org/apache/tools/ant/gui/About.java View File

@@ -58,6 +58,7 @@ import javax.swing.*;
import java.io.IOException;
import java.util.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

@@ -104,7 +105,7 @@ public class About extends JDialog {
while(tok.hasMoreTokens()) {
String name = tok.nextToken();
buf.append(name);
buf.append("<P>\n");
buf.append("<br>\n");
}

String message = context.getResources().getMessage(
@@ -115,7 +116,14 @@ public class About extends JDialog {
getClass(), "title");
setTitle(title);

JLabel contents = new JLabel(message);
JTextPane contents = new JTextPane();
contents.setContentType("text/html");
contents.setText(message);
contents.setEditable(false);
// XXX Still not sure why this is necessary. JTextPane doesn't
// seem to report a "true" preferred size.
contents.setPreferredSize(
new Dimension(contents.getPreferredSize().width, 450));
getContentPane().add(BorderLayout.CENTER, contents);

// Add the OK button.


+ 6
- 0
src/antidote/org/apache/tools/ant/gui/EventResponder.java View File

@@ -119,6 +119,12 @@ class EventResponder {
if(command.equals(OpenCmd.ACTION_NAME)) {
new OpenCmd(_context).execute();
}
else if(command.equals(SaveCmd.ACTION_NAME)) {
new SaveCmd(_context).execute();
}
else if(command.equals(SaveAsCmd.ACTION_NAME)) {
new SaveAsCmd(_context).execute();
}
else if(command.equals(BuildCmd.ACTION_NAME)) {
new BuildCmd(_context).execute();
}


+ 22
- 1
src/antidote/org/apache/tools/ant/gui/ProjectProxy.java View File

@@ -56,6 +56,7 @@ import org.apache.tools.ant.*;
import org.apache.tools.ant.gui.event.*;
import org.apache.tools.ant.gui.acs.*;
import java.io.File;
import java.io.Writer;
import java.io.IOException;
import javax.swing.tree.TreeModel;
import javax.swing.text.Document;
@@ -95,7 +96,6 @@ public class ProjectProxy {
_file = file;
_context = context;
loadProject();

}

/**
@@ -108,6 +108,17 @@ public class ProjectProxy {
_selections.addTreeSelectionListener(new SelectionForwarder());
}

/**
* Write the project in XML format to the given output.
*
* @param out Output to write to.
*/
public void write(Writer out) throws IOException {
if(_project == null) return;

_project.write(out);
}

/**
* Build the project with the current target (or the default target
* if none is selected. Build occurs on a separate thread, so method
@@ -144,6 +155,16 @@ public class ProjectProxy {
return _file;
}

/**
* Set the file that this is to be saved to.
*
* @param file File to save to.
*/
public void setFile(File file) {
_file = file;
}


/**
* Get the TreeModel perspective on the data.
*


+ 100
- 0
src/antidote/org/apache/tools/ant/gui/command/EmacsNotifyCmd.java View File

@@ -0,0 +1,100 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.AppContext;
import org.apache.tools.ant.gui.ide.EmacsNotifier;

/**
* Toggle on or off the sending of error events to emacs so that
* it can display the source of the error.
*
* @version $Revision$
* @author Simeon Fitch
*/
public class EmacsNotifyCmd implements Command {
/** Action command. */
public static final String ACTION_NAME = "notifyEmacs";

/** A global notifier can be used as it stores no state. */
private static EmacsNotifier _notifier = new EmacsNotifier();
/** Application context. */
private AppContext _context = null;
/** State notification should be in. */
private boolean _notify = false;

/**
* Standard ctor.
*
* @param context Application context.
* @param state True if notifying on, false for notifying off.
*/
public EmacsNotifyCmd(AppContext context, boolean state) {
_context = context;
_notify = state;
}

/**
* Turn on or off the notifying of emacs.
*
*/
public void execute() {
if(_notify) {
_context.addBuildListener(_notifier);
}
else {
_context.removeBuildListener(_notifier);
}
}
}

+ 1
- 2
src/antidote/org/apache/tools/ant/gui/command/OpenCmd.java View File

@@ -73,7 +73,7 @@ public class OpenCmd implements Command {

/** The application context */
private AppContext _context = null;
/** Filter for showing only XML file.s */
/** Filter for showing only XML files. */
private FileFilter _filter = null;

/**
@@ -93,7 +93,6 @@ public class OpenCmd implements Command {
*
*/
public void execute() {
// XXX need to set chooser text based on ResourceManager values.
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(_filter);
int val = chooser.showOpenDialog(_context.getParentFrame());


+ 76
- 0
src/antidote/org/apache/tools/ant/gui/command/SaveAsCmd.java View File

@@ -0,0 +1,76 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.AppContext;


/**
* Command for doing a "Save as" type of save.
*
* @version $Revision$
* @author Simeon Fitch
*/
public class SaveAsCmd extends SaveCmd {
/** Name of the action the command maps to. */
public static final String ACTION_NAME = "saveas";

/**
* Standard ctor.
*
* @param context Application context.
*/
public SaveAsCmd(AppContext context) {
super(context, null);
}
}

+ 174
- 0
src/antidote/org/apache/tools/ant/gui/command/SaveCmd.java View File

@@ -0,0 +1,174 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999, 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.gui.command;
import org.apache.tools.ant.gui.AppContext;
import org.apache.tools.ant.gui.ProjectProxy;
import org.apache.tools.ant.gui.event.ErrorEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.tools.ant.gui.XMLFileFilter;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.JOptionPane;

/**
* Command to execute the saving of the current build file.
*
* @version $Revision$
* @author Simeon Fitch
*/
public class SaveCmd implements Command {
/** Name of the action the command maps to. */
public static final String ACTION_NAME = "save";

/** The application context */
private AppContext _context = null;
/** Filter for showing only XML files. */
private FileFilter _filter = null;
/** File to save to. */
private File _file = null;

/**
* Standard ctor with file.
*
* @param context Application context.
* @param file File to save to, or null.
*/
public SaveCmd(AppContext context, File file) {
_context = context;
_filter = new XMLFileFilter(_context.getResources());
_file = file;
}

/**
* Standard ctor.
*
* @param context Application context.
*/
public SaveCmd(AppContext context) {
this(context, context.getProject() == null ? null :
context.getProject().getFile());
}

/**
* Save the project to the current file name.
*
*/
public void execute() {
ProjectProxy project = _context.getProject();
if(project != null) {
if(_file == null) {
// XXX code here to select a file to save to.
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(_filter);
int val = chooser.showSaveDialog(_context.getParentFrame());
if(val == JFileChooser.APPROVE_OPTION) {
_file = chooser.getSelectedFile();
if(_file.exists()) {
String title = _context.getResources().getString(
SaveCmd.class, "title");
String message = _context.getResources().getMessage(
SaveCmd.class, "overwrite",
new Object[] {_file.toString()});
val = JOptionPane.showConfirmDialog(
_context.getParentFrame(), message, title,
JOptionPane.YES_NO_OPTION);
// If cancelled unset file.
if(val != JOptionPane.YES_OPTION) {
_file = null;
}
}
}
}
if(_file != null) {
project.setFile(_file);
FileWriter out = null;
try {
out = new FileWriter(_file);
project.write(out);
}
catch(IOException ex) {
String message = _context.getResources().getMessage(
SaveCmd.class, "saveError",
new Object[] { _file.toString() });
_context.getEventBus().
postEvent(new ErrorEvent(_context, message));
}
finally {
if (out != null) {
try {
out.flush();
out.close();
}
catch(IOException ex) {
// Intentionally ignored.
}
}
}
}
}
else {
// We shouldn't ever get here.
String message = _context.getResources().getString(
SaveCmd.class, "noProject");
_context.getEventBus().
postEvent(new ErrorEvent(_context, message));
}
}
}

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

@@ -3,12 +3,12 @@ menus=File, Build, Options, Help

# Declare the list of known actions.
actions=\
open, save, close, exit, about, startBuild, stopBuild, \
open, save, saveas, close, exit, about, startBuild, stopBuild, \
notifyEmacs, changeLookAndFeel

# Configure the decalred actions.

open.name=Open
open.name=Open...
open.shortDescription=Open an existing project
open.parentMenuName=File
open.icon=open.gif
@@ -21,6 +21,23 @@ save.parentMenuName=File
save.icon=save.gif
save.accelerator=control S
save.enabled=false
save.disableOn= \
org.apache.tools.ant.gui.event.ProjectClosedEvent, \
org.apache.tools.ant.gui.event.BuildStartedEvent
save.enableOn= \
org.apache.tools.ant.gui.event.NewProjectEvent, \
org.apache.tools.ant.gui.event.BuildFinishedEvent

saveas.name=Save As...
saveas.shortDescription=Save to a specific file
saveas.parentMenuName=File
saveas.enabled=false
saveas.disableOn= \
org.apache.tools.ant.gui.event.ProjectClosedEvent, \
org.apache.tools.ant.gui.event.BuildStartedEvent
saveas.enableOn= \
org.apache.tools.ant.gui.event.NewProjectEvent, \
org.apache.tools.ant.gui.event.BuildFinishedEvent

close.name=Close
close.shortDescription=Close the current project
@@ -39,13 +56,13 @@ exit.parentMenuName=File
exit.separator=true
exit.enabled=true

about.name=About
about.name=About...
about.shortDescription=About this application
about.parentMenuName=Help
about.separator=true;
about.enabled=true

startBuild.name=Start
startBuild.name=Start Build
startBuild.shortDescription=Start build of selected target
startBuild.parentMenuName=Build
startBuild.icon=start.gif
@@ -59,7 +76,7 @@ startBuild.disableOn=\
org.apache.tools.ant.gui.event.BuildStartedEvent, \
org.apache.tools.ant.gui.event.ProjectClosedEvent

stopBuild.name=Stop
stopBuild.name=Stop Build
stopBuild.shortDescription=Stop the current build
stopBuild.parentMenuName=Build
stopBuild.icon=stop.gif


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

@@ -36,12 +36,18 @@ org.apache.tools.ant.gui.command.LoadFileCmd.noFile=The file "{0}" was not found
org.apache.tools.ant.gui.command.LoadFileCmd.loadError=The file "{0}" could not be loaded.
org.apache.tools.ant.gui.command.DisplayErrorCmd.title=Error...

org.apache.tools.ant.gui.command.SaveCmd.saveError=Could not save to "{0}".
org.apache.tools.ant.gui.command.SaveCmd.noProject=No project to save.
org.apache.tools.ant.gui.command.SaveCmd.title=Overwrite?
org.apache.tools.ant.gui.command.SaveCmd.overwrite=Overwrite file "{0}"?

org.apache.tools.ant.gui.About.title=About
org.apache.tools.ant.gui.About.ok=OK
org.apache.tools.ant.gui.About.message=\
<html><h1>Antidote</h1> \
<p>Copyright &copy; 2000 The Apache Software Foundation.</p> \
<p>All rights reserved.</p> \
<p>Copyright &copy; 2000 The Apache Software Foundation. <br>\
All rights reserved.</p><br> \
<p>Visit http://jakarta.apache.org/ant for more information.</p><br> \
<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> \
@@ -49,8 +55,8 @@ org.apache.tools.ant.gui.About.message=\
<td>{2}</td></tr> \
</table> \
<hr> \
<p>Icons Copyright &copy; 1998 Dean S. Jones (deansjones@hotmail.com)</p> \
<p>http://jfa.javalobby.org/projects/icons</p> \
<p>Icons Copyright &copy; 1998 Dean S. Jones (deansjones@hotmail.com)<br> \
http://jfa.javalobby.org/projects/icons</p> \
</html>




Loading…
Cancel
Save