1 19 20 package org.netbeans.modules.web.project.ui.wizards; 21 22 import java.io.File ; 23 import java.text.MessageFormat ; 24 25 import javax.swing.JButton ; 26 import javax.swing.event.DocumentEvent ; 27 import javax.swing.event.DocumentListener ; 28 29 import org.openide.util.NbBundle; 30 31 public class ImportBuildfile extends javax.swing.JPanel implements DocumentListener { 32 33 private JButton ok; 34 private File buildFileDir; 35 36 37 public ImportBuildfile(File buildFile, JButton okButton) { 38 initComponents(); 39 this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ImportBuildfile.class, "ACS_IW_BuildFileDialog_A11YDesc")); 41 ok = okButton; 42 buildFileDir = buildFile.getParentFile(); 43 ok.setEnabled(false); 44 45 String msg = MessageFormat.format(NbBundle.getMessage(ImportBuildfile.class, 46 "LBL_IW_BuildfileDesc_Label"), buildFile.getAbsolutePath()); jLabelDesc.setText(msg); 48 jTextFieldBuildName.getDocument().addDocumentListener(this); 49 jTextFieldBuildName.setText(NbBundle.getMessage(ImportBuildfile.class, "LBL_IW_ProposedName_TextField")); 51 resize(); 52 } 53 54 private void resize() { 55 int width = (new Double (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 dim = new java.awt.Dimension (width, height); 62 setMinimumSize(dim); 63 setPreferredSize(dim); 64 } 65 66 71 private void initComponents() { 73 java.awt.GridBagConstraints gridBagConstraints; 74 75 jLabelDesc = new javax.swing.JLabel (); 76 jLabelBuildName = new javax.swing.JLabel (); 77 jTextFieldBuildName = new javax.swing.JTextField (); 78 jLabelCreatedFile = new javax.swing.JLabel (); 79 jTextFieldCreatedFile = new javax.swing.JTextField (); 80 81 setLayout(new java.awt.GridBagLayout ()); 82 83 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 94 gridBagConstraints.gridx = 0; 95 gridBagConstraints.gridy = 1; 96 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 97 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 98 add(jLabelBuildName, gridBagConstraints); 99 100 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 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 (0, 12, 11, 11); 120 add(jLabelCreatedFile, gridBagConstraints); 121 122 jTextFieldCreatedFile.setEditable(false); 123 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 } 137 private javax.swing.JLabel jLabelBuildName; 139 private javax.swing.JLabel jLabelCreatedFile; 140 private javax.swing.JLabel jLabelDesc; 141 private javax.swing.JTextField jTextFieldBuildName; 142 private javax.swing.JTextField jTextFieldCreatedFile; 143 145 protected String getBuildName() { 146 return jTextFieldBuildName.getText().trim(); 147 } 148 149 public void changedUpdate(DocumentEvent e) { 151 updateButton(); 152 } 153 154 public void insertUpdate(DocumentEvent e) { 155 updateButton(); 156 } 157 158 public void removeUpdate(DocumentEvent e) { 159 updateButton(); 160 } 161 163 private void updateButton() { 164 String buildFileName = getBuildName(); 165 File buildFile = new File (buildFileDir, buildFileName); 166 jTextFieldCreatedFile.setText(buildFile.getAbsolutePath()); 167 ok.setEnabled(!(buildFileName.length() == 0 || buildFile.exists())); 168 } 169 } 170 | Popular Tags |