thomasfelix

PBO EAS

Jan 11th, 2021
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package jobme.pk;
  7.  
  8. /**
  9.  *
  10.  * @author Majey
  11.  */
  12. import java.io.File;
  13. import javax.swing.filechooser.FileFilter;
  14.  
  15. /**
  16.  *
  17.  * @author Majey
  18.  */
  19. public class FileTypeFilter extends FileFilter{
  20.    
  21.     // File Extentions String
  22.     private final String extension;
  23.     // File Extension Description
  24.     private final String description;
  25.    
  26.     // Constructor Method
  27.     public FileTypeFilter(String extension, String description){
  28.         // Set Contructor Values
  29.         this.extension = extension;
  30.         this.description = description;
  31.     }
  32.    
  33.     @Override
  34.     public boolean accept(File file) {
  35.         // If File Is Returning Directory
  36.         if(file.isDirectory()){
  37.             return true;
  38.         }
  39.         // Return File Name with Extension
  40.         return file.getName().endsWith(extension);
  41.     }
  42.  
  43.     @Override
  44.     public String getDescription() {
  45.         // Return To Display File Type and Description
  46.         return description + String.format(" (*%s)", extension);
  47.     }
  48.    
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment