View Javadoc

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.component;
17  
18  /**
19   * PainelPesquisa.java
20   *
21   * Created on 13 de Janeiro de 2006, 12:33
22   */
23  import java.awt.event.MouseListener;
24  import java.io.Serializable;
25  import javax.swing.JPanel;
26  import net.sf.webphotos.action.AcaoPesquisa;
27  
28  /**
29   * Desenvolve um painel para pesquisas. Através do construtor, trabalha os
30   * eventos para obter o resultado das pesquisas.
31   *
32   * @author guilherme
33   */
34  public class PainelPesquisa extends JPanel implements Serializable {
35      
36      private AcaoPesquisa acaoPesquisa;
37      
38      /**
39       * Construtor da classe. Chama o método initComponents(), responsável por
40       * gerar o painel. Trata os eventos e as ações de pesquisa.
41       */
42      public PainelPesquisa() {
43          initComponents();
44  
45          // ACAO PESQUISA
46          // TODO: Reformular esse trecho (ver versão anterior)
47          //acaoPesquisa = new AcaoPesquisa(lstCategoriasPesquisa, txtPesquisa, tbAlbuns);
48          //registerResearchActionComponent(acaoPesquisa);
49  
50      }
51  
52      private void registerResearchActionComponent(AcaoPesquisa acaoPesquisa) {
53          btPesquisar.addActionListener(acaoPesquisa);
54          txtPesquisa.registerKeyboardAction(acaoPesquisa,
55                  javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0),
56                  javax.swing.JComponent.WHEN_FOCUSED);
57      }
58  
59      /**
60       * This method is called from within the constructor to initialize the form.
61       * WARNING: Do NOT modify this code. The content of this method is always
62       * regenerated by the Form Editor.
63       */
64      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
65      private void initComponents() {
66  
67          painelBusca = new javax.swing.JPanel();
68          lblPesquisar = new javax.swing.JLabel();
69          lstCategoriasPesquisa = new javax.swing.JComboBox();
70          lblPalavras = new javax.swing.JLabel();
71          txtPesquisa = new javax.swing.JTextField();
72          btPesquisar = new javax.swing.JButton();
73          painelSQL = new javax.swing.JPanel();
74          btFiltro = new javax.swing.JButton();
75  
76          setMaximumSize(new java.awt.Dimension(65534, 35));
77          setMinimumSize(new java.awt.Dimension(780, 35));
78          setPreferredSize(new java.awt.Dimension(780, 35));
79          setLayout(new java.awt.BorderLayout());
80  
81          painelBusca.setMaximumSize(new java.awt.Dimension(32767, 35));
82          painelBusca.setPreferredSize(new java.awt.Dimension(461, 35));
83          painelBusca.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
84  
85          lblPesquisar.setText("Pesquisar em");
86          painelBusca.add(lblPesquisar);
87  
88          lstCategoriasPesquisa.setName("lstCategoriasPesquisa"); // NOI18N
89          painelBusca.add(lstCategoriasPesquisa);
90  
91          lblPalavras.setText("palavra(s)");
92          painelBusca.add(lblPalavras);
93  
94          txtPesquisa.setMinimumSize(new java.awt.Dimension(192, 19));
95          txtPesquisa.setPreferredSize(new java.awt.Dimension(192, 19));
96          painelBusca.add(txtPesquisa);
97  
98          btPesquisar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/zoom16.gif"))); // NOI18N
99          btPesquisar.setText("pesquisar");
100         painelBusca.add(btPesquisar);
101 
102         add(painelBusca, java.awt.BorderLayout.CENTER);
103 
104         painelSQL.setMaximumSize(new java.awt.Dimension(32767, 35));
105         painelSQL.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
106 
107         btFiltro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/sql.gif"))); // NOI18N
108         painelSQL.add(btFiltro);
109 
110         add(painelSQL, java.awt.BorderLayout.EAST);
111     }// </editor-fold>//GEN-END:initComponents
112     // Variables declaration - do not modify//GEN-BEGIN:variables
113     private javax.swing.JButton btFiltro;
114     private javax.swing.JButton btPesquisar;
115     private javax.swing.JLabel lblPalavras;
116     private javax.swing.JLabel lblPesquisar;
117     private javax.swing.JComboBox lstCategoriasPesquisa;
118     private javax.swing.JPanel painelBusca;
119     private javax.swing.JPanel painelSQL;
120     private javax.swing.JTextField txtPesquisa;
121     // End of variables declaration//GEN-END:variables
122     // Bean Variables
123     private javax.swing.ComboBoxModel categoriasPesquisaComboBoxModel;
124 
125     /**
126      * Retorna a {@link javax.swing.ComboBoxModel ComboBoxModel}
127      * categoriasPesquisaComboBoxModel.
128      *
129      * @return Retorna uma ComboBoxModel.
130      */
131     public javax.swing.ComboBoxModel getCategoriasPesquisaComboBoxModel() {
132         return categoriasPesquisaComboBoxModel;
133     }
134 
135     /**
136      * Sets a {@link javax.swing.ComboBoxModel ComboBoxModel}
137      * categoriasPesquisaComboBoxModel.
138      *
139      * @param lstCategoriasPesquisaModel Modelo de lista de categorias para a
140      * pesquisa.
141      */
142     public void setCategoriasPesquisaComboBoxModel(javax.swing.ComboBoxModel lstCategoriasPesquisaModel) {
143         this.categoriasPesquisaComboBoxModel = lstCategoriasPesquisaModel;
144         lstCategoriasPesquisa.setModel(this.categoriasPesquisaComboBoxModel);
145     }
146 
147     /**
148      * @param popupAction the popupAction to add
149      */
150     public void addPopupMouseListener(MouseListener popupAction) {
151         btFiltro.addMouseListener(popupAction);
152     }
153     
154     /**
155      * @param popupAction the popupAction to remove
156      */
157     public void removePopupMouseListener(MouseListener popupAction) {
158         btFiltro.removeMouseListener(popupAction);
159     }
160 
161     /**
162      * @return the acaoPesquisa
163      */
164     public AcaoPesquisa getAcaoPesquisa() {
165         return acaoPesquisa;
166     }
167 
168     /**
169      * @param acaoPesquisa the acaoPesquisa to set
170      */
171     public synchronized void setAcaoPesquisa(AcaoPesquisa acaoPesquisa) {
172         this.acaoPesquisa = acaoPesquisa;
173         registerResearchActionComponent(this.acaoPesquisa);        
174     }
175 }