Changeset 1627


Ignore:
Timestamp:
2000-10-30T15:10:28+13:00 (24 years ago)
Author:
paynter
Message:

The applet is now operational. Phrases work, documents work, getting new
phrases and documents work, backdrops work.

Location:
trunk/gsdl/src/phind/client
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/phind/client/Phind.java

    r1626 r1627  
    5555   words on the screen, and handles user input from the mouse.
    56566. ResultItem represents a single result object (a phrase or document).
    57 
    58 7. PhindTitle is for drawing backdrops in empty Displays. (?)
     577. PhindTitle is for drawing backdrops in ResultDisplays.
    5958
    6059**********************************************************************/
     
    104103
    105104    // Do we want a background image in the applet?
     105    String backdrop_address;
    106106    public boolean showImage;
    107107    public Image backgroundImage;
     
    109109    // Holders for the downloaded data
    110110    Panel resultPanel;
    111     PhindTitle title;
    112111    ResultDisplay firstDisplay, lastDisplay;
    113112
     
    198197    System.out.println("Phind library: " + library_address);
    199198
     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
    200211    // Is there a search URL for this collection?
    201212    try {
     
    238249    System.out.println("Phind phrase block size: " + phraseBlockSize);
    239250
    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 
    252251    // How large should the font be?
    253252    try {
     
    271270    // The phind applet layout manager
    272271    setLayout(new BorderLayout());
    273 
    274     // the Phind title window
    275     if (showImage) backgroundImage = getImage(getCodeBase(), "sequitur.jpg");
    276     title = new PhindTitle(this, true);
    277272
    278273    // initialise the user interface
     
    495490    throws IOException {
    496491
    497     // Set up connections (streams)
    498     //connection = new Socket(server, Integer.parseInt(port));
    499     //OutputStream out = connection.getOutputStream();
    500     //InputStream in = connection.getInputStream();
    501 
    502492    // Build the query
    503493    String query = phindcgi_address + "?x=1&c=" + collection;
    504494
    505495    if (keyKnown) {
    506         query = query + "&n=" + word;
     496      query = query + "&n=" + word;
    507497    } 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
    512509    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;
    526530
    527531    // 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
     31PhindTitle is for drawing backdrops in empty ResultDisplay panels.
     32
     33**********************************************************************/
     34
    135import java.applet.Applet;
    236import java.awt.Canvas;
    337import java.awt.Color;
    438import java.awt.Dimension;
    5 import java.awt.Font;
    639import java.awt.Graphics;
    740import java.awt.Image;
     
    942public class PhindTitle extends Canvas {
    1043
    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;
    3550    }
    3651
    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);
    6054    }
     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    }
    6172  }
    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 
    6873}
    6974
    7075 
     76
     77
     78
     79
     80
  • trunk/gsdl/src/phind/client/ResultBox.java

    r1626 r1627  
    6767    Panel label;
    6868
    69     // Information about the query
     69  // The key identifying the phrase displayed, with its text and the
     70  // collection from which it is drawn
    7071    String searchKey, searchPhrase;
    7172    String searchCollection;
    7273   
    73     // Information about the result set
     74  // The total frequency, expansion frequency, and document frequency
     75  // of the phrase
     76  int numberOfOccurances;
    7477    int numberOfExpansions;
    75     int expansionsRetrieved;
    7678    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;
    7884    int nextPhraseBlock;
    7985    int nextDocumentBlock;
     
    103109    if (prev != null) prev.next = this;
    104110
     111    searchKey = key;
     112    searchPhrase = phrase;
     113    searchCollection = collect;
     114
     115    numberOfOccurances = -1;
    105116    numberOfExpansions = -1;
     117    numberOfDocuments = -1;
     118
    106119    expansionsRetrieved = 0;
    107     numberOfDocuments = -1;
    108120    documentsRetrieved = 0;
    109121    nextPhraseBlock = 1;
    110122    nextDocumentBlock = 1;
    111123
    112     searchKey = key;
    113     searchPhrase = phrase;
    114     searchCollection = collect;
    115124
    116125    setLayout(new BorderLayout());
    117 
    118126
    119127    s = new Scrollbar(Scrollbar.VERTICAL);
     
    176184    }
    177185
    178 
     186   
     187    // Look up a phrase
     188    // Phrase lookups are passed on to the Phind applet itself.
    179189    void lookupPhrase(String key, String phrase, int queryMode) {
    180190    buffer = "";
     
    264274    }
    265275 
    266     // The <expansionlist> tag
    267     else if (buffer.startsWith("<expansionlist ")) {
     276    // The <phinddata> tag introduces the dataset
     277    else if (buffer.startsWith("<phinddata ")) {
    268278        item = buffer.substring(0, eol);
    269279        buffer = buffer.substring(eol + 1);
    270         addExpansionListTag(item);
     280        addPhinddataTag(item);
    271281        return true;
    272     }
    273  
    274     // The <documentlist> tag
    275     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 dataset
    283     else if (buffer.startsWith("<phinddata ")) {
    284 
    285282    }
    286283
     
    291288    }
    292289   
     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 
    293300    // Ignore the piece we've read
    294301    item = buffer.substring(0, eol);
     
    299306
    300307
    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">
    306312    // Read the expansion information from the tag
    307313    //
    308314    // Return true if successful, otherwise false.
    309315
    310     boolean addExpansionListTag( String line ) {
     316    boolean addPhinddataTag( String line ) {
    311317
    312318    // System.out.println( "addExpansionListTag: " + line);
    313319
    314     String lenStr = "";
    315     int length = 0;
     320    String idStr = "", tfStr = "", efStr = "", dfStr = "";
     321    int tf = 0, ef = 0, df = 0;
    316322
    317323    // Break the tag down into its component parts
    318     line = line.substring(15);
    319324    int nextSplit;
    320325        while (line.length() > 0) {
    321326        line = line.trim();
    322327
    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();
    330373            line = line.substring(nextSplit + 1);
    331374        } else {
     
    345388    }
    346389
    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;
    349395    return true;
    350396    }
     
    455501
    456502
    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 
    508 
    509503    // Add an document tag
    510504    //
    511505    // Given a string containing an XML document tag of the form:
    512     //   <document num="2" hash="HASH424e64b811fdad933be69c" freq="1" title="CONTENS"/>
     506    //   <document num="2" hash="HASH424e64b811fdad933be69c" freq="1" title="CONTENTS"/>
    513507    //   <document num="3" hash="HASH01f08efd8752ad54ca0a99cf" freq="1" title="Tree mixtures"/>
    514508    //
  • trunk/gsdl/src/phind/client/ResultCanvas.java

    r1626 r1627  
    242242    // draw the background
    243243    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        }
    247254    } else {
    248255        g.setColor(Color.white);
     
    296303        g.drawString(" " + Integer.toString(result.freq), secondColumn, y);
    297304        }
    298 
    299         // Write the expand button
    300         //if (result.expansion > 0) {
    301         //  g.drawString(" +", leftMargin, y);
    302         //}
    303 
    304305
    305306        if (result.isPhrase()) {
     
    360361
    361362
    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.
    363368    public boolean handleEvent(Event event) {
    364369   
  • 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 *********************************************************************/
    227
    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
     30This class is used in the Phind java applet (Phind.java).
     31
     32A ResultDisplay is a Panel that can display a single Component, which will
     33be a ResultBox or PhindTitle object.
     34
     35ResultBoxes can be "chained" together with their "prev" and "next" fields,
     36allowing us to have an arbitrary number of "displays" in which to show
     37phrase lists.
    638
    739Main methods:
    8 
    940* emptyContents will remove the component and emptyAll the "next" display
    1041* display will add an item to the first (ie: most "prev") available box
    1142
     43**********************************************************************/
    1244
    13 */
    1445
    1546import java.awt.Panel;
     
    3364
    3465    empty = true;
    35     current = new PhindTitle(ph,false);
     66    current = new PhindTitle(ph);
    3667    add(current);
    3768  }
     
    4273    if (empty == false) {
    4374      empty = true;
    44       current = new PhindTitle(phind,false);
     75      current = new PhindTitle(phind);
    4576      removeAll();
    4677      add(current);
Note: See TracChangeset for help on using the changeset viewer.