下面列出了javax.swing.JFileChooser#setApproveButtonMnemonic ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
protected void selectFile() {
ResourceManager rm = ResourceManager.all(FilePropertyEditor.class);
JFileChooser chooser = UserPreferences.getDefaultFileChooser();
chooser.setDialogTitle(rm.getString("FilePropertyEditor.dialogTitle"));
chooser.setApproveButtonText(
rm.getString("FilePropertyEditor.approveButtonText"));
chooser.setApproveButtonMnemonic(
rm.getChar("FilePropertyEditor.approveButtonMnemonic"));
customizeFileChooser(chooser);
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(editor)) {
File oldFile = (File)getValue();
File newFile = chooser.getSelectedFile();
String text = newFile.getAbsolutePath();
textfield.setText(text);
firePropertyChange(oldFile, newFile);
}
}
private JFileChooser getJFileChooser() {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
// set the current directory
chooser.setSelectedFile(new File(locationTextField.getText().trim()));
return chooser;
}
private JFileChooser getJFileChooser(){
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("LBL_Chooser_Name"); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new dirFilter());
chooser.setAcceptAllFileFilterUsed(false);
chooser.setApproveButtonToolTipText("LBL_Chooser_Name"); //NOI18N
chooser.getAccessibleContext().setAccessibleName("LBL_Chooser_Name"); //NOI18N
chooser.getAccessibleContext().setAccessibleDescription("LBL_Chooser_Name"); //NOI18N
return chooser;
}
private JFileChooser getJFileChooser() {
JFileChooser chooser = new JFileChooser();
String t = NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName");
chooser.setDialogTitle(t); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new DirFilter());
chooser.setAcceptAllFileFilterUsed(false);
chooser.setApproveButtonToolTipText(t); //NOI18N
chooser.getAccessibleContext().setAccessibleName(t); //NOI18N
chooser.getAccessibleContext().setAccessibleDescription(t); //NOI18N
// set the current directory
File currentLocation = new File(hk2HomeTextField.getText());
File currentLocationParent = currentLocation.getParentFile();
if(currentLocationParent != null && currentLocationParent.exists()) {
chooser.setCurrentDirectory(currentLocationParent);
}
if (currentLocation.exists() && currentLocation.isDirectory()) {
chooser.setSelectedFile(currentLocation);
}
return chooser;
}
private JFileChooser getJFileChooser(){
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ChooserName")); //NOI18N
// set the current directory
chooser.setSelectedFile(new File(locationTextField.getText().trim()));
return chooser;
}
private JFileChooser getJFileChooser(){
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("LBL_Chooser_Name"); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.addChoosableFileFilter(new dirFilter());
chooser.setAcceptAllFileFilterUsed(false);
chooser.setApproveButtonToolTipText("LBL_Chooser_Name"); //NOI18N
chooser.getAccessibleContext().setAccessibleName("LBL_Chooser_Name"); //NOI18N
chooser.getAccessibleContext().setAccessibleDescription("LBL_Chooser_Name"); //NOI18N
return chooser;
}
protected void selectFile() {
ResourceManager rm = ResourceManager.all(FilePropertyEditor.class);
JFileChooser chooser = UserPreferences.getDefaultFileChooser();
chooser.setDialogTitle(rm.getString("FilePropertyEditor.dialogTitle"));
chooser.setApproveButtonText(
rm.getString("FilePropertyEditor.approveButtonText"));
chooser.setApproveButtonMnemonic(
rm.getChar("FilePropertyEditor.approveButtonMnemonic"));
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(editor)) {
File oldFile = (File)getValue();
File newFile = chooser.getSelectedFile();
String text = newFile.getAbsolutePath();
textfield.setText(text);
firePropertyChange(oldFile, newFile);
}
}
void decorateChooser(JFileChooser chooser,String fname,String title) {
chooser.setDialogTitle(title); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory() || (file.isFile() && file.getName().endsWith(".xml"));
}
@Override
public String getDescription() {
return "";
}
});
chooser.setApproveButtonMnemonic(NbBundle.getMessage(WildflyTabVisualPanel.class,
"Choose_Button_Mnemonic").charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.setAcceptAllFileFilterUsed(false);
chooser.setApproveButtonToolTipText(NbBundle.getMessage(WildflyTabVisualPanel.class,
"LBL_Chooser_Name")); //NOI18N
chooser.getAccessibleContext().
setAccessibleName(NbBundle.getMessage(WildflyTabVisualPanel.class,
"LBL_Chooser_Name")); //NOI18N
chooser.getAccessibleContext().
setAccessibleDescription(NbBundle.getMessage(WildflyTabVisualPanel.class,
"LBL_Chooser_Name")); //NOI18N
if (null != fname && fname.length() > 0) {
File sel = new File(fname);
if (sel.isDirectory())
chooser.setCurrentDirectory(sel);
else
chooser.setSelectedFile(sel);
}
}
private JFileChooser getConfigJFileChooser() {
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ConfigChooserName")); //NOI18N
chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory() || (file.isFile() && file.getName().endsWith(".xml"));
}
@Override
public String getDescription() {
return "";
}
});
chooser.setApproveButtonMnemonic("Choose_Button_Mnemonic".charAt(0)); //NOI18N
chooser.setMultiSelectionEnabled(false);
chooser.setApproveButtonToolTipText(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ConfigChooserName")); //NOI18N
chooser.getAccessibleContext().setAccessibleName(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ConfigChooserName")); //NOI18N
chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(AddServerLocationVisualPanel.class, "LBL_ConfigChooserName")); //NOI18N
// set the current directory
chooser.setSelectedFile(new File(configurationTextField.getText().trim()));
return chooser;
}
protected void selectFile() {
ResourceManager rm = ResourceManager.all(FilePropertyEditor.class);
JFileChooser chooser = UserPreferences.getDefaultDirectoryChooser();
chooser.setDialogTitle(rm.getString("DirectoryPropertyEditor.dialogTitle"));
chooser.setApproveButtonText(
rm.getString("DirectoryPropertyEditor.approveButtonText"));
chooser.setApproveButtonMnemonic(
rm.getChar("DirectoryPropertyEditor.approveButtonMnemonic"));
File oldFile = (File)getValue();
if (oldFile != null && oldFile.isDirectory()) {
try {
chooser.setCurrentDirectory(oldFile.getCanonicalFile());
} catch (IOException e) {
e.printStackTrace();
}
}
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(editor)) {
File newFile = chooser.getSelectedFile();
String text = newFile.getAbsolutePath();
textfield.setText(text);
firePropertyChange(oldFile, newFile);
}
}
protected void selectFile() {
ResourceManager rm = ResourceManager.all(FilePropertyEditor.class);
JFileChooser chooser = UserPreferences.getDefaultDirectoryChooser();
chooser.setDialogTitle(rm.getString("DirectoryPropertyEditor.dialogTitle"));
chooser.setApproveButtonText(
rm.getString("DirectoryPropertyEditor.approveButtonText"));
chooser.setApproveButtonMnemonic(
rm.getChar("DirectoryPropertyEditor.approveButtonMnemonic"));
File oldFile = (File)getValue();
if (oldFile != null && oldFile.isDirectory()) {
try {
chooser.setCurrentDirectory(oldFile.getCanonicalFile());
} catch (IOException e) {
e.printStackTrace();
}
}
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(editor)) {
File newFile = chooser.getSelectedFile();
String text = newFile.getAbsolutePath();
textfield.setText(text);
firePropertyChange(oldFile, newFile);
}
}
private void addResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addResource
// TODO add your handling code here:
JFileChooser chooser = new JFileChooser();
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setAcceptAllFileFilterUsed(false);
if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_CLASSPATH)) {
chooser.setMultiSelectionEnabled (true);
chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenClasses"));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
J2SEVolumeCustomizer.class,"TXT_Classpath"),new String[] {"ZIP","JAR"})); //NOI18N
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectCP"));
chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectCP").charAt(0));
}
else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_JAVADOC)) {
chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenJavadoc"));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
J2SEVolumeCustomizer.class,"TXT_Javadoc"),new String[] {"ZIP","JAR"})); //NOI18N
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectJD"));
chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectJD").charAt(0));
}
else if (this.volumeType.equals(PersistenceLibrarySupport.VOLUME_TYPE_SRC)) {
chooser.setDialogTitle(NbBundle.getMessage(J2SEVolumeCustomizer.class,"TXT_OpenSources"));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.setFileFilter (new SimpleFileFilter(NbBundle.getMessage(
J2SEVolumeCustomizer.class,"TXT_Sources"),new String[] {"ZIP","JAR"})); //NOI18N
chooser.setApproveButtonText(NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_SelectSRC"));
chooser.setApproveButtonMnemonic(NbBundle.getMessage(J2SEVolumeCustomizer.class,"MNE_SelectSRC").charAt(0));
}
if (lastFolder != null) {
chooser.setCurrentDirectory (lastFolder);
}
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
lastFolder = chooser.getCurrentDirectory();
if (chooser.isMultiSelectionEnabled()) {
addFiles (chooser.getSelectedFiles());
}
else {
final File selectedFile = chooser.getSelectedFile();
addFiles (new File[] {selectedFile});
}
} catch (MalformedURLException mue) {
Exceptions.printStackTrace(mue);
}
}
}
private void addPathElement () {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(null);
chooser.setMultiSelectionEnabled (true);
String title = null;
String message = null;
String approveButtonName = null;
String approveButtonNameMne = null;
if (SOURCES.equals(this.type)) {
title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
message = NbBundle.getMessage (CustomizerSupport.class,"TXT_Sources");
approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenSources");
} else if (JAVADOC.equals(this.type)) {
title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
message = NbBundle.getMessage (CustomizerSupport.class,"TXT_Javadoc");
approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenJavadoc");
} else {
throw new IllegalStateException("Can't add element for classpath"); // NOI18N
}
chooser.setDialogTitle(title);
chooser.setApproveButtonText(approveButtonName);
chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
//#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
chooser.setAcceptAllFileFilterUsed( false );
chooser.setFileFilter (new SimpleFileFilter(message,new String[] {"ZIP","JAR"})); //NOI18N
if (this.currentDir != null && currentDir.exists()) {
chooser.setCurrentDirectory(this.currentDir);
}
if (chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
File[] fs = chooser.getSelectedFiles();
PathModel model = (PathModel) this.resources.getModel();
boolean addingFailed = false;
int firstIndex = this.resources.getModel().getSize();
for (int i = 0; i < fs.length; i++) {
File f = fs[i];
//XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
// E.g. for /foo/src it returns /foo/src/src
// Try to convert it back by removing last invalid name component
if (!f.exists()) {
File parent = f.getParentFile();
if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
f = parent;
}
}
addingFailed|=!model.addPath (f);
}
if (addingFailed) {
new NotifyDescriptor.Message (NbBundle.getMessage(CustomizerSupport.class,"TXT_CanNotAddResolve"),
NotifyDescriptor.ERROR_MESSAGE);
}
int lastIndex = this.resources.getModel().getSize()-1;
if (firstIndex<=lastIndex) {
int[] toSelect = new int[lastIndex-firstIndex+1];
for (int i = 0; i < toSelect.length; i++) {
toSelect[i] = firstIndex+i;
}
this.resources.setSelectedIndices(toSelect);
}
this.currentDir = FileUtil.normalizeFile(chooser.getCurrentDirectory());
}
}
private void addPathElement () {
JFileChooser chooser = new JFileChooser();
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setMultiSelectionEnabled (true);
String title = null;
String message = null;
String approveButtonName = null;
String approveButtonNameMne = null;
if (SOURCES.equals(this.type)) {
title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
message = NbBundle.getMessage (CustomizerSupport.class,"TXT_FilterSources");
approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenSources");
} else if (JAVADOC.equals(this.type)) {
title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
message = NbBundle.getMessage (CustomizerSupport.class,"TXT_FilterJavadoc");
approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenJavadoc");
} else {
throw new IllegalStateException("Can't add element for classpath"); // NOI18N
}
chooser.setDialogTitle(title);
chooser.setApproveButtonText(approveButtonName);
chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
//#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
chooser.setAcceptAllFileFilterUsed( false );
chooser.setFileFilter (new SimpleFileFilter(message,new String[] {"ZIP","JAR"})); //NOI18N
if (this.currentDir != null && currentDir.exists()) {
chooser.setCurrentDirectory(this.currentDir);
}
if (chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
File[] fs = chooser.getSelectedFiles();
PathModel model = (PathModel) this.resources.getModel();
boolean addingFailed = false;
int firstIndex = this.resources.getModel().getSize();
for (int i = 0; i < fs.length; i++) {
File f = fs[i];
//XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
// E.g. for /foo/src it returns /foo/src/src
// Try to convert it back by removing last invalid name component
if (!f.exists()) {
File parent = f.getParentFile();
if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
f = parent;
}
}
addingFailed|=!model.addPath (f);
}
if (addingFailed) {
new NotifyDescriptor.Message (NbBundle.getMessage(CustomizerSupport.class,"TXT_CanNotAddResolve"),
NotifyDescriptor.ERROR_MESSAGE);
}
int lastIndex = this.resources.getModel().getSize()-1;
if (firstIndex<=lastIndex) {
int[] toSelect = new int[lastIndex-firstIndex+1];
for (int i = 0; i < toSelect.length; i++) {
toSelect[i] = firstIndex+i;
}
this.resources.setSelectedIndices(toSelect);
}
this.currentDir = FileUtil.normalizeFile(chooser.getCurrentDirectory());
}
}
private void addPathElement () {
JFileChooser chooser = new JFileChooser();
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
chooser.setMultiSelectionEnabled (true);
String title = null;
String message = null;
String approveButtonName = null;
String approveButtonNameMne = null;
if (SOURCES.equals(this.type)) {
title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
message = NbBundle.getMessage (CustomizerSupport.class,"TXT_Sources");
approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenSources");
} else if (JAVADOC.equals(this.type)) {
title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
message = NbBundle.getMessage (CustomizerSupport.class,"TXT_Javadoc");
approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenJavadoc");
} else {
throw new IllegalStateException("Can't add element for classpath"); // NOI18N
}
chooser.setDialogTitle(title);
chooser.setApproveButtonText(approveButtonName);
chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
//#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
chooser.setAcceptAllFileFilterUsed( false );
chooser.setFileFilter (new SimpleFileFilter(message,new String[] {"ZIP","JAR"})); //NOI18N
if (this.currentDir != null && currentDir.exists()) {
chooser.setCurrentDirectory(this.currentDir);
}
if (chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
File[] fs = chooser.getSelectedFiles();
PathModel model = (PathModel) this.resources.getModel();
boolean addingFailed = false;
int firstIndex = this.resources.getModel().getSize();
for (int i = 0; i < fs.length; i++) {
File f = fs[i];
//XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
// E.g. for /foo/src it returns /foo/src/src
// Try to convert it back by removing last invalid name component
if (!f.exists()) {
File parent = f.getParentFile();
if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
f = parent;
}
}
addingFailed|=!model.addPath (f);
}
if (addingFailed) {
new NotifyDescriptor.Message (NbBundle.getMessage(CustomizerSupport.class,"TXT_CanNotAddResolve"),
NotifyDescriptor.ERROR_MESSAGE);
}
int lastIndex = this.resources.getModel().getSize()-1;
if (firstIndex<=lastIndex) {
int[] toSelect = new int[lastIndex-firstIndex+1];
for (int i = 0; i < toSelect.length; i++) {
toSelect[i] = firstIndex+i;
}
this.resources.setSelectedIndices(toSelect);
}
this.currentDir = FileUtil.normalizeFile(chooser.getCurrentDirectory());
}
}
/** Factory method for project chooser
*/
public static JFileChooser createProjectChooser( boolean defaultAccessory ) {
ProjectManager.getDefault().clearNonProjectCache(); // #41882
OpenProjectListSettings opls = OpenProjectListSettings.getInstance();
JFileChooser chooser = new ProjectFileChooser();
chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
if ("GTK".equals(javax.swing.UIManager.getLookAndFeel().getID())) { // NOI18N
// see BugTraq #5027268
chooser.putClientProperty("GTKFileChooser.showDirectoryIcons", Boolean.TRUE); // NOI18N
//chooser.putClientProperty("GTKFileChooser.showFileIcons", Boolean.TRUE); // NOI18N
}
chooser.setApproveButtonText( NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonText" ) ); // NOI18N
chooser.setApproveButtonMnemonic( NbBundle.getMessage( ProjectChooserAccessory.class, "MNM_PrjChooser_ApproveButtonText" ).charAt (0) ); // NOI18N
chooser.setApproveButtonToolTipText (NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonTooltipText")); // NOI18N
// chooser.setMultiSelectionEnabled( true );
chooser.setDialogTitle( NbBundle.getMessage( ProjectChooserAccessory.class, "LBL_PrjChooser_Title" ) ); // NOI18N
//#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
chooser.setAcceptAllFileFilterUsed( false );
chooser.setFileFilter( ProjectDirFilter.INSTANCE );
// A11Y
chooser.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AN_ProjectChooserAccessory"));
chooser.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AD_ProjectChooserAccessory"));
if ( defaultAccessory ) {
chooser.setAccessory(new ProjectChooserAccessory(chooser, opls.isOpenSubprojects()));
}
File currDir = null;
String dir = opls.getLastOpenProjectDir();
if ( dir != null ) {
File d = new File( dir );
if ( d.exists() && d.isDirectory() ) {
currDir = d;
}
}
FileUtil.preventFileChooserSymlinkTraversal(chooser, currDir);
new ProjectFileView(chooser);
return chooser;
}
public void loadFromFile() {
final JFileChooser chooser = new AccessibleJFileChooser(NbBundle.getMessage(SvnProperties.class, "ACSD_Properties"));
chooser.setDialogTitle(NbBundle.getMessage(SvnProperties.class, "CTL_Load_Value_Title"));
chooser.setMultiSelectionEnabled(false);
javax.swing.filechooser.FileFilter[] fileFilters = chooser.getChoosableFileFilters();
for (int i = 0; i < fileFilters.length; i++) {
javax.swing.filechooser.FileFilter fileFilter = fileFilters[i];
chooser.removeChoosableFileFilter(fileFilter);
}
chooser.setCurrentDirectory(roots[0].getParentFile()); // NOI18N
chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {
@Override
public boolean accept(File f) {
return f.exists();
}
@Override
public String getDescription() {
return "";
}
});
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
chooser.setApproveButtonMnemonic(NbBundle.getMessage(SvnProperties.class, "MNE_LoadValue").charAt(0));
chooser.setApproveButtonText(NbBundle.getMessage(SvnProperties.class, "CTL_LoadValue"));
DialogDescriptor dd = new DialogDescriptor(chooser, NbBundle.getMessage(SvnProperties.class, "CTL_Load_Value_Title"));
dd.setOptions(new Object[0]);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
chooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String state = e.getActionCommand();
if (state.equals(JFileChooser.APPROVE_SELECTION)) {
File source = chooser.getSelectedFile();
if (Utils.isFileContentText(source)) {
if (source.canRead()) {
StringWriter sw = new StringWriter();
try {
Utils.copyStreamsCloseAll(sw, new FileReader(source));
panel.txtAreaValue.setText(sw.toString());
} catch (IOException ex) {
Subversion.LOG.log(Level.SEVERE, null, ex);
}
}
} else {
handleBinaryFile(source);
}
}
dialog.dispose();
}
});
dialog.setVisible(true);
}
private File getPatchFor(FileObject fo) {
JFileChooser chooser = new JFileChooser();
String patchDirPath = DiffModuleConfig.getDefault().getPreferences().get(PREF_RECENT_PATCH_PATH, System.getProperty("user.home"));
File patchDir = new File(patchDirPath);
while (!patchDir.isDirectory()) {
patchDir = patchDir.getParentFile();
if (patchDir == null) {
patchDir = new File(System.getProperty("user.home"));
break;
}
}
FileUtil.preventFileChooserSymlinkTraversal(chooser, patchDir);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
String title = NbBundle.getMessage(PatchAction.class,
(fo.isData()) ? "TITLE_SelectPatchForFile"
: "TITLE_SelectPatchForFolder", fo.getNameExt());
chooser.setDialogTitle(title);
// setup filters, default one filters patch files
FileFilter patchFilter = new javax.swing.filechooser.FileFilter() {
@Override
public boolean accept(File f) {
return f.getName().endsWith("diff") || f.getName().endsWith("patch") || f.isDirectory(); // NOI18N
}
@Override
public String getDescription() {
return NbBundle.getMessage(PatchAction.class, "CTL_PatchDialog_FileFilter");
}
};
chooser.addChoosableFileFilter(patchFilter);
chooser.setFileFilter(patchFilter);
chooser.setApproveButtonText(NbBundle.getMessage(PatchAction.class, "BTN_Patch"));
chooser.setApproveButtonMnemonic(NbBundle.getMessage(PatchAction.class, "BTN_Patch_mnc").charAt(0));
chooser.setApproveButtonToolTipText(NbBundle.getMessage(PatchAction.class, "BTN_Patch_tooltip"));
HelpCtx ctx = new HelpCtx(PatchAction.class.getName());
DialogDescriptor descriptor = new DialogDescriptor( chooser, title, true, new Object[0], null, 0, ctx, null );
final Dialog dialog = DialogDisplayer.getDefault().createDialog( descriptor );
dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(PatchAction.class, "ACSD_PatchDialog"));
ChooserListener listener = new PatchAction.ChooserListener(dialog,chooser);
chooser.addActionListener(listener);
dialog.setVisible(true);
File selectedFile = listener.getFile();
if (selectedFile != null) {
DiffModuleConfig.getDefault().getPreferences().put(PREF_RECENT_PATCH_PATH, selectedFile.getParentFile().getAbsolutePath());
}
return selectedFile;
}
@Override
protected void performContextAction(Node[] nodes) {
VCSContext ctx = HgUtils.getCurrentContext(nodes);
final File roots[] = HgUtils.getActionRoots(ctx);
if (roots == null || roots.length == 0) {
return;
}
final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);
final JFileChooser fileChooser = new AccessibleJFileChooser(Bundle.ACSD_ApplyDiffPatchBrowseFolder(), null);
fileChooser.setDialogTitle(Bundle.ApplyDiffPatchBrowse_title());
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
fileChooser.setApproveButtonMnemonic(Bundle.ApplyDiffPatch_Apply().charAt(0));
fileChooser.setApproveButtonText(Bundle.ApplyDiffPatch_Apply());
fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
// setup filters, default one filters patch files
FileFilter patchFilter = new javax.swing.filechooser.FileFilter() {
@Override
public boolean accept(File f) {
return f.getName().endsWith("diff") || f.getName().endsWith("patch") || f.isDirectory(); // NOI18N
}
@Override
public String getDescription() {
return Bundle.CTL_PatchDialog_FileFilter();
}
};
fileChooser.addChoosableFileFilter(patchFilter);
fileChooser.setFileFilter(patchFilter);
DialogDescriptor dd = new DialogDescriptor(fileChooser, Bundle.ApplyDiffPatchBrowse_title());
dd.setOptions(new Object[0]);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
fileChooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String state = e.getActionCommand();
if (state.equals(JFileChooser.APPROVE_SELECTION)) {
final File patchFile = fileChooser.getSelectedFile();
final RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
new HgProgressSupport() {
@Override
protected void perform () {
if (isNetBeansPatch(patchFile)) {
PatchAction.performPatch(patchFile, roots[0]);
} else {
new ImportDiffAction.ImportDiffProgressSupport(root, patchFile, false, ImportDiffAction.ImportDiffProgressSupport.Kind.PATCH)
.start(rp, root, Bundle.MSG_ApplyDiffPatch_importingPatch());
}
}
}.start(rp, root, Bundle.MSG_ApplyDiffPatch_checkingFile());
}
dialog.dispose();
}
});
dialog.setVisible(true);
}
private static void importDiff(VCSContext ctx) {
final File roots[] = HgUtils.getActionRoots(ctx);
if (roots == null || roots.length == 0) return;
final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);
final JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(ImportDiffAction.class, "ACSD_ImportBrowseFolder"), null); // NO I18N
fileChooser.setDialogTitle(NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title")); // NO I18N
fileChooser.setMultiSelectionEnabled(false);
fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
fileChooser.setApproveButtonMnemonic(NbBundle.getMessage(ImportDiffAction.class, "Import").charAt(0)); // NO I18N
fileChooser.setApproveButtonText(NbBundle.getMessage(ImportDiffAction.class, "Import")); // NO I18N
fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
JPanel panel = new JPanel();
final JRadioButton asPatch = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_PatchOption")); //NOI18N
org.openide.awt.Mnemonics.setLocalizedText(asPatch, asPatch.getText()); // NOI18N
final JRadioButton asBundle = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_BundleOption")); //NOI18N
org.openide.awt.Mnemonics.setLocalizedText(asBundle, asBundle.getText()); // NOI18N
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(asBundle);
buttonGroup.add(asPatch);
asPatch.setSelected(true);
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(asPatch);
panel.add(asBundle);
fileChooser.setAccessory(panel);
DialogDescriptor dd = new DialogDescriptor(fileChooser, NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title")); // NO I18N
dd.setOptions(new Object[0]);
final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
fileChooser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String state = e.getActionCommand();
if (state.equals(JFileChooser.APPROVE_SELECTION)) {
final File patchFile = fileChooser.getSelectedFile();
HgModuleConfig.getDefault().setImportFolder(patchFile.getParent());
RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
ImportDiffProgressSupport.Kind kind;
if (asBundle.isSelected()) {
kind = ImportDiffProgressSupport.Kind.BUNDLE;
} else if (asPatch.isSelected()) {
kind = ImportDiffProgressSupport.Kind.PATCH;
} else {
kind = null;
}
HgProgressSupport support = new ImportDiffProgressSupport(root, patchFile, true, kind);
support.start(rp, root, org.openide.util.NbBundle.getMessage(ImportDiffAction.class, "LBL_ImportDiff_Progress")); // NOI18N
}
dialog.dispose();
}
});
dialog.setVisible(true);
}