KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > ui > wizards > ImportBuildfile


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.project.ui.wizards;
21
22 import java.io.File JavaDoc;
23 import java.text.MessageFormat JavaDoc;
24
25 import javax.swing.JButton JavaDoc;
26 import javax.swing.event.DocumentEvent JavaDoc;
27 import javax.swing.event.DocumentListener JavaDoc;
28
29 import org.openide.util.NbBundle;
30
31 public class ImportBuildfile extends javax.swing.JPanel JavaDoc implements DocumentListener JavaDoc {
32
33     private JButton JavaDoc ok;
34     private File JavaDoc buildFileDir;
35
36     /** Creates new form ImportBuildfile */
37     public ImportBuildfile(File JavaDoc buildFile, JButton JavaDoc okButton) {
38         initComponents();
39         this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportBuildfile.class, "ACS_IW_BuildFileDialog_A11YDesc")); // NOI18N
40

41         ok = okButton;
42         buildFileDir = buildFile.getParentFile();
43         ok.setEnabled(false);
44         
45         String JavaDoc msg = MessageFormat.format(NbBundle.getMessage(ImportBuildfile.class,
46                 "LBL_IW_BuildfileDesc_Label"), buildFile.getAbsolutePath()); //NOI18N
47
jLabelDesc.setText(msg);
48         jTextFieldBuildName.getDocument().addDocumentListener(this);
49         jTextFieldBuildName.setText(NbBundle.getMessage(ImportBuildfile.class, "LBL_IW_ProposedName_TextField")); //NOI18N
50

51         resize();
52     }
53     
54     private void resize() {
55         int width = (new Double JavaDoc(jLabelDesc.getFontMetrics(jLabelDesc.getFont()).getStringBounds(jLabelDesc.getText(), getGraphics()).getWidth() / 2.7)).intValue() + 40;
56         int height = (jLabelDesc.getFont().getSize() * 5) + 100;
57         if (width < 400)
58             width = 400;
59         if (height < 160)
60             height = 160;
61         java.awt.Dimension JavaDoc dim = new java.awt.Dimension JavaDoc(width, height);
62         setMinimumSize(dim);
63         setPreferredSize(dim);
64     }
65     
66     /** This method is called from within the constructor to
67      * initialize the form.
68      * WARNING: Do NOT modify this code. The content of this method is
69      * always regenerated by the Form Editor.
70      */

71     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
72
private void initComponents() {
73         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
74
75         jLabelDesc = new javax.swing.JLabel JavaDoc();
76         jLabelBuildName = new javax.swing.JLabel JavaDoc();
77         jTextFieldBuildName = new javax.swing.JTextField JavaDoc();
78         jLabelCreatedFile = new javax.swing.JLabel JavaDoc();
79         jTextFieldCreatedFile = new javax.swing.JTextField JavaDoc();
80
81         setLayout(new java.awt.GridBagLayout JavaDoc());
82
83         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
84         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
85         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
86         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
87         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 11, 11);
88         add(jLabelDesc, gridBagConstraints);
89
90         jLabelBuildName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportBuildfile.class, "LBL_IW_BuildFilename_LabelMnemonic").charAt(0));
91         jLabelBuildName.setLabelFor(jTextFieldBuildName);
92         jLabelBuildName.setText(NbBundle.getMessage(ImportBuildfile.class, "LBL_IW_BuildFilename_Label"));
93         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
94         gridBagConstraints.gridx = 0;
95         gridBagConstraints.gridy = 1;
96         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 11, 11);
98         add(jLabelBuildName, gridBagConstraints);
99
100         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.gridx = 1;
102         gridBagConstraints.gridy = 1;
103         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
104         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
105         gridBagConstraints.weightx = 1.0;
106         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
107         add(jTextFieldBuildName, gridBagConstraints);
108         jTextFieldBuildName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportBuildfile.class, "ACS_LBL_IW_BuildFilename_A11YDesc"));
109
110         jLabelCreatedFile.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ImportBuildfile.class, "LBL_IW_CreatedFile_LabelMnemonic").charAt(0));
111         jLabelCreatedFile.setLabelFor(jTextFieldCreatedFile);
112         jLabelCreatedFile.setText(NbBundle.getMessage(ImportBuildfile.class, "LBL_IW_CreatedFile_Label"));
113         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
114         gridBagConstraints.gridx = 0;
115         gridBagConstraints.gridy = 2;
116         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
117         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
118         gridBagConstraints.weighty = 1.0;
119         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 11, 11);
120         add(jLabelCreatedFile, gridBagConstraints);
121
122         jTextFieldCreatedFile.setEditable(false);
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridx = 1;
125         gridBagConstraints.gridy = 2;
126         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
127         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
128         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
129         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
130         gridBagConstraints.weighty = 1.0;
131         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 11);
132         add(jTextFieldCreatedFile, gridBagConstraints);
133         jTextFieldCreatedFile.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ImportBuildfile.class, "ACS_LBL_IW_CreatedFile_A11YDesc"));
134
135     }// </editor-fold>//GEN-END:initComponents
136

137     // Variables declaration - do not modify//GEN-BEGIN:variables
138
private javax.swing.JLabel JavaDoc jLabelBuildName;
139     private javax.swing.JLabel JavaDoc jLabelCreatedFile;
140     private javax.swing.JLabel JavaDoc jLabelDesc;
141     private javax.swing.JTextField JavaDoc jTextFieldBuildName;
142     private javax.swing.JTextField JavaDoc jTextFieldCreatedFile;
143     // End of variables declaration//GEN-END:variables
144

145     protected String JavaDoc getBuildName() {
146         return jTextFieldBuildName.getText().trim();
147     }
148     
149     // Implementation of DocumentListener --------------------------------------
150
public void changedUpdate(DocumentEvent JavaDoc e) {
151         updateButton();
152     }
153     
154     public void insertUpdate(DocumentEvent JavaDoc e) {
155         updateButton();
156     }
157     
158     public void removeUpdate(DocumentEvent JavaDoc e) {
159         updateButton();
160     }
161     // End if implementation of DocumentListener -------------------------------
162

163     private void updateButton() {
164         String JavaDoc buildFileName = getBuildName();
165         File JavaDoc buildFile = new File JavaDoc(buildFileDir, buildFileName);
166         jTextFieldCreatedFile.setText(buildFile.getAbsolutePath());
167         ok.setEnabled(!(buildFileName.length() == 0 || buildFile.exists()));
168     }
169 }
170
Popular Tags