1. package org.jr.swing.filter;
  2. /**
  3. * Copyright: Copyright (c) 2002-2004
  4. * Company: JavaResearch(http://www.javaresearch.org)
  5. * 最后更新日期:2003年4月2日
  6. * @author Cherami
  7. */
  8. import java.io.*;
  9. /**
  10. * 文件名前后限定过滤器。
  11. * @since 0.6
  12. */
  13. public class FileNameFilter
  14. extends CombineFileFilter {
  15. String start;
  16. String end;
  17. /**
  18. * 根据指定参数构造一个FileNameFilter。
  19. * @param start 文件名的开始字符串
  20. * @param end 文件名的结束字符串
  21. * @param type 过滤器类型
  22. * @since 0.6
  23. */
  24. public FileNameFilter(String start, String end,int type) {
  25. super(type);
  26. this.start = (start == null) ? "" : start;
  27. this.end = (end == null) ? "" : end;
  28. }
  29. /**
  30. * 根据指定的参数构造一个FileNameFilter。
  31. * @param start 文件名的开始字符串
  32. * @param end 文件名的结束字符串
  33. * @since 0.6
  34. */
  35. public FileNameFilter(String start, String end) {
  36. this(start,end,SWING);
  37. }
  38. /**
  39. * 判断指定的文件是否可以被接受。
  40. * @param file 需要判断的文件
  41. * @return 在任何情况都返回true。
  42. * @since 0.6
  43. */
  44. protected boolean acceptFile(File file) {
  45. String filename = file.getName();
  46. if (filename.startsWith(start) && filename.endsWith(end)) {
  47. return true;
  48. }
  49. return false;
  50. }
  51. /**
  52. * 返回过滤器的描述字符串。
  53. * @return 过滤器的描述字符串
  54. * @since 0.6
  55. */
  56. public String getDescription() {
  57. return "Start with:" + start + " and end with:" + end;
  58. }
  59. }