You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by me...@apache.org on 2001/01/16 19:35:35 UTC

cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard AbstractWizardStep.java ButtonNavigator.java InstructionStep.java NavigatorListener.java Wizard.java WizardListener.java WizardNavigator.java WizardStep.java

metasim     01/01/16 10:35:35

  Added:       src/antidote/org/apache/tools/ant/gui/wizard
                        AbstractWizardStep.java ButtonNavigator.java
                        InstructionStep.java NavigatorListener.java
                        Wizard.java WizardListener.java
                        WizardNavigator.java WizardStep.java
  Log:
  Successfully managed to expose myself to public embarassssment by mispellln'
  "wizzzerd" all over the place. :-(
  
  Revision  Changes    Path
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/AbstractWizardStep.java
  
  Index: AbstractWizardStep.java
  ===================================================================
  /*
   * 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.wizard;
  import org.apache.tools.ant.gui.core.ResourceManager;
  import javax.swing.JComponent;
  
  
  /**
   * Abstract class implementing the basic support for the WizardStep interface.
   * 
   * @version $Revision: 1.1 $ 
   * @author Simeon Fitch 
   */
  public abstract class  AbstractWizardStep extends JComponent 
      implements WizardStep {
      
      /** Flag to indicate whether or not init has been called. */
      private boolean _initialized = false;
      /** Resources. */
      private ResourceManager _resources = null;
      /** 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;
  
      /** 
       * Called when the instance should initialize its contents, e.g.
       * create the widgets, etc. When this is called then all
       * data values, including the ResourceManager, have been setup.
       * 
       */
      protected abstract void init();
  
      /** 
       * Set the step's resources.
       * 
       */
      public void setResources(ResourceManager resources) {
          _resources = resources;
      }
  
      /** 
       * Get the step's resources.
       * 
       * @return Resources.
       */
      protected ResourceManager getResources() {
          return _resources;
      }
  
      /** 
       * Set the step id. The id must be unique among steps within the wizard.
       * 
       * @param id Wizard 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 wizard 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 wizard container.
       * 
       * @return Editing component.
       */
      public JComponent getEditorComponent() {
          if(!_initialized) {
              init();
              _initialized = true;
          }
  
          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();
      }
  
  }
  
  
  
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/ButtonNavigator.java
  
  Index: ButtonNavigator.java
  ===================================================================
  /*
   * 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.wizard;
  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 WizardNavigator {
      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;
                  }
  
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/InstructionStep.java
  
  Index: InstructionStep.java
  ===================================================================
  /*
   * 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.wizard;
  import javax.swing.*;
  import java.awt.BorderLayout;
  import java.awt.Font;
  import java.awt.Insets;
  
  /**
   * Wizard step whose only purpose is to display some text.
   * 
   * @version $Revision: 1.1 $ 
   * @author Simeon Fitch 
   */
  public class InstructionStep extends AbstractWizardStep {
  
      /** 
       * Initialize the contents of the container.
       * 
       */
      protected void init() {
          setLayout(new BorderLayout());
          String msg = getResources().getString(getID() + ".instructions");
  
          JTextArea text = new JTextArea(msg);
          text.setMargin(new Insets(30, 20, 5, 5));
          text.setOpaque(false);
          text.setFont(new Font("Serif", Font.PLAIN, 18));
          text.setEditable(false);
          text.setLineWrap(true);
          text.setWrapStyleWord(true);
          add(text);
      }
  
      /** 
       * Called when the step should refresh its display based on the 
       * current model setting.
       * 
       */
      public void updateDisplay() {
          // NOOP
      }
      /** 
       * Called when the step should update the data model based on the
       * settings of its widgets.
       * 
       */
      public void updateDataModel() {
          // NOOP
      }
  }
  
  
  
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/NavigatorListener.java
  
  Index: NavigatorListener.java
  ===================================================================
  /*
   * 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.wizard;
  
  /**
   * Interface for classes interested in events from the WizardNavigator.
   * 
   * @version $Revision: 1.1 $ 
   * @author Simeon Fitch 
   */
  public interface NavigatorListener {
      /** 
       * Called when the wizard should show the next step.
       * 
       */
      void nextStep();
      /** 
       * Called when the wizard should show the previous step.
       * 
       */
      void backStep();
      /** 
       * Called when the wizard should show the step with the given id.
       * 
       * @param stepID ID of step to show.
       */
      void gotoStep(String stepID);
      /** 
       * Called when the wizard activity shold be cancelled.
       * 
       */
      void cancel();
      /** 
       * Called when the wizard is finished.
       * 
       */
      void finish();
  }
  
  
  
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/Wizard.java
  
  Index: Wizard.java
  ===================================================================
  /*
   * 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.wizard;
  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.awt.Insets;
  import java.util.*;
  
  /**
   * Top level container and controller for wizard-type GUI.
   * 
   * @version $Revision: 1.1 $ 
   * @author Simeon Fitch 
   */
  public class Wizard extends JComponent {
      /** Resources defining the wizard 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();
      /** Steps saved in a list to preserve ordering. */
      private List _stepOrdering = new ArrayList();
      /** Description text. XXX should probably change to some other widget. */
      private JTextArea _description = null;
      /** Progress meter. */
      private JProgressBar _progress = null;
      /** Widget for navigating through steps. */
      private WizardNavigator _nav = null;
      /** The data model to pass on to each step. */
      private Object _model = null;
      /** The current Wizard step. */
      private WizardStep _curr = null;
      /** The set of wizard listeners. */
      private List _listeners = new ArrayList(1);
  
      /** 
       * Standard ctor.
       * 
       * @param resources Wizard definition resources
       * @param dataModel Initial data model.
       */
      public Wizard(ResourceManager resources, Object dataModel) {
          setLayout(new BorderLayout());
          _resources = resources;
          _model = dataModel;
  
          _progress = new JProgressBar();
          _progress.setBorder(BorderFactory.createTitledBorder(
              _resources.getString("progress")));
          _progress.setStringPainted(true);
          add(_progress, BorderLayout.NORTH);
  
          _description = new JTextArea();
          _description.setMargin(new Insets(5, 5, 5, 5));
          _description.setPreferredSize(new Dimension(100, 100));
          _description.setOpaque(true);
          _description.setFont(new Font("Serif", Font.PLAIN, 12));
          _description.setEditable(false);
          _description.setLineWrap(true);
          _description.setWrapStyleWord(true);
  
          JScrollPane scroller = new JScrollPane(
              _description, 
              JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 
              JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 
  
          scroller.setBorder(BorderFactory.createTitledBorder(
              _resources.getString("help")));
          add(scroller, BorderLayout.WEST);
  
          _stepContainer = new JPanel(_layout = new CardLayout());
          _stepContainer.setBorder(BorderFactory.createEtchedBorder());
          _stepContainer.setPreferredSize(new Dimension(400, 400));
  
  
          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");
          _progress.setMaximum(steps.length - 1);
          try {
              for(int i = 0; i < steps.length; i++) {
                  Class type = _resources.getClass(steps[i] + ".editor");
                  WizardStep step = (WizardStep) type.newInstance();
                  step.setResources(_resources);
                  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);
                  _stepOrdering.add(step);
                  _stepContainer.add(step.getEditorComponent(), steps[i]);
              }
              // Initialize the first screen with the data model.
              if(steps.length > 0) {
                  WizardStep first = (WizardStep)_steps.get(steps[0]);
                  first.setDataModel(_model);
                  _curr = first;
                  showStep(first);
              }
          }
          catch(Exception ex) {
              // If we get here then the wizard didn't initialize properly.
              // XXX log me.
              ex.printStackTrace();
          }
  
      }
  
      /** 
       * Add a wizard listener.
       * 
       * @param l Listener to add.
       */
      public void addWizardListener(WizardListener l) {
          _listeners.add(l);
      }
  
      /** 
       * Remove a wizard listener.
       * 
       * @param l Listener to remove.
       */
      public void removeWizardListener(WizardListener l) {
          _listeners.remove(l);
      }
  
      /** 
       * Go to the given step.
       * 
       * @param step Step to go to.
       */
      private void showStep(WizardStep step) {
          if(step == null) return;
  
          // Transfer data model (in case step wants to create a new one.
          _curr.updateDataModel();
          step.setDataModel(_curr.getDataModel());
          
          // Update the title and description.
          _stepContainer.setBorder(
              BorderFactory.createTitledBorder(step.getTitle()));
          _description.setText(step.getDescription());
  
          _nav.setBackEnabled(step.getPrevious() != null);
          _nav.setNextEnabled(step.getNext() != null);
          _nav.setFinishEnabled(step.getNext() == null);
          _progress.setValue(_stepOrdering.indexOf(step));
  
          // Tell the step to refresh its display based on the data model.
          step.updateDisplay();
  
          // Display the step.
          _layout.show(_stepContainer, step.getID());
  
          _curr = step;
      }
  
      /** Handler for actions invoked by wizard. */
      private class NavHandler implements NavigatorListener {
          public void nextStep() {
              String nextID = _curr.getNext();
              if(nextID != null) {
                  showStep((WizardStep)_steps.get(nextID));
              }
          }
          public void backStep() {
              String prevID = _curr.getPrevious();
              if(prevID != null) {
                  showStep((WizardStep)_steps.get(prevID));
              }
          }
          public void gotoStep(String stepID){
              showStep((WizardStep) _steps.get(stepID));
          }
          public void cancel() {
              Iterator it = _listeners.iterator();
              while(it.hasNext()) {
                  WizardListener l = (WizardListener) it.next();
                  l.canceled();
              }
          }
          public void finish() {
              Iterator it = _listeners.iterator();
              while(it.hasNext()) {
                  WizardListener l = (WizardListener) it.next();
                  l.finished(_curr.getDataModel());
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/WizardListener.java
  
  Index: WizardListener.java
  ===================================================================
  /*
   * 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.wizard;
  
  
  /**
   * Interface for classes desiring notifiction of when the user
   * completes his/her use of wizard.
   * 
   * @version $Revision: 1.1 $ 
   * @author Simeon Fitch 
   */
  public interface WizardListener {
      /** 
       * 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();  
  }
  
  
  
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/WizardNavigator.java
  
  Index: WizardNavigator.java
  ===================================================================
  /*
   * 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.wizard;
  
  /**
   * Interface for classes that control the movement from one step of a 
   * wizard to another.
   * 
   * @version $Revision: 1.1 $ 
   * @author Simeon Fitch 
   */
  public interface WizardNavigator {
      /** 
       * 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);
  }
  
  
  
  1.1                  jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/WizardStep.java
  
  Index: WizardStep.java
  ===================================================================
  /*
   * 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.wizard;
  import org.apache.tools.ant.gui.core.ResourceManager;
  import javax.swing.JComponent;
  
  
  /**
   * Interface for classes defining a step in a wizard.
   * 
   * @version $Revision: 1.1 $ 
   * @author Simeon Fitch 
   */
  public interface WizardStep {
      /** 
       * Set the step's resources.
       * 
       */
      void setResources(ResourceManager resources);
  
      /** 
       * Set the step id. The id must be unique among steps within the wizard.
       * 
       * @param id Wizard 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 wizard 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 wizard container.
       * 
       * @return Editing component.
       */
      JComponent getEditorComponent();
  
      /** 
       * Called when the step should refresh its display based on the 
       * current model setting.
       * 
       */
      void updateDisplay();
  
      /** 
       * Called when the step should update the data model based on the
       * settings of its widgets.
       * 
       */
      void updateDataModel();
  
  }