| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PopupMenu |
|
| 1.25;1,25 |
| 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 javax.swing.*; | |
| 19 | import net.sf.webphotos.action.AcaoPopup; | |
| 20 | import net.sf.webphotos.util.Util; | |
| 21 | ||
| 22 | /** | |
| 23 | * Cria um menu popup com os dados do albúm. | |
| 24 | * Monta a parte gráfica e puxa as ações da classe {@link net.sf.webphotos.gui.AcaoPopMenu AcaoPopMenu}. | |
| 25 | * Possui utilizações nas classes PopupMenuTest em pacotes de teste e PainelPesquisa em pacotes de código-fonte. | |
| 26 | */ | |
| 27 | public class PopupMenu extends JPopupMenu { | |
| 28 | 9 | private String preSQL="select albumID as ID, categorias.nmcategoria as Categoria, nmalbum as Pauta, DATE_FORMAT(DtInsercao, '%d/%m/%y') as Data from albuns left join categorias using(categoriaID) "; |
| 29 | ||
| 30 | /** | |
| 31 | * Construtor da classe. | |
| 32 | * Cria os itens do menu e envia o evento para a classe AcaoPopMenu que se encarregará de gerar o menu. | |
| 33 | */ | |
| 34 | 9 | public PopupMenu() { |
| 35 | String posSQL; | |
| 36 | 9 | int ct=1; |
| 37 | ||
| 38 | 36 | while((posSQL=Util.getConfig().getString("relatorio" + ct++))!=null) { |
| 39 | 27 | int pos=posSQL.indexOf('/'); |
| 40 | 27 | String nomeComando=posSQL.substring(0,pos).trim(); |
| 41 | 27 | String comando=posSQL.substring(pos+1).trim(); |
| 42 | ||
| 43 | 27 | JMenuItem menuItem=new JMenuItem(nomeComando, new ImageIcon(getClass().getResource("/icons/pontoazul.gif"))); |
| 44 | ||
| 45 | 27 | menuItem.addActionListener(new AcaoPopMenu(comando)); |
| 46 | 27 | this.add(menuItem); |
| 47 | 27 | } |
| 48 | ||
| 49 | 9 | } |
| 50 | ||
| 51 | /** | |
| 52 | * Método principal. | |
| 53 | * Cria um objeto PopupMenu e um frame para armazenar esse menu. | |
| 54 | * Seta toda a configuração e chama a classe AcaoPopup para trabalhar o evento de clique do mouse. | |
| 55 | * @param a args do método main. | |
| 56 | */ | |
| 57 | public static void main(String[] a) { | |
| 58 | 0 | PopupMenu t=new PopupMenu(); |
| 59 | 0 | JFrame f=new JFrame(); |
| 60 | 0 | f.getContentPane().setLayout(null); |
| 61 | ||
| 62 | 0 | JButton bt=new JButton("teste"); |
| 63 | 0 | bt.setBounds(20,20,100,25); |
| 64 | 0 | bt.addMouseListener(new AcaoPopup((JPopupMenu) t)); |
| 65 | 0 | f.getContentPane().add(bt); |
| 66 | ||
| 67 | ||
| 68 | 0 | f.setSize(200,200); |
| 69 | 0 | f.getContentPane().add(t); |
| 70 | //t.show(); | |
| 71 | 0 | f.setVisible(true); |
| 72 | 0 | } |
| 73 | ||
| 74 | /** | |
| 75 | * Retorna uma query de SQL. | |
| 76 | * @return Retorna uma query. | |
| 77 | */ | |
| 78 | public String getPreSQL() { | |
| 79 | 6 | return preSQL; |
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * Seta uma nova query para a variável preSQL. | |
| 84 | * @param preSQL Query. | |
| 85 | */ | |
| 86 | public void setPreSQL(String preSQL) { | |
| 87 | 3 | this.preSQL = preSQL; |
| 88 | 3 | } |
| 89 | ||
| 90 | } |