| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib.input; |
| 17 |
|
| 18 |
import java.awt.*; |
| 19 |
import javax.swing.*; |
| 20 |
|
| 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; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class GUIInputHandler implements InputHandler { |
| 35 |
|
| 36 |
private Component parent = null; |
| 37 |
|
| 38 |
public GUIInputHandler() {} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public GUIInputHandler( Component parent ) { |
| 44 |
this.parent = parent; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public void handleInput( InputRequest request ) throws BuildException { |
| 52 |
|
| 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; |
| 58 |
Icon icon = null; |
| 59 |
Object[] choices = ( ( MultipleChoiceInputRequest ) request ).getChoices().toArray(); |
| 60 |
Object initialChoice = null; |
| 61 |
do { |
| 62 |
Object input = JOptionPane.showInputDialog(parent, prompt, |
| 63 |
title, optionType, icon, choices, initialChoice); |
| 64 |
if (input == null) |
| 65 |
throw new BuildException("User cancelled."); |
| 66 |
request.setInput(input.toString()); |
| 67 |
} while (!request.isInputValid()); |
| 68 |
|
| 69 |
} |
| 70 |
else { |
| 71 |
do { |
| 72 |
String input = JOptionPane.showInputDialog( parent, request.getPrompt() ); |
| 73 |
request.setInput( input ); |
| 74 |
} while ( !request.isInputValid() ); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
} |