2
* Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
package net.sf.antcontrib.input;
21
import org.apache.tools.ant.BuildException;
22
import org.apache.tools.ant.input.InputHandler;
23
import org.apache.tools.ant.input.InputRequest;
24
import org.apache.tools.ant.input.MultipleChoiceInputRequest;
27
* Prompts for user input using a JOptionPane. Developed for use with
28
* Antelope, migrated to ant-contrib Oct 2003.
30
* @author <a href="mailto:danson@germane-software.com">Dale Anson</a>
31
* @version $Revision: 1.3 $
34
public class GUIInputHandler implements InputHandler {
36
private Component parent = null;
38
public GUIInputHandler() {}
41
* @param parent the parent component to display the input dialog.
43
public GUIInputHandler( Component parent ) {
48
* Prompts and requests input. May loop until a valid input has
51
public void handleInput( InputRequest request ) throws BuildException {
53
if ( request instanceof MultipleChoiceInputRequest ) {
54
String prompt = request.getPrompt();
55
String title = "Select Input";
56
int optionType = JOptionPane.YES_NO_OPTION;
57
int messageType = JOptionPane.QUESTION_MESSAGE;
59
Object[] choices = ( ( MultipleChoiceInputRequest ) request ).getChoices().toArray();
60
Object initialChoice = null;
62
Object input = JOptionPane.showInputDialog(parent, prompt,
63
title, optionType, icon, choices, initialChoice);
65
throw new BuildException("User cancelled.");
66
request.setInput(input.toString());
67
} while (!request.isInputValid());
72
String input = JOptionPane.showInputDialog( parent, request.getPrompt() );
73
request.setInput( input );
74
} while ( !request.isInputValid() );