| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package net.sf.webphotos.action; |
| 17 | |
|
| 18 | |
import java.awt.event.ActionEvent; |
| 19 | |
import java.io.File; |
| 20 | |
import javax.swing.AbstractAction; |
| 21 | |
import javax.swing.JComboBox; |
| 22 | |
import javax.swing.JFileChooser; |
| 23 | |
import javax.swing.JTable; |
| 24 | |
import net.sf.webphotos.Album; |
| 25 | |
import net.sf.webphotos.gui.PainelWebFotos; |
| 26 | |
import net.sf.webphotos.gui.util.ImageFilter; |
| 27 | |
import net.sf.webphotos.gui.util.TableModelFoto; |
| 28 | |
import net.sf.webphotos.gui.util.TableSorter; |
| 29 | |
import net.sf.webphotos.util.Util; |
| 30 | |
import org.apache.commons.configuration.Configuration; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
public class AcaoAdicionarFoto extends AbstractAction { |
| 37 | |
|
| 38 | |
private static final long serialVersionUID = 8331561928830049243L; |
| 39 | |
private static File diretorioInicial; |
| 40 | |
private JFileChooser fileChooser; |
| 41 | |
private JTable tbFotos; |
| 42 | |
private String larguraColunasFotos; |
| 43 | |
private String titulo; |
| 44 | |
private JComboBox lstCreditosTabelaFotos; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | 6 | public AcaoAdicionarFoto(JTable tabela, JComboBox combo, String tituloDialogo) { |
| 58 | 6 | Configuration c = Util.getConfig(); |
| 59 | 6 | diretorioInicial = Util.getFolder("diretorioAdicionarFotos"); |
| 60 | 6 | tbFotos = tabela; |
| 61 | 6 | lstCreditosTabelaFotos = combo; |
| 62 | 6 | larguraColunasFotos = c.getString("colunas2"); |
| 63 | 6 | titulo = tituloDialogo; |
| 64 | 6 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
@Override |
| 77 | |
public void actionPerformed(ActionEvent e) { |
| 78 | 6 | fileChooser = new JFileChooser(); |
| 79 | 6 | fileChooser.setAcceptAllFileFilterUsed(false); |
| 80 | 6 | fileChooser.setFileFilter(new ImageFilter()); |
| 81 | 6 | fileChooser.setDialogTitle(titulo); |
| 82 | 6 | fileChooser.setApproveButtonText("Ok"); |
| 83 | 6 | fileChooser.setApproveButtonToolTipText("Adiciona as fotos selecionadas ao álbum"); |
| 84 | 6 | fileChooser.setMultiSelectionEnabled(true); |
| 85 | |
|
| 86 | 6 | if (diretorioInicial != null && diretorioInicial.isDirectory()) { |
| 87 | 6 | fileChooser.setCurrentDirectory(diretorioInicial); |
| 88 | |
} |
| 89 | |
|
| 90 | 6 | int retornoFc = fileChooser.showOpenDialog(null); |
| 91 | |
|
| 92 | 6 | if (retornoFc == JFileChooser.APPROVE_OPTION && fileChooser.getSelectedFiles().length > 0) { |
| 93 | 6 | Album.getAlbum().adicionarFotos(fileChooser.getSelectedFiles()); |
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | 6 | TableModelFoto.getModel().update(); |
| 99 | 6 | TableModelFoto.getModel().fireTableDataChanged(); |
| 100 | 6 | tbFotos.setModel(new TableSorter(TableModelFoto.getModel(), tbFotos.getTableHeader())); |
| 101 | 6 | tbFotos.getColumnModel().getColumn(2).setCellEditor(new javax.swing.DefaultCellEditor(lstCreditosTabelaFotos)); |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | 6 | Util.ajustaLargura(tbFotos, larguraColunasFotos); |
| 107 | 6 | tbFotos.repaint(); |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | 6 | PainelWebFotos.alteracaoDetectada(); |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | 6 | diretorioInicial = null; |
| 118 | 6 | diretorioInicial = new File(fileChooser.getSelectedFiles()[0].getParent()); |
| 119 | |
} |
| 120 | 6 | } |
| 121 | |
} |