FileDocCategorySizeDatePackage
DialogBoxTask.javaAPI DocExample4225Wed Aug 07 19:33:18 BST 2002com.oreilly.javaxp.ant

DialogBoxTask

public class DialogBoxTask extends org.apache.tools.ant.Task
A custom Ant task that shows a graphical dialog box with a message.
author
Eric M. Burke
version
$Id: DialogBoxTask.java,v 1.1 2002/08/08 00:33:19 jepc Exp $

Fields Summary
private String
message
private String
title
private int
optionType
private String
propertyName
Constructors Summary
Methods Summary
public voidaddText(java.lang.String msg)

        if (message == null) {
            message = "";
        }
        // we must manually replace properties for nested text
        message += ProjectHelper.replaceProperties(
                getProject(), msg, getProject().getProperties());
    
public voidexecute()

        validateAttributes();

        log("optionType = " + optionType, Project.MSG_DEBUG);

        if (optionType == -1) {
            JOptionPane.showMessageDialog(
                    null, // parent
                    message,
                    title,
                    JOptionPane.INFORMATION_MESSAGE);
        } else {
            int response = JOptionPane.showConfirmDialog(
                    null, // parent
                    message,
                    title,
                    optionType,
                    JOptionPane.QUESTION_MESSAGE);
            if (propertyName != null) {
                String responseText = formatResponseCode(response);
                log("Setting " + propertyName + " to " + responseText,
                        Project.MSG_VERBOSE);
                getProject().setProperty(propertyName, responseText);
            }
        }
    
private java.lang.StringformatResponseCode(int optionPaneResponse)

        switch (optionPaneResponse) {
            // note: JOptionPane.OK_OPTION is the same as YES_OPTION
            case JOptionPane.YES_OPTION:
                return "yes";
            case JOptionPane.NO_OPTION:
                return "no";
            case JOptionPane.CANCEL_OPTION:
            case JOptionPane.CLOSED_OPTION:
                return "cancel";
            default:
                throw new BuildException("Internal error: Unknown option " +
                        "pane response: " + optionPaneResponse);
        }
    
public voidsetMessage(java.lang.String msg)

        // ant always replaces properties for attributes
        message = msg;
    
public voidsetOptiontype(com.oreilly.javaxp.ant.DialogBoxTask$OptionType ot)

        log("Calling setOptionType: " + ot.getValue(),
                Project.MSG_DEBUG);

        String value = ot.getValue();
        if ("ok".equals(value)) {
            optionType = -1;
        } else if ("ok_cancel".equals(value)) {
            optionType = JOptionPane.OK_CANCEL_OPTION;
        } else if ("yes_no".equals(value)) {
            optionType = JOptionPane.YES_NO_OPTION;
        } else {
            // only remaining possibility
            optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        }
    
public voidsetProperty(java.lang.String propertyName)

        this.propertyName = propertyName;
    
public voidsetTitle(java.lang.String title)


        
        this.title = title;
    
protected voidvalidateAttributes()

        if (message == null) {
            throw new BuildException("Message must be specified using the "
                    + "message attribute or nested text.");
        }

        if (optionType == -1 && propertyName != null) {
            throw new BuildException(
                    "Cannot specify property unless optionType is "
                    + "'ok_cancel', 'yes_no', or 'yes_no_cancel'");
        }