KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nqadmin > swingSet > formatting > SSFormattedTextFieldCustomizer


1 /*
2  * SSFormattedTextFieldCustomizer.java
3  *
4  * Created on 19 de enero de 2005, 19:47
5  */

6
7 package com.nqadmin.swingSet.formatting;
8
9 import com.nqadmin.swingSet.SSDataNavigator;
10 import com.nqadmin.swingSet.datasources.SSRowSet;
11 import java.awt.Dimension JavaDoc;
12 import java.awt.event.TextListener JavaDoc;
13 import java.beans.Customizer JavaDoc;
14 import java.beans.PropertyChangeListener JavaDoc;
15 import java.beans.PropertyChangeSupport JavaDoc;
16 import javax.swing.JComboBox JavaDoc;
17
18
19 /**
20  * @author dags
21  */

22 public class SSFormattedTextFieldCustomizer extends javax.swing.JPanel JavaDoc implements Customizer JavaDoc, TextListener JavaDoc {
23     
24     private PropertyChangeSupport JavaDoc support = new PropertyChangeSupport JavaDoc(this);
25     private SSFormattedTextField ftf = null;
26     
27     /** Creates new customizer SSFormattedTextFieldCustomizer */
28     public SSFormattedTextFieldCustomizer() {
29         super();
30         initComponents();
31
32     }
33     
34     public Dimension JavaDoc getPreferredSize() {
35         return new Dimension JavaDoc(400, 152);
36     }
37     
38     
39     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
40         support.addPropertyChangeListener(l);
41     }
42     
43     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
44         support.removePropertyChangeListener(l);
45     }
46     
47     public void setObject(Object JavaDoc bean) {
48         
49         SSDataNavigator dn1 = null;
50         SSRowSet rs = null;
51         
52         int n = 0;
53         
54         ftf = (SSFormattedTextField)bean;
55         
56         try {
57             
58             rs = ftf.getSSRowSet();
59             
60             //dn1 = ftf.getNavigator();
61

62             //rs = dn1.getRowSet();
63

64             //jTextField2.setText(((SSJdbcRowSetImpl)rs).getCommand());
65

66             rs.execute();
67             
68             jTextField1.setText("execute");
69             
70             n = rs.getColumnCount();
71             
72             jTextField1.setText("getColumnCount");
73             
74             // jTextField1.setText(String.valueOf(n));
75

76             for (int i = 1; i <= n; i++) {
77                 jComboBox3.addItem( rs.getColumnName(i));
78             }
79         } catch (java.sql.SQLException JavaDoc se) {
80             jTextField1.setText("SQLException");
81             se.printStackTrace();
82         } catch (java.lang.NullPointerException JavaDoc np) {
83             //jTextField1.setText("NullPointerException");
84
np.printStackTrace();
85         } catch (java.lang.Exception JavaDoc ex) {
86             jTextField1.setText("Exception");
87             ex.printStackTrace();
88         } finally {
89             jTextField2.setText(ftf.getColumnName());
90         }
91         
92         
93     }
94
95     public void textValueChanged(java.awt.event.TextEvent JavaDoc e) {
96     }
97     
98     /** This method is called from within the constructor to
99      * initialize the form.
100      * WARNING: Do NOT modify this code. The content of this method is
101      * always regenerated by the FormEditor.
102      */

103     private void initComponents() {//GEN-BEGIN:initComponents
104
jPanel1 = new javax.swing.JPanel JavaDoc();
105         jLabel1 = new javax.swing.JLabel JavaDoc();
106         jLabel2 = new javax.swing.JLabel JavaDoc();
107         jComboBox1 = new javax.swing.JComboBox JavaDoc();
108         jComboBox2 = new javax.swing.JComboBox JavaDoc();
109         jLabel3 = new javax.swing.JLabel JavaDoc();
110         jComboBox3 = new javax.swing.JComboBox JavaDoc();
111         jTextField1 = new javax.swing.JTextField JavaDoc();
112         jTextField2 = new javax.swing.JTextField JavaDoc();
113         jCheckBox1 = new javax.swing.JCheckBox JavaDoc();
114
115         FormListener formListener = new FormListener();
116
117         setLayout(new java.awt.BorderLayout JavaDoc(2, 2));
118
119         setMaximumSize(new java.awt.Dimension JavaDoc(400, 152));
120         setMinimumSize(new java.awt.Dimension JavaDoc(400, 152));
121         setName("SSFormattedTextField Customizer");
122         jPanel1.setLayout(null);
123
124         jPanel1.setMaximumSize(new java.awt.Dimension JavaDoc(400, 152));
125         jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(400, 152));
126         jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
127         jLabel1.setText("SSDataNavigator : ");
128         jPanel1.add(jLabel1);
129         jLabel1.setBounds(20, 20, 130, 20);
130
131         jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
132         jLabel2.setText("SSRowSet : ");
133         jPanel1.add(jLabel2);
134         jLabel2.setBounds(30, 50, 120, 20);
135
136         jComboBox1.setEditable(true);
137         jPanel1.add(jComboBox1);
138         jComboBox1.setBounds(160, 20, 200, 20);
139
140         jComboBox2.setEditable(true);
141         jPanel1.add(jComboBox2);
142         jComboBox2.setBounds(160, 50, 200, 20);
143
144         jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
145         jLabel3.setText("Column Name : ");
146         jPanel1.add(jLabel3);
147         jLabel3.setBounds(30, 80, 120, 20);
148
149         jComboBox3.setEditable(true);
150         jComboBox3.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "<none>", "account_id", "account_name", "currency_id", "instructions" }));
151         jComboBox3.addActionListener(formListener);
152
153         jPanel1.add(jComboBox3);
154         jComboBox3.setBounds(160, 80, 200, 20);
155
156         jTextField1.addKeyListener(formListener);
157
158         jPanel1.add(jTextField1);
159         jTextField1.setBounds(160, 110, 90, 19);
160
161         jTextField2.setText("jTextField2");
162         jPanel1.add(jTextField2);
163         jTextField2.setBounds(260, 110, 100, 19);
164
165         jCheckBox1.setText("jCheckBox1");
166         jPanel1.add(jCheckBox1);
167         jCheckBox1.setBounds(30, 110, 98, 23);
168
169         add(jPanel1, java.awt.BorderLayout.CENTER);
170
171     }
172
173     // Code for dispatching events from components to event handlers.
174

175     private class FormListener implements java.awt.event.ActionListener JavaDoc, java.awt.event.KeyListener JavaDoc {
176         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
177             if (evt.getSource() == jComboBox3) {
178                 SSFormattedTextFieldCustomizer.this.jComboBox3ActionPerformed(evt);
179             }
180         }
181
182         public void keyPressed(java.awt.event.KeyEvent JavaDoc evt) {
183         }
184
185         public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
186             if (evt.getSource() == jTextField1) {
187                 SSFormattedTextFieldCustomizer.this.jTextField1KeyReleased(evt);
188             }
189         }
190
191         public void keyTyped(java.awt.event.KeyEvent JavaDoc evt) {
192         }
193     }//GEN-END:initComponents
194

195     private void jComboBox3ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
196
// TODO add your handling code here:
197
// TODO add your handling code here:
198

199         JComboBox JavaDoc s = (JComboBox JavaDoc)(evt.getSource());
200         
201         String JavaDoc colName = null;
202         String JavaDoc oldName = null;
203         
204         oldName = ftf.getColumnName();
205         colName = ((String JavaDoc)(s.getSelectedItem()));
206         
207         ftf.setColumnName(colName);
208         support.firePropertyChange("columnName", oldName, colName);
209         
210     }//GEN-LAST:event_jComboBox3ActionPerformed
211

212     private void jTextField1KeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTextField1KeyReleased
213
// TODO add your handling code here:
214
ftf.setColumnName(jTextField1.getText());
215         firePropertyChange("columnName", null, jTextField1.getText());
216         
217     }//GEN-LAST:event_jTextField1KeyReleased
218

219     
220     // Variables declaration - do not modify//GEN-BEGIN:variables
221
javax.swing.JCheckBox JavaDoc jCheckBox1;
222     javax.swing.JComboBox JavaDoc jComboBox1;
223     javax.swing.JComboBox JavaDoc jComboBox2;
224     javax.swing.JComboBox JavaDoc jComboBox3;
225     javax.swing.JLabel JavaDoc jLabel1;
226     javax.swing.JLabel JavaDoc jLabel2;
227     javax.swing.JLabel JavaDoc jLabel3;
228     javax.swing.JPanel JavaDoc jPanel1;
229     javax.swing.JTextField JavaDoc jTextField1;
230     javax.swing.JTextField JavaDoc jTextField2;
231     // End of variables declaration//GEN-END:variables
232

233 }
234
Popular Tags