git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268454 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -52,6 +52,7 @@ | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.gui.wizzard; | |||
| import org.apache.tools.ant.gui.core.ResourceManager; | |||
| import javax.swing.JComponent; | |||
| @@ -64,6 +65,10 @@ import javax.swing.JComponent; | |||
| public abstract class AbstractWizzardStep extends JComponent | |||
| implements WizzardStep { | |||
| /** 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. */ | |||
| @@ -77,6 +82,31 @@ public abstract class AbstractWizzardStep extends JComponent | |||
| /** 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 wizzard. | |||
| * | |||
| @@ -195,6 +225,11 @@ public abstract class AbstractWizzardStep extends JComponent | |||
| * @return Editing component. | |||
| */ | |||
| public JComponent getEditorComponent() { | |||
| if(!_initialized) { | |||
| init(); | |||
| _initialized = true; | |||
| } | |||
| return this; | |||
| } | |||
| @@ -53,6 +53,9 @@ | |||
| */ | |||
| package org.apache.tools.ant.gui.wizzard; | |||
| import javax.swing.*; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.Font; | |||
| import java.awt.Insets; | |||
| /** | |||
| * Wizzard step whose only purpose is to display some text. | |||
| @@ -62,4 +65,38 @@ import javax.swing.*; | |||
| */ | |||
| public class InstructionStep extends AbstractWizzardStep { | |||
| /** | |||
| * 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 | |||
| } | |||
| } | |||
| @@ -60,6 +60,7 @@ import java.awt.BorderLayout; | |||
| import java.awt.CardLayout; | |||
| import java.awt.Dimension; | |||
| import java.awt.Font; | |||
| import java.awt.Insets; | |||
| import java.util.*; | |||
| /** | |||
| @@ -78,8 +79,12 @@ public class Wizzard extends JComponent { | |||
| 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 WizzardNavigator _nav = null; | |||
| /** The data model to pass on to each step. */ | |||
| @@ -100,21 +105,35 @@ public class Wizzard extends JComponent { | |||
| _resources = resources; | |||
| _model = dataModel; | |||
| TitledBorder border = new TitledBorder("Border"); | |||
| setBorder(border); | |||
| _progress = new JProgressBar(); | |||
| _progress.setBorder(BorderFactory.createTitledBorder( | |||
| _resources.getString("progress"))); | |||
| _progress.setStringPainted(true); | |||
| add(_progress, BorderLayout.NORTH); | |||
| _description = new JTextArea(4, 40); | |||
| _description.setBorder(BorderFactory.createEtchedBorder()); | |||
| _description.setOpaque(false); | |||
| _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); | |||
| add(_description, BorderLayout.NORTH); | |||
| 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); | |||
| @@ -123,10 +142,12 @@ public class Wizzard extends JComponent { | |||
| 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"); | |||
| WizzardStep step = (WizzardStep) type.newInstance(); | |||
| step.setResources(_resources); | |||
| step.setID(steps[i]); | |||
| step.setTitle(_resources.getString(steps[i]+ ".title")); | |||
| step.setDescription( | |||
| @@ -141,6 +162,7 @@ public class Wizzard extends JComponent { | |||
| 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. | |||
| @@ -157,8 +179,6 @@ public class Wizzard extends JComponent { | |||
| ex.printStackTrace(); | |||
| } | |||
| setPreferredSize(new Dimension(500, 400)); | |||
| } | |||
| /** | |||
| @@ -188,22 +208,26 @@ public class Wizzard extends JComponent { | |||
| 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. | |||
| TitledBorder border = (TitledBorder) getBorder(); | |||
| border.setTitle(step.getTitle()); | |||
| _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 wizzard. */ | |||
| @@ -52,6 +52,7 @@ | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.gui.wizzard; | |||
| import org.apache.tools.ant.gui.core.ResourceManager; | |||
| import javax.swing.JComponent; | |||
| @@ -62,6 +63,12 @@ import javax.swing.JComponent; | |||
| * @author Simeon Fitch | |||
| */ | |||
| public interface WizzardStep { | |||
| /** | |||
| * Set the step's resources. | |||
| * | |||
| */ | |||
| void setResources(ResourceManager resources); | |||
| /** | |||
| * Set the step id. The id must be unique among steps within the wizzard. | |||
| * | |||
| @@ -153,4 +160,19 @@ public interface WizzardStep { | |||
| * @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(); | |||
| } | |||
| @@ -0,0 +1,112 @@ | |||
| /* | |||
| * 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.build; | |||
| import org.apache.tools.ant.gui.wizzard.AbstractWizzardStep; | |||
| import javax.swing.*; | |||
| import java.awt.BorderLayout; | |||
| import java.awt.FlowLayout; | |||
| import java.awt.GridBagLayout; | |||
| import org.apache.tools.ant.gui.acs.*; | |||
| /** | |||
| * Build file wizzard step for naming the project and | |||
| * selecting what features are desired. | |||
| * | |||
| * @version $Revision$ | |||
| * @author Simeon Fitch | |||
| */ | |||
| public class ProjectSetupStep extends AbstractWizzardStep { | |||
| /** Name of the project. */ | |||
| private JTextField _name = null; | |||
| protected void init() { | |||
| setLayout(new BorderLayout()); | |||
| JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT)); | |||
| add(p, BorderLayout.NORTH); | |||
| _name = new JTextField(10); | |||
| p.add(new JLabel(getResources().getString(getID() + ".nameLabel"))); | |||
| p.add(_name); | |||
| p = new JPanel(new GridBagLayout()); | |||
| p.setBorder(BorderFactory.createTitledBorder( | |||
| getResources().getString(getID() + ".optionsLabel"))); | |||
| add(p, BorderLayout.CENTER); | |||
| } | |||
| /** | |||
| * Called when the step should refresh its display based on the | |||
| * current model setting. | |||
| * | |||
| */ | |||
| public void updateDisplay() { | |||
| ACSProjectElement project = (ACSProjectElement) getDataModel(); | |||
| _name.setText(project.getName()); | |||
| } | |||
| /** | |||
| * Called when the step should update the data model based on the | |||
| * settings of its widgets. | |||
| * | |||
| */ | |||
| public void updateDataModel() { | |||
| ACSProjectElement project = (ACSProjectElement) getDataModel(); | |||
| project.setName(_name.getText()); | |||
| } | |||
| } | |||
| @@ -1,18 +1,49 @@ | |||
| # Property file for the wizzard used to create a new build file. | |||
| steps=start, finish | |||
| ########################################################### | |||
| # Define required properties for wizzard. | |||
| ########################################################### | |||
| next=Next >> | |||
| back=<< Back | |||
| cancel=Cancel | |||
| finish=Finish | |||
| progress=Progress | |||
| help=Help | |||
| ########################################################### | |||
| # Define the steps the comprise the wizzard. | |||
| ########################################################### | |||
| steps=start, setup, finish | |||
| ########################################################### | |||
| # Step 1 | |||
| ########################################################### | |||
| 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. | |||
| start.instructions=Welcome to the Ant build file wizzard!\n\ | |||
| You will be asked a series of questions about the project you wish to create\ | |||
| and the types of build options you want included.\n\n\ | |||
| Click "Next >>" to proceed. | |||
| ########################################################### | |||
| # Step 2 | |||
| ########################################################### | |||
| setup.editor=org.apache.tools.ant.gui.wizzard.build.ProjectSetupStep | |||
| setup.title=Setup project | |||
| setup.description=Give the project a name, and select the features you \ | |||
| wish to be included in the project file, such as JavaDoc and JAR creation. | |||
| setup.nameLabel=Project Name: | |||
| setup.optionsLabel=Options | |||
| ########################################################### | |||
| # Last step | |||
| ########################################################### | |||
| finish.editor=org.apache.tools.ant.gui.wizzard.InstructionStep | |||
| finish.title=Complete build file | |||
| finish.description=Click "Finish" to save your build file definition. | |||
| finish.instructions=You are done!\n\nClick "Finish" to complete your new\ | |||
| build file. | |||