| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AcaoItemListener |
|
| 2.3333333333333335;2,333 |
| 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.ItemEvent; | |
| 19 | import java.awt.event.ItemListener; | |
| 20 | import javax.swing.JTable; | |
| 21 | import net.sf.webphotos.Album; | |
| 22 | import net.sf.webphotos.PhotoDTO; | |
| 23 | import net.sf.webphotos.gui.PainelWebFotos; | |
| 24 | import net.sf.webphotos.gui.util.TableModelFoto; | |
| 25 | ||
| 26 | /** | |
| 27 | * Informa se o item foi ou não selecionado. Possui dois construtores, um geral | |
| 28 | * que seta um valor para a tabela de fotos e o segundo que não recebe | |
| 29 | * parâmetros, serve apenas para mudar o flag de alteração detectada. Possui um | |
| 30 | * método que identifica o elemento selecionado e faz as alterações necessárias. | |
| 31 | */ | |
| 32 | public class AcaoItemListener implements ItemListener { | |
| 33 | ||
| 34 | 6 | private JTable tbFotos = null; |
| 35 | ||
| 36 | /** | |
| 37 | * Construtor da classe. Recebe uma tabela como parâmetro e seta esse valor | |
| 38 | * para a variável tabela de fotos da classe. | |
| 39 | * | |
| 40 | * @param tabela Tabela de fotos. | |
| 41 | */ | |
| 42 | 3 | public AcaoItemListener(JTable tabela) { |
| 43 | 3 | tbFotos = tabela; |
| 44 | 3 | } |
| 45 | ||
| 46 | /** | |
| 47 | * Construtor da classe. Inicialmente vazio. Utilizado pelo combo | |
| 48 | * lstCategoriasAlbum em | |
| 49 | * {@link net.sf.webphotos.gui.PainelWebFotos PainelWebFotos}, muda somente | |
| 50 | * o flag | |
| 51 | * {@link net.sf.webphotos.gui.PainelWebFotos#alteracaoDetectada() alteracaoDetectada}. | |
| 52 | */ | |
| 53 | 3 | public AcaoItemListener() { |
| 54 | 3 | } |
| 55 | ||
| 56 | /** | |
| 57 | * Checa quando for evento de lstCategoriasAlbum, significa que o album esta | |
| 58 | * vazio, muda somente a flag de alteração detectada. Caso contrário busca | |
| 59 | * qual item, no caso foto, foi selecionado pelo usuário, seta creditoNome | |
| 60 | * com o item afetado pelo evento, atualiza o modelo do albúm e muda o flag | |
| 61 | * de alteração detectada. | |
| 62 | * | |
| 63 | * @param e Evento de item (selecionado ou não selecionado). | |
| 64 | */ | |
| 65 | @Override | |
| 66 | public void itemStateChanged(ItemEvent e) { | |
| 67 | PhotoDTO f; | |
| 68 | // quando for evento de lstCategoriasAlbum, somente muda a flag | |
| 69 | 72 | if (tbFotos == null) { |
| 70 | 12 | PainelWebFotos.alteracaoDetectada(); |
| 71 | //return; | |
| 72 | 60 | } else if (e.getStateChange() == ItemEvent.SELECTED) { |
| 73 | 30 | if (e.getItem().toString().length() > 0) { |
| 74 | 12 | Object fotoID = tbFotos.getModel().getValueAt(tbFotos.getSelectedRow(), 0); |
| 75 | try { | |
| 76 | 12 | f = (PhotoDTO) Album.getAlbum().getFoto(Integer.parseInt(fotoID.toString())); |
| 77 | 12 | } catch (Exception ex) { |
| 78 | 12 | f = (PhotoDTO) Album.getAlbum().getFoto((String) fotoID); |
| 79 | 0 | } |
| 80 | 12 | f.setCreditoNome((String) e.getItem().toString()); |
| 81 | 12 | TableModelFoto.getModel().update(); |
| 82 | 12 | TableModelFoto.getModel().fireTableCellUpdated(tbFotos.getSelectedRow(), 2); |
| 83 | 12 | PainelWebFotos.alteracaoDetectada(); |
| 84 | } | |
| 85 | } | |
| 86 | 72 | } |
| 87 | } |