Changeset 2222 for trunk/java-client


Ignore:
Timestamp:
2001-03-24T15:16:44+12:00 (23 years ago)
Author:
daven
Message:

dynamically update display mode based on preference changes. i.e. if the user
switches to raw text mode the document display should update on the
exit of the prefences dialog, not until the user selects a new result.
Altered the listhandler in SearchPanel.java to simplify this and reduce
occurrences of multiple code.

Location:
trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CSFrame.java

    r2197 r2222  
    9191    content.add(searchPanel);
    9292   
    93         addWindowListener(new WindowHandler());
     93    addWindowListener(new WindowHandler());
    9494       
    9595    pack();
     
    110110  abstract class CSAction extends AbstractAction {
    111111      int menuItemID;
    112       Frame frame;
    113  
    114           CSAction( String name, int newMenuItemID, Frame f)
     112      CSFrame frame;
     113 
     114          CSAction( String name, int newMenuItemID, CSFrame f)
    115115          {
    116116            super(name);
     
    125125  class FileAction extends CSAction
    126126  {
    127         FileAction(String name, int newMenuItemID, Frame frame)
     127        FileAction(String name, int newMenuItemID, CSFrame frame)
    128128        {
    129129             super(name,newMenuItemID, frame );
     
    159159  class EditAction extends CSAction
    160160  {
    161         EditAction(String name, int newMenuItemID, Frame frame)
     161        EditAction(String name, int newMenuItemID, CSFrame frame)
    162162        {
    163163             super(name,newMenuItemID, frame );
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CollectionInfoDialog.java

    r2210 r2222  
    5555private String fullCollectionName = "";
    5656private String descString = "";
     57private String numOfWordsString, numOfDocsString;
    5758private NumberFormat numFormat = NumberFormat.getInstance();
    5859
     
    8182    contentPanel.add(collectionLabel);
    8283    contentPanel.add(new JLabel("Number of Documents:"));
    83     String numOfDocs = numFormat.format( collectionInfo.getNumOfDocs());
    84     contentPanel.add(new JLabel(numOfDocs));
     84
     85    long numOfDocs =  collectionInfo.getNumOfDocs();
     86    if (numOfDocs == 0)
     87    numOfDocsString = "unknown";
     88    else
     89    numOfDocsString = numFormat.format(numOfDocs);
     90    contentPanel.add(new JLabel(numOfDocsString));
    8591    contentPanel.add(new JLabel("Number of Words:"));
    86     String numOfWords = numFormat.format( collectionInfo.getNumOfWords());
    87     contentPanel.add(new JLabel(numOfWords));
     92
     93    long numOfWords = collectionInfo.getNumOfWords();
     94    if (numOfWords == 0)
     95    numOfWordsString = "unknown";
     96    else
     97    numOfWordsString = numFormat.format(numOfWords);
     98    contentPanel.add(new JLabel(numOfWordsString));
    8899    contentPanel.add(new JLabel("Size:"));
    89100    long numOfBytes = collectionInfo.getNumOfBytes();
    90101    contentPanel.add(new JLabel(formatByteSize(numOfBytes)));
    91102    contentPanel.add(new JLabel("Last built on:"));
     103    // waiting for API to return a correct Date object ...
    92104    Date buildDate = new Date( collectionInfo.getBuildDate()*1000);
    93105    contentPanel.add(new JLabel(DateFormat.getDateTimeInstance().format(buildDate)));
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/Constants.java

    r2190 r2222  
    1919package org.nzdl.gsdl.SimpleGraphicalClient;
    2020
    21 import java.awt.Font;
     21import java.awt.*;
    2222
    2323/**
     
    5959    String SAVE_DOCS = "Save documents";
    6060
     61    /* Cursors */
     62
     63    Cursor NORMAL_CURSOR = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
     64    Cursor WAIT_CURSOR = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
     65
     66
     67
     68
    6169/*Fonts */
    6270
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/PreferencesDialog.java

    r2195 r2222  
    4747public class PreferencesDialog extends JDialog implements ActionListener {
    4848
     49    private CSFrame parentFrame;
    4950private JButton okButton, cancelButton;
    5051private JPanel  buttonPanel, holderPanel;
     
    5455
    5556
    56 PreferencesDialog(Frame f, String title, boolean modal) {
     57PreferencesDialog(CSFrame f, String title, boolean modal) {
    5758    super(f, title, modal );
     59    parentFrame = f;
    5860
    5961    contentBox = Box.createVerticalBox();
     
    138140        //System.err.println("ok button pressed!");
    139141
     142        boolean oldRawText =  NzdlPreferences.getBoolean(Constants.RAW_TEXT);
     143
    140144        NzdlPreferences.setBoolean(Constants.DISPLAY_FIRST_DOC,showFirstDocCheckBox.isSelected());
    141145        NzdlPreferences.setBoolean(Constants.RAW_TEXT, showAsTextCheckBox.isSelected());
     
    148152      // update the current display if raw text option has changed ?
    149153
     154      boolean newRawText = NzdlPreferences.getBoolean(Constants.RAW_TEXT);
     155     
     156      if (oldRawText != newRawText) {
     157          //System.err.println("raw text option changed");
     158          if (newRawText) {
     159          // kludgy direct access to instance and method
     160          parentFrame.searchPanel.switchToRawText();
     161          }
     162          else
     163          // kludgy direct access to instance and method
     164              parentFrame.searchPanel.switchToHTML();
     165      } // end if oldRawText != newRawTex
     166
    150167      dispose(); //close window
    151     }
     168    } // end if source == okButton
    152169    else
    153170    {
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java

    r2210 r2222  
    210210     
    211211      nzdl.service( collectionName, request, response );
    212      Date t8 = new Date();
    213212      NzdlResultSet results = response.getResultSet();
    214213      ArrayList docIDs = new ArrayList(results.getDocumentIDs());
     
    225224    titleMap.put(docID, titleList.get(0));
    226225      } // end for
    227       Date t9 = new Date();
    228       long sdiff = t9.getTime() - t8.getTime();
    229       System.err.println("processing results = " + sdiff + " ms");
    230226      // update the results list
    231227      csModel.clearResults();
     
    251247    else {
    252248    if (e.getSource() == collectionInfoButton) {
    253         //System.err.println("colllection info button pressed");
    254249        CollectionInfoDialog cid = new CollectionInfoDialog(windowParent, collectionList.getSelectedItem().toString(), nzdl);
    255250    }
     
    278273      System.err.println("clicked on fake result");
    279274      }
    280       else {
    281  // a real result representing a real document to deal with
    282 
    283       windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    284       //trash the old htmlDoc for memory/garbage collection
    285       try {
    286         if (htmlDoc != null)
    287           htmlDoc.remove(0, htmlDoc.getLength());
    288         if (defaultStyledDoc != null)
    289         defaultStyledDoc.remove(0, defaultStyledDoc.getLength());
    290       } catch (Exception exception) {
    291       throw new Error (exception.toString());
     275      else { // a real result representing a real document to deal with
     276
     277      windowParent.setCursor(WAIT_CURSOR);
     278
     279      deleteDocContents(); // for memory/garbage collection
     280
     281      StringReader sr = new StringReader(nzdl.getDocument(result.getCollectionName(),  result.getDocID()));
     282
     283      if (NzdlPreferences.getInstance().getBoolean(Constants.RAW_TEXT))
     284          // display the document as raw text
     285          displayAsRawText(sr);
     286      else {
     287          // treat as HTML
     288          displayAsHTML(sr);
     289          htmlDoc.getImageData(nzdl, result.getCollectionName());
    292290      }
    293       defaultStyledDoc = new DefaultStyledDocument();
    294       htmlDoc = new GMLDocument();
    295 
    296       try { // get the document
    297           String docContents = csModel.getNzdlService().getDocument(result.getCollectionName(),  result.getDocID());
    298            StringReader sr = new StringReader(docContents);
    299            if (NzdlPreferences.getInstance().getBoolean(Constants.RAW_TEXT)) { // display the document as raw text
    300            documentPane.setEditorKit(styledEditorKit);
    301            styledEditorKit.read( sr, defaultStyledDoc, 0);
    302            documentPane.setDocument(defaultStyledDoc);
    303            docLength = defaultStyledDoc.getLength();
    304            }
    305            else { // treat as HTML
    306            documentPane.setEditorKit(htmlEditorKit);
    307            htmlEditorKit.read( sr, htmlDoc, 0);
    308            documentPane.setStyledDocument( htmlDoc );
    309            docLength = htmlDoc.getLength();
    310            }
    311       } // end try
    312       catch(BadLocationException badLocException)
    313       {
    314       System.err.println("Bad Location Exception in creating HTML doc" + badLocException);
    315       }
    316       catch(IOException ioException)
    317       {
    318           System.err.println("IO Exception whilst reading doc contents" + ioException);
    319       }
    320 
    321       if (docLength > 0)
    322           documentPane.setCaretPosition(1);
    323       // we might not be using htmlDoc at this point!!
    324       htmlDoc.getImageData(nzdl, result.getCollectionName());
    325       windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    326       //System.err.println("prefix = " + nzdl.getCollectionInfo(result.getCollectionName()).getHTTPPrefix());
     291
     292      windowParent.setCursor(NORMAL_CURSOR);
    327293      }
    328294    } //end valueChanged
    329295  }//end ResultListSelectionHandler
    330296
    331 } //end SearchPanel
     297
     298
     299    private void deleteDocContents() {
     300    //trash the old htmlDoc for memory/garbage collection
     301    try {
     302        if (htmlDoc != null)
     303        htmlDoc.remove(0, htmlDoc.getLength());
     304        if (defaultStyledDoc != null)
     305        defaultStyledDoc.remove(0, defaultStyledDoc.getLength());
     306    }
     307    catch (Exception exception) {
     308        throw new Error (exception.toString());
     309    }
     310    } // end deleteDocContents
     311
     312
     313    public void switchToRawText() {
     314    windowParent.setCursor(WAIT_CURSOR);
     315    System.err.println("switching to raw text");
     316    displayAsRawText(new StringReader(documentPane.getText()));
     317    windowParent.setCursor(NORMAL_CURSOR);
     318    }
     319
     320    public void displayAsRawText(StringReader sr) {
     321        defaultStyledDoc = new DefaultStyledDocument();
     322        documentPane.setEditorKit(styledEditorKit);
     323        try {
     324        styledEditorKit.read( sr, defaultStyledDoc, 0);
     325        }
     326        catch (Exception e) {
     327        System.err.println(e);
     328        }
     329        documentPane.setDocument(defaultStyledDoc);
     330        setCaretToStart(defaultStyledDoc.getLength());
     331     } // end displayAsRawText
     332
     333
     334    public void switchToHTML() {
     335         windowParent.setCursor(WAIT_CURSOR);
     336         System.err.println("switching to HTML");
     337         displayAsHTML(new StringReader(documentPane.getText()));
     338         windowParent.setCursor(NORMAL_CURSOR);
     339    }
     340
     341     public void displayAsHTML(StringReader sr) {
     342         htmlDoc = new GMLDocument();
     343         documentPane.setEditorKit(htmlEditorKit);
     344         try {
     345         htmlEditorKit.read( sr, htmlDoc, 0);
     346         }
     347         catch (Exception e) {
     348         System.err.println(e);
     349         }
     350         documentPane.setStyledDocument( htmlDoc );
     351         setCaretToStart(htmlDoc.getLength());
     352      } // end displayAsHTML
     353
     354
     355    private void setCaretToStart(int docLength) {
     356         // it seems as if they haven't considered
     357         // documents with > MAX_INT num of chars ...
     358    if (docLength > 0)
     359        documentPane.setCaretPosition(1);
     360    }
     361
     362
     363     } //end SearchPanel
Note: See TracChangeset for help on using the changeset viewer.