| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AcaoAtualizaLegenda |
|
| 1.0;1 |
| 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.action; | |
| 17 | ||
| 18 | import java.awt.event.ActionEvent; | |
| 19 | import javax.swing.AbstractAction; | |
| 20 | import javax.swing.JComboBox; | |
| 21 | import javax.swing.JTable; | |
| 22 | import javax.swing.JTextArea; | |
| 23 | import net.sf.webphotos.Album; | |
| 24 | import net.sf.webphotos.PhotoDTO; | |
| 25 | import net.sf.webphotos.gui.util.TableModelFoto; | |
| 26 | import net.sf.webphotos.util.Util; | |
| 27 | ||
| 28 | /** | |
| 29 | * Atualiza legenda. Seu construtor seta todas as variáveis da classe exceto o | |
| 30 | * índice da foto. No método que implementa a ação, o índice é setado através | |
| 31 | * dos valores da seleção obtidos no programa e a partir da posição é encontrada | |
| 32 | * a foto e feita a atualização da legenda. | |
| 33 | */ | |
| 34 | public class AcaoAtualizaLegenda extends AbstractAction { | |
| 35 | ||
| 36 | /** | |
| 37 | * | |
| 38 | */ | |
| 39 | private static final long serialVersionUID = 3926799612502941998L; | |
| 40 | private JTable tbFotos; | |
| 41 | private JTextArea txtLegenda; | |
| 42 | private int indiceFoto; | |
| 43 | private JComboBox lstCreditos; | |
| 44 | ||
| 45 | /** | |
| 46 | * Construtor da classe. Recebe três parâmetros, uma tabela de fotos, um | |
| 47 | * texto de legenda e uma lista de créditos. Seta esses 3 valores para | |
| 48 | * variáveis da classe para posteriormente manipulá-las. | |
| 49 | * | |
| 50 | * @param tabela Tabela de fotos. | |
| 51 | * @param legenda Texto de legenda. | |
| 52 | * @param creditos Lista de créditos. | |
| 53 | */ | |
| 54 | 0 | public AcaoAtualizaLegenda(JTable tabela, JTextArea legenda, JComboBox creditos) { |
| 55 | 0 | tbFotos = tabela; |
| 56 | 0 | txtLegenda = legenda; |
| 57 | 0 | lstCreditos = creditos; |
| 58 | 0 | } |
| 59 | ||
| 60 | /** | |
| 61 | * Método responsável pela ação de atualização da legenda. Faz uma busca | |
| 62 | * pelo índice da foto e seta a variável fID. Logo após, instancia um objeto | |
| 63 | * PhotoDTO e indica a foto para atualização através de fID. Seta o valor da | |
| 64 | * legenda da foto, pelo valor armazenado em txtLegenda e ao final atualiza | |
| 65 | * os valores. | |
| 66 | * | |
| 67 | * @param e Evento de ação de atualização de legenda. | |
| 68 | */ | |
| 69 | @Override | |
| 70 | public void actionPerformed(ActionEvent e) { | |
| 71 | 0 | Util.out.println("indiceFoto:" + indiceFoto); |
| 72 | 0 | int fID = Integer.parseInt(tbFotos.getModel().getValueAt(tbFotos.getSelectedRow(), 0).toString()); |
| 73 | 0 | PhotoDTO f = Album.getAlbum().getFoto(fID); |
| 74 | 0 | f.setLegenda(txtLegenda.getText()); |
| 75 | 0 | TableModelFoto.getModel().update(); |
| 76 | 0 | TableModelFoto.getModel().fireTableCellUpdated(tbFotos.getSelectedRow(), 1); |
| 77 | 0 | lstCreditos.requestFocus(); |
| 78 | 0 | } |
| 79 | } |