Changeset 1832


Ignore:
Timestamp:
2001-01-12T15:20:55+13:00 (23 years ago)
Author:
paynter
Message:

Numerous applet options to control the appearanceof the applet. The colour
of pretty much every component can be set, as can the column widths, fonts
initial search term, control panel visibility, and probably others that I
forget. This gives us most of what we need to embed a small, simple phind
applet in a search relsults page.

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

Legend:

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

    r1831 r1832  
    107107    public String library_address, phindcgi_address;
    108108
     109    // Initial serach term
     110    public String initialSearch;
     111
    109112    // Number of phrases to retrieve at any one time
    110113    public int phraseBlockSize;
     
    113116    public boolean vertical;
    114117    public int depth;
     118
     119    // Font
    115120    public int fontSize;
     121    public String fontName;
    116122    public Font plainFont, boldFont;
    117123
     
    120126    public String backdrop_address;
    121127    public Image backgroundImage;
     128
     129    // Colours
     130    public Color panel_fg, panel_bg,
     131    column_1_fg, column_1_bg,
     132    column_2_fg, column_2_bg,
     133    highlight_fg, highlight_bg,
     134    thesaurus_fg, thesaurus_bg, thesaurus_bar_fg, thesaurus_bar_bg,
     135    expansion_fg, expansion_bg, expansion_bar_fg, expansion_bar_bg,
     136    document_fg, document_bg, document_bar_fg, document_bar_bg,
     137    message_fg, message_bg;
     138   
     139    // Column dimensions
     140    int column_1_width, column_2_width;
     141
     142    // Where do we open new windows
     143    String searchWindowName, documentWindowName;
    122144
    123145    // the mode of operation
     
    127149    final int searchMode = 2;
    128150
    129     // elements of the page
     151    // Elements of the control panel
     152    boolean showControlPanel;
    130153    Label titleLabel;
    131154    TextField wordField;
     
    170193    mode = initMode;
    171194   
    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 
    186195    // Read applet parameters
    187196    getParameters();
    188197
    189    
    190198    // Initialise the user interface
    191     setBackground(Color.white);
     199    setBackground(panel_bg);
    192200    lastQueryEndTime = new Date();
    193201
    194202    // fonts used to output text
    195     plainFont = new Font("Helvetica", Font.PLAIN, fontSize);
    196     boldFont  = new Font("Helvetica", Font.BOLD, fontSize);
     203    plainFont = new Font(fontName, Font.PLAIN, fontSize);
     204    boldFont  = new Font(fontName, Font.BOLD, fontSize);
    197205
    198206    // The phind applet layout manager
    199207    setLayout(new BorderLayout());
    200208
    201     // the Panel containing the displays is in the center of the display
     209    // Panel containing the displays is in the center of the display
    202210    resultPanel = new Panel();
    203211    if (vertical) {
     
    209217    add("Center", resultPanel);
    210218
    211     // Create ResultDisplays and place in the interface
     219    // Create ResultDisplays and place into the interface
    212220    ResultDisplay d1, d2 = null;
    213221    firstDisplay = new ResultDisplay(this, null);
    214222    resultPanel.add(firstDisplay);
    215223
    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);
     224    if (depth == 1) {
     225        lastDisplay = firstDisplay;
     226    } else {
     227        d1 = firstDisplay;
     228        for (int i = 2; i <= depth; i++) {
     229        d2 = new ResultDisplay(this, d1);
     230        resultPanel.add(d2);
     231        d1 = d2;
     232        }
     233        lastDisplay = d2;
     234    }
     235
     236    // The control panel
     237    initialiseControlPanel();
    254238
    255239    // lets get started then
    256240    setStatus("Welcome to Phind.");
    257241    mode = idleMode;
    258     }
    259 
    260 
    261     // Get the applet parameters
    262     void getParameters() {
    263 
    264 
    265     // What is this collection called?
    266     try {
    267         collection = new String(getParameter("collection"));
    268         System.out.println("Phind collection: " + collection);
    269     } catch (Exception e) {
    270         System.err.println("Phind could not read collection name: " + e.toString());
    271         stop();
    272     }
    273 
    274     // Where do we get the phind data
    275     try {
    276         phindcgi_address = new String(getParameter("phindcgi"));
    277         phindcgi_address = tidy_URL(phindcgi_address, true);
    278         System.out.println("Phind phindcgi: " + phindcgi_address);
    279     } catch (Exception e) {
    280         System.err.println("Phind could not process phindcgi URL: " + e.toString());
    281         stop();
    282     }
    283 
    284     // Where is the collection served from
    285     try {
    286         library_address = new String(getParameter("library"));
    287         library_address = tidy_URL(library_address, true);
    288         System.out.println("Phind library: " + library_address);
    289     } catch (Exception e) {
    290         System.err.println("Phind library: not specified");
    291         library_address = "";
    292     }
    293 
    294     // Should we display a background image?
    295     try {
    296         backdrop_address = new String(getParameter("backdrop"));
    297         backdrop_address = tidy_URL(backdrop_address, false);
    298         URL backdrop_url = new URL(backdrop_address);
    299         backgroundImage = getImage(backdrop_url);
    300         showImage = true;
    301         System.out.println("Phind backdrop: " + backdrop_address);
    302     } catch (Exception e) {
    303         System.out.println("Phind backdrop not set: " + e.toString());
    304     }
    305 
    306     // Are the windows arranged vertically or horizontally
    307     try {
    308         if (getParameter("orientation").toLowerCase().startsWith("h")) {
    309         vertical = false;
    310         System.out.println("Phind orientation: horizontal");
    311         }
    312     } catch (Exception e) {
    313         System.out.println("Phind orientation: vertical");
    314     }
    315 
    316     // How many phind windows are there?
    317     try {
    318         depth = Integer.valueOf(getParameter("depth")).intValue();
    319     } catch (Exception e) {
    320         depth = 3;
    321     }
    322     System.out.println("Phind depth: " + depth);
    323 
    324     // How many phrases should we fetch at any given time?
    325     try {
    326         phraseBlockSize = Integer.valueOf(getParameter("blocksize")).intValue();
    327     } catch (Exception e) {
    328         phraseBlockSize = 10;
    329     }
    330     System.out.println("Phind retrieval block size: " + phraseBlockSize);
    331 
    332     // How large should the font be?
    333     try {
    334         fontSize = Integer.valueOf(getParameter("fontsize")).intValue();
    335     } catch (Exception e) {
    336         fontSize = 12;
    337     }
    338     System.out.println("Phind font size: " + fontSize);
    339     }
    340 
     242
     243    // Perform initial search, if requested
     244    if (initialSearch.length() > 0) {
     245        searchForWord(initialSearch);
     246    }
     247    }
     248
     249
     250    // Display a message in the status bar
    341251    void setStatus(String status) {
    342252    showStatus(status);
    343253    }
    344254
     255    // The user performs an action in the interface
    345256    public boolean action(Event evt, Object arg) {
    346257
    347258    if (evt.target == searchButton) {
    348         searchForWord();
     259        searchForWord(getSearchTerm());
    349260    } else if (evt.target == wordField) {
    350         searchForWord();
     261        searchForWord(getSearchTerm());
    351262    } else if (evt.target == prevButton) {
    352263        shiftPrevious();
     
    354265        shiftNext();
    355266    } else {
    356         System.out.println("unknown action: " + evt.toString() + ", object: " + arg.toString());
     267        System.out.println("unknown action: " + evt.toString()
     268                   + ", object: " + arg.toString());
    357269    }
    358270    return true;
     
    362274    // Search for a word
    363275    //
    364     // called when the "Search" Button is pressed
    365     void searchForWord() {
     276    // Clled on two occasions:
     277    //   when the "Search" Button is pressed, or
     278    //   to perform an "initial search"
     279    void searchForWord(String searchWord) {
    366280
    367281    if (mode == idleMode) {
    368 
     282       
    369283        // transform the word to an appropriate search key
    370         String searchWord = wordField.getText().trim().toLowerCase();
     284        searchWord = searchWord.trim().toLowerCase();
    371285        for (int i = 0; i < searchWord.length(); i++) {
    372286        if ((searchWord.charAt(i) < 'a') || (searchWord.charAt(i) > 'z')) {
     
    374288        }
    375289        }
    376         wordField.setText(searchWord);
     290        setSearchTerm(searchWord);
    377291
    378292        // look up the word
     
    410324    if (mode == idleMode) {
    411325
    412         // If we are going to replace the next ResultDisplay, then empty it
     326        // If we are going to replace the first ResultDisplay, then empty it
    413327        if (queryMode <= 2) {
    414328        if (source.display.next != null) source.display.next.emptyContents();
     
    452366                   boolean keyKnown, String key, String phrase,
    453367                   int queryMode) {
    454         searchButton.disable();
     368        disableSearchButton();
    455369    mode = searchMode;
    456370    ResultBox r = null;
     
    468382        setStatus("Query error: " + e.toString());
    469383        mode = idleMode;
    470         searchButton.enable();
     384        enableSearchButton();
    471385        return null;
    472386    }
     
    475389    setStatus(r.c.numberOfItems + " results for \"" + phrase + "\"");
    476390    mode = idleMode;
    477     searchButton.enable();
     391    enableSearchButton();
    478392    lastQueryEndTime = new Date();
    479393
     
    566480    }
    567481   
    568 
    569     // Previous and Next button functionality
    570 
    571     // enable or disable the "Previous" and "Next" buttons
    572     void enablePreviousAndNext() {
    573 
    574     Component c = firstDisplay.current;
    575     if (c.getClass().getName().equals("ResultBox")) {
    576         if (((ResultBox) c).prevBoxExists()) {
    577         prevButton.enable();
    578         } else {
    579         prevButton.disable();
    580         }
    581     }
    582 
    583     c = lastDisplay.current;
    584     if (c.getClass().getName().equals("ResultBox")) {
    585         if (((ResultBox) c).nextBoxExists()) {
    586         nextButton.enable();
    587         } else {
    588         nextButton.disable();
    589         }
    590     }
    591     }
    592 
    593     // Shift to previous box
    594     //
    595     // If the user clicks "Previous" then scroll up.
    596     void shiftPrevious() {
    597 
    598     Component c = firstDisplay.current;
    599     if (c.getClass().getName().equals("ResultBox")) {
    600 
    601         ResultBox b = (ResultBox) c;
    602         if (b.prevBoxExists()) {
    603         b = b.prev;
    604 
    605         // empty all the displays
    606         firstDisplay.emptyContents();
    607 
    608         // add as many result boxes as there are displays
    609         for (int i = 1 ; ((i <= depth) && (b != null)); i++) {
    610             lastDisplay.display(b);
    611             b.resize(b.display.size());
    612             b.paintAll(b.getGraphics());
    613             b = b.next;
    614         }
    615         }
    616     }
    617     enablePreviousAndNext();
    618     }
    619 
    620 
    621     // Shift to next box
    622     //
    623     // If the user clicks "Next" then scroll down if possible
    624     void shiftNext() {
    625 
    626     Component c = lastDisplay.current;
    627     if (c.getClass().getName().equals("ResultBox")) {
    628 
    629         ResultBox b = (ResultBox) c;
    630         if (b.nextBoxExists()) {
    631 
    632         // find the new "first" displayed box
    633         c = firstDisplay.current;
    634         b = (ResultBox) c;
    635         b = b.next;
    636 
    637         // empty all the displays
    638         firstDisplay.emptyContents();
    639 
    640         // add as many result boxes as there are displays
    641         for (int i = 1 ; ((i <= depth) && (b != null)); i++) {
    642             lastDisplay.display(b);
    643             b.resize(b.display.size());
    644             b.paintAll(b.getGraphics());
    645             b = b.next;
    646         }
    647         }
    648     }
    649     enablePreviousAndNext();
    650     }
    651 
    652 
    653482
    654483    // Tidy up URLs
     
    710539    }
    711540
     541
     542    // Get the applet parameters
     543    void getParameters() {
     544
     545    // What is this collection called?
     546    collection = parameterValue("collection");
     547    System.out.println("Phind collection: " + collection);
     548
     549    // Where is the phind CGI script
     550    phindcgi_address = parameterValue("phindcgi");
     551    phindcgi_address = tidy_URL(phindcgi_address, true);
     552    System.out.println("Phind phindcgi: " + phindcgi_address);
     553
     554    // Where is the Greenstone library
     555    library_address = parameterValue("library");
     556    library_address = tidy_URL(library_address, true);
     557    System.out.println("Phind library: " + library_address);
     558   
     559    // Is there a default search term?
     560    initialSearch = parameterValue("initial_search", "");
     561
     562    // Should we display the control panel
     563    showControlPanel = true;
     564    if (parameterValue("control_panel", "show").toLowerCase().equals("hide")) {
     565        showControlPanel = false;
     566    }
     567   
     568    // Should we show a background image?
     569    backdrop_address = parameterValue("backdrop", "");
     570    if (backdrop_address.length() > 0) {
     571        backdrop_address = tidy_URL(backdrop_address, false);
     572        System.out.println("Phind backdrop URL: " + backdrop_address);
     573
     574        try {
     575        URL backdrop_url = new URL(backdrop_address);
     576        backgroundImage = getImage(backdrop_url);
     577        showImage = true;
     578        } catch (Exception e) {
     579        System.out.println("Phind could not load " + backdrop_address);
     580        showImage = false;
     581        }
     582    }
     583
     584    // Are the windows arranged vertically or horizontally
     585    if (parameterValue("orientation", "vertical").toLowerCase().startsWith("hori")) {
     586        vertical = false;
     587    } else {
     588        vertical = true;
     589    }
     590
     591    // How many phind windows are there?
     592    depth = parameterValue("depth", 3);
     593
     594    // How many phrases should we fetch at any given time?
     595    phraseBlockSize = parameterValue("blocksize", 10);
     596
     597    // What font should we use?
     598    fontSize = parameterValue("fontsize", 10);
     599    fontName = parameterValue("fontname", "Helvetica");
     600
     601    // Column dimensions
     602    column_1_width = parameterValue("first_column_width", 6);
     603    column_2_width = parameterValue("second_column_width", column_1_width);
     604   
     605    // Where do we open new windows
     606    searchWindowName = parameterValue("search_window", "phindsearch");
     607    documentWindowName = parameterValue("document_window", "phinddoc");
     608
     609    // Colours
     610    panel_fg = parameterValue("panel_fg", panel_fg);
     611    panel_bg = parameterValue("panel_bg", panel_bg);
     612
     613    highlight_bg = parameterValue("highlight_bg", new Color(255, 220, 115));
     614
     615    expansion_fg = parameterValue("expansion_fg", Color.black);
     616    thesaurus_fg = parameterValue("thesaurus_fg", new Color(0, 100, 0));
     617    document_fg = parameterValue("document_fg", Color.blue);
     618
     619    thesaurus_bar_fg = parameterValue("thesaurus_bar_fg", Color.black);
     620    expansion_bar_fg = parameterValue("expansion_bar_fg", Color.black);
     621    document_bar_fg = parameterValue("document_bar_fg", Color.black);
     622
     623    thesaurus_bar_bg = parameterValue("thesaurus_bar_bg", new Color(160, 160, 190));
     624    expansion_bar_bg = parameterValue("expansion_bar_bg", new Color(255, 200, 200));
     625    document_bar_bg = parameterValue("document_bar_bg", new Color(150, 193, 156));
     626
     627    column_1_fg = parameterValue("first_column_fg", Color.black);
     628    column_1_bg = parameterValue("first_column_bg", new Color(235, 245, 235));
     629    column_2_fg = parameterValue("second_column_fg", Color.black);
     630    column_2_bg = parameterValue("second_column_bg", new Color(200, 220, 200));
     631
     632    message_fg = parameterValue("message_fg", Color.black);
     633    message_bg = parameterValue("message_bg", Color.white);
     634
     635    // Colours I don't use, yet
     636    // thesaurus_bg = parameterValue("thesaurus_bg", Color.white);
     637    // expansion_bg = parameterValue("expansion_bg", Color.white);
     638    // document_bg = parameterValue("document_bg", Color.white);
     639    }
     640
     641    // Get the value of a parameter given its name.
     642    // There are many types of parameters, hence the variety of functions.
     643
     644    // Get a REQUIRED string.  Stop the applet if we cannot.
     645    String parameterValue(String name) {
     646    try {
     647        return getParameter(name);
     648    } catch (Exception e) {
     649        System.err.println("Phind: you must give a parameter for \""
     650                   + name + "\".  Stopping.");
     651        stop();
     652    }
     653    return "";
     654    }
     655
     656    // Get an optional parameter.  Return a default if we cannot.
     657    String parameterValue(String name, String defaultValue) {
     658    String text = getParameter(name);
     659    if (text == null) {
     660        return defaultValue;
     661    }
     662    System.out.println("Phind " + name + ": " + text);
     663    return text;
     664    }
     665
     666    int parameterValue(String name, int defaultValue) {
     667    int value;
     668    try {
     669        value = Integer.parseInt(getParameter(name));
     670    } catch (Exception e) {
     671        return defaultValue;
     672    }
     673    System.out.println("Phind " + name + ": " + value);
     674    return value;
     675    }
     676
     677    Color parameterValue(String name, Color defaultValue) {
     678
     679    String text = getParameter(name);
     680    if (text == null) {
     681        return defaultValue;
     682    }
     683    text = text.toLowerCase();
     684
     685    // a number of the form "#ddffee"
     686    if (text.startsWith("#") && (text.length() == 7)) {
     687        text = text.substring(1);
     688        int r, g, b;
     689        try {
     690        r = Integer.parseInt(text.substring(0,2), 16);
     691        g = Integer.parseInt(text.substring(2,4), 16);
     692        b = Integer.parseInt(text.substring(4), 16);
     693        return new Color(r, g, b);
     694        }  catch (Exception e) {
     695        return defaultValue;
     696        }
     697    }
     698
     699    // a known Java colour string
     700    else if (text.equals("black")) { return Color.black; }
     701    else if (text.equals("blue")) { return Color.blue; }
     702    else if (text.equals("cyan")) { return Color.cyan; }
     703    else if (text.equals("darkgray")) { return Color.darkGray; }
     704    else if (text.equals("gray")) { return Color.gray; }
     705    else if (text.equals("green")) { return Color.green; }
     706    else if (text.equals("lightgray")) { return Color.lightGray; }
     707    else if (text.equals("magenta")) { return Color.magenta; }
     708    else if (text.equals("orange")) { return Color.orange; }
     709    else if (text.equals("pink")) { return Color.pink; }
     710    else if (text.equals("red")) { return Color.red; }
     711    else if (text.equals("white")) { return Color.white; }
     712    else if (text.equals("yellow")) { return Color.yellow; }
     713
     714    return defaultValue;
     715    }
     716
     717
     718    // Control panel operations
     719
     720    // Initialise the control panel
     721    void initialiseControlPanel() {
     722   
     723    if (showControlPanel) {
     724        Panel p1 = new Panel();
     725        add("North", p1);
     726        p1.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
     727       
     728        searchButton = new Button("Search");
     729        searchButton.setFont(boldFont);
     730        p1.add(searchButton);
     731       
     732        Label tempLabel = new Label("  for");
     733        tempLabel.setFont(boldFont);
     734        p1.add(tempLabel);
     735       
     736        wordField = new TextField(12);
     737        wordField.setFont(boldFont);
     738        p1.add(wordField);
     739       
     740        Label temp2 = new Label("          ");
     741        p1.add(temp2);
     742       
     743        prevButton = new Button("Previous");
     744        prevButton.setFont(boldFont);
     745        prevButton.disable();
     746       
     747        p1.add(prevButton);
     748       
     749        nextButton = new Button("  Next  ");
     750        nextButton.setFont(boldFont);
     751        nextButton.disable();
     752        p1.add(nextButton);
     753       
     754    }
     755    }
     756   
     757    // Button and field functionality
     758   
     759    // Enable and disable the word field
     760    void enableSearchButton() {
     761    if (showControlPanel) {
     762        searchButton.enable();
     763    }
     764    }
     765    void disableSearchButton() {
     766    if (showControlPanel) {
     767        searchButton.disable();
     768    }
     769    }
     770
     771    // Get and set the search text in the wordField
     772    String getSearchTerm() {
     773    if (showControlPanel) {
     774        return wordField.getText();
     775    } else {
     776        return initialSearch;
     777    }
     778    }
     779    void setSearchTerm(String word) {
     780    if (showControlPanel) {
     781        wordField.setText(word);
     782    }
     783    }
     784
     785    // Enable or disable the "Previous" and "Next" buttons
     786    void enablePreviousAndNext() {
     787
     788    if (showControlPanel) {
     789        Component c = firstDisplay.current;
     790        if (c.getClass().getName().equals("ResultBox")) {
     791        if (((ResultBox) c).prevBoxExists()) {
     792            prevButton.enable();
     793        } else {
     794            prevButton.disable();
     795        }
     796        }
     797       
     798        c = lastDisplay.current;
     799        if (c.getClass().getName().equals("ResultBox")) {
     800        if (((ResultBox) c).nextBoxExists()) {
     801            nextButton.enable();
     802        } else {
     803            nextButton.disable();
     804        }
     805        }
     806    }
     807    }
     808
     809    // Shift to previous box
     810    //
     811    // If the user clicks "Previous" then scroll up.
     812    void shiftPrevious() {
     813
     814    Component c = firstDisplay.current;
     815    if (c.getClass().getName().equals("ResultBox")) {
     816
     817        ResultBox b = (ResultBox) c;
     818        if (b.prevBoxExists()) {
     819        b = b.prev;
     820
     821        // empty all the displays
     822        firstDisplay.emptyContents();
     823
     824        // add as many result boxes as there are displays
     825        for (int i = 1 ; ((i <= depth) && (b != null)); i++) {
     826            lastDisplay.display(b);
     827            b.resize(b.display.size());
     828            b.paintAll(b.getGraphics());
     829            b = b.next;
     830        }
     831        }
     832    }
     833    enablePreviousAndNext();
     834    }
     835
     836    // Shift to next box
     837    //
     838    // If the user clicks "Next" then scroll down if possible
     839    void shiftNext() {
     840
     841    Component c = lastDisplay.current;
     842    if (c.getClass().getName().equals("ResultBox")) {
     843
     844        ResultBox b = (ResultBox) c;
     845        if (b.nextBoxExists()) {
     846
     847        // find the new "first" displayed box
     848        c = firstDisplay.current;
     849        b = (ResultBox) c;
     850        b = b.next;
     851
     852        // empty all the displays
     853        firstDisplay.emptyContents();
     854
     855        // add as many result boxes as there are displays
     856        for (int i = 1 ; ((i <= depth) && (b != null)); i++) {
     857            lastDisplay.display(b);
     858            b.resize(b.display.size());
     859            b.paintAll(b.getGraphics());
     860            b = b.next;
     861        }
     862        }
     863    }
     864    enablePreviousAndNext();
     865    }
     866
     867
     868
     869
     870
    712871}
  • trunk/gsdl/src/phind/client/ResultCanvas.java

    r1831 r1832  
    205205    void updateMoreLinksMarker() {
    206206   
    207     System.out.println("updateMoreLinksMarker() ");
    208     System.out.println("retreived: " + parent.thesaurusLinksRetrieved);
    209     System.out.println("total: " + parent.numberOfThesaurusLinks);
     207    // System.out.println("updateMoreLinksMarker() ");
    210208
    211209    // look for a marker
     
    255253    g.setFont(areaPlain);
    256254    int space = g.getFontMetrics().stringWidth(" ");
    257     int margin = g.getFontMetrics().stringWidth(" 8888 ");
    258 
    259     int secondColumn = canvasSize.width - margin;
    260     int firstColumn = secondColumn - margin;
    261 
    262     int leftMargin = 0;
    263     int rightMargin = firstColumn;
     255    int nought = g.getFontMetrics().stringWidth("0");
     256
     257    int firstColumnWidth = phind.column_1_width * nought;
     258    int secondColumnWidth = phind.column_2_width * nought;
     259    int columnWidth = firstColumnWidth + secondColumnWidth;
     260
     261    int firstColumnLeft = canvasSize.width - columnWidth;
     262    int secondColumnLeft = firstColumnLeft + firstColumnWidth;
     263
     264    int mainLeftMargin = 0;
     265    int mainRightMargin = firstColumnLeft;
    264266
    265267    // the number of items that will fit on the canvas
     
    276278
    277279    // Draw the phrase area
     280    Color fore = phind.panel_fg;
     281    Color back = phind.panel_bg;
     282
    278283
    279284    // draw the background
     
    281286        try {
    282287        g.drawImage(backgroundImage,
    283                 leftMargin, 0, rightMargin, canvasSize.height,
    284                 Color.white, null);
     288                mainLeftMargin, 0, mainRightMargin, canvasSize.height,
     289                back, null);
    285290        } catch (Exception e) {
    286291        phind.showImage = false;
    287292        System.err.println("ResultCanvas paint error: " + e);
    288         g.setColor(Color.white);
     293        g.setColor(back);
    289294        g.fillRect(0, 0, canvasSize.width, canvasSize.height);
    290295        }
    291296    } else {
    292         g.setColor(Color.white);
     297        g.setColor(back);
    293298        g.fillRect(0, 0, canvasSize.width, canvasSize.height);
    294299    }
     
    296301    // If there are no phrases, output a brief explanation.
    297302    if (numberOfItems == 0) {
    298         g.drawString("No phrases match this query.", leftMargin + 10, lineSpacing);
     303        g.drawString("No phrases match this query.", mainLeftMargin + 10, lineSpacing);
    299304    }
    300305
     
    302307    ResultItem result;
    303308    int tab, i, y = 0;
    304     int center = leftMargin
    305         + ((rightMargin - leftMargin
     309    int center = mainLeftMargin
     310        + ((mainRightMargin - mainLeftMargin
    306311        - g.getFontMetrics().stringWidth(parent.searchPhrase)) / 2);
    307     int thesColumn = leftMargin + margin
     312    int thesColumn = mainLeftMargin + firstColumnWidth
    308313        + g.getFontMetrics().stringWidth("Narrower term");
    309314
     
    320325        g.setFont(areaPlain);
    321326
    322         // Highlight if the selected phrase.
     327        // Highlight the selected phrase.
    323328        if (i == itemSelected) {
    324         g.setColor(new Color(255, 220, 115));
    325         g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);
    326         g.setColor(Color.black);
     329        g.setColor(phind.highlight_bg);
     330        g.fillRect(mainLeftMargin, y-lineSpacing+2, mainRightMargin, lineSpacing);
    327331        }
    328332
     
    335339        suffix = result.suffixText();
    336340       
    337         g.setColor(Color.black);
     341        g.setColor(phind.expansion_fg);
    338342        g.setFont(areaPlain);
    339343        tab = center - g.getFontMetrics().stringWidth(prefix) - space;
     
    342346        g.setFont(areaBold);
    343347        g.drawString(body, center, y);
     348       
    344349        tab = center + space + g.getFontMetrics().stringWidth(body);
    345        
    346350        g.setFont(areaPlain);
    347351        g.drawString(suffix, tab, y);
     
    353357        body = result.mainText();
    354358
     359        g.setColor(phind.document_fg);
    355360        g.setFont(areaPlain);
    356         g.setColor(Color.blue);
    357         tab = (rightMargin - g.getFontMetrics().stringWidth(body)) / 2;
     361        tab = (mainRightMargin - g.getFontMetrics().stringWidth(body)) / 2;
    358362        g.drawString(body, tab, y);
    359363     
     
    366370        tab = thesColumn - g.getFontMetrics().stringWidth(prefix) - space;
    367371
    368         g.setColor(new Color(0, 100, 0));
     372        g.setColor(phind.thesaurus_fg);
    369373        g.setFont(areaPlain);
    370374        g.drawString(prefix, tab, y);
     
    380384       
    381385        if (result.isMorePhrases()) {
    382             g.setColor(new Color(255, 200, 200));
     386            g.setColor(phind.expansion_bar_bg);
     387        } else if (result.isMoreDocuments()) {
     388            g.setColor(phind.document_bar_bg);
    383389        } else {
    384             g.setColor(new Color(150, 193, 156));
     390            g.setColor(phind.thesaurus_bar_bg);         
    385391        }
    386         g.fillRect(leftMargin, y-lineSpacing+2, rightMargin, lineSpacing);
    387 
    388         g.setColor(Color.black);
     392        g.fillRect(mainLeftMargin, y-lineSpacing+2, mainRightMargin, lineSpacing);
     393
     394        if (result.isMorePhrases()) {
     395            g.setColor(phind.expansion_bar_fg);
     396        } else if (result.isMoreDocuments()) {
     397            g.setColor(phind.document_bar_fg);
     398        } else {
     399            g.setColor(phind.thesaurus_bar_fg);         
     400        }
    389401        g.setFont(areaPlain);
    390         tab = (rightMargin - g.getFontMetrics().stringWidth(body)) / 2;
     402        tab = (mainRightMargin - g.getFontMetrics().stringWidth(body)) / 2;
    391403        g.drawString(body, tab, y);
    392404        }
     
    396408
    397409    // column backgrounds
    398     g.setColor(new Color(235, 245, 235));
    399     g.fillRect(firstColumn, 0, margin, canvasSize.height);
    400     g.setColor(new Color(200, 220, 200));
    401     g.fillRect(secondColumn, 0, margin, canvasSize.height);
     410    g.setColor(phind.column_1_bg);
     411    g.fillRect(firstColumnLeft, 0, firstColumnWidth, canvasSize.height);
     412    g.setColor(phind.column_2_bg);
     413    g.fillRect(secondColumnLeft, 0, secondColumnWidth, canvasSize.height);
    402414
    403415    // fill in the numbers
    404     g.setColor(Color.black);
     416    g.setColor(phind.column_1_fg);
    405417    g.setFont(areaPlain);
    406418    y = 0;
     
    420432        // Write the document frequency
    421433        if (docsText.length() > 0) {
    422         tab = secondColumn - space - g.getFontMetrics().stringWidth(docsText);
     434        tab = secondColumnLeft - space - g.getFontMetrics().stringWidth(docsText);
    423435        g.drawString(docsText, tab, y);
    424436        }
     
    426438        // Write the term frequency
    427439        if (freqText.length() > 0) {
    428         tab = secondColumn + margin - space - g.getFontMetrics().stringWidth(freqText);
     440        tab = secondColumnLeft + secondColumnWidth
     441            - space - g.getFontMetrics().stringWidth(freqText);
    429442        g.drawString(freqText, tab, y);
    430443        }
     
    447460    }
    448461
     462   
     463    g.setColor(phind.panel_fg);
    449464    g.drawRect(0,0, canvasSize.width - 1, canvasSize.height - 1);
    450465    }
     
    470485        // which Item is selected?
    471486        int rowSelected = event.y / lineSpacing;
    472         int itemSelected = rowSelected + firstItemDisplayed;
     487        itemSelected = rowSelected + firstItemDisplayed;
    473488        ResultItem item = (ResultItem) items.elementAt(itemSelected);
    474489
     
    486501                + "a=q&c=" + phind.collection
    487502                + "&q=%22" + item.toString().replace(' ', '+') + "%22";
    488             phind.displayWebPage(address, "phindsearch");
     503            phind.displayWebPage(address, phind.searchWindowName);
    489504            }
    490505        }
     
    501516                + "a=q&c=" + phind.collection
    502517                + "&q=%22" + item.toString().replace(' ', '+') + "%22";
    503             phind.displayWebPage(address, "phindsearch");
     518            phind.displayWebPage(address, phind.searchWindowName);
    504519            }
    505520        }
     
    514529            + "&d=" + item.hiddenText()
    515530            + "&q=" + parent.searchPhrase.replace(' ', '+');
    516             phind.displayWebPage(address, "phinddoc");
     531            phind.displayWebPage(address, phind.documentWindowName);
    517532        }
    518533         
  • trunk/gsdl/src/phind/client/ResultItemLink.java

    r1830 r1832  
    5858    id = newId;
    5959    symbol = Integer.valueOf(newId).intValue();
    60     text = newText;
     60    text = newText.trim();
    6161    linkType = newLinkType;
    6262    frequency = Integer.valueOf(tf).intValue();
  • trunk/gsdl/src/phind/client/ResultItemPhrase.java

    r1827 r1832  
    6666    body = b;
    6767    suffix = s;
    68     text = prefix + " " + body + " " + suffix;
     68    text = (prefix + " " + body + " " + suffix).trim();
    6969    }
    7070
Note: See TracChangeset for help on using the changeset viewer.