📄 xmlfilechooser.java
字号:
package com.sutternow.swingkar.gui;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.File;
/**
* Created by IntelliJ IDEA.
* User: payne
* Date: Apr 21, 2003
* Time: 1:13:13 PM
* todo: Make this more generics, perhaps, have a method that takes in a collection
* of file extensions pared with descriptions.
*/
public class XmlFileChooser {
public static String doChoose(final String description) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileFilter() {
public String getDescription() {
return description;
}
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String ext = getExtension(f);
if (ext != null) {
if (ext.equals("xml"))
return true;
}
return false;
}
public String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
}
return ext;
}
}); // end of inner class file filter
if (chooser.showDialog(null, "Select file") != JFileChooser.APPROVE_OPTION) {
return null;
}
String filename = replaceString(chooser.getSelectedFile().getPath(), "\\", "/");
//scriptPath.setText(filename);
return filename;
}
//{{{ replaceString() method
private static String replaceString(String aSearch, String aFind, String aReplace) { /* MP could not get regex replace to work.
so I am including this function for now */
String result = aSearch;
if (result != null && result.length() > 0) {
int a = 0;
int b = 0;
while (true) {
a = result.indexOf(aFind, b);
if (a != -1) {
result = result.substring(0, a) + aReplace + result.substring(a + aFind.length());
b = a + aReplace.length();
} else
break;
}
}
return result;
} //}}}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -