1 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 ; 13 import java.awt.Frame ; 14 15 19 public class NodeNameLicListEditDialog extends javax.swing.JDialog 20 { 21 private boolean isOK; 22 private NodeNameLicList nodeNameLicList; 23 private DefaultListModel content; 24 25 public static boolean showDialog(Component frameComp, NodeNameLicList nodeNameLicList, String title) 26 { 27 Frame frame = JOptionPane.getFrameForComponent(frameComp); 28 NodeNameLicListEditDialog dialog = new NodeNameLicListEditDialog(frame, true, nodeNameLicList, title); 29 dialog.setVisible(true); 30 return dialog.isOK(); 31 32 } 33 34 public NodeNameLicListEditDialog(java.awt.Frame parent, boolean modal, NodeNameLicList nodeNameLicList, String 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 64 private void initComponents() { 66 jScrollPane1 = new javax.swing.JScrollPane (); 67 jList = new javax.swing.JList (); 68 jPanel1 = new javax.swing.JPanel (); 69 jPanel5 = new javax.swing.JPanel (); 70 setButton = new javax.swing.JButton (); 71 cancelButton = new javax.swing.JButton (); 72 jPanel2 = new javax.swing.JPanel (); 73 jPanel3 = new javax.swing.JPanel (); 74 addButton = new javax.swing.JButton (); 75 deleteSelectedButton = new javax.swing.JButton (); 76 moveUpButton = new javax.swing.JButton (); 77 moveDownButton = new javax.swing.JButton (); 78 jPanel4 = new javax.swing.JPanel (); 79 jLabel = new javax.swing.JLabel (); 80 81 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 82 jScrollPane1.setMinimumSize(new java.awt.Dimension (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 ()); 89 90 jPanel1.setMinimumSize(new java.awt.Dimension (250, 35)); 91 jPanel1.setPreferredSize(new java.awt.Dimension (250, 35)); 92 setButton.setText("Set"); 93 setButton.addActionListener(new java.awt.event.ActionListener () 94 { 95 public void actionPerformed(java.awt.event.ActionEvent 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 () 105 { 106 public void actionPerformed(java.awt.event.ActionEvent 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 ()); 119 120 jPanel3.setLayout(new java.awt.GridLayout (4, 0)); 121 122 jPanel3.setBorder(new javax.swing.border.TitledBorder ("Edit")); 123 addButton.setText("Add"); 124 addButton.addActionListener(new java.awt.event.ActionListener () 125 { 126 public void actionPerformed(java.awt.event.ActionEvent 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 () 136 { 137 public void actionPerformed(java.awt.event.ActionEvent 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 () 147 { 148 public void actionPerformed(java.awt.event.ActionEvent 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 () 158 { 159 public void actionPerformed(java.awt.event.ActionEvent 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 (1, 0)); 172 173 jPanel4.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (3, 1, 1, 1))); 174 jPanel4.setMinimumSize(new java.awt.Dimension (350, 19)); 175 jPanel4.setPreferredSize(new java.awt.Dimension (350, 19)); 176 jLabel.setText("String List:"); 177 jPanel4.add(jLabel); 178 179 getContentPane().add(jPanel4, java.awt.BorderLayout.NORTH); 180 181 pack(); 182 } 184 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 187 } 189 private void setButtonActionPerformed(java.awt.event.ActionEvent evt) { nodeNameLicList.getList().clear(); 192 Enumeration en = content.elements(); 193 while (en.hasMoreElements()) nodeNameLicList.add((NodeNameLicList.NodeLicPair)en.nextElement()); 194 isOK = true; 195 dispose(); 196 } 198 private void moveDownButtonActionPerformed(java.awt.event.ActionEvent evt) { int i = jList.getSelectedIndex(); 201 if (i == -1 || i >= content.size() - 1) return; 202 203 Object o1 = content.getElementAt(i); 204 Object o2 = content.getElementAt(i + 1); 205 content.setElementAt(o2, i); 206 content.setElementAt(o1, i + 1); 207 jList.setSelectedIndex(i + 1); 208 } 210 private void moveUpButtonActionPerformed(java.awt.event.ActionEvent evt) { int i = jList.getSelectedIndex(); 213 if (i == -1 || i == 0) return; 214 215 Object o1 = content.getElementAt(i); 216 Object o2 = content.getElementAt(i - 1); 217 content.setElementAt(o2, i); 218 content.setElementAt(o1, i - 1); 219 jList.setSelectedIndex(i - 1); 220 } 222 private void deleteSelectedButtonActionPerformed(java.awt.event.ActionEvent evt) { Object [] selected = jList.getSelectedValues(); 225 for (int i = 0; i < selected.length; i++) 226 { 227 content.removeElement(selected[i]); 228 } 229 } 231 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { NodeNameLicList.NodeLicPair nodeLicPair = NewNodeNameLicDialog.showDialog(this); 234 if (nodeLicPair != null) content.addElement(nodeLicPair); 235 } 237 238 private javax.swing.JButton addButton; 240 private javax.swing.JButton cancelButton; 241 private javax.swing.JButton deleteSelectedButton; 242 private javax.swing.JLabel jLabel; 243 private javax.swing.JList jList; 244 private javax.swing.JPanel jPanel1; 245 private javax.swing.JPanel jPanel2; 246 private javax.swing.JPanel jPanel3; 247 private javax.swing.JPanel jPanel4; 248 private javax.swing.JPanel jPanel5; 249 private javax.swing.JScrollPane jScrollPane1; 250 private javax.swing.JButton moveDownButton; 251 private javax.swing.JButton moveUpButton; 252 private javax.swing.JButton setButton; 253 255 } 256 | Popular Tags |