Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Delivered-To: moderator for ant-dev@jakarta.apache.org Received: (qmail 19297 invoked from network); 30 Nov 2000 16:32:38 -0000 Received: from demon-gw.synamic.co.uk (HELO speedy.synamic.co.uk) (194.70.193.66) by locus.apache.org with SMTP; 30 Nov 2000 16:32:38 -0000 Received: by speedy.synamic.co.uk with Internet Mail Service (5.5.2650.21) id ; Thu, 30 Nov 2000 16:29:53 -0000 Message-ID: From: Jeff Martin To: "'ant-dev@jakarta.apache.org'" Subject: RE: Prompt task Date: Thu, 30 Nov 2000 16:28:48 -0000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C05AEA.9DD17190" X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C05AEA.9DD17190 Content-Type: text/plain; charset="iso-8859-1" Doh, left off the file. ------_=_NextPart_000_01C05AEA.9DD17190 Content-Type: application/octet-stream; name="Prompt.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Prompt.java" package org.apache.tools.ant.taskdefs;=0A= =0A= import org.apache.tools.ant.*;=0A= import javax.swing.*;=0A= import java.util.*;=0A= import java.io.*;=0A= =0A= public class Prompt extends Task{=0A= private String property =3D null;=0A= private String type =3D null;=0A= private String mode =3D null;=0A= private Vector list =3D new Vector();=0A= =0A= public void execute() throws BuildException{=0A= if(property=3D=3Dnull)throw new BuildException("property must = be set.", location);=0A= String value =3D project.getProperty(property);=0A= =0A= Prompter p;=0A= if(mode!=3Dnull&&mode.equals("gui")){=0A= p =3D new SwingPrompt();=0A= }else{=0A= p =3D new CommandLinePrompt();=0A= }=0A= value =3D p.prompt();=0A= =0A= if(value!=3Dnull)=0A= project.setProperty( property, value);=0A= =0A= =0A= }=0A= public void setProperty(String property){=0A= this.property =3D property;=0A= }=0A= public void setType(String type){=0A= this.type =3D type;=0A= }=0A= public void setMode(String mode){=0A= this.mode =3D mode;=0A= }=0A= public Value createValue(){=0A= Value value =3D new Value();=0A= list.addElement(value);=0A= return value;=0A= }=0A= public class Value{=0A= private String value =3D null;=0A= private String label =3D null;=0A= public void setLabel(String label){=0A= this.label=3Dlabel;=0A= }=0A= public void setValue(String value){=0A= this.value=3Dvalue;=0A= }=0A= public String getLabel(){=0A= return label;=0A= }=0A= public String getValue(){=0A= return value;=0A= }=0A= public String toString(){=0A= if(label!=3Dnull)=0A= return label;=0A= return value;=0A= }=0A= }=0A= private interface Prompter{=0A= public String prompt() throws BuildException;=0A= }=0A= private class SwingPrompt implements Prompter{=0A= public String prompt() throws BuildException{=0A= String value =3D null;=0A= if(type=3D=3Dnull||type.equals("plain")){=0A= value =3D (String)JOptionPane.showInputDialog(=0A= null,=0A= "Set value for " + property,=0A= "Ant",=0A= 3,=0A= null,=0A= null,=0A= value=0A= );=0A= }else if(type.equals("file")){=0A= JFileChooser chooser =3D new JFileChooser();=0A= chooser.showDialog(null, "Select file");=0A= = chooser.setFileSelectionMode(chooser.FILES_AND_DIRECTORIES);=0A= if(chooser.getCurrentDirectory()!=3Dnull)=0A= value =3D = chooser.getCurrentDirectory().getName();=0A= if(chooser.getSelectedFile()!=3Dnull)=0A= value =3D chooser.getSelectedFile().getName();=0A= }else if(type.equals("list")){=0A= Object[] o =3D list.toArray(new = Object[list.size()]);=0A= Value v =3D (Value)JOptionPane.showInputDialog(=0A= null,=0A= "Set value for " + property,=0A= "Ant",=0A= 3,=0A= null,=0A= o,=0A= value=0A= );=0A= if(v!=3Dnull)=0A= value =3D v.getValue();=0A= }=0A= return value;=0A= }=0A= }=0A= private class CommandLinePrompt implements Prompter{=0A= public String prompt() throws BuildException{=0A= String value =3D null;=0A= = if(type=3D=3Dnull||type.equals("plain")||type.equals("file")){=0A= System.out.print("Enter value for " + property + ": = ");=0A= BufferedReader in =3D new BufferedReader(new = InputStreamReader(System.in));=0A= try{=0A= value =3D in.readLine();=0A= }catch(Exception e){=0A= throw new BuildException(e);=0A= }=0A= }else if(type.equals("list")){=0A= int i=3D0;=0A= for(Enumeration e =3D = list.elements();e.hasMoreElements();){=0A= System.out.println(++i+": "+ e.nextElement());=0A= }=0A= System.out.println("Enter the number of the desired = value: ");=0A= BufferedReader in =3D new BufferedReader(new = InputStreamReader(System.in));=0A= try{=0A= value =3D in.readLine();=0A= }catch(Exception e){=0A= throw new BuildException(e);=0A= }=0A= try{=0A= = value=3D((Value)list.elementAt(Integer.parseInt(value)-1)).getValue();=0A= }catch(Exception e){=0A= //e.printStackTrace();=0A= }=0A= }=0A= return value;=0A= }=0A= }=0A= }=0A= ------_=_NextPart_000_01C05AEA.9DD17190--