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 package net.sf.webphotos.gui;
17
18 import java.io.File;
19 import javax.swing.JComponent;
20 import javax.swing.JFileChooser;
21 import net.sf.webphotos.gui.util.ImageFilter;
22
23 /**
24 * Implementa um menu para seleção de arquivos de imagem.
25 * Não possui utilizações.
26 */
27 public class AdicionarFotos {
28 private static JFileChooser fc;
29 private static int retornoFc;
30
31 private AdicionarFotos() {
32 }
33
34 /**
35 * Retorna um vetor com os arquivos selecionados para inclusão.
36 * Configura o objeto JFileChooser para escolher os arquivos, testa se as imagens são válidas através da classe ImageFilter.
37 * Seta um diretório com parâmetro caminho e retorna os arquivos selecionados.
38 * Não possui utilizações.
39 * @param caminho Caminho do diretório de imagens.
40 * @param pai Componente para busca no opendialog.
41 * @return Retorna uma lista de imagens.
42 */
43 public static File[] getFiles(String caminho, JComponent pai) {
44 fc=new JFileChooser();
45 fc.setAcceptAllFileFilterUsed(false);
46 fc.setFileFilter(new ImageFilter());
47 fc.setDialogTitle("Adicionar fotos ao álbum");
48 fc.setApproveButtonText("Ok");
49 fc.setApproveButtonToolTipText("Adiciona as fotos selecionadas ao álbum");
50 fc.setMultiSelectionEnabled(true);
51
52 File f=new File(caminho);
53 if(f.isDirectory()) {
54 fc.setCurrentDirectory(f);
55 }
56
57 retornoFc=fc.showOpenDialog(pai);
58
59 if(retornoFc==JFileChooser.APPROVE_OPTION) {
60 return fc.getSelectedFiles();
61 } else { return null; }
62 }
63 }