KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nqadmin > swingSet > formatting > helpers > SelectorPopupPanel


1 /* $Id: SelectorPopupPanel.java,v 1.4 2005/02/04 22:42:15 yoda2 Exp $
2  *
3  * Tab Spacing = 4
4  *
5  * Copyright (c) 2004-2005, The Pangburn Company, Prasanth R. Pasala and
6  * Diego Gil
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * Redistributions of source code must retain the above copyright notice, this
13  * list of conditions and the following disclaimer. Redistributions in binary
14  * form must reproduce the above copyright notice, this list of conditions and
15  * the following disclaimer in the documentation and/or other materials
16  * provided with the distribution. The names of its contributors may not be
17  * used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  */

33
34 package com.nqadmin.swingSet.formatting.helpers;
35 import java.awt.event.ActionListener JavaDoc;
36
37 /**
38  *
39  * @author dags
40  */

41 public class SelectorPopupPanel extends javax.swing.JPanel JavaDoc implements ActionListener JavaDoc {
42     
43     private javax.swing.ListModel JavaDoc model = null;
44     
45     /** Creates new form SelectorPopupPanel */
46     public SelectorPopupPanel() {
47         initComponents();
48         selectorList1.setModel(selectorListModel1);
49     }
50     
51     public SelectorPopupPanel(javax.swing.ListModel JavaDoc model) {
52         initComponents();
53         selectorList1.setModel(model);
54     }
55     
56     /** This method is called from within the constructor to
57      * initialize the form.
58      * WARNING: Do NOT modify this code. The content of this method is
59      * always regenerated by the Form Editor.
60      */

61     private void initComponents() {//GEN-BEGIN:initComponents
62
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
63
64         sSConnection1 = new com.nqadmin.swingSet.datasources.SSConnection();
65         selectorListModel1 = new com.nqadmin.swingSet.formatting.helpers.SelectorListModel();
66         jPanel1 = new javax.swing.JPanel JavaDoc();
67         jTextField1 = new javax.swing.JTextField JavaDoc();
68         jButton1 = new javax.swing.JButton JavaDoc();
69         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
70         selectorList1 = new com.nqadmin.swingSet.formatting.helpers.SelectorList();
71         jLabel1 = new javax.swing.JLabel JavaDoc();
72
73         sSConnection1.setDriverName("org.postgresql.Driver");
74         sSConnection1.setUrl("jdbc:postgresql://localhost/mag");
75         sSConnection1.setUsername("dags");
76         try {
77             sSConnection1.createConnection();
78         }
79         catch (java.lang.ClassNotFoundException JavaDoc nf) {
80             System.out.println(nf);
81         }
82         catch (java.lang.Exception JavaDoc ex) {
83             System.out.println(ex);
84         }
85         selectorListModel1.setDataColumn("publication_id");
86         selectorListModel1.setListColumn("publication_title");
87         selectorListModel1.setOrderBy("publication_title");
88         selectorListModel1.setSsConnection(sSConnection1);
89         selectorListModel1.setTable("publications");
90         selectorListModel1.refresh();
91
92         setLayout(new java.awt.BorderLayout JavaDoc());
93
94         setBorder(new javax.swing.border.TitledBorder JavaDoc("Selector"));
95         setFocusable(false);
96         jPanel1.setLayout(new java.awt.GridBagLayout JavaDoc());
97
98         jTextField1.setColumns(20);
99         jTextField1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
100             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
101                 jTextField1ActionPerformed(evt);
102             }
103         });
104
105         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
106         gridBagConstraints.gridx = 0;
107         gridBagConstraints.gridy = 0;
108         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
109         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
110         gridBagConstraints.weightx = 0.8;
111         jPanel1.add(jTextField1, gridBagConstraints);
112
113         jButton1.setFont(new java.awt.Font JavaDoc("Dialog", 1, 10));
114         jButton1.setText("Buscar");
115         jButton1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 1, 1, 1)));
116         jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
117             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
118                 jButton1ActionPerformed(evt);
119             }
120         });
121
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridx = 1;
124         gridBagConstraints.gridy = 0;
125         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
126         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
127         gridBagConstraints.weightx = 0.2;
128         jPanel1.add(jButton1, gridBagConstraints);
129
130         add(jPanel1, java.awt.BorderLayout.SOUTH);
131
132         jScrollPane1.setFocusable(false);
133         selectorList1.setDoubleBuffered(true);
134         jScrollPane1.setViewportView(selectorList1);
135
136         add(jScrollPane1, java.awt.BorderLayout.CENTER);
137
138         jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
139         jLabel1.setText("Selecci\u00f3n");
140         add(jLabel1, java.awt.BorderLayout.NORTH);
141
142     }//GEN-END:initComponents
143

144     private void jTextField1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jTextField1ActionPerformed
145
// TODO add your handling code here:
146

147         javax.swing.JTextField JavaDoc s;
148         int j, n;
149         // text to find
150
String JavaDoc toFind = null;
151         s= ((javax.swing.JTextField JavaDoc)evt.getSource());
152         toFind = s.getText().toUpperCase();
153         s.setText(toFind);
154         System.out.println("Texto a buscar : " + toFind);
155         n = selectorList1.getModel().getSize();
156         
157         /**
158          * Here implements list search logic.
159          *
160          *
161          */

162         
163         for (j= 0; j < n; j++) {
164             String JavaDoc texto = selectorList1.getModel().getElementAt(j).toString().toUpperCase();
165             System.out.println("Comparando con " + texto);
166             if (texto.startsWith(toFind)) {
167                 selectorList1.setSelectedIndex(j);
168                 selectorList1.ensureIndexIsVisible(j);
169                 selectorList1.requestFocus();
170                 break;
171             }
172         }
173     }//GEN-LAST:event_jTextField1ActionPerformed
174

175     public void setModel(javax.swing.ListModel JavaDoc model) {
176         this.model = model;
177         selectorList1.setModel(this.model);
178     }
179     
180     private void jButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButton1ActionPerformed
181

182         System.out.println("Search Action Performed");
183         
184         // TODO add your handling code here:
185
}//GEN-LAST:event_jButton1ActionPerformed
186

187     
188     // Variables declaration - do not modify//GEN-BEGIN:variables
189
javax.swing.JButton JavaDoc jButton1;
190     javax.swing.JLabel JavaDoc jLabel1;
191     javax.swing.JPanel JavaDoc jPanel1;
192     javax.swing.JScrollPane JavaDoc jScrollPane1;
193     javax.swing.JTextField JavaDoc jTextField1;
194     com.nqadmin.swingSet.datasources.SSConnection sSConnection1;
195     com.nqadmin.swingSet.formatting.helpers.SelectorList selectorList1;
196     com.nqadmin.swingSet.formatting.helpers.SelectorListModel selectorListModel1;
197     // End of variables declaration//GEN-END:variables
198

199     public static void main(String JavaDoc args[])
200     {
201         // ejemplo
202
javax.swing.JFrame JavaDoc frame = new javax.swing.JFrame JavaDoc();
203         frame.setLayout(new java.awt.BorderLayout JavaDoc());
204         frame.add(new SelectorPopupPanel(), java.awt.BorderLayout.CENTER);
205         frame.setSize(640, 480);
206         frame.setVisible(true);
207     }
208
209     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
210     }
211 }
212
Popular Tags