Changeset 1626 for trunk/gsdl
- Timestamp:
- 2000-10-30T11:40:56+13:00 (24 years ago)
- Location:
- trunk/gsdl/src/phind/client
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/phind/client/Phind.java
r1625 r1626 51 51 3. ResultBox holds the results of a query. Result boxes are shown 52 52 to the user through ResultDisplays. Another doubly-linked list. 53 4. ResultCanvas is what a ResultBox's data is drawn on, and does 54 the painting in ResultCanvas windows. Also handles clicks. 55 5. ResultItem represents a single result object (a phrase or document). 56 6. PhindTitle is a canvas used for drawing backgrops in empty Displays. 53 4. ResultTitle acts as a caption to a ResultBox describing its contents. 54 5. ResultCanvas is what the ResultBox data is drawn on. It draws the 55 words on the screen, and handles user input from the mouse. 56 6. ResultItem represents a single result object (a phrase or document). 57 58 7. PhindTitle is for drawing backdrops in empty Displays. (?) 57 59 58 60 **********************************************************************/ -
trunk/gsdl/src/phind/client/ResultBox.java
r1625 r1626 248 248 } 249 249 250 // The <phinddata> tag introduces the dataset251 else if (buffer.startsWith("<phinddata ")) {252 253 }254 255 // The <expansionlist> tag256 else if (buffer.startsWith("<expansionlist ")) {257 258 }259 260 250 // The <expansion> tag 261 251 else if (buffer.startsWith("<expansion ")) { … … 274 264 } 275 265 266 // The <expansionlist> tag 267 else if (buffer.startsWith("<expansionlist ")) { 268 item = buffer.substring(0, eol); 269 buffer = buffer.substring(eol + 1); 270 addExpansionListTag(item); 271 return true; 272 } 273 276 274 // The <documentlist> tag 277 275 else if (buffer.startsWith("<documentlist ")) { 278 276 item = buffer.substring(0, eol); 277 buffer = buffer.substring(eol + 1); 278 addDocumentListTag(item); 279 return true; 279 280 } 280 281 282 // The <phinddata> tag introduces the dataset 283 else if (buffer.startsWith("<phinddata ")) { 284 285 } 286 281 287 // The </phinddata> tag concludes the dataset 282 288 else if (buffer.startsWith("</phinddata>")) { … … 291 297 } 292 298 299 300 301 // Add an expansion list tag 302 // 303 // Given a string containing an XML expansinlist tag of the form: 304 // <expansionlist length="5" start="0" end="5"> 305 // <expansionlist length="134" start="0" end="10"> 306 // Read the expansion information from the tag 307 // 308 // Return true if successful, otherwise false. 309 310 boolean addExpansionListTag( String line ) { 311 312 // System.out.println( "addExpansionListTag: " + line); 313 314 String lenStr = ""; 315 int length = 0; 316 317 // Break the tag down into its component parts 318 line = line.substring(15); 319 int nextSplit; 320 while (line.length() > 0) { 321 line = line.trim(); 322 323 // Read the overall length of the list 324 if (line.startsWith("length")) { 325 line = line.substring(8); 326 nextSplit = line.indexOf((int) '"'); 327 if (nextSplit >= 1) { 328 lenStr = line.substring(0, nextSplit); 329 length = Integer.valueOf(lenStr).intValue(); 330 line = line.substring(nextSplit + 1); 331 } else { 332 System.err.println("addExpansionListTag: error parsing: " + line); 333 } 334 } 335 336 // Read and ignore some other tag 337 else { 338 nextSplit = line.indexOf((int) ' '); 339 if (nextSplit >= 1) { 340 line = line.substring(nextSplit + 1); 341 } else { 342 line = ""; 343 } 344 } 345 } 346 347 // Add the length data to the ResultBox 348 numberOfExpansions = length; 349 return true; 350 } 293 351 294 352 … … 398 456 399 457 458 // Add a document list tag 459 // 460 // Given a string containing an XML documentlist tag of the form: 461 // <documentlist length="797" start="0" end="10"> 462 // Read the expansion information from the tag 463 // 464 // Return true if successful, otherwise false. 465 466 boolean addDocumentListTag( String line ) { 467 468 // System.out.println( "addExpansionListTag: " + line); 469 470 String lenStr = ""; 471 int length = 0; 472 473 // Break the tag down into its component parts 474 line = line.substring(13); 475 int nextSplit; 476 while (line.length() > 0) { 477 line = line.trim(); 478 479 // Read the overall length of the list 480 if (line.startsWith("length")) { 481 line = line.substring(8); 482 nextSplit = line.indexOf((int) '"'); 483 if (nextSplit >= 1) { 484 lenStr = line.substring(0, nextSplit); 485 length = Integer.valueOf(lenStr).intValue(); 486 line = line.substring(nextSplit + 1); 487 } else { 488 System.err.println("addExpansionListTag: error parsing: " + line); 489 } 490 } 491 492 // Read and ignore some other tag 493 else { 494 nextSplit = line.indexOf((int) ' '); 495 if (nextSplit >= 1) { 496 line = line.substring(nextSplit + 1); 497 } else { 498 line = ""; 499 } 500 } 501 } 502 503 // Add the length data to the ResultBox 504 numberOfDocuments = length; 505 return true; 506 } 507 400 508 401 509 // Add an document tag … … 411 519 boolean addDocumentTag( String line ) { 412 520 413 System.out.println( "addDocumentTag: " + line + " (" + expansionsRetrieved + ")");521 // System.out.println( "addDocumentTag: " + line + " (" + documentsRetrieved + ")"); 414 522 415 523 String num = "", hash = "", freq = "", title = ""; … … 468 576 } 469 577 } 578 579 // Read some other tag or close the string off 580 else { 581 nextSplit = line.indexOf((int) ' '); 582 if (nextSplit >= 1) { 583 line = line.substring(nextSplit + 1); 584 } else { 585 line = ""; 586 } 587 } 470 588 } 471 589 472 590 // Create a new ResultItem and add it to the display 473 591 ResultItem ri = new ResultItem(hash, title, freq); 474 592 475 593 if (c.addResultItem(ri)) { 476 594 documentsRetrieved++; -
trunk/gsdl/src/phind/client/ResultCanvas.java
r1621 r1626 1 // ResultCanvas.java 2 3 /* 4 5 The results of a query are displayed on a ResultCanvas object. 6 Each line of the result is stored in a Result, and the ResultCanvas 1 /********************************************************************** 2 * 3 * ResultCanvas.java -- a Canvas onto which a phrase list is drawn 4 * 5 * Copyright 1997-2000 Gordon W. Paynter 6 * Copyright 2000 The New Zealand Digital Library Project 7 * 8 * A component of the Greenstone digital library software 9 * from the New Zealand Digital Library Project at the 10 * University of Waikato, New Zealand. 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * 26 *********************************************************************/ 27 28 /********************************************************************* 29 30 This class is used in the Phind java applet (Phind.java). 31 32 The results of a query are displayed on a ResultCanvas object. Each 33 line of the result is stored in a ResultItem, and the ResultCanvas 7 34 contains a Vector of ResultItems. 8 35 9 Each ResultCanvas is embedded in a ResultBox alongside a 10 Scrollbar. When the ResultCanvas is drawn, it looks at the11 scrollbar, calculates which ResultItems are visible, then draws 12 them on the screen. 13 14 */ 36 Each ResultCanvas is embedded in a ResultBox alongside a Scrollbar. 37 When the ResultCanvas is drawn, it looks at the scrollbar, calculates 38 which ResultItems are visible, then draws them on the screen. 39 40 **********************************************************************/ 41 15 42 16 43 import java.awt.Canvas; … … 31 58 public class ResultCanvas extends Canvas { 32 59 33 // Other objects associated with this34 Phind phind;35 ResultBox parent;36 Scrollbar scrollbar;37 38 // fonts and font spacings to use39 Font areaPlain, areaBold;40 int lineSpacing;60 // Other objects associated with this 61 Phind phind; 62 ResultBox parent; 63 Scrollbar scrollbar; 64 65 // fonts and font spacings to use 66 Font areaPlain, areaBold; 67 int lineSpacing; 41 68 42 69 // The phrases to display on this canvas 43 int numberOfPhrases;44 int firstPhraseDisplayed;45 int phraseSelected;46 Vector phrases;70 int numberOfPhrases; 71 int firstPhraseDisplayed; 72 int phraseSelected; 73 Vector phrases; 47 74 48 75 // the background image 49 public static Image backgroundImage;50 51 52 // Create a ResultCanvas from the ResultBox which is its parent.53 ResultCanvas(ResultBox p) {54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 76 public static Image backgroundImage; 77 78 79 // Create a ResultCanvas from the ResultBox which is its parent. 80 ResultCanvas(ResultBox p) { 81 82 parent = p; 83 phind = p.phind; 84 scrollbar = p.s; 85 parent.disableScrollbar(); 86 87 areaPlain = phind.plainFont; 88 areaBold = phind.boldFont; 89 90 lineSpacing = phind.fontSize + 2; 91 92 phrases = new Vector(); 93 numberOfPhrases = 0; 94 firstPhraseDisplayed = 0; 95 phraseSelected = -1; 69 96 70 71 72 73 74 }75 76 void resetCanvas( ) {77 78 79 80 }81 82 83 // add a new item of input.84 // return true if successful, otherwise false.85 boolean addResultItem( ResultItem item ) {97 if (backgroundImage == null) { 98 backgroundImage = p.phind.backgroundImage; 99 } 100 101 } 102 103 void resetCanvas( ) { 104 phrases.removeAllElements(); 105 numberOfPhrases = 0; 106 repaint(); 107 } 108 109 110 // add a new item of input. 111 // return true if successful, otherwise false. 112 boolean addResultItem( ResultItem item ) { 86 113 87 88 89 90 91 92 93 ((item.kind > ((ResultItem) phrases.elementAt(index)).kind) ||94 95 96 97 98 99 100 101 }102 103 104 // Make sure the more Phrases item only appears in the list105 // if it is meant to.106 void updateMorePhrasesMarker() {114 // Add a new result, in sorted order. 115 // First sort key is item kind (lowest first), 116 // second is frequency (highest first). 117 // This is not efficient, but I don't care right now. 118 int index = 0; 119 while ((index < numberOfPhrases) && 120 ((item.kind > ((ResultItem) phrases.elementAt(index)).kind) || 121 ((item.kind == ((ResultItem) phrases.elementAt(index)).kind) && 122 (item.freq <= ((ResultItem) phrases.elementAt(index)).freq)))) { 123 index++; 124 } 125 phrases.insertElementAt(item,index); 126 numberOfPhrases++; 127 return true; 128 } 129 130 131 // Make sure the more Phrases item only appears in the list 132 // if it is meant to. 133 void updateMorePhrasesMarker() { 107 134 108 109 110 111 112 113 114 115 // System.out.println("found marker at: " + index + " of " + numberOfPhrases);116 found = true;117 118 index++;119 120 121 122 123 124 125 126 // System.out.println("Remove marker");127 phrases.removeElementAt(index);128 numberOfPhrases--;129 130 131 132 133 134 135 136 // System.out.println("Add marker");137 ResultItem ri = new ResultItem(ResultItem.morePhrases, parent.searchKey);138 addResultItem(ri);139 140 141 }142 143 144 // Make sure the more documents marker appears when required145 void updateMoreDocumentsMarker() {135 // System.out.println("updateMorePhrasesMarker() "); 136 137 // look for a marker 138 boolean found = false; 139 int index = 0; 140 while (!found && (index < numberOfPhrases)) { 141 if (((ResultItem) phrases.elementAt(index)).isMorePhrases()) { 142 // System.out.println("found marker at: " + index + " of " + numberOfPhrases); 143 found = true; 144 } else { 145 index++; 146 } 147 } 148 149 if (parent.expansionsRetrieved == parent.numberOfExpansions) { 150 // there should be no marker 151 // System.out.println("No marker needed"); 152 if (found) { 153 // System.out.println("Remove marker"); 154 phrases.removeElementAt(index); 155 numberOfPhrases--; 156 } 157 158 } else if (parent.expansionsRetrieved < parent.numberOfExpansions) { 159 // there should be a marker 160 // System.out.println("Needs marker"); 161 162 if (!found) { 163 // System.out.println("Add marker"); 164 ResultItem ri = new ResultItem(ResultItem.morePhrases, parent.searchKey); 165 addResultItem(ri); 166 } 167 } 168 } 169 170 171 // Make sure the more documents marker appears when required 172 void updateMoreDocumentsMarker() { 146 173 147 148 149 150 151 152 153 154 found = true;155 156 index++;157 158 159 160 161 162 163 phrases.removeElementAt(index);164 numberOfPhrases--;165 166 167 168 169 170 ResultItem ri = new ResultItem(ResultItem.moreDocuments, parent.searchKey);171 addResultItem(ri);172 173 174 }174 // System.out.println("updateMoreDocumentsMarker() "); 175 176 // look for a marker 177 boolean found = false; 178 int index = 0; 179 while (!found && (index < numberOfPhrases)) { 180 if (((ResultItem) phrases.elementAt(index)).isMoreDocuments()) { 181 found = true; 182 } else { 183 index++; 184 } 185 } 186 187 if (parent.documentsRetrieved == parent.numberOfDocuments) { 188 // there should be no marker 189 if (found) { 190 phrases.removeElementAt(index); 191 numberOfPhrases--; 192 } 193 194 } else if (parent.documentsRetrieved < parent.numberOfDocuments) { 195 // there should be a marker 196 if (!found) { 197 ResultItem ri = new ResultItem(ResultItem.moreDocuments, parent.searchKey); 198 addResultItem(ri); 199 } 200 } 201 } 175 202 176 203 … … 179 206 180 207 181 public void update(Graphics g) {182 183 }184 185 public void paint(Graphics g) {186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 208 public void update(Graphics g) { 209 paint(g); 210 } 211 212 public void paint(Graphics g) { 213 214 // calculate the canvas size, margins, and spacing 215 Dimension canvasSize = getSize(); 216 217 g.setFont(areaPlain); 218 int space = g.getFontMetrics().stringWidth(" "); 219 int margin = g.getFontMetrics().stringWidth(" 8888 "); 220 221 int leftMargin = 0; 222 int secondColumn = canvasSize.width - margin; 223 int firstColumn = secondColumn - margin; 224 int rightMargin = firstColumn; 225 226 // calculate the number of values that will fit onscreen 227 int visible = canvasSize.height / lineSpacing; 228 229 //System.out.println("h " + canvasSize.height + ", l " 230 // + lineSpacing + ", v " + visible); 231 232 // get the initial scrollbar setting 233 // and calculate the first result to output 234 int scrollValue = scrollbar.getValue(); 235 if (numberOfPhrases <= visible) { 236 scrollValue = 0; 237 } else if (scrollValue > (numberOfPhrases - visible)) { 238 scrollValue = numberOfPhrases - visible; 239 } 240 firstPhraseDisplayed = scrollValue; 241 242 // draw the background 243 if (phind.showImage) { 244 g.drawImage(backgroundImage, 245 leftMargin, 0, rightMargin, canvasSize.height, 246 Color.white, null); 247 } else { 248 g.setColor(Color.white); 249 g.fillRect(0, 0, canvasSize.width, canvasSize.height); 250 } 224 251 225 // First column 226 g.setColor(new Color(235, 245, 235)); 227 g.fillRect(firstColumn, 0, margin, canvasSize.height); 228 229 // Second column 230 g.setColor(new Color(200, 220, 200)); 231 g.fillRect(secondColumn, 0, margin, canvasSize.height); 232 g.setColor(Color.black); 233 234 // if there are no phrases, output a brief explanation. 235 if (numberOfPhrases == 0) { 236 g.drawString("No phrases match this query.", leftMargin + 10, lineSpacing); 237 } 238 239 // Output each of the visible ResultItems 240 int tab, i, y = 0; 241 int center = leftMargin + ((rightMargin - leftMargin - g.getFontMetrics().stringWidth(parent.searchPhrase)) / 2); 242 ResultItem result; 243 244 for (i = scrollValue; (i < numberOfPhrases) && (y + lineSpacing < canvasSize.height); i++) { 245 246 // Get the resultItem to output 247 result = (ResultItem) phrases.elementAt(i); 248 249 // Graphics settings for drawing this line 250 y += lineSpacing; 251 g.setFont(areaPlain); 252 253 // Highlight if the selected phrase. 254 if (i == phraseSelected) { 255 g.setColor(new Color(255, 220, 115)); 256 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing); 252 // First column 253 g.setColor(new Color(235, 245, 235)); 254 g.fillRect(firstColumn, 0, margin, canvasSize.height); 255 256 // Second column 257 g.setColor(new Color(200, 220, 200)); 258 g.fillRect(secondColumn, 0, margin, canvasSize.height); 257 259 g.setColor(Color.black); 258 } 259 260 // Draw the item - it could be phrase or a URL 261 262 // Write the document frequency 263 if ((result.documents > 1) || result.isPhrase()) { 264 g.drawString(" " + Integer.toString(result.documents), firstColumn, y); 265 } 266 267 // Write the term frequency 268 if (result.freq > 0) { 269 g.drawString(" " + Integer.toString(result.freq), secondColumn, y); 270 } 271 272 // Write the expand button 273 //if (result.expansion > 0) { 274 // g.drawString(" +", leftMargin, y); 275 //} 276 277 278 if (result.isPhrase()) { 279 // The item is a Phrase 280 tab = center - g.getFontMetrics().stringWidth(result.prefix) - space; 281 g.drawString(result.prefix, tab, y); 282 g.setFont(areaBold); 283 g.drawString(result.body, center, y); 284 tab = center + space + g.getFontMetrics().stringWidth(result.body); 285 g.setFont(areaPlain); 286 g.drawString(result.suffix, tab, y); 260 261 // if there are no phrases, output a brief explanation. 262 if (numberOfPhrases == 0) { 263 g.drawString("No phrases match this query.", leftMargin + 10, lineSpacing); 264 } 265 266 // Output each of the visible ResultItems 267 int tab, i, y = 0; 268 int center = leftMargin + ((rightMargin - leftMargin - g.getFontMetrics().stringWidth(parent.searchPhrase)) / 2); 269 ResultItem result; 270 271 for (i = scrollValue; (i < numberOfPhrases) && (y + lineSpacing < canvasSize.height); i++) { 272 273 // Get the resultItem to output 274 result = (ResultItem) phrases.elementAt(i); 275 276 // Graphics settings for drawing this line 277 y += lineSpacing; 278 g.setFont(areaPlain); 279 280 // Highlight if the selected phrase. 281 if (i == phraseSelected) { 282 g.setColor(new Color(255, 220, 115)); 283 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing); 284 g.setColor(Color.black); 285 } 286 287 // Draw the item - it could be phrase or a URL 288 289 // Write the document frequency 290 if ((result.documents > 1) || result.isPhrase()) { 291 g.drawString(" " + Integer.toString(result.documents), firstColumn, y); 292 } 293 294 // Write the term frequency 295 if (result.freq > 0) { 296 g.drawString(" " + Integer.toString(result.freq), secondColumn, y); 297 } 298 299 // Write the expand button 300 //if (result.expansion > 0) { 301 // g.drawString(" +", leftMargin, y); 302 //} 303 304 305 if (result.isPhrase()) { 306 // The item is a Phrase 307 tab = center - g.getFontMetrics().stringWidth(result.prefix) - space; 308 g.drawString(result.prefix, tab, y); 309 g.setFont(areaBold); 310 g.drawString(result.body, center, y); 311 tab = center + space + g.getFontMetrics().stringWidth(result.body); 312 g.setFont(areaPlain); 313 g.drawString(result.suffix, tab, y); 287 314 288 289 // The item is a URL290 g.setFont(areaPlain);291 g.setColor(Color.blue);292 tab = (rightMargin - g.getFontMetrics().stringWidth(result.suffix)) / 2;293 g.drawString(result.suffix, tab, y);294 g.setColor(Color.black);315 } else if (result.isDocument()){ 316 // The item is a URL 317 g.setFont(areaPlain); 318 g.setColor(Color.blue); 319 tab = (rightMargin - g.getFontMetrics().stringWidth(result.body)) / 2; 320 g.drawString(result.body, tab, y); 321 g.setColor(Color.black); 295 322 296 297 // The item is a More documents marker298 g.setColor(new Color(255, 200, 200));299 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);300 g.setColor(Color.black);301 302 g.setFont(areaPlain);303 tab = (rightMargin - g.getFontMetrics().stringWidth("Get more phrases")) / 2;304 g.drawString("Get more phrases", tab, y);305 306 307 // The item is a More documents marker308 g.setColor(new Color(150, 193, 156));309 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);310 g.setColor(Color.black);311 312 g.setFont(areaPlain);313 tab = (rightMargin - g.getFontMetrics().stringWidth("Get more documents")) / 2;314 g.drawString("Get more documents", tab, y);315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 }333 334 335 // Handle user input336 public boolean handleEvent(Event event) {323 } else if (result.isMorePhrases()){ 324 // The item is a More documents marker 325 g.setColor(new Color(255, 200, 200)); 326 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing); 327 g.setColor(Color.black); 328 329 g.setFont(areaPlain); 330 tab = (rightMargin - g.getFontMetrics().stringWidth("Get more phrases")) / 2; 331 g.drawString("Get more phrases", tab, y); 332 333 } else if (result.isMoreDocuments()){ 334 // The item is a More documents marker 335 g.setColor(new Color(150, 193, 156)); 336 g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing); 337 g.setColor(Color.black); 338 339 g.setFont(areaPlain); 340 tab = (rightMargin - g.getFontMetrics().stringWidth("Get more documents")) / 2; 341 g.drawString("Get more documents", tab, y); 342 343 } 344 345 } 346 347 // adjust the scrollbar 348 if (visible >= numberOfPhrases) { 349 parent.disableScrollbar(); 350 } else { 351 //System.out.println("s " + scrollValue + ", v " + visible 352 // + ", m " + (numberOfPhrases)); 353 scrollbar.setValues(scrollValue, visible, 0, numberOfPhrases); 354 scrollbar.setBlockIncrement(visible - 1); 355 scrollbar.setEnabled(true); 356 } 357 358 g.drawRect(0,0, canvasSize.width - 1, canvasSize.height - 1); 359 } 360 361 362 // Handle user input 363 public boolean handleEvent(Event event) { 337 364 338 if (event.id == Event.MOUSE_UP) { 339 340 // ignore actions that occur within 1 second of the last 341 Date now = new Date(); 342 // System.out.println("Click time: " + now.toString()); 343 if (now.getTime() < (phind.lastQueryEndTime.getTime() + 1000)) { 344 System.out.println("Ignoring click - too close to last query."); 365 if (event.id == Event.MOUSE_UP) { 366 367 // ignore actions that occur within 1 second of the last 368 Date now = new Date(); 369 // System.out.println("Click time: " + now.toString()); 370 if (now.getTime() < (phind.lastQueryEndTime.getTime() + 1000)) { 371 System.out.println("Ignoring click - too close to last query."); 372 return true; 373 } 374 375 // which Item is selected? 376 int rowSelected = event.y / lineSpacing; 377 int itemSelected = rowSelected + firstPhraseDisplayed; 378 ResultItem item = (ResultItem) phrases.elementAt(itemSelected); 379 380 // System.out.println("Select: " + String.valueOf(rowSelected) ); 381 if (itemSelected <= numberOfPhrases) { 382 383 // What do we do with the event? 384 // If user clicks on a phrase, we expand the phrase 385 // or send the phrase to a search engine (right click) 386 387 if (item.isPhrase()) { 388 // Expand the phrase 389 390 phraseSelected = itemSelected; 391 update(getGraphics()); 392 393 parent.lookupPhrase(item.rule, item.toString(), 2); 394 395 if (event.metaDown()) { 396 // Also send to search engine 397 if (phind.search_url.equals("none") || phind.search_url.equals("")) { 398 System.out.println("No searching in this collection"); 399 } else { 400 URL url; 401 try { 402 url = new URL(phind.search_url + "%22" + item.toString() + "%22&"); 403 phind.getAppletContext().showDocument(url, "phindsearch"); 404 System.out.println("The query is: " + url.toString()); 405 } catch (Exception e) { 406 System.out.println("URL error: " + e.toString()); 407 } 408 } 409 } 410 411 } else if (item.isDocument()) { 412 // The user clicks on a URL; display it. 413 phraseSelected = itemSelected; 414 update(getGraphics()); 415 416 URL url; 417 try { 418 String address = phind.library_address 419 + "?a=d&c=" + phind.collection 420 + "&d=" + item.rule; 421 url = new URL(address); 422 System.out.println("URL selected: " + url.toString()); 423 phind.getAppletContext().showDocument(url, "phindselect"); 424 } catch (Exception e) { 425 System.out.println("URL error: " + e.toString()); 426 } 427 428 } else if (item.isMorePhrases()){ 429 // The user clicks on a "get more phrases" marker. 430 // We have to send a new query to the host 431 parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 3); 432 433 } else if (item.isMoreDocuments()){ 434 parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 4); 435 436 437 } 438 repaint(); 439 } 440 } 345 441 return true; 346 } 347 348 // which Item is selected? 349 int rowSelected = event.y / lineSpacing; 350 int itemSelected = rowSelected + firstPhraseDisplayed; 351 ResultItem item = (ResultItem) phrases.elementAt(itemSelected); 352 353 // System.out.println("Select: " + String.valueOf(rowSelected) ); 354 if (itemSelected <= numberOfPhrases) { 355 356 // What do we do with the event? 357 // If user clicks on a phrase, we expand the phrase 358 // or send the phrase to a search engine (right click) 359 360 if (item.isPhrase()) { 361 // Expand the phrase 362 363 phraseSelected = itemSelected; 364 update(getGraphics()); 365 366 parent.lookupPhrase(item.rule, item.toString(), 2); 367 368 if (event.metaDown()) { 369 // Also send to search engine 370 if (phind.search_url.equals("none") || phind.search_url.equals("")) { 371 System.out.println("No searching in this collection"); 372 } else { 373 URL url; 374 try { 375 url = new URL(phind.search_url + "%22" + item.toString() + "%22&"); 376 phind.getAppletContext().showDocument(url, "phindsearch"); 377 System.out.println("The query is: " + url.toString()); 378 } catch (Exception e) { 379 System.out.println("URL error: " + e.toString()); 380 } 381 } 382 } 383 384 } else if (item.isDocument()) { 385 // The user clicks on a URL; display it. 386 phraseSelected = itemSelected; 387 update(getGraphics()); 388 389 URL url; 390 try { 391 url = new URL(item.body); 392 // System.out.println("URL selected: " + url.toString()); 393 phind.getAppletContext().showDocument(url, "phindselect"); 394 } catch (Exception e) { 395 System.out.println("URL error: " + e.toString()); 396 } 397 398 } else if (item.isMorePhrases()){ 399 // The user clicks on a "get more phrases" marker. 400 // We have to send a new query to the host 401 parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 3); 402 403 } else if (item.isMoreDocuments()){ 404 parent.lookupPhrase(parent.searchKey, parent.searchPhrase, 4); 405 406 407 } 408 repaint(); 409 } 410 } 411 return true; 412 } 442 } 413 443 414 444 } -
trunk/gsdl/src/phind/client/ResultItem.java
r1625 r1626 40 40 41 41 // There are four kinds of item 42 // 1. a phrase 43 // 2. a document (or URL) 44 // 3. a "get more phrases" marker 45 // 4. a "get more documents" marker 42 // 1. a phrase 43 // 2. a document (or URL) 44 // 3. a "get more phrases" marker 45 // 4. a "get more documents" marker 46 // These should possibly be written as subclasses of a ResultItem 47 // superclass, but I cannot be bothered rewriting it for now. 46 48 47 49 final static int phraseItem = 1; … … 53 55 int kind; 54 56 55 // The symbol of this item as a string (rule) and integer 57 // The "rule" is the unique identifier of this item. For a phrase, 58 // this is its "phrase number", and is also stored as a number in 59 // symbol. For a document it is the document's OID (hash) value. 56 60 String rule; 57 61 int symbol; … … 66 70 int expansion; 67 71 68 // The text of the item, split into a prefix, body, and suffix.69 // For phrases, the body is the search term and the prefix and suffix70 // the surrounding text in the new phrase.71 // For URLs the prefix and suffix are ignored.72 // When the item is a phrase, the text of the item is split into a 73 // prefix, body, and suffix. The body is the search term and the 74 // prefix and suffix the surrounding text in the new phrase. 75 // When the item is a document, its title is stored in the body. 72 76 String prefix; 73 77 String body; … … 79 83 String p, String b, String s) { 80 84 81 System.out.println("ResultItem (phrase): " + r + " (" + f + ", " + d + ")");82 83 85 kind = phraseItem; 84 86 rule = r; … … 92 94 body = b; 93 95 suffix = s; 96 94 97 } 95 98 … … 98 101 ResultItem(String hash, String title, String df) { 99 102 100 System.out.println("ResultItem (document): " + hash + " (" + df + ")");101 102 103 kind = documentItem; 103 104 rule = hash; -
trunk/gsdl/src/phind/client/ResultTitle.java
r1621 r1626 1 // ResultTitle.java 1 /********************************************************************** 2 * 3 * ResultTitle.java -- describe the contents of a ResultBox 4 * 5 * Copyright 1997-2000 Gordon W. Paynter 6 * Copyright 2000 The New Zealand Digital Library Project 7 * 8 * A component of the Greenstone digital library software 9 * from the New Zealand Digital Library Project at the 10 * University of Waikato, New Zealand. 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * 26 *********************************************************************/ 2 27 3 /* 28 /********************************************************************* 4 29 5 What is being displayed in theis ResultBox? 30 This class is used in the Phind java applet (Phind.java). 6 31 7 Each ResultTitle is part of a ResultBox and 8 describes what is in that ResultBox. 32 ResultTitle is part of the result list displayed to the user. It lists the 33 phrase in the Result box, the number of expansions it occurs in, and the 34 number of documents it occurs in. 9 35 10 */ 36 **********************************************************************/ 37 11 38 12 39 import java.awt.Canvas; … … 28 55 Font plain, bold; 29 56 Graphics g; 30 31 57 32 58 // Create a ResultTitle from the ResultBox which is its parent. … … 101 127 102 128 g.setFont(plain); 103 String status = ""; 104 if (parent.prev == null) { 105 status = "(" + expansions + ")"; 106 } else { 107 status = "(" + expansions + ", " + documents + ")"; 108 } 129 String status = "(" + expansions + ", " + documents + ")"; 109 130 g.drawString(status, tab, y); 110 131 tab = tab + g.getFontMetrics().stringWidth(status);
Note:
See TracChangeset
for help on using the changeset viewer.