Changeset 2154
- Timestamp:
- 2001-03-10T16:11:02+13:00 (23 years ago)
- 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 78 78 public void clearResults() 79 79 { 80 System.out.println("Clearing resultModel");80 //System.out.println("Clearing resultModel"); 81 81 results.clear(); 82 82 } -
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java
r2153 r2154 57 57 58 58 CSModel csModel; 59 NzdlService nzdl; 60 59 61 JLabel collectionLabel; 60 62 JTextField searchTextField; 61 63 JButton searchButton; 62 JComboBox collectionList; // can we search multiple collections at once?64 JComboBox collectionList; 63 65 JPanel queryFormulationPanel, resultsPanel, dataPanel; 64 66 JPanel collectionListPanel, searchTextFieldPanel, searchButtonPanel; 65 /** where the ranked results are displayed */66 67 JList resultsList; 67 68 JScrollPane scrollResultsPane; 68 69 JScrollPane scrollDataPane; 69 70 JFrame windowParent; 70 /** where the doc contents are displayed */ 71 71 72 JTextPane documentPane; 72 73 HTMLEditorKit htmlEditorKit; 73 74 HTMLDocument htmlDoc; 74 75 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); 77 77 78 78 /** … … 85 85 windowParent = parent; 86 86 csModel = newCsModel; 87 nzdl = csModel.getNzdlService(); 87 88 setLayout( new BoxLayout(this, BoxLayout.Y_AXIS)); 88 89 setBorder(BorderFactory.createTitledBorder("Search")); … … 115 116 }; 116 117 117 //collectionList.setSelectedIndex(0); // only if there is content118 118 collectionListPanel.add(collectionLabel); 119 119 collectionListPanel.add(collectionList); … … 150 150 dataPanel.setLayout(new BorderLayout()); 151 151 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 */155 152 documentPane = new JTextPane(); 156 htmlEditorKit = new HTMLEditorKit(); 157 153 htmlEditorKit = new HTMLEditorKit(); 158 154 documentPane.setEditorKit(htmlEditorKit); 159 155 documentPane.setEditable(false); … … 167 163 168 164 parent.getRootPane().setDefaultButton(searchButton); 169 170 //resultsList.getSelectionModel().addListSelectionListener(new ResultListSelectionHandler() ); 165 171 166 resultsList.addListSelectionListener(new ResultListSelectionHandler() ); 172 167 173 168 add(Box.createHorizontalStrut(400)); 174 175 169 add(queryFormulationPanel); 176 170 add(resultsPanel); … … 181 175 /** respond to the user pressing the Search button */ 182 176 183 184 177 public void actionPerformed(ActionEvent e) { 185 178 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 + "\" ..." ); 187 183 //send query to collection 188 NzdlQuery nzdlQuery = new NzdlQuery( searchTextField.getText());184 NzdlQuery nzdlQuery = new NzdlQuery(queryString); 189 185 // return the first numResults that match 190 186 //query.setEndResults( 15 ); 191 187 // "-1" means consider all the documents that match 192 188 nzdlQuery.setMaxDocs( -1 ); 193 String collectionName = collectionList.getSelectedItem().toString();194 189 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 ); 197 192 NzdlResultSet results = response.getResultSet(); 198 193 java.util.List docIDs = results.getDocumentIDs(); … … 209 204 } // end for 210 205 // update the results list 211 // empty previous results List212 206 csModel.clearResults(); 213 207 // System.err.println("Size of docIDs = " + docIDs.size()); 214 if (docIDs.size() == 0 ) { // no realresults208 if (docIDs.size() == 0 ) { // give some feedback for 0 results 215 209 csModel.addResult(new Result(Result.FAKE_RESULT, "", "")); 216 210 documentPane.setText(""); … … 220 214 while (docIDsIterator.hasNext()) { 221 215 String resultDocID = (String) docIDsIterator.next(); 222 //System.err.println("Adding result");223 216 csModel.addResult(new Result((String)titleMap.get(resultDocID), resultDocID, collectionName )); 224 217 } //end while 218 resultsList.setSelectedIndex(0); 225 219 } // 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)); 229 221 } // end if 230 222 else { 231 System. out.println("unknown Action event in SearchPanel");223 System.err.println("unknown Action event in SearchPanel"); 232 224 } 233 225 } //end actionPerformed … … 243 235 Result result = (Result) resultsList.getSelectedValue(); 244 236 if (result.toString() == Result.FAKE_RESULT) { 245 //System.err.println("no results");246 237 documentPane.setText(""); 247 //System.err.println("no results");248 238 } 249 239 else { 250 240 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(); 256 242 try 257 {243 { // get the document and read it in as HTML 258 244 htmlEditorKit.read( new StringReader(csModel.getNzdlService().getDocument(result.getCollectionName(), result.getDocID())), htmlDoc, 0); 259 245 } … … 267 253 } 268 254 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); 274 256 windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 275 257 } … … 277 259 }//end ResultListSelectionHandler 278 260 279 280 281 261 } //end SearchPanel
Note:
See TracChangeset
for help on using the changeset viewer.