1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.awt.KeyboardFocusManager ; 23 import java.awt.Window ; 24 import java.util.*; 25 import java.security.cert.Certificate ; 26 import java.security.cert.X509Certificate ; 27 import java.awt.Component ; 28 import java.awt.Font ; 29 import java.io.File ; 30 import java.io.FileNotFoundException ; 31 import java.util.logging.Level ; 32 import java.util.logging.Logger ; 33 import javax.swing.*; 34 import javax.swing.table.AbstractTableModel ; 35 import javax.swing.table.TableCellRenderer ; 36 37 import org.openide.DialogDisplayer; 38 import org.openide.util.NbBundle; 39 import org.openide.NotifyDescriptor; 40 import org.openide.util.Exceptions; 41 import org.openide.util.Utilities; 42 import org.openide.windows.WindowManager; 43 44 class ResultsPanel extends javax.swing.JPanel { 45 46 private static final String SPACE = " "; 48 private static final String BAD_DOWNLOAD = SPACE + getBundle("CTL_BAD_DOWNLOAD") + SPACE; 49 private static final String CORRUPTED = SPACE + getBundle("CTL_CORRUPTED") + SPACE; 50 private static final String NOT_SIGNED = SPACE + getBundle("CTL_NOT_SIGNED") + SPACE; 51 private static final String SIGNED = SPACE + getBundle("CTL_SIGNED") + SPACE; 52 private static final String TRUSTED = SPACE + getBundle("CTL_TRUSTED") + SPACE; 53 54 private static final Logger LOG = Logger.getLogger ("org.netbeans.modules.autoupdate.ResultsPanel"); 56 private Wizard.Validator validator; 57 58 private int modulesOK; 59 60 private JTable table; 61 private ResultsTableModel model; 62 63 private static JButton yesToAll; 65 private boolean includeAll = false; 66 private boolean globalAll = false; 67 68 static final long serialVersionUID =-6053101371836354161L; 69 70 71 private static File defaultDir = null; 72 73 74 public ResultsPanel( Wizard.Validator validator ) { 75 putClientProperty("WizardPanel_contentSelectedIndex", new Integer (3)); setName(getBundle("LBL_View")); 77 initComponents(); 78 79 this.validator = validator; 80 81 model = new ResultsTableModel(); 82 table = new ServerPanel.AutoResizeTable(model, 2); 85 table.getTableHeader().setReorderingAllowed( false ); 86 table.getColumnModel().getColumn(0).setCellRenderer( new BooleanRenderer() ); 87 table.getColumnModel().getColumn(1).setCellRenderer( new ResultsCellRenderer() ); 88 table.getColumnModel().getColumn(2).setCellRenderer( new BooleanRenderer() ); 89 table.setSelectionMode( javax.swing.ListSelectionModel.SINGLE_SELECTION ); 91 table.getColumnModel().getColumn(0).setPreferredWidth(48); 92 table.getColumnModel().getColumn(1).setPreferredWidth(480); 93 table.getColumnModel().getColumn(2).setPreferredWidth(48); 94 table.setIntercellSpacing( new java.awt.Dimension ( 0, 0 ) ); 95 96 jScrollPane1.setViewportView(table); 97 98 table.getSelectionModel().addListSelectionListener( 99 new javax.swing.event.ListSelectionListener () { 100 public void valueChanged( javax.swing.event.ListSelectionEvent evt ) { 101 selectionChange(); 102 } 103 } 104 ); 105 106 selectionChange(); 107 108 getAccessibleContext().setAccessibleName(getBundle("LBL_View")); 109 getAccessibleContext().setAccessibleDescription(getBundle("LBL_41")); 110 certificateButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_View")); 111 table.getAccessibleContext().setAccessibleDescription(getBundle("ACS_Module_List")); 112 113 jLabel1.setLabelFor( table ); 114 } 115 116 121 private void initComponents() { 123 java.awt.GridBagConstraints gridBagConstraints; 124 125 buttonGroup1 = new javax.swing.ButtonGroup (); 126 jTextArea1 = new javax.swing.JTextArea (); 127 jScrollPane1 = new javax.swing.JScrollPane (); 128 jLabel1 = new javax.swing.JLabel (); 129 jPanel1 = new javax.swing.JPanel (); 130 certificateButton = new javax.swing.JButton (); 131 saveButton = new javax.swing.JButton (); 132 133 setLayout(new java.awt.GridBagLayout ()); 134 135 jTextArea1.setBackground(getBackground()); 136 jTextArea1.setFont(new Font ("Dialog", Font.PLAIN, jTextArea1.getFont().getSize())); 137 jTextArea1.setLineWrap(true); 138 jTextArea1.setText(getBundle("LBL_41")); 139 jTextArea1.setWrapStyleWord(true); 140 jTextArea1.setDisabledTextColor(java.awt.Color.black); 141 jTextArea1.setEnabled(false); 142 gridBagConstraints = new java.awt.GridBagConstraints (); 143 gridBagConstraints.gridx = 0; 144 gridBagConstraints.gridy = 0; 145 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 146 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 147 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 148 gridBagConstraints.weightx = 1.0; 149 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 150 add(jTextArea1, gridBagConstraints); 151 152 gridBagConstraints = new java.awt.GridBagConstraints (); 153 gridBagConstraints.gridx = 0; 154 gridBagConstraints.gridy = 2; 155 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 156 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 157 gridBagConstraints.weightx = 1.0; 158 gridBagConstraints.weighty = 1.0; 159 add(jScrollPane1, gridBagConstraints); 160 161 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, getBundle("LAB_ModulesList")); 162 gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridy = 1; 164 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 165 add(jLabel1, gridBagConstraints); 166 167 jPanel1.setLayout(new java.awt.GridBagLayout ()); 168 169 org.openide.awt.Mnemonics.setLocalizedText(certificateButton, getBundle("BTN_View")); 170 buttonGroup1.add(certificateButton); 171 certificateButton.addActionListener(new java.awt.event.ActionListener () { 172 public void actionPerformed(java.awt.event.ActionEvent evt) { 173 certificateButtonActionPerformed(evt); 174 } 175 }); 176 177 gridBagConstraints = new java.awt.GridBagConstraints (); 178 gridBagConstraints.gridx = 0; 179 gridBagConstraints.gridy = 0; 180 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 181 gridBagConstraints.weightx = 1.0; 182 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 183 jPanel1.add(certificateButton, gridBagConstraints); 184 185 org.openide.awt.Mnemonics.setLocalizedText(saveButton, getBundle("BTN_SaveCopy")); 186 buttonGroup1.add(saveButton); 187 saveButton.addActionListener(new java.awt.event.ActionListener () { 188 public void actionPerformed(java.awt.event.ActionEvent evt) { 189 saveButtonActionPerformed(evt); 190 } 191 }); 192 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.gridx = 1; 195 gridBagConstraints.gridy = 0; 196 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 197 gridBagConstraints.weightx = 1.0; 198 gridBagConstraints.insets = new java.awt.Insets (12, 11, 0, 0); 199 jPanel1.add(saveButton, gridBagConstraints); 200 201 gridBagConstraints = new java.awt.GridBagConstraints (); 202 gridBagConstraints.gridx = 2; 203 gridBagConstraints.gridy = 3; 204 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 205 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 206 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 207 add(jPanel1, gridBagConstraints); 208 209 } 210 212 private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) { try { 214 File saveDir = getSaveCopyDir(); 215 if (saveDir == null) return ; 216 ModuleUpdate mu = getListSelection(); 217 File target = new File ( saveDir, mu.getDistributionFilename()); 218 if ( target.exists() ) { 219 NotifyDescriptor.Confirmation nd = 220 new NotifyDescriptor.Confirmation( 221 getBundle( "MSG_OverwriteConfirmation" ), 222 NotifyDescriptor.YES_NO_OPTION 223 ); 224 if ( ! DialogDisplayer.getDefault().notify( nd ).equals( NotifyDescriptor.YES_OPTION ) ) 225 return; 226 } 227 Downloader.saveCopy( getListSelection(), target ); 228 } catch (FileNotFoundException fnfe) { 229 Exceptions.attachLocalizedMessage( 230 fnfe, NbBundle.getMessage(ResultsPanel.class,"CTL_Directory_not_exits") 231 ); 232 NotifyDescriptor nd = new NotifyDescriptor.Exception(fnfe); 233 DialogDisplayer.getDefault().notifyLater(nd); 234 } 235 } 237 private void certificateButtonActionPerformed(java.awt.event.ActionEvent evt) { int accValue = CertificateDialog.showDialog( getListSelection().getCerts(), 239 getListSelection().getSecurity() ); 240 doCertAction(accValue, getListSelection()); 241 table.invalidate(); 242 table.repaint(); 243 selectionChange(); 244 } 246 private void doInclude(ModuleUpdate mu) { 247 if ( mu.isForcedGlobal () && Downloader.bannedWriteToInstall (mu)) { 248 NotifyDescriptor.Message nd = 249 new NotifyDescriptor.Message( 250 NbBundle.getMessage( ResultsPanel.class, "MSG_CannotInstall_2", mu.getName()) 251 ); 252 DialogDisplayer.getDefault().notify( nd ); 253 return; 254 } 255 if ( mu.getSecurity() == SignVerifier.NOT_SIGNED ) { 256 if ( mu.isInstallApproved() ) { 257 mu.setInstallApproved( false ); 258 checkValidity(); 259 } 260 else { 261 Object ret = null; 262 if ( !includeAll ) { 263 NotifyDescriptor.Confirmation nd = 264 new NotifyDescriptor.Confirmation( 265 getBundle( "MSG_NotSignedConfirmation" ), 266 getBundle( "CTL_NotSignedConfirmation" ), 267 NotifyDescriptor.YES_NO_OPTION 268 ); 269 nd.setOptions( new Object [] { 270 NotifyDescriptor.YES_OPTION, 271 NotifyDescriptor.NO_OPTION, 272 getYesToAll () } ); 273 ret = DialogDisplayer.getDefault().notify( nd ); 274 if (ret.equals (getYesToAll ())) { 275 includeAll = true; 276 } 277 } 278 if ( includeAll || ret.equals( NotifyDescriptor.YES_OPTION ) ) { 279 mu.setInstallApproved( true ); 280 checkValidity(); 281 } 282 } 283 } 284 else if ( mu.getSecurity() == SignVerifier.SIGNED || 285 mu.getSecurity() == SignVerifier.TRUSTED ) { 286 doCertAction(CertificateDialog.showDialog( 287 mu.getCerts(), 288 mu.getSecurity() 289 ), 290 mu 291 ); 292 } 293 else if ( mu.getSecurity() == SignVerifier.CORRUPTED ) { 294 NotifyDescriptor.Message nd = 295 new NotifyDescriptor.Message(getBundle( "MSG_CorruptedJAR" ) ); 296 DialogDisplayer.getDefault().notify( nd ); 297 } 298 else { 299 NotifyDescriptor.Message nd = 300 new NotifyDescriptor.Message(getBundle( "MSG_BadDownload" ) ); 301 DialogDisplayer.getDefault().notify( nd ); 302 } 303 table.invalidate(); 304 table.repaint(); 305 selectionChange(); 306 } 307 308 private void doGlobal(ModuleUpdate mu) throws IllegalArgumentException { 309 if ( mu.isForcedGlobal () ) { 310 NotifyDescriptor.Message nd = 311 new NotifyDescriptor.Message( 312 NbBundle.getMessage( ResultsPanel.class, "MSG_InstallDepending", 313 mu.getName() 314 ) 315 ); 316 DialogDisplayer.getDefault().notify( nd ); 317 return; 318 } 319 320 if (Downloader.bannedWriteToInstall (mu)) { 321 NotifyDescriptor.Message nd = 322 new NotifyDescriptor.Message( getBundle( "MSG_InstallNoWrite" ) ); 323 DialogDisplayer.getDefault().notify( nd ); 324 return; 325 } 326 327 if (mu.isGlobal () != null) { 328 if (mu.isGlobal ().booleanValue ()) { 329 NotifyDescriptor.Message nd = 330 new NotifyDescriptor.Message ( 331 NbBundle.getMessage( ResultsPanel.class, "MSG_InstallGloballyForced", 332 mu.getName() 333 ), 334 NotifyDescriptor.INFORMATION_MESSAGE 335 ); 336 DialogDisplayer.getDefault ().notify (nd); 337 return ; 338 } else { 339 NotifyDescriptor.Message nd = 340 new NotifyDescriptor.Message ( 341 NbBundle.getMessage( ResultsPanel.class, "MSG_InstallLocallyForced", 342 mu.getName() 343 ), 344 NotifyDescriptor.INFORMATION_MESSAGE 345 ); 346 DialogDisplayer.getDefault ().notify (nd); 347 return ; 348 } 349 } 350 351 if ( mu.isToInstallDir() ) { 352 Object ret = null; 353 if ("".equals (getBundle ("MSG_InstallLocallyConfirmation"))) { 354 mu.setToInstallDir (false); 355 } else { 356 NotifyDescriptor.Confirmation nd = 357 new NotifyDescriptor.Confirmation( 358 NbBundle.getMessage( ResultsPanel.class, "MSG_InstallLocallyConfirmation", 359 mu.getName() 360 ), 361 NotifyDescriptor.YES_NO_OPTION 362 ); 363 nd.setOptions( new Object [] { 364 NotifyDescriptor.YES_OPTION, 365 NotifyDescriptor.NO_OPTION } ); 366 ret = DialogDisplayer.getDefault().notify( nd ); 367 if ( ret.equals( NotifyDescriptor.YES_OPTION ) ) { 368 mu.setToInstallDir( false ); 369 } 370 } 371 } else { 372 Object ret = null; 373 if ( !globalAll ) { 374 if ("".equals (getBundle( "MSG_InstallGloballyConfirmation" ))) { 375 mu.setToInstallDir (false); 376 } else { 377 NotifyDescriptor.Confirmation nd = 378 new NotifyDescriptor.Confirmation( 379 NbBundle.getMessage( ResultsPanel.class, "MSG_InstallGloballyConfirmation", 380 mu.getName() 381 ), 382 NotifyDescriptor.YES_NO_OPTION 383 ); 384 nd.setOptions( new Object [] { 385 NotifyDescriptor.YES_OPTION, 386 NotifyDescriptor.NO_OPTION, 387 getYesToAll () } ); 388 ret = DialogDisplayer.getDefault().notify( nd ); 389 if (ret.equals ( getYesToAll ())) { 390 globalAll = true; 391 } 392 } 393 } 394 if ( globalAll || ret.equals( NotifyDescriptor.YES_OPTION ) ) { 395 mu.setToInstallDir( true ); 396 } 397 } 398 table.invalidate(); 399 table.repaint(); 400 selectionChange(); 401 } 402 403 void doCertAction(int accValue, ModuleUpdate mu) { 404 switch ( accValue ) { 405 411 case CertificateDialog.ACCEPT: 412 setApproved4All( mu.getCerts(), true, -1 ); 413 checkValidity(); 414 break; 415 case CertificateDialog.REJECT: 416 setApproved4All( mu.getCerts(), false, -1 ); 417 checkValidity(); 418 break; 419 case CertificateDialog.NOT_ALWAYS_ACCEPT: 420 setApproved4All( mu.getCerts(), false, SignVerifier.SIGNED ); 421 checkValidity(); 422 try { 423 SignVerifier.removeCertificates( mu.getCerts() ); 424 } 425 catch ( java.security.cert.CertificateException e ) { 426 LOG.log(Level.WARNING, null, e); 427 } 428 catch ( java.security.KeyStoreException e ) { 429 LOG.log(Level.WARNING, null, e); 430 } 431 catch ( java.io.IOException e ) { 432 LOG.log(Level.WARNING, null, e); 433 } 434 catch ( java.security.NoSuchAlgorithmException e ) { 435 LOG.log(Level.WARNING, null, e); 436 } 437 break; 438 case CertificateDialog.ALWAYS_ACCEPT: 439 setApproved4All( mu.getCerts(), true, SignVerifier.TRUSTED ); 440 checkValidity(); 441 try { 442 SignVerifier.addCertificates( mu.getCerts() ); 443 } 444 catch ( java.security.cert.CertificateException e ) { 445 LOG.log(Level.WARNING, null, e); 446 } 447 catch ( java.security.KeyStoreException e ) { 448 LOG.log(Level.WARNING, null, e); 449 } 450 catch ( java.io.IOException e ) { 451 LOG.log(Level.WARNING, null, e); 452 } 453 catch ( java.security.NoSuchAlgorithmException e ) { 454 LOG.log(Level.WARNING, null, e); 455 } 456 break; 457 default: 458 return; 459 } 460 } 461 462 465 private void setApproved4All( Collection certs, boolean approved, int security ) { 466 467 if ( certs == null ) { 468 return; 469 } 470 471 for ( int i=0; i < model.getRowCount(); i++ ) { 472 ModuleUpdate mu = (ModuleUpdate)model.getValueAt(i, 1); 473 474 boolean bannedWriteToInstall = Downloader.bannedWriteToInstall(mu); 475 if ( approved && mu.isForcedGlobal () && bannedWriteToInstall ) { 476 continue; 477 } 478 479 if ( mu.getCerts() != null && certs.containsAll( mu.getCerts() ) ) { 480 mu.setInstallApproved( approved ); 481 482 if ( security == SignVerifier.TRUSTED || security == SignVerifier.SIGNED ) { 483 mu.setSecurity( security ); 484 } 485 } 486 487 } 488 } 489 490 private javax.swing.ButtonGroup buttonGroup1; 492 private javax.swing.JButton certificateButton; 493 private javax.swing.JLabel jLabel1; 494 private javax.swing.JPanel jPanel1; 495 private javax.swing.JScrollPane jScrollPane1; 496 private javax.swing.JTextArea jTextArea1; 497 private javax.swing.JButton saveButton; 498 500 int generateResults() { 501 502 modulesOK = 0; 503 504 List modulelist = new ArrayList(); 505 506 Collection modules = Wizard.getAllModules(); 507 Iterator it = modules.iterator(); 508 boolean writeConflict = false; 509 int selectRow = -1; 510 while( it.hasNext() ) { 511 ModuleUpdate mu = (ModuleUpdate)it.next(); 512 513 if ( mu.isSelected() ) { 514 modulelist.add( mu ); 515 if ( mu.isDownloadOK() ) { 516 modulesOK ++; 517 if ( selectRow == -1 ) 518 if (!mu.isInstallApproved()) 519 selectRow = modulelist.size()-1; 520 } 521 if ( mu.isForcedGlobal () ) { 522 boolean bannedWriteToInstall = Downloader.bannedWriteToInstall (mu); 523 if ( bannedWriteToInstall ) { 524 mu.setInstallApproved( false ); 525 writeConflict = true; 526 } 527 mu.setToInstallDir( true ); 528 } 529 } 530 } 531 if ( writeConflict ) { 532 NotifyDescriptor.Message nd = 533 new NotifyDescriptor.Message( getBundle( "MSG_CannotInstall_1" ) ); 534 DialogDisplayer.getDefault().notify( nd ); 535 } 536 537 model.refreshContent( modulelist ); 538 539 if ( selectRow == -1 ) 540 selectRow = 0; 541 if ( table.getRowCount() > 0 ) 542 table.getSelectionModel().setSelectionInterval( selectRow, selectRow ); 543 544 checkValidity(); 545 selectionChange(); 546 includeAll = false; 547 globalAll = false; 548 return modulesOK; 549 } 550 551 552 private void selectionChange() { 553 ModuleUpdate mu = getListSelection(); 554 555 if ( mu != null && 557 ( mu.getSecurity() == SignVerifier.SIGNED || 558 mu.getSecurity() == SignVerifier.TRUSTED ) ) { 559 certificateButton.setEnabled( true ); 560 } 561 else { 562 certificateButton.setEnabled( false ); 563 } 564 565 if ( mu != null && 567 mu.getSecurity() != SignVerifier.BAD_DOWNLOAD ) { 568 saveButton.setEnabled( true ); 569 } 570 else { 571 saveButton.setEnabled( false ); 572 } 573 } 574 575 576 private ModuleUpdate getListSelection() { 577 578 int index = table.getSelectionModel().getMinSelectionIndex(); 579 580 if ( index < 0 ) 581 return null; 582 583 return (ModuleUpdate) model.getValueAt( index, 1 ); 584 } 585 586 589 private void checkValidity() { 590 591 boolean valid = false; 592 593 Collection modules = Wizard.getAllModules(); 594 Iterator it = modules.iterator(); 595 while( it.hasNext() ) { 596 ModuleUpdate mu = (ModuleUpdate)it.next(); 597 598 if ( mu.isSelected() && mu.isInstallApproved() ) { 599 valid = true; 600 } 601 602 } 603 604 validator.setValid( valid ); 605 606 } 607 608 class ResultsTableModel extends AbstractTableModel { 609 final String [] columnNames = {getBundle("LBL_42"), 610 getBundle("LBL_43"), 611 getBundle("LBL_Global")}; 612 private List modulelist = new ArrayList(); 613 614 public int getColumnCount() { 615 return columnNames.length; 616 } 617 618 public int getRowCount() { 619 return modulelist.size(); 620 } 621 622 public String getColumnName(int col) { 623 return columnNames[col]; 624 } 625 626 public Object getValueAt(int row, int col) { 627 if (col == 0) 628 return ((ModuleUpdate)modulelist.get(row)).isInstallApproved() ? Boolean.TRUE : Boolean.FALSE; 629 else if (col == 1) 630 return modulelist.get(row); 631 else { 632 ModuleUpdate mu = (ModuleUpdate)modulelist.get (row); 633 return Boolean.valueOf (mu.isToInstallDir()); 634 } 635 } 636 637 public Class getColumnClass(int c) { 638 return getValueAt(0, c).getClass(); 639 } 640 641 public boolean isCellEditable(int row, int col) { 642 if (col == 1) { 643 return false; 644 } else { 645 return true; 646 } 647 } 648 649 public void setValueAt(Object value, int row, int col) { 650 if (value instanceof Boolean ) { 651 if ( col == 0 ) 652 doInclude( (ModuleUpdate)modulelist.get(row) ); 653 else { 654 try { 655 doGlobal( (ModuleUpdate)modulelist.get(row) ); 656 } catch (IllegalArgumentException iae) { 657 LOG.log(Level.WARNING, null, iae); 658 } 659 } 660 } 661 } 662 663 void refreshContent( List modulelist ) { 664 this.modulelist = modulelist; 665 } 666 } 667 668 private class ResultsCellRenderer extends JPanel implements TableCellRenderer { 669 670 private JLabel nameLabel; 671 private JLabel securityLabel; 672 673 public ResultsCellRenderer() { 674 super(); 675 initComponents(); 676 } 677 678 679 public Component getTableCellRendererComponent(JTable table, Object value, 680 boolean isSelected, boolean hasFocus, int row, int column) { 681 682 String sec = ""; if ( value == null ) 684 value = model.getValueAt( row, column ); 685 switch ( ((ModuleUpdate)value).getSecurity() ) { 686 case SignVerifier.BAD_DOWNLOAD: 687 sec = BAD_DOWNLOAD; 688 break; 689 case SignVerifier.CORRUPTED: 690 sec = CORRUPTED; 691 break; 692 case SignVerifier.NOT_SIGNED: 693 sec = NOT_SIGNED; 694 break; 695 case SignVerifier.SIGNED: 696 StringBuffer sb = new StringBuffer ( SIGNED ); 697 sb.append( SPACE + getBundle("CTL_By")); 698 Collection certs = ((ModuleUpdate)value).getCerts(); 699 Iterator it = certs.iterator(); 700 while ( it.hasNext() ) { 701 Certificate cert = (Certificate )it.next(); 702 if ( cert instanceof X509Certificate ) { 703 sb.append( " " ).append( ((X509Certificate )cert).getSubjectDN().getName() ); } 705 } 706 707 sec = sb.toString(); 708 break; 709 case SignVerifier.TRUSTED: 710 sec = TRUSTED; 711 break; 712 } 713 714 if ( isSelected ) { 715 setBackground ((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("Table.selectionBackground")); nameLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("Table.selectionForeground")); securityLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("Table.selectionForeground")); } 719 else { 720 setBackground ((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("Table.background")); nameLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("Table.Foreground")); securityLabel.setForeground((java.awt.Color ) javax.swing.UIManager.getDefaults ().get ("Table.Foreground")); } 724 nameLabel.setText( ((ModuleUpdate)value).getName() + 725 " " + getBundle( "CTL_Version" ) + 726 ((ModuleUpdate)value).getRemoteModule().getSpecificationVersion()); 727 securityLabel.setText( sec ); 728 729 return this; 730 } 731 732 private void initComponents() { 733 java.awt.GridBagConstraints gridBagConstraints; 734 735 nameLabel = new JLabel(); 736 securityLabel = new JLabel(); 737 738 setLayout(new java.awt.GridBagLayout ()); 739 nameLabel.setFont(doDeriveFont(nameLabel.getFont(), Font.BOLD)); 740 741 gridBagConstraints = new java.awt.GridBagConstraints (); 742 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; 743 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 744 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 745 gridBagConstraints.weightx = 1.0; 746 gridBagConstraints.weighty = 1.0; 747 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 748 add(nameLabel, gridBagConstraints); 749 750 gridBagConstraints = new java.awt.GridBagConstraints (); 751 gridBagConstraints.gridx = 0; 752 gridBagConstraints.gridy = 1; 753 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE; 754 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 755 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 756 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 757 gridBagConstraints.weightx = 1.0; 758 gridBagConstraints.weighty = 1.0; 759 add(securityLabel, gridBagConstraints); 760 761 } 762 } 763 764 static class BooleanRenderer extends JCheckBox implements TableCellRenderer { 765 public BooleanRenderer() { 766 super(); 767 setHorizontalAlignment(JLabel.CENTER); 768 setBorder(new javax.swing.border.LineBorder ((java.awt.Color ) javax.swing.UIManager.getDefaults().get("Button.focus"))); 769 } 770 771 public Component getTableCellRendererComponent(JTable table, Object value, 772 boolean isSelected, boolean hasFocus, int row, int column) { 773 if (isSelected) { 774 setForeground(table.getSelectionForeground()); 775 super.setBackground(table.getSelectionBackground()); 776 } 777 else { 778 setForeground(table.getForeground()); 779 setBackground(table.getBackground()); 780 } 781 782 setBorderPainted( isSelected && table.getSelectedColumn() == column ); 783 784 setSelected((value != null && ((Boolean )value).booleanValue())); 785 return this; 786 } 787 } 788 789 private File getSaveCopyDir() throws FileNotFoundException { 790 JFileChooser chooser = new JFileChooser(); 791 chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY ); 792 chooser.setDialogTitle( 793 NbBundle.getMessage( ResultsPanel.class, "CTL_FileChooserSC_Title", 794 getListSelection().getDistributionFilename() 795 ) 796 ); 797 chooser.setFileFilter( new javax.swing.filechooser.FileFilter () { 798 public boolean accept( File f ) { 799 return f.canWrite(); 800 } 801 802 public String getDescription() { 803 return getBundle( "CTL_FileFilterSCDescription" ); 804 } 805 }); 806 807 if (defaultDir == null) 808 defaultDir = SelectModulesPanel.getDefaultDir(); 809 810 if ( defaultDir != null) { 811 File parent = defaultDir.getParentFile(); 812 if ( parent != null ) { 813 chooser.setCurrentDirectory( parent ); 814 chooser.setSelectedFile( defaultDir ); 815 } 816 else 817 chooser.setCurrentDirectory( defaultDir ); 818 } 819 820 Window focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow (); 821 822 File res = null; 823 824 if (chooser.showDialog( WindowManager.getDefault().getMainWindow (), 825 getBundle("CTL_Save")) 826 == JFileChooser.APPROVE_OPTION) { 827 828 defaultDir = chooser.getSelectedFile(); 829 if (defaultDir.exists ()) { 830 res = defaultDir; 831 } else { 832 throw new FileNotFoundException (defaultDir.getAbsolutePath ()); } 836 } else { 837 res = null; 838 } 839 840 if (focusOwner != null) { 842 focusOwner.toFront (); 843 } 844 845 return res; 846 } 847 848 private JButton getYesToAll () { 849 if (yesToAll == null) { 850 yesToAll = new JButton (); 851 org.openide.awt.Mnemonics.setLocalizedText(yesToAll, getBundle("CTL_Yes_All")); 852 yesToAll.getAccessibleContext ().setAccessibleName (getBundle("ACSN_Yes_All")); 853 yesToAll.getAccessibleContext ().setAccessibleDescription (getBundle("ACSD_Yes_All")); 854 } 855 return yesToAll; 856 } 857 858 private static String getBundle( String key ) { 859 return NbBundle.getMessage( ResultsPanel.class, key ); 860 } 861 862 static Font doDeriveFont(Font original, int style) { 863 if (Utilities.isMac()) { 865 return new Font (original.getName(), style, original.getSize()); 866 } 867 return original.deriveFont(style); 868 } 869 } 870 | Popular Tags |