1 /**
2 * Copyright 2008 WebPhotos
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 /*
17 * ImageFilter.java
18 *
19 * Created on 11 de Maio de 2007, 12:44
20 *
21 * To change this template, choose Tools | Template Manager
22 * and open the template in the editor.
23 */
24
25 package net.sf.webphotos.gui.util;
26
27 import java.io.File;
28 import javax.swing.filechooser.FileFilter;
29
30 /**
31 * Filtro da seleção de imagens.
32 * @author felipe
33 */
34 public class ImageFilter extends FileFilter {
35 String ext;
36
37 /**
38 * Retorna uma variável lógica que indica se o arquivo é válido.
39 * Aceita todos os diretorios e formatos de imagem .jpeg e .jpg.
40 * @param f Arquivo ou diretório.
41 * @return Retorna um valor lógico.
42 */
43 @Override
44 public boolean accept(File f) {
45 if (f.isDirectory()) {
46 return true;
47 }
48 String nmArquivo=f.getName();
49 int pos=nmArquivo.lastIndexOf('.');
50 if(pos > 0 && pos < nmArquivo.length()-1) {
51 ext=nmArquivo.substring(pos+1).toLowerCase();
52 }
53
54 if(ext.equals("jpg") || ext.equals("jpeg")) {
55 return true;
56 }
57
58 return false;
59 }
60
61 /**
62 * Retorna a descrição "Imagens jpeg e jpg".
63 * @return Retorna uma descrição.
64 */
65 @Override
66 public String getDescription() {
67 return "Imagens jpeg e jpg";
68 }
69 }