| 1 6 7 package com.quikj.application.utilities.lm; 8 9 import java.awt.*; 10 import java.util.*; 11 import java.io.*; 12 import java.security.*; 13 import java.security.spec.*; 14 import com.quikj.server.framework.*; 15 import com.quikj.client.beans.*; 16 20 public class LicenseManager extends java.awt.Frame  21 { 22 23 24 public LicenseManager() 25 { 26 initComponents(); 27 } 28 29 34 private void initComponents() { 36 java.awt.GridBagConstraints gridBagConstraints; 37 38 panel1 = new java.awt.Panel (); 39 panel2 = new java.awt.Panel (); 40 label1 = new java.awt.Label (); 41 secretField = new java.awt.TextField (); 42 label2 = new java.awt.Label (); 43 verifySecretField = new java.awt.TextField (); 44 panel3 = new java.awt.Panel (); 45 featureList = new java.awt.List (); 46 label3 = new java.awt.Label (); 47 deleteSelectionButton = new java.awt.Button (); 48 panel4 = new java.awt.Panel (); 49 label4 = new java.awt.Label (); 50 featureNameField = new java.awt.TextField (); 51 label5 = new java.awt.Label (); 52 featureExpiresField = new java.awt.TextField (); 53 label6 = new java.awt.Label (); 54 featureUnitsField = new java.awt.TextField (); 55 panel5 = new java.awt.Panel (); 56 addButton = new java.awt.Button (); 57 replaceButton = new java.awt.Button (); 58 menuBar = new java.awt.MenuBar (); 59 fileMenu = new java.awt.Menu (); 60 newMenuItem = new java.awt.MenuItem (); 61 openMenuItem = new java.awt.MenuItem (); 62 saveMenuItem = new java.awt.MenuItem (); 63 saveAsMenuItem = new java.awt.MenuItem (); 64 closeMenuItem = new java.awt.MenuItem (); 65 editMenu = new java.awt.Menu (); 66 copyMenuItem = new java.awt.MenuItem (); 67 pasteMenuItem = new java.awt.MenuItem (); 68 69 setLayout(new javax.swing.BoxLayout (this, javax.swing.BoxLayout.X_AXIS)); 70 71 setTitle("Ace License Manager : New file"); 72 addWindowListener(new java.awt.event.WindowAdapter () 73 { 74 public void windowClosing(java.awt.event.WindowEvent evt) 75 { 76 exitForm(evt); 77 } 78 }); 79 80 panel1.setLayout(new java.awt.GridBagLayout ()); 81 82 panel1.setBackground(new java.awt.Color (255, 255, 255)); 83 panel2.setLayout(new java.awt.GridBagLayout ()); 84 85 panel2.setBackground(new java.awt.Color (255, 255, 255)); 86 label1.setText("Enter secret key"); 87 gridBagConstraints = new java.awt.GridBagConstraints (); 88 gridBagConstraints.gridx = 0; 89 gridBagConstraints.gridy = 0; 90 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 91 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 0); 92 panel2.add(label1, gridBagConstraints); 93 94 secretField.setEchoChar('*'); 95 secretField.setColumns(25); 96 gridBagConstraints = new java.awt.GridBagConstraints (); 97 gridBagConstraints.gridx = 1; 98 gridBagConstraints.gridy = 0; 99 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 100 gridBagConstraints.insets = new java.awt.Insets (10, 2, 0, 10); 101 panel2.add(secretField, gridBagConstraints); 102 103 label2.setText("Verify secret key"); 104 gridBagConstraints = new java.awt.GridBagConstraints (); 105 gridBagConstraints.gridx = 0; 106 gridBagConstraints.gridy = 1; 107 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 108 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 0); 109 panel2.add(label2, gridBagConstraints); 110 111 verifySecretField.setEchoChar('*'); 112 verifySecretField.setColumns(25); 113 gridBagConstraints = new java.awt.GridBagConstraints (); 114 gridBagConstraints.gridx = 1; 115 gridBagConstraints.gridy = 1; 116 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 117 gridBagConstraints.insets = new java.awt.Insets (10, 2, 0, 10); 118 panel2.add(verifySecretField, gridBagConstraints); 119 120 gridBagConstraints = new java.awt.GridBagConstraints (); 121 gridBagConstraints.gridx = 0; 122 gridBagConstraints.gridy = 0; 123 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 124 gridBagConstraints.weightx = 100.0; 125 panel1.add(panel2, gridBagConstraints); 126 127 panel3.setLayout(new java.awt.GridBagLayout ()); 128 129 panel3.setBackground(new java.awt.Color (255, 255, 255)); 130 featureList.addActionListener(new java.awt.event.ActionListener () 131 { 132 public void actionPerformed(java.awt.event.ActionEvent evt) 133 { 134 featureListActionPerformed(evt); 135 } 136 }); 137 138 gridBagConstraints = new java.awt.GridBagConstraints (); 139 gridBagConstraints.gridx = 0; 140 gridBagConstraints.gridy = 1; 141 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 142 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 143 gridBagConstraints.weightx = 100.0; 144 gridBagConstraints.weighty = 100.0; 145 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 10); 146 panel3.add(featureList, gridBagConstraints); 147 148 label3.setText("List of features"); 149 gridBagConstraints = new java.awt.GridBagConstraints (); 150 gridBagConstraints.gridx = 0; 151 gridBagConstraints.gridy = 0; 152 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 153 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 0); 154 panel3.add(label3, gridBagConstraints); 155 156 deleteSelectionButton.setLabel("Delete selection"); 157 deleteSelectionButton.addActionListener(new java.awt.event.ActionListener () 158 { 159 public void actionPerformed(java.awt.event.ActionEvent evt) 160 { 161 deleteSelectionButtonActionPerformed(evt); 162 } 163 }); 164 165 gridBagConstraints = new java.awt.GridBagConstraints (); 166 gridBagConstraints.gridx = 1; 167 gridBagConstraints.gridy = 1; 168 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; 169 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 10); 170 panel3.add(deleteSelectionButton, gridBagConstraints); 171 172 gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 0; 174 gridBagConstraints.gridy = 1; 175 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 176 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 177 gridBagConstraints.weightx = 100.0; 178 gridBagConstraints.weighty = 60.0; 179 panel1.add(panel3, gridBagConstraints); 180 181 panel4.setLayout(new java.awt.GridBagLayout ()); 182 183 panel4.setBackground(new java.awt.Color (255, 255, 255)); 184 label4.setText("Feature name"); 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 187 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 0); 188 panel4.add(label4, gridBagConstraints); 189 190 featureNameField.setColumns(30); 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.gridx = 0; 193 gridBagConstraints.gridy = 1; 194 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 195 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 10); 196 panel4.add(featureNameField, gridBagConstraints); 197 198 label5.setText("Feature expiry Date MM-DD-YYYY (leave blank, if none)"); 199 gridBagConstraints = new java.awt.GridBagConstraints (); 200 gridBagConstraints.gridx = 0; 201 gridBagConstraints.gridy = 2; 202 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 203 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 0); 204 panel4.add(label5, gridBagConstraints); 205 206 featureExpiresField.setColumns(10); 207 gridBagConstraints = new java.awt.GridBagConstraints (); 208 gridBagConstraints.gridx = 0; 209 gridBagConstraints.gridy = 3; 210 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 211 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 10); 212 panel4.add(featureExpiresField, gridBagConstraints); 213 214 label6.setText("Number of Units (leave blank, if NA)"); 215 gridBagConstraints = new java.awt.GridBagConstraints (); 216 gridBagConstraints.gridx = 0; 217 gridBagConstraints.gridy = 4; 218 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 219 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 0); 220 panel4.add(label6, gridBagConstraints); 221 222 featureUnitsField.setColumns(4); 223 gridBagConstraints = new java.awt.GridBagConstraints (); 224 gridBagConstraints.gridx = 0; 225 gridBagConstraints.gridy = 5; 226 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 227 gridBagConstraints.insets = new java.awt.Insets (0, 10, 0, 10); 228 panel4.add(featureUnitsField, gridBagConstraints); 229 230 gridBagConstraints = new java.awt.GridBagConstraints (); 231 gridBagConstraints.gridx = 0; 232 gridBagConstraints.gridy = 2; 233 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 234 gridBagConstraints.insets = new java.awt.Insets (10, 10, 0, 0); 235 panel1.add(panel4, gridBagConstraints); 236 237 panel5.setLayout(new java.awt.GridBagLayout ()); 238 239 panel5.setBackground(new java.awt.Color (255, 255, 255)); 240 addButton.setLabel("Add"); 241 addButton.addActionListener(new java.awt.event.ActionListener () 242 { 243 public void actionPerformed(java.awt.event.ActionEvent evt) 244 { 245 addButtonActionPerformed(evt); 246 } 247 }); 248 249 gridBagConstraints = new java.awt.GridBagConstraints (); 250 gridBagConstraints.gridx = 0; 251 gridBagConstraints.gridy = 0; 252 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 50); 253 panel5.add(addButton, gridBagConstraints); 254 255 replaceButton.setLabel("Replace"); 256 replaceButton.addActionListener(new java.awt.event.ActionListener () 257 { 258 public void actionPerformed(java.awt.event.ActionEvent evt) 259 { 260 replaceButtonActionPerformed(evt); 261 } 262 }); 263 264 gridBagConstraints = new java.awt.GridBagConstraints (); 265 gridBagConstraints.gridx = 1; 266 gridBagConstraints.gridy = 0; 267 gridBagConstraints.insets = new java.awt.Insets (0, 50, 0, 0); 268 panel5.add(replaceButton, gridBagConstraints); 269 270 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridx = 0; 272 gridBagConstraints.gridy = 4; 273 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 274 gridBagConstraints.weightx = 100.0; 275 gridBagConstraints.insets = new java.awt.Insets (10, 10, 10, 10); 276 panel1.add(panel5, gridBagConstraints); 277 278 add(panel1); 279 280 fileMenu.setLabel("File"); 281 newMenuItem.setLabel("New"); 282 newMenuItem.addActionListener(new java.awt.event.ActionListener () 283 { 284 public void actionPerformed(java.awt.event.ActionEvent evt) 285 { 286 newMenuItemActionPerformed(evt); 287 } 288 }); 289 290 fileMenu.add(newMenuItem); 291 openMenuItem.setLabel("Open..."); 292 openMenuItem.addActionListener(new java.awt.event.ActionListener () 293 { 294 public void actionPerformed(java.awt.event.ActionEvent evt) 295 { 296 openMenuItemActionPerformed(evt); 297 } 298 }); 299 300 fileMenu.add(openMenuItem); 301 saveMenuItem.setLabel("Save"); 302 saveMenuItem.addActionListener(new java.awt.event.ActionListener () 303 { 304 public void actionPerformed(java.awt.event.ActionEvent evt) 305 { 306 saveMenuItemActionPerformed(evt); 307 } 308 }); 309 310 fileMenu.add(saveMenuItem); 311 saveAsMenuItem.setLabel("Save as..."); 312 saveAsMenuItem.addActionListener(new java.awt.event.ActionListener () 313 { 314 public void actionPerformed(java.awt.event.ActionEvent evt) 315 { 316 saveAsMenuItemActionPerformed(evt); 317 } 318 }); 319 320 fileMenu.add(saveAsMenuItem); 321 fileMenu.addSeparator(); 322 closeMenuItem.setLabel("Exit"); 323 closeMenuItem.addActionListener(new java.awt.event.ActionListener () 324 { 325 public void actionPerformed(java.awt.event.ActionEvent evt) 326 { 327 closeMenuItemActionPerformed(evt); 328 } 329 }); 330 331 fileMenu.add(closeMenuItem); 332 menuBar.add(fileMenu); 333 editMenu.setLabel("Edit"); 334 copyMenuItem.setName("null"); 335 copyMenuItem.setLabel("Copy"); 336 copyMenuItem.addActionListener(new java.awt.event.ActionListener () 337 { 338 public void actionPerformed(java.awt.event.ActionEvent evt) 339 { 340 copyMenuItemActionPerformed(evt); 341 } 342 }); 343 344 editMenu.add(copyMenuItem); 345 pasteMenuItem.setName("null"); 346 pasteMenuItem.setLabel("Paste"); 347 pasteMenuItem.addActionListener(new java.awt.event.ActionListener () 348 { 349 public void actionPerformed(java.awt.event.ActionEvent evt) 350 { 351 pasteMenuItemActionPerformed(evt); 352 } 353 }); 354 355 editMenu.add(pasteMenuItem); 356 menuBar.add(editMenu); 357 setMenuBar(menuBar); 358 359 pack(); 360 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 361 setSize(new java.awt.Dimension (576, 502)); 362 setLocation((screenSize.width-576)/2,(screenSize.height-502)/2); 363 } 365 private void pasteMenuItemActionPerformed(java.awt.event.ActionEvent evt) { if (copyBuffer != null) 369 { 370 ListIterator iter = copyBuffer.listIterator(); 371 372 while (iter.hasNext() == true) 373 { 374 AceLicenseElement element = (AceLicenseElement)iter.next(); 375 376 features.addLast(element); 377 featureList.add(element.getFeatureName()); 378 modified = true; 379 } 380 } 381 } 383 private void copyMenuItemActionPerformed(java.awt.event.ActionEvent evt) { copyBuffer = (LinkedList)features.clone(); 387 } 389 private void featureListActionPerformed(java.awt.event.ActionEvent evt) { int index = featureList.getSelectedIndex(); 393 394 if (index == -1) 395 { 396 return; 398 } 399 400 String name = featureList.getItem(index); 401 ListIterator iter = features.listIterator(); 402 int count = 0; 403 while (iter.hasNext() == true) 404 { 405 AceLicenseElement element = (AceLicenseElement)iter.next(); 406 if (count == index) 407 { 408 featureNameField.setText(name); 410 411 if (element.getFeatureExpires() != null) 412 { 413 featureExpiresField.setText(formatDate(element.getFeatureExpires())); 414 } 415 else 416 { 417 featureExpiresField.setText(""); 418 } 419 420 if (element.getUnitsAssigned() > 0) 421 { 422 featureUnitsField.setText((new Integer (element.getUnitsAssigned())).toString()); 423 } 424 else 425 { 426 featureUnitsField.setText(""); 427 } 428 429 break; 430 } 431 432 count++; 433 } 434 435 } 437 private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) { if (modified == true) 441 { 442 YesNoDialog ynd = new YesNoDialog(this, "Save file", 443 "Do you want to save your changes?", 444 "Yes", "No"); 445 if (ynd.okSelected() == true) 446 { 447 if (saveToFile() == false) 449 { 450 return; 451 } 452 } 453 } 454 455 FileDialog fd = new FileDialog(this, "Enter file name", FileDialog.LOAD); 456 fd.show(); 457 458 String dir = fd.getDirectory(); 459 String file = fd.getFile(); 460 461 if ((dir == null) || (file == null)) 462 { 463 new InformationDialog(this, "Data entry error", 464 "You have not entered a file name or the folder name", true); 465 return; 466 } 467 468 openedFile = new File(dir, file); 469 470 try 471 { 472 AceLicenseManager lm = new AceLicenseManager(openedFile.getAbsolutePath()); 473 474 HashMap map = lm.getFeatureList(); 476 477 resetScreen(); features.clear(); 479 480 Iterator iter = map.values().iterator(); 481 482 while(iter.hasNext() == true) 483 { 484 AceFeatureLicenseElement element = (AceFeatureLicenseElement)iter.next(); 485 486 ArrayList flist = element.getElementList(); 487 int num = flist.size(); 488 489 for (int i = 0; i < num; i++) 490 { 491 AceLicenseElement le = (AceLicenseElement)flist.get(i); 492 features.addLast(le); 493 featureList.add(le.getFeatureName()); 494 } 495 } 496 } 497 catch (Exception ex) 498 { 499 new InformationDialog(this, "File read error", 500 "The file does not exist, have permission problems or the data is in invalid format", 501 true); 502 503 openedFile = null; 504 return; 505 } 506 507 modified = false; 508 setTitle("Ace License Manager : " + openedFile.getAbsolutePath()); 509 } 511 private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) { saveToFile(true); 515 } 517 private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) { saveToFile(); 521 } 523 private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) { if (modified == true) 527 { 528 YesNoDialog ynd = new YesNoDialog(this, "Save file", 529 "Do you want to save your changes?", 530 "Yes", "No"); 531 if (ynd.okSelected() == true) 532 { 533 if (saveToFile() == false) 535 { 536 return; 537 } 538 } 539 } 540 541 modified = false; 543 resetScreen(); 544 features.clear(); 545 setTitle("Ace License Manager : New file"); 546 openedFile = null; 547 548 } 550 private void replaceButtonActionPerformed(java.awt.event.ActionEvent evt) { int index = featureList.getSelectedIndex(); 554 if (index < 0) 555 { 556 new InformationDialog(this, "Data entry error", 558 "You must first select an item from the list", true); 559 return; 560 } 561 562 String name = featureList.getItem(index); 563 564 AceLicenseElement entered_element = getEnteredData(); 565 if (entered_element == null) 566 { 567 return; 568 } 569 570 if (name.equals(entered_element.getFeatureName()) == false) 572 { 573 new InformationDialog(this, "Data entry error", 574 "The name field must match with the selected name, use add instead", true); 575 return; 576 } 577 578 ListIterator iter = features.listIterator(); 580 int count = 0; 581 while (iter.hasNext() == true) 582 { 583 AceLicenseElement element = (AceLicenseElement)iter.next(); 584 if (count == index) 585 { 586 iter.set(entered_element); 587 break; 588 } 589 590 count++; 591 } 592 modified = true; 593 } 595 private void deleteSelectionButtonActionPerformed(java.awt.event.ActionEvent evt) { int index = featureList.getSelectedIndex(); 599 if (index < 0) 600 { 601 new InformationDialog(this, "Data entry error", 603 "You must first select an item from the list", true); 604 return; 605 } 606 607 String name = featureList.getItem(index); 608 ListIterator iter = features.listIterator(); 609 int count = 0; 610 while (iter.hasNext() == true) 611 { 612 AceLicenseElement element = (AceLicenseElement)iter.next(); 613 if (count == index) 614 { 615 iter.remove(); 616 break; 617 } 618 count++; 619 } 620 621 featureList.remove(index); 622 modified = true; 623 } 625 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { AceLicenseElement element = getEnteredData(); 629 if (element == null) 630 { 631 return; 632 } 633 634 features.addLast(element); 636 featureList.add(element.getFeatureName()); 637 modified = true; 638 639 } 641 private boolean saveToFile(boolean save_as) 642 { 643 if (secretField.getText().trim().length() == 0) 644 { 645 new InformationDialog(this, "Data entry error", 646 "You have not entered the secret key", true); 647 return false; 648 } 649 650 if (secretField.getText().trim().equals(verifySecretField.getText().trim()) 651 == false) 652 { 653 new InformationDialog(this, "Data entry error", 654 "The secret keys do not match", true); 655 return false; 656 } 657 658 if (featureList.getItemCount() == 0) 659 { 660 new InformationDialog(this, "Data entry error", 661 "You must enter at least one feature", true); 662 return false; 663 } 664 665 if ((openedFile == null) || (save_as == true)) 666 { 667 FileDialog fd = new FileDialog(this, "Enter file name", FileDialog.SAVE); 668 fd.show(); 669 670 String dir = fd.getDirectory(); 671 String file = fd.getFile(); 672 673 if ((dir == null) || (file == null)) 674 { 675 new InformationDialog(this, "Data entry error", 676 "You have not entered a file name or the folder name", true); 677 return false; 678 } 679 680 openedFile = new File(dir, file); 681 682 } 683 684 try 685 { 686 FileWriter fw = new FileWriter(openedFile); 688 fw.write(format()); 689 fw.close(); 690 } 691 catch (IOException ex) 692 { 693 new InformationDialog(this, "Error", 694 "Error writing to file: " + ex.getMessage(), true); 695 openedFile = null; 696 return false; 697 } 698 catch (Exception ex) 699 { 700 new InformationDialog(this, "Error", 701 "Error " + ex.getClass().getName() + ": " 702 + ex.getMessage(), true); 703 return false; 704 } 705 706 modified = false; 708 return true; 709 } 710 711 private String format() 712 throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, AceException 713 { 714 StringBuffer buffer = new StringBuffer ("<?xml version=\"1.0\" encoding=\"us-ascii\"?>\n" 715 + "<" + AceLicenseManager.ROOT_NODE_NAME + ">\n"); 716 717 Encryption cryptor = new Encryption(); 718 buffer.append("<" + AceLicenseManager.EL_CODE + " " 719 + AceLicenseManager.ATT_CODE + "=\"" 720 + cryptor.encrypt(secretField.getText().trim(), 721 SysParam.getAuth1(getClass())) 722 + "\"/>\n"); 723 724 ListIterator iter = features.listIterator(); 725 int index = 0; 726 while (iter.hasNext() == true) 727 { 728 AceLicenseElement element = (AceLicenseElement)iter.next(); 729 buffer.append("<" + AceLicenseManager.EL_FEATURE + " " 730 + AceLicenseManager.ATT_NAME + "=\"" + element.getFeatureName() 731 + "\""); 732 733 buffer.append(" " + AceLicenseManager.ATT_INDEX + "=\"" 734 + (index) + "\""); 735 736 if (element.getUnitsAssigned() > 0) 737 { 738 buffer.append(" " + AceLicenseManager.ATT_UNITS + "=\"" 739 + element.getUnitsAssigned() + "\""); 740 } 741 742 if (element.getFeatureExpires() != null) 743 { 744 buffer.append(" " + AceLicenseManager.ATT_EXPIRES + "=\"" 745 + formatDate(element.getFeatureExpires()) + "\""); 746 } 747 748 buffer.append(" " + AceLicenseManager.ATT_CHECKSUM + "=\"" 750 + AceLicenseManager.computeChecksum(element.getFeatureName(), 751 element.getUnitsAssigned(), 752 element.getFeatureExpires(), 753 index, 754 secretField.getText().trim()) 755 + "\""); 756 757 buffer.append("/>\n"); 758 index++; 759 } 760 761 buffer.append("</" + AceLicenseManager.ROOT_NODE_NAME + ">\n"); 762 return buffer.toString(); 763 } 764 765 private String formatDate(Date date) 766 { 767 Calendar cal = Calendar.getInstance(); 768 cal.setTime(date); 769 770 int day = cal.get(Calendar.DAY_OF_MONTH); 771 int month = Calendar.JANUARY + cal.get(Calendar.MONTH) + 1; 772 int year = cal.get(Calendar.YEAR); 773 774 return month + "-" + day + "-" + year; 775 } 776 777 private boolean saveToFile() 778 { 779 return saveToFile(false); 780 } 781 782 private void resetScreen() 783 { 784 secretField.setText(""); 785 verifySecretField.setText(""); 786 featureList.removeAll(); 787 featureNameField.setText(""); 788 featureUnitsField.setText(""); 789 featureExpiresField.setText(""); 790 } 791 792 private AceLicenseElement getEnteredData() 793 { 794 String name = featureNameField.getText().trim(); 795 if (name.length() == 0) 796 { 797 new InformationDialog(this, "Data entry error", 798 "The name field cannot be blank", true); 799 return null; 800 } 801 802 803 int units = -1; 804 String units_s = featureUnitsField.getText().trim(); 805 if (units_s.length() > 0) 806 { 807 try 808 { 809 units = Integer.parseInt(units_s); 810 } 811 catch (NumberFormatException ex) 812 { 813 new InformationDialog(this, "Data entry error", 814 "The units field must have a numeric value", true); 815 return null; 816 } 817 } 818 819 Date date = null; 820 String date_s = featureExpiresField.getText().trim(); 821 if (date_s.length() > 0) 822 { 823 date = AceLicenseManager.processDate(date_s); 824 if (date == null) 825 { 826 new InformationDialog(this, "Data entry error", 827 "The date field must be in MM-DD-YYYY format", true); 828 return null; 829 } 830 } 831 832 return new AceLicenseElement(name, units, date); 833 } 834 835 private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) { handleExit(); 839 } 841 842 private void exitForm(java.awt.event.WindowEvent evt) { handleExit(); 844 } 846 private void handleExit() 847 { 848 if (modified == true) 849 { 850 YesNoDialog ynd = new YesNoDialog(this, "Save file", 851 "Do you want to save your changes?", 852 "Yes", "No"); 853 if (ynd.okSelected() == true) 854 { 855 if (saveToFile() == false) 857 { 858 return; 859 } 860 } 861 } 862 System.exit(0); 863 } 864 865 868 public static void main(String args[]) 869 { 870 new LicenseManager().show(); 871 } 872 873 874 private java.awt.MenuItem closeMenuItem; 876 private java.awt.TextField featureNameField; 877 private java.awt.MenuItem pasteMenuItem; 878 private java.awt.Button deleteSelectionButton; 879 private java.awt.TextField secretField; 880 private java.awt.TextField featureUnitsField; 881 private java.awt.TextField verifySecretField; 882 private java.awt.MenuItem saveAsMenuItem; 883 private java.awt.MenuItem saveMenuItem; 884 private java.awt.Label label6; 885 private java.awt.Button addButton; 886 private java.awt.Label label5; 887 private java.awt.Label label4; 888 private java.awt.MenuBar menuBar; 889 private java.awt.Label label3; 890 private java.awt.List featureList; 891 private java.awt.Label label2; 892 private java.awt.Panel panel5; 893 private java.awt.Label label1; 894 private java.awt.Panel panel4; 895 private java.awt.Panel panel3; 896 private java.awt.Button replaceButton; 897 private java.awt.Panel panel2; 898 private java.awt.Panel panel1; 899 private java.awt.Menu editMenu; 900 private java.awt.MenuItem newMenuItem; 901 private java.awt.MenuItem copyMenuItem; 902 private java.awt.TextField featureExpiresField; 903 private java.awt.Menu fileMenu; 904 private java.awt.MenuItem openMenuItem; 905 907 private File openedFile = null; 908 private boolean modified = false; 909 private LinkedList features = new LinkedList(); 910 private LinkedList copyBuffer = null; 911 } 912 | Popular Tags |