1 19 20 package org.netbeans.modules.javadoc.search; 21 22 import java.io.Externalizable ; 23 import java.io.ObjectStreamException ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.lang.ref.Reference ; 27 import java.lang.ref.SoftReference ; 28 import java.util.ResourceBundle ; 29 import javax.swing.ComboBoxModel ; 30 import javax.swing.DefaultListModel ; 31 import javax.swing.ImageIcon ; 32 import javax.swing.JSplitPane ; 33 import org.netbeans.api.java.source.ElementHandle; 34 import org.netbeans.api.java.source.UiUtils; 35 import org.netbeans.api.javahelp.Help; 36 import org.netbeans.modules.javadoc.settings.DocumentationSettings; 37 import org.openide.awt.HtmlBrowser; 38 import org.openide.windows.TopComponent; 39 import org.openide.util.RequestProcessor; 40 import org.openide.NotifyDescriptor; 41 import org.openide.DialogDisplayer; 42 import org.openide.filesystems.FileObject; 43 import org.openide.util.HelpCtx; 44 import org.openide.util.Lookup; 45 import org.openide.util.NbBundle; 46 import org.openide.util.Utilities; 47 48 52 public final class IndexSearch 53 extends TopComponent 54 implements Externalizable { 55 56 private static final String INDEX_SEARCH_HELP_CTX_KEY = "javadoc.search.window"; 58 private static final java.awt.Dimension PREFFERED_SIZE = new java.awt.Dimension ( 580, 430 ); 59 60 static final long serialVersionUID =1200348578933093459L; 61 62 63 private static Reference refIndexSearch; 64 65 66 private static Object [] MRU = new Object [0]; 67 68 69 private JavadocSearchEngine searchEngine = null; 70 71 72 private DocumentationSettings ds = DocumentationSettings.getDefault(); 73 74 private String quickFind; 75 76 77 private String currentSort = "A"; 79 80 private javax.swing.JScrollPane resultsScrollPane; 81 private javax.swing.JList resultsList; 82 private HtmlBrowser quickBrowser; 84 private JSplitPane splitPanel; 85 86 87 88 private static final String STR_FIND = NbBundle.getMessage(IndexSearch.class, "CTL_SEARCH_ButtonFind"); private static final String STR_STOP = NbBundle.getMessage(IndexSearch.class, "CTL_SEARCH_ButtonStop"); 91 92 private ArrayList results = new ArrayList (); 93 94 private DefaultListModel referenceModel = null; 95 private DefaultListModel typeModel = null; 96 private DefaultListModel alphaModel = null; 97 98 99 private int oldSplit = DocumentationSettings.getDefault().getIdxSearchSplit(); 100 101 private final DefaultListModel waitModel = new DefaultListModel (); 102 private final DefaultListModel notModel = new DefaultListModel (); 103 private boolean setDividerLocation; 104 105 106 public IndexSearch() { 107 ResourceBundle b = NbBundle.getBundle(IndexSearch.class); 108 DocIndexItem dii = new DocIndexItem( b.getString("CTL_SEARCH_Wait" ), "", null, "" ); dii.setIconIndex( DocSearchIcons.ICON_WAIT ); 110 waitModel.addElement( dii ); 111 112 DocIndexItem diin = new DocIndexItem( b.getString("CTL_SEARCH_NotFound" ), "", null, "" ); diin.setIconIndex( DocSearchIcons.ICON_NOT_FOUND ); 114 notModel.addElement( diin ); 115 116 initComponents (); 117 118 putClientProperty("TabPolicy", "HideWhenAlone"); 121 javax.swing.ComboBoxEditor editor = searchComboBox.getEditor(); 122 editor.addActionListener (new java.awt.event.ActionListener () { 123 public void actionPerformed (java.awt.event.ActionEvent evt) { 124 if ( searchEngine == null ) 125 searchButtonActionPerformed( evt ); 126 } 127 } 128 ); 129 130 splitPanel = new JSplitPane (JSplitPane.VERTICAL_SPLIT); 132 splitPanel.setPreferredSize(PREFFERED_SIZE); 133 134 splitPanel.setDividerLocation(oldSplit / 100.0); 135 setDividerLocation = true; 138 139 140 java.awt.GridBagConstraints gridBagConstraints1 = new java.awt.GridBagConstraints (); 141 gridBagConstraints1.gridwidth = 0; 142 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; 143 gridBagConstraints1.insets = new java.awt.Insets (5, 0, 0, 0); 144 gridBagConstraints1.weightx = 1.0; 145 gridBagConstraints1.weighty = 1.0; 146 add (splitPanel, gridBagConstraints1); 147 148 resultsScrollPane = new javax.swing.JScrollPane (); 150 151 resultsList = new javax.swing.JList (); 152 resultsList.setSelectionMode (javax.swing.ListSelectionModel.SINGLE_SELECTION ); 153 resultsList.addKeyListener (new java.awt.event.KeyAdapter () { 154 public void keyPressed (java.awt.event.KeyEvent evt) { 155 resultsListKeyPressed (evt); 156 } 157 } 158 ); 159 resultsList.addMouseListener (new java.awt.event.MouseAdapter () { 160 public void mouseClicked (java.awt.event.MouseEvent evt) { 161 resultsListMouseClicked (evt); 162 } 163 } 164 ); 165 166 resultsScrollPane.setViewportView (resultsList); 167 168 splitPanel.setTopComponent(resultsScrollPane); 169 170 quickBrowser = new HtmlBrowser( true, false ); quickBrowser.setEnableLocation( false ); 173 quickBrowser.setEnableHome( false ); 174 quickBrowser.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (8, 0, 0, 0))); 176 splitPanel.setBottomComponent(quickBrowser); 177 178 DefaultListModel listModel = new DefaultListModel (); resultsList.setModel( listModel ); 180 181 IndexListCellRenderer cr = new IndexListCellRenderer(); 182 resultsList.setCellRenderer( cr ); 183 184 resultsList.getSelectionModel().addListSelectionListener( 185 new javax.swing.event.ListSelectionListener () { 186 public void valueChanged( javax.swing.event.ListSelectionEvent evt ) { 187 showHelp( true ); 188 } 189 }); 190 resultsScrollPane.validate(); 191 192 searchButton.setText( STR_FIND ); 193 194 195 sourceButton.setIcon(new ImageIcon (Utilities.loadImage("org/netbeans/modules/javadoc/resources/showSource.gif"))); byReferenceButton.setIcon(new ImageIcon (Utilities.loadImage("org/netbeans/modules/javadoc/resources/refSort.gif"))); byTypeButton.setIcon(new ImageIcon (Utilities.loadImage("org/netbeans/modules/javadoc/resources/typeSort.gif"))); byNameButton.setIcon(new ImageIcon (Utilities.loadImage("org/netbeans/modules/javadoc/resources/alphaSort.gif"))); quickViewButton.setIcon(new ImageIcon (Utilities.loadImage("org/netbeans/modules/javadoc/resources/list_html.gif"))); quickViewButton.setSelectedIcon(new ImageIcon (Utilities.loadImage("org/netbeans/modules/javadoc/resources/list_only.gif"))); 202 javax.swing.ButtonGroup bg = new javax.swing.ButtonGroup (); 203 bg.add( byReferenceButton ); 204 bg.add( byTypeButton ); 205 bg.add( byNameButton ); 206 207 209 searchButton.setToolTipText(b.getString( "CTL_SEARCH_search_ToolTip" )); byReferenceButton.setToolTipText(b.getString( "CTL_SEARCH_byReference_ToolTip" )); byReferenceButton.setMnemonic(b.getString("CTL_SEARCH_byReference_Mnemonic").charAt(0)); byTypeButton.setToolTipText(b.getString( "CTL_SEARCH_byType_ToolTip" )); byTypeButton.setMnemonic(b.getString("CTL_SEARCH_byType_Mnemonic").charAt(0)); byNameButton.setToolTipText(b.getString( "CTL_SEARCH_byName_ToolTip" )); byNameButton.setMnemonic(b.getString("CTL_SEARCH_byName_Mnemonic").charAt(0)); quickViewButton.setToolTipText(b.getString( "CTL_SEARCH_quickView_ToolTip" )); quickViewButton.setMnemonic(b.getString("CTL_SEARCH_quickView_Mnemonic").charAt(0)); sourceButton.setToolTipText(b.getString( "CTL_SEARCH_showSource_ToolTip" )); sourceButton.setMnemonic(b.getString("CTL_SEARCH_showSource_Mnemonic").charAt(0)); searchComboBox.setToolTipText(b.getString( "ACS_SEARCH_SearchComboBoxA11yDesc" )); resultsList.setToolTipText(b.getString( "ACS_SEARCH_ResultsListA11yDesc" )); quickBrowser.setToolTipText(b.getString( "ACS_SEARCH_QuickBrowserA11yDesc" )); 224 searchButton.setMnemonic(b.getString("CTL_SEARCH_ButtonFind_Mnemonic").charAt(0)); helpButton.setMnemonic(b.getString("CTL_SEARCH_ButtonHelp_Mnemonic").charAt(0)); 227 initAccessibility(); 228 } 229 230 public int getPersistenceType() { 231 return TopComponent.PERSISTENCE_NEVER; 232 } 233 234 protected String preferredID() { 235 return "JavaDocIndexSearch"; } 237 238 public HelpCtx getHelpCtx() { 239 return new HelpCtx(INDEX_SEARCH_HELP_CTX_KEY); 240 } 241 242 private void initAccessibility() { 243 ResourceBundle b = NbBundle.getBundle(IndexSearch.class); 244 getAccessibleContext().setAccessibleName(b.getString("ACS_SEARCH_PanelA11yName")); getAccessibleContext().setAccessibleDescription(b.getString("ACS_SEARCH_PanelA11yDesc")); searchComboBox.getAccessibleContext().setAccessibleName(b.getString("ACS_SEARCH_SearchComboBoxA11yName")); searchComboBox.getAccessibleContext().setAccessibleDescription(b.getString("ACS_SEARCH_SearchComboBoxA11yDesc")); resultsList.getAccessibleContext().setAccessibleName(b.getString("ACS_SEARCH_ResultsListA11yName")); resultsList.getAccessibleContext().setAccessibleDescription(b.getString("ACS_SEARCH_ResultsListA11yDesc")); quickBrowser.getAccessibleContext().setAccessibleName(b.getString("ACS_SEARCH_QuickBrowserA11yName")); quickBrowser.getAccessibleContext().setAccessibleDescription(b.getString("ACS_SEARCH_QuickBrowserA11yDesc")); } 253 254 259 private void initComponents() { 261 java.awt.GridBagConstraints gridBagConstraints; 262 263 jPanel1 = new javax.swing.JPanel (); 264 searchComboBox = new javax.swing.JComboBox (MRU); 265 searchButton = new javax.swing.JButton (); 266 sourceButton = new javax.swing.JButton (); 267 byNameButton = new javax.swing.JToggleButton (); 268 byReferenceButton = new javax.swing.JToggleButton (); 269 byTypeButton = new javax.swing.JToggleButton (); 270 quickViewButton = new javax.swing.JToggleButton (); 271 helpButton = new javax.swing.JButton (); 272 273 FormListener formListener = new FormListener(); 274 275 setLayout(new java.awt.GridBagLayout ()); 276 277 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (8, 8, 8, 8))); 278 jPanel1.setLayout(new java.awt.GridBagLayout ()); 279 280 searchComboBox.setEditable(true); 281 searchComboBox.addActionListener(formListener); 282 283 gridBagConstraints = new java.awt.GridBagConstraints (); 284 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 285 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 286 gridBagConstraints.weightx = 1.0; 287 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 8); 288 jPanel1.add(searchComboBox, gridBagConstraints); 289 290 searchButton.setText(org.openide.util.NbBundle.getBundle(IndexSearch.class).getString("IndexSearch.searchButton.text")); 291 searchButton.addActionListener(formListener); 292 293 gridBagConstraints = new java.awt.GridBagConstraints (); 294 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 295 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 3); 296 jPanel1.add(searchButton, gridBagConstraints); 297 298 sourceButton.setPreferredSize(new java.awt.Dimension (25, 25)); 299 sourceButton.setMinimumSize(new java.awt.Dimension (25, 25)); 300 sourceButton.addActionListener(formListener); 301 302 gridBagConstraints = new java.awt.GridBagConstraints (); 303 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 3); 304 jPanel1.add(sourceButton, gridBagConstraints); 305 306 byNameButton.setSelected(true); 307 byNameButton.setPreferredSize(new java.awt.Dimension (25, 25)); 308 byNameButton.setActionCommand("A"); 309 byNameButton.setMinimumSize(new java.awt.Dimension (25, 25)); 310 byNameButton.setRequestFocusEnabled(false); 311 byNameButton.addActionListener(formListener); 312 313 jPanel1.add(byNameButton, new java.awt.GridBagConstraints ()); 314 315 byReferenceButton.setPreferredSize(new java.awt.Dimension (25, 25)); 316 byReferenceButton.setActionCommand("R"); 317 byReferenceButton.setMinimumSize(new java.awt.Dimension (25, 25)); 318 byReferenceButton.setRequestFocusEnabled(false); 319 byReferenceButton.addActionListener(formListener); 320 321 jPanel1.add(byReferenceButton, new java.awt.GridBagConstraints ()); 322 323 byTypeButton.setPreferredSize(new java.awt.Dimension (25, 25)); 324 byTypeButton.setActionCommand("T"); 325 byTypeButton.setMinimumSize(new java.awt.Dimension (25, 25)); 326 byTypeButton.setRequestFocusEnabled(false); 327 byTypeButton.addActionListener(formListener); 328 329 jPanel1.add(byTypeButton, new java.awt.GridBagConstraints ()); 330 331 quickViewButton.setSelected(true); 332 quickViewButton.setRequestFocusEnabled(false); 333 quickViewButton.addActionListener(formListener); 334 335 gridBagConstraints = new java.awt.GridBagConstraints (); 336 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 0); 337 jPanel1.add(quickViewButton, gridBagConstraints); 338 339 helpButton.setToolTipText(org.openide.util.NbBundle.getBundle(IndexSearch.class).getString("CTL_SEARCH_ButtonHelp_tooltip")); 340 helpButton.setText(org.openide.util.NbBundle.getBundle(IndexSearch.class).getString("CTL_SEARCH_ButtonHelp")); 341 helpButton.addActionListener(formListener); 342 343 gridBagConstraints = new java.awt.GridBagConstraints (); 344 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 345 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 0); 346 jPanel1.add(helpButton, gridBagConstraints); 347 348 gridBagConstraints = new java.awt.GridBagConstraints (); 349 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 350 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 351 gridBagConstraints.weightx = 1.0; 352 add(jPanel1, gridBagConstraints); 353 354 } 355 356 358 private class FormListener implements java.awt.event.ActionListener { 359 public void actionPerformed(java.awt.event.ActionEvent evt) { 360 if (evt.getSource() == searchComboBox) { 361 IndexSearch.this.searchComboBoxActionPerformed(evt); 362 } 363 else if (evt.getSource() == searchButton) { 364 IndexSearch.this.searchButtonActionPerformed(evt); 365 } 366 else if (evt.getSource() == sourceButton) { 367 IndexSearch.this.showSource(evt); 368 } 369 else if (evt.getSource() == byNameButton) { 370 IndexSearch.this.sortButtonActionPerformed(evt); 371 } 372 else if (evt.getSource() == byReferenceButton) { 373 IndexSearch.this.sortButtonActionPerformed(evt); 374 } 375 else if (evt.getSource() == byTypeButton) { 376 IndexSearch.this.sortButtonActionPerformed(evt); 377 } 378 else if (evt.getSource() == quickViewButton) { 379 IndexSearch.this.quickViewButtonActionPerformed(evt); 380 } 381 else if (evt.getSource() == helpButton) { 382 IndexSearch.this.helpButtonActionPerformed(evt); 383 } 384 } 385 } 386 388 private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) { Help help=(Help)Lookup.getDefault().lookup(Help.class); 390 391 help.showHelp(getHelpCtx()); 392 } 394 private void showSource (java.awt.event.ActionEvent evt) { showSource(); 396 } 398 private void sortButtonActionPerformed (java.awt.event.ActionEvent evt) { 400 currentSort = evt.getActionCommand(); 401 ds.setIdxSearchSort( currentSort ); 402 sortResults(); 403 404 } 406 private void quickViewButtonActionPerformed (java.awt.event.ActionEvent evt) { if ( quickViewButton.isSelected() ) { 408 splitPanel.setDividerLocation( oldSplit == 100 ? 0.5 : oldSplit / 100.0 ); 409 ds.setIdxSearchSplit( oldSplit == 100 ? 50 : oldSplit ); 410 ds.setIdxSearchNoHtml( false ); 411 showHelp( true ); 412 } 413 else { 414 oldSplit = (int) (splitPanel.getDividerLocation() / splitPanel.getSize().getHeight() * 100); 415 splitPanel.setDividerLocation( 1.0 ); 416 ds.setIdxSearchSplit( 100 ); 417 ds.setIdxSearchNoHtml( true ); 418 } 419 } 421 private void resultsListKeyPressed (java.awt.event.KeyEvent evt) { if ( evt.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER || 424 evt.getKeyCode() == java.awt.event.KeyEvent.VK_SPACE ) { 425 432 showHelp(); 433 } 434 } 436 private void resultsListMouseClicked (java.awt.event.MouseEvent evt) { if ( evt.getClickCount() == 2 ) { 439 if ( evt.isShiftDown() ) { 440 showSource(); 441 evt.consume(); 442 } 443 else 444 showHelp(); 445 } 446 } 448 private void showHelp( ) { 449 showHelp( false ); 450 } 451 452 RequestProcessor.Task task=null; 453 454 private void showHelp( boolean quick ) { 455 456 if (quick && splitPanel.getDividerLocation() == 100 ) 457 return; 458 459 if ( resultsList.getMinSelectionIndex() < 0 ) 460 return; 461 462 463 DocIndexItem dii = (DocIndexItem)resultsList.getModel().getElementAt( resultsList.getMinSelectionIndex() ); 464 465 try { 466 URL url = dii.getURL(); 467 468 if ( url == null ) 469 return; 470 471 String strUrl = url.toString(); 473 474 if ( strUrl.startsWith( "nbfs:" ) && strUrl.charAt( 5 ) != '/' ){ url = new URL ( "nbfs:/" + strUrl.substring( 5 ) ); } 477 478 if ( quick ){ 479 final URL furl = url; 480 if( task != null ) 481 task.cancel(); 482 task = RequestProcessor.getDefault().post( new Runnable (){ 483 public void run(){ 484 quickBrowser.setURL( furl ); 485 } 486 }, 100 ); 487 } 488 else 489 HtmlBrowser.URLDisplayer.getDefault().showURL( url ); 490 } 491 catch ( java.net.MalformedURLException ex ) { 492 } 494 } 495 496 499 private void showSource( ) { 500 501 if ( resultsList.getMinSelectionIndex() < 0 ) { 502 return; 503 } 504 505 DocIndexItem dii = (DocIndexItem)resultsList.getModel().getElementAt( resultsList.getMinSelectionIndex() ); 506 507 try { 508 Object [] e = SrcFinder.findSource( dii.getPackage(), dii.getURL() ); 509 510 if ( e != null ) { 511 FileObject toOpen = (FileObject) e[0]; 512 ElementHandle eh = (ElementHandle) e[1]; 513 UiUtils.open(toOpen, eh); 514 } 515 else { 516 NotifyDescriptor.Message nd = new NotifyDescriptor.Message( NbBundle.getMessage(IndexSearch.class, "MSG_SEARCH_SrcNotFound" ) ); DialogDisplayer.getDefault().notify( nd ); 518 } 519 520 } 521 catch ( java.net.MalformedURLException e ) { 522 } 524 } 525 526 private void searchComboBoxActionPerformed (java.awt.event.ActionEvent evt) { 529 } 531 private void searchButtonActionPerformed (java.awt.event.ActionEvent evt) { if ( searchEngine == null ) { 533 if ( searchComboBox.getEditor().getItem().toString() != null && 534 searchComboBox.getEditor().getItem().toString().length() > 0 ) { 535 searchEngine = JavadocSearchEngine.getDefault(); 536 go(); 537 } 538 } 539 else { 540 searchEngine.stop(); 541 searchEngine = null; 542 } 543 } 545 546 private javax.swing.JToggleButton byNameButton; 548 private javax.swing.JToggleButton byReferenceButton; 549 private javax.swing.JToggleButton byTypeButton; 550 private javax.swing.JButton helpButton; 551 private javax.swing.JPanel jPanel1; 552 private javax.swing.JToggleButton quickViewButton; 553 private javax.swing.JButton searchButton; 554 private javax.swing.JComboBox searchComboBox; 555 private javax.swing.JButton sourceButton; 556 558 559 private void searchStoped() { 560 searchEngine = null; 561 javax.swing.SwingUtilities.invokeLater( new Runnable () { 562 public void run() { 563 searchButton.setText( STR_FIND ); 564 searchButton.setMnemonic(NbBundle.getMessage(IndexSearch.class,"CTL_SEARCH_ButtonFind_Mnemonic").charAt(0)); if ( resultsList.getModel().getSize() > 0 ) { 566 resultsList.setSelectedIndex( 0 ); 567 resultsList.grabFocus(); 568 } 569 referenceModel = typeModel = alphaModel = null; 570 sortResults(); 571 } 572 } ); 573 } 574 575 void setTextToFind( String toFind ) { 576 quickFind = toFind; 577 582 } 583 584 585 public void open() { 586 super.open(); 587 588 if ( quickFind != null ) { 589 searchComboBox.getEditor().setItem( quickFind ); 590 if ( searchEngine == null ) { 591 searchButtonActionPerformed( null ); 592 } 593 } 594 595 quickFind = null; 596 searchComboBox.getEditor().selectAll(); 597 598 if (setDividerLocation) { 599 splitPanel.setDividerLocation(oldSplit / 100.0); 600 setDividerLocation = false; 601 } 602 } 603 604 java.awt.Dimension getPrefferedSize() { 605 return PREFFERED_SIZE; 606 } 607 608 public static IndexSearch getDefault() { 609 IndexSearch indexSearch; 610 if (refIndexSearch == null || null == (indexSearch = (IndexSearch) refIndexSearch.get())) { 611 indexSearch = new IndexSearch (); 612 refIndexSearch = new SoftReference (indexSearch); 613 614 indexSearch.setName( NbBundle.getMessage(IndexSearch.class, "CTL_SEARCH_WindowTitle") ); indexSearch.setIcon(Utilities.loadImage("org/netbeans/modules/javadoc/resources/searchDoc.gif")); } 617 return indexSearch; 618 } 619 620 public void resolveButtonState() { 621 622 final String sort = ds.getIdxSearchSort(); 623 final boolean noHtml = ds.isIdxSearchNoHtml(); 624 final int split = ds.getIdxSearchSplit(); 625 626 currentSort = sort; 627 628 javax.swing.SwingUtilities.invokeLater( new Runnable () { 629 public void run() { 630 byNameButton.setSelected( sort.equals( "A" ) ); byReferenceButton.setSelected( sort.equals( "R" ) ); byTypeButton.setSelected( sort.equals( "T" ) ); 634 quickViewButton.setSelected( !noHtml ); 635 636 splitPanel.setDividerLocation(split / 100.0); 637 } 638 } ); 639 } 640 641 647 private Object readResolve() throws ObjectStreamException { 648 return getDefault(); 649 } 650 651 void go() { 652 String toFind = searchComboBox.getEditor().getItem().toString().trim(); 653 654 results = new ArrayList (); 656 657 referenceModel = null; 659 typeModel = null; 660 alphaModel = null; 661 662 664 for ( int i = 0; i < searchComboBox.getItemCount(); i++ ) { 665 if ( searchComboBox.getItemAt( i ).toString().equals( toFind ) || i >= 10 ) { 666 searchComboBox.removeItemAt( i ); 667 } 668 } 669 670 searchComboBox.insertItemAt( toFind, 0 ); 671 mirrorMRUStrings(); 672 searchComboBox.getEditor().setItem( toFind ); 673 674 resultsList.setModel( waitModel ); 675 676 try { 677 searchEngine.search(new String []{toFind}, new JavadocSearchEngine.SearchEngineCallback(){ 678 public void finished(){ 679 searchStoped(); 680 } 681 public void addItem(DocIndexItem item){ 682 results.add(item); 683 } 684 }); 685 } 686 catch(NoJavadocException noJdc){ 687 DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( noJdc.getMessage() ) ); searchStoped(); 689 return; 690 } 691 692 searchButton.setText( STR_STOP ); 693 searchButton.setMnemonic(NbBundle.getMessage(IndexSearch.class,"CTL_SEARCH_ButtonStop_Mnemonic").charAt(0)); } 695 696 private void mirrorMRUStrings() { 697 ComboBoxModel model = searchComboBox.getModel(); 698 int size = model.getSize(); 699 MRU = new Object [size]; 700 for (int i = 0; i < size; i++) { 701 MRU[i] = model.getElementAt(i); 702 } 703 } 704 705 DefaultListModel generateModel( java.util.Comparator comp ) { 706 DefaultListModel model = new DefaultListModel (); 707 708 java.util.Collections.sort( results, comp ); 709 java.util.Iterator it = results.iterator(); 710 711 String pckg = null; 712 713 while ( it.hasNext() ) { 714 DocIndexItem dii = (DocIndexItem)it.next(); 715 if ( comp == DocIndexItem.REFERENCE_COMPARATOR && 716 !dii.getPackage().equals( pckg ) && 717 dii.getIconIndex() != DocSearchIcons.ICON_PACKAGE ) { 718 DocIndexItem ndii = new DocIndexItem( "PACKAGE ", dii.getPackage(), null, "" ); ndii.setIconIndex( DocSearchIcons.ICON_PACKAGE ); 720 model.addElement( ndii ); 721 pckg = dii.getPackage(); 722 } 723 724 model.addElement( dii ); 725 } 726 return model; 727 } 728 729 void sortResults() { 730 731 if ( results.size() < 1 ) { 732 resultsList.setModel( notModel ); 733 } 734 else if ( currentSort.equals( "R" ) ) { if ( referenceModel == null ) { 736 resultsList.setModel( waitModel ); 737 resultsList.invalidate(); 738 resultsList.revalidate(); 739 referenceModel = generateModel( DocIndexItem.REFERENCE_COMPARATOR ); 740 } 741 resultsList.setModel( referenceModel ); 742 } 743 else if ( currentSort.equals( "T" ) ) { if ( typeModel == null ) { 745 resultsList.setModel( waitModel ); 746 resultsList.invalidate(); 747 resultsList.revalidate(); 748 typeModel = generateModel( DocIndexItem.TYPE_COMPARATOR ); 749 } 750 resultsList.setModel( typeModel ); 751 } 752 else if ( currentSort.equals( "A" ) ) { if ( alphaModel == null ) { 754 resultsList.setModel( waitModel ); 755 resultsList.invalidate(); 756 resultsList.revalidate(); 757 alphaModel = generateModel( DocIndexItem.ALPHA_COMPARATOR ); 758 } 759 resultsList.setModel( alphaModel ); 760 } 761 762 resultsList.invalidate(); 763 resultsList.revalidate(); 764 resultsList.repaint(); 765 } 766 } 767 | Popular Tags |