git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268453 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -65,7 +65,7 @@ import java.lang.reflect.Constructor; | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public class Antidote extends JPanel { | |||
| public class Antidote extends JComponent { | |||
| /** Source of application state data. */ | |||
| private AppContext _context = null; | |||
| @@ -0,0 +1,161 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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; | |||
| import org.apache.tools.ant.gui.core.ResourceManager; | |||
| /** | |||
| * Class encapsulating the parsing of command-line arguments for Antidote. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public class Args { | |||
| private ResourceManager _resources = null; | |||
| private boolean _wizzardMode = false; | |||
| private String _fileName = null; | |||
| private boolean _debugMode = false; | |||
| /** | |||
| * Ctor for parsing command line arguments. | |||
| * | |||
| * @param args Arguments to parse. | |||
| */ | |||
| public Args(String[] args) { | |||
| for(int i = 0; i < args.length; i++) { | |||
| String arg = args[i]; | |||
| if(i == args.length - 1 && !arg.startsWith("-")) { | |||
| _fileName = arg; | |||
| } | |||
| else if(arg.startsWith("-h")) { | |||
| System.out.println(getUsage()); | |||
| System.exit(0); | |||
| } | |||
| else if(arg.equals("-wizzard")) { | |||
| _wizzardMode = true; | |||
| } | |||
| else if(arg.equals("-debug")) { | |||
| _debugMode = true; | |||
| } | |||
| else { | |||
| String msg = getResources().getMessage( | |||
| "invalidArg", new Object[] { arg }); | |||
| abort(msg); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * Get the resources, loading them if necessary. | |||
| * | |||
| * @return Loaded resources. | |||
| */ | |||
| private ResourceManager getResources() { | |||
| if(_resources == null) { | |||
| _resources = new ResourceManager( | |||
| "org.apache.tools.ant.gui.resources.args"); | |||
| } | |||
| return _resources; | |||
| } | |||
| /** | |||
| * Print message and exit. | |||
| * | |||
| * @param error Error message to print. | |||
| */ | |||
| private void abort(String error) { | |||
| System.err.println(error); | |||
| System.err.println(getUsage()); | |||
| System.exit(1); | |||
| } | |||
| /** | |||
| * Get the command line usage of Antidote. | |||
| * | |||
| * @return Command line usage help. | |||
| */ | |||
| public String getUsage() { | |||
| return getResources().getString("usage"); | |||
| } | |||
| /** | |||
| * Get the build filename. | |||
| * | |||
| * @return Build file name. | |||
| */ | |||
| public String getBuildFile() { | |||
| return _fileName; | |||
| } | |||
| /** | |||
| * Determine if wizzard mode was requested for generating a new | |||
| * build file. | |||
| * | |||
| * @return True if wizzard mode, false otherwise. | |||
| */ | |||
| public boolean isWizzardMode() { | |||
| return _wizzardMode; | |||
| } | |||
| /** | |||
| * Determine if debug mode was requested. | |||
| * | |||
| * @return True if debug mode, false otherwise. | |||
| */ | |||
| public boolean isDebugMode() { | |||
| return _debugMode; | |||
| } | |||
| } | |||
| @@ -0,0 +1,218 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| import javax.swing.JComponent; | |||
| /** | |||
| * Abstract class implementing the basic support for the WizzardStep interface. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public abstract class AbstractWizzardStep extends JComponent | |||
| implements WizzardStep { | |||
| /** Step id. */ | |||
| private String _id = null; | |||
| /** Step display title. */ | |||
| private String _title = null; | |||
| /** Description of the step. */ | |||
| private String _description = null; | |||
| /** Data model. */ | |||
| private Object _model = null; | |||
| /** ID of next step. */ | |||
| private String _nextID = null; | |||
| /** ID of previous step. */ | |||
| private String _prevID = null; | |||
| /** | |||
| * Set the step id. The id must be unique among steps within the wizzard. | |||
| * | |||
| * @param id Wizzard id. | |||
| */ | |||
| public void setID(String id) { | |||
| _id = id; | |||
| } | |||
| /** | |||
| * Get the step id. | |||
| * | |||
| * @return Step id. | |||
| */ | |||
| public String getID() { | |||
| return _id; | |||
| } | |||
| /** | |||
| * Set the step title. | |||
| * | |||
| * @param title Step title. | |||
| */ | |||
| public void setTitle(String title) { | |||
| _title = title; | |||
| } | |||
| /** | |||
| * Get the step title. | |||
| * | |||
| * @return Step title. | |||
| */ | |||
| public String getTitle() { | |||
| return _title; | |||
| } | |||
| /** | |||
| * Set the step description. | |||
| * | |||
| * @param desc Step description. | |||
| */ | |||
| public void setDescription(String desc) { | |||
| _description = desc; | |||
| } | |||
| /** | |||
| * Get the step description. | |||
| * | |||
| * @return Step description. | |||
| */ | |||
| public String getDescription() { | |||
| return _description; | |||
| } | |||
| /** | |||
| * Set the default id of the next step. | |||
| * | |||
| * @param nextID ID of next step. | |||
| */ | |||
| public void setNext(String nextID) { | |||
| _nextID = nextID; | |||
| } | |||
| /** | |||
| * Get the id of the next step. | |||
| * | |||
| * @return ID of next step. | |||
| */ | |||
| public String getNext() { | |||
| return _nextID; | |||
| } | |||
| /** | |||
| * Set the default id of the previous step. | |||
| * | |||
| * @param prevID ID of previous step. | |||
| */ | |||
| public void setPrevious(String prevID) { | |||
| _prevID = prevID; | |||
| } | |||
| /** | |||
| * Get the id of the previous step. | |||
| * | |||
| * @return Previous step. | |||
| */ | |||
| public String getPrevious() { | |||
| return _prevID; | |||
| } | |||
| /** | |||
| * Set the data model object that the step will edit. It is assumed | |||
| * that all steps initialized within a single wizzard agree on the | |||
| * data model type. | |||
| * | |||
| * @param model Data model to edit. | |||
| */ | |||
| public void setDataModel(Object model) { | |||
| _model = model; | |||
| } | |||
| /** | |||
| * Get the data model that should be passeed on to the next step. | |||
| * | |||
| * @return Current data model. | |||
| */ | |||
| public Object getDataModel() { | |||
| return _model; | |||
| } | |||
| /** | |||
| * Get the component that should be displayed to the user for | |||
| * editing the model. This component should <b>not</b> include the | |||
| * title and text display, which is handled by the wizzard container. | |||
| * | |||
| * @return Editing component. | |||
| */ | |||
| public JComponent getEditorComponent() { | |||
| return this; | |||
| } | |||
| /** | |||
| * Get a string representation of this. | |||
| * | |||
| * @return String representation. | |||
| */ | |||
| public String toString() { | |||
| StringBuffer buf = new StringBuffer(getClass().getName()); | |||
| buf.append("[id="); | |||
| buf.append(getID()); | |||
| buf.append(",prev="); | |||
| buf.append(getPrevious()); | |||
| buf.append(",next="); | |||
| buf.append(getNext()); | |||
| buf.append("]"); | |||
| return buf.toString(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,197 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| import org.apache.tools.ant.gui.core.ResourceManager; | |||
| import javax.swing.*; | |||
| import java.awt.event.ActionListener; | |||
| import java.awt.event.ActionEvent; | |||
| import java.awt.FlowLayout; | |||
| import java.util.*; | |||
| class ButtonNavigator extends JComponent implements WizzardNavigator { | |||
| public static final String NEXT = "next"; | |||
| public static final String BACK = "back"; | |||
| public static final String CANCEL = "cancel"; | |||
| public static final String FINISH = "finish"; | |||
| /** Resources. */ | |||
| private ResourceManager _resources = null; | |||
| /** Event listeners. */ | |||
| private List _listeners = new ArrayList(); | |||
| /* Buttons. */ | |||
| private JButton _next = null; | |||
| private JButton _back = null; | |||
| private JButton _cancel = null; | |||
| private JButton _finish = null; | |||
| /** Action handler. */ | |||
| private ActionHandler _handler = new ActionHandler(); | |||
| public ButtonNavigator(ResourceManager resources) { | |||
| _resources = resources; | |||
| setLayout(new FlowLayout(FlowLayout.RIGHT)); | |||
| _back = new JButton(_resources.getString(BACK)); | |||
| _next = new JButton(_resources.getString(NEXT)); | |||
| _finish = new JButton(_resources.getString(FINISH)); | |||
| _cancel = new JButton(_resources.getString(CANCEL)); | |||
| _back.setActionCommand(BACK); | |||
| _next.setActionCommand(NEXT); | |||
| _finish.setActionCommand(FINISH); | |||
| _cancel.setActionCommand(CANCEL); | |||
| _back.addActionListener(_handler); | |||
| _next.addActionListener(_handler); | |||
| _finish.addActionListener(_handler); | |||
| _cancel.addActionListener(_handler); | |||
| _back.setEnabled(false); | |||
| _next.setEnabled(false); | |||
| _finish.setEnabled(false); | |||
| _cancel.setEnabled(true); | |||
| add(_back); | |||
| add(_next); | |||
| add(_finish); | |||
| add(_cancel); | |||
| } | |||
| /** | |||
| * Add a navigator listener. | |||
| * | |||
| * @param l Listener to add. | |||
| */ | |||
| public void addNavigatorListener(NavigatorListener l) { | |||
| _listeners.add(l); | |||
| } | |||
| /** | |||
| * Remove a navigator listener. | |||
| * | |||
| * @param l Listener to remove. | |||
| */ | |||
| public void removeNavigatorListener(NavigatorListener l) { | |||
| _listeners.remove(l); | |||
| } | |||
| /** | |||
| * Set the enabled state of the back button. | |||
| * | |||
| * @param state True for enabled, false for disabled. | |||
| */ | |||
| public void setBackEnabled(boolean state) { | |||
| _back.setEnabled(state); | |||
| } | |||
| /** | |||
| * Set the enabled state of the next button. | |||
| * | |||
| * @param state True for enabled, false for disabled. | |||
| */ | |||
| public void setNextEnabled(boolean state) { | |||
| _next.setEnabled(state); | |||
| } | |||
| /** | |||
| * Set the enabled state of the finished button. | |||
| * | |||
| * @param state True for enabled, false for disabled. | |||
| */ | |||
| public void setFinishEnabled(boolean state) { | |||
| _finish.setEnabled(state); | |||
| } | |||
| /** Handler of the button presses. */ | |||
| private class ActionHandler implements ActionListener { | |||
| public void actionPerformed(ActionEvent e) { | |||
| Object source = e.getSource(); | |||
| // Predetermine which method to call so that | |||
| // we don't traverse if statements for each iteration. | |||
| int idx = -1; | |||
| if(source == _next) { | |||
| idx = 0; | |||
| } | |||
| else if(source == _back) { | |||
| idx = 1; | |||
| } | |||
| else if(source == _cancel) { | |||
| idx = 2; | |||
| } | |||
| else if(source == _finish) { | |||
| idx = 3; | |||
| } | |||
| Iterator it = _listeners.iterator(); | |||
| while(it.hasNext()) { | |||
| NavigatorListener l = (NavigatorListener) it.next(); | |||
| switch(idx) { | |||
| case 0: | |||
| l.nextStep(); | |||
| break; | |||
| case 1: | |||
| l.backStep(); | |||
| break; | |||
| case 2: | |||
| l.cancel(); | |||
| break; | |||
| case 3: | |||
| l.finish(); | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,65 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| import javax.swing.*; | |||
| /** | |||
| * Wizzard step whose only purpose is to display some text. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public class InstructionStep extends AbstractWizzardStep { | |||
| } | |||
| @@ -0,0 +1,89 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| /** | |||
| * Interface for classes interested in events from the WizzardNavigator. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public interface NavigatorListener { | |||
| /** | |||
| * Called when the wizzard should show the next step. | |||
| * | |||
| */ | |||
| void nextStep(); | |||
| /** | |||
| * Called when the wizzard should show the previous step. | |||
| * | |||
| */ | |||
| void backStep(); | |||
| /** | |||
| * Called when the wizzard should show the step with the given id. | |||
| * | |||
| * @param stepID ID of step to show. | |||
| */ | |||
| void gotoStep(String stepID); | |||
| /** | |||
| * Called when the wizzard activity shold be cancelled. | |||
| * | |||
| */ | |||
| void cancel(); | |||
| /** | |||
| * Called when the wizzard is finished. | |||
| * | |||
| */ | |||
| void finish(); | |||
| } | |||
| @@ -0,0 +1,241 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| import org.apache.tools.ant.gui.core.ResourceManager; | |||
| import javax.swing.*; | |||
| import javax.swing.border.TitledBorder; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.CardLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.Font; | |||
| import java.util.*; | |||
| /** | |||
| * Top level container and controller for wizzard-type GUI. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public class Wizzard extends JComponent { | |||
| /** Resources defining the wizzard contents. Separate from the | |||
| * application context resources. */ | |||
| private ResourceManager _resources = null; | |||
| /** Container for the step editors. */ | |||
| private JPanel _stepContainer = null; | |||
| /** Layout manager for all the step panels. */ | |||
| private CardLayout _layout = null; | |||
| /** Set initialized steps. */ | |||
| private Map _steps = new HashMap(); | |||
| /** Description text. XXX should probably change to some other widget. */ | |||
| private JTextArea _description = null; | |||
| /** Widget for navigating through steps. */ | |||
| private WizzardNavigator _nav = null; | |||
| /** The data model to pass on to each step. */ | |||
| private Object _model = null; | |||
| /** The current Wizzard step. */ | |||
| private WizzardStep _curr = null; | |||
| /** The set of wizzard listeners. */ | |||
| private List _listeners = new ArrayList(1); | |||
| /** | |||
| * Standard ctor. | |||
| * | |||
| * @param resources Wizzard definition resources | |||
| * @param dataModel Initial data model. | |||
| */ | |||
| public Wizzard(ResourceManager resources, Object dataModel) { | |||
| setLayout(new BorderLayout()); | |||
| _resources = resources; | |||
| _model = dataModel; | |||
| TitledBorder border = new TitledBorder("Border"); | |||
| setBorder(border); | |||
| _description = new JTextArea(4, 40); | |||
| _description.setBorder(BorderFactory.createEtchedBorder()); | |||
| _description.setOpaque(false); | |||
| _description.setFont(new Font("Serif", Font.PLAIN, 12)); | |||
| _description.setEditable(false); | |||
| _description.setLineWrap(true); | |||
| _description.setWrapStyleWord(true); | |||
| add(_description, BorderLayout.NORTH); | |||
| _stepContainer = new JPanel(_layout = new CardLayout()); | |||
| _stepContainer.setBorder(BorderFactory.createEtchedBorder()); | |||
| add(_stepContainer, BorderLayout.CENTER); | |||
| _nav = new ButtonNavigator(_resources); | |||
| _nav.addNavigatorListener(new NavHandler()); | |||
| ((ButtonNavigator)_nav).setBorder(BorderFactory.createEtchedBorder()); | |||
| add((ButtonNavigator)_nav, BorderLayout.SOUTH); | |||
| String[] steps = _resources.getStringArray("steps"); | |||
| try { | |||
| for(int i = 0; i < steps.length; i++) { | |||
| Class type = _resources.getClass(steps[i] + ".editor"); | |||
| WizzardStep step = (WizzardStep) type.newInstance(); | |||
| step.setID(steps[i]); | |||
| step.setTitle(_resources.getString(steps[i]+ ".title")); | |||
| step.setDescription( | |||
| _resources.getString(steps[i]+ ".description")); | |||
| String id = _resources.getString(steps[i] + ".next"); | |||
| id = (id == null && i < steps.length - 1) ? steps[i + 1] : id; | |||
| step.setNext(id); | |||
| id = _resources.getString(steps[i] + ".prev"); | |||
| id = (id == null && i > 0) ? steps[i - 1] : id; | |||
| step.setPrevious(id); | |||
| _steps.put(steps[i], step); | |||
| _stepContainer.add(step.getEditorComponent(), steps[i]); | |||
| } | |||
| // Initialize the first screen with the data model. | |||
| if(steps.length > 0) { | |||
| WizzardStep first = (WizzardStep)_steps.get(steps[0]); | |||
| first.setDataModel(_model); | |||
| _curr = first; | |||
| showStep(first); | |||
| } | |||
| } | |||
| catch(Exception ex) { | |||
| // If we get here then the wizzard didn't initialize properly. | |||
| // XXX log me. | |||
| ex.printStackTrace(); | |||
| } | |||
| setPreferredSize(new Dimension(500, 400)); | |||
| } | |||
| /** | |||
| * Add a wizzard listener. | |||
| * | |||
| * @param l Listener to add. | |||
| */ | |||
| public void addWizzardListener(WizzardListener l) { | |||
| _listeners.add(l); | |||
| } | |||
| /** | |||
| * Remove a wizzard listener. | |||
| * | |||
| * @param l Listener to remove. | |||
| */ | |||
| public void removeWizzardListener(WizzardListener l) { | |||
| _listeners.remove(l); | |||
| } | |||
| /** | |||
| * Go to the given step. | |||
| * | |||
| * @param step Step to go to. | |||
| */ | |||
| private void showStep(WizzardStep step) { | |||
| if(step == null) return; | |||
| // Transfer data model (in case step wants to create a new one. | |||
| step.setDataModel(_curr.getDataModel()); | |||
| // Update the title and description. | |||
| TitledBorder border = (TitledBorder) getBorder(); | |||
| border.setTitle(step.getTitle()); | |||
| _description.setText(step.getDescription()); | |||
| _nav.setBackEnabled(step.getPrevious() != null); | |||
| _nav.setNextEnabled(step.getNext() != null); | |||
| _nav.setFinishEnabled(step.getNext() == null); | |||
| // Display the step. | |||
| _layout.show(_stepContainer, step.getID()); | |||
| _curr = step; | |||
| } | |||
| /** Handler for actions invoked by wizzard. */ | |||
| private class NavHandler implements NavigatorListener { | |||
| public void nextStep() { | |||
| String nextID = _curr.getNext(); | |||
| if(nextID != null) { | |||
| showStep((WizzardStep)_steps.get(nextID)); | |||
| } | |||
| } | |||
| public void backStep() { | |||
| String prevID = _curr.getPrevious(); | |||
| if(prevID != null) { | |||
| showStep((WizzardStep)_steps.get(prevID)); | |||
| } | |||
| } | |||
| public void gotoStep(String stepID){ | |||
| showStep((WizzardStep) _steps.get(stepID)); | |||
| } | |||
| public void cancel() { | |||
| Iterator it = _listeners.iterator(); | |||
| while(it.hasNext()) { | |||
| WizzardListener l = (WizzardListener) it.next(); | |||
| l.canceled(); | |||
| } | |||
| } | |||
| public void finish() { | |||
| Iterator it = _listeners.iterator(); | |||
| while(it.hasNext()) { | |||
| WizzardListener l = (WizzardListener) it.next(); | |||
| l.finished(_curr.getDataModel()); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,77 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| /** | |||
| * Interface for classes desiring notifiction of when the user | |||
| * completes his/her use of wizzard. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public interface WizzardListener { | |||
| /** | |||
| * Called when the user has clicked the finish button. | |||
| * | |||
| * @param model Last state of the object model. | |||
| */ | |||
| void finished(Object model); | |||
| /** | |||
| * Called when the user has clicked the cancel button. | |||
| * | |||
| */ | |||
| void canceled(); | |||
| } | |||
| @@ -0,0 +1,88 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| public interface WizzardNavigator { | |||
| /** | |||
| * Add a navigator listener. | |||
| * | |||
| * @param l Listener to add. | |||
| */ | |||
| void addNavigatorListener(NavigatorListener l); | |||
| /** | |||
| * Remove a navigator listener. | |||
| * | |||
| * @param l Listener to remove. | |||
| */ | |||
| void removeNavigatorListener(NavigatorListener l); | |||
| /** | |||
| * Set the enabled state of the back control. | |||
| * | |||
| * @param state True for enabled, false for disabled. | |||
| */ | |||
| void setBackEnabled(boolean state); | |||
| /** | |||
| * Set the enabled state of the next control. | |||
| * | |||
| * @param state True for enabled, false for disabled. | |||
| */ | |||
| void setNextEnabled(boolean state); | |||
| /** | |||
| * Set the enabled state of the finished control. | |||
| * | |||
| * @param state True for enabled, false for disabled. | |||
| */ | |||
| void setFinishEnabled(boolean state); | |||
| } | |||
| @@ -0,0 +1,156 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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", "Ant", 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.wizzard; | |||
| import javax.swing.JComponent; | |||
| /** | |||
| * Interface for classes defining a step in a wizzard. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public interface WizzardStep { | |||
| /** | |||
| * Set the step id. The id must be unique among steps within the wizzard. | |||
| * | |||
| * @param id Wizzard id. | |||
| */ | |||
| void setID(String id); | |||
| /** | |||
| * Get the step id. | |||
| * | |||
| * @return Step id. | |||
| */ | |||
| String getID(); | |||
| /** | |||
| * Set the step title. | |||
| * | |||
| * @param title Step title. | |||
| */ | |||
| void setTitle(String title); | |||
| /** | |||
| * Get the step title. | |||
| * | |||
| * @return Step title. | |||
| */ | |||
| String getTitle(); | |||
| /** | |||
| * Set the step description. | |||
| * | |||
| * @param desc Step description. | |||
| */ | |||
| void setDescription(String desc); | |||
| /** | |||
| * Get the step description. | |||
| * | |||
| * @return Step description. | |||
| */ | |||
| String getDescription(); | |||
| /** | |||
| * Set the default id of the next step. | |||
| * | |||
| * @param nextID ID of next step. | |||
| */ | |||
| void setNext(String nextID); | |||
| /** | |||
| * Get the id of the next step. | |||
| * | |||
| * @return ID of next step. | |||
| */ | |||
| String getNext(); | |||
| /** | |||
| * Set the default id of the previous step. | |||
| * | |||
| * @param prevID ID of previous step. | |||
| */ | |||
| void setPrevious(String prevID); | |||
| /** | |||
| * Get the id of the previous step. | |||
| * | |||
| * @return Previous step. | |||
| */ | |||
| String getPrevious(); | |||
| /** | |||
| * Set the data model object that the step will edit. It is assumed | |||
| * that all steps initialized within a single wizzard agree on the | |||
| * data model type. | |||
| * | |||
| * @param model Data model to edit. | |||
| */ | |||
| void setDataModel(Object model); | |||
| /** | |||
| * Get the data model that should be passeed on to the next step. | |||
| * | |||
| * @return Current data model. | |||
| */ | |||
| Object getDataModel(); | |||
| /** | |||
| * Get the component that should be displayed to the user for | |||
| * editing the model. This component should <b>not</b> include the | |||
| * title and text display, which is handled by the wizzard container. | |||
| * | |||
| * @return Editing component. | |||
| */ | |||
| JComponent getEditorComponent(); | |||
| } | |||
| @@ -54,8 +54,11 @@ | |||
| package org.apache.tools.ant.gui; | |||
| import org.apache.tools.ant.gui.core.*; | |||
| import org.apache.tools.ant.gui.util.XMLHelper; | |||
| import org.apache.tools.ant.gui.wizzard.Wizzard; | |||
| import org.apache.tools.ant.gui.wizzard.WizzardListener; | |||
| import org.apache.tools.ant.gui.command.LoadFileCmd; | |||
| import org.apache.tools.ant.gui.event.EventBus; | |||
| import org.apache.tools.ant.gui.acs.ACSFactory; | |||
| import javax.swing.*; | |||
| import java.awt.BorderLayout; | |||
| import java.io.File; | |||
| @@ -75,27 +78,62 @@ public class Main { | |||
| public static void main(String[] args) { | |||
| XMLHelper.init(); | |||
| Args settings = new Args(args); | |||
| try { | |||
| JFrame f = new JFrame("Antidote"); | |||
| f.setDefaultCloseOperation(3 /*JFrame.EXIT_ON_CLOSE*/); | |||
| AppContext context = new AppContext(f); | |||
| EventResponder resp = new EventResponder(context); | |||
| Antidote gui = new Antidote(context); | |||
| f.setDefaultCloseOperation(3 /*JFrame.EXIT_ON_CLOSE*/); | |||
| JMenuBar menu = context.getActions().createMenuBar(); | |||
| f.setJMenuBar(menu); | |||
| f.getContentPane().add(BorderLayout.CENTER, gui); | |||
| f.getContentPane().add(BorderLayout.NORTH, | |||
| context.getActions().createToolBar()); | |||
| if(!settings.isWizzardMode()) { | |||
| EventResponder resp = new EventResponder(context); | |||
| Antidote gui = new Antidote(context); | |||
| // Add the project selection menu. | |||
| ProjectSelectionMenu ps = new ProjectSelectionMenu(context); | |||
| ps.insertInto(menu); | |||
| JMenuBar menu = context.getActions().createMenuBar(); | |||
| f.setJMenuBar(menu); | |||
| f.getContentPane().add(BorderLayout.CENTER, gui); | |||
| f.getContentPane().add(BorderLayout.NORTH, | |||
| context.getActions().createToolBar()); | |||
| // Add the project selection menu. | |||
| ProjectSelectionMenu ps = new ProjectSelectionMenu(context); | |||
| ps.insertInto(menu); | |||
| // Add debugging items. | |||
| if(settings.isDebugMode()) { | |||
| context.getEventBus().addMember( | |||
| EventBus.VETOING, new EventDebugMonitor()); | |||
| } | |||
| // Add debugging items. | |||
| if(context.isDebugOn()) { | |||
| context.getEventBus().addMember( | |||
| EventBus.VETOING, new EventDebugMonitor()); | |||
| // Load a build file if one is provided. | |||
| if(settings.getBuildFile() != null) { | |||
| LoadFileCmd load = new LoadFileCmd(context); | |||
| load.setFile(new File(settings.getBuildFile())); | |||
| load.run(); | |||
| } | |||
| } | |||
| else { | |||
| // We are in wizzard mode. Create it. | |||
| ResourceManager resources = new ResourceManager( | |||
| "org.apache.tools.ant.gui.resources.buildFileWizzard"); | |||
| Wizzard wiz = new Wizzard( | |||
| resources, ACSFactory.getInstance().createProject()); | |||
| // XXX this is temporary for testing. Eventually | |||
| // it will launch the regular antidote screen with the | |||
| // results of the wizzard. | |||
| wiz.addWizzardListener(new WizzardListener() { | |||
| public void finished(Object model) { | |||
| System.out.println(model); | |||
| System.exit(0); | |||
| } | |||
| public void canceled() { | |||
| System.exit(0); | |||
| } | |||
| }); | |||
| f.getContentPane().add(BorderLayout.CENTER, wiz); | |||
| } | |||
| ImageIcon icon = | |||
| @@ -106,17 +144,10 @@ public class Main { | |||
| else { | |||
| System.out.println("Application icon not found."); | |||
| } | |||
| f.pack(); | |||
| f.pack(); | |||
| f.setVisible(true); | |||
| // XXX this will change once full command line argument parsing | |||
| // is supported. | |||
| if(args.length > 0) { | |||
| LoadFileCmd load = new LoadFileCmd(context); | |||
| load.setFile(new File(args[0])); | |||
| load.run(); | |||
| } | |||
| } | |||
| catch(Exception ex) { | |||
| ex.printStackTrace(); | |||
| @@ -159,16 +159,6 @@ public class AppContext { | |||
| public SelectionManager getSelectionManager() { | |||
| return _selectionManager; | |||
| } | |||
| /** | |||
| * Determine if debug mode is turned on. | |||
| * | |||
| * @return True if in debug mode, false otherwise. | |||
| */ | |||
| public boolean isDebugOn() { | |||
| return _resources.getBoolean("debug"); | |||
| } | |||
| } | |||
| @@ -99,6 +99,19 @@ public class ResourceManager { | |||
| _resources = ResourceBundle.getBundle(propName); | |||
| } | |||
| /** | |||
| * Generate a composit key from the given class and key name. | |||
| * | |||
| * @param clazz Class to find resource for. | |||
| * @param name Name of the resource. | |||
| * @return Composite key. | |||
| */ | |||
| private String getKey(Class clazz, String name) { | |||
| name = name == null ? "" : name; | |||
| return clazz == null ? name : clazz.getName() + "." + name; | |||
| } | |||
| /** | |||
| * Get non-qualified String resource. | |||
| * | |||
| @@ -121,7 +134,12 @@ public class ResourceManager { | |||
| return null; | |||
| } | |||
| return _resources.getString(getKey(clazz, name)); | |||
| try { | |||
| return _resources.getString(getKey(clazz, name)); | |||
| } | |||
| catch(MissingResourceException ex) { | |||
| return null; | |||
| } | |||
| } | |||
| /** | |||
| @@ -156,7 +174,12 @@ public class ResourceManager { | |||
| } | |||
| if(toTok == null) { | |||
| return _resources.getStringArray(key); | |||
| try { | |||
| return _resources.getStringArray(key); | |||
| } | |||
| catch(MissingResourceException ex) { | |||
| return null; | |||
| } | |||
| } | |||
| else { | |||
| StringTokenizer tok = new StringTokenizer(toTok, ", "); | |||
| @@ -201,25 +224,45 @@ public class ResourceManager { | |||
| value = _resources.getString(key); | |||
| } | |||
| catch(MissingResourceException ex) { | |||
| // Ignore missing resources as they imply false. | |||
| return false; | |||
| } | |||
| return value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"); | |||
| } | |||
| /** | |||
| * Generate a composit key from the given class and key name. | |||
| * Get the non-qualified Class type resource for the given key. | |||
| * | |||
| * @param clazz Class to find resource for. | |||
| * @param name Name of the resourdce. | |||
| * @return Class associated with the key name. | |||
| */ | |||
| public Class getClass(String name) | |||
| throws ClassNotFoundException { | |||
| return getClass(null, name); | |||
| } | |||
| /** | |||
| * Get the Class type resource for the given class and key name. | |||
| * | |||
| * @param clazz Class requesting the resource. | |||
| * @param name Name of the resource. | |||
| * @return Composite key. | |||
| * @return Class associated with the key name. | |||
| */ | |||
| private String getKey(Class clazz, String name) { | |||
| name = name == null ? "" : name; | |||
| public Class getClass(Class clazz, String name) | |||
| throws ClassNotFoundException { | |||
| String key = getKey(clazz, name); | |||
| try { | |||
| String value = _resources.getString(key); | |||
| return Class.forName(value); | |||
| } | |||
| catch(MissingResourceException ex) { | |||
| return null; | |||
| } | |||
| return clazz == null ? name : clazz.getName() + "." + name; | |||
| } | |||
| /** | |||
| * Generate a localized message using the given set of arguments to | |||
| * format the message with. | |||
| @@ -0,0 +1,7 @@ | |||
| # Property file for the command-line strings used by the Args class. | |||
| usage=usage: antidote [-help] [-wizzard] [-debug] [build-file]\n\ | |||
| \nReport bugs to http://jakarta.apache.org/site/bugs.html\n\ | |||
| Copyright (C) 2001 Apache Software Foundation. All rights reserved. | |||
| invalidArg=Unrecognized argument: "{0}" | |||
| @@ -0,0 +1,18 @@ | |||
| # Property file for the wizzard used to create a new build file. | |||
| steps=start, finish | |||
| next=Next >> | |||
| back=<< Back | |||
| cancel=Cancel | |||
| finish=Finish | |||
| start.editor=org.apache.tools.ant.gui.wizzard.InstructionStep | |||
| start.title=Create new build file | |||
| start.description=This wizzard will step you through the process of creating \ | |||
| a basic Ant build file for your project. | |||
| finish.editor=org.apache.tools.ant.gui.wizzard.InstructionStep | |||
| finish.title=Complete build file | |||
| finish.description=Click "Finish" to save your build file definition. | |||