KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > connection > wizard > advanced > AdvancedPanel


1 /*
2  * Copyright 2002-2004 Greg Hinkle
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
17 package org.mc4j.console.connection.wizard.advanced;
18
19 import javax.swing.table.DefaultTableModel JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Properties JavaDoc;
23 import java.util.Vector JavaDoc;
24
25
26
27 /**
28  *
29  * @author Administrator
30  */

31 public class AdvancedPanel extends javax.swing.JPanel JavaDoc {
32     
33     /** Creates new form AdvancedPanel */
34     public AdvancedPanel(Map JavaDoc properties) {
35         initComponents();
36         if (properties != null) {
37             setProperties(properties);
38         }
39     }
40
41     private void setProperties(Map JavaDoc properties) {
42         DefaultTableModel JavaDoc model = (DefaultTableModel JavaDoc) this.propertyTable.getModel();
43         for (Iterator JavaDoc iterator = properties.entrySet().iterator(); iterator.hasNext();) {
44             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iterator.next();
45             String JavaDoc key = (String JavaDoc) entry.getKey();
46             String JavaDoc value = (String JavaDoc) entry.getValue();
47
48             Vector JavaDoc row = new Vector JavaDoc();
49             row.add(key); row.add(value);
50             model.addRow(row);
51         }
52     }
53
54     public Properties JavaDoc getProperties() {
55         Properties JavaDoc properties = new Properties JavaDoc();
56         DefaultTableModel JavaDoc model = (DefaultTableModel JavaDoc) this.propertyTable.getModel();
57         Vector JavaDoc data = model.getDataVector();
58         for (Object JavaDoc aData : data) {
59             Vector JavaDoc vector = (Vector JavaDoc) aData;
60             String JavaDoc key = (String JavaDoc) vector.get(0);
61             String JavaDoc value = (String JavaDoc) vector.get(0);
62             properties.put(key, value);
63         }
64         return properties;
65     }
66
67
68     /** This method is called from within the constructor to
69      * initialize the form.
70      * WARNING: Do NOT modify this code. The content of this method is
71      * always regenerated by the Form Editor.
72      */

73     private void initComponents() {//GEN-BEGIN:initComponents
74
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
75
76         borderLayout1 = new java.awt.BorderLayout JavaDoc();
77         infoLabel = new javax.swing.JLabel JavaDoc();
78         propertyTableScrollPane = new javax.swing.JScrollPane JavaDoc();
79         propertyTable = new javax.swing.JTable JavaDoc();
80         rightButtonPanel = new javax.swing.JPanel JavaDoc();
81         addButton = new javax.swing.JButton JavaDoc();
82         removeButton = new javax.swing.JButton JavaDoc();
83
84         setLayout(new java.awt.GridBagLayout JavaDoc());
85
86         infoLabel.setText("Add new connection properties here...");
87         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
88         gridBagConstraints.insets = new java.awt.Insets JavaDoc(8, 8, 8, 8);
89         add(infoLabel, gridBagConstraints);
90
91         propertyTable.setModel(new javax.swing.table.DefaultTableModel JavaDoc(
92             new Object JavaDoc [][] {
93
94             },
95             new String JavaDoc [] {
96                 "Name", "Value"
97             }
98         ) {
99             Class JavaDoc[] types = new Class JavaDoc [] {
100                 java.lang.String JavaDoc.class, java.lang.String JavaDoc.class
101             };
102
103             public Class JavaDoc getColumnClass(int columnIndex) {
104                 return types [columnIndex];
105             }
106         });
107         propertyTableScrollPane.setViewportView(propertyTable);
108
109         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
110         gridBagConstraints.gridx = 0;
111         gridBagConstraints.gridy = 1;
112         gridBagConstraints.gridheight = 2;
113         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
114         gridBagConstraints.weightx = 1.0;
115         gridBagConstraints.weighty = 1.0;
116         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 5, 5);
117         add(propertyTableScrollPane, gridBagConstraints);
118
119         rightButtonPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
120
121         addButton.setText("Add");
122         addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
123             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
124                 addButtonActionPerformed(evt);
125             }
126         });
127
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
131         rightButtonPanel.add(addButton, gridBagConstraints);
132
133         removeButton.setText("Remove");
134         removeButton.setEnabled(false);
135         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
136             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
137                 removeButtonActionPerformed(evt);
138             }
139         });
140
141         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142         gridBagConstraints.gridx = 0;
143         gridBagConstraints.gridy = 1;
144         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
145         gridBagConstraints.insets = new java.awt.Insets JavaDoc(4, 4, 4, 4);
146         rightButtonPanel.add(removeButton, gridBagConstraints);
147
148         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
149         gridBagConstraints.gridx = 1;
150         gridBagConstraints.gridy = 1;
151         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
152         add(rightButtonPanel, gridBagConstraints);
153
154     }//GEN-END:initComponents
155

156     private void removeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeButtonActionPerformed
157
int rowSelection = this.propertyTable.getSelectedRow();
158         DefaultTableModel JavaDoc model = (DefaultTableModel JavaDoc) this.propertyTable.getModel();
159         model.removeRow(rowSelection);
160     }//GEN-LAST:event_removeButtonActionPerformed
161

162     private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addButtonActionPerformed
163
DefaultTableModel JavaDoc model = (DefaultTableModel JavaDoc) this.propertyTable.getModel();
164         model.addRow(new Object JavaDoc[] { "", "" });
165
166     }//GEN-LAST:event_addButtonActionPerformed
167

168
169     // Variables declaration - do not modify//GEN-BEGIN:variables
170
private javax.swing.JButton JavaDoc addButton;
171     private java.awt.BorderLayout JavaDoc borderLayout1;
172     private javax.swing.JLabel JavaDoc infoLabel;
173     private javax.swing.JTable JavaDoc propertyTable;
174     private javax.swing.JScrollPane JavaDoc propertyTableScrollPane;
175     private javax.swing.JButton JavaDoc removeButton;
176     private javax.swing.JPanel JavaDoc rightButtonPanel;
177     // End of variables declaration//GEN-END:variables
178

179 }
180
Popular Tags