1 19 20 package org.netbeans.modules.javawebstart.ui.customizer; 21 22 import java.io.File ; 23 24 import javax.swing.JComponent ; 25 import javax.swing.JFileChooser ; 26 import javax.swing.JPanel ; 27 import javax.swing.filechooser.FileFilter ; 28 29 import org.openide.filesystems.FileUtil; 30 import org.openide.util.HelpCtx; 31 import org.openide.util.NbBundle; 32 33 import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectProperties.CodebaseComboBoxModel; 34 import org.netbeans.modules.javawebstart.CustomizerRunComponent; 35 36 40 public class JWSCustomizerPanel extends JPanel implements HelpCtx.Provider { 41 42 private JWSProjectProperties jwsProps; 43 private File lastImageFolder = null; 44 45 public static CustomizerRunComponent runComponent; 46 static { 47 runComponent = new CustomizerRunComponent(); 48 } 49 50 51 public JWSCustomizerPanel(JWSProjectProperties props) { 52 53 this.jwsProps = props; 54 55 initComponents(); 56 57 enableCheckBox.setModel(jwsProps.enabledModel); 58 offlineCheckBox.setModel(jwsProps.allowOfflineModel); 59 iconTextField.setDocument(jwsProps.iconDocument); 60 codebaseComboBox.setModel(jwsProps.codebaseModel); 61 codebaseTextField.setDocument(jwsProps.codebaseURLDocument); 62 63 setCodebaseComponents(); 64 boolean enableSelected = enableCheckBox.getModel().isSelected(); 65 setEnabledAllComponents(enableSelected); 66 setEnabledRunComponent(enableSelected); 67 68 } 69 70 private static void setEnabledRunComponent(boolean enable) { 71 runComponent.setCheckboxEnabled(enable); 72 runComponent.setHintVisible(!enable); 73 } 74 75 80 private void initComponents() { 82 java.awt.GridBagConstraints gridBagConstraints; 83 84 enableCheckBox = new javax.swing.JCheckBox (); 85 iconLabel = new javax.swing.JLabel (); 86 codebaseLabel = new javax.swing.JLabel (); 87 iconTextField = new javax.swing.JTextField (); 88 browseButton = new javax.swing.JButton (); 89 codebaseComboBox = new javax.swing.JComboBox (); 90 codebaseTextField = new javax.swing.JTextField (); 91 offlineLabel = new javax.swing.JLabel (); 92 offlineCheckBox = new javax.swing.JCheckBox (); 93 panelDescLabel = new javax.swing.JLabel (); 94 95 setLayout(new java.awt.GridBagLayout ()); 96 97 enableCheckBox.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.enableCheckBox.text")); enableCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 99 enableCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 100 enableCheckBox.addActionListener(new java.awt.event.ActionListener () { 101 public void actionPerformed(java.awt.event.ActionEvent evt) { 102 enableCheckBoxActionPerformed(evt); 103 } 104 }); 105 gridBagConstraints = new java.awt.GridBagConstraints (); 106 gridBagConstraints.gridx = 0; 107 gridBagConstraints.gridy = 1; 108 gridBagConstraints.gridwidth = 2; 109 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 110 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 111 add(enableCheckBox, gridBagConstraints); 112 113 iconLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.iconLabel.text")); gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridx = 0; 116 gridBagConstraints.gridy = 2; 117 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 118 gridBagConstraints.insets = new java.awt.Insets (11, 0, 0, 0); 119 add(iconLabel, gridBagConstraints); 120 121 codebaseLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.codebaseLabel.text")); gridBagConstraints = new java.awt.GridBagConstraints (); 123 gridBagConstraints.gridx = 0; 124 gridBagConstraints.gridy = 3; 125 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 126 gridBagConstraints.insets = new java.awt.Insets (8, 0, 0, 0); 127 add(codebaseLabel, gridBagConstraints); 128 129 iconTextField.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.iconTextField.text")); gridBagConstraints = new java.awt.GridBagConstraints (); 131 gridBagConstraints.gridx = 1; 132 gridBagConstraints.gridy = 2; 133 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 134 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 135 gridBagConstraints.insets = new java.awt.Insets (8, 6, 0, 0); 136 add(iconTextField, gridBagConstraints); 137 138 browseButton.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.browseButton.text")); browseButton.addActionListener(new java.awt.event.ActionListener () { 140 public void actionPerformed(java.awt.event.ActionEvent evt) { 141 browseButtonActionPerformed(evt); 142 } 143 }); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.gridx = 2; 146 gridBagConstraints.gridy = 2; 147 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 148 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 149 add(browseButton, gridBagConstraints); 150 151 codebaseComboBox.addActionListener(new java.awt.event.ActionListener () { 152 public void actionPerformed(java.awt.event.ActionEvent evt) { 153 codebaseComboBoxActionPerformed(evt); 154 } 155 }); 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 1; 158 gridBagConstraints.gridy = 3; 159 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 160 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 161 gridBagConstraints.weightx = 1.0; 162 gridBagConstraints.insets = new java.awt.Insets (5, 6, 0, 0); 163 add(codebaseComboBox, gridBagConstraints); 164 165 codebaseTextField.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.codebaseTextField.text")); gridBagConstraints = new java.awt.GridBagConstraints (); 167 gridBagConstraints.gridx = 1; 168 gridBagConstraints.gridy = 4; 169 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 170 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 171 gridBagConstraints.insets = new java.awt.Insets (5, 6, 0, 0); 172 add(codebaseTextField, gridBagConstraints); 173 174 offlineLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.offlineLabel.text")); gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridx = 0; 177 gridBagConstraints.gridy = 5; 178 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 179 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 180 gridBagConstraints.weighty = 1.0; 181 gridBagConstraints.insets = new java.awt.Insets (10, 0, 0, 0); 182 add(offlineLabel, gridBagConstraints); 183 184 offlineCheckBox.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.offlineCheckBox.text")); offlineCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 186 offlineCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 187 gridBagConstraints = new java.awt.GridBagConstraints (); 188 gridBagConstraints.gridx = 1; 189 gridBagConstraints.gridy = 5; 190 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 191 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 192 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 193 gridBagConstraints.weighty = 1.0; 194 gridBagConstraints.insets = new java.awt.Insets (11, 7, 0, 0); 195 add(offlineCheckBox, gridBagConstraints); 196 197 panelDescLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.panelDescLabel.text")); gridBagConstraints = new java.awt.GridBagConstraints (); 199 gridBagConstraints.gridx = 0; 200 gridBagConstraints.gridy = 0; 201 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 202 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 203 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 204 gridBagConstraints.insets = new java.awt.Insets (0, 0, 10, 0); 205 add(panelDescLabel, gridBagConstraints); 206 } 208 private void codebaseComboBoxActionPerformed(java.awt.event.ActionEvent evt) { setCodebaseComponents(); 210 } 212 private void enableCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { boolean isSelected = enableCheckBox.getModel().isSelected(); 214 setEnabledAllComponents(isSelected); 215 setEnabledRunComponent(isSelected); 216 } 218 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); 220 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 221 chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES); 222 chooser.setMultiSelectionEnabled(false); 223 chooser.setFileFilter(new IconFileFilter()); 224 if (lastImageFolder != null) { 225 chooser.setSelectedFile(lastImageFolder); 226 } else { } 230 chooser.setDialogTitle(NbBundle.getMessage(JWSCustomizerPanel.class, "LBL_Select_Icon_Image")); 231 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { 232 File file = FileUtil.normalizeFile(chooser.getSelectedFile()); 233 iconTextField.setText(file.getAbsolutePath()); 234 lastImageFolder = file.getParentFile(); 235 } 236 } 238 public HelpCtx getHelpCtx() { 239 return new HelpCtx(JWSCustomizerPanel.class); 240 } 241 242 private static class IconFileFilter extends FileFilter { 243 244 public boolean accept(File f) { 246 if (f.isDirectory()) { 247 return true; 248 } 249 String name = f.getName(); 250 int index = name.lastIndexOf('.'); 251 if (index > 0 && index < name.length() - 1) { 252 String ext = name.substring(index+1).toLowerCase(); 253 if ("gif".equals(ext) || "png".equals(ext) || "jpg".equals(ext)) { 254 return true; 255 } 256 } 257 return false; 258 } 259 260 public String getDescription() { 261 return "Icon image files"; 262 } 263 264 } 265 266 private CodebaseComboBoxModel getCBModel() { 267 return (CodebaseComboBoxModel) codebaseComboBox.getModel(); 268 } 269 270 private void setCodebaseComponents() { 271 String value = getCBModel().getSelectedCodebaseItem(); 272 if (JWSProjectProperties.CB_TYPE_LOCAL.equals(value)) { 273 codebaseTextField.setText(jwsProps.getProjectDistDir()); 274 codebaseTextField.setEditable(false); 275 } else if (JWSProjectProperties.CB_TYPE_WEB.equals(value)) { 276 codebaseTextField.setText(JWSProjectProperties.CB_URL_WEB); 277 codebaseTextField.setEditable(false); 278 } else if (JWSProjectProperties.CB_TYPE_USER.equals(value)) { 279 codebaseTextField.setText(jwsProps.getCodebaseLocation()); 280 codebaseTextField.setEditable(true); 281 } 282 } 283 284 private void setEnabledAllComponents(boolean b) { 285 iconLabel.setEnabled(b); 286 iconTextField.setEnabled(b); 287 browseButton.setEnabled(b); 288 codebaseLabel.setEnabled(b); 289 codebaseComboBox.setEnabled(b); 290 codebaseTextField.setEnabled(b); 291 offlineLabel.setEnabled(b); 292 offlineCheckBox.setEnabled(b); 293 } 294 295 private javax.swing.JButton browseButton; 297 private javax.swing.JComboBox codebaseComboBox; 298 private javax.swing.JLabel codebaseLabel; 299 private javax.swing.JTextField codebaseTextField; 300 private javax.swing.JCheckBox enableCheckBox; 301 private javax.swing.JLabel iconLabel; 302 private javax.swing.JTextField iconTextField; 303 private javax.swing.JCheckBox offlineCheckBox; 304 private javax.swing.JLabel offlineLabel; 305 private javax.swing.JLabel panelDescLabel; 306 308 } 309 | Popular Tags |