KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Browser > NodeNameLicListEditDialog


1 /*
2  * NodeNameLicListEditDialog.java
3  *
4  * Created on 12. květen 2004, 22:35
5  */

6
7 package SOFA.SOFAnet.Browser;
8
9 import SOFA.SOFAnet.Repository.NodeNameLicList;
10 import java.util.*;
11 import javax.swing.*;
12 import java.awt.Component JavaDoc;
13 import java.awt.Frame JavaDoc;
14
15 /**
16  *
17  * @author Ladislav Sobr
18  */

19 public class NodeNameLicListEditDialog extends javax.swing.JDialog JavaDoc
20 {
21   private boolean isOK;
22   private NodeNameLicList nodeNameLicList;
23   private DefaultListModel content;
24   
25   public static boolean showDialog(Component JavaDoc frameComp, NodeNameLicList nodeNameLicList, String JavaDoc title)
26   {
27     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
28     NodeNameLicListEditDialog dialog = new NodeNameLicListEditDialog(frame, true, nodeNameLicList, title);
29     dialog.setVisible(true);
30     return dialog.isOK();
31     
32   }
33   /** Creates new form NodeNameLicListEditDialog */
34   public NodeNameLicListEditDialog(java.awt.Frame JavaDoc parent, boolean modal, NodeNameLicList nodeNameLicList, String JavaDoc title)
35   {
36     super(parent, modal);
37     this.nodeNameLicList = nodeNameLicList;
38     
39     isOK = false;
40     content = new DefaultListModel();
41     
42     content.ensureCapacity(nodeNameLicList.getList().size());
43     Iterator it = nodeNameLicList.getList().iterator();
44     while (it.hasNext()) content.addElement(((NodeNameLicList.NodeLicPair)it.next()).clone());
45     
46     initComponents();
47     setLocationRelativeTo(parent);
48     setTitle(title);
49     
50     jLabel.setText("Node Name - Licence List");
51   }
52   
53   public boolean isOK()
54   {
55     return isOK;
56   }
57   
58   
59   /** This method is called from within the constructor to
60    * initialize the form.
61    * WARNING: Do NOT modify this code. The content of this method is
62    * always regenerated by the Form Editor.
63    */

64   private void initComponents()//GEN-BEGIN:initComponents
65
{
66     jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
67     jList = new javax.swing.JList JavaDoc();
68     jPanel1 = new javax.swing.JPanel JavaDoc();
69     jPanel5 = new javax.swing.JPanel JavaDoc();
70     setButton = new javax.swing.JButton JavaDoc();
71     cancelButton = new javax.swing.JButton JavaDoc();
72     jPanel2 = new javax.swing.JPanel JavaDoc();
73     jPanel3 = new javax.swing.JPanel JavaDoc();
74     addButton = new javax.swing.JButton JavaDoc();
75     deleteSelectedButton = new javax.swing.JButton JavaDoc();
76     moveUpButton = new javax.swing.JButton JavaDoc();
77     moveDownButton = new javax.swing.JButton JavaDoc();
78     jPanel4 = new javax.swing.JPanel JavaDoc();
79     jLabel = new javax.swing.JLabel JavaDoc();
80
81     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
82     jScrollPane1.setMinimumSize(new java.awt.Dimension JavaDoc(260, 132));
83     jList.setModel(content);
84     jScrollPane1.setViewportView(jList);
85
86     getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
87
88     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
89
90     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(250, 35));
91     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(250, 35));
92     setButton.setText("Set");
93     setButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
94     {
95       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
96       {
97         setButtonActionPerformed(evt);
98       }
99     });
100
101     jPanel5.add(setButton);
102
103     cancelButton.setText("Cancel");
104     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
105     {
106       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
107       {
108         cancelButtonActionPerformed(evt);
109       }
110     });
111
112     jPanel5.add(cancelButton);
113
114     jPanel1.add(jPanel5, java.awt.BorderLayout.EAST);
115
116     getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
117
118     jPanel2.setLayout(new java.awt.BorderLayout JavaDoc());
119
120     jPanel3.setLayout(new java.awt.GridLayout JavaDoc(4, 0));
121
122     jPanel3.setBorder(new javax.swing.border.TitledBorder JavaDoc("Edit"));
123     addButton.setText("Add");
124     addButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
125     {
126       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
127       {
128         addButtonActionPerformed(evt);
129       }
130     });
131
132     jPanel3.add(addButton);
133
134     deleteSelectedButton.setText("Delete Selected");
135     deleteSelectedButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
136     {
137       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
138       {
139         deleteSelectedButtonActionPerformed(evt);
140       }
141     });
142
143     jPanel3.add(deleteSelectedButton);
144
145     moveUpButton.setText("Move Up");
146     moveUpButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
147     {
148       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
149       {
150         moveUpButtonActionPerformed(evt);
151       }
152     });
153
154     jPanel3.add(moveUpButton);
155
156     moveDownButton.setText("Move Down");
157     moveDownButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
158     {
159       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
160       {
161         moveDownButtonActionPerformed(evt);
162       }
163     });
164
165     jPanel3.add(moveDownButton);
166
167     jPanel2.add(jPanel3, java.awt.BorderLayout.NORTH);
168
169     getContentPane().add(jPanel2, java.awt.BorderLayout.EAST);
170
171     jPanel4.setLayout(new java.awt.GridLayout JavaDoc(1, 0));
172
173     jPanel4.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(3, 1, 1, 1)));
174     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(350, 19));
175     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(350, 19));
176     jLabel.setText("String List:");
177     jPanel4.add(jLabel);
178
179     getContentPane().add(jPanel4, java.awt.BorderLayout.NORTH);
180
181     pack();
182   }//GEN-END:initComponents
183

184   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
185
{//GEN-HEADEREND:event_cancelButtonActionPerformed
186
dispose();
187   }//GEN-LAST:event_cancelButtonActionPerformed
188

189   private void setButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_setButtonActionPerformed
190
{//GEN-HEADEREND:event_setButtonActionPerformed
191
nodeNameLicList.getList().clear();
192     Enumeration en = content.elements();
193     while (en.hasMoreElements()) nodeNameLicList.add((NodeNameLicList.NodeLicPair)en.nextElement());
194     isOK = true;
195     dispose();
196   }//GEN-LAST:event_setButtonActionPerformed
197

198   private void moveDownButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_moveDownButtonActionPerformed
199
{//GEN-HEADEREND:event_moveDownButtonActionPerformed
200
int i = jList.getSelectedIndex();
201     if (i == -1 || i >= content.size() - 1) return;
202     
203     Object JavaDoc o1 = content.getElementAt(i);
204     Object JavaDoc o2 = content.getElementAt(i + 1);
205     content.setElementAt(o2, i);
206     content.setElementAt(o1, i + 1);
207     jList.setSelectedIndex(i + 1);
208   }//GEN-LAST:event_moveDownButtonActionPerformed
209

210   private void moveUpButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_moveUpButtonActionPerformed
211
{//GEN-HEADEREND:event_moveUpButtonActionPerformed
212
int i = jList.getSelectedIndex();
213     if (i == -1 || i == 0) return;
214     
215     Object JavaDoc o1 = content.getElementAt(i);
216     Object JavaDoc o2 = content.getElementAt(i - 1);
217     content.setElementAt(o2, i);
218     content.setElementAt(o1, i - 1);
219     jList.setSelectedIndex(i - 1);
220   }//GEN-LAST:event_moveUpButtonActionPerformed
221

222   private void deleteSelectedButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteSelectedButtonActionPerformed
223
{//GEN-HEADEREND:event_deleteSelectedButtonActionPerformed
224
Object JavaDoc[] selected = jList.getSelectedValues();
225     for (int i = 0; i < selected.length; i++)
226     {
227       content.removeElement(selected[i]);
228     }
229   }//GEN-LAST:event_deleteSelectedButtonActionPerformed
230

231   private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_addButtonActionPerformed
232
{//GEN-HEADEREND:event_addButtonActionPerformed
233
NodeNameLicList.NodeLicPair nodeLicPair = NewNodeNameLicDialog.showDialog(this);
234     if (nodeLicPair != null) content.addElement(nodeLicPair);
235   }//GEN-LAST:event_addButtonActionPerformed
236

237   
238   // Variables declaration - do not modify//GEN-BEGIN:variables
239
private javax.swing.JButton JavaDoc addButton;
240   private javax.swing.JButton JavaDoc cancelButton;
241   private javax.swing.JButton JavaDoc deleteSelectedButton;
242   private javax.swing.JLabel JavaDoc jLabel;
243   private javax.swing.JList JavaDoc jList;
244   private javax.swing.JPanel JavaDoc jPanel1;
245   private javax.swing.JPanel JavaDoc jPanel2;
246   private javax.swing.JPanel JavaDoc jPanel3;
247   private javax.swing.JPanel JavaDoc jPanel4;
248   private javax.swing.JPanel JavaDoc jPanel5;
249   private javax.swing.JScrollPane JavaDoc jScrollPane1;
250   private javax.swing.JButton JavaDoc moveDownButton;
251   private javax.swing.JButton JavaDoc moveUpButton;
252   private javax.swing.JButton JavaDoc setButton;
253   // End of variables declaration//GEN-END:variables
254

255 }
256
Popular Tags