1 19 20 package org.netbeans.modules.html.palette.items; 21 import java.awt.Dialog ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.File ; 25 import javax.swing.DefaultComboBoxModel ; 26 import javax.swing.text.Document ; 27 import javax.swing.text.JTextComponent ; 28 import org.netbeans.api.project.SourceGroup; 29 import org.netbeans.modules.html.palette.BrowseFolders; 30 import org.netbeans.modules.html.palette.HTMLPaletteUtilities; 31 import org.netbeans.modules.editor.NbEditorUtilities; 32 import org.openide.DialogDescriptor; 33 import org.openide.DialogDisplayer; 34 import org.openide.filesystems.FileObject; 35 import org.openide.filesystems.FileUtil; 36 import org.openide.util.NbBundle; 37 38 39 40 41 45 public class ACustomizer extends javax.swing.JPanel { 46 47 private Dialog dialog = null; 48 private DialogDescriptor descriptor = null; 49 private boolean dialogOK = false; 50 51 A a; 52 JTextComponent target; 53 54 public ACustomizer(A a, JTextComponent target) { 55 this.a = a; 56 this.target = target; 57 58 initComponents(); 59 60 jComboBox1.setModel(new DefaultComboBoxModel (A.protocols)); 61 jComboBox1.setSelectedIndex(a.getProtocolIndex()); 62 jComboBox2.setModel(new DefaultComboBoxModel (A.targets)); 63 jComboBox2.setSelectedIndex(a.getTargetIndex()); 64 } 65 66 public boolean showDialog() { 67 68 dialogOK = false; 69 70 String displayName = ""; 71 try { 72 displayName = NbBundle.getBundle("org.netbeans.modules.html.palette.items.resources.Bundle").getString("NAME_html-A"); } 74 catch (Exception e) {} 75 76 descriptor = new DialogDescriptor 77 (this, NbBundle.getMessage(ACustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true, 78 DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, 79 new ActionListener () { 80 public void actionPerformed(ActionEvent e) { 81 if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) { 82 evaluateInput(); 83 dialogOK = true; 84 } 85 dialog.dispose(); 86 } 87 } 88 ); 89 90 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 91 dialog.setVisible(true); 92 repaint(); 93 94 return dialogOK; 95 } 96 97 private void evaluateInput() { 98 99 int protocolIndex = jComboBox1.getSelectedIndex(); 100 a.setProtocolIndex(protocolIndex); 101 102 String url = jTextField1.getText(); 103 a.setUrl(url); 104 105 String text = jTextField2.getText(); 106 a.setText(text); 107 108 int targetIndex = jComboBox2.getSelectedIndex(); 109 a.setTargetIndex(targetIndex); 110 if (targetIndex == -1) a.setTarget(jComboBox2.getSelectedItem().toString()); 112 113 } 114 115 120 private void initComponents() { 122 java.awt.GridBagConstraints gridBagConstraints; 123 124 jFileChooser1 = new javax.swing.JFileChooser (); 125 jLabel4 = new javax.swing.JLabel (); 126 jTextField1 = new javax.swing.JTextField (); 127 jButton1 = new javax.swing.JButton (); 128 jLabel1 = new javax.swing.JLabel (); 129 jLabel2 = new javax.swing.JLabel (); 130 jLabel3 = new javax.swing.JLabel (); 131 jTextField2 = new javax.swing.JTextField (); 132 jComboBox1 = new javax.swing.JComboBox (); 133 jComboBox2 = new javax.swing.JComboBox (); 134 135 jFileChooser1.setCurrentDirectory(null); 136 137 setLayout(new java.awt.GridBagLayout ()); 138 139 jLabel4.setLabelFor(jComboBox2); 140 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(ACustomizer.class, "LBL_A_Target")); 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.gridx = 0; 143 gridBagConstraints.gridy = 3; 144 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 146 gridBagConstraints.weighty = 1.0; 147 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 0); 148 add(jLabel4, gridBagConstraints); 149 jLabel4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSN_A_Target")); 150 jLabel4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSD_A_Target")); 151 152 jTextField1.setColumns(35); 153 gridBagConstraints = new java.awt.GridBagConstraints (); 154 gridBagConstraints.gridx = 1; 155 gridBagConstraints.gridy = 1; 156 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 157 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 158 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 159 add(jTextField1, gridBagConstraints); 160 161 org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(ACustomizer.class, "LBL_A_Browse")); 162 jButton1.addActionListener(new java.awt.event.ActionListener () { 163 public void actionPerformed(java.awt.event.ActionEvent evt) { 164 jButton1ActionPerformed(evt); 165 } 166 }); 167 168 gridBagConstraints = new java.awt.GridBagConstraints (); 169 gridBagConstraints.gridx = 2; 170 gridBagConstraints.gridy = 1; 171 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 172 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 12); 173 add(jButton1, gridBagConstraints); 174 jButton1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSN_A_Browse")); 175 jButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSD_A_Browse")); 176 177 jLabel1.setLabelFor(jComboBox1); 178 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ACustomizer.class, "LBL_A_Protocol")); 179 gridBagConstraints = new java.awt.GridBagConstraints (); 180 gridBagConstraints.gridx = 0; 181 gridBagConstraints.gridy = 0; 182 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 183 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 184 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 185 add(jLabel1, gridBagConstraints); 186 jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSN_A_Protocol")); 187 jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSD_A_Protocol")); 188 189 jLabel2.setLabelFor(jTextField1); 190 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(ACustomizer.class, "LBL_A_URL")); 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.gridx = 0; 193 gridBagConstraints.gridy = 1; 194 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 195 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 196 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 197 add(jLabel2, gridBagConstraints); 198 jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSN_A_URL")); 199 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSD_A_URL")); 200 201 jLabel3.setLabelFor(jTextField2); 202 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(ACustomizer.class, "LBL_A_Text")); 203 gridBagConstraints = new java.awt.GridBagConstraints (); 204 gridBagConstraints.gridx = 0; 205 gridBagConstraints.gridy = 2; 206 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 207 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 208 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 209 add(jLabel3, gridBagConstraints); 210 jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSN_A_Text")); 211 jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ACustomizer.class, "ACSD_A_Text")); 212 213 jTextField2.setColumns(35); 214 gridBagConstraints = new java.awt.GridBagConstraints (); 215 gridBagConstraints.gridx = 1; 216 gridBagConstraints.gridy = 2; 217 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 218 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 219 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 220 add(jTextField2, gridBagConstraints); 221 222 gridBagConstraints = new java.awt.GridBagConstraints (); 223 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 224 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 225 add(jComboBox1, gridBagConstraints); 226 227 jComboBox2.setEditable(true); 228 gridBagConstraints = new java.awt.GridBagConstraints (); 229 gridBagConstraints.gridx = 1; 230 gridBagConstraints.gridy = 3; 231 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 232 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 233 gridBagConstraints.weightx = 1.0; 234 gridBagConstraints.weighty = 1.0; 235 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 0); 236 add(jComboBox2, gridBagConstraints); 237 238 } 240 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 242 Document targetDoc = target.getDocument(); 243 FileObject targetDocFO = NbEditorUtilities.getFileObject(targetDoc); 244 SourceGroup[] sg = HTMLPaletteUtilities.getSourceGroups(targetDocFO); 245 246 File file = null; 247 if (sg.length > 0) { 248 FileObject fo = BrowseFolders.showDialog(sg); 249 if (fo != null) 250 file = FileUtil.toFile(fo); 251 } 252 else { 253 jFileChooser1.setCurrentDirectory(FileUtil.toFile(targetDocFO.getParent())); 254 int returnVal = jFileChooser1.showOpenDialog(this); 255 256 if (returnVal == jFileChooser1.APPROVE_OPTION) 257 file = jFileChooser1.getSelectedFile(); 258 } 259 260 if (file != null) { 261 String path = file.getAbsolutePath(); 262 FileObject aFO = FileUtil.toFileObject(file); 263 try { 264 String relPathToFile = HTMLPaletteUtilities.getRelativePath(targetDocFO, aFO); 265 if (relPathToFile.length() > 0) 266 path = relPathToFile; 267 } 268 catch (Exception e) { 269 } 271 272 jTextField1.setText(path); 273 } 274 } 276 277 private javax.swing.JButton jButton1; 279 private javax.swing.JComboBox jComboBox1; 280 private javax.swing.JComboBox jComboBox2; 281 private javax.swing.JFileChooser jFileChooser1; 282 private javax.swing.JLabel jLabel1; 283 private javax.swing.JLabel jLabel2; 284 private javax.swing.JLabel jLabel3; 285 private javax.swing.JLabel jLabel4; 286 private javax.swing.JTextField jTextField1; 287 private javax.swing.JTextField jTextField2; 288 290 } 291 | Popular Tags |