Changeset 1627
- Timestamp:
- 2000-10-30T15:10:28+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
r1626 r1627 55 55 words on the screen, and handles user input from the mouse. 56 56 6. ResultItem represents a single result object (a phrase or document). 57 58 7. PhindTitle is for drawing backdrops in empty Displays. (?) 57 7. PhindTitle is for drawing backdrops in ResultDisplays. 59 58 60 59 **********************************************************************/ … … 104 103 105 104 // Do we want a background image in the applet? 105 String backdrop_address; 106 106 public boolean showImage; 107 107 public Image backgroundImage; … … 109 109 // Holders for the downloaded data 110 110 Panel resultPanel; 111 PhindTitle title;112 111 ResultDisplay firstDisplay, lastDisplay; 113 112 … … 198 197 System.out.println("Phind library: " + library_address); 199 198 199 // Should we display a background image? 200 showImage = false; 201 try { 202 backdrop_address = new String(getParameter("backdrop")); 203 URL backdrop_url = new URL(backdrop_address); 204 backgroundImage = getImage(backdrop_url); 205 showImage = true; 206 System.out.println("Phind backdrop: " + backdrop_address); 207 } catch (Exception e) { 208 System.out.println("Phind backdrop not set"); 209 } 210 200 211 // Is there a search URL for this collection? 201 212 try { … … 238 249 System.out.println("Phind phrase block size: " + phraseBlockSize); 239 250 240 // Should we display a background image?241 showImage = false;242 try {243 if (getParameter("background").toLowerCase().equals("on")) {244 showImage = true;245 System.out.println("Phind background: on");246 }247 } catch (Exception e) {248 System.out.println("Phind background: off");249 }250 251 252 251 // How large should the font be? 253 252 try { … … 271 270 // The phind applet layout manager 272 271 setLayout(new BorderLayout()); 273 274 // the Phind title window275 if (showImage) backgroundImage = getImage(getCodeBase(), "sequitur.jpg");276 title = new PhindTitle(this, true);277 272 278 273 // initialise the user interface … … 495 490 throws IOException { 496 491 497 // Set up connections (streams)498 //connection = new Socket(server, Integer.parseInt(port));499 //OutputStream out = connection.getOutputStream();500 //InputStream in = connection.getInputStream();501 502 492 // Build the query 503 493 String query = phindcgi_address + "?x=1&c=" + collection; 504 494 505 495 if (keyKnown) { 506 496 query = query + "&n=" + word; 507 497 } else { 508 query = query + "&p=" + word; 509 } 510 511 // Specify the number of results to return and the first and last results. 498 query = query + "&p=" + word; 499 } 500 501 502 // Specify the set of results to return 503 int first_e = 0; 504 int last_e = 0; 505 int first_d = 0; 506 int last_d = 0; 507 508 // the initial query 512 509 if (queryMode <= 2) { 513 query = query + "&f=0&d=" + phraseBlockSize + "&g=0&e=" + phraseBlockSize; 514 } else if (queryMode == 3) { 515 // Add phrases to an existing result set. 516 query = query + "&f=0&d=" + phraseBlockSize + "&g=0&e=" + phraseBlockSize; 517 // query = (word + " " + queryMode + " " + phraseBlockSize + " " + area.nextPhraseBlock); 518 area.nextPhraseBlock++; 519 } else if (queryMode == 4) { 520 // Add documents to existing result set. 521 query = query + "&f=0&d=" + phraseBlockSize + "&g=0&e=" + phraseBlockSize; 522 // query = (word + " " + queryMode + " " + phraseBlockSize + " " + area.nextDocumentBlock); 523 area.nextDocumentBlock++; 524 } 525 510 last_e = phraseBlockSize; 511 last_d = phraseBlockSize; 512 } 513 514 // add phrases to an existing result set 515 else if (queryMode == 3) { 516 first_e = area.nextPhraseBlock * phraseBlockSize; 517 area.nextPhraseBlock++; 518 last_e = area.nextPhraseBlock * phraseBlockSize; 519 } 520 521 // add documents to existing result set 522 else if (queryMode == 4) { 523 first_d = area.nextDocumentBlock * phraseBlockSize; 524 area.nextDocumentBlock++; 525 last_d = area.nextDocumentBlock * phraseBlockSize; 526 } 527 528 query = query + "&f=" + first_d + "&d=" + last_d 529 + "&g=" + first_e + "&e=" + last_e; 526 530 527 531 // Send the query to the phindcgi program -
trunk/gsdl/src/phind/client/PhindTitle.java
r1621 r1627 1 /********************************************************************** 2 * 3 * PhindTitle.java -- backdrops to empty ResultDisplay panels. 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 31 PhindTitle is for drawing backdrops in empty ResultDisplay panels. 32 33 **********************************************************************/ 34 1 35 import java.applet.Applet; 2 36 import java.awt.Canvas; 3 37 import java.awt.Color; 4 38 import java.awt.Dimension; 5 import java.awt.Font;6 39 import java.awt.Graphics; 7 40 import java.awt.Image; … … 9 42 public class PhindTitle extends Canvas { 10 43 11 Phind phind; 12 static Image backgroundImage; 13 boolean displayInfo; 14 15 PhindTitle(Phind p, boolean disp) { 16 backgroundImage = p.backgroundImage; 17 displayInfo = disp; 18 phind = p; 19 } 20 21 public void update(Graphics g) { 22 paint(g); 23 } 24 25 public void paint(Graphics g) { 26 Dimension canvasSize = size(); 27 28 // set the screen background 29 if (phind.showImage) 30 g.drawImage(backgroundImage, 0, 0, canvasSize.width, canvasSize.height, Color.white, null); 31 else { 32 g.setColor(Color.white); 33 g.fillRect(0,0, canvasSize.width, canvasSize.height); 34 g.setColor(Color.black); 44 Phind phind; 45 static Image backgroundImage; 46 boolean displayInfo; 47 48 PhindTitle(Phind p) { 49 phind = p; 35 50 } 36 51 37 // display the title information 38 if (displayInfo) { 39 String title = "Phind 2.0"; 40 String author = "by Craig Nevill-Manning, Ian H. Witten, and Gordon Paynter"; 41 String contact = "[email protected], {ihw.gwp}@cs.waikato.ac.nz"; 42 String ref1 = "see \"Browsing in Digital Libraries: A Phrase-based Approach\""; 43 String ref2 = "by Nevill-Manning and friends in DL'97 for details."; 44 45 g.setColor(Color.black); 46 int center = canvasSize.width / 2; 47 int y = 20; 48 49 g.setFont(phind.boldFont); 50 paintLine(g, title, y, center); 51 y += (phind.fontSize + 10); 52 g.setFont(phind.plainFont); 53 paintLine(g, author, y, center); 54 y += (phind.fontSize + 5); 55 paintLine(g, contact, y, center); 56 y += (phind.fontSize + 10); 57 paintLine(g, ref1, y, center); 58 y += (phind.fontSize + 5); 59 paintLine(g, ref2, y, center); 52 public void update(Graphics g) { 53 paint(g); 60 54 } 55 56 public void paint(Graphics g) { 57 Dimension canvasSize = size(); 58 59 // set the screen background 60 if (phind.showImage) 61 try { 62 g.drawImage(phind.backgroundImage, 63 0, 0, canvasSize.width, canvasSize.height, Color.white, null); 64 } catch (Exception e) { 65 System.err.println("PhindTitle paint: " + e); 66 } 67 else { 68 g.setColor(Color.white); 69 g.fillRect(0,0, canvasSize.width, canvasSize.height); 70 g.setColor(Color.black); 71 } 61 72 } 62 63 void paintLine(Graphics g, String s, int y, int center) {64 int x = center - (g.getFontMetrics().stringWidth(s) / 2);65 g.drawString(s, x, y);66 }67 68 73 } 69 74 70 75 76 77 78 79 80 -
trunk/gsdl/src/phind/client/ResultBox.java
r1626 r1627 67 67 Panel label; 68 68 69 // Information about the query 69 // The key identifying the phrase displayed, with its text and the 70 // collection from which it is drawn 70 71 String searchKey, searchPhrase; 71 72 String searchCollection; 72 73 73 // Information about the result set 74 // The total frequency, expansion frequency, and document frequency 75 // of the phrase 76 int numberOfOccurances; 74 77 int numberOfExpansions; 75 int expansionsRetrieved;76 78 int numberOfDocuments; 77 int documentsRetrieved; 79 80 // The number of phrases and documents retrieved, and the number of 81 // times the user has requested more phrases or documents. 82 int documentsRetrieved; 83 int expansionsRetrieved; 78 84 int nextPhraseBlock; 79 85 int nextDocumentBlock; … … 103 109 if (prev != null) prev.next = this; 104 110 111 searchKey = key; 112 searchPhrase = phrase; 113 searchCollection = collect; 114 115 numberOfOccurances = -1; 105 116 numberOfExpansions = -1; 117 numberOfDocuments = -1; 118 106 119 expansionsRetrieved = 0; 107 numberOfDocuments = -1;108 120 documentsRetrieved = 0; 109 121 nextPhraseBlock = 1; 110 122 nextDocumentBlock = 1; 111 123 112 searchKey = key;113 searchPhrase = phrase;114 searchCollection = collect;115 124 116 125 setLayout(new BorderLayout()); 117 118 126 119 127 s = new Scrollbar(Scrollbar.VERTICAL); … … 176 184 } 177 185 178 186 187 // Look up a phrase 188 // Phrase lookups are passed on to the Phind applet itself. 179 189 void lookupPhrase(String key, String phrase, int queryMode) { 180 190 buffer = ""; … … 264 274 } 265 275 266 // The < expansionlist> tag267 else if (buffer.startsWith("< expansionlist")) {276 // The <phinddata> tag introduces the dataset 277 else if (buffer.startsWith("<phinddata ")) { 268 278 item = buffer.substring(0, eol); 269 279 buffer = buffer.substring(eol + 1); 270 add ExpansionListTag(item);280 addPhinddataTag(item); 271 281 return true; 272 }273 274 // The <documentlist> tag275 else if (buffer.startsWith("<documentlist ")) {276 item = buffer.substring(0, eol);277 buffer = buffer.substring(eol + 1);278 addDocumentListTag(item);279 return true;280 }281 282 // The <phinddata> tag introduces the dataset283 else if (buffer.startsWith("<phinddata ")) {284 285 282 } 286 283 … … 291 288 } 292 289 290 // The <expansionlist> tag 291 else if (buffer.startsWith("<expansionlist ")) { 292 293 } 294 295 // The <documentlist> tag 296 else if (buffer.startsWith("<documentlist ")) { 297 298 } 299 293 300 // Ignore the piece we've read 294 301 item = buffer.substring(0, eol); … … 299 306 300 307 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"> 308 // Add a phinddata tag 309 // 310 // Given a string containing an XML phinddata tag of the form: 311 // <phinddata id="35" text="FOREST" df="797" ef="134"> 306 312 // Read the expansion information from the tag 307 313 // 308 314 // Return true if successful, otherwise false. 309 315 310 boolean add ExpansionListTag( String line ) {316 boolean addPhinddataTag( String line ) { 311 317 312 318 // System.out.println( "addExpansionListTag: " + line); 313 319 314 String lenStr = "";315 int length= 0;320 String idStr = "", tfStr = "", efStr = "", dfStr = ""; 321 int tf = 0, ef = 0, df = 0; 316 322 317 323 // Break the tag down into its component parts 318 line = line.substring(15);319 324 int nextSplit; 320 325 while (line.length() > 0) { 321 326 line = line.trim(); 322 327 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(); 328 // Read the phrase identifier 329 if (line.startsWith("id")) { 330 line = line.substring(4); 331 nextSplit = line.indexOf((int) '"'); 332 if (nextSplit >= 1) { 333 idStr = line.substring(0, nextSplit); 334 line = line.substring(nextSplit + 1); 335 } else { 336 System.err.println("addExpansionListTag: error parsing: " + line); 337 } 338 } 339 340 // Read the total frequency 341 else if (line.startsWith("tf")) { 342 line = line.substring(4); 343 nextSplit = line.indexOf((int) '"'); 344 if (nextSplit >= 1) { 345 tfStr = line.substring(0, nextSplit); 346 tf = Integer.valueOf(tfStr).intValue(); 347 line = line.substring(nextSplit + 1); 348 } else { 349 System.err.println("addExpansionListTag: error parsing: " + line); 350 } 351 } 352 353 // Read the expansion frequency 354 else if (line.startsWith("ef")) { 355 line = line.substring(4); 356 nextSplit = line.indexOf((int) '"'); 357 if (nextSplit >= 1) { 358 efStr = line.substring(0, nextSplit); 359 ef = Integer.valueOf(efStr).intValue(); 360 line = line.substring(nextSplit + 1); 361 } else { 362 System.err.println("addExpansionListTag: error parsing: " + line); 363 } 364 } 365 366 // Read the document frequency 367 else if (line.startsWith("df")) { 368 line = line.substring(4); 369 nextSplit = line.indexOf((int) '"'); 370 if (nextSplit >= 1) { 371 dfStr = line.substring(0, nextSplit); 372 df = Integer.valueOf(dfStr).intValue(); 330 373 line = line.substring(nextSplit + 1); 331 374 } else { … … 345 388 } 346 389 347 // Add the length data to the ResultBox 348 numberOfExpansions = length; 390 // Add the data to the ResultBox 391 searchKey = idStr; 392 numberOfOccurances = tf; 393 numberOfExpansions = ef; 394 numberOfDocuments = df; 349 395 return true; 350 396 } … … 455 501 456 502 457 458 // Add a document list tag459 //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 tag463 //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 parts474 line = line.substring(13);475 int nextSplit;476 while (line.length() > 0) {477 line = line.trim();478 479 // Read the overall length of the list480 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 tag493 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 ResultBox504 numberOfDocuments = length;505 return true;506 }507 508 509 503 // Add an document tag 510 504 // 511 505 // Given a string containing an XML document tag of the form: 512 // <document num="2" hash="HASH424e64b811fdad933be69c" freq="1" title="CONTEN S"/>506 // <document num="2" hash="HASH424e64b811fdad933be69c" freq="1" title="CONTENTS"/> 513 507 // <document num="3" hash="HASH01f08efd8752ad54ca0a99cf" freq="1" title="Tree mixtures"/> 514 508 // -
trunk/gsdl/src/phind/client/ResultCanvas.java
r1626 r1627 242 242 // draw the background 243 243 if (phind.showImage) { 244 g.drawImage(backgroundImage, 245 leftMargin, 0, rightMargin, canvasSize.height, 246 Color.white, null); 244 try { 245 g.drawImage(backgroundImage, 246 leftMargin, 0, rightMargin, canvasSize.height, 247 Color.white, null); 248 } catch (Exception e) { 249 phind.showImage = false; 250 System.err.println("ResultCanvas paint error: " + e); 251 g.setColor(Color.white); 252 g.fillRect(0, 0, canvasSize.width, canvasSize.height); 253 } 247 254 } else { 248 255 g.setColor(Color.white); … … 296 303 g.drawString(" " + Integer.toString(result.freq), secondColumn, y); 297 304 } 298 299 // Write the expand button300 //if (result.expansion > 0) {301 // g.drawString(" +", leftMargin, y);302 //}303 304 305 305 306 if (result.isPhrase()) { … … 360 361 361 362 362 // Handle user input 363 // User interaction 364 // 365 // All interaction with the ResultCanvas is therough mouse clicks, and 366 // is handles in this method. Note we ignore clicks that follow 367 // another too closely to avoid problems with slow connections. 363 368 public boolean handleEvent(Event event) { 364 369 -
trunk/gsdl/src/phind/client/ResultDisplay.java
r1621 r1627 1 /* ResultDisplay 1 /********************************************************************** 2 * 3 * ResultDisplay.java -- Phrase list holder for Phind java applet 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 A ResultDisplay is a Panel that can display a single Component. 4 ResultBoxes can be "chained" together with their "prev" and "next" 5 fields. 28 /********************************************************************* 29 30 This class is used in the Phind java applet (Phind.java). 31 32 A ResultDisplay is a Panel that can display a single Component, which will 33 be a ResultBox or PhindTitle object. 34 35 ResultBoxes can be "chained" together with their "prev" and "next" fields, 36 allowing us to have an arbitrary number of "displays" in which to show 37 phrase lists. 6 38 7 39 Main methods: 8 9 40 * emptyContents will remove the component and emptyAll the "next" display 10 41 * display will add an item to the first (ie: most "prev") available box 11 42 43 **********************************************************************/ 12 44 13 */14 45 15 46 import java.awt.Panel; … … 33 64 34 65 empty = true; 35 current = new PhindTitle(ph ,false);66 current = new PhindTitle(ph); 36 67 add(current); 37 68 } … … 42 73 if (empty == false) { 43 74 empty = true; 44 current = new PhindTitle(phind ,false);75 current = new PhindTitle(phind); 45 76 removeAll(); 46 77 add(current);
Note:
See TracChangeset
for help on using the changeset viewer.