1 19 20 package org.netbeans.modules.apisupport.project.ui.platform; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.File ; 25 import java.io.IOException ; 26 import javax.swing.JFileChooser ; 27 import javax.swing.filechooser.FileFilter ; 28 import org.netbeans.modules.apisupport.project.ui.ModuleUISettings; 29 import org.netbeans.modules.apisupport.project.ui.wizard.BasicVisualPanel; 30 import org.netbeans.modules.apisupport.project.universe.NbPlatform; 31 import org.openide.WizardDescriptor; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.NbBundle; 34 35 41 public class PlatformChooserVisualPanel extends BasicVisualPanel 42 implements PropertyChangeListener { 43 44 45 public PlatformChooserVisualPanel(WizardDescriptor setting) { 46 super(setting); 47 initComponents(); 48 initAccessibility(); 49 String location = ModuleUISettings.getDefault().getLastUsedNbPlatformLocation(); 50 if (location != null) { 51 platformChooser.setCurrentDirectory(new File (location)); 52 } 53 platformChooser.setAcceptAllFileFilterUsed(false); 54 platformChooser.setFileFilter(new FileFilter () { 55 public boolean accept(File f) { 56 return f.isDirectory(); 57 } 58 public String getDescription() { 59 return getMessage("CTL_PlatformFolder"); 60 } 61 }); 62 platformChooser.addPropertyChangeListener(this); 63 setName(NbPlatformCustomizer.CHOOSER_STEP); 64 platformChooser.putClientProperty( 65 "JFileChooser.appBundleIsTraversable", "always"); } 67 68 public void addNotify() { 69 super.addNotify(); 70 checkForm(); 71 } 72 73 74 void storeData() { 75 File file = platformChooser.getSelectedFile(); 76 if (file != null) { 77 getSettings().putProperty(NbPlatformCustomizer.PLAF_DIR_PROPERTY, 78 file.getAbsolutePath()); 79 getSettings().putProperty(NbPlatformCustomizer.PLAF_LABEL_PROPERTY, 80 plafLabelValue.getText()); 81 } } 83 84 public void propertyChange(PropertyChangeEvent evt) { 85 String propName = evt.getPropertyName(); 86 if (propName.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) { 87 checkForm(); 88 } 89 } 90 91 private void checkForm() { 92 File selFile = platformChooser.getSelectedFile(); 93 boolean invalid = true; 94 if (selFile != null) { File plafDir = FileUtil.normalizeFile(selFile); 96 if ( plafDir != null && NbPlatform.isPlatformDirectory(plafDir)) { 97 try { 98 setPlafLabel(NbPlatform.computeDisplayName(plafDir)); 99 } catch (IOException e) { 100 setPlafLabel(plafDir.getAbsolutePath()); 101 } 102 if (!NbPlatform.isSupportedPlatform(plafDir)) { 103 setError(getMessage("MSG_UnsupportedPlatform")); 104 } else if (NbPlatform.contains(plafDir)) { 105 setError(getMessage("MSG_AlreadyAddedPlatform")); 106 } else if (!NbPlatform.isLabelValid(plafLabelValue.getText())) { 107 setWarning(getMessage("MSG_NameIsAlreadyUsedGoToNext")); 108 } else { 109 markValid(); 110 ModuleUISettings.getDefault().setLastUsedNbPlatformLocation(plafDir.getParentFile().getAbsolutePath()); 111 } 112 invalid = false; 113 } 114 } 115 if (invalid) { 116 markInvalid(); 117 setPlafLabel(null); 118 storeData(); 119 } 120 } 121 122 private void setPlafLabel(String label) { 123 plafLabelValue.setText(label); 124 plafLabelValue.setCaretPosition(0); 125 storeData(); 126 } 127 128 private static String getMessage(String key) { 129 return NbBundle.getMessage(PlatformChooserVisualPanel.class, key); 130 } 131 132 137 private void initComponents() { 139 infoPanel = new javax.swing.JPanel (); 140 inner = new javax.swing.JPanel (); 141 plafLabel = new javax.swing.JLabel (); 142 plafLabelValue = new javax.swing.JTextField (); 143 platformChooser = new javax.swing.JFileChooser (); 144 145 infoPanel.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT, 6, 0)); 146 147 inner.setLayout(new java.awt.GridLayout (2, 1, 0, 6)); 148 149 plafLabel.setLabelFor(plafLabelValue); 150 org.openide.awt.Mnemonics.setLocalizedText(plafLabel, org.openide.util.NbBundle.getMessage(PlatformChooserVisualPanel.class, "LBL_PlatformName_P")); 151 inner.add(plafLabel); 152 153 plafLabelValue.setColumns(15); 154 plafLabelValue.setEditable(false); 155 inner.add(plafLabelValue); 156 157 infoPanel.add(inner); 158 159 setLayout(new java.awt.BorderLayout ()); 160 161 platformChooser.setAccessory(infoPanel); 162 platformChooser.setControlButtonsAreShown(false); 163 platformChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); 164 add(platformChooser, java.awt.BorderLayout.CENTER); 165 166 } 167 169 private javax.swing.JPanel infoPanel; 171 private javax.swing.JPanel inner; 172 private javax.swing.JLabel plafLabel; 173 private javax.swing.JTextField plafLabelValue; 174 private javax.swing.JFileChooser platformChooser; 175 177 private void initAccessibility() { 178 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_PlatformChooserVisualPanel")); 179 plafLabelValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_plafLabelValue")); 180 } 181 182 } 183 | Popular Tags |