Changeset 2154 for trunk/java-client


Ignore:
Timestamp:
2001-03-10T16:11:02+13:00 (23 years ago)
Author:
daven
Message:

minor performance tweaks, tidying, dead code removal, comment removal

Location:
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CSModel.java

    r2148 r2154  
    7878  public void clearResults()
    7979  {
    80     System.out.println("Clearing resultModel");
     80    //System.out.println("Clearing resultModel");
    8181    results.clear();
    8282  }
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java

    r2153 r2154  
    5757
    5858  CSModel csModel;
     59  NzdlService nzdl;
     60
    5961  JLabel collectionLabel;
    6062  JTextField searchTextField;
    6163  JButton searchButton;
    62   JComboBox collectionList;  // can we search multiple collections at once?
     64  JComboBox collectionList; 
    6365  JPanel queryFormulationPanel, resultsPanel, dataPanel;
    6466  JPanel collectionListPanel, searchTextFieldPanel, searchButtonPanel;
    65   /** where the ranked results are displayed */
    6667  JList   resultsList;   
    6768  JScrollPane scrollResultsPane;
    6869  JScrollPane scrollDataPane;
    6970  JFrame windowParent;
    70   /** where the doc contents are displayed */
     71
    7172  JTextPane documentPane;
    7273  HTMLEditorKit htmlEditorKit;
    7374  HTMLDocument htmlDoc;
    7475 
    75   final static String DOC_HEADER = "<html><body>";
    76   final static String DOC_FOOTER = "</body></html>";
     76   final static Rectangle TOP_RECT = new Rectangle(0,0,0,0);
    7777
    7878  /**
     
    8585    windowParent = parent;
    8686    csModel = newCsModel;
     87    nzdl = csModel.getNzdlService();
    8788    setLayout( new BoxLayout(this, BoxLayout.Y_AXIS));
    8889    setBorder(BorderFactory.createTitledBorder("Search"));
     
    115116      };
    116117
    117     //collectionList.setSelectedIndex(0); // only if there is content
    118118    collectionListPanel.add(collectionLabel);
    119119    collectionListPanel.add(collectionList);
     
    150150    dataPanel.setLayout(new BorderLayout());
    151151    dataPanel.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
    152     /* documentPane = new JEditorPane("text/html",
    153        "<html><body>Document details will appear here.</body></html>");
    154  */
    155152    documentPane = new JTextPane();
    156     htmlEditorKit  =  new HTMLEditorKit();
    157    
     153    htmlEditorKit  =  new HTMLEditorKit();   
    158154    documentPane.setEditorKit(htmlEditorKit);
    159155    documentPane.setEditable(false);
     
    167163   
    168164    parent.getRootPane().setDefaultButton(searchButton);
    169    
    170     //resultsList.getSelectionModel().addListSelectionListener(new ResultListSelectionHandler() );
     165
    171166    resultsList.addListSelectionListener(new ResultListSelectionHandler() );
    172    
     167
    173168    add(Box.createHorizontalStrut(400));
    174    
    175169    add(queryFormulationPanel);
    176170    add(resultsPanel);
     
    181175  /** respond to the user pressing the Search button */
    182176
    183 
    184177  public void actionPerformed(ActionEvent e) {
    185178    if (e.getSource() == searchButton ) { //assume only searchButton generates events
    186       System.out.println("Search button pressed in SearchPanel");
     179      windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
     180      String queryString = searchTextField.getText();
     181      String collectionName = collectionList.getSelectedItem().toString();
     182      System.err.println("Search started (" + collectionName + "): \"" + queryString + "\" ..." );
    187183      //send query to collection
    188       NzdlQuery nzdlQuery = new NzdlQuery( searchTextField.getText() );
     184      NzdlQuery nzdlQuery = new NzdlQuery(queryString);
    189185      // return the first numResults that match
    190186      //query.setEndResults( 15 );
    191187      // "-1" means consider all the documents that match
    192188      nzdlQuery.setMaxDocs( -1 );
    193       String collectionName = collectionList.getSelectedItem().toString();
    194189      NzdlRequest request = new NzdlRequest( nzdlQuery );
    195       NzdlResponse response = new NzdlResponse( );
    196       csModel.getNzdlService().service( collectionName, request, response ); //nzdl object ????
     190      NzdlResponse response = new NzdlResponse();
     191      nzdl.service( collectionName, request, response );
    197192      NzdlResultSet results = response.getResultSet();
    198193      java.util.List docIDs = results.getDocumentIDs();
     
    209204      } // end for
    210205      // update the results list
    211       // empty previous results List
    212206      csModel.clearResults();
    213207      // System.err.println("Size of docIDs = " + docIDs.size());
    214       if (docIDs.size() == 0 ) { // no real results
     208      if (docIDs.size() == 0 ) { // give some feedback for 0 results
    215209    csModel.addResult(new Result(Result.FAKE_RESULT, "", ""));
    216210    documentPane.setText("");
     
    220214    while (docIDsIterator.hasNext()) {
    221215      String resultDocID =  (String) docIDsIterator.next();
    222       //System.err.println("Adding result");
    223216      csModel.addResult(new Result((String)titleMap.get(resultDocID), resultDocID, collectionName ));
    224217    } //end while
     218    resultsList.setSelectedIndex(0);
    225219      } // end else
    226       // default to showing the top ranked document
    227       if (docIDs.size() > 0)
    228     resultsList.setSelectedIndex(0);
     220      windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    229221    } // end if
    230222    else {
    231       System.out.println("unknown Action event in SearchPanel");
     223      System.err.println("unknown Action event in SearchPanel");
    232224    }
    233225  } //end actionPerformed
     
    243235      Result result =  (Result) resultsList.getSelectedValue();
    244236      if (result.toString() == Result.FAKE_RESULT) {
    245       //System.err.println("no results");
    246237      documentPane.setText("");
    247       //System.err.println("no results");
    248238      }
    249239      else {
    250240      windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    251       //get the document content from the result object
    252       // use a String for the moment to hold the contents
    253       // should cache document contents here to speed access
    254       // String documentContents = csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID());
    255       htmlDoc = new HTMLDocument();
     241      htmlDoc = new HTMLDocument();
    256242      try
    257       {
     243          { // get the document and read it in as HTML
    258244          htmlEditorKit.read( new StringReader(csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID())), htmlDoc, 0);
    259245      }
     
    267253      }
    268254      documentPane.setStyledDocument( htmlDoc );
    269       //documentContents = DOC_HEADER + documentContents + DOC_FOOTER;
    270       //documentPane.setText(documentContents);
    271 System.err.println("caret(before) = " + documentPane.getCaretPosition());
    272       documentPane.setCaretPosition(1);
    273       System.err.println("caret = " + documentPane.getCaretPosition());
     255      documentPane.scrollRectToVisible(TOP_RECT);
    274256      windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    275257      }
     
    277259  }//end ResultListSelectionHandler
    278260
    279 
    280 
    281261} //end SearchPanel
Note: See TracChangeset for help on using the changeset viewer.