1 50 package com.lowagie.tools.arguments; 51 52 import java.io.File; 53 54 import javax.swing.filechooser.FileFilter; 55 56 59 public class ImageFilter extends FileFilter { 60 61 62 public static final String[] IMAGES = new String[8]; 63 static { 64 IMAGES[0] = ".jpg"; 65 IMAGES[1] = ".jpeg"; 66 IMAGES[2] = ".png"; 67 IMAGES[3] = ".gif"; 68 IMAGES[4] = ".bmp"; 69 IMAGES[5] = ".wmf"; 70 IMAGES[6] = ".tif"; 71 IMAGES[7] = ".tiff"; 72 } 73 74 75 public boolean[] filter = new boolean[8]; 76 77 80 public ImageFilter() { 81 for (int i = 0; i < filter.length; i++) { 82 filter[i] = true; 83 } 84 } 85 86 95 public ImageFilter(boolean jpeg, boolean png, boolean gif, boolean bmp, boolean wmf, boolean tiff) { 96 if (jpeg) { 97 filter[0] = true; 98 filter[1] = true; 99 } 100 if (png) { 101 filter[2] = true; 102 } 103 if (gif) { 104 filter[3] = true; 105 } 106 if (bmp) { 107 filter[4] = true; 108 } 109 if (wmf) { 110 filter[5] = true; 111 } 112 if (tiff) { 113 filter[6] = true; 114 filter[7] = true; 115 } 116 } 117 118 121 public boolean accept(File f) { 122 if (f.isDirectory()) return true; 123 for (int i = 0; i < IMAGES.length; i++) { 124 if (filter[i] && f.getName().endsWith(IMAGES[i])) return true; 125 } 126 return false; 127 } 128 129 132 public String getDescription() { 133 return "Image files"; 134 } 135 } | Popular Tags |