1 33 34 package com.nqadmin.swingSet.formatting.helpers; 35 import java.awt.event.ActionListener ; 36 37 41 public class SelectorPopupPanel extends javax.swing.JPanel implements ActionListener { 42 43 private javax.swing.ListModel model = null; 44 45 46 public SelectorPopupPanel() { 47 initComponents(); 48 selectorList1.setModel(selectorListModel1); 49 } 50 51 public SelectorPopupPanel(javax.swing.ListModel model) { 52 initComponents(); 53 selectorList1.setModel(model); 54 } 55 56 61 private void initComponents() { java.awt.GridBagConstraints 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 (); 67 jTextField1 = new javax.swing.JTextField (); 68 jButton1 = new javax.swing.JButton (); 69 jScrollPane1 = new javax.swing.JScrollPane (); 70 selectorList1 = new com.nqadmin.swingSet.formatting.helpers.SelectorList(); 71 jLabel1 = new javax.swing.JLabel (); 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 nf) { 80 System.out.println(nf); 81 } 82 catch (java.lang.Exception 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 ()); 93 94 setBorder(new javax.swing.border.TitledBorder ("Selector")); 95 setFocusable(false); 96 jPanel1.setLayout(new java.awt.GridBagLayout ()); 97 98 jTextField1.setColumns(20); 99 jTextField1.addActionListener(new java.awt.event.ActionListener () { 100 public void actionPerformed(java.awt.event.ActionEvent evt) { 101 jTextField1ActionPerformed(evt); 102 } 103 }); 104 105 gridBagConstraints = new java.awt.GridBagConstraints (); 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 ("Dialog", 1, 10)); 114 jButton1.setText("Buscar"); 115 jButton1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 1, 1, 1))); 116 jButton1.addActionListener(new java.awt.event.ActionListener () { 117 public void actionPerformed(java.awt.event.ActionEvent evt) { 118 jButton1ActionPerformed(evt); 119 } 120 }); 121 122 gridBagConstraints = new java.awt.GridBagConstraints (); 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 } 144 private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { 147 javax.swing.JTextField s; 148 int j, n; 149 String toFind = null; 151 s= ((javax.swing.JTextField )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 162 163 for (j= 0; j < n; j++) { 164 String 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 } 175 public void setModel(javax.swing.ListModel model) { 176 this.model = model; 177 selectorList1.setModel(this.model); 178 } 179 180 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { 182 System.out.println("Search Action Performed"); 183 184 } 187 188 javax.swing.JButton jButton1; 190 javax.swing.JLabel jLabel1; 191 javax.swing.JPanel jPanel1; 192 javax.swing.JScrollPane jScrollPane1; 193 javax.swing.JTextField 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 199 public static void main(String args[]) 200 { 201 javax.swing.JFrame frame = new javax.swing.JFrame (); 203 frame.setLayout(new java.awt.BorderLayout ()); 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 e) { 210 } 211 } 212 | Popular Tags |