Changeset 1831
- Timestamp:
- 2001-01-11T16:17:07+13:00 (23 years ago)
- Location:
- trunk/gsdl/src/phind/client
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/phind/client/Phind.java
r1830 r1831 32 32 33 33 <APPLET CODE="Phind.class" WIDTH=500 HEIGHT=500> 34 34 35 <PARAM NAME=phindcgi VALUE="http://kowhai/cgi-bin/phindcgi"> 35 36 <PARAM NAME=library VALUE="http://kowhai/cgi-bin/library"> 37 36 38 <PARAM NAME=backdrop VALUE="http://kowhai/~paynter/transfer/phindtest/green1.jpg"> 39 37 40 <PARAM NAME=collection VALUE="fao.org"> 41 38 42 <PARAM NAME=orientation VALUE="vertical"> 39 43 <PARAM NAME=depth VALUE="2"> 44 <PARAM NAME=blocksize VALUE="10"> 45 40 46 <PARAM NAME=fontsize VALUE="12"> 41 <PARAM NAME=blocksize VALUE="10">42 47 The Phind java applet. 43 48 </APPLET> … … 96 101 public class Phind extends java.applet.Applet { 97 102 98 // elements of the page 99 Label titleLabel; 100 TextField wordField; 101 Button searchButton, prevButton, nextButton; 103 // What is the collection called? 104 public String collection; 105 106 // Internet address of phind resources 107 public String library_address, phindcgi_address; 108 109 // Number of phrases to retrieve at any one time 110 public int phraseBlockSize; 102 111 103 112 // Appearance parameters … … 108 117 109 118 // Do we want a background image in the applet? 110 String backdrop_address;111 119 public boolean showImage; 120 public String backdrop_address; 112 121 public Image backgroundImage; 113 114 // Holders for the downloaded data115 Panel resultPanel;116 ResultDisplay firstDisplay, lastDisplay;117 122 118 123 // the mode of operation … … 122 127 final int searchMode = 2; 123 128 124 // what to search for 125 String collection; 126 int phraseBlockSize; 127 128 //int stopwordLevel = 1; 129 //int lowFrequencyCutoff = 0; 130 //int stemming = 0; 131 132 // where to search 133 Socket connection; 134 String library_address, phindcgi_address; 135 URL library, phindcgi; 136 137 String search_url; 138 139 // browser details 140 String localHost; 129 // elements of the page 130 Label titleLabel; 131 TextField wordField; 132 Button searchButton, prevButton, nextButton; 133 134 // Holders for the downloaded data 135 Panel resultPanel; 136 ResultDisplay firstDisplay, lastDisplay; 141 137 142 138 // The time at which the last query finished … … 166 162 167 163 public String getAppletInfo() { 168 return "Phind by Gordon Paynter ([email protected]). Copyright 1997-2000."; 169 } 164 return "Phind by Gordon Paynter ([email protected]). Copyright 1997-2000."; 165 } 166 170 167 171 168 public void init() { 172 169 173 // default search variable values174 170 mode = initMode; 171 172 // Default applet parameters 173 collection = ""; 174 phindcgi_address = ""; 175 library_address = ""; 176 177 showImage = false; 178 backdrop_address = ""; 179 180 vertical = true; 181 depth = 3; 182 183 phraseBlockSize = 10; 184 fontSize = 12; 185 186 // Read applet parameters 187 getParameters(); 188 189 190 // Initialise the user interface 191 setBackground(Color.white); 175 192 lastQueryEndTime = new Date(); 193 194 // fonts used to output text 195 plainFont = new Font("Helvetica", Font.PLAIN, fontSize); 196 boldFont = new Font("Helvetica", Font.BOLD, fontSize); 197 198 // The phind applet layout manager 199 setLayout(new BorderLayout()); 200 201 // the Panel containing the displays is in the center of the display 202 resultPanel = new Panel(); 203 if (vertical) { 204 resultPanel.setLayout(new GridLayout(depth,1,0,2)); 205 } else { 206 System.out.println("horizontal"); 207 resultPanel.setLayout(new GridLayout(1,depth,2,0)); 208 } 209 add("Center", resultPanel); 210 211 // Create ResultDisplays and place in the interface 212 ResultDisplay d1, d2 = null; 213 firstDisplay = new ResultDisplay(this, null); 214 resultPanel.add(firstDisplay); 215 216 d1 = firstDisplay; 217 for (int i = 2; i <= depth; i++) { 218 d2 = new ResultDisplay(this, d1); 219 resultPanel.add(d2); 220 d1 = d2; 221 } 222 lastDisplay = d2; 223 224 225 // The "control panel" 226 Panel p1 = new Panel(); 227 add("North", p1); 228 p1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); 229 230 searchButton = new Button("Search"); 231 searchButton.setFont(boldFont); 232 p1.add(searchButton); 233 234 Label tempLabel = new Label(" for"); 235 tempLabel.setFont(boldFont); 236 p1.add(tempLabel); 237 238 wordField = new TextField(12); 239 wordField.setFont(boldFont); 240 p1.add(wordField); 241 242 Label temp2 = new Label(" "); 243 p1.add(temp2); 244 245 prevButton = new Button("Previous"); 246 prevButton.setFont(boldFont); 247 prevButton.disable(); 248 p1.add(prevButton); 249 250 nextButton = new Button(" Next "); 251 nextButton.setFont(boldFont); 252 nextButton.disable(); 253 p1.add(nextButton); 254 255 // lets get started then 256 setStatus("Welcome to Phind."); 257 mode = idleMode; 258 } 259 260 261 // Get the applet parameters 262 void getParameters() { 263 176 264 177 265 // What is this collection called? 178 266 try { 179 267 collection = new String(getParameter("collection")); 180 } catch (Exception e) { 181 System.err.println("Phind: You must specify a collection."); 268 System.out.println("Phind collection: " + collection); 269 } catch (Exception e) { 270 System.err.println("Phind could not read collection name: " + e.toString()); 182 271 stop(); 183 } 184 System.out.println("Phind collection: " + collection); 272 } 185 273 186 274 // Where do we get the phind data 187 275 try { 188 276 phindcgi_address = new String(getParameter("phindcgi")); 277 phindcgi_address = tidy_URL(phindcgi_address, true); 278 System.out.println("Phind phindcgi: " + phindcgi_address); 189 279 } catch (Exception e) { 190 System.err.println("Phind : You must specify a URL for phindcgi.");280 System.err.println("Phind could not process phindcgi URL: " + e.toString()); 191 281 stop(); 192 282 } 193 phindcgi_address = tidy_URL(phindcgi_address, true);194 System.out.println("Phind phindcgi: " + phindcgi_address);195 283 196 284 // Where is the collection served from 197 285 try { 198 286 library_address = new String(getParameter("library")); 287 library_address = tidy_URL(library_address, true); 288 System.out.println("Phind library: " + library_address); 199 289 } catch (Exception e) { 200 System.err.println("Phind: You must specify a URL for library."); 201 stop(); 202 } 203 library_address = tidy_URL(library_address, true); 204 System.out.println("Phind library: " + library_address); 290 System.err.println("Phind library: not specified"); 291 library_address = ""; 292 } 205 293 206 294 // Should we display a background image? 207 showImage = false; 208 try { 295 try { 209 296 backdrop_address = new String(getParameter("backdrop")); 210 297 backdrop_address = tidy_URL(backdrop_address, false); … … 214 301 System.out.println("Phind backdrop: " + backdrop_address); 215 302 } catch (Exception e) { 216 System.out.println("Phind backdrop not set"); 217 } 218 219 // Is there a search URL for this collection? 220 try { 221 search_url = new String(getParameter("search_url")); 222 System.out.println("Phind search URL: " + search_url); 223 } catch (Exception e) { 224 System.out.println("Phind search_url not set."); 303 System.out.println("Phind backdrop not set: " + e.toString()); 225 304 } 226 305 227 306 // Are the windows arranged vertically or horizontally 228 vertical = true;229 307 try { 230 308 if (getParameter("orientation").toLowerCase().startsWith("h")) { … … 237 315 238 316 // How many phind windows are there? 239 Integer temp;240 317 try { 241 temp = Integer.valueOf(getParameter("depth")); 242 depth = temp.intValue(); 243 } catch (Exception e) { 244 temp = null; 318 depth = Integer.valueOf(getParameter("depth")).intValue(); 319 } catch (Exception e) { 245 320 depth = 3; 246 321 } … … 249 324 // How many phrases should we fetch at any given time? 250 325 try { 251 temp = Integer.valueOf(getParameter("blocksize")); 252 phraseBlockSize = temp.intValue(); 326 phraseBlockSize = Integer.valueOf(getParameter("blocksize")).intValue(); 253 327 } catch (Exception e) { 254 temp = null;255 328 phraseBlockSize = 10; 256 329 } 257 System.out.println("Phind phraseblock size: " + phraseBlockSize);330 System.out.println("Phind retrieval block size: " + phraseBlockSize); 258 331 259 332 // How large should the font be? 260 333 try { 261 temp = Integer.valueOf(getParameter("fontsize")); 262 fontSize = temp.intValue(); 334 fontSize = Integer.valueOf(getParameter("fontsize")).intValue(); 263 335 } catch (Exception e) { 264 temp = null;265 336 fontSize = 12; 266 337 } 267 338 System.out.println("Phind font size: " + fontSize); 268 269 // browser details 270 try { 271 localHost = InetAddress.getLocalHost().toString(); 272 } catch (Exception e) { 273 localHost = "Can't get client host."; 274 } 275 System.out.println("Phind client: " + localHost); 276 System.out.println(""); 277 278 // The phind applet layout manager 279 setLayout(new BorderLayout()); 280 281 // initialise the user interface 282 setBackground(Color.white); 283 plainFont = new Font("Helvetica", Font.PLAIN, fontSize); 284 boldFont = new Font("Helvetica", Font.BOLD, fontSize); 285 286 // the main Result area 287 288 // the Panel containing the displays is in the center of the display 289 resultPanel = new Panel(); 290 if (vertical) { 291 resultPanel.setLayout(new GridLayout(depth,1,0,2)); 292 } else { 293 System.out.println("horizontal"); 294 resultPanel.setLayout(new GridLayout(1,depth,2,0)); 295 } 296 add("Center", resultPanel); 297 298 // Create ResultDisplays and place in the interface 299 ResultDisplay d1, d2 = null; 300 firstDisplay = new ResultDisplay(this, null); 301 resultPanel.add(firstDisplay); 302 303 d1 = firstDisplay; 304 for (int i = 2; i <= depth; i++) { 305 d2 = new ResultDisplay(this, d1); 306 resultPanel.add(d2); 307 d1 = d2; 308 } 309 310 lastDisplay = d2; 311 312 313 // The "control panel" 314 Panel p1 = new Panel(); 315 add("North", p1); 316 p1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); 317 318 searchButton = new Button("Search"); 319 searchButton.setFont(boldFont); 320 p1.add(searchButton); 321 322 Label tempLabel = new Label(" for"); 323 tempLabel.setFont(boldFont); 324 p1.add(tempLabel); 325 326 wordField = new TextField(12); 327 wordField.setFont(boldFont); 328 p1.add(wordField); 329 330 Label temp2 = new Label(" "); 331 p1.add(temp2); 332 333 prevButton = new Button("Previous"); 334 prevButton.setFont(boldFont); 335 prevButton.disable(); 336 p1.add(prevButton); 337 338 nextButton = new Button(" Next "); 339 nextButton.setFont(boldFont); 340 nextButton.disable(); 341 p1.add(nextButton); 342 343 // lets get started then 344 setStatus("Welcome to Phind."); 345 mode = idleMode; 346 } 347 339 } 348 340 349 341 void setStatus(String status) { … … 551 543 System.out.println("sending query: " + query); 552 544 try { 553 phindcgi = new URL(query);545 URL phindcgi = new URL(query); 554 546 DataInputStream in = new DataInputStream(phindcgi.openStream()); 555 547 byte[] buffer; … … 702 694 } 703 695 696 697 698 // Open an arbitrary web page 699 void displayWebPage(String address, String window) { 700 try { 701 URL url= new URL(address); 702 if (window.length() > 0) { 703 getAppletContext().showDocument(url, window); 704 } else { 705 getAppletContext().showDocument(url); 706 } 707 } catch (Exception e) { 708 System.out.println("Cannot open web page: " + e.toString()); 709 } 710 } 711 704 712 } -
trunk/gsdl/src/phind/client/ResultCanvas.java
r1830 r1831 477 477 //User clicks on a phrase 478 478 if (item.isPhrase()) { 479 480 479 itemSelected = itemSelected; 481 480 update(getGraphics()); 482 483 481 parent.lookupPhrase(item.hiddenText(), item.toString(), 2); 484 482 485 483 // If meta key is held down, send query to search engine 486 if (event.metaDown()) { 487 if (phind.search_url.equals("none") || phind.search_url.equals("")) { 488 System.out.println("No searching in this collection"); 489 } else { 490 URL url; 491 try { 492 url = new URL(phind.search_url + "%22" + item.toString() + "%22&"); 493 phind.getAppletContext().showDocument(url, "phindsearch"); 494 System.out.println("The query is: " + url.toString()); 495 } catch (Exception e) { 496 System.out.println("URL error: " + e.toString()); 497 } 498 } 484 if (event.metaDown() && !phind.library_address.equals("")) { 485 String address = phind.library_address 486 + "a=q&c=" + phind.collection 487 + "&q=%22" + item.toString().replace(' ', '+') + "%22"; 488 phind.displayWebPage(address, "phindsearch"); 499 489 } 500 501 490 } 502 491 … … 506 495 update(getGraphics()); 507 496 parent.lookupPhrase(item.hiddenText(), item.toString(), 2); 497 498 // If meta key is held down, send query to search engine 499 if (event.metaDown() && !phind.library_address.equals("")) { 500 String address = phind.library_address 501 + "a=q&c=" + phind.collection 502 + "&q=%22" + item.toString().replace(' ', '+') + "%22"; 503 phind.displayWebPage(address, "phindsearch"); 504 } 508 505 } 509 506 … … 513 510 update(getGraphics()); 514 511 515 URL url; 516 try { 517 String address = phind.library_address 518 + "a=d&c=" + phind.collection 519 + "&d=" + item.hiddenText() 520 + "&q=" + parent.searchPhrase.replace(' ', '+'); 521 url = new URL(address); 522 System.out.println("URL selected: " + url.toString()); 523 phind.getAppletContext().showDocument(url, "phinddoc"); 524 } catch (Exception e) { 525 System.out.println("URL error: " + e.toString()); 526 } 512 String address = phind.library_address 513 + "a=d&c=" + phind.collection 514 + "&d=" + item.hiddenText() 515 + "&q=" + parent.searchPhrase.replace(' ', '+'); 516 phind.displayWebPage(address, "phinddoc"); 527 517 } 528 518
Note:
See TracChangeset
for help on using the changeset viewer.