langtools/make/tools/SelectTool/SelectToolTask.java
author alanb
Fri, 18 Jun 2010 16:16:51 +0100
changeset 5807 d34ed576e234
parent 5520 86e4b9a9da40
permissions -rw-r--r--
4981129: (dc) DatagramSocket created by DatagramChannel does not provide sender info Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1873
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     2
 * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
1873
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
     4
 *
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
1873
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
1873
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    10
 *
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    15
 * accompanied this code).
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    16
 *
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    23
 * questions.
1873
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    24
 */
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    25
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    26
import java.awt.GridBagConstraints;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    27
import java.awt.GridBagLayout;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    28
import java.awt.event.ActionEvent;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    29
import java.awt.event.ActionListener;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    30
import java.awt.event.FocusEvent;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    31
import java.awt.event.FocusListener;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    32
import java.awt.event.ItemEvent;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    33
import java.awt.event.ItemListener;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    34
import java.io.BufferedReader;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    35
import java.io.BufferedWriter;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    36
import java.io.File;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    37
import java.io.FileReader;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    38
import java.io.FileWriter;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    39
import java.io.IOException;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    40
import java.io.Reader;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    41
import java.io.Writer;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    42
import java.util.ArrayList;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    43
import java.util.Arrays;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    44
import java.util.List;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    45
import java.util.Properties;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    46
import javax.swing.JButton;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    47
import javax.swing.JCheckBox;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    48
import javax.swing.JComboBox;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    49
import javax.swing.JDialog;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    50
import javax.swing.JLabel;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    51
import javax.swing.JOptionPane;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    52
import javax.swing.JPanel;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    53
import javax.swing.JTextField;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    54
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    55
import javax.swing.SwingUtilities;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    56
import org.apache.tools.ant.BuildException;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    57
import org.apache.tools.ant.Project;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    58
import org.apache.tools.ant.Task;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    59
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    60
/**
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    61
 * Task to allow the user to control langtools tools built when using NetBeans.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    62
 *
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    63
 * There are two primary modes.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    64
 * 1) Property mode. In this mode, property names are provided to get values
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    65
 * that may be specified by the user, either directly in a GUI dialog, or
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    66
 * read from a properties file. If the GUI dialog is invoked, values may
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    67
 * optionally be set for future use.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    68
 * 2) Setup mode. In this mode, no property names are provided, and the GUI
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    69
 * is invoked to allow the user to set or reset values for use in property mode.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    70
 */
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    71
public class SelectToolTask extends Task {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    72
    /**
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    73
     * Set the location of the private properties file used to keep the retain
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    74
     * user preferences for this repository.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    75
     */
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    76
    public void setPropertyFile(File propertyFile) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    77
        this.propertyFile = propertyFile;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    78
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    79
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    80
    /**
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    81
     * Set the name of the property which will be set to the name of the
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    82
     * selected tool, if any. If no tool is selected, the property will
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    83
     * remain unset.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    84
     */
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    85
    public void setToolProperty(String toolProperty) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    86
        this.toolProperty = toolProperty;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    87
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    88
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    89
    /**
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    90
     * Set the name of the property which will be set to the execution args of the
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    91
     * selected tool, if any. The args default to an empty string.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    92
     */
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    93
    public void setArgsProperty(String argsProperty) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    94
        this.argsProperty = argsProperty;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    95
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    96
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    97
    /**
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    98
     * Specify whether or not to pop up a dialog if the user has not specified
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
    99
     * a default value for a property.
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   100
     */
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   101
    public void setAskIfUnset(boolean askIfUnset) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   102
        this.askIfUnset = askIfUnset;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   103
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   104
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   105
    @Override
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   106
    public void execute() {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   107
        Project p = getProject();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   108
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   109
        Properties props = readProperties(propertyFile);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   110
        toolName = props.getProperty("tool.name");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   111
        if (toolName != null) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   112
            toolArgs = props.getProperty(toolName + ".args", "");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   113
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   114
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   115
        if (toolProperty == null ||
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   116
            askIfUnset && (toolName == null
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   117
                || (argsProperty != null && toolArgs == null))) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   118
            showGUI(props);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   119
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   120
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   121
        // finally, return required values, if any
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   122
        if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   123
            p.setProperty(toolProperty, toolName);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   124
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   125
            if (argsProperty != null && toolArgs != null)
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   126
                p.setProperty(argsProperty, toolArgs);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   127
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   128
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   129
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   130
    void showGUI(Properties fileProps) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   131
        Properties guiProps = new Properties(fileProps);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   132
        JOptionPane p = createPane(guiProps);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   133
        p.createDialog("Select Tool").setVisible(true);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   134
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   135
        toolName = (String) toolChoice.getSelectedItem();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   136
        toolArgs = argsField.getText();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   137
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   138
        if (defaultCheck.isSelected()) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   139
            if (toolName.equals("")) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   140
                fileProps.remove("tool.name");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   141
            } else {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   142
                fileProps.put("tool.name", toolName);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   143
                fileProps.put(toolName + ".args", toolArgs);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   144
            }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   145
            writeProperties(propertyFile, fileProps);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   146
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   147
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   148
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   149
    JOptionPane createPane(final Properties props) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   150
        JPanel body = new JPanel(new GridBagLayout());
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   151
        GridBagConstraints lc = new GridBagConstraints();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   152
        lc.insets.right = 10;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   153
        lc.insets.bottom = 3;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   154
        GridBagConstraints fc = new GridBagConstraints();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   155
        fc.anchor = GridBagConstraints.WEST;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   156
        fc.gridx = 1;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   157
        fc.gridwidth = GridBagConstraints.REMAINDER;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   158
        fc.insets.bottom = 3;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   159
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   160
        JLabel toolLabel = new JLabel("Tool:");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   161
        body.add(toolLabel, lc);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   162
        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   163
        if (true || toolProperty == null) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   164
            // include empty value in setup mode
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   165
            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   166
            l.add(0, "");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   167
            toolChoices = l.toArray(new String[l.size()]);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   168
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   169
        toolChoice = new JComboBox(toolChoices);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   170
        if (toolName != null)
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   171
            toolChoice.setSelectedItem(toolName);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   172
        toolChoice.addItemListener(new ItemListener() {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   173
            public void itemStateChanged(ItemEvent e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   174
                String tn = (String) e.getItem();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   175
                argsField.setText(getDefaultArgsForTool(props, tn));
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   176
                if (toolProperty != null)
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   177
                    okButton.setEnabled(!tn.equals(""));
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   178
            }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   179
        });
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   180
        body.add(toolChoice, fc);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   181
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   182
        argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   183
        if (toolProperty == null || argsProperty != null) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   184
            JLabel argsLabel = new JLabel("Args:");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   185
            body.add(argsLabel, lc);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   186
            body.add(argsField, fc);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   187
            argsField.addFocusListener(new FocusListener() {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   188
                public void focusGained(FocusEvent e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   189
                }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   190
                public void focusLost(FocusEvent e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   191
                    String toolName = (String) toolChoice.getSelectedItem();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   192
                    if (toolName.length() > 0)
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   193
                        props.put(toolName + ".args", argsField.getText());
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   194
                }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   195
            });
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   196
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   197
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   198
        defaultCheck = new JCheckBox("Set as default");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   199
        if (toolProperty == null)
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   200
            defaultCheck.setSelected(true);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   201
        else
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   202
            body.add(defaultCheck, fc);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   203
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   204
        final JOptionPane p = new JOptionPane(body);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   205
        okButton = new JButton("OK");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   206
        okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   207
        okButton.addActionListener(new ActionListener() {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   208
            public void actionPerformed(ActionEvent e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   209
                JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   210
                d.setVisible(false);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   211
            }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   212
        });
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   213
        p.setOptions(new Object[] { okButton });
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   214
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   215
        return p;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   216
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   217
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   218
    Properties readProperties(File file) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   219
        Properties p = new Properties();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   220
        if (file != null && file.exists()) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   221
            Reader in = null;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   222
            try {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   223
                in = new BufferedReader(new FileReader(file));
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   224
                p.load(in);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   225
                in.close();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   226
            } catch (IOException e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   227
                throw new BuildException("error reading property file", e);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   228
            } finally {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   229
                if (in != null) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   230
                    try {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   231
                        in.close();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   232
                    } catch (IOException e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   233
                        throw new BuildException("cannot close property file", e);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   234
                    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   235
                }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   236
            }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   237
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   238
        return p;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   239
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   240
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   241
    void writeProperties(File file, Properties p) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   242
        if (file != null) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   243
            Writer out = null;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   244
            try {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   245
                File dir = file.getParentFile();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   246
                if (dir != null && !dir.exists())
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   247
                    dir.mkdirs();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   248
                out = new BufferedWriter(new FileWriter(file));
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   249
                p.store(out, "langtools properties");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   250
                out.close();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   251
            } catch (IOException e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   252
                throw new BuildException("error writing property file", e);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   253
            } finally {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   254
                if (out != null) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   255
                    try {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   256
                        out.close();
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   257
                    } catch (IOException e) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   258
                        throw new BuildException("cannot close property file", e);
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   259
                    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   260
                }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   261
            }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   262
        }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   263
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   264
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   265
    String getDefaultArgsForTool(Properties props, String tn) {
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   266
        return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", "");
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   267
    }
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   268
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   269
    // Ant task parameters
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   270
    private boolean askIfUnset;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   271
    private String toolProperty;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   272
    private String argsProperty;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   273
    private File propertyFile;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   274
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   275
    // GUI components
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   276
    private JComboBox toolChoice;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   277
    private JTextField argsField;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   278
    private JCheckBox defaultCheck;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   279
    private JButton okButton;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   280
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   281
    // Result values for the client
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   282
    private String toolName;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   283
    private String toolArgs;
658385834998 6795365: NetBeans projects in langtools repository are not NB6.5-friendly
jjg
parents:
diff changeset
   284
}