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/17 23:23:33 UTC
cvs commit: jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard DefaultStateMachine.java StateMachine.java WizardData.java AbstractWizardStep.java Wizard.java WizardStep.java
metasim 01/01/17 14:23:33
Modified: src/antidote/org/apache/tools/ant/gui/wizard
AbstractWizardStep.java Wizard.java WizardStep.java
Added: src/antidote/org/apache/tools/ant/gui/wizard
DefaultStateMachine.java StateMachine.java
WizardData.java
Log:
Added more panels to build wizard, and created state machine framework.
Revision Changes Path
1.2 +24 -47 jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/AbstractWizardStep.java
Index: AbstractWizardStep.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/AbstractWizardStep.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractWizardStep.java 2001/01/16 18:35:32 1.1
+++ AbstractWizardStep.java 2001/01/17 22:23:31 1.2
@@ -59,7 +59,7 @@
/**
* Abstract class implementing the basic support for the WizardStep interface.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Simeon Fitch
*/
public abstract class AbstractWizardStep extends JComponent
@@ -76,11 +76,7 @@
/** 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;
+ private WizardData _model = null;
/**
* Called when the instance should initialize its contents, e.g.
@@ -161,50 +157,15 @@
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) {
+ public void setDataModel(WizardData model) {
_model = model;
}
@@ -213,7 +174,7 @@
*
* @return Current data model.
*/
- public Object getDataModel() {
+ public WizardData getDataModel() {
return _model;
}
@@ -234,6 +195,26 @@
}
/**
+ * Get the id of the next step.
+ *
+ * @return ID of next step.
+ */
+ public String getNext() {
+ return getDataModel().getStateMachine().getNext(
+ this, getDataModel());
+ }
+
+ /**
+ * Get the id of the previous step.
+ *
+ * @return Previous step.
+ */
+ public String getPrevious() {
+ return getDataModel().getStateMachine().getPrevious(
+ this, getDataModel());
+ }
+
+ /**
* Get a string representation of this.
*
* @return String representation.
@@ -242,10 +223,6 @@
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.2 +27 -31 jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/Wizard.java
Index: Wizard.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/Wizard.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Wizard.java 2001/01/16 18:35:33 1.1
+++ Wizard.java 2001/01/17 22:23:31 1.2
@@ -66,13 +66,12 @@
/**
* Top level container and controller for wizard-type GUI.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Simeon Fitch
*/
public class Wizard extends JComponent {
- /** Resources defining the wizard contents. Separate from the
- * application context resources. */
- private ResourceManager _resources = null;
+ /** The data model to pass on to each step. */
+ private WizardData _data = null;
/** Container for the step editors. */
private JPanel _stepContainer = null;
/** Layout manager for all the step panels. */
@@ -87,8 +86,6 @@
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. */
@@ -97,17 +94,15 @@
/**
* Standard ctor.
*
- * @param resources Wizard definition resources
- * @param dataModel Initial data model.
+ * @param data Data for the wizard.
*/
- public Wizard(ResourceManager resources, Object dataModel) {
+ public Wizard(WizardData data) {
setLayout(new BorderLayout());
- _resources = resources;
- _model = dataModel;
+ _data = data;
_progress = new JProgressBar();
_progress.setBorder(BorderFactory.createTitledBorder(
- _resources.getString("progress")));
+ _data.getResources().getString("progress")));
_progress.setStringPainted(true);
add(_progress, BorderLayout.NORTH);
@@ -126,7 +121,7 @@
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroller.setBorder(BorderFactory.createTitledBorder(
- _resources.getString("help")));
+ _data.getResources().getString("help")));
add(scroller, BorderLayout.WEST);
_stepContainer = new JPanel(_layout = new CardLayout());
@@ -136,30 +131,23 @@
add(_stepContainer, BorderLayout.CENTER);
- _nav = new ButtonNavigator(_resources);
+ _nav = new ButtonNavigator(_data.getResources());
_nav.addNavigatorListener(new NavHandler());
((ButtonNavigator)_nav).setBorder(BorderFactory.createEtchedBorder());
add((ButtonNavigator)_nav, BorderLayout.SOUTH);
- String[] steps = _resources.getStringArray("steps");
+ String[] steps = _data.getResources().getStringArray("steps");
_progress.setMaximum(steps.length - 1);
try {
for(int i = 0; i < steps.length; i++) {
- Class type = _resources.getClass(steps[i] + ".editor");
+ Class type = _data.getResources().getClass(steps[i] + ".editor");
WizardStep step = (WizardStep) type.newInstance();
- step.setResources(_resources);
+ step.setResources(_data.getResources());
step.setID(steps[i]);
- step.setTitle(_resources.getString(steps[i]+ ".title"));
+ step.setTitle(
+ _data.getResources().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);
+ _data.getResources().getString(steps[i]+ ".description"));
_steps.put(steps[i], step);
_stepOrdering.add(step);
@@ -168,7 +156,7 @@
// Initialize the first screen with the data model.
if(steps.length > 0) {
WizardStep first = (WizardStep)_steps.get(steps[0]);
- first.setDataModel(_model);
+ first.setDataModel(_data);
_curr = first;
showStep(first);
}
@@ -207,13 +195,13 @@
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()));
+ BorderFactory.createCompoundBorder(
+ BorderFactory.createTitledBorder(step.getTitle()),
+ BorderFactory.createEmptyBorder(5, 15, 5, 15)));
_description.setText(step.getDescription());
_nav.setBackEnabled(step.getPrevious() != null);
@@ -233,21 +221,28 @@
/** Handler for actions invoked by wizard. */
private class NavHandler implements NavigatorListener {
public void nextStep() {
+ // Called to give data model chance to make changes to what is next.
+ _curr.updateDataModel();
String nextID = _curr.getNext();
if(nextID != null) {
showStep((WizardStep)_steps.get(nextID));
}
}
public void backStep() {
+ // Called to give data model chance to make changes to what is
+ // before.
+ _curr.updateDataModel();
String prevID = _curr.getPrevious();
if(prevID != null) {
showStep((WizardStep)_steps.get(prevID));
}
}
public void gotoStep(String stepID){
+ _curr.updateDataModel();
showStep((WizardStep) _steps.get(stepID));
}
public void cancel() {
+ _curr.updateDataModel();
Iterator it = _listeners.iterator();
while(it.hasNext()) {
WizardListener l = (WizardListener) it.next();
@@ -255,6 +250,7 @@
}
}
public void finish() {
+ _curr.updateDataModel();
Iterator it = _listeners.iterator();
while(it.hasNext()) {
WizardListener l = (WizardListener) it.next();
1.2 +17 -30 jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/WizardStep.java
Index: WizardStep.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/WizardStep.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WizardStep.java 2001/01/16 18:35:34 1.1
+++ WizardStep.java 2001/01/17 22:23:32 1.2
@@ -59,7 +59,7 @@
/**
* Interface for classes defining a step in a wizard.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Simeon Fitch
*/
public interface WizardStep {
@@ -110,47 +110,20 @@
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);
+ void setDataModel(WizardData model);
/**
* Get the data model that should be passeed on to the next step.
*
* @return Current data model.
*/
- Object getDataModel();
+ WizardData getDataModel();
/**
* Get the component that should be displayed to the user for
@@ -174,5 +147,19 @@
*
*/
void updateDataModel();
+
+ /**
+ * Get the id of the next step.
+ *
+ * @return ID of next step.
+ */
+ String getNext();
+
+ /**
+ * Get the id of the previous step.
+ *
+ * @return Previous step.
+ */
+ String getPrevious();
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/DefaultStateMachine.java
Index: DefaultStateMachine.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 java.util.*;
/**
* A simple state machine based on the defined ordering of steps
* in the resources.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch
*/
public class DefaultStateMachine implements StateMachine {
/**
* Get the list of step IDs defined in the resources as a list.
*
* @param data Current wizard state.
* @return List of step IDs
*/
protected List getStepList(WizardData data) {
return Arrays.asList(data.getResources().getStringArray("steps"));
}
/**
* Get the next step.
*
* @param curr The current step.
* @param data The current state of the wizard.
* @return The ID of next step, or null if there currently isn't one.
*/
public String getNext(WizardStep curr, WizardData data) {
List steps = getStepList(data);
int nextIndex = steps.indexOf(curr.getID()) + 1;
if(nextIndex > 0 && nextIndex < steps.size()) {
return (String) steps.get(nextIndex);
}
return null;
}
/**
* Get the previous step.
*
* @param curr The current step.
* @param data The current state of the wizard.
* @return The ID of previous step, or null if there currently isn't one.
*/
public String getPrevious(WizardStep curr, WizardData data) {
List steps = getStepList(data);
int nextIndex = steps.indexOf(curr.getID()) - 1;
if(nextIndex > 0 && nextIndex < steps.size()) {
return (String) steps.get(nextIndex);
}
return null;
}
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/StateMachine.java
Index: StateMachine.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 the wizard state machine, responsible for determining the
* next step in the wizard.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch
*/
public interface StateMachine {
/**
* Get the next step.
*
* @param curr The current step.
* @param data The current state of the wizard.
* @return The next step, or null if there currently isn't one.
*/
String getNext(WizardStep curr, WizardData data);
/**
* Get the previous step.
*
* @param curr The current step.
* @param data The current state of the wizard.
* @return The previous step, or null if there currently isn't one.
*/
String getPrevious(WizardStep curr, WizardData data);
}
1.1 jakarta-ant/src/antidote/org/apache/tools/ant/gui/wizard/WizardData.java
Index: WizardData.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;
/**
* Interface for the wizard data model.
*
* @version $Revision: 1.1 $
* @author Simeon Fitch
*/
public interface WizardData {
/**
* Get access to the resources for the wizard.
*
* @return Wizard resources.
*/
ResourceManager getResources();
/**
* Get the class the determines what the next step should be.
*
* @return State machine.
*/
StateMachine getStateMachine();
}