Changeset 2225 for trunk/java-client


Ignore:
Timestamp:
2001-03-26T19:07:55+12:00 (23 years ago)
Author:
daven
Message:

added QueryHistory, tooltips on collectionInfoButton. Altered
CSModel to retain CollectionInfo objects and longCollectionNames
for performance. Added files for a BerryBasket - to be turned on
soon. Added sorting of the QueryHistory via the TableMap and TableSorter
files - from the Java Swing tutorial - not sure about GPL status
of these 2.

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

Legend:

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

    r2222 r2225  
    8888    searchPanel = new SearchPanel(csModel, this);
    8989       
     90    JPanel centerPanel = new JPanel();
     91    QueryHistoryPanel queryHistoryPanel = new QueryHistoryPanel(csModel);
     92    centerPanel.add(queryHistoryPanel);
     93
    9094    content.setLayout(new BoxLayout(content, BoxLayout.X_AXIS));   
    9195    content.add(searchPanel);
     96    content.add(centerPanel);
    9297   
    9398    addWindowListener(new WindowHandler());
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CSModel.java

    r2184 r2225  
    1919package org.nzdl.gsdl.SimpleGraphicalClient;
    2020
     21import java.util.*;
    2122import java.util.Set;
    2223import java.util.TreeSet;
     
    2829import org.nzdl.gsdl.service.NzdlService;
    2930import org.nzdl.gsdl.service.NzdlCollectionInfo;
     31
    3032/**
    3133 * Class
     
    4345
    4446  Vector collectionList;
     47  TreeMap collectionInfoMap;
     48    HashMap collectionNameMap;
    4549  String currentCollection;
    4650  ResultModel results;
    4751  NzdlService nzdl;
     52  QueryHistoryModel queryHistoryModel;
    4853   
    4954
     
    5358    results = new ResultModel();
    5459    collectionList = new Vector();
     60    collectionInfoMap = new TreeMap();
     61    collectionNameMap = new HashMap();
     62    queryHistoryModel = new QueryHistoryModel();
    5563    currentCollection = "";
    5664    initialiseCollection();
     
    6371  }
    6472
    65    
     73    public QueryHistoryModel getQueryHistoryModel() {
     74    return queryHistoryModel;
     75    }
    6676   
    6777
     
    8696  /* collectionList methods */
    8797
    88   public Vector getCollectionList()
    89   {
    90     return collectionList;
    91   }
     98    public Vector getCollectionList() {
     99    return new Vector(collectionInfoMap.keySet());
     100    }
    92101
    93   public int getCollectionListSize()
    94   {
    95     return collectionList.size();
    96   }
    97    
    98   public void addCollection(String collection)
    99   {
    100     collectionList.add(collection);
    101   }
     102    public Collection getCollectionAsCollection() {
     103    return (Collection)collectionInfoMap;
     104    }
    102105
    103   public void setCurrentCollection(String collection )
    104   {
    105     currentCollection = collection;
    106   }
     106    public int getCollectionListSize() {
     107    return collectionInfoMap.size();
     108    }
    107109
    108   public String getCurrentCollection()
    109   {
    110     return currentCollection;
    111   }
     110    public NzdlCollectionInfo getCollectionInfo(String collectionName) {
     111    return (NzdlCollectionInfo) collectionInfoMap.get(collectionName);
     112    }
    112113
    113   public String getFirstCollection()
    114   {
    115     if (collectionList.size() > 0)
    116       return (String)collectionList.get(0);
    117     else
    118       return "no collections";
    119   }
    120   /**
    121    *
    122    */
    123   public void initialiseCollection()
    124   {
    125     Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles
    126     TreeSet orderedCollectionSet = new TreeSet(collectionSet);
    127     // TreeSet automatically puts strings in alphabetical order
    128     System.out.println("Number of collections on the server: " +
    129                orderedCollectionSet.size());
    130     Iterator collectionSetIterator = orderedCollectionSet.iterator();
    131     while (collectionSetIterator.hasNext() ) {
    132       // object -> String
    133       String collectionName = (String)collectionSetIterator.next();
    134       NzdlCollectionInfo info = nzdl.getCollectionInfo(collectionName);
    135       //System.err.println(info);
    136       if (info != null &&
    137       info.getBuildDate() != 0) {
    138     addCollection(collectionName);
    139     System.err.println("Adding " + collectionName + " to collection list...");
    140       } // end if
    141       else {
    142     System.err.println("Collection " + collectionName + " getBuildDate() returned 0");
    143       } // end else
    144     } // end while 
    145114
     115    public String getLongCollectionName(String collectionName) {
     116    return (String) collectionNameMap.get(collectionName);
     117    }
     118
     119
     120    public String getCollectionDescription(String collectionName) {
     121    Set descSet = nzdl.getMetaData(collectionName, "collection", "collectionextra");
     122    if (descSet.size() == 1)
     123        return (String) descSet.toArray()[0];
     124    else
     125        return "collectionName has more than 1 collectionextra entry";
     126    }
     127
     128
     129    public void setCurrentCollection(String collection )
     130        {
     131        currentCollection = collection;
     132        }
     133
     134    public String getCurrentCollection()
     135        {
     136        return currentCollection;
     137        }
     138
     139    public String getFirstCollection()
     140        {
     141        if (getCollectionListSize() > 0)
     142            return (String)collectionInfoMap.firstKey();
     143        else
     144            return "no collections";
     145        }
     146    /**
     147     *
     148     */
     149    public void initialiseCollection()
     150        {
     151        Set collectionSet = nzdl.getCollectionSet(); // set of strings of collection titles
     152        TreeSet orderedCollectionSet = new TreeSet(collectionSet);
     153        // TreeSet automatically puts strings in alphabetical order
     154        System.out.println("Number of collections on the server: " +
     155                   orderedCollectionSet.size());
     156        Iterator collectionSetIterator = orderedCollectionSet.iterator();
     157        while (collectionSetIterator.hasNext() ) {
     158            // object -> String
     159            String collectionName = (String)collectionSetIterator.next();
     160            NzdlCollectionInfo info = nzdl.getCollectionInfo(collectionName);
     161            if (info != null &&
     162            info.getBuildDate() != 0) {
     163            collectionInfoMap.put(collectionName, info);
     164            String longCollectionName = "";
     165            Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
     166            if (n.size() == 1)
     167                longCollectionName = (String) n.toArray()[0];
     168            else
     169                longCollectionName = collectionName + " has more than 1 collectionname";
     170            collectionNameMap.put(collectionName,longCollectionName );
     171            System.err.println("Adding " + collectionName + " to collection list...");
     172            } // end if
     173            else {
     174            System.err.println("Collection " + collectionName + " getBuildDate() returned 0");
     175            } // end else
     176        } // end while 
     177        setCurrentCollection(getFirstCollection()); //assume at least one collection
    146178   
    147 
    148     setCurrentCollection(getFirstCollection()); //assume at least one collection
    149    
    150   }
     179        }
    151180   
    152181   
    153 }
     182    }
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/CollectionInfoDialog.java

    r2222 r2225  
    5858private NumberFormat numFormat = NumberFormat.getInstance();
    5959
    60 CollectionInfoDialog(Frame f, String collectionName, NzdlService nzdl) {
    61     super(f, "Collection Information" );
    62 
    63     contentPanel = new JPanel(new GridLayout(0,2, 5, 4));;
    64     buttonPanel = new JPanel();
    65 
    66     NzdlCollectionInfo collectionInfo =  nzdl.getCollectionInfo(collectionName);
    67     Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
    68       if (n.size() == 1) {
    69     fullCollectionName =  (String) n.toArray()[0];
    70      }
    71     else {
    72     System.err.println(collectionName + " has more than 1 collectionname");
    73     }
    74     n.clear();
    75 
    76     collectionNamePanel = new JPanel();
    77     // collectionNamePanel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
    78     collectionNamePanel.add(new JLabel(fullCollectionName));
    79 
    80     contentPanel.add(new JLabel("Short collection name:"));
    81     JLabel collectionLabel = new JLabel(collectionName);
    82     contentPanel.add(collectionLabel);
    83     contentPanel.add(new JLabel("Number of Documents:"));
    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));
    91     contentPanel.add(new JLabel("Number of Words:"));
    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));
    99     contentPanel.add(new JLabel("Size:"));
    100     long numOfBytes = collectionInfo.getNumOfBytes();
    101     contentPanel.add(new JLabel(formatByteSize(numOfBytes)));
    102     contentPanel.add(new JLabel("Last built on:"));
    103     // waiting for API to return a correct Date object ...
    104     Date buildDate = new Date( collectionInfo.getBuildDate()*1000);
    105     contentPanel.add(new JLabel(DateFormat.getDateTimeInstance().format(buildDate)));
    106     contentPanel.add(new JLabel("Is it Public?"));
    107 
    108     if (collectionInfo.isPublic())
    109     publicString = "yes";
    110     else
    111     publicString = "no";
    112     contentPanel.add(new JLabel(publicString));
    113     contentPanel.add(new JLabel("Is it beta?"));
    114     if (collectionInfo.isBeta())
    115     betaString = "yes";
    116     else
    117     betaString = "no";
    118     contentPanel.add(new JLabel(betaString));
    119 
    120     JPanel descPanel = new JPanel();
    121     Set descSet = nzdl.getMetaData(collectionName, "collection", "collectionextra");
    122     if (descSet.size() == 1) {
    123     descString = (String) descSet.toArray()[0];
     60    CollectionInfoDialog(Frame f, String collectionName, CSModel csModel) {
     61    super(f, "Collection Information" );
     62
     63    contentPanel = new JPanel(new GridLayout(0,2, 5, 4));;
     64    buttonPanel = new JPanel();
     65
     66    NzdlCollectionInfo collectionInfo =  csModel.getCollectionInfo(collectionName);
     67    /*
     68      Set n = nzdl.getMetaData(collectionName, "collection", "collectionname");
     69      if (n.size() == 1) {
     70      fullCollectionName =  (String) n.toArray()[0];
     71      }
     72      else {
     73      System.err.println(collectionName + " has more than 1 collectionname");
     74      }
     75      n.clear();
     76    */
     77    collectionNamePanel = new JPanel();
     78    // collectionNamePanel.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
     79    collectionNamePanel.add(new JLabel(csModel.getLongCollectionName(collectionName)));
     80
     81    contentPanel.add(new JLabel("Short collection name:"));
     82    JLabel collectionLabel = new JLabel(collectionName);
     83    contentPanel.add(collectionLabel);
     84    contentPanel.add(new JLabel("Number of Documents:"));
     85
     86    long numOfDocs =  collectionInfo.getNumOfDocs();
     87    if (numOfDocs == 0)
     88        numOfDocsString = "unknown";
     89    else
     90        numOfDocsString = numFormat.format(numOfDocs);
     91    contentPanel.add(new JLabel(numOfDocsString));
     92    contentPanel.add(new JLabel("Number of Words:"));
     93
     94    long numOfWords = collectionInfo.getNumOfWords();
     95    if (numOfWords == 0)
     96        numOfWordsString = "unknown";
     97    else
     98        numOfWordsString = numFormat.format(numOfWords);
     99    contentPanel.add(new JLabel(numOfWordsString));
     100    contentPanel.add(new JLabel("Size:"));
     101    long numOfBytes = collectionInfo.getNumOfBytes();
     102    contentPanel.add(new JLabel(formatByteSize(numOfBytes)));
     103    contentPanel.add(new JLabel("Last built on:"));
     104    // waiting for API to return a correct Date object ...
     105    Date buildDate = new Date( collectionInfo.getBuildDate()*1000);
     106    contentPanel.add(new JLabel(DateFormat.getDateTimeInstance().format(buildDate)));
     107    contentPanel.add(new JLabel("Is it Public?"));
     108
     109    if (collectionInfo.isPublic())
     110        publicString = "yes";
     111    else
     112        publicString = "no";
     113    contentPanel.add(new JLabel(publicString));
     114    contentPanel.add(new JLabel("Is it beta?"));
     115    if (collectionInfo.isBeta())
     116        betaString = "yes";
     117    else
     118        betaString = "no";
     119    contentPanel.add(new JLabel(betaString));
     120
     121    JPanel descPanel = new JPanel();
     122    descString = csModel.getCollectionDescription(collectionName);
    124123    //System.err.println(descString);
    125124    if (descString.length() > 0) {
     
    143142        descPanel.add(scrollPane);
    144143    } // if
    145     } // if
    146     descSet.clear();
    147 
    148     okButton = new JButton("Ok");
    149     okButton.setPreferredSize(new Dimension(80,20));
    150     okButton.addActionListener(this);
    151     buttonPanel.add( okButton );
    152     getRootPane().setDefaultButton(okButton);
     144
     145    okButton = new JButton("Ok");
     146    okButton.setPreferredSize(new Dimension(80,20));
     147    okButton.addActionListener(this);
     148    buttonPanel.add( okButton );
     149    getRootPane().setDefaultButton(okButton);
    153150   
    154     holderPanel = new JPanel();
    155     holderPanel.setBorder(BorderFactory.createEmptyBorder(10,10,2,10));
    156     holderPanel.setLayout( new BoxLayout(holderPanel, BoxLayout.Y_AXIS));
    157     holderPanel.add(collectionNamePanel);
    158     holderPanel.add(contentPanel);
    159     if (descString.length() > 0) {
    160     holderPanel.add(Box.createVerticalStrut(10));
    161     holderPanel.add(descPanel); // only if we have a description to show
    162     }
    163     holderPanel.add(Box.createVerticalStrut(5));
    164     holderPanel.add(buttonPanel);
    165     getContentPane().add(holderPanel);
    166     pack();
    167     setVisible(true);
     151    holderPanel = new JPanel();
     152    holderPanel.setBorder(BorderFactory.createEmptyBorder(10,10,2,10));
     153    holderPanel.setLayout( new BoxLayout(holderPanel, BoxLayout.Y_AXIS));
     154    holderPanel.add(collectionNamePanel);
     155    holderPanel.add(contentPanel);
     156    if (descString.length() > 0) {
     157        holderPanel.add(Box.createVerticalStrut(10));
     158        holderPanel.add(descPanel); // only if we have a description to show
     159    }
     160    holderPanel.add(Box.createVerticalStrut(5));
     161    holderPanel.add(buttonPanel);
     162    getContentPane().add(holderPanel);
     163    pack();
     164    setVisible(true);
    168165    } //end CollectionInfoDialog constructor
    169166
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/Constants.java

    r2222 r2225  
    6464    Cursor WAIT_CURSOR = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    6565
    66 
     66    /* Query History Table Column Titles */
     67   
     68    String[]  QUERY_HISTORY_COLUMN_TITLES = {"Collection", "Terms"};
    6769
    6870
  • trunk/java-client/org/nzdl/gsdl/SimpleGraphicalClient/SearchPanel.java

    r2222 r2225  
    116116
    117117    collectionList = new JComboBox(csModel.getCollectionList()){
    118     public boolean isFocusTraversable() {
    119       return false;
    120     }
    121       };
    122     collectionInfoButton = new JButton("Info...");
     118           public boolean isFocusTraversable() {
     119        return false;
     120        }
     121    };
     122    collectionList.setEditable(false);
     123     
     124    collectionInfoButton = new JButton("Info...") {
     125        public String getToolTipText(MouseEvent e) {
     126        //return "more information on " + collectionList.getSelectedItem();
     127        return "More information on " + csModel.getLongCollectionName((String)collectionList.getSelectedItem());
     128        }
     129    };
     130    ToolTipManager.sharedInstance().registerComponent(collectionInfoButton);
    123131    collectionInfoButton.addActionListener(this);
    124132
     
    194202
    195203  public void actionPerformed(ActionEvent e) {
     204      String collectionName = collectionList.getSelectedItem().toString();
    196205    if (e.getSource() == searchButton ) {
    197206      // cursor not set when RETURN pressed, only when button clicked ?
    198207      windowParent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    199208      String queryString = searchTextField.getText();
    200       String collectionName = collectionList.getSelectedItem().toString();
    201209      System.err.println("Search started (" + collectionName + "): \"" + queryString + "\" ..." );
    202210      //send query to collection
     
    240248    resultsList.setSelectedIndex(0); // should be under Preference control!
    241249      } // end else
     250
     251
     252      csModel.getQueryHistoryModel().add( new QueryHistoryItem(new Query(queryString), new Date(), collectionName, "user"));
     253
    242254      titleMap.clear();
    243255      titleMetaData.clear();
     
    247259    else {
    248260    if (e.getSource() == collectionInfoButton) {
    249         CollectionInfoDialog cid = new CollectionInfoDialog(windowParent, collectionList.getSelectedItem().toString(), nzdl);
     261        CollectionInfoDialog cid = new CollectionInfoDialog(windowParent, collectionName, csModel);
    250262    }
    251263    else {
     
    287299          // treat as HTML
    288300          displayAsHTML(sr);
    289           htmlDoc.getImageData(nzdl, result.getCollectionName());
     301          //htmlDoc.getImageData(nzdl, result.getCollectionName());
    290302      }
    291303
Note: See TracChangeset for help on using the changeset viewer.